Skip to main content

glassllm — see every step of a small language model

glassllm

A small Transformer written from scratch in NumPy, built to be looked at. Follow a token through the model and inspect the equation, source code and values produced at each step.

PyPI version Python 3.10+ NumPy only MIT license

English · Português · Documentation

glassllm is an educational language model and Python library. Its decoder-only Transformer, tokenizer, automatic differentiation engine, training code and tracing tools are implemented with NumPy. Pretrained Portuguese and English models are included in the package.

Install

python -m pip install glassllm

The library supports Python 3.10 and later. NumPy is its only runtime dependency. The pretrained weights and tokenizers are included, so inference works immediately after installation.

Generate text

The glassllm command uses the included English model by default. Select pt for Portuguese.

glassllm --lang en generate "Alice was beginning to" --n 40
glassllm --lang pt generate "Capitu olhou para" --n 40

Use greedy decoding for repeatable output, or inspect the available model operations:

glassllm --lang en generate "Alice was beginning to" --n 40 --greedy
glassllm steps
glassllm trace "Alice was beginning to" --step attn.softmax --layer 0 --head 1

Inspect a calculation

Pass a Tracer to the model to record its actual intermediate values. Each record includes the equation, tensor shape and source location for a tagged operation.

from glassllm import Tracer, load_pretrained

model, tokenizer = load_pretrained("en")
token_ids = tokenizer.encode("Alice was beginning to")

tracer = Tracer()
model.forward(token_ids, trace=tracer)

step = tracer.get("attn.softmax", layer=0, head=1)
print(step.equation)
print(step.shape)
print(step.value)

List all traceable operations with glassllm steps. The same tagged calculations are explained in the library documentation.

What happens inside the model

Each prediction follows the same sequence of real calculations. The website can replay all 77 recorded operations for a prediction and lets you inspect their equations, tensors and source.

text → BPE tokens → embeddings → 4 Transformer blocks → logits → probabilities → next token
                                  attention + SwiGLU

The model uses causal self-attention, RoPE, grouped-query attention, an attention KV cache, RMSNorm, SwiGLU and tied input/output embeddings. It has 852,608 parameters and runs on CPU. It is deliberately small for learning; it is not intended for production text generation.

Interactive site and documentation

Try the live bilingual lab. It runs the same Python wheel in a Pyodide worker in your browser. The network view shows the complete model architecture, and slow motion steps through each recorded calculation at a readable pace.

The documentation includes 35 pages in each language, with interface guides, inference and training flowcharts, mathematical foundations, API reference, examples and research references:

Training and data

The included models were trained on public-domain books by Machado de Assis (Portuguese) and Lewis Carroll (English), sourced from Project Gutenberg. Training scripts and dataset preparation live in the repository. PyTorch is used only for development and parity checks; it is not installed when users install the library.

Contributing

The source code, tests, design notes and issue tracker are on GitHub. See the contribution guide before opening a pull request.

The interactive lab and complete library documentation are available now. The guided chapter experience is planned for a later phase.

License

The Python library is licensed under the MIT License. Documentation text is licensed under CC BY 4.0.

Metadata

Release files for glassllm 0.1.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 glassllm 0.1.0
File Size Uploaded
glassllm-0.1.0.tar.gz 3.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for glassllm 0.1.0
File Interpreter ABI Platform
glassllm-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 MB

Release files / glassllm-0.1.0.tar.gz

Download URL glassllm-0.1.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
556b302f4b7f86e62d9c793ed8e10a74bb88b9db2adae25f4aa892db7273bac5
BLAKE2b-256 checksum
How to use checksums
2f9ab66ddfd2120fbe391118dee880adf58324547194dbf61b7995f3a3336822
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 11, 2026.

Transparency log

Release files / glassllm-0.1.0-py3-none-any.whl

Download URL glassllm-0.1.0-py3-none-any.whl
Size 3.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1611801c031d0fc300dc89d3c07cd6be56dc1784e38e24422b2242d0761a333b
BLAKE2b-256 checksum
How to use checksums
e915e76cd8ca5aab92788e5e784200b75dd392bb47f1358d783ec9ef31ef6854
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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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