An open API service indexing awesome lists of open source software.

https://github.com/ginaecho/finetuninglearn

Learning finetuning from real hands-on examples to understand the theories, and implement it, step by step
https://github.com/ginaecho/finetuninglearn

Last synced: about 1 month ago
JSON representation

Learning finetuning from real hands-on examples to understand the theories, and implement it, step by step

Awesome Lists containing this project

README

          

# FinetuningLearn

Learning fine-tuning from real hands-on examples โ€” understand the theory, then implement it, step by step.

Each **case** has three layers so you can learn the way that suits you:

| Layer | File | What it gives you |
|-------|------|-------------------|
| ๐ŸŽฌ **Animation** | `animation.html` | Open in a browser. Sliders + animated canvases build intuition *before* any math. |
| ๐Ÿ““ **Notebook** | `*.ipynb` | Runnable Jupyter notebook: theory refresher โ†’ code โ†’ experiment. Cases 01-02 run on CPU; from Case 03 onward, notebooks are **Colab-first** (free T4 GPU). |
| ๐Ÿงช **Your turn** | `challenge.md` | An open problem to solve yourself, with hints and a checklist. |

> **New here?** Read [`SETUP.md`](./SETUP.md) first to install PyTorch + LoRA/QLoRA and hook up your local Llama.

---

## The roadmap (medium โ†’ professional)

The cases are ordered so each one earns the next. The whole path is built to land on **your** question:
*how do you keep fine-tuning a self-driving model as new data arrives โ€” cheaply, accurately, and without it forgetting what it already knew?*

| # | Case | Level | Core idea you'll own | Status |
|---|------|-------|----------------------|--------|
| 00 | **Tensors & NN Basics** โ€” the co-pilot vocabulary | Beginner | Shapes, layers, the training loop; what you must know vs what the agent handles | โœ… Built |
| 01 | **Foundations** โ€” what *is* fine-tuning? | Medium | Pre-train vs fine-tune; which weights move; over/underfitting | โœ… Built |
| 02 | **LoRA from scratch** | Medium | Why low-rank adapters work; implement LoRA in ~30 lines | โœ… Built |
| 03 | **QLoRA on a real LLM** | Medium+ | 4-bit quantization + LoRA; fine-tune on a free Colab T4 | โœ… Built |
| 04 | **Instruction / SFT tuning** | Pro-ish | Datasets, chat templates, eval; measure if it actually learned | ๐Ÿ”œ |
| 05 | **Catastrophic forgetting โ€” see it happen** | Pro-ish | Train task B, watch task A collapse; *measure* forgetting | โœ… Built |
| 06 | **Continual learning toolkit** | Pro | Replay, EWC, LoRA-per-task, distillation โ€” when to use which | โœ… Built |
| 07 | **Capstone: Auto-car continual fine-tuning** | Pro | Cost vs accuracy vs forgetting on a streaming-update problem | โœ… Built |

โœ… = ready to learn now. ๐Ÿ”œ = built as you progress (so each builds on what you actually ran).

---

## How to use this repo

1. **Install once:** follow [`SETUP.md`](./SETUP.md).
2. **Pick a case folder** under [`cases/`](./cases/), start with `01_foundations`.
3. In each folder:
- Open `animation.html` in your browser โ†’ play with it for 5 min.
- Open the `.ipynb` โ€” Cases 01-02 run locally; **from Case 03 onward, open in Google Colab** (free T4 GPU, no install needed). Each notebook has a setup cell that installs everything.
- Try `challenge.md` โ†’ solve it, then compare with notes.
4. Come back and we build the next case together.

---

## ๐Ÿ’ฌ Ask-the-tutor (in the animations)

Every `animation.html` has a **floating "๐Ÿ’ฌ Ask tutor" button**. Click it, paste your API key once
(โš™ settings), and ask questions about whatever you're looking at โ€” the tutor is given the page's context
so its answers fit the lesson.

- **Resizable window:** drag the bottom-right corner, **โคข maximize**, or **โ– collapse** to just the title
bar. Your size/state is remembered.
- **Readable answers:** replies render as **Markdown** (headings, lists, code blocks, links).
- **๐Ÿ“š Self-updating lesson:** every answer is folded into the tutorial as a new collapsible section, so the
lesson grows to cover *your* questions. **Curate it:** click **๐Ÿ‘ Useful** to keep a section or
**๐Ÿ—‘ This can be removed** to drop it. Kept sections are fed back to the tutor as memory, so it builds on
what you found useful (saved per page).

- **Bring your own key:** **Anthropic (Claude)** by default, or **OpenAI**. Pick the provider in โš™.
- **Your key stays local.** It's saved in your browser's `localStorage` on your machine and sent *only*
to the provider you choose (Claude calls use Anthropic's official direct-browser-access header). It is
**never** written into the HTML or committed to git.
- **Where to get a key:** Anthropic โ†’ ยท OpenAI โ†’ .
- โš ๏ธ Don't type your key on a shared/public computer, and don't paste a key into any file in this repo.

See [`SETUP.md` ยง7](./SETUP.md#7-in-page-ai-tutor-optional) for details.

---

## Your capstone question (Case 07)

> *"In fine-tuning for an autonomous car, when new memory/data and new training arrive, how do I fine-tune in the best way for cost, efficiency, and accuracy โ€” and how do I overcome catastrophic forgetting?"*

We don't hand-wave this. By Case 07 you'll have built every piece:
- **Cost/efficiency** โ† LoRA & QLoRA (Cases 02โ€“03): tune <1% of weights.
- **Accuracy** โ† SFT + eval discipline (Case 04).
- **Forgetting** โ† measure it (Case 05), then defeat it (Case 06) with replay / regularization / modular adapters.

Case 07 puts them together on a simulated streaming self-driving task and makes you trade the three off against each other โ€” the real engineering decision.

---

## Glossary quick-reference

- **Fine-tuning** โ€” continue training a pre-trained model on new, narrower data.
- **LoRA** (Low-Rank Adaptation) โ€” freeze the big model, train two small matrices per layer.
- **QLoRA** โ€” LoRA on top of a 4-bit quantized model โ†’ fits big models on small GPUs.
- **Catastrophic forgetting** โ€” a model loses old skills when trained on new data.
- **Continual / lifelong learning** โ€” training on a *stream* of tasks without forgetting.