Skip to content

Commit

Permalink
allow for easy docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed May 13, 2024
1 parent b0aafc7 commit e4e10f3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
66 changes: 50 additions & 16 deletions .devcontainer/Dockerfile-prod-vllm
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# doker container with aicirt
# TAG: aici/vllm-openai
FROM rust:1.75.0-bookworm AS aicirt

FROM vllm/vllm-openai
WORKDIR /workspace

RUN rustup target add wasm32-wasi
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs

COPY controllers controllers
COPY aicirt aicirt
COPY scripts scripts
COPY py/pyaici py/pyaici
COPY Cargo.toml Cargo.lock /workspace/

RUN grep -v rllm Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml

RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/workspace/target \
cargo fetch

ARG tag=latest
ENV BUILD_TAG=$tag
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/workspace/target \
SKIP_LLAMA_CPP=1 \
./scripts/release.sh && cp -r /workspace/target/dist /workspace/


FROM vllm/vllm-openai as vllm-base

# install pyaici pre-requisites
RUN pip install posix_ipc ujson
Expand All @@ -13,23 +40,30 @@ COPY py/pyaici /tmp/pyaici/pyaici
RUN cd /tmp/pyaici && pip install . && rm -rf /tmp/pyaici

# patch the vllm python files
COPY target/vllm.tar.gz /tmp/
RUN tar -xzf /tmp/vllm.tar.gz -C /usr/local/lib/python3.10/dist-packages/vllm && rm /tmp/vllm.tar.gz
RUN --mount=source=py/vllm/vllm,target=/tmp/vllm \
(cd /tmp/vllm && find . -name '*.py' -print0 | tar -cf - --null -T -) | \
tar -C /usr/local/lib/python3.10/dist-packages/vllm -xf -

# install aicirt
COPY target/dist/aicirt/aicirt /usr/bin/aicirt

# copy the controllers
# copy the controllers and aicirt
WORKDIR /vllm-workspace
RUN mkdir wasm
COPY target/dist/aici_*.wasm wasm/

# "upload" and tag the controllers
RUN aicirt --module wasm/aici_guidance_ctrl.wasm --tag guidance
RUN aicirt --module wasm/aici_pyctrl.wasm --tag pyctrl --gh-module gh:microsoft/aici/pyctrl
RUN aicirt --module wasm/aici_jsctrl.wasm --tag jsctrl --gh-module gh:microsoft/aici/jsctrl
RUN --mount=from=aicirt,source=/workspace/dist,target=/tmp/dist \
cp /tmp/dist/aicirt/aicirt /usr/bin/aicirt && \
cp /tmp/dist/aici_*.wasm wasm/

RUN ls -l wasm/

ENV RUST_LOG info,tokenizers=error

# not sure about --enforce-eager
ENTRYPOINT ["python3", "-m", "vllm.entrypoints.openai.api_server", "--enforce-eager", "--use-v2-block-manager", "--enable-chunked-prefill", "--aici-rt=/usr/bin/aicirt", "-A--restricted"]
ENTRYPOINT ["python3", "-m", "vllm.entrypoints.openai.api_server", "--enforce-eager", "--use-v2-block-manager", "--enable-chunked-prefill", "--aici-rt=/usr/bin/aicirt", "-A--restricted", "-A--wasm-timer-resolution-us=10"]

FROM vllm-base AS vllm-guidance

RUN aicirt --module wasm/aici_guidance_ctrl.wasm --tag guidance --tag guidance_ctrl-latest

FROM vllm-base as vllm-general

RUN aicirt --module wasm/aici_guidance_ctrl.wasm --tag guidance --tag guidance_ctrl-latest
RUN aicirt --module wasm/aici_pyctrl.wasm --tag pyctrl --gh-module gh:microsoft/aici/pyctrl
RUN aicirt --module wasm/aici_jsctrl.wasm --tag jsctrl --gh-module gh:microsoft/aici/jsctrl
2 changes: 1 addition & 1 deletion py/vllm
39 changes: 13 additions & 26 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,33 @@

