transformer_lens.model_bridge.supported_architectures.hrm_text module¶
HRM-Text architecture adapter.
HRM-Text (Sapient Intelligence) is a hierarchical two-timescale recurrent model: two transformer stacks (H = slow/planning, L = fast/computation) iterate in a nested loop with additive cross-stack coupling.
- Architecture notes:
Two physical stacks:
model.L_moduleandmodel.H_module, each withnum_layers_per_stacklayers. The stacks share identical internal structure but have separate weights.Recurrence: outer H-cycle iterates
H_cyclestimes; each iteration runsL_cyclesinner L-cycle iterations. Total forward passes through the layer stacks =H_cycles * (L_cycles + 1). The config fieldnum_hidden_layersis rewritten by HF tonum_layers_per_stack * H_cycles * (L_cycles + 1)to size the KV cache slots.Parameterless RMSNorm:
input_layernorm,post_attention_layernorm, and each stack’sfinal_normhave no learnable weight tensor.Sigmoid attention gate: each attention block has a
gate_projlinear that produces a per-head sigmoid gate applied to the attention output beforeo_proj. Delegated to HF; hookable viaL_blocks.{i}.attn.gate.hook_out.Embedding scale:
inputs_embeds *= embedding_scale(default ~39.19 for HRM-Text-1B). Applied at runtime byHrmTextModel.forward; must NOT be folded intoembed.weight— same reasoning asgemma1.py.PrefixLM mask: instruction tokens attend bidirectionally when
token_type_idsis passed to HF forward; delegated, not modeled by bridge.
- Known limitations:
Hooks on
L_blocks.{i}.*fireH_cycles * L_cyclestimes per forward; onH_blocks.{i}.*they fireH_cyclestimes. No per-iteration index is exposed; per-cycle disambiguation is future work.Compat-mode with PrefixLM (
token_type_ids) inputs is untested in v1.supports_fold_ln = False— parameterless norms cannot be folded.supports_center_writing_weights = False— block naming (L_blocks/H_blocksinstead ofblocks) is incompatible with weight-centering iteration overrange(cfg.n_layers).Requires
transformers >= 5.9.0at runtime.
- class transformer_lens.model_bridge.supported_architectures.hrm_text.HrmTextArchitectureAdapter(cfg: Any)¶
Bases:
ArchitectureAdapterArchitecture adapter for HRM-Text (Sapient Intelligence).
Exposes
L_blocks(fast/low-level stack) andH_blocks(slow/high-level stack) as sibling block lists. The nested recurrence loop is owned by HF’s forward; hooks fire once per iteration through the physical layers.- __init__(cfg: Any) None¶
Initialize the HRM-Text architecture adapter.
- applicable_phases: list[int] = [1, 2, 3]¶
- component_mapping: ComponentMapping | None¶
- setup_component_testing(hf_model: Any, bridge_model: Any = None) None¶
Set up rotary embedding references for HRM-Text component testing.
HRM-Text uses RoPE. We set the rotary_emb reference on all attention bridge instances so component-level isolation tests can run.
- supports_center_writing_weights = False¶
- supports_fold_ln = False¶
- uses_split_attention: bool¶
- weight_processing_conversions: Dict[str, ParamProcessingConversion | str] | None¶