Skip to content

standardized

standardized

Standardized, what every standardized model shares, and StandardizedTransformer, the TransformersModel one.

Logits module-attribute

Logits = Float[Tensor, f'{BATCH} {SEQ} {VOCAB}']

NextTokenProbs module-attribute

NextTokenProbs = Float[Tensor, f'{BATCH} {VOCAB}']

Tokens module-attribute

Tokens = Int[Tensor, f'{BATCH} {SEQ}']

StandardizedProperty

StandardizedProperty(fget: Callable[[Any], Any])

A read-only value of the model that a family may define instead.

Wraps the standard implementation. On read, a function of the same name in the model's family module wins (def num_kv_heads(model): ... in falcon.py), so a family whose config spells a size its own way keeps that knowledge beside its names and values, and the implementation here stays the plain case.

fget instance-attribute

fget = fget

__set_name__

__set_name__(owner: type, name: str) -> None

__get__

__get__(obj: Any, owner: type | None = None) -> Any

__set__

__set__(obj: Any, value: Any) -> None

StandardizedCapability

StandardizedCapability(fget: Callable[[Any], Any])

Bases: StandardizedProperty

A method of the model that a family may define instead.

StandardizedProperty for a method: on attribute access, a function of the same name in the model's family module (def project_on_vocab(model, hidden): ... in cohere.py) is bound in place of the standard implementation, so a family whose model does something of its own keeps that beside its names and values, and the implementation here stays the plain case.

__get__

__get__(obj: Any, owner: type | None = None) -> Any

Standardized

What a standardized model is on any engine: a family, its sizes, its availability, and the methods over its values.

Mixed in ahead of the nnsight model class that runs the checkpoint (StandardizedTransformer over TransformersModel, nnterp.StandardizedVLLM over nnsight's VLLM). The leaf resolves family and hands its RENAME and ENVOYS to nnsight, and defines the root's values (logits, token_embeddings, ...), which are read where its engine keeps them. Everything here is written against the standard names and values only, so it holds on both.

family instance-attribute

family: ModuleType

layers instance-attribute

layers: Sequence[Layer]

embed_tokens instance-attribute

embed_tokens: Envoy

norm instance-attribute

norm: Envoy

lm_head instance-attribute

lm_head: Envoy

skip_layers

skip_layers(start: int, end: int, skip_with: Tensor | None = None) -> None

Skip blocks start through end inclusive.

The residual stream entering block start (or skip_with) is handed straight to block end + 1; the skipped blocks do not run. Negative indices count from the end. Inside a trace::

with model.trace(prompt):
    model.skip_layers(4, 7)
    logits = model.logits.save()

steer

steer(layers: int | list[int], vector: Tensor, factor: float = 1.0, token_positions: int | list[int] | slice | None = None, batch_index: int | None = None) -> None

Add factor * vector to the residual stream leaving the given blocks.

vector is [hidden_size] (or broadcastable to the selected slice). token_positions restricts the positions and batch_index the row; both default to all. The add is in place on layer_output, so it reaches the model. Inside a trace, with layers ascending.

probs_to_dict

probs_to_dict(probs: Tensor, k: int = 5) -> dict[str, float]

The k most likely tokens of one [vocab_size] distribution, as {token: probability}, most likely first.

Keyed by the decoded text. Where two or more of the k decode to the same text (partial UTF-8 byte tokens all decode to '�'), those entries are keyed by the tokenizer's raw vocabulary token instead (convert_ids_to_tokens, unique per id), with the id appended should even that repeat, so the dict always holds k entries, each with its own probability.

get_topk_closest_tokens

get_topk_closest_tokens(hidden: Tensor, k: int = 5) -> list[dict[str, float]]

The k most likely next tokens for each position of hidden, [..., hidden_size].

project_on_vocab then softmax, one {token: probability} per position, in row-major order over the leading dimensions.

support

support(layer: int | None = None) -> dict[str, Any]

Which standard values this checkpoint has, without running anything.

With layer, that block's values by dotted name ("layer_output", "self_attn.attention_probabilities", "mlp.mlp_output"): None when available, else the reason, including "no <module> module" when the block has no such module at all (a hybrid's blocks have either self_attn or linear_attn). Without, the root's values plus every block value: None when available on every block, else {layer: reason} for the blocks where it is not, so a hybrid reads as a short dict.

