AdvancedAI & Machine LearningFree prompt

Fine-tuning LLMs with Custom Data Using LoRA and QLoRA

Complete guide to fine-tuning language models with efficient parameter adaptation techniques.

Fine-tune a large language model for a specific domain, minimizing computational costs with PEFT (Parameter-Efficient Fine-Tuning) techniques.

At a glance

Access

Free prompt

Open to copy — no account or payment needed.

Prompt objective

Fine-tune a large language model for a specific domain, minimizing computational costs with PEFT (Parameter-Efficient Fine-Tuning) techniques.

Real use case

Minas Gerais legaltech JurisAI wants to fine-tune an LLM to answer questions about Brazilian labor legislation. They have 15,000 lawyer-reviewed question-answer pairs and a budget of R$ 5,000 (~$1,000 USD) for compute. They need a model that outperforms GPT-4 in this specific domain.

Customize these fields first

BASE MODEL NAME: Llama 3/Mistral/GemmaDOMAINLoRA/QLoRANAME AND SIZE: e.g. Llama 3.1 8BNUMBERTYPE: QA/instruction/chat/classificationGPU: A100/L4/T4/RTX 4090VRAM

Replace the placeholders with your own context before you run the prompt. That usually improves the first output more than adding more instructions later.

Prompt

Create a complete fine-tuning pipeline for [BASE MODEL NAME: Llama 3/Mistral/Gemma] focused on [DOMAIN] using [LoRA/QLoRA].

**Context:**
- Base model: [NAME AND SIZE: e.g. Llama 3.1 8B]
- Dataset: [NUMBER] examples of [TYPE: QA/instruction/chat/classification]
- Available hardware: [GPU: A100/L4/T4/RTX 4090] with [VRAM] GB
- Compute budget: R$ [AMOUNT]
- Goal: [DESCRIBE WHAT THE MODEL SHOULD DO BETTER]

**1) Data Preparation:**
- Dataset format (Alpaca, ShareGPT, chat template)
- Cleaning: duplicate removal, normalization, quality validation
- Split: train (80%) / validation (10%) / test (10%)
- Tokenization and length distribution analysis
- Augmentation strategies (if small dataset < 5,000)
- Consistent prompt template with base model
- Example of 3 correctly formatted records

**2) LoRA/QLoRA Configuration:**
```python
# Recommended configuration
```
- `r` (rank): [4/8/16/32] — quality vs. memory trade-off
- `lora_alpha`: [16/32] — scaling factor
- `target_modules`: which layers to adapt (q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj)
- `lora_dropout`: [0.05/0.1]
- Quantization: 4-bit (QLoRA) with nf4 + double quantization
- Estimated trainable vs. total parameters

**3) Training Loop:**
- Framework: Hugging Face TRL (SFTTrainer)
- Hyperparameters:
  - Learning rate: [1e-4/2e-4/5e-5] with cosine scheduler
  - Effective batch size: [VALUE] (gradient accumulation)
  - Epochs: [1-5] (monitor for overfitting)
  - Max sequence length: [512/1024/2048/4096]
  - Warmup steps: [VALUE]
- Mixed precision: bf16 (if A100) or fp16 (if T4/RTX)
- Gradient checkpointing for memory savings
- WandB/MLflow for experiment tracking

**4) Evaluation:**
- Automatic metrics: perplexity, BLEU, ROUGE, BERTScore
- Human evaluation: quality rubric (1-5) with 100 test set examples
- Comparison: base model vs. fine-tuned vs. GPT-4 (baseline)
- Hallucination and factuality assessment in domain
- Portuguese benchmark (if available for domain)

**5) Merge and Deploy:**
- Merge LoRA weights into base model
- Quantization for inference: GGUF (llama.cpp) or GPTQ
- Deploy: vLLM/TGI for high-performance API
- Estimated inference cost per 1K tokens

**6) Cost Estimate:**
- Training cost (GPU-hours × price)
- Inference cost (per 1K tokens)
- Comparison with using API (OpenAI/Anthropic) for same volume

Provide the complete Python script for the pipeline, from data prep to deploy.

Open directly in an AI — the text is pre-filled:

How to use this prompt

  1. 1Replace the key placeholders first: BASE MODEL NAME: Llama 3/Mistral/Gemma, DOMAIN, LoRA/QLoRA, NAME AND SIZE: e.g. Llama 3.1 8B.
  2. 2Replace any bracketed placeholders like [this] with your own context.
  3. 3Add extra background information when you want more tailored results.
  4. 4Combine multiple prompts in one conversation when you need a richer output.
  5. 5Save your best-performing prompts so they are easy to reuse later.

Next best step

Open the guide first, then branch only if you still need more.

A guide for technical builders choosing between prompts, coding workflows, and agent-based implementation.

If this prompt is close but not quite right, generate variants next. If the job is recurring, move into the course library after the guide.

Related prompts

View all

Explore other prompt categories

Move sideways into adjacent libraries when the current category is not the full answer.

Every prompt here is free. The course teaches the thinking behind them.

Copy as many prompts as you like. When you want to move from single prompts to a repeatable AI workflow, Learn AI in 30 Days walks through it, one day at a time.

Get the courseSee the 30-day curriculum first

Buy the course once ($15/$20 by length), or go all-access for $10/mo with a verifiable certificate.