Fine-Tuning LLMs with Hugging Face
Two approaches: no-code AutoTrain or code-based LoRA with PEFT.
Option 1: AutoTrain (No Code)
1. Go to [huggingface.co/autotrain](https://huggingface.co/autotrain)
2. Select a base model (e.g., Llama 3.2 3B)
3. Upload your training data (CSV or JSONL)
4. Configure: learning rate, epochs, batch size
5. Click Train — results in 1-4 hours
Option 2: LoRA with PEFT (Code)
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments
from peft import LoraConfig, get_peft_model
from trl import SFTTrainer
Load base model
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
Configure LoRA
lora_config = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q_proj", "v_proj"],
lora_dropout=0.05,
task_type="CAUSAL_LM"
)
model = get_peft_model(model, lora_config)
Train
trainer = SFTTrainer(
model=model,
train_dataset=dataset,
args=TrainingArguments(
output_dir="./results",
num_train_epochs=3,
per_device_train_batch_size=4,
learning_rate=2e-4,
),
)
trainer.train()
Push to Hub
model.push_to_hub("your-username/my-fine-tuned-model")
```
When to Use What
| Method | Best For | GPU Needed |
|--------|----------|------------|
| AutoTrain | Quick experiments, non-technical users | Cloud (included) |
| LoRA/QLoRA | Custom training, research, production | 16GB+ VRAM |
| Full fine-tuning | Maximum quality, large datasets | 80GB+ VRAM |