mojolearn.ByteLanguageModelConfig#
- class mojolearn.ByteLanguageModelConfig(batch=2, length=32, d_model=32, n_heads=4, n_kv=2, head_dim=8, intermediate=64, n_layers=2, vocab_size=256, chunked_lm_head_v2=False)[source]#
Bases:
objectDimensions of the decoder language model: batch, sequence, layers, vocabulary.
An immutable description of the model and training-batch shape passed to
LanguageModelTrainerasshape=. Each layer has an attention block with grouped key/value heads and a gated MLP, each with its own norm weight; the model has a token embedding and a separate output head. The defaults describe the small published byte-level model (vocabulary 256).LanguageModelConfigis the same class.- Parameters:
batch (int, default 2) – Sequences per training step.
length (int, default 32) – Tokens per sequence, at most 8192.
d_model (int, default 32) – Model width; must equal
n_heads * head_dim.n_heads (int, default 4) – Attention heads; must be divisible by
n_kv.n_kv (int, default 2) – Key/value heads.
head_dim (int, default 8) – Width of each head; must be even.
intermediate (int, default 64) – MLP hidden width.
n_layers (int, default 2) – Number of decoder layers.
vocab_size (int, default 256) – Token vocabulary size (256 for bytes;
corpus.n_vocabfor a BPE corpus frommojolearn.lm_corpus).chunked_lm_head_v2 (bool, default False) – Compute the loss and its gradient over bounded vocabulary panels, which bounds memory for large vocabularies. Logits from prediction still cover the full vocabulary.
- Raises:
ValueError – If a dimension is not an integer in [1, 2**20], the head constraints above are not met, or the shape exceeds signed 32-bit indexing.
- Parameters:
Examples
>>> import mojolearn >>> shape = mojolearn.LanguageModelConfig(batch=1, length=128, d_model=64, n_heads=4, ... n_kv=2, head_dim=16, intermediate=128, ... n_layers=2, vocab_size=256) >>> shape.n_total > 0 True
- __init__(batch=2, length=32, d_model=32, n_heads=4, n_kv=2, head_dim=8, intermediate=64, n_layers=2, vocab_size=256, chunked_lm_head_v2=False)#
Methods
to_dict()The fields as a dict, suitable for
ByteLanguageModelConfig(**d).Attributes
batchchunked_lm_head_v2d_modelhead_dimintermediatelengthn_headsn_kvn_layers2 + 9 * n_layers.Total number of parameters.
The dimensions as a tuple of ints, in field order.
Start offset of every parameter tensor in the flat parameter vector, plus the total.
The name of every parameter tensor, in packing order.
The shape of every parameter tensor, in packing order.
The name of the training profile this shape selects.
vocab_size- property native_shape#
The dimensions as a tuple of ints, in field order.
- property profile#
The name of the training profile this shape selects.
- property parameter_shapes#
The shape of every parameter tensor, in packing order.
- property n_tensors#
2 + 9 * n_layers.- Type:
Number of parameter tensors
- property parameter_names#
The name of every parameter tensor, in packing order.
- property offsets#
Start offset of every parameter tensor in the flat parameter vector, plus the total.
- property n_total#
Total number of parameters.