set -e

if test -w target ; then
:
else
sudo chgrp docker target
sudo chmod g+w target
DOCKER_TARGET="$1"
if test -z "$DOCKER_TARGET" ; then
DOCKER_TARGET=vllm-general
fi

if test -f target/dist/README.md ; then
:
else
echo "Run ./scripts/release.sh first (in dev docker container)"
exit 1
fi

DOCKERFILE="$1"
DOCKERFILE="$2"
if test -z "$DOCKERFILE" ; then
DOCKERFILE=.devcontainer/Dockerfile-prod-vllm
fi

set -x
D=`date +%Y%m%d-%H%M`
TAG=`git describe --dirty --tags --match 'v[0-9]*' --always | sed -e 's/^v//; s/-dirty/-'"$D/"`

case "$DOCKERFILE" in
*vllm*)
rm -f target/vllm.tar.gz
( cd py/vllm/vllm; \
find . -name '*.py' -print0 | tar -czf - --null -T - ) > target/vllm.tar.gz
ls -l target/vllm.tar.gz
;;
esac

LOCAL_TAG=$(grep "TAG:" $DOCKERFILE | sed -e 's/.*TAG: *//')
set -x

DOCKER_BUILDKIT=1 \
docker build . -f $DOCKERFILE --tag $LOCAL_TAG
docker build . -f $DOCKERFILE \
--target $DOCKER_TARGET \
--tag $DOCKER_TARGET \
--build-arg tag="$TAG" \
--progress=plain

if [ "X$DOCKER_PUSH" != X ] ; then
if test -z "$DOCKER_TAG" ; then
DOCKER_TAG=v$(date '+%Y%m%d-%H%M')
fi
docker tag $LOCAL_TAG $DOCKER_PUSH:$DOCKER_TAG
docker tag $DOCKER_TARGET $DOCKER_PUSH:$DOCKER_TAG
docker push $DOCKER_PUSH:$DOCKER_TAG

set +x
Expand Down
24 changes: 19 additions & 5 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ controllers/declctrl
controllers/jsctrl
controllers/pyctrl
controllers/uppercase
controllers/guidance_ctrl
aicirt
rllm/rllm-llamacpp
"

NATIVE="$(uname -s | tr 'A-Z' 'a-z')-$(uname -m)"
D=`date +%Y%m%d-%H%M`
TAG=`git describe --dirty --tags --match 'v[0-9]*' --always | sed -e 's/^v//; s/-dirty/-'"$D/"`

if test -z "$BUILD_TAG" ; then
D=`date +%Y%m%d-%H%M`
TAG=`git describe --dirty --tags --match 'v[0-9]*' --always | sed -e 's/^v//; s/-dirty/-'"$D/"`
else
TAG="$BUILD_TAG"
fi

XZ=

if [ "$1" == "--xz" ] ; then
XZ=1
shift
fi

echo "Building for $NATIVE"
echo "Building for $NATIVE with tag $TAG..."

set -e

if test -z "$SKIP_LLAMA_CPP" ; then
FOLDERS="$FOLDERS rllm/rllm-llamacpp"
fi

for f in $FOLDERS ; do
echo "Build $f..."
(cd $f && cargo build --release)
Expand Down Expand Up @@ -157,4 +168,7 @@ echo -n > target/dist/README.md

release aici-controllers "AICI Controllers" "wasm32-wasi" target/wasm32-wasi/release/*.wasm
release aicirt "AICI Runtime" "$NATIVE" target/release/aicirt
release rllm-llamacpp "rLLM with llama.cpp" "$NATIVE" target/release/rllm-llamacpp

if test -z "$SKIP_LLAMA_CPP" ; then
release rllm-llamacpp "rLLM with llama.cpp" "$NATIVE" target/release/rllm-llamacpp
fi

0 comments on commit e4e10f3

Please sign in to comment.