Skip to main content

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.

  1. Learn: run(Model) with defaults.
  2. Tinker: change a setting, or train several seeds=, and compare.
  3. Research: a Study with seeds, budgets, parameter matching and preregistration.
  4. 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):

  1. 01_first_model: write a bigram model and train it.
  2. 02_gpt2: a real transformer.
  3. 03_modern_block: RoPE, RMSNorm, SwiGLU, GQA, QK-norm, z-loss.
  4. 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.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanoscope-lab 0.5.0
File Size Uploaded Provenance Actions
nanoscope_lab-0.5.0.tar.gz 2.6 MB With provenance Details for nanoscope_lab-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nanoscope-lab 0.5.0
File Interpreter ABI Platform Actions
nanoscope_lab-0.5.0-py3-none-any.whl Python 3 none any Details for nanoscope_lab-0.5.0-py3-none-any.whl

Total release size: 5.0 MB

Release files / nanoscope_lab-0.5.0.tar.gz

Download URL nanoscope_lab-0.5.0.tar.gz
Size 2.6 MB
Tags Source
SHA-256 checksum
How to use checksums
f5795d1ea270f15fbd096222d94a924c1ba549e15a03c1ecb15a39aea751e7de
BLAKE2b-256 checksum
How to use checksums
f13d6032b8ef4c683214470e0c5770c655d0b483a1e7234d06b9909791d4bb41
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 8, 2026.

Transparency log

Release files / nanoscope_lab-0.5.0-py3-none-any.whl

Download URL nanoscope_lab-0.5.0-py3-none-any.whl
Size 2.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
55268d8ee903626ab7f15dfecf95f802c77be8b1dcd274e1ad6cac9a5861e040
BLAKE2b-256 checksum
How to use checksums
396d0e7c40580d170aa2e139784b49a19e7aa8584652e5f7ac6646f1007a58e9
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 8, 2026.

Transparency log

Security for nanoscope-lab 0.5.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.

Select from 2 files

Attestation for nanoscope_lab-0.5.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 8, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page