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

feat/uv package manager #74

Merged
merged 10 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v2
with:
python-version: 3.12
- run: pip install uv
- run: uv pip install --system -r requirements-dev.txt
- run: ruff check .
- run: ruff format --check --diff .
version: "0.4.4"
enable-cache: true
- run: uv python install 3.12
- run: uv sync --extra dev
- run: uv run ruff check .
- run: uv run ruff format --check --diff .
16 changes: 10 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ on:
pull_request:
jobs:
pytest:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v2
with:
python-version: 3.12
- run: pip install uv
- run: uv pip install --no-cache --system -r requirements-dev.txt
version: "0.4.4"
enable-cache: true
- run: uv python install 3.12
- run: uv sync --extra dev
# TODO: figure out why `pytest` doesn't discover tests in `faster_whisper_server` directory by itself
- run: pytest faster_whisper_server/* tests
- run: uv run pytest src/faster_whisper_server/* tests
18 changes: 11 additions & 7 deletions Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3.12 python3.12-distutils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:0.4.4 /uv /bin/uv
WORKDIR /root/faster-whisper-server
COPY requirements.txt .
RUN --mount=from=ghcr.io/astral-sh/uv:latest,source=/uv,target=/bin/uv \
uv pip install --system --python 3.12 --no-cache -r requirements.txt
COPY ./faster_whisper_server ./faster_whisper_server
ENV WHISPER__MODEL=Systran/faster-whisper-medium.en
# https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
COPY ./src ./pyproject.toml ./uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen
ENV WHISPER__MODEL=Systran/faster-whisper-small
ENV WHISPER__INFERENCE_DEVICE=cpu
ENV WHISPER__COMPUTE_TYPE=int8
ENV UVICORN_HOST=0.0.0.0
ENV UVICORN_PORT=8000
CMD ["uvicorn", "faster_whisper_server.main:app"]
CMD ["uv", "run", "uvicorn", "faster_whisper_server.main:app"]
17 changes: 11 additions & 6 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3.12 python3.12-distutils && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:0.4.4 /uv /bin/uv
WORKDIR /root/faster-whisper-server
COPY requirements.txt .
RUN --mount=from=ghcr.io/astral-sh/uv:latest,source=/uv,target=/bin/uv \
uv pip install --system --python 3.12 --no-cache -r requirements.txt
COPY ./faster_whisper_server ./faster_whisper_server
ENV WHISPER__MODEL=Systran/faster-distil-whisper-large-v3
# https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
COPY ./src ./pyproject.toml ./uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen
ENV WHISPER__MODEL=Systran/faster-whisper-large-v3
ENV WHISPER__INFERENCE_DEVICE=auto
ENV UVICORN_HOST=0.0.0.0
ENV UVICORN_PORT=8000
CMD ["uvicorn", "faster_whisper_server.main:app"]
CMD ["uv", "run", "uvicorn", "faster_whisper_server.main:app"]
12 changes: 0 additions & 12 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ tasks:
sources:
- Dockerfile.*
- faster_whisper_server/*.py
pip-compile:
cmds:
- uv pip compile --override overrides.txt pyproject.toml {{.CLI_ARGS}} > requirements.txt
- uv pip compile --override overrides.txt --extra dev pyproject.toml {{.CLI_ARGS}} > requirements-dev.txt
- uv pip compile --override overrides.txt --all-extras pyproject.toml {{.CLI_ARGS}} > requirements-all.txt
sources:
- pyproject.toml
pip-sync:
cmds:
- uv pip sync requirements-all.txt
sources:
- requirements-all.txt
create-multi-arch-builder: docker buildx create --name main --driver=docker-container
docker-build:
cmds:
Expand Down
13 changes: 11 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: https://docs.astral.sh/uv/guides/integration/docker/#configuring-watch-with-docker-compose
# NOTE: arm images haven't been tested
services:
faster-whisper-server-cuda:
Expand All @@ -9,7 +10,7 @@ services:
- linux/amd64
- linux/arm64
volumes:
- ~/.cache/huggingface:/root/.cache/huggingface
- hugging_face_cache:/root/.cache/huggingface
restart: unless-stopped
ports:
- 8000:8000
Expand All @@ -22,6 +23,12 @@ services:
reservations:
devices:
- capabilities: ["gpu"]
# If you have CDI feature enabled use the following instead
# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html
# https://docs.docker.com/reference/cli/dockerd/#enable-cdi-devices
# - driver: cdi
# device_ids:
# - nvidia.com/gpu=all
faster-whisper-server-cpu:
image: fedirz/faster-whisper-server:latest-cpu
build:
Expand All @@ -31,11 +38,13 @@ services:
- linux/amd64
- linux/arm64
volumes:
- ~/.cache/huggingface:/root/.cache/huggingface
- hugging_face_cache:/root/.cache/huggingface
restart: unless-stopped
ports:
- 8000:8000
develop:
watch:
- path: faster_whisper_server
action: rebuild
volumes:
hugging_face_cache:
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{ nixpkgs, flake-utils, ... }:
Expand All @@ -11,6 +12,8 @@
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
# `cudnn_8_9` is marked as broken but still seems to work as before
config.allowBroken = true;
};
in
{
Expand Down
Empty file removed overrides.txt
Empty file.
38 changes: 21 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
[project]
name = "faster-whisper-server"
version = "0.1.0"
requires-python = ">=3.12,<3.13"
dependencies = [
"pydantic",
"fastapi",
"uvicorn",
"python-multipart",
"soundfile",
"pydantic-settings",
"pydantic==2.9.0",
"fastapi==0.113.0",
"uvicorn==0.30.6",
"python-multipart==0.0.9",
"soundfile==0.12.1",
"pydantic-settings==2.4.0",
"numpy<2.0.0",
"faster-whisper==1.0.3",
"huggingface-hub",
"httpx-sse",
"httpx",
"gradio",
"openai",
"huggingface-hub==0.24.6",
"httpx-sse==0.4.0",
"httpx==0.27.2",
"gradio==4.42.0",
"openai==1.43.1",
]

[project.optional-dependencies]
client = [
"keyboard",
"keyboard==0.13.5",
]
dev = [
"ruff==0.5.3",
"pytest",
"webvtt-py",
"srt",
"pytest==8.3.2",
"webvtt-py==0.5.1",
"srt==3.5.3",
"basedpyright==1.13.0",
"pytest-xdist"
"pytest-xdist==3.6.1",
"pytest-asyncio>=0.24.0",
]

other = ["youtube-dl @ git+https://github.com/ytdl-org/youtube-dl.git@37cea84f775129ad715b9bcd617251c831fcc980", "aider-chat==0.39.0"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

# https://docs.astral.sh/ruff/configuration/
[tool.ruff]
Expand Down
Loading