Skip to main content
Full-parameter fine-tuning updates all model weights during training, providing the most comprehensive adaptation to your task. This method achieves the best performance but requires significant GPU resources.

Overview

Full-parameter fine-tuning is recommended when:
  • You have access to multiple high-memory GPUs (A100 80GB or similar)
  • You need maximum model performance for production deployment
  • Your task requires significant deviation from the pretrained behavior
  • You can afford longer training times and higher computational costs
Full-parameter fine-tuning of Qwen-7B requires at least 2x A100-80GB GPUs. Single-GPU training will result in out-of-memory errors.

Hardware Requirements

Memory Requirements by Model Size

Performance Benchmarks

Qwen-1.8B on Single A100-80GB:
Batch size: 1, Gradient accumulation: 8, Flash Attention 2 enabled, BF16 precision

Installation

Install the required dependencies:
Flash Attention 2 significantly reduces memory usage and improves training speed. Highly recommended for full-parameter training.

Training Configuration

Basic Training Script

The finetune/finetune_ds.sh script provides a complete configuration for distributed full-parameter training:
finetune/finetune_ds.sh

Running Training

1

Prepare Your Data

Create your training data in the required JSON format:
See Data Preparation for details.
2

Launch Training

Run the training script with your model and data paths:
3

Monitor Progress

Training logs will show loss and learning rate:
Checkpoints are saved to output_qwen/ every 1000 steps.
4

Load Fine-tuned Model

After training completes, load your model:

DeepSpeed Configuration

Full-parameter training uses DeepSpeed ZeRO-3 to distribute model parameters across GPUs:
finetune/ds_config_zero3.json

ZeRO-3 Features

  • Parameter Sharding: Distributes all model parameters across GPUs
  • Gradient Sharding: Distributes gradients across GPUs
  • Optimizer State Sharding: Distributes optimizer states across GPUs
  • Communication Overlap: Overlaps communication with computation
ZeRO-3 enables training of much larger models than would fit on a single GPU, but requires high inter-GPU bandwidth for best performance.

Hyperparameter Guide

Learning Rate

Full-parameter fine-tuning uses a lower learning rate (1e-5) compared to LoRA (3e-4) because all parameters are being updated.
  • Cosine decay with 1% warmup steps
  • Gradually reduces learning rate over training
  • Helps achieve better convergence

Batch Size and Gradient Accumulation

Effective batch size = per_device_batch_size × gradient_accumulation_steps × num_gpus For 2 GPUs: 1 × 16 × 2 = 32 effective batch size
Increasing per_device_train_batch_size beyond 1 may cause OOM errors. Adjust gradient_accumulation_steps instead.

Sequence Length

Longer sequences require more memory:

Training Duration

Number of Epochs

  • Small (less than 1K samples): 10-20 epochs
  • Medium (1K-10K samples): 3-5 epochs
  • Large (more than 10K samples): 1-3 epochs
Watch for these signs of overfitting:
  • Training loss continues decreasing while validation loss increases
  • Model memorizes training examples verbatim
  • Poor generalization to new inputs
Solutions:
  • Reduce number of epochs
  • Increase dataset size
  • Add regularization (weight decay)

Checkpointing

  • Saves checkpoint every 1000 steps
  • Keeps only the last 10 checkpoints
  • Automatically deletes older checkpoints to save disk space

Checkpoint Structure

Advanced Options

Gradient Checkpointing

Trades computation for memory by recomputing activations during backward pass:
  • Memory savings: 30-50% reduction
  • Speed impact: 20-30% slower training
  • Recommended: Always enable for full-parameter training

Mixed Precision Training

BF16 advantages:
  • Wider dynamic range than FP16
  • No loss scaling required
  • Consistent with Qwen pretraining
  • Requires Ampere GPUs or newer (A100, RTX 30xx+)

Troubleshooting

Solutions:
  1. Reduce model_max_length
  2. Enable gradient_checkpointing
  3. Reduce per_device_train_batch_size to 1
  4. Add more GPUs
  5. Use DeepSpeed ZeRO-3 with CPU offloading:
Causes and solutions:
  • Learning rate too high: Reduce to 5e-6
  • Gradient explosion: Enable gradient clipping (automatic with DeepSpeed)
  • Data quality issues: Check for corrupted samples
  • Mixed precision issues: Try BF16 instead of FP16
Optimizations:
  1. Enable Flash Attention 2
  2. Use --lazy_preprocess True
  3. Increase gradient_accumulation_steps, reduce save_steps
  4. Ensure high-bandwidth inter-GPU connection (NVLink)
  5. Profile with:
Common fixes:
  • Install compatible versions: torch>=2.0, deepspeed>=0.10
  • Check CUDA version compatibility
  • Verify all GPUs are accessible: nvidia-smi
  • Ensure consistent PyTorch versions across all nodes (for multi-node)

Inference After Training

Load and use your fine-tuned model:

Next Steps

LoRA Fine-tuning

Learn about memory-efficient LoRA training

Multi-node Training

Scale to multiple machines for even larger models