This document provides a comprehensive overview of the complete project setup and automation system created for the SFT-Play supervised fine-tuning template.
SFT-Play is a plug-and-play Supervised Fine-Tuning template designed for small GPUs (8GB+) with comprehensive automation, multiple backend support, and memory-efficient checkpointing.
-
.gitignore- Comprehensive ignore patterns for ML projects- Python-specific ignores (bytecode, virtual environments)
- ML-specific ignores (data directories, model outputs, adapters)
- OS and IDE-specific ignores
- Smart exceptions for essential project files
-
LICENSE- MIT License for open source distribution -
pyproject.toml- Modern Python project configuration- Complete dependency specification
- Optional dependencies (dev tools, wandb, unsloth, trackio)
- Project metadata and scripts
- Development tool configurations (black, isort, pytest, mypy)
-
README.md- Comprehensive project documentation- Project description and use cases
- Complete folder structure explanation
- Backend-specific configuration guides
- XFormers compatibility solutions
- Installation and quickstart guides
- Configuration examples
- Automation documentation
- Comprehensive troubleshooting section
-
configs/run_bnb.yaml- BitsAndBytes backend configuration- Optimized for stability and broad compatibility
- fp16 precision settings
- Separate output directory (outputs/run-bnb)
- Comprehensive safety settings
-
configs/run_unsloth.yaml- Unsloth backend configuration- Optimized for speed (with automatic fallback)
- bf16 precision settings
- Separate output directory (outputs/run-unsloth)
- XFormers compatibility handling
-
configs/run_bnb.yaml- BitsAndBytes backend configuration (default)- Optimized for stability and broad compatibility
- Uses fp16 precision for maximum compatibility
- Default configuration used by Makefile
-
configs/run_unsloth.yaml- Unsloth backend configuration (optional)- Optimized for speed with automatic fallback
- Uses bf16 precision for better performance
- Requires compatible CUDA setup
scripts/train.py- Enhanced training script with safety features- Backend stamping: Creates backend.json for run tracking
- Resume protection: Prevents cross-backend resume conflicts
- Automatic fallback: Unsloth β BitsAndBytes when XFormers issues occur
- Precision validation: Ensures compatible precision settings
- Configuration mismatch fixes: Handles evaluation_strategy vs eval_strategy
- XFormers protection: Multiple layers of compatibility safeguards
-
Makefile- Complete automation with backend-specific commands- Installation management (auto-detects uv or pip)
- Backend-specific training commands (train-bnb, train-unsloth)
- TensorBoard integration for all backends
- Directory setup and data processing pipeline
- Enhanced environment variable handling
- Customizable variables and error handling
-
workflows/quick_start.sh- Interactive setup script- Colored output for better UX
- Automatic sample data creation
- Error handling and validation
- Step-by-step guidance
- Prerequisites checking
-
workflows/batch_process.sh- Batch processing automation- Multiple dataset processing
- Different configuration support
- Experiment management
- Template for YAML-based configuration
- BitsAndBytes Backend: Stable, broad compatibility across hardware configurations
- Unsloth Backend: Faster training with automatic fallback for compatibility issues
- Backend Stamping: Each run creates
backend.jsonto track configuration - Resume Protection: Prevents accidental resume across different backends
- Automatic Fallback: Seamless fallback from Unsloth to BitsAndBytes when needed
- Issue Identification: Resolved
NotImplementedError: No operator found for memory_efficient_attention_backward - Multi-layer Protection: Environment variables, model configuration, and script-level safeguards
- Automatic Detection: System detects XFormers incompatibility and handles gracefully
- User Guidance: Clear warnings and recommendations for optimal performance
- Training Arguments Fix: Resolved
evaluation_strategyvseval_strategymismatch - Precision Validation: Ensures only one precision type (bf16 or fp16) is enabled
- GPU Auto-detection: Automatically selects optimal precision for Ada GPUs
- Backend-specific Configs: Optimized settings for each backend
- pip: Traditional Python package management
- uv: Modern, fast Python package manager
- Auto-detection: Makefile automatically chooses the best available option
- Automatic Downloads: Models are downloaded from Hugging Face Hub on first use
- Local Caching: Models are stored locally to avoid re-downloading
- Offline Support: Works offline after the first download
- One-command setup:
./workflows/quick_start.sh - Backend-specific commands:
make train-bnb,make train-unsloth - Granular control: Individual Makefile commands
- Batch processing: Multiple datasets and experiments
- Pipeline automation: Complete data processing workflows
- Auto-creation: All necessary directories created automatically
- Git-friendly: .gitkeep files maintain structure
- Clean separation: Raw, processed, styled, and rendered data
- Backend isolation: Separate output directories prevent conflicts
- Prerequisites checking: Validates environment before execution
- Graceful failures: Clear error messages and recovery suggestions
- Interactive prompts: User-friendly decision points
- Compatibility checks: Automatic detection and resolution of common issues
- Variable overrides: Customize commands with environment variables
- Multiple configs: Support for different configuration files
- Style customization: Easy prompt modification
- Backend switching: Easy migration between different backends
sft-play/
βββ .gitignore # Comprehensive ignore patterns
βββ LICENSE # MIT License
βββ README.md # Complete documentation
βββ pyproject.toml # Modern Python project config
βββ Makefile # Automation commands
βββ workflows/ # Automation scripts
β βββ quick_start.sh # Interactive setup
β βββ batch_process.sh # Batch processing
βββ scripts/
β βββ utils/
β βββ model_store.py # Model caching and downloading
βββ configs/ # Configuration files
βββ data/ # Data directories
β βββ raw/ # Raw input data
β βββ processed/ # Structured chat data
β βββ processed_with_style/ # Style-enhanced data
β βββ rendered/ # Template-rendered data
βββ scripts/ # Core functionality scripts
βββ chat_templates/ # Jinja templates
βββ env/ # Environment configs
βββ outputs/ # Training outputs
βββ adapters/ # LoRA adapter storage
# Setup
make install # Install dependencies
make setup-dirs # Create directories
make help # Show all commands
# Data Pipeline
make process # Process raw data
make style # Apply style prompts
make render # Render templates
make full-pipeline # Complete data processing
# Training & Evaluation
make train # Start training
make eval # Run evaluation
make infer # Run inference
# Model Management
make download-model # Pre-download a model
make merge # Merge LoRA adapters
# Utilities
make clean # Clean generated files
# Customization
make style STYLE="Custom prompt"
make train CONFIG=custom_config.yaml# Interactive setup
./workflows/quick_start.sh
# Batch processing
./workflows/batch_process.sh- One-command setup: Complete project initialization
- Sample data creation: Automatic demo data generation
- Interactive guidance: Step-by-step prompts
- Clear documentation: Comprehensive README with examples
- Granular control: Individual command execution
- Customization options: Variable overrides and custom configs
- Batch processing: Multiple dataset handling
- Professional tooling: Complete development environment
- Error prevention: Validation and prerequisite checking
- Clean output: Colored, structured terminal output
- Flexible installation: Support for both pip and uv
- Memory efficiency: Smart gitignore and directory management
- PHONY targets: Prevents conflicts with file names
- Variable support: Customizable CONFIG and STYLE variables
- Error handling: Proper exit codes and validation
- Cross-platform: Works on Linux, macOS, and Windows (with make)
- Set -e: Exit on any error for safety
- Colored output: Enhanced user experience
- Function organization: Modular, reusable code
- Input validation: Checks for required files and directories
- Modern packaging: pyproject.toml with complete metadata
- Development tools: Integrated linting, formatting, and testing
- Optional dependencies: Modular installation options
- Script entry points: Easy command-line access
- Reduced Setup Time: From hours to minutes
- Lower Barrier to Entry: Beginners can start immediately
- Professional Standards: Industry-standard tooling and practices
- Maintainability: Clean structure and comprehensive documentation
- Scalability: Batch processing and experiment management
- Flexibility: Multiple installation and usage options
- Zero-config startup: Works out of the box
- Complete automation: End-to-end pipeline automation
- Professional quality: Production-ready structure
- Comprehensive documentation: Self-explanatory setup
- Multi-user support: Beginner to advanced user workflows
Problem: ValueError: --load_best_model_at_end requires the save and eval strategy to match
- Root Cause: Configuration used
evaluation_strategybut script looked foreval_strategy - Solution: Enhanced config key handling to support both formats
- Implementation: Added flexible key detection in
train.py
Problem: NotImplementedError: No operator found for memory_efficient_attention_backward
- Root Cause: Unsloth + XFormers incompatibility on certain GPU/CUDA configurations
- Affected Systems: RTX 4060 + CUDA 12.6, tensor format BMGHK not supported
- Solution: Multi-layer protection and automatic fallback system
- Implementation:
- Environment variables set before imports
- Model attention implementation forced to SDPA
- Automatic fallback to BitsAndBytes
- Clear user warnings and guidance
Problem: Users could accidentally resume training with wrong backend
- Root Cause: No tracking of which backend was used for previous runs
- Solution: Backend stamping system
- Implementation: Creates
backend.jsonwith run metadata
Problem: Both bf16 and fp16 could be enabled simultaneously
- Root Cause: No validation of precision settings
- Solution: Precision validation and auto-detection
- Implementation: GPU-specific precision selection and conflict resolution
Problem: XFormers environment variables not set early enough
- Root Cause: Variables set after imports had already occurred
- Solution: Move environment variable setting to script start
- Implementation: Set variables before any other imports
- Backend Stamping: Tracks which backend was used for each run
- Resume Protection: Prevents cross-backend resume conflicts
- Automatic Fallback: Graceful degradation when compatibility issues occur
- Clear Warnings: User-friendly messages explaining what's happening
- Precision Validation: Ensures only one precision type is enabled
- Strategy Matching: Validates evaluation and save strategies match
- GPU Detection: Automatically selects optimal settings for hardware
- Error Prevention: Catches common configuration mistakes
- Early Protection: Environment variables set before any imports
- Multiple Layers: Script, model, and environment-level protections
- Compatibility Checks: Automatic detection of known issues
- Graceful Handling: Clear error messages and recovery paths
- Clone the repository
- Run
./workflows/quick_start.shfor immediate setup - Add your data to
data/raw/ - Choose your backend:
make train-bnb-tbfor maximum stability (recommended)make train-unsloth-tbfor speed (with automatic fallback)
- Monitor progress with built-in TensorBoard
- Evaluate and deploy your fine-tuned model
make train-bnb-tb # BitsAndBytes with TensorBoardmake train-unsloth-tb # Unsloth with automatic fallbackmake train CONFIG=configs/my_config.yamlThis setup transforms SFT-Play from a collection of scripts into a professional, production-ready machine learning toolkit with comprehensive automation, robust error handling, and extensive documentation.