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.
- Workflows covering google_colab/fine-tuning.ipynb, mac/fine-tuning.ipynb, and windows-linux/fine-tuning.ipynb
- Ready-to-use basketball dataset in data plus raw corpus in data/data.txt
- Three training setups: Unsloth on Colab, Hugging Face's SFTTrainer on macOS (Apple Silicon), and Windows/Linux (CUDA)
- Logging-ready setup (Accelerate, bitsandbytes, safetensors) for efficient experimentation on consumer GPUs or Colab T4s
├── 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
- 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
- Create a Python 3.10+ environment (uv, conda, or venv) and activate it
- Install dependencies from mac/requirements.txt
python -m venv .venv
source .venv/bin/activate
pip install -r mac/requirements.txt- Launch mac/fine-tuning.ipynb and run the cells sequentially
- 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- Ensure CUDA drivers are installed and a compatible GPU is available
- Open windows-linux/fine-tuning.ipynb in VS Code or Jupyter
- 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.
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."
}- Review the Colab notebook to understand the end-to-end flow
- Inspect the dataset examples in data.
- Enjoy the notebooks!
This project is released under the MIT License. See LICENSE for details.
