Skip to content

A straightforward method for training your LLM, from downloading data to generating text.

docs: contributing guide, issue and pull request templates, pre-commit hooks

FareedKhan-devf07be23c1388
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000..dee7c8d
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,34 @@
+name: Bug report
+description: Something does not work as described
+labels: [bug]
+body:
+ - type: textarea
+ id: what
+ attributes:
+ label: What happened?
+ description: What you expected, and what happened instead.
+ validations:
+ required: true
+ - type: textarea
+ id: command
+ attributes:
+ label: Command and config
+ description: The exact command you ran, and any config or flags you changed.
+ render: bash
+ validations:
+ required: true
+ - type: textarea
+ id: error
+ attributes:
+ label: Full error output
+ render: text
+ - type: textarea
+ id: env
+ attributes:
+ label: Environment
+ description: |
+ Output of:
+ python -c "import torch, sys; print(sys.version); print(torch.__version__, torch.cuda.is_available())"
+ render: text
+ validations:
+ required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..150662e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,5 @@
+blank_issues_enabled: true
+contact_links:
+ - name: Documentation
+ url: https://fareedkhan-dev.github.io/train-llm-from-scratch/
+ about: Theory, diagrams and commands for every stage.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml
new file mode 100644
index 0000000..8cbe248
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.yml
@@ -0,0 +1,19 @@
+name: Feature request
+description: Suggest an algorithm, a model idea, or an improvement to the tutorial
+labels: [enhancement]
+body:
+ - type: textarea
+ id: idea
+ attributes:
+ label: What would you like to see?
+ validations:
+ required: true
+ - type: textarea
+ id: why
+ attributes:
+ label: Why is it useful for people learning to train LLMs?
+ - type: textarea
+ id: references
+ attributes:
+ label: Papers or references
+ description: Links to the paper or code the idea comes from, if any.
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..3cb520e
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,13 @@
+## What and why
+
+<!-- What does this change, and what problem does it solve? Link the issue if there is one: Fixes #123 -->
+
+## How it was tested
+
+<!-- Commands you ran. Tests run on a CPU: `pytest -q`. -->
+
+## Checklist
+
+- [ ] `ruff check .`, `mypy` and `pytest -q` pass
+- [ ] Tests cover the new or changed behavior
+- [ ] Docs or README updated if a command, flag or config changed
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..952178d
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,20 @@
+# Optional local checks before each commit:
+# pip install pre-commit (or: uv tool install pre-commit)
+# pre-commit install
+# The same checks run in CI (.github/workflows/ci.yml).
+repos:
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v6.0.0
+ hooks:
+ - id: check-yaml
+ - id: check-toml
+ - id: check-json
+ - id: end-of-file-fixer
+ - id: trailing-whitespace
+ - id: check-added-large-files
+ args: ["--maxkb=2000"]
+ - repo: https://github.com/astral-sh/ruff-pre-commit
+ rev: v0.16.10
+ hooks:
+ - id: ruff-check
+ args: ["--fix"]
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..4a73685
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,67 @@
+# Contributing
+
+Thanks for helping. This repo is a teaching project first, so the bar for a change is: does
+it stay easy to read, and is it correct? Small, focused pull requests are the easiest to
+review and merge.
+
+## Setup
+
+With [uv](https://docs.astral.sh/uv/) (fast, recommended):
+
+```bash
+git clone https://github.com/FareedKhan-dev/train-llm-from-scratch.git
+cd train-llm-from-scratch
+uv sync # creates .venv with the package + test tools
+uv run pytest -q # everything runs on a CPU in under a minute
+```
+
+With pip:
+
+```bash
+python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
+pip install -e . pytest beartype ruff mypy
+pytest -q
+```
+
+On Linux the default PyTorch wheel bundles CUDA (about 2.5 GB). If you only need the CPU
+build, install it first: `pip install torch --index-url https://download.pytorch.org/whl/cpu`.
+
+## Checks
+
+The same three checks run in CI on Linux, Windows and macOS:
+
+```bash
+ruff check . # lint (pyflakes, pycodestyle, bugbear, pyupgrade, import order)
+mypy # types, configured in pyproject.toml
+pytest -q # tests, CPU only
+```
+
+Some guidelines that keep the code consistent:
+
+- **No GPU needed for tests.** Use tiny models (a few thousand parameters) and generated data.
+ Test a property when you can (causality, a cached forward equals a full one, a loss is zero
+ at its target) rather than a hard-coded number.
+- **Type everything new.** New functions have annotations; tensor arguments use
+ [jaxtyping](https://github.com/patrick-kidger/jaxtyping) shapes such as
+ `Float[Tensor, "batch seq vocab"]`. `tests/conftest.py` checks these shapes at runtime.
+- **Configs are typed dataclasses.** A new hyperparameter is a field in
+ `config/post_training_config.py` (use `Literal[...]` for choices) and a key in the matching
+ `configs/*.json`. The loader rejects unknown keys and wrong types.
+- **Keep the classic model simple.** `src/models/` is what the README teaches line by line.
+ New architecture ideas go in `src/models/modern/` or behind a flag.
+- **Write like the README.** Plain words, short sentences, explain why before how.
+
+## Pull requests
+
+- One topic per pull request, with a short description of what changed and why.
+- Add or update tests for the behavior you changed, and the docs if a command or flag changed.
+- Commit messages follow the existing style: `fix(area): what was wrong`,
+ `feat(area): what is new`, `docs: ...`.
+
+## Reporting a bug
+
+Please include the command you ran, the full error, and the output of:
+
+```bash
+python -c "import torch, sys; print(sys.version); print(torch.__version__, torch.cuda.is_available())"
+```