Imports, types, dimensions and contracts of the NumPy glassllm engine.
glassllm 0.1.03 min read · estimate
Choose an entry level
The glassllm package exports 12 names: Config, GenStep, GlassLM, LANGUAGES, STEPS, StepRecord, Tensor, Tokenizer, Tracer, load_pretrained, no_grad and __version__. They cover configuration, generation, loading and model inspection. Mathematical operations, layers, optimizers and training helpers are imported from their submodules.
This example uses random weights to check contracts. To generate with trained weights, use model, tokenizer = load_pretrained("en"). Library publication remains deferred, so installation uses the checkout or a local wheel.
Import paths
Module
Symbols and purpose
glassllm.config
Config: dimensions, limits and validation
glassllm.model
GlassLM, GenStep, next_token_probs: logits, loss and generation
Names starting with _ are internal helpers. This is not the PyTorch module interface: Module has no .train(), .eval(), .to() or .state_dict(). The engine runs on NumPy; the browser runs the same Python through Pyodide.
Shape and indexing conventions
Symbol
Meaning
Included model default
B
batch
1 in the interface and trace
n
positions received by this call
up to 128
m
key positions, including cache
up to 128
V
vocabulary size
1024
d
model dimension
128
Hq, Hkv
query and key/value heads
4 and 2
dk = d / Hq
head dimension
32
IDs and targets are integer indices; positions, layers and heads are zero based. forward accepts (n,) or (B,n) IDs and returns a (B,n,V)Tensor. The batch axis remains even when the input was a list. The tracer removes a unit batch axis: a full attention record is (Hq,n,m), or (n,m) after head selection. The tokenizer does not automatically add BOS/EOS.
Types, state and errors
Tensor.data is a numpy.ndarray; Tensor.grad starts as None. Parameters usually use float32; derivative examples may use float64. There is no GPU device, symbolic type system or second-order differentiation. Direct NumPy operations on .data are outside the graph.
forward, loss and generate do not update weights. train and AdamW.step modify the existing object; forward also fills a supplied cache. generate owns its cache and creates a fresh tracer for each token when trace=True.
Explicit validation primarily raises ValueError, TypeError, KeyError and FileNotFoundError. Incompatible shapes, out-of-range IDs and malformed files can also raise NumPy or JSON errors. The library does not wrap every internal exception in one error class. Because generate is a generator, its validation runs only when iteration advances.