From f085204c5e2f09a09fbfd167bea4940219871fbd Mon Sep 17 00:00:00 2001 From: David Corvoysier Date: Tue, 11 Feb 2025 15:51:09 +0000 Subject: [PATCH] feat(neuron): add server standalone installation --- backends/neuron/Makefile | 6 ++++-- backends/neuron/server/Makefile | 21 +++++++++++++++++++-- backends/neuron/server/pyproject.toml | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/backends/neuron/Makefile b/backends/neuron/Makefile index f7a33393..6da77f79 100644 --- a/backends/neuron/Makefile +++ b/backends/neuron/Makefile @@ -16,13 +16,15 @@ mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) root_dir := "${mkfile_dir}/../.." -.PHONY: image +.PHONY: image install_server VERSION := $(shell gawk 'match($$0, /^version = "(.*)"/, a) {print a[1]}' ${root_dir}/Cargo.toml) image: docker build --rm -f ${root_dir}/Dockerfile.neuron \ --build-arg VERSION=$(VERSION) \ - --ulimit nofile=100000:100000 \ -t text-generation-inference:$(VERSION)-neuron ${root_dir} docker tag text-generation-inference:$(VERSION)-neuron text-generation-inference:latest-neuron + +install_server: + make -C ${mkfile_dir}/server install VERSION:=${VERSION} diff --git a/backends/neuron/server/Makefile b/backends/neuron/server/Makefile index 24d5e0d1..efe34bd0 100644 --- a/backends/neuron/server/Makefile +++ b/backends/neuron/server/Makefile @@ -1,15 +1,20 @@ # Initialize base variables +SHELL := /bin/bash pkg_name := text_generation_server BUILDDIR ?= $(CURDIR)/build VERSION ?= 0.0.1 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_dir := $(dir $(mkfile_path)) pkg_dir := $(BUILDDIR)/$(pkg_name) -pkg_dist := ${BUILDDIR}/dist/${pkg_name}-${VERSION}.tar.gz +py_version := $(subst -,.,${VERSION}) +pkg_dist := ${BUILDDIR}/dist/${pkg_name}-$(py_version).tar.gz clean: rm -rf $(BUILDDIR)/* +${BUILDDIR}: + install -d $@ + # List static sources to be deployed in the package src_dir := $(mkfile_dir)/$(pkg_name) sources := $(wildcard $(src_dir)/*.py) @@ -21,7 +26,15 @@ define COPY cp -f $< $@ endef -$(BUILDDIR)/pyproject.toml: $(mkfile_dir)/pyproject.toml +# We use a PHONY target to represent the VERSION +.PHONY: VERSION + +VERSION: ${BUILDDIR} + # The trick is to compare the value of the variable with the content of a file in the build directory + @if [[ `cat ${BUILDDIR}/VERSION 2>&1` != '$(VERSION)' ]]; then echo -n $(VERSION) >${BUILDDIR}/VERSION; fi + +# Depending on the PHONY VERSION target makes sure the pyproject.toml is regenerated if the version changes +$(BUILDDIR)/pyproject.toml: $(mkfile_dir)/pyproject.toml VERSION mkdir -p $(BUILDDIR) $(COPY) sed -i -e 's/version = "VERSION"/version = \"${VERSION}\"/' $@ @@ -55,3 +68,7 @@ ${pkg_dist}: $(BUILDDIR)/pyproject.toml $(deployed_sources) $(generated_sources) python -m build $(BUILDDIR) package: ${pkg_dist} + +install: ${pkg_dist} + python3 -m pip uninstall -y ${pkg_name} + python3 -m pip install ${pkg_dist} diff --git a/backends/neuron/server/pyproject.toml b/backends/neuron/server/pyproject.toml index f37dc91f..ed790fdb 100644 --- a/backends/neuron/server/pyproject.toml +++ b/backends/neuron/server/pyproject.toml @@ -15,7 +15,8 @@ dependencies = [ 'grpc-interceptor == 0.15.2', 'typer == 0.6.1', 'safetensors', - 'loguru == 0.6.0' + 'loguru == 0.6.0', + 'optimum-neuron[neuronx] >= 0.0.28', ] [tool.setuptools]