Skip to content

Commit

Permalink
Merge pull request #54 from michaelfeil/docker-dependency-update
Browse files Browse the repository at this point in the history
update dockerfile and tests
  • Loading branch information
michaelfeil authored Jan 7, 2024
2 parents 7556042 + 8acd414 commit 2799105
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 671 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release_docker_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
# We can only build for the intersection of platforms supported by
# QEMU and base python image, for now build only for
# linux/amd64 and linux/arm64
cache-from: type=registry,ref=${{ env.LATEST_TAG }}
platforms: linux/amd64,linux/arm64
tags: ${{ env.LATEST_TAG }},${{ env.VERSION_TAG }}
push: true
2 changes: 0 additions & 2 deletions libs/infinity_emb/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.venv
tests
**/*_cache
Dockerfile
**/__pycache__
34 changes: 23 additions & 11 deletions libs/infinity_emb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Use the Python base image
FROM nvidia/cuda:11.8.0-base-ubuntu22.04 AS base
FROM nvidia/cuda:12.1.0-base-ubuntu22.04 AS base

ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
Expand All @@ -18,11 +16,11 @@ ENV PYTHONUNBUFFERED=1 \

RUN apt-get update && apt-get install python3.10 curl -y
# python3.10-venv
WORKDIR /app

FROM base as builder

# Set the working directory for the app
WORKDIR /app

# Define the version of Poetry to install (default is 1.6.1)
# Define the directory to install Poetry to (default is /opt/poetry)
Expand All @@ -38,20 +36,34 @@ ENV PATH=$POETRY_HOME/bin:$PATH
RUN echo "Poetry version:" && poetry --version

# Copy the rest of the app source code (this layer will be invalidated and rebuilt whenever the source code changes)
COPY poetry.lock poetry.toml pyproject.toml README.md .
COPY poetry.lock poetry.toml pyproject.toml README.md /app/
# Install dependencies only
RUN poetry install --no-interaction --no-ansi --no-root --extras all --without lint,test
COPY infinity_emb infinity_emb

# Install dependencies and project
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi --extras all
# Install dependency with infinity_emb package
RUN poetry install --no-interaction --no-ansi --extras all --without lint,test
# remove cache
RUN poetry cache clear pypi --all

FROM builder as testing
# install lint and test dependencies
RUN poetry install --no-interaction --no-ansi --extras all
# lint
RUN poetry run ruff .
RUN poetry run black --check .
RUN poetry run mypy .
# pytest
COPY tests tests
RUN poetry run python -m pytest -x
# write a file
RUN echo "all tests passed" > "test_results.txt"

# Use a multi-stage build -> production version
from base AS production
FROM base AS production

COPY --from=builder /app /app
WORKDIR /app
# force testing stage to run
COPY --from=testing /app/test_results.txt /app/test_results.txt

ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache/torch
ENV PATH=/app/.venv/bin:$PATH
Expand Down
1,218 changes: 579 additions & 639 deletions libs/infinity_emb/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/infinity_emb/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "infinity_emb"
version = "0.0.16"
version = "0.0.17"
description = "Infinity is a high-throughput, low-latency REST API for serving vector embeddings, supporting a wide range of sentence-transformer models and frameworks."
authors = ["michaelfeil <[email protected]>"]
license = "MIT"
Expand Down
6 changes: 4 additions & 2 deletions libs/infinity_emb/tests/end_to_end/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def _post_batch(inputs):
cosine_sim = np.dot(r, e) / (np.linalg.norm(e) * np.linalg.norm(r))
assert cosine_sim > 0.95
np.testing.assert_almost_equal(
np.array(responses), np.array(encodings), decimal=0
np.array(responses), np.array(encodings), decimal=3
)
assert time_api / time_st < 2.5

Expand All @@ -93,7 +93,9 @@ async def embedding_verify(client, model_base, prefix, model_name):
want_embeddings = model_base.encode(inp)

for embedding, st_embedding in zip(rdata["data"], want_embeddings):
np.testing.assert_almost_equal(embedding["embedding"], st_embedding)
np.testing.assert_almost_equal(
embedding["embedding"], st_embedding, decimal=3
)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions libs/infinity_emb/tests/end_to_end/test_ct2_sentence.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ async def test_model_route(client):

@pytest.mark.anyio
async def test_embedding(client, model_base, helpers):
helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)
await helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)


@pytest.mark.performance
@pytest.mark.anyio
async def test_batch_embedding(client, get_sts_bechmark_dataset, model_base, helpers):
helpers.util_batch_embedding(
await helpers.util_batch_embedding(
client=client,
sts_bechmark_dataset=get_sts_bechmark_dataset,
model_base=model_base,
Expand Down
4 changes: 2 additions & 2 deletions libs/infinity_emb/tests/end_to_end/test_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ async def test_model_route(client):

@pytest.mark.anyio
async def test_embedding(client, model_base, helpers):
helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)
await helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)


@pytest.mark.performance
@pytest.mark.anyio
async def test_batch_embedding(client, get_sts_bechmark_dataset, model_base, helpers):
helpers.util_batch_embedding(
await helpers.util_batch_embedding(
client=client,
sts_bechmark_dataset=get_sts_bechmark_dataset,
model_base=model_base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ async def test_model_route(client):

@pytest.mark.anyio
async def test_embedding(client, model_base, helpers):
helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)
await helpers.embedding_verify(client, model_base, prefix=PREFIX, model_name=MODEL)


@pytest.mark.performance
@pytest.mark.anyio
async def test_batch_embedding(client, get_sts_bechmark_dataset, model_base, helpers):
helpers.util_batch_embedding(
await helpers.util_batch_embedding(
client=client,
sts_bechmark_dataset=get_sts_bechmark_dataset,
model_base=model_base,
Expand Down
4 changes: 2 additions & 2 deletions libs/infinity_emb/tests/unit_test/inference/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def _pretrained_model_score(
("sentence-transformers/all-MiniLM-L6-v2", 82.03, "default"),
("sentence-transformers/all-MiniLM-L6-v2", 81.73, "int8"),
("sentence-transformers/all-MiniLM-L6-v2", 82.03, "default"),
("BAAI/bge-small-en-v1.5", 86.03, None),
("BAAI/bge-small-en-v1.5", 86.03, "int8"),
("BAAI/bge-small-en-v1.5", 86.00, None),
("BAAI/bge-small-en-v1.5", 86.00, "int8"),
],
)
def test_bert(get_sts_bechmark_dataset, model, score, compute_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from infinity_emb.transformer.classifier.torch import SentenceClassifier


def test_classifier():
model = SentenceClassifier("SamLowe/roberta-base-go_emotions")
pipe = pipeline(
model="SamLowe/roberta-base-go_emotions", task="text-classification"
)
def test_classifier(model_name: str = "SamLowe/roberta-base-go_emotions"):
model = SentenceClassifier(model_name)
pipe = pipeline(model=model_name, task="text-classification")

sentences = ["This is awesome.", "I am depressed."]

Expand All @@ -30,6 +28,8 @@ def test_classifier():

for pred_orig, pred in zip(preds_orig, preds):
assert len(pred_orig) == len(pred)
for pred_orig_i, pred_i in zip(pred_orig, pred):
assert pred_orig_i["label"] == pred_i["label"]
assert abs(pred_orig_i["score"] - pred_i["score"]) < 0.1
for pred_orig_i, pred_i in zip(pred_orig[:5], pred[:5]):
assert abs(pred_orig_i["score"] - pred_i["score"]) < 0.05

if pred_orig_i["score"] > 0.005:
assert pred_orig_i["label"] == pred_i["label"]

0 comments on commit 2799105

Please sign in to comment.