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 without upgrading.

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].\\\\\\\\n\\\\\\\\n**Context:**\\\\\\\\n- Base model: [NAME AND SIZE: e.g. Llama 3.1 8B]\\\\\\\\n- Dataset: [NUMBER] examples of [TYPE: QA/instruction/chat/classification]\\\\\\\\n- Available hardware: [GPU: A100/L4/T4/RTX 4090] with [VRAM] GB\\\\\\\\n- Compute budget: R$ [AMOUNT]\\\\\\\\n- Goal: [DESCRIBE WHAT THE MODEL SHOULD DO BETTER]\\\\\\\\n\\\\\\\\n**1) Data Preparation:**\\\\\\\\n- Dataset format (Alpaca, ShareGPT, chat template)\\\\\\\\n- Cleaning: duplicate removal, normalization, quality validation\\\\\\\\n- Split: train (80%) / validation (10%) / test (10%)\\\\\\\\n- Tokenization and length distribution analysis\\\\\\\\n- Augmentation strategies (if small dataset < 5,000)\\\\\\\\n- Consistent prompt template with base model\\\\\\\\n- Example of 3 correctly formatted records\\\\\\\\n\\\\\\\\n**2) LoRA/QLoRA Configuration:**\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\\\\\\\\\`python\\\\\\\\n# Recommended configuration\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\n- \\\\\\\\\\\\\\\\\\\\\\\`r\\\\\\\\\\\\\\\\\\\\\\\` (rank): [4/8/16/32] — quality vs. memory trade-off\\\\\\\\n- \\\\\\\\\\\\\\\\\\\\\\\`lora_alpha\\\\\\\\\\\\\\\\\\\\\\\`: [16/32] — scaling factor\\\\\\\\n- \\\\\\\\\\\\\\\\\\\\\\\`target_modules\\\\\\\\\\\\\\\\\\\\\\\`: which layers to adapt (q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj)\\\\\\\\n- \\\\\\\\\\\\\\\\\\\\\\\`lora_dropout\\\\\\\\\\\\\\\\\\\\\\\`: [0.05/0.1]\\\\\\\\n- Quantization: 4-bit (QLoRA) with nf4 + double quantization\\\\\\\\n- Estimated trainable vs. total parameters\\\\\\\\n\\\\\\\\n**3) Training Loop:**\\\\\\\\n- Framework: Hugging Face TRL (SFTTrainer)\\\\\\\\n- Hyperparameters:\\\\\\\\n  - Learning rate: [1e-4/2e-4/5e-5] with cosine scheduler\\\\\\\\n  - Effective batch size: [VALUE] (gradient accumulation)\\\\\\\\n  - Epochs: [1-5] (monitor for overfitting)\\\\\\\\n  - Max sequence length: [512/1024/2048/4096]\\\\\\\\n  - Warmup steps: [VALUE]\\\\\\\\n- Mixed precision: bf16 (if A100) or fp16 (if T4/RTX)\\\\\\\\n- Gradient checkpointing for memory savings\\\\\\\\n- WandB/MLflow for experiment tracking\\\\\\\\n\\\\\\\\n**4) Evaluation:**\\\\\\\\n- Automatic metrics: perplexity, BLEU, ROUGE, BERTScore\\\\\\\\n- Human evaluation: quality rubric (1-5) with 100 test set examples\\\\\\\\n- Comparison: base model vs. fine-tuned vs. GPT-4 (baseline)\\\\\\\\n- Hallucination and factuality assessment in domain\\\\\\\\n- Portuguese benchmark (if available for domain)\\\\\\\\n\\\\\\\\n**5) Merge and Deploy:**\\\\\\\\n- Merge LoRA weights into base model\\\\\\\\n- Quantization for inference: GGUF (llama.cpp) or GPTQ\\\\\\\\n- Deploy: vLLM/TGI for high-performance API\\\\\\\\n- Estimated inference cost per 1K tokens\\\\\\\\n\\\\\\\\n**6) Cost Estimate:**\\\\\\\\n- Training cost (GPU-hours × price)\\\\\\\\n- Inference cost (per 1K tokens)\\\\\\\\n- Comparison with using API (OpenAI/Anthropic) for same volume\\\\\\\\n\\\\\\\\nProvide 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.

Free browsing stays open. Premium prompts unlock the reusable workflow layer.

Use the guides and role paths to validate the job first. Upgrade when you want the full prompt text, editable premium prompts, and the surrounding course paths in one place.

Free access

  • Browse guides, role paths, and category pages.
  • Preview prompts before you decide to upgrade.
  • Find the right starting point without friction.

Membership access

  • Unlock premium prompts and the full copy text.
  • See more workflow paths and course connections.
  • Keep the reusable templates in one place.
Chat on WhatsApp