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

Added huggingfaceserver rock and tests #103

Merged
merged 61 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cd50c09
Added huggingfaceserver rock and tests
BON4 Dec 18, 2024
5954e1d
Added huggingfaceserver rock and tests
BON4 Dec 18, 2024
0e921f9
Added huggingfaceserver rock and tests
BON4 Jan 8, 2025
dfc0f81
Added huggingfaceserver rock and tests
BON4 Jan 9, 2025
11daab8
Added huggingfaceserver rock and tests
BON4 Jan 10, 2025
8e42937
Added huggingfaceserver rock and tests
BON4 Jan 10, 2025
64f73b8
Added huggingfaceserver rock and tests
BON4 Jan 10, 2025
ee9fe0c
Added huggingfaceserver rock and tests
BON4 Jan 10, 2025
12d86e0
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
ba63b53
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
b0707f1
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
6c379ca
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
916c4d4
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
64baec4
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
5b26c08
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
b41e498
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
d7d383d
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
49b337a
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
2694154
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
29f373f
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
9ff2613
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
12c2639
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
911f900
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
fbdf73a
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
1856b80
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
09fff43
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
d443c95
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
91f2a89
Added huggingfaceserver rock and tests
BON4 Jan 16, 2025
8ae8cd5
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
fc1c3c7
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
1c8b369
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
286e233
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
09f176a
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
06feacd
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
ff88b5f
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
5f6ef0f
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
96ed015
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
d3dbd7c
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
f51876e
Added huggingfaceserver rock and tests
BON4 Jan 17, 2025
aa439f6
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
0e870ed
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
f7e6b78
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
921548c
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
6a310f8
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
ee831be
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
b5c04c2
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
0915077
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
1f70aa2
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
7d0f3a2
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
23a9238
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
1f7727f
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
76080f1
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
08e592f
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
87b917f
cAdded huggingfaceserver rock and tests
BON4 Jan 20, 2025
a3268fb
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
ab3d93f
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
e583ef7
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
e8893c7
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
d4ae296
Added huggingfaceserver rock and tests
BON4 Jan 20, 2025
1fea30d
Added huggingfaceserver rock and tests
BON4 Jan 27, 2025
1b4c066
Merge branch 'main' into huggingfaceserver
misohu Jan 29, 2025
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
11 changes: 11 additions & 0 deletions huggingfaceserver/dummy_pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.poetry]
name = "workaround-for-editable-install"
version = "0.0.1"
description = ""
authors = ["none"]

[tool.poetry.dependencies]
# This range should match that used upstream: https://github.com/kserve/kserve/blob/v0.13.0/python/huggingfaceserver/pyproject.toml#L13
python = ">=3.9,<3.12"
kserve = { path = "../python/kserve", develop = false }
huggingfaceserver = { path = "../python/huggingfaceserver", develop = false }
120 changes: 120 additions & 0 deletions huggingfaceserver/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Based on https://github.com/kserve/kserve/blob/v0.13.0/python/huggingface_server.Dockerfile
# See ../CONTRIBUTING.md for more details about the patterns used in this rock.
# This rock is implemented with some atypical patterns due to the native of the upstream
# Dockerfile.
name: huggingfaceserver
summary: Huggingface server for Kserve deployments
description: "Kserve Huggingface server"
version: "0.13.0"
license: Apache-2.0
base: ubuntu@22.04
run-user: _daemon_

platforms:
amd64:

services:
huggingfaceserver:
override: replace
summary: "Huggingface server service"
startup: enabled
command: "python -m huggingfaceserver [ ]"
environment:
PYTHONPATH: "/usr/local/lib/python3.10/dist-packages"
HF_HOME: "/tmp/huggingface"
SAFETENSORS_FAST_GPU: "1"
HF_HUB_DISABLE_TELEMETRY: "1"
CUDA: "12.1"
CUDA_VERSION: "12.1.0"
NVIDIA_VISIBLE_DEVICES: "all"
NVIDIA_DRIVER_CAPABILITIES: "compute,utility"
PATH: "/usr/local/nvidia/bin:/usr/local/cuda/bin:$PATH"
LD_LIBRARY_PATH: "/usr/local/cuda-12.1/lib:/usr/local/cuda-12.1/lib64:$LD_LIBRARY_PATH"
entrypoint-service: huggingfaceserver

parts:
security-team-requirement:
plugin: nil
override-build: |
mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks
(echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && \
dpkg-query --root=${CRAFT_PROJECT_DIR}/../bundles/ubuntu-22.04/rootfs/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) \
> ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query

python:
plugin: nil
source: https://github.com/kserve/kserve.git
source-subdir: python
source-tag: v0.13.0
overlay-packages:
- python3.10
# Including python3-pip here means pip also gets primed for the final rock
- python3-pip
build-packages:
- build-essential
- libgomp1
- wget
build-environment:
- CUDA: "12.1"
- LD_LIBRARY_PATH: "/usr/local/cuda-12.1/lib:/usr/local/cuda-12.1/lib64:$LD_LIBRARY_PATH"
override-build: |
# Add NVIDIA repository key and update the package list
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
dpkg -i cuda-keyring_1.0-1_all.deb
apt-get -yq update

