Fine-tuning · QLoRA

Counsel Assist

Llama 3.1 8B fine-tuned with QLoRA to write structured support plans.

Last commit
Apr 2025
Stack
  • Llama 3.1 8B
  • Unsloth
  • TRL SFTTrainer
  • QLoRA
  • GPT-3.5 (labels)
  • Weights & Biases
  • Hugging Face

Problem

CounselChat has several free-form counselor answers per question. The project condenses them into a fixed plan (core issue, coping strategies, immediate actions, long-term focus) and trains an 8B model on a single consumer GPU to produce that structure directly.

Architecture

CounselChatgroup by questionGPT-3.5 planssection filterchat templateLlama 3.1 8B 4-bitSFT + LoRAmerge 16-bitHugging Face
CounselChatgroup by questionGPT-3.5 planssection filterchat templateLlama 3.1 8B 4-bitSFT + LoRAmerge 16-bitHugging Face

860 filtered examples (774 train / 86 held out) train LoRA adapters on the 4-bit base, merged to 16-bit and served from the Hub.

  • Groups answers per question, generates plans with GPT-3.5, keeps only complete four-section plans.

  • Unsloth + TRL on one RTX 4060 Ti, logged to Weights & Biases.

  • transformers pipeline loading the published model.

Key decisions

  • QLoRA on every projection

    LoRA r=16, alpha=16 on q/k/v/o/gate/up/down projections with rsLoRA over a 4-bit base: 41.9M trainable parameters (0.52%).

    llm_finetuning.ipynb · cells 5–6
  • Training setup for a 16 GB GPU

    lr 1e-4 linear, effective batch 16 (8 × 2 accumulation), 2 epochs (96 steps), 8-bit AdamW, bf16 where supported, eval every 10% of steps.

    llm_finetuning.ipynb · cells 18–21
  • Synthetic labels with a completeness filter

    All answers to a question go to GPT-3.5 with retries and backoff; a plan is kept only if all four sections are present and none is empty or a placeholder.

    dataset_prep.ipynb · cells 7–13

Evaluation

WhatHow it was measuredResult
Validation lossSFTTrainer on the 86-example held-out split, every ~10 steps over 96 steps, logged to W&B. Token loss only; targets are GPT-3.5-written. llm_finetuning.ipynb · cell 21 output 1.467 → 1.219, falling at every eval
Training lossSame run, steps 10 → 90. llm_finetuning.ipynb · cell 21 output 1.387 → 1.195

Run it

Notebooksdataset_prep.ipynb → llm_finetuning.ipynb → inference.ipynb