Skip to content

Commit

Permalink
Merge branch 'uv' into 'master'
Browse files Browse the repository at this point in the history
use uv

See merge request pitchtrack/pitch-detectors!67
  • Loading branch information
tandav committed Nov 24, 2024
2 parents 1df3679 + b43d538 commit 67738e7
Show file tree
Hide file tree
Showing 8 changed files with 2,209 additions and 232 deletions.
30 changes: 15 additions & 15 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
stages:
# - build
- test

variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
RUFF_CACHE_DIR: "$CI_PROJECT_DIR/.cache/ruff_cache"
MYPY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/mypy_cache"

cache:
key: $CI_PROJECT_NAME
paths:
- .cache/


test:
stage: test
needs: []
tags:
- u60-docker-gpu
image: tandav/pitch-detectors:12.4.1-cudnn-devel-ubuntu22.0-python3.12
- u60
- docker
- gpu
image: tandav/pitch-detectors:12.6.2-cudnn-devel-ubuntu24.04-python3.12
cache:
key: $CI_PROJECT_NAME
paths:
- .cache/
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
RUFF_CACHE_DIR: "$CI_PROJECT_DIR/.cache/ruff_cache"
MYPY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/mypy_cache"
PITCH_DETECTORS_SPICE_MODEL_PATH: /models/spice_model
PITCH_DETECTORS_PENN_CHECKPOINT_PATH: /models/fcnf0++.pt
script:
Expand All @@ -38,6 +35,9 @@ test:

lint:
stage: test
tags:
- u61
- docker
needs: []
image: python:3.12@sha256:fce9bc7648ef917a5ab67176cf1c7eb41b110452e259736144bc22f32f3aa622
variables:
Expand Down
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,3 @@ repos:
hooks:
- id: mypy
additional_dependencies: [types-redis, types-tabulate, pydantic]

# - repo: https://github.com/RobertCraigie/pyright-python
# rev: v1.1.369
# hooks:
# - id: pyright
47 changes: 31 additions & 16 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
version: '3'
dotenv: ['.env']
vars:
BASE_IMAGE: tandav/pitch-detectors-base:12.4.1-cudnn-devel-ubuntu22.0-python3.12
IMAGE: tandav/pitch-detectors:12.4.1-cudnn-devel-ubuntu22.0-python3.12

env:
UBUNTU_VERSION: 24.04
CUDA_VERSION: 12.6.2
PYTHON_VERSION: 3.12
UV_IMAGE: ghcr.io/astral-sh/uv:0.5.4@sha256:5436c72d52c9c0d011010ce68f4c399702b3b0764adcf282fe0e546f20ebaef6
BASE_IMAGE_CUDA_SHA256: 431b2307f69f41ca51503a6103be3b5c52dcfad18b201af7f12349a0cca35a4e
BASE_IMAGE_CUDA: nvidia/cuda:{{.CUDA_VERSION}}-cudnn-devel-ubuntu{{.UBUNTU_VERSION}}@sha256:{{.BASE_IMAGE_CUDA_SHA256}}
BASE_IMAGE: tandav/pitch-detectors-base:{{.CUDA_VERSION}}-cudnn-devel-ubuntu{{.UBUNTU_VERSION}}-python{{.PYTHON_VERSION}}
IMAGE: tandav/pitch-detectors:{{.CUDA_VERSION}}-cudnn-devel-ubuntu{{.UBUNTU_VERSION}}-python{{.PYTHON_VERSION}}
MODEL_PATH_SPICE: /mnt/sg8tb1/downloads-archive/libmv-data/spice_model
MODEL_PATH_PENN: /mnt/sg8tb1/downloads-archive/libmv-data/fcnf0++.pt
tasks:
build-base:
cmd: docker build --tag {{.BASE_IMAGE}} --file docker/base.dockerfile .
cmd: >
docker build
--build-arg BASE_IMAGE_CUDA=$BASE_IMAGE_CUDA
--tag $BASE_IMAGE
--file docker/base.dockerfile .
push-base:
cmd: docker push {{.BASE_IMAGE}}

