nanoscope
See what your language model learns. You write an nn.Module; nanoscope handles the
data, the training loop, evaluation, checkpoints and comparison against baselines.
It has four levels that share one core. The level changes what you see, never which code runs.
- Learn:
run(Model)with defaults. - Tinker: change a setting, or train several
seeds=, and compare. - Research: a
Studywith seeds, budgets, parameter matching and preregistration. - Extend: hooks, presets, optimizers and your own blocks.
You can use it as a library, from the command line, through an HTTP API (nanoscope serve), or
as a docker-compose stack with lessons and notebooks.
Install
pip install nanoscope-lab # the library
pip install "nanoscope-lab[server]" # plus the HTTP API (`nanoscope serve`)
To run it as a service (API, a worker, and optional notebooks and GPU worker), see Run it as a service.
From a clone, for development: uv sync --all-extras.
Learn
import torch.nn as nn
from nanoscope import compare, run
class Bigram(nn.Module):
def __init__(self, vocab_size: int, d_model: int = 32):
super().__init__()
self.token_embedding = nn.Embedding(vocab_size, d_model)
self.head = nn.Linear(d_model, vocab_size, bias=False)
def forward(self, idx):
return self.head(self.token_embedding(idx))
result = run(Bigram, preset="tinystories-5min") # about a minute on a laptop CPU
result.plot()
compare(result, "gpt2") # against a shipped 3-seed baseline
Work through the notebooks in order (marimo notebooks: pip install "nanoscope-lab[notebook]", then
marimo edit notebooks/marimo/01_first_model.py, or docker compose --profile notebook up):
01_first_model: write a bigram model and train it.02_gpt2: a real transformer.03_modern_block: RoPE, RMSNorm, SwiGLU, GQA, QK-norm, z-loss.04_ablations: which part matters, with seeds and confidence intervals.
Token data downloads from the Hub (RedhouaneLazib/nanoscope-tokens) when a preset has
it, and is tokenized locally otherwise. Everything is cached under ~/.nanoscope/data.
Research
See the research guide. The research program itself is in
docs/project-nanoscope.md.
Build models from blocks
GPT2 and Modern are short compositions of the blocks in nanoscope.blocks, and so can your
own models. See docs/blocks.md.
Guided lessons
Guided paths build the models step by step, with checks that say why. See
docs/learn.md: nanoscope learn list, learn start, learn check.
Run it as a service
nanoscope serve --worker cpu # the HTTP API on 127.0.0.1:8000 and one local worker
docker compose up # the same in containers: API on 127.0.0.1:8765, one CPU worker
docker compose --profile gpu up # plus an NVIDIA GPU worker
docker compose --profile notebook up # plus marimo notebooks on 127.0.0.1:8766
Anything that runs your code is a job for a worker; the API never runs it. See docs/server.md for the API and docs/deploy.md for compose, remote sign-in, backups and GPUs. The token is a remote login: keep it on loopback or behind an SSH tunnel or an HTTPS proxy.
Command line
nanoscope presets # available presets
nanoscope run nanoscope/models/gpt2.py:GPT2 --seeds 3
nanoscope compare modern gpt2 --preset tinystories-5min
nanoscope study studies/m1_ablation.py --devices cuda:0
nanoscope report studies/m1_ablation.py # writes experiments/<name>/
nanoscope bench modern --compile reduce-overhead # speed, and whether CPU or GPU is the limit
nanoscope status runs # what is running and how far along
nanoscope describe nanoscope/models/modern.py:Modern # shapes, params, FLOPs, memory per module
nanoscope graph my_model.py # a model file's architecture, without running it
nanoscope blocks # the blocks models are composed from
nanoscope prepare-data tinystories-5min # download or tokenize now
nanoscope publish-data tinystories-5min user/repo # upload tokens to a Hub dataset
Develop
uv sync --all-extras
make test # offline tests
make lint
make typecheck
make check # lint, typecheck, then test: what CI runs
Data credits
Tokens are derived from TinyStories (CDLA-Sharing-1.0) and FineWeb-Edu (ODC-By 1.0).
Metadata
Release files for nanoscope-lab 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nanoscope_lab-0.4.0.tar.gz | 439.3 kB | With provenance | Details for nanoscope_lab-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nanoscope_lab-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for nanoscope_lab-0.4.0-py3-none-any.whl |
Total release size: 744.5 kB
Release files / nanoscope_lab-0.4.0.tar.gz
| Download URL | nanoscope_lab-0.4.0.tar.gz |
|---|---|
| Size | 439.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5040a6e5e301823785c165ea5852ced12a9e6461e8803b93601e93bf1cf62efa
|
|
BLAKE2b-256 checksum How to use checksums |
4043d6d88a7a6abf14e458a785cbb7101e9e64d20f2cb97b658a457b8e977adc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logRelease files / nanoscope_lab-0.4.0-py3-none-any.whl
| Download URL | nanoscope_lab-0.4.0-py3-none-any.whl |
|---|---|
| Size | 305.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bae5a8ebab67475fa2b82f6755e2333faae5d44e191533033e35023024cfbc65
|
|
BLAKE2b-256 checksum How to use checksums |
3b0326b3309406d93849199c57e7b497612bbd5088c16a0fc0dc453adac3bbca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logSecurity for nanoscope-lab 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for nanoscope_lab-0.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.