Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

AI Fundamental - Fine-Tuning

Back


Fine-Tuning

The Analogy:

  • Pretrained LLM: A smart generalist who has read the entire internet.
  • Fine-tuning: Sending that generalist to a specific job-training program to learn your company’s unique workflows.

Use fine-tuning when prompting (Zero-shot or Few-shot) alone is not enough to achieve the desired consistency or specialized behavior.


  1. Domain-specific knowledge: Medical, legal, finance, or internal company policies.
  2. Style & Tone Control: Customer support tone, brand voice (formal, friendly, etc.).
  3. Structured Outputs: Consistently generating JSON, API responses, or SQL queries.
  4. Classification Tasks: Sentiment analysis, ticket routing, or fraud detection.
  5. Task Specialization: Code generation for specific frameworks or Log Analysis (a high-value DevOps use case).

Common Techniques

There are three main levels of fine-tuning used in the industry today:

Full Fine-Tuning

Training all model parameters.


Parameter-Efficient Fine-Tuning (PEFT)

The industry standard for most applications.


Instruction Fine-Tuning

Training the model specifically on an Instruction -> Response format.


Simple Example

Goal: Train a model to analyze CI/CD failures automatically.

Step 1: Prepare Dataset

Format your data as input → output pairs:

{
  "input": "ERROR: Docker build failed COPY requirements.txt not found",
  "output": "Root Cause: requirements.txt missing from build context. Fix: ensure file exists or correct path."
}

Requirement: 100–10,000+ high-quality examples.


Step 2: Choose Base Model

Examples:


Step 3: Train (Fine-Tune)

Using LoRA (typical modern approach):


Step 4: Evaluate

Test with unseen logs:

ERROR: npm install failed package.json missing
Root Cause: package.json missing
Fix: add package.json or correct working directory

Step 5: Deploy

Use it in your pipeline:


Fine-Tuning vs RAG

Method Purpose
Fine-tuning Change model behavior/style
RAG (Retrieval-Augmented Generation) Inject external knowledge

Rule of thumb:


Avoid fine-tuning