-
Notifications
You must be signed in to change notification settings - Fork 27
Migration & Upgrades
Refer to the CHANGELOG.md file in the repo
- This should provide the latest migration or upgrade information
This guide explains how to migrate the Chatterbox TTS FastAPI from pip to uv for better dependency management, faster installations, and improved PyTorch/CUDA compatibility.
Based on user feedback and testing, uv provides several advantages for this project:
- Better PyTorch/CUDA handling: Native support for PyTorch indexes and variants
- Faster installations: 25-40% faster than pip in benchmarks
- Superior dependency resolution: SAT-based resolver prevents conflicts
-
Git dependency support: Better handling of
chatterbox-tts
from GitHub - Cross-platform consistency: Environment markers handle CPU/GPU variants automatically
- Docker optimizations: Better caching and faster container builds
- FastAPI compatibility: Excellent support for FastAPI and Pydantic dependencies
The combination of FastAPI and uv provides:
- Faster builds: uv resolves FastAPI dependencies more efficiently
- Better type checking: Enhanced support for Pydantic and type hint libraries
- Cleaner environments: More reliable async dependency management
- Development speed: Faster dependency installation during development
Previous Problem: The original uv Docker implementations were failing because:
-
Missing CUDA Index:
pyproject.toml
only defined CPU PyTorch indexes - Incorrect Configuration: Assumed PyTorch would "auto-detect CUDA" (which doesn't work with uv)
- Complex Index Logic: Overly complicated platform markers that didn't work reliably
-
Missing Dependency:
resemble-perth
watermarker dependency was not explicitly included
Solution Implemented: The fixed uv Dockerfiles now:
- Explicit PyTorch Installation: Install PyTorch with correct CUDA/CPU versions first
-
Direct Index Usage: Use
uv pip install
with explicit--index-url
flags - Simplified Configuration: Removed complex pyproject.toml index configurations
-
Complete Dependencies: Added
resemble-perth
for watermarker functionality - FastAPI Optimization: Optimized for FastAPI and async dependencies
Fixed Commands:
# GPU version (Dockerfile.uv.gpu)
RUN uv venv --python 3.11 && \
uv pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124 && \
uv pip install resemble-perth && \
uv pip install "chatterbox-tts @ git+https://github.com/resemble-ai/chatterbox.git" && \
uv pip install fastapi uvicorn[standard] python-dotenv requests
# CPU version (Dockerfile.uv)
RUN uv venv --python 3.11 && \
uv pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu && \
uv pip install resemble-perth && \
uv pip install "chatterbox-tts @ git+https://github.com/resemble-ai/chatterbox.git" && \
uv pip install fastapi uvicorn[standard] python-dotenv requests
Common Error Fixed:
TypeError: 'NoneType' object is not callable
self.watermarker = perth.PerthImplicitWatermarker()
This was caused by missing resemble-perth
package that provides the watermarker functionality.
- Backup your current
.venv
directory (if using virtual environments) - Note your current Python version (
python --version
) - Save current package versions (
pip freeze > backup-requirements.txt
) - Check if you're using the Flask or FastAPI version (this guide assumes FastAPI)
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
pip install uv
-
Remove old virtual environment:
rm -rf .venv
-
Install dependencies with uv:
uv sync
-
Test the installation:
uv run python -c "import chatterbox; print('✓ chatterbox-tts installed')" uv run python -c "import torch; print(f'✓ PyTorch {torch.__version__} - CUDA: {torch.cuda.is_available()}')" uv run python -c "import fastapi; print(f'✓ FastAPI {fastapi.__version__}')"
-
Run the FastAPI server:
uv run uvicorn app.main:app --host 0.0.0.0 --port 4123 # or uv run main.py
-
Initialize uv project (if you want to customize):
uv init --no-readme --no-workspace
-
Add dependencies:
uv add "chatterbox-tts @ git+https://github.com/resemble-ai/chatterbox.git" uv add "torch>=2.0.0,<2.7.0" uv add "torchaudio>=2.0.0,<2.7.0" uv add "fastapi>=0.104.0" uv add "uvicorn[standard]>=0.24.0" uv add "pydantic>=2.0.0" uv add "python-dotenv>=1.0.0" uv add "requests>=2.28.0" --optional dev
The provided pyproject.toml
automatically handles PyTorch variants:
- Linux: Uses CUDA-enabled PyTorch
- macOS/Windows: Uses CPU-only PyTorch
- Manual override: Set environment variables if needed
UV_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu uv sync
UV_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu124 uv sync
-
Build with uv:
docker build -f Dockerfile.uv -t chatterbox-tts-uv .
-
Or use docker-compose:
docker-compose -f docker-compose.uv.yml up -d
-
GPU variant:
docker build -f Dockerfile.uv.gpu -t chatterbox-tts-uv-gpu .
# Health check
uv run python -c "
import requests
r = requests.get('http://localhost:4123/health')
print(f'Status: {r.status_code}')
print(r.json())
"
# Test FastAPI documentation
uv run python -c "
import requests
r = requests.get('http://localhost:4123/docs')
print(f'Docs available: {r.status_code == 200}')
"
# Test TTS generation
uv run python tests/test_api.py
# Time the installation
time uv sync --reinstall
# vs
time pip install -r requirements.txt
Old pip command | New uv command |
---|---|
pip install package |
uv add package |
pip install -r requirements.txt |
uv sync |
python script.py |
uv run script.py |
pip freeze |
uv pip freeze |
flask run --debug |
N/A (now FastAPI) |
python main.py |
uv run main.py |
# Start FastAPI development server
uv run uvicorn app.main:app --host 0.0.0.0 --port 4123 --reload
# Run with specific Python version
uv run --python 3.11 uvicorn app.main:app --reload
# Install development dependencies (basic tools)
uv sync
# Install test dependencies (for testing/contributing)
uv sync --group test
# Create/sync environment
uv sync
# Add new dependency
uv add numpy
# Remove dependency
uv remove numpy
# Update all dependencies
uv sync --upgrade
# Install dev dependencies (basic development tools)
uv sync
# Install test dependencies (for contributors/testing)
uv sync --group test
Update your CI/CD pipelines to use uv with FastAPI:
# GitHub Actions example
- name: Set up uv
uses: astral-sh/setup-uv@v2
- name: Install dependencies
run: uv sync
- name: Run tests
run: uv run python tests/test_api.py
- name: Test FastAPI endpoints
run: |
uv run uvicorn api:app --host 0.0.0.0 --port 4123 &
sleep 10
curl -f http://localhost:4123/health
curl -f http://localhost:4123/docs
-
CUDA compatibility:
# Clear cache and reinstall uv cache clean uv sync --reinstall
-
Git dependency issues:
# Force refresh git dependencies uv sync --refresh-package chatterbox-tts
-
Lock file conflicts:
# Regenerate lock file rm uv.lock uv sync
-
Python version mismatch:
# Use specific Python version uv python install 3.11 uv sync --python 3.11
-
FastAPI startup issues:
# Check FastAPI dependencies uv run python -c "import fastapi, uvicorn; print('FastAPI ready')" # Run with verbose logging uv run uvicorn api:app --log-level debug --reload
Expected improvements after migration:
- Installation speed: 25-40% faster
- Dependency resolution: More reliable, fewer conflicts
- Docker builds: 20-30% faster with better caching
- Development workflow: Faster environment creation
- PyTorch compatibility: Better handling of CUDA variants
- FastAPI performance: Better async dependency management
- Faster development cycles: uv's speed + FastAPI's auto-reload
- Better type checking: Enhanced IDE support for async functions
- Cleaner dependency trees: uv resolves FastAPI/Pydantic dependencies better
- Improved testing: Faster test environment setup
If you need to rollback to pip:
-
Restore backup:
pip install -r backup-requirements.txt
-
Remove uv files:
rm pyproject.toml uv.lock
-
Use original Docker files:
docker-compose -f docker-compose.yml up -d
Note: If you're rolling back from FastAPI to Flask, you'll need to restore the previous Flask version of the codebase.
- uv Documentation
- PyTorch with uv Guide
- uv Docker Guide
- FastAPI Documentation
- FastAPI Deployment Guide
If you encounter issues during migration:
- Check the uv troubleshooting guide
- Check the FastAPI documentation
- Open an issue with reproduction steps
- Include
uv.lock
andpyproject.toml
files - Provide error logs with
--verbose
flag
For FastAPI-specific issues, visit the interactive documentation at http://localhost:4123/docs
once the server is running.