This tutorial provides a step-by-step walkthrough for fine-tuning Liquid AI's LFM2 language model using QLoRA and Direct Preference Optimization (DPO) entirely on Google Colab. The process begins by loading the base LFM2 checkpoint with 4-bit quantization to reduce memory usage, then preparing a chat-style dataset for supervised fine-tuning (SFT). A lightweight LoRA adapter is trained using the TRL and PEFT libraries, which is then merged back into the base model. The workflow is extended with DPO to align the model's responses with preferred outputs using chosen and rejected answer pairs. By the end, you'll have a practical pipeline that transforms a base LFM2 model into an SFT-tuned, preference-aligned checkpoint, ready for deployment or further testing.
The tutorial covers essential steps including installation of required libraries, model loading with quantization, baseline evaluation, SFT training, adapter merging, and DPO training. All code snippets are provided, making it easy to replicate the process in Colab.