masoodafar-web/MyXTTSModel

0

stars

425

commits

Python

primary language

Oct 24, 2025

updated

README

πŸŽ™οΈ MyXTTS - Advanced Text-to-Speech Training Framework

A comprehensive, production-ready Text-to-Speech training framework with advanced voice cloning capabilities, GPU optimization, and plateau breakthrough techniques.

⚑ GPU Optimization Alert (New!)

Having GPU utilization issues (2-40%)? Retracing warnings?

βœ… SOLVED! We've implemented a complete fix for tf.function retracing issues.

# Quick validation before training
./validate_setup.sh configs/config.yaml

# Or run the diagnostic tool
python utilities/diagnose_retracing.py --config configs/config.yaml

πŸ“– See: RETRACING_COMPLETE_SOLUTION.md for the complete fix

Results: 70-90% GPU utilization (stable), 30x faster training

πŸš€ Quick Start

# Clone the repository
git clone <your-repo-url>
cd MyXTTSModel

# Install dependencies
pip install -r requirements.txt

# Validate your setup (recommended!)
./validate_setup.sh configs/config.yaml

# Basic training - NOW WITH SMART DEFAULTS! 🎯
# Uses: tiny model, batch-size 16, static shapes enabled
python3 train_main.py --train-data ../dataset/dataset_train --val-data ../dataset/dataset_eval

# Or even simpler (uses default dataset paths):
python3 train_main.py

# Override specific parameters as needed:
python3 train_main.py --model-size small --batch-size 24

# Advanced training with all optimizations
python3 train_main.py --model-size normal --optimization-level enhanced

✨ New Smart Defaults

The training script now comes with sensible defaults that work out of the box:

  • Model size: tiny (great for learning and quick iterations)
  • Batch size: 16 (automatically adjusted based on your GPU memory)
  • Static shapes: enabled (prevents GPU utilization issues)
  • GPU mode: single-GPU (automatically switches to multi-GPU when you specify --data-gpu and --model-gpu)
  • Workers: 8 (automatically adjusted based on your system)

You can override any of these with command-line arguments!

πŸ“ Project Structure

MyXTTSModel/
β”œβ”€β”€ πŸ“œ Core Files
β”‚   β”œβ”€β”€ train_main.py          # Main training script
β”‚   β”œβ”€β”€ inference_main.py      # Inference and voice cloning script
β”‚   β”œβ”€β”€ fixed_inference.py     # Fixed inference implementation
β”‚   β”œβ”€β”€ manage.sh              # Project management script
β”‚   β”œβ”€β”€ setup.py               # Package setup and installation
β”‚   └── requirements.txt       # Python dependencies
β”‚
β”œβ”€β”€ 🧠 myxtts/                 # Core model package
β”‚   β”œβ”€β”€ config/                # Configuration classes
β”‚   β”œβ”€β”€ models/                # XTTS model implementations
β”‚   β”œβ”€β”€ training/              # Training classes and utilities
β”‚   └── utils/                 # Common utilities
β”‚
β”œβ”€β”€ βš™οΈ configs/                # Configuration files
β”‚   β”œβ”€β”€ config.yaml            # Main configuration
β”‚   └── example_config.yaml    # Example configuration
β”‚
β”œβ”€β”€ πŸ“‹ scripts/                # Utility scripts
β”‚   β”œβ”€β”€ install_dependencies.sh   # Dependency installation
β”‚   β”œβ”€β”€ quick_restart.sh          # Quick restart utility
β”‚   └── train_gpu_optimized.sh    # GPU-optimized training
β”‚
β”œβ”€β”€ πŸ› οΈ utilities/              # Utility scripts
β”‚   β”œβ”€β”€ memory_optimizer.py    # Memory optimization tools
β”‚   β”œβ”€β”€ evaluate_tts.py        # TTS quality evaluation
β”‚   └── optimize_model.py      # Model optimization for deployment
β”‚
β”œβ”€β”€ πŸ“˜ examples/               # Usage examples and demos
β”‚   └── Various usage examples
β”‚
β”œβ”€β”€ πŸ§ͺ tests/                  # Test suite
β”‚   └── Comprehensive test files
β”‚
β”œβ”€β”€ πŸ““ notebooks/              # Jupyter notebooks
β”‚   └── Training and evaluation notebooks
β”‚
β”œβ”€β”€ πŸ“š docs/                   # Documentation
β”‚   └── Technical documentation
β”‚
└── πŸ—ƒοΈ data/               # Data directories
    β”œβ”€β”€ checkpointsmain/             # Training checkpoints
    β”œβ”€β”€ dataset/                     # Training datasets
    └── small_dataset_test/          # Test datasets

🎯 Key Features

🧠 Advanced Model Architecture

  • Multiple Model Sizes: tiny, small, normal, big
  • Voice Cloning: Advanced speaker conditioning and adaptation
  • Global Style Tokens (GST): Prosody and emotion control
  • Multi-language Support: 16+ languages with NLLB tokenization

⚑ Optimization Levels

  • Basic: Stable, conservative settings
  • Enhanced: Recommended optimizations with model-size-aware tuning (default)
  • Experimental: Bleeding-edge features
  • Plateau Breaker: Special config for stuck loss (around 2.5-2.8)

New in Latest Version: Enhanced level now automatically adjusts learning rate, gradient clipping, and other parameters based on model size for better convergence and plateau prevention.

πŸ”§ GPU Optimization

  • Memory Management: Efficient VRAM usage
  • Single GPU Training: Optimized for single GPU or CPU training
  • Intelligent GPU Pipeline: πŸ†• Automatic Multi-GPU and Single-GPU Buffered modes
    • Multi-GPU Mode: Separate GPUs for data and model
    • Single-GPU Buffered Mode: Smart prefetching with configurable buffer
    • See docs/INTELLIGENT_GPU_PIPELINE.md for details

πŸ“ˆ Training Enhancements

  • Fast Convergence: 2-3x faster loss convergence
  • Adaptive Loss Weights: Auto-adjusting loss components
  • Plateau Detection: Automatic learning rate adjustment
  • Enhanced Monitoring: Real-time training metrics
  • Text-to-Audio Evaluation: πŸ†• Automatic audio generation during training
    • Generates audio samples every N steps (default: 200)
    • Saves WAV files for quality comparison
    • TensorBoard integration for real-time listening
    • See docs/TEXT2AUDIO_EVAL_GUIDE.md for details

πŸš€ Usage Examples

Basic Training

# Simplest command - uses smart defaults (tiny model, batch-size 16, static shapes enabled)
python3 train_main.py

# Quick test with even smaller batch
python3 train_main.py --batch-size 4 --epochs 10

# Production training with larger model
python3 train_main.py \
    --model-size normal \
    --optimization-level enhanced \
    --batch-size 32 \
    --epochs 500

Advanced Voice Cloning

# Enable Global Style Tokens for prosody control
python3 train_main.py \
    --enable-gst \
    --gst-num-style-tokens 12 \
    --model-size normal \
    --optimization-level enhanced

Multi-GPU Training (OPTIMIZED! ⚑)

NEW v2.0: Async pipeline with triple buffering for 2-3x faster training!

# Memory-Isolated Dual-GPU (RECOMMENDED - Optimized v2.0)
python3 train_main.py \
    --model-size tiny \
    --batch-size 16 \
    --data-gpu 0 \
    --model-gpu 1 \
    --enable-memory-isolation \
    --enable-static-shapes \
    --data-gpu-memory 8192 \
    --model-gpu-memory 16384 \
    --epochs 500

# Legacy Multi-GPU (older method)
python3 train_main.py \
    --data-gpu 0 \
    --model-gpu 1 \
    --buffer-size 100 \
    --batch-size 64 \
    --epochs 500

# Single-GPU with buffer (for users with 1 GPU)
python3 train_main.py \
    --buffer-size 100 \
    --batch-size 32 \
    --epochs 500

πŸ“Š Performance improvement: The new memory-isolated mode achieves 80-95% GPU utilization (vs 50-70% before) πŸ“– Documentation: See DUAL_GPU_BOTTLENECK_FIX.md for details πŸ”§ Profiler: Use utilities/dual_gpu_bottleneck_profiler.py to diagnose bottlenecks

Model Evaluation and Optimization