build:
cmd: docker build --build-arg="BASE_IMAGE={{.BASE_IMAGE}}" --tag {{.IMAGE}} --file docker/pitch-detectors.dockerfile .
deps: [build-base]
cmd: >
docker build
--build-arg="BASE_IMAGE=$BASE_IMAGE"
--build-arg="UV_IMAGE=$UV_IMAGE"
--tag $IMAGE
--file docker/pitch-detectors.dockerfile .
push:
cmd: docker push {{.IMAGE}}
cmd: docker push $IMAGE

test:
deps: [build]
cmd: >
docker run --rm -t --gpus all
-v /media/tandav/sg8tb1/downloads-archive/libmv-data/spice_model:/spice_model:ro
-v /media/tandav/sg8tb1/downloads-archive/libmv-data/fcnf0++.pt:/fcnf0++.pt:ro
{{.IMAGE}}
-v $MODEL_PATH_SPICE:/spice_model:ro
-v $MODEL_PATH_PENN:/fcnf0++.pt:ro
$IMAGE
uv run
pytest -v
test-no-docker:
cmd: pytest -v

freeze:
cmd: docker run --rm -t --gpus all {{.IMAGE}} /venv/bin/pip freeze > freeze.txt
cmd: uv run pytest -v

bumpver:
desc: 'Bump version. Pass --<part>. Usage example: task bumpver -- --minor'
cmds:
- bumpver update --no-fetch {{.CLI_ARGS}}
- uv run bumpver update --no-fetch {{.CLI_ARGS}}

evaluation:
deps: [build]
Expand All @@ -48,4 +63,4 @@ tasks:
python -m pitch_detectors.evaluation
table:
cmd: python -m pitch_detectors.evaluation.table
cmd: uv run python -m pitch_detectors.evaluation.table
22 changes: 10 additions & 12 deletions docker/base.dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04@sha256:0a1cb6e7bd047a1067efe14efdf0276352d5ca643dfd77963dab1a4f05a003a4

ARG BASE_IMAGE_CUDA=scratch
FROM ${BASE_IMAGE_CUDA}
# https://github.com/NVIDIA/nvidia-docker/wiki/Usage
# https://github.com/NVIDIA/nvidia-docker/issues/531
ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
ENV DEBIAN_FRONTEND=noninteractive

ARG PYTHON_VERSION=3.12

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get install -y python${PYTHON_VERSION}-dev python${PYTHON_VERSION}-venv libsndfile-dev libasound-dev portaudio19-dev

# this is only need for crepe @ git+https://github.com/tandav/crepe
RUN apt-get install -y git

# https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
ENV VIRTUAL_ENV=/venv
RUN python${PYTHON_VERSION} -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
apt-get install -y --no-install-recommends \
python${PYTHON_VERSION}-dev \
libsndfile-dev \
libasound-dev \
portaudio19-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
26 changes: 16 additions & 10 deletions docker/pitch-detectors.dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
ARG BASE_IMAGE=scratch
ARG UV_IMAGE=ghcr.io/astral-sh/uv:latest
FROM ${UV_IMAGE} AS uv

WORKDIR /app
COPY pyproject.toml .
ENV PIP_INDEX_URL=https://pypi.tandav.me/index/
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip setuptools wheel && \
pip install .[dev]
FROM ${BASE_IMAGE} AS base

COPY --from=uv /uv /uvx /bin/

WORKDIR /app
COPY pitch_detectors /app/pitch_detectors

RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-deps .
ENV UV_LINK_MODE=copy \
UV_FROZEN=1

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

COPY tests /app/tests
COPY scripts/ /app/scripts
COPY data /app/data

ENV PATH="/app/.venv/bin:$PATH"
152 changes: 0 additions & 152 deletions freeze.txt

This file was deleted.

Loading

0 comments on commit 67738e7

Please sign in to comment.