Skip to content

Commit bdcc971

Browse files
committed
MEAP release: chapters 01-05
1 parent 7869f3f commit bdcc971

103 files changed

Lines changed: 14202 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: Bug report
3+
about: Report a bug in the chapter code, tests, or shared utilities
4+
title: "[Bug] "
5+
labels: bug
6+
assignees: ''
7+
---
8+
9+
## Summary
10+
11+
<!-- One sentence describing what's broken. -->
12+
13+
## Which chapter / listing / file?
14+
15+
<!-- e.g., Chapter 5, Listing 5.2, code/chapter05/scripts/listing_5_2_prepare_dataset.py -->
16+
17+
## Steps to reproduce
18+
19+
<!--
20+
Minimal, copy-pasteable commands. Run from the code/ directory unless noted otherwise.
21+
22+
Example:
23+
1. cd code
24+
2. source .venv/bin/activate
25+
3. python -m chapter05.scripts.listing_5_2_prepare_dataset --out chapter05/data/dolly_subset
26+
-->
27+
28+
```bash
29+
# your commands here
30+
```
31+
32+
## What happened
33+
34+
<!-- The actual output, error message, or unexpected behavior. Paste tracebacks in full. -->
35+
36+
```
37+
# paste the error output here
38+
```
39+
40+
## What you expected to happen
41+
42+
<!-- What you thought would happen based on the book and the code. -->
43+
44+
## Environment
45+
46+
- **OS:** <!-- e.g., Ubuntu 24.04, Windows 11, macOS 14 -->
47+
- **Python version:** <!-- output of `python --version` -->
48+
- **GPU (if relevant):** <!-- e.g., RTX 4090 24GB, A30 24GB, none (CPU) -->
49+
- **CUDA version (if relevant):** <!-- output of `nvcc --version` or `nvidia-smi` -->
50+
- **PyTorch version (if relevant):** <!-- output of `python -c "import torch; print(torch.__version__)"` -->
51+
- **Branch / commit:** <!-- output of `git log -1 --oneline` -->
52+
- **MEAP version of the book (if relevant):** <!-- e.g., MEAP v6 -->
53+
54+
## Additional context
55+
56+
<!--
57+
Anything else that might help: relevant prior steps, partial outputs, model checkpoints
58+
already trained, datasets you swapped in, etc.
59+
60+
If the issue is reproducible only with specific data or a specific model, please
61+
note that here.
62+
-->

‎.github/ISSUE_TEMPLATE/config.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Book content questions — Manning liveBook forum
4+
url: https://livebook.manning.com/
5+
about: Please ask questions about the book's content (techniques, choices, explanations) in Manning's liveBook forum. GitHub Issues is for code bugs and errata only.
6+
- name: Manning support
7+
url: https://support.manning.com/
8+
about: Questions about your MEAP subscription, account, or purchase.