# Training with automatic evaluation
python3 train_main.py \
    --enable-evaluation \
    --evaluation-interval 25 \
    --create-optimized-model

πŸ”§ Configuration

Optimization Levels

  • --optimization-level basic: Conservative, stable settings for compatibility
  • --optimization-level enhanced: Recommended optimizations with model-size-aware tuning (default)
    • Automatically adjusts learning rate and gradient clipping based on model size
    • Tiny model: lr=3e-5, clip=0.5 | Small: lr=5e-5, clip=0.7 | Normal/Big: lr=8e-5, clip=0.8
    • Includes warnings for suboptimal configurations
  • --optimization-level plateau_breaker: For persistent plateaus at 2.5-2.8

Model Sizes

  • --model-size tiny: Fast training, lower quality (256/768 dims)
    • Best with: --batch-size 8 or 16, --optimization-level enhanced
  • --model-size small: Balanced quality vs speed (384/1024 dims)
    • Best with: --batch-size 16, --optimization-level enhanced
  • --model-size normal: High quality, default (512/1536 dims)
    • Best with: --batch-size 32, --optimization-level enhanced
  • --model-size big: Maximum quality (768/2048 dims)
    • Best with: --batch-size 8 or 16, --optimization-level enhanced

πŸ”§ Troubleshooting

Loss Plateau Issues

If your loss plateaus and stops decreasing (e.g., stuck at 2.8):

For Tiny Model:

# Option 1: Use recommended batch size (RECOMMENDED)
python3 train_main.py --model-size tiny --optimization-level enhanced --batch-size 16

# Option 2: Use plateau_breaker if still stuck
python3 train_main.py --model-size tiny --optimization-level plateau_breaker --batch-size 16

# Option 3: Upgrade to small model for better capacity
python3 train_main.py --model-size small --optimization-level enhanced --batch-size 16

Common Causes:

  • Batch size too large for model size (tiny model with batch_size > 16)
  • Model capacity insufficient (tiny model may underfit)
  • Learning rate too high (now auto-adjusted in enhanced level)

Solution Path:

  1. Try with recommended batch size for your model size
  2. If still stuck, use --optimization-level plateau_breaker
  3. Consider upgrading to a larger model size
  4. Check training logs for warnings and recommendations

See: docs/LOSS_PLATEAU_2.8_TINY_ENHANCED_FIX.md for detailed troubleshooting.

πŸ“Š Monitoring and Validation

Quick Validation

# Run comprehensive model validation
python3 utilities/validate_model_correctness.py

# Run end-to-end tests
python3 tests/test_end_to_end_validation.py

# Quick validation (both commands)
python3 utilities/validate_model_correctness.py && python3 tests/test_end_to_end_validation.py

Full Validation Suite

# Validate model functionality
python3 utilities/validate_enhancements.py

# Memory optimization testing
python3 utilities/validate_memory_fixes.py

# Complete system validation
python3 utilities/comprehensive_validation.py --data-path YOUR_DATA --quick-test

Validation Results

  • βœ“ Model Architecture: PASS (100%)
  • βœ“ Loss Functions: PASS (100%)
  • βœ“ Gradient Flow: PASS (100%)
  • βœ“ Training Pipeline: PASS (100%)
  • βœ“ Inference Mode: PASS (100%)

See Validation Guide for details.

πŸ› οΈ Development and Testing

Running Tests

# Basic functionality tests
python3 tests/test_basic_functionality.py

# Enhanced model tests
python3 tests/test_enhanced_model.py

# GPU optimization tests
python3 tests/test_gpu_optimization.py

Utilities

# Model optimization for deployment
python3 utilities/optimize_model.py

# TTS quality evaluation
python3 utilities/evaluate_tts.py

# Memory usage optimization
python3 utilities/memory_optimizer.py

πŸ“š Documentation

Comprehensive guides available in the docs/ directory:

Validation and Testing

Architecture and Features

Optimization Guides

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built on the XTTS architecture
  • Optimized for production use cases
  • Community-driven improvements and bug fixes

🎯 Ready to train high-quality voice cloning models? Start with the quick start guide above!

Contributors

Copilot

289 commits

masoodafar-web

80 commits

masoudafar

56 commits

masoodafar-web/MyXTTSModel

0

stars

425

commits

Python

primary language

Oct 24, 2025

updated

README

πŸŽ™οΈ MyXTTS - Advanced Text-to-Speech Training Framework

A comprehensive, production-ready Text-to-Speech training framework with advanced voice cloning capabilities, GPU optimization, and plateau breakthrough techniques.

⚑ GPU Optimization Alert (New!)

Having GPU utilization issues (2-40%)? Retracing warnings?

βœ… SOLVED! We've implemented a complete fix for tf.function retracing issues.

# Quick validation before training
./validate_setup.sh configs/config.yaml

# Or run the diagnostic tool
python utilities/diagnose_retracing.py --config configs/config.yaml

πŸ“– See: RETRACING_COMPLETE_SOLUTION.md for the complete fix

Results: 70-90% GPU utilization (stable), 30x faster training

πŸš€ Quick Start

# Clone the repository
git clone <your-repo-url>
cd MyXTTSModel

# Install dependencies
pip install -r requirements.txt

# Validate your setup (recommended!)
./validate_setup.sh configs/config.yaml

# Basic training - NOW WITH SMART DEFAULTS! 🎯
# Uses: tiny model, batch-size 16, static shapes enabled
python3 train_main.py --train-data ../dataset/dataset_train --val-data ../dataset/dataset_eval

# Or even simpler (uses default dataset paths):
python3 train_main.py

# Override specific parameters as needed:
python3 train_main.py --model-size small --batch-size 24

# Advanced training with all optimizations
python3 train_main.py --model-size normal --optimization-level enhanced

✨ New Smart Defaults

The training script now comes with sensible defaults that work out of the box:

  • Model size: tiny (great for learning and quick iterations)
  • Batch size: 16 (automatically adjusted based on your GPU memory)
  • Static shapes: enabled (prevents GPU utilization issues)
  • GPU mode: single-GPU (automatically switches to multi-GPU when you specify --data-gpu and --model-gpu)
  • Workers: 8 (automatically adjusted based on your system)

You can override any of these with command-line arguments!

πŸ“ Project Structure

MyXTTSModel/
β”œβ”€β”€ πŸ“œ Core Files
β”‚   β”œβ”€β”€ train_main.py          # Main training script
β”‚   β”œβ”€β”€ inference_main.py      # Inference and voice cloning script
β”‚   β”œβ”€β”€ fixed_inference.py     # Fixed inference implementation
β”‚   β”œβ”€β”€ manage.sh              # Project management script
β”‚   β”œβ”€β”€ setup.py               # Package setup and installation
β”‚   └── requirements.txt       # Python dependencies
β”‚
β”œβ”€β”€ 🧠 myxtts/                 # Core model package
β”‚   β”œβ”€β”€ config/                # Configuration classes
β”‚   β”œβ”€β”€ models/                # XTTS model implementations
β”‚   β”œβ”€β”€ training/              # Training classes and utilities
β”‚   └── utils/                 # Common utilities
β”‚
β”œβ”€β”€ βš™οΈ configs/                # Configuration files
β”‚   β”œβ”€β”€ config.yaml            # Main configuration
β”‚   └── example_config.yaml    # Example configuration
β”‚
β”œβ”€β”€ πŸ“‹ scripts/                # Utility scripts
β”‚   β”œβ”€β”€ install_dependencies.sh   # Dependency installation
β”‚   β”œβ”€β”€ quick_restart.sh          # Quick restart utility
β”‚   └── train_gpu_optimized.sh    # GPU-optimized training
β”‚
β”œβ”€β”€ πŸ› οΈ utilities/              # Utility scripts
β”‚   β”œβ”€β”€ memory_optimizer.py    # Memory optimization tools
β”‚   β”œβ”€β”€ evaluate_tts.py        # TTS quality evaluation
β”‚   └── optimize_model.py      # Model optimization for deployment
β”‚
β”œβ”€β”€ πŸ“˜ examples/               # Usage examples and demos
β”‚   └── Various usage examples
β”‚
β”œβ”€β”€ πŸ§ͺ tests/                  # Test suite
β”‚   └── Comprehensive test files
β”‚
β”œβ”€β”€ πŸ““ notebooks/              # Jupyter notebooks
β”‚   └── Training and evaluation notebooks
β”‚
β”œβ”€β”€ πŸ“š docs/                   # Documentation
β”‚   └── Technical documentation
β”‚
└── πŸ—ƒοΈ data/               # Data directories
    β”œβ”€β”€ checkpointsmain/             # Training checkpoints
    β”œβ”€β”€ dataset/                     # Training datasets
    └── small_dataset_test/          # Test datasets

🎯 Key Features

🧠 Advanced Model Architecture

  • Multiple Model Sizes: tiny, small, normal, big
  • Voice Cloning: Advanced speaker conditioning and adaptation
  • Global Style Tokens (GST): Prosody and emotion control
  • Multi-language Support: 16+ languages with NLLB tokenization

⚑ Optimization Levels

  • Basic: Stable, conservative settings
  • Enhanced: Recommended optimizations with model-size-aware tuning (default)
  • Experimental: Bleeding-edge features
  • Plateau Breaker: Special config for stuck loss (around 2.5-2.8)

New in Latest Version: Enhanced level now automatically adjusts learning rate, gradient clipping, and other parameters based on model size for better convergence and plateau prevention.

πŸ”§ GPU Optimization

  • Memory Management: Efficient VRAM usage
  • Single GPU Training: Optimized for single GPU or CPU training
  • Intelligent GPU Pipeline: πŸ†• Automatic Multi-GPU and Single-GPU Buffered modes
    • Multi-GPU Mode: Separate GPUs for data and model
    • Single-GPU Buffered Mode: Smart prefetching with configurable buffer
    • See docs/INTELLIGENT_GPU_PIPELINE.md for details

πŸ“ˆ Training Enhancements

  • Fast Convergence: 2-3x faster loss convergence
  • Adaptive Loss Weights: Auto-adjusting loss components
  • Plateau Detection: Automatic learning rate adjustment
  • Enhanced Monitoring: Real-time training metrics
  • Text-to-Audio Evaluation: πŸ†• Automatic audio generation during training
    • Generates audio samples every N steps (default: 200)
    • Saves WAV files for quality comparison
    • TensorBoard integration for real-time listening
    • See docs/TEXT2AUDIO_EVAL_GUIDE.md for details

πŸš€ Usage Examples

Basic Training

# Simplest command - uses smart defaults (tiny model, batch-size 16, static shapes enabled)
python3 train_main.py

# Quick test with even smaller batch
python3 train_main.py --batch-size 4 --epochs 10

# Production training with larger model
python3 train_main.py \
    --model-size normal \
    --optimization-level enhanced \
    --batch-size 32 \
    --epochs 500

Advanced Voice Cloning

# Enable Global Style Tokens for prosody control
python3 train_main.py \
    --enable-gst \
    --gst-num-style-tokens 12 \
    --model-size normal \
    --optimization-level enhanced

Multi-GPU Training (OPTIMIZED! ⚑)

NEW v2.0: Async pipeline with triple buffering for 2-3x faster training!

# Memory-Isolated Dual-GPU (RECOMMENDED - Optimized v2.0)
python3 train_main.py \
    --model-size tiny \
    --batch-size 16 \
    --data-gpu 0 \
    --model-gpu 1 \
    --enable-memory-isolation \
    --enable-static-shapes \
    --data-gpu-memory 8192 \
    --model-gpu-memory 16384 \
    --epochs 500

# Legacy Multi-GPU (older method)
python3 train_main.py \
    --data-gpu 0 \
    --model-gpu 1 \
    --buffer-size 100 \
    --batch-size 64 \
    --epochs 500

# Single-GPU with buffer (for users with 1 GPU)
python3 train_main.py \
    --buffer-size 100 \
    --batch-size 32 \
    --epochs 500

πŸ“Š Performance improvement: The new memory-isolated mode achieves 80-95% GPU utilization (vs 50-70% before) πŸ“– Documentation: See DUAL_GPU_BOTTLENECK_FIX.md for details πŸ”§ Profiler: Use utilities/dual_gpu_bottleneck_profiler.py to diagnose bottlenecks

Model Evaluation and Optimization

# Training with automatic evaluation
python3 train_main.py \
    --enable-evaluation \
    --evaluation-interval 25 \
    --create-optimized-model

