Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for CUDA #944

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2d3d82a
Implement support for CUDA
gaby Dec 4, 2023
2418ef0
Add suffix to CI
gaby Dec 4, 2023
e6f625a
Merge branch 'main' into gpu-support
gaby Dec 6, 2023
c956afc
Merge branch 'main' into gpu-support
gaby Dec 7, 2023
cc2022b
Merge branch 'main' into gpu-support
gaby Dec 9, 2023
e054956
Merge branch 'main' into gpu-support
gaby Dec 13, 2023
a766ce6
Merge branch 'main' into gpu-support
gaby Dec 18, 2023
6f102a6
Merge branch 'main' into gpu-support
gaby Dec 18, 2023
c9bffc0
Merge branch 'main' into gpu-support
gaby Dec 19, 2023
0b125ae
Merge branch 'main' into gpu-support
gaby Dec 20, 2023
7523f78
Merge branch 'main' into gpu-support
gaby Dec 21, 2023
9701d12
Merge branch 'main' into gpu-support
gaby Dec 22, 2023
0f3358a
Merge branch 'main' into gpu-support
gaby Dec 27, 2023
85c9892
Merge branch 'main' into gpu-support
gaby Jan 4, 2024
e00be78
Merge branch 'main' into gpu-support
gaby Jan 8, 2024
8af2083
Merge branch 'main' into gpu-support
gaby Jan 10, 2024
fe52b4c
Merge branch 'main' into gpu-support
gaby Feb 5, 2024
8e35f23
Add GPU support (#1056)
Smartappli Feb 13, 2024
b65e7ab
Merge branch 'main' into gpu-support
gaby Feb 13, 2024
da4bdef
Merge branch 'main' into gpu-support
gaby Feb 14, 2024
ca84dcc
Merge branch 'main' into gpu-support
gaby Feb 14, 2024
235d65c
Update llama-cpp-python (#1138)
Smartappli Feb 18, 2024
9dc8f42
Merge branch 'main' into gpu-support
gaby Feb 24, 2024
38d2245
Merge branch 'main' into gpu-support
gaby Feb 25, 2024
c0322a8
Merge branch 'main' into gpu-support
gaby Mar 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tests
_releaser
_site
CONTRIBUTING.md
Dockerfile
docker/
docker-compose.yml
docker-compose.dev.yml
.vscode/
Expand Down
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/docker-gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Docker (CUDA Suport)

on:
push:
branches:
- "main"
paths-ignore:
- "**.md"
- LICENSE
- "docker-compose.yml"
- "docker-compose.dev.yml"
- ".github/ISSUE_TEMPLATE/*.yml"
- ".github/dependabot.yml"
- ".github/release-drafter.yml"
pull_request:
branches:
- "*"
paths:
- "docker/Dockerfile.gpu"
- "scripts/deploy.sh"
- "scripts/dev.sh"
workflow_dispatch:
release:
types: [published, edited]

jobs:
build-and-publish-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/serge-chat/serge
flavor: |
suffix=-cuda,onlatest=true
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Publish Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile.gpu
push: ${{ github.event_name != 'pull_request' }}
target: release
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
gaby marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ on:
branches:
- "*"
paths:
- "Dockerfile"
- "Dockerfile.dev"
- "docker/Dockerfile"
- "scripts/deploy.sh"
- "scripts/dev.sh"
workflow_dispatch:
Expand Down Expand Up @@ -61,6 +60,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
target: release
cache-from: type=gha
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
restart: on-failure
build:
context: .
dockerfile: Dockerfile.dev
dockerfile: docker/Dockerfile.dev
volumes:
- ./web:/usr/src/app/web/:z
- ./api:/usr/src/app/api/:z
Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ---------------------------------------
# Base image for redis
FROM redis:7-bookworm as redis

# ---------------------------------------
# Build frontend
FROM node:20-bookworm-slim as frontend

WORKDIR /usr/src/app
COPY ./web/package.json ./web/package-lock.json ./
RUN npm ci

COPY ./web /usr/src/app/web/
WORKDIR /usr/src/app/web/
RUN npm run build

# ---------------------------------------
# Runtime environment
FROM python:3.11-slim-bookworm as release

# Set ENV
ENV NODE_ENV='production'
ENV TZ=Etc/UTC
WORKDIR /usr/src/app

# Copy artifacts
COPY --from=redis /usr/local/bin/redis-server /usr/local/bin/redis-server
COPY --from=redis /usr/local/bin/redis-cli /usr/local/bin/redis-cli
COPY --from=frontend /usr/src/app/web/build /usr/src/app/api/static/
COPY ./api /usr/src/app/api
COPY scripts/deploy.sh /usr/src/app/deploy.sh
COPY scripts/serge.env /usr/src/app/serge.env
COPY vendor/requirements.txt /usr/src/app/requirements.txt

# Install api dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends dumb-init \
&& pip install --no-cache-dir ./api \
&& pip install -r /usr/src/app/requirements.txt \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* \
&& chmod 755 /usr/src/app/deploy.sh \
&& chmod 755 /usr/local/bin/redis-server \
&& chmod 755 /usr/local/bin/redis-cli \
&& mkdir -p /etc/redis \
&& mkdir -p /data/db \
&& mkdir -p /usr/src/app/weights \
&& echo "appendonly yes" >> /etc/redis/redis.conf \
&& echo "dir /data/db/" >> /etc/redis/redis.conf

EXPOSE 8008
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/bin/bash", "-c", "/usr/src/app/deploy.sh"]
gaby marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 8 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ detect_cpu_features() {
echo "basic"
fi
}

# Check if the CPU architecture is aarch64/arm64
if [ "$cpu_arch" = "aarch64" ]; then
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://gaby.github.io/arm64-wheels/"
else
# Use @smartappli provided wheels
cpu_feature=$(detect_cpu_features)
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cpu"

if [ "$SERGE_GPU_NVIDIA_SUPPORT" = true ]; then
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cu122"
elif [ "$SERGE_GPU_AMD_SUPPORT" = true ]; then
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/rocm5.6.1"
else
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cpu"
fi
fi

echo "Recommended install command for llama-cpp-python: $pip_command"
Expand Down
9 changes: 8 additions & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ if [ "$cpu_arch" = "aarch64" ]; then
else
# Use @smartappli provided wheels
cpu_feature=$(detect_cpu_features)
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cpu"

if [ "$SERGE_GPU_NVIDIA_SUPPORT" = true ]; then
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cu122"
elif [ "$SERGE_GPU_AMD_SUPPORT" = true ]; then
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/rocm5.6.1"
else
pip_command="python -m pip install -v llama-cpp-python==$LLAMA_PYTHON_VERSION --only-binary=:all: --extra-index-url=https://smartappli.github.io/serge-wheels/$cpu_feature/cpu"
fi
fi

echo "Recommended install command for llama-cpp-python: $pip_command"
Expand Down
2 changes: 2 additions & 0 deletions scripts/serge.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SERGE_GPU_NVIDIA_SUPPORT=false
SERGE_GPU_AMD_SUPPORT=false
LLAMA_PYTHON_VERSION=0.2.50
SERGE_ENABLE_IPV4=true
SERGE_ENABLE_IPV6=false