Skip to content

model_hooks

LiteRT frontend hook helpers and built-in hook registration.

Classes

Functions

apply_litert_model_hooks

apply_litert_model_hooks(model: 'litert.ModelT', *, model_path: Path, subgraph_index: int, hooks: list[LiteRtModelHook]) -> 'litert.ModelT'

Apply frontend-specific LiteRT hooks before AIR conversion.

Hooks may mutate the ModelT in place or return a replacement model. They run before the selected subgraph is flattened into AIR, so they can inspect and rewrite cross-subgraph control-flow structures such as WHILE.

register_default_litert_model_hooks

register_default_litert_model_hooks(registry: Registry[str, LiteRtModelHook]) -> None

Register built-in LiteRT model hooks into registry.

Hooks run in registration order before the selected subgraph is flattened into AIR. Callers that need the raw WHILE graph can drop a hook through a RegistryContext customizer.

Parameters:

  • registry

    (Registry[str, LiteRtModelHook]) –

    Registry receiving the built-in hooks.