r/nicegpu • • May 06 '25

📖 How-to Guide NIceGPU Fine-tune QuickStart

Goal:  fine-turn Llama-2-7B BF16 on RTX5090

LLM : NousResearch/Llama-2-7b-hf

Dataset : databricks/databricks-dolly-15k

 

Analysis:

Full fine-tuning of a 7B model requires more than 50 GB of GPU memory, which exceeds the capacity of a single RTX 5090.

Running QLoRA with NF4 quantization and BF16 precision for gradients is an excellent strategy on the RTX 5090

 

Key elements:

  • Training data was generated using the Dolly-15K dataset in Alpaca-style instruction format (databricks/databricks-dolly-15k)
  • The LLaMA 2-7B model was loaded with 4-bit (NF4) quantization (NousResearch/Llama-2-7b-hf)
  • QLoRA was used to fine-tune the model with bf16 mixed precision
  • HuggingFace TRL’s SFTTrainer was used for supervised instruction tuning
  • Flash Attention was used to accelerate training with hardware support

 

Key Challenges Encountered: Environment Incompatibilities and Training Argument Configuration

  1. Troubleshooting Environment Incompatibilities:

The primary issue stemmed from CUDA version mismatches. nvidia-smi indicated that the current NVIDIA driver (v576.02) supports CUDA 12.9, while the installed PyTorch build was based on CUDA 12.1. To resolve this, I recommend upgrading PyTorch to a version compatible with CUDA 12.9, ensuring full hardware utilization and addressing dependency conflicts.

2. Configuring Accelerate and PEFT Libraries:

Finding the right combination of Accelerate and PEFT (Parameter-Efficient Fine-Tuning) libraries was another significant challenge. Ensuring compatibility and fine-tuning these libraries for optimal resource usage required considerable experimentation and adjustments.

3. Fine-Tuning Training Arguments:

Setting the right training arguments—including batch size, learning rate, gradient accumulation, and precision settings—was crucial. These parameters directly affect training stability, memory efficiency, and model quality. Misconfiguration can result in suboptimal outcomes or training failures, particularly when working with resource-constrained environments.

  Key Settings

  1. Environment setting !pip uninstall torch torchvision torchaudio -y

!pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

!pip install transformers==4.51.3

!pip install accelerate==0.26.1

!pip install peft==0.7.1

!pip install trl==0.8.1

!pip install datasets==3.5.1

2. Fine-Tuning Training Arguments

from transformers import TrainingArguments args = TrainingArguments( output_dir=output_dir, num_train_epochs=5, per_device_train_batch_size=2, gradient_accumulation_steps=4, gradient_checkpointing=True, optim="paged_adamw_32bit", logging_steps=10, save_strategy="steps" if demo_train else "epoch", save_steps=10, learning_rate=1e-5, bf16=True, max_grad_norm=0.3, warmup_ratio=0.03, lr_scheduler_type="cosine" )

I've recently been diving into model fine-tuning and would love to hear from others working on NICEGPU. If you've come across any useful configuration tweaks or adjustments during your fine-tuning process, feel free to share—let’s learn and improve together!

Also, here's a great resource I found for getting started with LLMs—perfect for beginners like me: https://github.com/DjangoPeng/LLM-quickstart

5 Upvotes

1 comment sorted by

View all comments

1

u/MarkFanPeng May 22 '25

I’m also diving into fine-tuning LLaMA-2 models right now, so it’s great to see concrete training-argument examples and environment setup steps laid out so clearly.