The tree decides what is listed: every child of a block that carries standard values (a Standard envoy) is walked under its standard name, so a value installed through envoys= or a registered family appears here as it does in the envoy's own Standard.support, and a module no block has (OPT's mlp) has no entry. A standard child of the root (the vision tower, Vision) is listed the same way, its own support rows under its standard name ("vision.image_features", "vision.self_attn.attention_probabilities"); a tower no image reaches lists none.

num_layers

num_layers() -> int

hidden_size

hidden_size() -> int

vocab_size

vocab_size() -> int

num_heads

num_heads() -> int

num_kv_heads

num_kv_heads() -> int

Key/value heads: num_key_value_heads under grouped-query attention, else num_heads.

head_dim

head_dim() -> int

Width of one attention head: the config's head_dim when it says (Qwen3, Gemma), else hidden_size // num_heads.

qk_head_dim

qk_head_dim() -> int

Width of one head's queries and keys: head_dim, unless the family separates them (DeepSeek's latent attention).

intermediate_size

intermediate_size() -> int

Width of the dense MLP's hidden layer, config.intermediate_size; a mixture of experts' experts are moe_intermediate_size wide.

StandardizedTransformer

StandardizedTransformer(repo_id: Any, *args: Any, family: ModuleType | None = None, rename: dict[str, str | list[str]] | None = None, envoys: dict | None = None, tokenizer_kwargs: dict | None = None, **kwargs: Any)

Bases: Standardized, TransformersModel

A causal language model whose modules answer to one set of names.

The checkpoint's config is read first (its model_type), the matching family toolkit is looked up in nnterp.families.REGISTRY, and the family's RENAME is handed to nnsight's rename so every envoy in the tree also answers to the standard name. The original names keep working: an alias is an extra attribute on the same envoy, not a replacement.

The family's ENVOYS wraps its decoder blocks in its Layer (layer_output), its attention modules in its Attention (attention_output, attention_probabilities) and its feed-forwards in its Mlp (mlp_output). The pattern is read inside the eager attention forward, so it is unavailable unless the model is loaded with attn_implementation="eager"; support says which values this checkpoint has. See nnterp.components.

PARAMETER DESCRIPTION
repo_id

A HuggingFace repo id, or an already-loaded torch.nn.Module (its own config is read then).

TYPE: Any

family

The family to use instead of the one looked up: a module or any object with RENAME and ENVOYS (and, like a shipped family, any size function or project_on_vocab it defines). It applies to this model only; the config is not read for it, and no model type is named or checked. nnterp.families.default itself runs its load-time check; a copy of it (a SimpleNamespace spread from its vars) does not, so call default.check(model) after the load.

TYPE: ModuleType | None DEFAULT: None

rename

Extra aliases, merged over the family's; a key given here wins.

TYPE: dict[str, str | list[str]] | None DEFAULT: None

envoys

Extra envoys= entries, merged over the family's ENVOYS (and nnsight's tensor-parallel envoys when the load shards); a key given here wins.

TYPE: dict | None DEFAULT: None

tokenizer_kwargs

Attributes to set on the loaded tokenizer, such as padding_side="left" or a pad_token.

TYPE: dict | None DEFAULT: None

**kwargs

Passed through to TransformersModel. task defaults to "text-generation"; pass task="image-text-to-text" to load a multimodal checkpoint as its wrapper, with its processor.

TYPE: Any DEFAULT: {}

Over the values, skip_layers, steer, project_on_vocab and get_topk_closest_tokens do the common things (see each). Inside a trace input_ids, input_size and attention_mask are what the model was called with.

