Hugging Face: Fine-Tune LLMs on Your Data (2026)
๐ Quick start
- Create a Hugging Face dataset repo and upload JSONL training data in chat-template format.
- Install unsloth, transformers, datasets, and accelerate in a CUDA 12.1+ Python environment.
- Load a 4-bit base model with FastLanguageModel.from_pretrained and attach LoRA adapters.
- Train with SFTTrainer, then save and merge LoRA adapters for inference.
๐ก Why use Hugging Face for this
This guide walks through fine-tuning an open-weight LLM on your own data using Hugging Face Hub for dataset hosting, Unsloth for memory-efficient 4-bit loading and LoRA training, and the transformers/datasets stack for orchestration. The workflow targets a single consumer GPU (16GB+ VRAM) and produces a set of LoRA adapter weights you can merge or serve separately. Note that Unsloth's supported model list changes frequently, so verify your target base model is supported before starting. Hugging Face pricing and plan limits checked 2026-10-15.
๐ ๏ธ How to Fine-Tune LLMs on Your Data (6 steps)
Step 1
Sign in to huggingface.co and click 'New dataset' from your profile menu to create a dataset repository (e.g., my-company-finetuning-data).
Step 2
Upload your JSONL file (one JSON object per line, each with a 'messages' array of role/content objects) via drag-and-drop on the Files tab or with `huggingface-cli upload <repo_id> <local_path>`.
Step 3
In a Python 3.10+ environment with CUDA 12.1+ and PyTorch installed, run `pip install unsloth transformers datasets accelerate trl peft bitsandbytes`.
Step 4
Load the base model in 4-bit with Unsloth: `from unsloth import FastLanguageModel; model, tokenizer = FastLanguageModel.from_pretrained(model_name='<supported-base-model>', max_seq_length=4096, load_in_4bit=True)`. Confirm the model appears on Unsloth's supported-models list first.
Step 5
Attach LoRA adapters with `FastLanguageModel.get_peft_model(model, r=16, lora_alpha=16, lora_dropout=0, target_modules=['q_proj','k_proj','v_proj','o_proj','gate_proj','up_proj','down_proj'])`.
Step 6
Format your dataset with `tokenizer.apply_chat_template` and train using `trl.SFTTrainer` with a cosine schedule, 10% warmup, and a starting learning rate of 2e-4. Save adapters with `model.save_pretrained('lora_model')`.
๐ฆ What you'll get
You end up with a `lora_model/` directory containing adapter_config.json and adapter_model.safetensors, plus a tokenizer folder. You can load the base model and adapters together for inference, or merge them into a single set of weights with `model.save_pretrained_merged('merged_model', tokenizer)`.
๐ฐ Pricing (checked 2026-10-15)
| Plan | Price | What you get for this workflow | Official link |
|---|---|---|---|
| Free | $0 |
Public and private repos, community support, limited Inference API credits | pricing โ |
| Pro | $9/month |
Higher Inference API credits, ZeroGPU access, PRO badge, priority support | pricing โ |
| Enterprise Hub | From $20/user/month |
SSO, audit logs, resource groups, data residency, advanced access control | pricing โ |
| Unsloth | Free (open source) |
Local library; no hosted training service | pricing โ |
๐ Copy-paste prompts
"Generate a JSONL file with 100 examples of support conversations for {your company}. Use the chat template format: {'messages': [{'role': 'user', 'content': '...'}, {'role': 'assistant', 'content': '...'}]}. Include common issues: password reset, billing inquiries, feature requests."
"Generate a JSONL file with 50 code-centric conversations where the user asks about using {your API} endpoints. Each assistant answer should include a short code snippet in Python. Use the chat template format."
"Generate a JSONL file with 30 examples of marketing copy conversations. The user provides a brief description, and the assistant writes a social media post in {brand tone}: witty, concise, and uses emojis sparingly. Use the chat template format."
โ ๏ธ Common mistakes
โ๏ธ Hugging Face vs Alternatives
| Tool | Price | Best For | Verdict |
|---|---|---|---|
| โ | Pay-per-token training; see official pricing page (checked 2026-10-15) |
Teams that want managed fine-tuning without owning GPUs | |
| โ | Pay-per-token training and inference; see official pricing page (checked 2026-10-15) |
Teams already standardized on OpenAI models and APIs |
โ Frequently Asked Questions
Q: Do I need a GPU to fine-tune with Hugging Face and Unsloth?
Yes. Unsloth's 4-bit QLoRA workflow targets NVIDIA GPUs with CUDA 12.1+ and at least 16GB VRAM for typical 7B-8B models at moderate sequence lengths. Larger models need more VRAM or multi-GPU setups.
Q: Is Hugging Face free for fine-tuning?
The Hub free tier covers dataset and model hosting. Training itself runs on your own hardware, so there is no Hugging Face compute charge unless you use paid Inference Endpoints or Spaces GPU upgrades.
Q: What is QLoRA and why use it?
QLoRA loads the base model in 4-bit precision and trains small low-rank adapter matrices. This cuts VRAM usage dramatically compared to full fine-tuning while preserving most quality for domain adaptation tasks.
Q: Can I fine-tune any model with Unsloth?
No. Unsloth maintains a supported-models list that changes over time. Check the official documentation for your target architecture before starting.
Q: How much training data do I need?
For style and format adaptation, a few hundred to a few thousand high-quality examples often suffice. For new factual knowledge, fine-tuning is usually the wrong tool; consider RAG instead.
Q: How do I deploy the fine-tuned model?
You can merge LoRA adapters into the base weights and serve with vLLM, TGI, or llama.cpp, or keep adapters separate and load them at inference time with PEFT.
๐ Level up your AI toolkit
Understand AI in 5 minutes a day. No jargon. No hype. Unsubscribe anytime.