Commit 4a81091f authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Make CI tests light: defer torch/demucs to a prod-only requirements file

CI's test job was installing torch + demucs (a neural net stem-separation
model) on every single push even though nothing in the test suite calls the
real separator - test_remix.py mocks render_remix_sync entirely, and
remix_engine.py's own detect_key/sidechain/style-preset tests only need
librosa/scipy/numpy/pedalboard, not torch. That's most of what was making
the pipeline slow (torch alone is a large download+install, on top of the
memory pressure that caused the earlier 5min stall).

- src/services/remix_engine.py: `import torch` and the mkldnn tweak move
  from module level into _get_separator(), alongside the already-lazy demucs
  import. The module (and everything depending on it, like the /remix
  router) now imports cleanly with neither installed.
- requirements.txt: demucs removed. numpy/scipy/librosa/soundfile/pedalboard
  stay - real libraries, but not the heavy part, and needed for the audio-
  math tests that do run in CI.
- requirements-remix.txt (new): just demucs, install torch CPU-only before
  it. Only installed by deploy.sh (prod), never in CI.
- .gitlab-ci.yml test job: drops the torch install step entirely.

Verified locally: uninstalled torch+demucs from the dev venv, app still
imports and all 104 tests still pass in ~3s.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 4a6db62c
Pipeline #1013 canceled with stage
in 17 minutes and 27 seconds
......@@ -17,9 +17,9 @@ test:
image: python:3.10-slim
before_script:
- apt-get update -qq && apt-get install -y -qq --no-install-recommends ffmpeg git libsndfile1
# CPU-only torch first - this repo has no GPU anywhere, and the default PyPI
# wheel is a multi-GB CUDA build that would blow out CI time/disk for nothing.
- pip install --index-url https://download.pytorch.org/whl/cpu torch
# No torch/demucs here on purpose - requirements-remix.txt (the heavy stem-separation
# model) is prod-only. Nothing in the test suite needs the real separator; see
# remix_engine.py's _get_separator() and requirements-remix.txt for why that's safe.
- pip install --prefer-binary -q -r requirements.txt
script:
- PYTHONPATH=. pytest tests/ -v
......
......@@ -67,6 +67,9 @@ source "$VENV_DIR/bin/activate"
# build. pip skips this entirely on repeat runs once the CPU wheel is already satisfied.
pip install --prefer-binary -q --index-url https://download.pytorch.org/whl/cpu torch
pip install --prefer-binary -q -r requirements.txt
# The real stem-separation model - prod only, CI's test job never installs this (see
# requirements-remix.txt for why).
pip install --prefer-binary -q -r requirements-remix.txt
# --- 4. .env - only (re)written when the CI job actually supplied prod secrets, so a manual
# redeploy with no secrets in the environment never wipes a working .env ------------------
......
# The actual stem-separation model - the heavy part of the remix engine. Installed only on
# prod (see deploy.sh), never in CI: nothing in the test suite calls the real separator
# (test_remix.py mocks render_remix_sync entirely; remix_engine.py imports torch/demucs
# lazily inside _get_separator(), not at module level, so the app and its test suite import
# fine without either of these present).
#
# Install torch CPU-only *before* this file, this VPS has no GPU:
# pip install torch --index-url https://download.pytorch.org/whl/cpu
# Otherwise pip pulls the default CUDA wheel (multiple GB, useless here).
demucs>=4.0.1
......@@ -23,14 +23,13 @@ tgcrypto>=1.2.5
pyjwt>=2.8.0
alembic>=1.13.0
# Remix engine. Install torch CPU-only *before* this file, this VPS has no GPU:
# pip install torch --index-url https://download.pytorch.org/whl/cpu
# Otherwise pip pulls the default CUDA wheel (multiple GB, useless here).
# numpy is pinned <2: this VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all,
# and numpy>=2's default wheels require the x86-64-v2 baseline and segfault/RuntimeError
# on import here. 1.26.4 is what the rest of this project already runs on successfully.
# Remix engine's audio-math helpers (key detection, sidechain envelope, style presets) -
# real libraries, but nowhere near as heavy as the stem-separation model in
# requirements-remix.txt, and everything that needs these is covered by tests/test_remix_engine.py.
# numpy is pinned <2: this VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all, and
# numpy>=2's default wheels require the x86-64-v2 baseline and segfault/RuntimeError on
# import here. 1.26.4 is what the rest of this project already runs on successfully.
numpy==1.26.4
scipy==1.13.1
demucs>=4.0.1
librosa>=0.10.2
soundfile>=0.12.1
......@@ -9,7 +9,6 @@ import google.generativeai as genai
import librosa
import numpy as np
import soundfile as sf
import torch
from pedalboard import (
Compressor,
Distortion,
......@@ -27,12 +26,6 @@ from src.core.database import LibrarySong, Post, RemixJob, SessionLocal
from src.services import storage
from src.services.music_identification import identify_audio
# This VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all, which makes PyTorch's
# oneDNN (MKLDNN) backend fail with "could not create a primitive" on demucs's real-sized
# convolutions (a tiny toy conv works fine, which is what makes this easy to miss). Disabling
# MKLDNN falls back to PyTorch's plain conv kernels, which are slower but actually run here.
torch.backends.mkldnn.enabled = False
if GEMINI_API_KEY:
genai.configure(api_key=GEMINI_API_KEY)
......@@ -64,9 +57,20 @@ _separator_lock = threading.Lock()
def _get_separator():
"""torch/demucs are only imported here, not at module level - this whole module (and
everything that depends on it, like the /remix router) stays importable without those
heavy deps installed as long as a real remix is never actually rendered. Real prod
deploys still install them (see requirements-remix.txt); CI's test job doesn't."""
global _separator
if _separator is None:
import torch
from demucs.api import Separator
# This VPS's virtualized CPU exposes no SSE3/SSE4/AVX at all, which makes PyTorch's
# oneDNN (MKLDNN) backend fail with "could not create a primitive" on demucs's
# real-sized convolutions (a tiny toy conv works fine, which is what makes this easy
# to miss). Disabling MKLDNN falls back to plain conv kernels, slower but functional.
torch.backends.mkldnn.enabled = False
_separator = Separator(model="htdemucs")
return _separator
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment