Skip to content

Latest commit

 

History

History
79 lines (58 loc) · 2.46 KB

analysis_report.md

File metadata and controls

79 lines (58 loc) · 2.46 KB

LoRA Hyperparameter Sensitivity Analysis Report

Summary

Systematic analysis of LoRA fine-tuning hyperparameters across 45 combinations (5 ranks x 3 alpha ratios x 3 target_modules) on Alpaca-GPT4-zh and ShareGPT datasets using Qwen2-7B as base model.

Experiment Setup

Variable Values
Base Model Qwen2-7B
rank (r) 4, 8, 16, 32, 64
alpha/rank ratio 0.5x, 1.0x, 2.0x, 4.0x
target_modules QKV only, Attention (QKV+O), All Linear
Datasets Alpaca-GPT4-zh, ShareGPT
Training 3 epochs, lr=2e-4, cosine schedule, BF16

Key Finding 1: Rank Selection

Rank Trainable Params BLEU % of Best
4 0.85M 18.2 84.3%
8 1.7M 19.8 91.7%
16 3.4M 21.1 97.8%
32 6.7M 21.4 99.1%
64 13.4M 21.6 100%

Recommendation: r=16 delivers 97.8% of the best performance with only 25% of the trainable parameters compared to r=64.

Key Finding 2: Alpha/Rank Ratio

Ratio Training Stability BLEU (r=16) Recommendation
< 1.0 Unstable, high gradient variance 19.1 Avoid
1.0 - 2.0 Stable, good convergence 21.1 - 21.3 Recommended
> 4.0 Diminishing returns 21.4 Not worth the overhead

Key Finding 3: Target Modules

Target Params (M) BLEU Training Time
QKV only 1.7 17.5 1.0x (baseline)
Attention only 2.3 19.9 1.03x
All Linear 3.4 21.1 1.08x

Key Finding 4: Dataset Size Effect

  • Small dataset (< 1000 samples): More sensitive to rank selection; r >= 16 strongly recommended
  • Medium dataset (1000-5000 samples): r=8~16 range stable
  • Large dataset (> 5000 samples): r=8 provides sufficient capacity; diminishing returns beyond r=16

Practical Recommendations

  1. Default: r=16, alpha=32, target all linear + attention layers
  2. Resource-constrained: r=8, alpha=16, target QKV+O only
  3. Maximum quality: r=32, alpha=64, target all linear layers

Reproducibility

# Install dependencies
pip install llamafactory matplotlib numpy pyyaml wandb

# Run full sweep
python run_experiments.py --config configs/experiment_config.yaml

# Generate analysis
python analyze_results.py --results_dir ./outputs/

Figures

Rank vs BLEU Loss Curves