| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A comprehensive implementation of multi-head LoRA training for masked diffusion on Qwen3-Coder-30B-A3B-Instruct-FP8 with on-policy learning using Bend/HVM verification.
This project implements a state-of-the-art code generation system that combines:
┌─────────────────────────────────────────────────────────────┐
│ Multi-Head LoRA System │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ AR Head │ │ Diffusion │ │ Length Prediction │ │
│ │ (Scaffold) │ │ Head │ │ Head │ │
│ └──────┬──────┘ └──────┬──────┘ └─────────┬───────────┘ │
│ │ │ │ │
│ └─────────────────┼──────────────────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Qwen3-Coder-30B-A3B-Instruct-FP8 │ │
│ │ (30.5B total, 3.3B active) │ │
│ │ 128 experts, 8 activated │ │
│ └─────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ LoRA Adapters │ │
│ │ • AR: 128M parameters │ │
│ │ • Diffusion: 128M parameters │ │
│ │ • Length: 32M parameters │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────────────────┐
│ Bend/HVM Verifier │
│ • Massive parallel execution │
│ • Functional correctness │
│ • On-policy learning feedback │
└─────────────────────────────────┘
# Clone the repository
git clone <repository-url>
cd qwen_diffusion_training
# Install Python dependencies
pip install -r requirements.txt
# Install Bend and HVM
bash scripts/setup_bend_hvm.sh
# Verify installation
python scripts/test_verifier_integration.py# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install PyTorch with CUDA support
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# Install other dependencies
pip install -r requirements.txt# Run the setup script
bash scripts/setup_bend_hvm.sh
# Manual installation (if script fails)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
cargo install hvm bend-lang# Test Bend
bend run-cu --version
# Test HVM
hvm --version
# Run integration tests
python scripts/test_verifier_integration.pyIf you want to verify everything is wired correctly without long runs:
# Train on the bundled tiny dataset (50 steps)
bash scripts/train_tiny.sh
# Generate a small function using the trained adapters
bash scripts/generate_tiny.shArtifacts are written to logs/tiny. The base model remains frozen; only LoRA adapters and the small length head are updated.
# Create data directory
mkdir -p data
# Prepare your code dataset
python scripts/prepare_data.py --input_dir /path/to/code --output_dir data/code_dataset
# Create test cases for verification
cp data/test_cases.json.example data/test_cases.json
# Edit data/test_cases.json with your test casesEdit configs/qwen3_coder_30b_moe.yaml to match your setup:
model:
name: "Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8"
training:
micro_batch_size: 16 # Adjust based on GPU memory
max_steps: 40000
learning_rate: 1e-4
verifier:
bend:
enabled: true
use_cuda: true
on_policy_learning:
enabled: true
verification_frequency: 100# For H100 or similar high-end GPU
bash scripts/train_lora_h100.sh
# For other GPUs
bash scripts/train_lora.sh
# Monitor training with TensorBoard
tensorboard --logdir logs# Generate code with trained adapters
python scripts/generate.py \
--model_path logs/qwen3_coder_30b_moe_lora/checkpoint-40000 \
--prompt "def quicksort(arr):" \
--output generated_code.pyTo use on-policy verification with Bend/HVM during main training, enable it in your main config (configs/qwen3_coder_30b_moe.yaml):
verifier:
bend:
enabled: true
path: "bend"
timeout: 30
use_cuda: true
hvm:
enabled: true
path: "hvm"
timeout: 30
on_policy_learning:
enabled: true
verification_frequency: 100Requirements:
If Bend/HVM are not installed, keep them disabled or use the tiny config (configs/qwen3_coder_30b_moe_tiny.yaml) which ships with verification off.
# Evaluate on benchmarks
python scripts/evaluate.py \
--model_path logs/qwen3_coder_30b_moe_lora/checkpoint-40000 \
--benchmark human_eval| Metric | Value |
|---|---|
| Training Time | ~7 hours (40k steps on H100) |
| Memory Usage | ~40GB peak |
| GPU Utilization | 85-95% |
| Convergence | 20k steps for basic quality, 40k for optimal |
| Method | Tokens/Second | Relative Speed | Quality (HumanEval) |
|---|---|---|---|
| Autoregressive (AR) | ~400 | 1.0x | 54.3% |
| Diffusion (100 steps) | ~800 | 2.0x | 52-56% |
| Diffusion (50 steps) | ~1600 | 4.0x | 50-54% |
| Diffusion (25 steps) | ~2000+ | 5.0x+ | 45-50% |
Quality (%)
100% ┤
│
95% ┤ ● (100 steps)
│ /
90% ┤ /
│ /
85% ┤ ● (50 steps) ← Sweet spot
│ /
80% ┤ /
│ /
75% ┤ ● (25 steps)
│ /
70% ┤/
└───────────────────────────────────
10 25 50 100 200 Steps
Speed (tokens/s) →
The system supports various model configurations:
# Qwen3-Coder-30B-A3B-Instruct-FP8 (recommended)
model:
name: "Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8"
total_params: 30.5B
active_params: 3.3B
# Alternative models
# model:
# name: "Qwen/Qwen3-Coder-7B"
# total_params: 7B
# active_params: 7B# High-quality settings
ar_head:
r: 128
alpha: 256
diffusion_head:
r: 128
alpha: 256
length_head:
r: 64
alpha: 128verifier:
bend:
timeout: 30
use_cuda: true
on_policy_learning:
enabled: true
verification_frequency: 100
target_steps: 50
reward_weights:
correctness: 1.0
speed: 0.5
efficiency: 0.2# Run basic tests
python -m pytest tests/ -v
# Run integration tests
python scripts/test_verifier_integration.py# Test generation speed
python scripts/benchmark_generation.py
# Test verification performance
python scripts/benchmark_verification.py# TensorBoard
tensorboard --logdir logs
# Wandb (if enabled)
# Set wandb.enabled: true in config# Reduce batch size
training:
micro_batch_size: 8 # From 16
# Enable gradient checkpointing
training:
gradient_checkpointing: true
# Use CPU offload
training:
cpu_offload: true# Check installation
bend --version
hvm --version
# Reinstall if needed
cargo uninstall bend-lang hvm
cargo install bend-lang hvm
# Check CUDA availability
nvidia-smi# Increase batch size if memory allows
training:
micro_batch_size: 32
# Reduce verification frequency
verifier:
on_policy_learning:
verification_frequency: 200We welcome contributions! Please see our contributing guidelines:
# Clone your fork
git clone <your-fork-url>
cd qwen_diffusion_training
# Create development environment
python -m venv dev-env
source dev-env/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit installThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For questions and support:
Note: This is an advanced research implementation. Results may vary based on hardware, data quality, and configuration. The on-policy learning component requires careful tuning for optimal performance.
| Back | FazBrowse Home | New Git URL |