# Install CUDA toolkit
apt-get -yq install --no-install-recommends cuda-keyring=1.0-1 cuda-compat-12-1=530.30.02-1 cuda-cudart-12-1=12.1.55-1 cuda-toolkit-12-1-config-common=12.1.105-1 cuda-toolkit-12-config-common=12.3.52-1 cuda-toolkit-config-common=12.3.52-1

# Copy cuda libs
mkdir -p $CRAFT_PART_INSTALL/usr/local
cp -a /usr/local/cuda-12.1 $CRAFT_PART_INSTALL/usr/local/

# Copy dpkg and apt information to the final image
mkdir -p $CRAFT_PART_INSTALL/var/lib/dpkg
cp -a /var/lib/dpkg/* $CRAFT_PART_INSTALL/var/lib/dpkg/

mkdir -p $CRAFT_PART_INSTALL/var/lib/apt/lists
cp -a /var/lib/apt/lists/* $CRAFT_PART_INSTALL/var/lib/apt/lists/

mkdir -p $CRAFT_PART_INSTALL/etc/apt
cp -a /etc/apt/sources.list.d $CRAFT_PART_INSTALL/etc/apt/
cp -a /etc/apt/trusted.gpg* $CRAFT_PART_INSTALL/etc/apt/

# Clean up the apt cache
apt-get clean
rm -rf /var/lib/apt/lists/*

# Setup poetry
pip install --no-cache-dir poetry==1.7.1 vllm==0.4.2
poetry config virtualenvs.create false

# Install the kserve package, this specific server package, and their dependencies.
mkdir -p ./python_env_builddir
cp -rf $CRAFT_PROJECT_DIR/dummy_pyproject.toml ./python_env_builddir/pyproject.toml
(cd python_env_builddir && poetry install --no-interaction --no-root)

# Promote the packages we've installed from the local env to the primed image
mkdir -p $CRAFT_PART_INSTALL/usr/local/lib/python3.10/dist-packages
cp -fr /usr/local/lib/python3.10/dist-packages/* $CRAFT_PART_INSTALL/usr/local/lib/python3.10/dist-packages/

mkdir -p $CRAFT_PART_INSTALL/usr/local/share
cp -fr /usr/local/share/* $CRAFT_PART_INSTALL/usr/local/share/

# Ensure `python` is an executable command in our primed image by making
# a symbolic link
mkdir -p $CRAFT_PART_INSTALL/usr/bin/
ln -s /usr/bin/python3.10 $CRAFT_PART_INSTALL/usr/bin/python

rm -rf /root/.cache


# Copy licenses
third-party:
plugin: nil
after: [python]
source: https://github.com/kserve/kserve.git
source-subdir: python
source-tag: v0.13.0
override-build: |
cp -fr third_party/* ${CRAFT_PART_INSTALL}/third_party
56 changes: 56 additions & 0 deletions huggingfaceserver/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import random
import pytest
import string
import subprocess

from charmed_kubeflow_chisme.rock import CheckRock


@pytest.mark.abort_on_fail
def test_rock():
"""Test rock."""
check_rock = CheckRock("rockcraft.yaml")
rock_image = check_rock.get_name()
rock_version = check_rock.get_version()
LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}"

# assert we have the expected files
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /usr/local/lib/python3.10/dist-packages/huggingfaceserver",
],
check=True,
)
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /usr/local/lib/python3.10/dist-packages/kserve",
],
check=True,
)
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /third_party",
],
check=True,
)
54 changes: 54 additions & 0 deletions huggingfaceserver/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = pack, export-to-docker, sanity, integration

[testenv]
setenv =
PYTHONPATH={toxinidir}
PYTHONBREAKPOINT=ipdb.set_trace
CHARM_REPO=https://github.com/canonical/kserve-operators.git
CHARM_BRANCH=main
LOCAL_CHARM_DIR=charm_repo

[testenv:pack]
passenv = *
allowlist_externals =
rockcraft
commands =
rockcraft pack

[testenv:export-to-docker]
passenv = *
allowlist_externals =
bash
skopeo
yq
commands =
# pack rock and export to docker
bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \
VERSION=$(yq eval .version rockcraft.yaml) && \
ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \
ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \
DOCKER_IMAGE=$NAME:$VERSION && \
echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \
skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE'

[testenv:sanity]
passenv = *
deps =
pytest
charmed-kubeflow-chisme
commands =
# run rock tests
pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests

[testenv:integration]
passenv = *
allowlist_externals =
echo
commands =
# TODO: Implement integration tests here
echo "WARNING: This is a placeholder test - no test is implemented here."
Loading