‎.github/ISSUE_TEMPLATE/errata.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Errata
3+
about: Report a typo, factual error, or unclear passage in the book itself
4+
title: "[Errata] "
5+
labels: errata
6+
assignees: ''
7+
---
8+
9+
## What's wrong
10+
11+
<!-- One or two sentences describing the issue. -->
12+
13+
## Where in the book
14+
15+
- **MEAP version:** <!-- e.g., MEAP v6 -->
16+
- **Chapter:** <!-- e.g., Chapter 5 -->
17+
- **Section:** <!-- e.g., §5.4 -->
18+
- **Listing / figure / table (if applicable):** <!-- e.g., Listing 5.3 -->
19+
- **Page (if available in your MEAP build):** <!-- e.g., p. 142 -->
20+
21+
## What the book currently says
22+
23+
<!-- Quote the exact text, formula, or claim that's wrong. -->
24+
25+
```
26+
> current text from the book
27+
```
28+
29+
## What it should say
30+
31+
<!-- Suggested correction. If you're not sure, that's fine -- just describe the problem clearly. -->
32+
33+
```
34+
> proposed text
35+
```
36+
37+
## Why this matters
38+
39+
<!--
40+
Optional. Helpful context: is this a small typo, a misleading explanation, an outdated reference, or a factual error that would mislead a reader trying to apply the technique?
41+
-->
42+
43+
---
44+
45+
*Note: errata reports help readers and the author. They are forwarded to Manning for the next MEAP update or the print edition. For broader book questions (not corrections), please use [Manning's liveBook forum](https://livebook.manning.com/) instead.*

‎.github/ISSUE_TEMPLATE/question.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Question (please use Manning's liveBook forum instead)
3+
about: Questions about the book's content belong in Manning's liveBook forum
4+
title: "[Question] "
5+
labels: question
6+
assignees: ''
7+
---
8+
9+
> ⚠️ **Stop! GitHub Issues is not the right place for questions about the book's content.**
10+
>
11+
> Please ask in [Manning's liveBook forum](https://livebook.manning.com/) for this book. The forum is where the author and other readers gather to discuss the material. You'll get faster, better answers there, and the question may help future readers too.
12+
>
13+
> **GitHub Issues** is for **code bugs and errata in this repository**, not for "how does this technique work?" or "why did the book make this choice?" style questions.
14+
15+
---
16+
17+
If you're still sure your question belongs here (e.g., it's specifically about how to run the code, not about the book's content), please use the [Bug report](.github/ISSUE_TEMPLATE/bug_report.md) template if it's about a runtime problem, or describe below what's actually about the code and not the book.
18+
19+
## What's your question
20+
21+
<!--
22+
Describe what you're trying to do, what you've tried, and where you're stuck.
23+
Include the chapter and listing you're working with.
24+
-->
25+
26+
## What you've already checked
27+
28+
- [ ] I searched the book's [liveBook forum](https://livebook.manning.com/) for this question
29+
- [ ] I read the chapter's README in `code/chapterNN/README.md`
30+
- [ ] I searched existing issues on this repo
31+
32+
## Environment (if it might matter)
33+
34+
- **OS:**
35+
- **Python version:**
36+
- **GPU (if relevant):**

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
Thanks for opening a pull request!
3+
4+
This repo is the code companion to the book *Practical Model Adaptation Techniques for Large Language Models* (Manning). Code fixes, test improvements, and README clarifications are welcome. The book's prose is not part of this repo and cannot be changed via PR -- for book content corrections, please use the Errata issue template instead.
5+
6+
Before submitting, please:
7+
- Review CONTRIBUTING.md
8+
- Run `pytest -q` and `ruff check .` from the `code/` directory
9+
-->
10+
11+
## What does this PR do
12+
13+
<!-- One or two sentences. What changes, and why? -->
14+
15+
## Related issue
16+
17+
<!-- e.g., Closes #42, or N/A if there isn't one. -->
18+
19+
## Which chapter or area does this touch
20+
21+
<!-- e.g., chapter05 training script, common/jsonl utility, chapter04 tests, root README -->
22+
23+
## How to test
24+
25+
<!-- Concrete commands a reviewer can run to verify your change. Run from the code/ directory. -->
26+
27+
```bash
28+
# example
29+
cd code
30+
pytest chapter05/tests -q
31+
```
32+
33+
## Checklist
34+
35+
- [ ] Tests added or updated for the change (if it's a bug fix or behavior change)
36+
- [ ] `pytest -q` passes from `code/`
37+
- [ ] `ruff check .` passes from `code/`
38+
- [ ] README or chapter README updated if user-facing instructions changed
39+
- [ ] No secrets, API keys, or personal data in the diff
40+
- [ ] No large binary artifacts (model checkpoints, training runs) in the diff
41+
- [ ] The change does not alter file paths the book references in listings
42+
43+
## Additional context
44+
45+
<!-- Anything a reviewer should know. Tradeoffs, alternatives considered, follow-up work. -->

‎.github/workflows/code-ci.yml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: code-ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
tests:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest, windows-latest]
14+
python: ["3.11"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python }}
23+
24+
- name: Install package (dev extras)
25+
working-directory: code
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev]"
29+
30+
- name: Run unit tests
31+
working-directory: code
32+
run: |
33+
pytest -q
34+

‎.gitignore‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[codz]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# Installer logs
30+
pip-log.txt
31+
pip-delete-this-directory.txt
32+
33+
# Unit test / coverage reports
34+
htmlcov/
35+
.tox/
36+
.nox/
37+
.coverage
38+
.coverage.*
39+
.cache
40+
nosetests.xml
41+
coverage.xml
42+
*.cover
43+
*.py.cover
44+
.hypothesis/
45+
.pytest_cache/
46+
cover/
47+
48+
# Jupyter Notebook
49+
.ipynb_checkpoints
50+
51+
# Environments
52+
.env
53+
.envrc
54+
.venv
55+
env/
56+
venv/
57+
ENV/
58+
env.bak/
59+
venv.bak/
60+
61+
# mypy / ruff / pyre / pytype
62+
.mypy_cache/
63+
.dmypy.json
64+
dmypy.json
65+
.ruff_cache/
66+
.pyre/
67+
.pytype/
68+
69+
# Cython debug symbols
70+
cython_debug/
71+
72+
# Word lock files
73+
~$*.docx
74+
75+
# Temp files
76+
*.tmp
77+
78+
# Book code workspace artifacts
79+
code/**/runs/
80+
code/**/wandb/
81+
code/**/__pycache__/
82+
code/**/.pytest_cache/

‎CHANGELOG.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Changelog
2+
3+
All notable changes to the code in this repository are documented here.
4+
5+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses calendar-versioned releases tied to Manning MEAP drops (`MEAP-vN`) and a final `1.0.0` at print publication.
6+
7+
## [Unreleased]
8+
9+
<!-- Changes landing on `main` between releases go here. -->
10+
11+
## [MEAP-v0.1] — TBD
12+
13+
First public release of the code repository alongside Manning's MEAP launch.
14+
15+
### Added
16+
17+
- Initial release of code for Chapters 1 through 5.
18+
- **Chapter 1** — reproducibility script for the §1.6 sidebar (`run_sidebar_example.py`). Runs the chapter's prompt through base Qwen3-4B, the Chapter 5 LoRA adapter, and the Chapter 6 SFT model side by side; degrades gracefully when later-chapter artifacts are not yet built.
19+
- **Chapter 2** — Unsloth-based fine-tuning quickstart reproducing the Dragon LLM open-finance recipe on Qwen3-0.6B end to end (data preparation across four HF datasets, LoRA via TRL's `SFTTrainer`, five evaluation tests, model export).
20+
- **Chapter 3** — data-quality experiment, six-step synthetic-data-generation pipeline using a frontier teacher, and a standalone `DatasetManifest` module for content hashing and lineage tracking.
21+
- **Chapter 4** — few-shot ticket classifier, many-shot prompt assembly, prompt validator with run-to-run variability measurement, minimal RAG pipeline (50 lines), Precision@k / Recall@k / Hit@1 retrieval evaluator.
22+
- **Chapter 5** — LoRA and QLoRA training, evaluation, and inference on a 400-example Dolly subset of Qwen3-4B-Instruct-2507; published adapter on Hugging Face Hub at `bahree/qwen3-4b-dolly-lora-ch5`.
23+
- Shared utilities in `common/` (JSONL I/O, env loading, deterministic seeding, manifest tracking, OpenRouter helper).
24+
- CI workflow (`pytest` on Ubuntu and Windows with Python 3.11).
25+
- Issue templates for bug reports and errata; redirect for book-content questions to Manning's liveBook forum.
26+
- Contributing guidelines.
27+
28+
### Notes
29+
30+
- Chapters 6 through 9 (Full SFT, Distillation, DPO, Operations) are written and will be released to this repo as they reach MEAP in subsequent drops.
31+
- All hands-on chapters use Qwen3-4B-Instruct-2507 as the base model and Databricks Dolly-15K (filtered subsets) as the dataset, so the chapters compose into a single coherent example pipeline.
32+
33+
---
34+
35+
## Release tagging convention
36+
37+
Each MEAP release is tagged in Git so readers can check out the exact tree that matches the manuscript they're reading.
38+
39+
```bash
40+
git tag # list all releases
41+
git checkout MEAP-v0.1 # check out a specific release
42+
```

0 commit comments

Comments
 (0)