Skip to content

Commit

Permalink
Merge pull request #274 from michaelfeil/ci-nightly
Browse files Browse the repository at this point in the history
add nightly and pypi pull
  • Loading branch information
michaelfeil authored Jun 20, 2024
2 parents bb7e700 + c9fb19b commit b4dab11
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
branches:
- main
- dev
schedule: # nightly
- cron: '0 0 * * *'
workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI

# If another push to the same PR or branch happens while this workflow is still running,
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.11
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release_modal_com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
unused:
required: false
type: string
description: "From which folder this pipeline executes"
description: "To be replaced."

jobs:
modal:
Expand Down Expand Up @@ -46,4 +46,5 @@ jobs:
- name: Modal Deploy
run: |
cd infra/modal
INFINITY_VERSION=$ {{ steps.get-latest-tag.outputs.tag }}
modal deploy --tag ${{ steps.get-latest-tag.outputs.tag }}-github-ci --env prod webserver.py
19 changes: 15 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
type: boolean
default: true


env:
POETRY_VERSION: "1.7.1"

Expand All @@ -23,13 +24,14 @@ jobs:
strategy:
# fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, ] # macos-latest
os: [ubuntu-latest, windows-latest] # macos-latest
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
coverage_tests: ["unit_test", "end_to_end"]
source: ["local", "pypi"]
exclude:
# Exclude unit tests on macOS due to compatibility issues
- python-version: "3.9"
Expand All @@ -48,7 +50,7 @@ jobs:


runs-on: ${{ matrix.os }}
name: Py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.coverage_tests }}
name: Py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.coverage_tests }}-${{ matrix.source }}
steps:
- name: Free Disk Space
uses: jlumbroso/[email protected]
Expand All @@ -70,11 +72,20 @@ jobs:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: ${{ inputs.working-directory }}
cache-key: infinity-emb-test-${{ matrix.coverage_tests }}
cache-key: infinity-emb-test-${{ matrix.coverage_tests }}-${{ matrix.source }}

- name: Install dependencies
- name: Install dependencies from local
# only if source is local
if: matrix.source == 'local'
shell: bash
run: poetry install --extras all --with test

- name: Install from PyPI
# only if source is pypi
if: matrix.source == 'pypi'
run: |
poetry install --only test
poetry run pip install infinity-emb[all] --upgrade
- name: Run Pytest Coverage
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ asyncio.run(classifier(array["SamLowe/roberta-base-go_emotions"]))

Example models:
- [ProsusAI/finbert](https://huggingface.co/ProsusAI/finbert)
- [SamLowe/roberta-base-go_emotions](SamLowe/roberta-base-go_emotions)
- [SamLowe/roberta-base-go_emotions](https://huggingface.co/SamLowe/roberta-base-go_emotions)

## Integrations:
- [Serverless deployments at Runpod](https://github.com/runpod-workers/worker-infinity-embedding)
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmarks/simple_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def encode_sentence_transformer(text: list[str]):


async def encode_infinity(text: list[str]):
return (await engine.embed(text))[0]
return (await engine.embed(sentences=text))[0]


@asynccontextmanager
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/python_engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ asyncio.run(classifier(array["SamLowe/roberta-base-go_emotions"]))

Example models:
- [ProsusAI/finbert](https://huggingface.co/ProsusAI/finbert)
- [SamLowe/roberta-base-go_emotions](SamLowe/roberta-base-go_emotions)
- [SamLowe/roberta-base-go_emotions](https://huggingface.co/SamLowe/roberta-base-go_emotions)

43 changes: 27 additions & 16 deletions infra/modal/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"""

from modal import App, Image, build, enter, method
import os

image = Image.from_registry("michaelf34/infinity:0.0.45").entrypoint([]).pip_install("timm")
INFINITY_VERSION = os.environ.get("INFINITY_VERSION", "0.0.46")
image = Image.from_registry(f"michaelf34/infinity:{INFINITY_VERSION}").entrypoint([])

app = App("infinity-functional", image=image)

Expand All @@ -15,6 +17,7 @@

class BaseInfinityModel:
"""Base class for the infinity model."""

def _get_array(self):
return AsyncEngineArray.from_args(
[
Expand All @@ -39,10 +42,10 @@ async def enter(self):
@app.cls(gpu="any", allow_concurrent_inputs=500)
class InfinityModal(BaseInfinityModel):
"""Model for embedding text (via clip or Bert) and images (via clip) ."""

def __init__(self, model_id: tuple[str]) -> None:
self.model_id = model_id
super().__init__()


@method()
async def embed(self, sentences: list[str], model: str | int = 0):
Expand All @@ -68,24 +71,32 @@ async def classify(self, sentences: list[str], model: str | int = 0):
classes, usage = await engine.classify(sentences=sentences)
return classes


@app.local_entrypoint()
def main():
model_id=(
"jinaai/jina-clip-v1",
"michaelfeil/bge-small-en-v1.5",
"mixedbread-ai/mxbai-rerank-xsmall-v1",
"philschmid/tiny-bert-sst2-distilled",
)
deployment = InfinityModal(
model_id=model_id
model_id = (
"jinaai/jina-clip-v1",
"michaelfeil/bge-small-en-v1.5",
"mixedbread-ai/mxbai-rerank-xsmall-v1",
"philschmid/tiny-bert-sst2-distilled",
)
deployment = InfinityModal(model_id=model_id)
embeddings_1 = deployment.embed.remote(sentences=["hello world"], model=model_id[1])
embeddings_2 = deployment.image_embed.remote(urls=["http://images.cocodataset.org/val2017/000000039769.jpg"], model=model_id[0])
embeddings_2 = deployment.image_embed.remote(
urls=["http://images.cocodataset.org/val2017/000000039769.jpg"],
model=model_id[0],
)

rerankings_1 = deployment.rerank.remote(
query="Where is Paris?",
docs=["Paris is the capital of France.", "Berlin is a city in Europe."],
model=model_id[2],
)

classifications_1 = deployment.classify.remote(
sentences=["I feel great today!"], model=model_id[3]
)

rerankings_1 =deployment.rerank.remote(query="Where is Paris?", docs=["Paris is the capital of France.", "Berlin is a city in Europe."], model=model_id[2])

classifications_1 = deployment.classify.remote(sentences=["I feel great today!"], model=model_id[3])

print(
"Success, all tasks submitted! Embeddings:",
embeddings_1[0].shape,
Expand All @@ -94,4 +105,4 @@ def main():
rerankings_1,
"Classifications:",
classifications_1,
)
)
6 changes: 2 additions & 4 deletions infra/modal/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# CONFIG.
# Writing the configuration to a .env file to have the example in one file.
PORT = 7997
INFINITY_PIPY_VERSION = "0.0.45"
INFINITY_VERSION = os.environ.get("INFINITY_VERSION", "0.0.45")
pathlib.Path(".env").write_text(
f"""
# Auto-generated by webserver.py
Expand Down Expand Up @@ -44,9 +44,7 @@ def download_models():
# We'll start from a recommended Docker Hub image and install `infinity`.
image = (
Image.from_registry("nvidia/cuda:12.1.1-base-ubuntu22.04", add_python="3.11")
.pip_install(
f"infinity_emb[all,vision]=={INFINITY_PIPY_VERSION}"
)
.pip_install(f"infinity_emb[all]=={INFINITY_VERSION}")
.run_function(
download_models,
secrets=[
Expand Down
2 changes: 1 addition & 1 deletion libs/infinity_emb/tests/unit_test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_async_api_debug():
EngineArgs(engine=InferenceEngine.debugengine)
)
async with engine:
embeddings, usage = await engine.embed(sentences=sentences)
embeddings, usage = await engine.embed(sentences)
embeddings = np.array(embeddings)
assert usage == sum([len(s) for s in sentences])
assert embeddings.shape[0] == len(sentences)
Expand Down

0 comments on commit b4dab11

Please sign in to comment.