Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Docker 8 min read How-to mediumAdept

LoRA Explained: Faster, More Efficient Fine-Tuning with Docker

Gemma 3 270M can be specialized into a compact PII-masking assistant using LoRA, which freezes the base weights and trains only small low-rank adapters, cutting compute and memory needs while avoiding catastrophic forgetting. The walkthrough covers formatting supervised examples with the model's chat template so training data matches inference input, configuring PEFT adapters (r=16, alpha=32 on q_proj/v_proj), training with TRL's SFTConfig via Unsloth, and merging adapters into a standalone 16-bit checkpoint. The merged model can then be packaged and shared through Docker Model Runner and Docker Hub.

Assumes: Pythonbasic LLM conceptsHugging Face transformers

Related posts

  • Fine-Tuning Local Models with Docker Offload and Unsloth

    Docker mediumAdept

    Gemma 3 270M, a sub-1GB local model, can be fine-tuned with LoRA via Unsloth to mask personally identifiable information. Before fine-tuning it returned only "[PERSON]"; afterward it correctly redacted names, ID numbers and dates. The walkthrough runs the official Unsloth Docker image on a cloud NVIDIA L4 GPU through Docker Offload from a MacBook, with Mutagen syncing files back to the laptop. It then trains on the ai4privacy pii-masking-400k dataset in under 20 minutes, converts the result to GGUF with llama.cpp, and packages and pushes the roughly 518MB model to Docker Hub for use with Docker Model Runner.

  • Fine-Tuning Gemma Models in Hugging Face

    Hugging Face mediumAdept

    Gemma 2B and 7B can be fine-tuned cheaply with LoRA via the Hugging Face PEFT library, loading the base model in 4-bit NF4 with bitsandbytes (QLoRA) so it fits on free Colab GPUs. A worked example adapts all linear projection layers (r=8) and trains with TRL's SFTTrainer on an English quotes dataset, teaching the model to emit a "Quote/Author" format in just 10 steps. For Cloud TPUs, transformers now supports PyTorch/XLA FSDP via SPMD, enabled by adding an fsdp_config that wraps GemmaDecoderLayer with xla_fsdp_v2 and gradient checkpointing.

  • Parameter-Efficient Fine-Tuning using 🤗 PEFT

    Hugging Face mediumAdept

    Hugging Face's PEFT library brings parameter-efficient fine-tuning methods (LoRA, Prefix Tuning, Prompt Tuning, P-Tuning) to Transformers and Accelerate. Most pretrained weights stay frozen and only a small set of extra parameters is trained, which gives performance comparable to full fine-tuning at a fraction of the compute and storage cost. A LoRA config on mt0-large trains about 0.19% of the parameters, and the saved adapters are only a few MB (19MB for T0_3B) instead of 40GB per-task checkpoints. Example use cases include tuning T0_3B on 11GB consumer GPUs with DeepSpeed offload, INT8 tuning of OPT-6.7b in Colab with bitsandbytes, and Stable Diffusion Dreambooth, plus code for training, saving and loading adapters.

  • Welcome Gemma 2 - Google’s new open LLM

    Hugging Face mediumAdept

    Gemma 2 ships in 9B and 27B sizes (base and instruction-tuned) with an 8K context, trained on 8T and 13T tokens respectively. Architecturally it interleaves 4096-token sliding-window attention with global attention on alternating layers, applies tanh logit soft-capping (50.0 for attention, 30.0 for final logits), pre-trains the 9B via knowledge distillation, uses on-policy distillation in post-training, and merges models with WARP. Practical notes: soft-capping is incompatible with Flash Attention/SDPA, so fine-tune with eager attention, and run the 27B instruct model in bfloat16 because float16 gives erratic output. Covers Transformers usage (about 18 GB for the 9B model, and 4-bit loading of the 27B in about 18 GB), QLoRA fine-tuning with TRL, and TGI deployment.

  • Make LLM Fine-tuning 2x faster with Unsloth and 🤗 TRL

    Hugging Face mediumAdept

    Unsloth speeds up QLoRA fine-tuning of Llama and Mistral-family models by rewriting PyTorch modules as Triton kernels with manually derived backpropagation. Because no approximations are made, it claims 0% accuracy loss relative to standard QLoRA. Across 59 benchmark runs on A100 and T4 GPUs, it ran 1.5–3.9x faster than Hugging Face transformers and used up to 74% less VRAM. Code examples show loading pre-quantized 4-bit models with FastLanguageModel, attaching LoRA adapters, and training with TRL's SFTTrainer or DPOTrainer.

The quest for software engineering knowledge.

Look:
Layout: