Skip to content

families

families

The registry: config.model_type -> the family's standardization toolkit.

A toolkit is one module in this package, named after the model_type (from the checkpoint's config) it covers. Each declares:

  • RENAME: an nnsight rename dict mapping the family's own module names onto the standard vocabulary (see nnterp). Keys are resolved relative to every envoy in the tree, so a single-component key such as "attn" binds in every block that has one, and a key that does not resolve anywhere is simply skipped.
  • Layer, Attention and Mlp, and LinearAttention on a hybrid: the family's own subclasses of nnterp.components's, overriding only what its forward spells differently.
  • ENVOYS: an nnsight envoys dict keying those on the family's module types (envoys= matches by type first, then by path, in a native or an alias spelling).

The module's name is its model_type (gemma3_text.py covers gemma3_text), and that is the whole registry: lookup imports nnterp.families.<model_type> on first use, so import nnterp loads no transformers modeling module. To add a family, write the module beside these; to add one from elsewhere, or to override a shipped one, pass it to register with the model types it covers; to use one for a single load, pass it as StandardizedTransformer(..., family=) or StandardizedVLLM(..., family=). A model_type with neither gets default, the best-effort family, with a warning; it is not one of known.

Another engine's families live in a package of their own under this one, named after the engine: nnterp.families.vllm.llama is vLLM's implementation of the llama model type, looked up with lookup("llama", engine="vllm"). There is no default on another engine: a type it has no family for raises.

REGISTRY module-attribute

REGISTRY: dict[str, ModuleType] = {}

UnsupportedFamily

Bases: ValueError

No toolkit standardizes the checkpoint: it has no family, and the best-effort default cannot standardize it.

covers

covers(model_type: str, engine: str | None = None) -> bool

Whether a family covers model_type on engine: one registered for it, or a module of that name here.

resolve

resolve(config: Any, engine: str | None = None) -> ModuleType

The family for a config: its own model_type where a family covers it, else its text model's.

A multimodal wrapper usually resolves through its text_config (Llava to llama, Gemma 3 to gemma3_text). A wrapper with a family of its own, named after the wrapper, resolves to that family whatever its text config says: Kimi K2.5's text config says deepseek_v3 from transformers 5.20, and kimi_k25 covers it.

known

known(engine: str | None = None) -> list[str]

The shipped families' model types: the modules in this package (but default, which covers none), or in engine's package under it.

lookup

lookup(model_type: str, engine: str | None = None) -> ModuleType

The toolkit for model_type: a registered one, else the module of that name, imported on first use.

With neither, on transformers, default with a warning: its standardization is a name guess, which it checks at load (raising UnsupportedFamily when the guess finds no blocks, embedding, final norm or head, or the stream's shape does not hold), and what a guess cannot make safe (the contributions, the logit lens) is unavailable.

engine names another engine's families ("vllm"): its modules are their own implementations of the same checkpoints, with their own classes and conventions, so they are their own toolkits under the same name. default is written against transformers' modules, so it is no fallback there: an engine's lookup with no family raises.

RAISES DESCRIPTION
UnsupportedFamily

on another engine, when there is neither.

register

register(family: ModuleType, *model_types: str, engine: str | None = None) -> ModuleType

Add a family toolkit without editing this package.

family is any module (or object) with RENAME and ENVOYS like the ones here. It covers model_types; with none given, the type its __name__ names, as a shipped module's file name does (register(my_pkg.zamba) covers zamba). The types go into REGISTRY, which lookup consults before the shipped modules, so a user can also override a shipped family. engine registers it as that engine's (engine="vllm"). Returns family.

RAISES DESCRIPTION
TypeError

when no type is given and family has no __name__ (a types.SimpleNamespace): pass them, register(ns, "zamba").

all_families

all_families(engine: str | None = None) -> list[ModuleType]

Every shipped family, imported: for tooling and tests, not for a load.

__getattr__

__getattr__(name: str) -> ModuleType

nnterp.families.<model_type>: the family module, imported on first use.

__dir__

__dir__() -> list[str]

Submodules