πŸ”§ Configuration

Optimization Levels

  • --optimization-level basic: Conservative, stable settings for compatibility
  • --optimization-level enhanced: Recommended optimizations with model-size-aware tuning (default)
    • Automatically adjusts learning rate and gradient clipping based on model size
    • Tiny model: lr=3e-5, clip=0.5 | Small: lr=5e-5, clip=0.7 | Normal/Big: lr=8e-5, clip=0.8
    • Includes warnings for suboptimal configurations
  • --optimization-level plateau_breaker: For persistent plateaus at 2.5-2.8

Model Sizes

  • --model-size tiny: Fast training, lower quality (256/768 dims)
    • Best with: --batch-size 8 or 16, --optimization-level enhanced
  • --model-size small: Balanced quality vs speed (384/1024 dims)
    • Best with: --batch-size 16, --optimization-level enhanced
  • --model-size normal: High quality, default (512/1536 dims)
    • Best with: --batch-size 32, --optimization-level enhanced
  • --model-size big: Maximum quality (768/2048 dims)
    • Best with: --batch-size 8 or 16, --optimization-level enhanced

πŸ”§ Troubleshooting

Loss Plateau Issues

If your loss plateaus and stops decreasing (e.g., stuck at 2.8):

For Tiny Model:

# Option 1: Use recommended batch size (RECOMMENDED)
python3 train_main.py --model-size tiny --optimization-level enhanced --batch-size 16

# Option 2: Use plateau_breaker if still stuck
python3 train_main.py --model-size tiny --optimization-level plateau_breaker --batch-size 16

# Option 3: Upgrade to small model for better capacity
python3 train_main.py --model-size small --optimization-level enhanced --batch-size 16

Common Causes:

  • Batch size too large for model size (tiny model with batch_size > 16)
  • Model capacity insufficient (tiny model may underfit)
  • Learning rate too high (now auto-adjusted in enhanced level)

Solution Path:

  1. Try with recommended batch size for your model size
  2. If still stuck, use --optimization-level plateau_breaker
  3. Consider upgrading to a larger model size
  4. Check training logs for warnings and recommendations

See: docs/LOSS_PLATEAU_2.8_TINY_ENHANCED_FIX.md for detailed troubleshooting.

πŸ“Š Monitoring and Validation

Quick Validation

# Run comprehensive model validation
python3 utilities/validate_model_correctness.py

# Run end-to-end tests
python3 tests/test_end_to_end_validation.py

# Quick validation (both commands)
python3 utilities/validate_model_correctness.py && python3 tests/test_end_to_end_validation.py

Full Validation Suite

# Validate model functionality
python3 utilities/validate_enhancements.py

# Memory optimization testing
python3 utilities/validate_memory_fixes.py

# Complete system validation
python3 utilities/comprehensive_validation.py --data-path YOUR_DATA --quick-test

Validation Results

  • βœ“ Model Architecture: PASS (100%)
  • βœ“ Loss Functions: PASS (100%)
  • βœ“ Gradient Flow: PASS (100%)
  • βœ“ Training Pipeline: PASS (100%)
  • βœ“ Inference Mode: PASS (100%)

See Validation Guide for details.

πŸ› οΈ Development and Testing

Running Tests

# Basic functionality tests
python3 tests/test_basic_functionality.py

# Enhanced model tests
python3 tests/test_enhanced_model.py

# GPU optimization tests
python3 tests/test_gpu_optimization.py

Utilities

# Model optimization for deployment
python3 utilities/optimize_model.py

# TTS quality evaluation
python3 utilities/evaluate_tts.py

# Memory usage optimization
python3 utilities/memory_optimizer.py

πŸ“š Documentation

Comprehensive guides available in the docs/ directory:

Validation and Testing

Architecture and Features

Optimization Guides

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built on the XTTS architecture
  • Optimized for production use cases
  • Community-driven improvements and bug fixes

🎯 Ready to train high-quality voice cloning models? Start with the quick start guide above!

Contributors

Copilot

289 commits

masoodafar-web

80 commits

masoudafar

56 commits

Languages

Python

91.9%

Jupyter Notebook

7.0%

Shell

1.2%