transformer_lens.model_bridge.supported_architectures.minicpm module¶
MiniCPM architecture adapter.
Supports MiniCPMForCausalLM checkpoints (trust_remote_code) with dense attention,
e.g. openbmb/MiniCPM4-0.5B and openbmb/MiniCPM-1B-sft-bf16. Opt-in InfLLM v2
sparse attention (a non-null sparse_config) is rejected.
- class transformer_lens.model_bridge.supported_architectures.minicpm.MiniCPMArchitectureAdapter(cfg: Any)¶
Bases:
ArchitectureAdapterArchitecture adapter for dense MiniCPM models (MiniCPMForCausalLM).
Llama-shaped (RMSNorm, RoPE incl. LongRoPE, GQA, gated SiLU MLP, tied embeddings) plus three muP scalings, all applied by the HF forward:
embeddings are multiplied by
scale_emb(hook_embed exposes the product);each sublayer output is multiplied by
scale_depth / sqrt(num_hidden_layers)before the residual add (hook_attn_out / hook_mlp_out expose the product);the final hidden state is divided by
hidden_size / dim_model_basebefore lm_head (reproduced by output_logits_scale).
Nothing is folded into weights: HF applies the scales on the raw and the processed path alike, and weight processing is linear, so it commutes.
Optional Parameters (may not exist in state_dict):¶
blocks.{i}.attn.b_Q/b_K/b_V/b_O - attention_bias=False on shipped models
blocks.{i}.mlp.b_in/b_gate/b_out - No bias on MLP projections
blocks.{i}.ln1.b, blocks.{i}.ln2.b, ln_final.b - RMSNorm has no bias
- __init__(cfg: Any) None¶
Initialize the MiniCPM architecture adapter.
- output_logits_scale() float¶
Match MiniCPM’s
lm_head(h / (hidden_size / dim_model_base))output path.lm_head is bias-free, so dividing its output equals dividing its input.
- prepare_loading(model_name: str, model_kwargs: dict) None¶
Patch the remote code’s transformers-v5 incompatibilities before loading.
- prepare_model(hf_model: Any) None¶
Rebuild the per-layer rotary tables meta-device loading leaves uninitialized.