Skip to content

DanielPuentee/llm-finetuning-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fine-Tuning Guide

Fine-Tuning Guide Cover

Visual Studio Code Python PyTorch Transformers TRL PEFT GitHub last commit License

Author: Daniel Puente Viejo

A hands-on guide for fine-tuning the models TinyLlama1.1B & Llama3.1-8B-Instruct with low-rank adapters (LoRA). The repository bundles Colab and macOS & Windows/Linux local workflows with curated datasets, and fully reproducible experiments so you can adapt compact open models to your own domain with minimal compute.

🎯 What You Get

🧱 Project Structure

├── data/                      # Supervised fine-tuning corpora (JSON + raw text)
├── google_colab/
│   ├── fine-tuning.ipynb      # Colab workflow (setup + training + evaluation)
│   └── imgs/                  # Notebook figures and configuration screenshots
├── mac/
│   ├── fine-tuning.ipynb      # Local M-series workflow with Accelerate + LoRA
│   └── requirements.txt       # Exact Python dependencies for local runs
├── windows-linux/
│   ├── fine-tuning.ipynb      # Local Windows/Linux workflow with PEFT + CUDA
│   └── requirements.txt       # Exact Python dependencies for local runs
└── README.md                  # You are here

🚀 Quick Start

Option A — Google Colab (GPU in the cloud)

  • Open google_colab/fine-tuning.ipynb and connect to a GPU runtime (T4 or better)
  • Run the setup cells to install Transformers, TRL, PEFT, bitsandbytes and Unsloth.
  • Load datasets directly from data

Option B — Local macOS (Apple Silicon or CPU)

  1. Create a Python 3.10+ environment (uv, conda, or venv) and activate it
  2. Install dependencies from mac/requirements.txt
python -m venv .venv
source .venv/bin/activate
pip install -r mac/requirements.txt
  1. Launch mac/fine-tuning.ipynb and run the cells sequentially

Option C — Local Windows/Linux (CUDA GPU or CPU)

  1. Create and activate a Python 3.10+ virtual environment (Command Prompt shown below)
python -m venv .venv
.venv\Scripts\activate
pip install -r windows-linux/requirements.txt
  1. Ensure CUDA drivers are installed and a compatible GPU is available
  2. Open windows-linux/fine-tuning.ipynb in VS Code or Jupyter

📓 Notebooks at a Glance

  • google_colab/fine-tuning.ipynb: Designed for quick iteration on Colab with Unsloth, showcasing the full fine-tuning loop and evaluation on the basketball dataset
  • mac/fine-tuning.ipynb: Optimized for Apple Silicon with 4-bit loading, Accelerate configuration, and local inference tests. You can use CPU only if you don't have an M-series chip, but performance will be slower.
  • windows-linux/fine-tuning.ipynb: CUDA-ready notebook using PEFT + Accelerate for GPUs on Windows, Linux, or WSL. CPU fallback is available but not recommended for large models.

🧾 Data Expectations

You can train the model with 2 different types of data:

  • Raw context text for language-model warm-up resides in data/data.txt. Provide one or more paragraphs separated by blank lines.
  • Supervised pairs live in data/atomic_train.json. Each entry follows the schema below:
{
	"question": "What type of sport is basketball?",
	"answer": "Basketball is a team sport played on a rectangular court."
}

🧠 Recommended Learning Path

  1. Review the Colab notebook to understand the end-to-end flow
  2. Inspect the dataset examples in data.
  3. Enjoy the notebooks!

📃 License

This project is released under the MIT License. See LICENSE for details.

About

A practical guide to fine-tuning LLMs (1B & 8B) using two distinct approaches: fast cloud training with Unsloth on Google Colab, and local adaptation on Mac (MPS) & Windows/Linux (CUDA) using PEFT.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors