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.
Run the NumPy reference
Section titled “Run the NumPy reference”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:
uv venv --python 3.12uv pip install numpyuv 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.
Develop your own experiment
Section titled “Develop your own experiment”Create a separate project when you want to change the model or add tests:
uv init --bare --python 3.12 model-experimentscd model-experimentsuv add numpyuv add --dev ruff tyAdd your Python files to this directory. Then run:
uv run ruff check .uv run ruff format --check .uv run ty checkUse 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.
Official references
Section titled “Official references”Spotted a mistake, a confusing explanation or a broken widget? Report a problem with this page