The root envoy also answers for the whole model, inside a trace: logits (the logits the model returns, after any softcap or scale past the head), token_embeddings (the embedding's output) and next_token_probs; and outside one: the sizes num_layers, num_heads, num_kv_heads, head_dim, qk_head_dim, hidden_size, intermediate_size and vocab_size, read off the config, each a StandardizedProperty the family can define instead; project_on_vocab is a StandardizedCapability, a method the family can define the same way.

On an image-text-to-text checkpoint loaded with task="image-text-to-text" the text names keep their meaning (the language model's), the vision tower is vision (a Vision, with its own blocks, sizes and values, among them vision.image_token_mask and vision.image_features) and the last module before the scatter into the text stream is projector.

ATTRIBUTE DESCRIPTION
family

The toolkit module the checkpoint resolved to, or the family passed.

layers

The decoder blocks, each a Layer (the family's subclass).

TYPE: Sequence[Layer]

embed_tokens,

The embedding, the final norm, the unembedding.

TYPE: (norm, lm_head)

vision

The vision tower, a Vision, on a multimodal wrapper whose family names it.

TYPE: Vision

projector

The last module before the wrapper scatters the image features into the text stream.

TYPE: Envoy

RAISES DESCRIPTION
UnsupportedFamily

when no family is passed and none covers the checkpoint's model_type and the best-effort default family cannot standardize it either.

vision instance-attribute

vision: Vision

projector instance-attribute

projector: Envoy

family instance-attribute

family = family

add_prefix_false_tokenizer property

add_prefix_false_tokenizer: Any

The checkpoint's tokenizer loaded with add_prefix_space=False, so "word" and " word" differ.

What nnterp.prompt_utils.get_first_tokens uses. Loaded once, on first use.

logits

logits(value: Tensor) -> Any

token_embeddings

token_embeddings(value: Tensor) -> Residual

The embedding module's output, [batch, seq, hidden_size].

Positional embeddings and embedding norms (GPT-2's wpe, BLOOM's word_embeddings_layernorm) are applied after this by the families that have them. Assign to replace it.

final_norm_output

final_norm_output(value: Tensor) -> Residual

The final norm's output, [batch, seq, hidden_size]: the stream the head projects. Assign to replace it; in-place edits reach the model.

lm_head_output

lm_head_output(value: Tensor) -> Logits

lm_head's own output, [batch, seq, vocab_size].

logits is what the model returns; on most families the same tensor, on Gemma-2 the softcapped one. Assign to replace it; in-place edits reach the model.

next_token_probs

next_token_probs(value: Any) -> Any

project_on_vocab

project_on_vocab(hidden: Tensor) -> Tensor

Logits for a residual-stream tensor: the final norm, lm_head, and what the model does after the head.

The logit lens: applied to a block's layer_output it reads that layer's prediction; applied to the last block's, it is logits. Works inside a trace on a live value and outside on a saved one. After the head the plain case is the text config's final_logit_softcapping, when set (Gemma-2's own config; a multimodal checkpoint's text_config). A family whose model does something else there (Cohere multiplies by logit_scale, Granite divides by logits_scaling) defines def project_on_vocab(model, hidden) in its module, which is bound in this one's place (StandardizedCapability).

input_ids

input_ids(value: Tensor) -> Any

attention_mask

attention_mask(value: Tensor) -> Any

input_size

input_size(value: Any) -> Any

order

order(layer: int | None = None) -> dict[str, int]

The available values in forward order: name -> rank; equal ranks are one location, either read first.

With layer, that block's values by dotted name (support's), from 0. Without, the root's, numbered across the whole forward. Measured by a probe run on first use (nnterp.order.probe) and kept on the model, so route kernels (route_kernels, chunk_per_token) before the first.

rank

rank(name: str, layer: int | None = None) -> tuple[int, int]

Where a value falls in the forward: (side, r), which sorts reads into forward order.

side is -1 or num_layers for a root value served before or after the blocks, else layer; r is order's rank.

RAISES DESCRIPTION
Unavailable

the checkpoint has no such value (support gives the reason).

KeyError

there is no value of that name (a block value needs layer).