Skip to content

Python development with Astral

We recommend Astral’s Python tools when you reproduce or extend an experiment. Start with uv to manage Python, packages and environments. Add Ruff for linting and formatting, and ty for type checking as your code grows. The browser investigations need none of these tools.

Install uv using Astral’s instructions. The easiest option is the ready-to-run starter ZIP, with all model files and a locked environment. To assemble the files yourself, download the reference script, model configuration and trained weights into one folder. Open a terminal in that folder and run:

Terminal window
uv venv --python 3.12
uv pip install numpy
uv run --no-project python itm_model.py "the cat sat on the"

These commands create an isolated .venv, install NumPy there, and run the model. They work in PowerShell, macOS and Linux shells without activating the environment. uv can download Python 3.12 if it is missing. The three files must stay together so the script can find the configuration and weights.

To rebuild the computation yourself, follow Reproduce the Explorer’s forward pass. For the larger model, use the GPT-2 replication’s pinned requirements, which also include its CPU package index.

Create a separate project when you want to change the model or add tests:

Terminal window
uv init --bare --python 3.12 model-experiments
cd model-experiments
uv add numpy
uv add --dev ruff ty

Add your Python files to this directory. Then run:

Terminal window
uv run ruff check .
uv run ruff format --check .
uv run ty check

Use uv run ruff format . when you want to apply formatting. Ruff finds lint issues and handles formatting; ty checks types. Neither validates the mathematical result. Compare your outputs with known traces and include a control that should change the result.

Commit pyproject.toml, uv.lock and .python-version with your experiment. Someone cloning it can use uv sync --locked and run the same commands. Keep .venv/ out of version control. When sharing a measured claim, record the model revision, inputs, package versions and numerical tolerance as well.

Spotted a mistake, a confusing explanation or a broken widget? Report a problem with this page

Methods & evidence · Run locally

Free for noncommercial use. Text CC BY-NC-SA 4.0, code PolyForm Noncommercial. Source on GitHub · How to contribute