bridge.models.ernie.configuration_ernie55#
Hugging Face PretrainedConfig for ERNIE 5.5 (model_type == "ernie5_5_moe", formerly "ernie5_5").
ERNIE 5.5 has no Hugging Face modeling code: the checkpoints carry a config.json whose
architectures entry is Ernie5_5_MoeForCausalLM. This class lets
AutoConfig.from_pretrained read such a checkpoint offline and lets recipes build a config
from scratch with AutoConfig.for_model("ernie5_5_moe", ...). Importing this module registers the
class with AutoConfig, together with :class:Ernie55LegacyConfig for checkpoints written before the
model_type became "ernie5_5_moe" ("ernie5_5", the reference implementation’s --model_type). Both read
the same keys and build the same model; exports write "ernie5_5_moe".
Architecture fields default to None: an ERNIE 5.5 config must spell them out, and the Bridge
mapping (:class:~megatron.bridge.models.ernie.ernie55_bridge.Ernie55Bridge) rejects a config that
omits one. Optional keys default to the value the reference implementation assumes when the key is
missing, so a config written without them means the same thing to both.
The reference implementation also reads n_routed_experts, first_k_dense_replace and
n_shared_experts under other names (:data:ERNIE55_REFERENCE_KEY_SPELLINGS); Bridge reads only these
keys. A config whose other spellings give a different value is rejected
(:func:check_ernie55_reference_key_spellings), because the two would build different models.
Module Contents#
Classes#
Configuration of the ERNIE 5.5 hybrid MoE language model ( |
|
|
Functions#
|
|
Reject a config that spells a key the way only the reference implementation reads it. |
Data#
Hugging Face |
|
|
|
Hugging Face |
|
Config keys the reference implementation also reads under other names: the names in its lookup order, where the first one present wins. Bridge reads only the key itself. |
API#
- bridge.models.ernie.configuration_ernie55.__all__#
[‘ERNIE55_ARCHITECTURE’, ‘ERNIE55_LEGACY_MODEL_TYPE’, ‘ERNIE55_MODEL_TYPE’, ‘ERNIE55_REFERENCE_KEY_S…
- bridge.models.ernie.configuration_ernie55.ERNIE55_MODEL_TYPE#
‘ernie5_5_moe’
Hugging Face
model_typeof ERNIE 5.5 checkpoints; Bridge exports write it.
- bridge.models.ernie.configuration_ernie55.ERNIE55_LEGACY_MODEL_TYPE#
‘ernie5_5’
model_typeof ERNIE 5.5 checkpoints written before"ernie5_5_moe"; Bridge still reads them.
- bridge.models.ernie.configuration_ernie55.ERNIE55_ARCHITECTURE#
‘Ernie5_5_MoeForCausalLM’
Hugging Face
architecturesentry of ERNIE 5.5 checkpoints.
- bridge.models.ernie.configuration_ernie55.ERNIE55_REFERENCE_KEY_SPELLINGS: dict[str, tuple[str, ...]]#
None
Config keys the reference implementation also reads under other names: the names in its lookup order, where the first one present wins. Bridge reads only the key itself.
- bridge.models.ernie.configuration_ernie55._config_value(config: Any, name: str) Any#
nameof a Hugging Face config object or a plain dict,Nonewhen absent.
- bridge.models.ernie.configuration_ernie55.check_ernie55_reference_key_spellings(config: Any) None#
Reject a config that spells a key the way only the reference implementation reads it.
The reference implementation also accepts other names for
n_routed_experts,first_k_dense_replaceandn_shared_expertsand takes the first name present (:data:ERNIE55_REFERENCE_KEY_SPELLINGS). Bridge reads only the key itself, so a config where the two readings differ would build a different model: withnum_shared_expertsalone, for example, the model would have no shared experts, and an import would skip their tensors.- Parameters:
config – The config’s keys as given (a dict), or a config object. :class:
Ernie55Configchecks its own keys before it fills in defaults.- Raises:
ValueError – If the reference reading of a key differs from the key’s own value.
- class bridge.models.ernie.configuration_ernie55.Ernie55Config(
- vocab_size: int | None = None,
- hidden_size: int | None = None,
- num_hidden_layers: int | None = None,
- intermediate_size: int | None = None,
- first_k_dense_replace: int | None = None,
- max_position_embeddings: int | None = None,
- rms_norm_eps: float | None = None,
- hidden_act: str = 'silu',
- activation_situ_beta: float = 1.0,
- activation_situ_linear_beta: float | None = None,
- tie_word_embeddings: bool = False,
- attention_bias: bool = False,
- mlp_bias: bool = False,
- attention_dropout: float = 0.0,
- initializer_range: float = 0.02,
- num_attention_heads: int | None = None,
- num_key_value_heads: int | None = None,
- head_dim: int | None = None,
- v_head_dim: int | None = None,
- qk_rope_head_dim: int | None = None,
- qk_nope_head_dim: int | None = None,
- q_lora_rank: int | None = None,
- o_groups: int | None = None,
- o_lora_rank: int | None = None,
- use_qk_norm: bool | None = None,
- rope_theta: float | None = None,
- compress_rope_theta: float | None = None,
- hca_rope_type: str = 'rope',
- rotary_scaling_factor: float | None = None,
- original_max_position_embeddings: int | None = None,
- sliding_window: int | None = None,
- compress_ratios: list[int] | None = None,
- csa_dense_mode: bool = True,
- hybrid_mla_attention: str = 'mha',
- hybrid_mla_num_attention_heads: int | None = None,
- hybrid_mla_q_lora_rank: int | None = None,
- hybrid_mla_kv_lora_rank: int | None = None,
- hybrid_mla_qk_nope_head_dim: int | None = None,
- hybrid_mla_qk_rope_head_dim: int | None = None,
- hybrid_mla_v_head_dim: int | None = None,
- mqa_latent_rope_adjacent_pairing: bool | None = None,
- index_n_heads: int = 64,
- index_head_dim: int = 128,
- index_topk: int = 2048,
- hc_mult: int | None = None,
- hc_sinkhorn_iters: int | None = None,
- hc_eps: float | None = None,
- n_routed_experts: int | None = None,
- num_experts_per_tok: int | None = None,
- moe_intermediate_size: int | None = None,
- n_shared_experts: int | None = None,
- scoring_func: str = 'sigmoid',
- norm_topk_prob: bool = True,
- routed_scaling_factor: float = 1.0,
- moe_latent_size: int | None = None,
- latent_moe_use_norm: bool = False,
- num_nextn_predict_layers: int = 0,
- mtp_shared_last_layer: bool = False,
- sigmoid_gate_fusion: bool = False,
- vha_rank: int | None = None,
- **kwargs: Any,
Bases:
transformers.configuration_utils.PretrainedConfigConfiguration of the ERNIE 5.5 hybrid MoE language model (
Ernie5_5_MoeForCausalLM).Layer
iof thenum_hidden_layersdecoder layers is an H layer (DeepSeek-V4 heavily compressed attention) whencompress_ratios[i] == 128and a D layer (latent MQA with DSA top-k, window and sink) when it is-2; its MLP is dense fori < first_k_dense_replaceand MoE after. Thenum_nextn_predict_layerstrailingcompress_ratiosentries describe the MTP depths. Each layer and each MTP depth carrieshc_multhyper-connection residual streams.- Parameters:
vocab_size – Vocabulary size (the model’s, not the tokenizer’s).
hidden_size – Hidden size.
num_hidden_layers – Decoder layers, MTP excluded.
intermediate_size – FFN width of the dense layers.
first_k_dense_replace – Number of leading dense (non-MoE) layers (0 when absent).
max_position_embeddings – Longest supported sequence.
rms_norm_eps – RMSNorm epsilon.
hidden_act – MLP activation,
"silu"(SwiGLU) or"situ"(SiTU-GLU).activation_situ_beta – SiTU gate clamp scale (
hidden_act="situ").activation_situ_linear_beta – SiTU up-projection clamp scale,
Nonefor no clamp.tie_word_embeddings – Whether the output layer shares the embedding (ERNIE 5.5:
False).attention_bias – Bias on the attention projections (ERNIE 5.5:
False).mlp_bias – Bias on the MLP projections (ERNIE 5.5:
False).attention_dropout – Attention dropout (ERNIE 5.5:
0).initializer_range – Standard deviation of the weight initialization.
num_attention_heads – H-layer attention heads.
num_key_value_heads – H-layer key/value heads (one shared latent head).
head_dim – H-layer head dimension (equal to
v_head_dim).v_head_dim – H-layer value and latent dimension.
qk_rope_head_dim – H-layer RoPE dimension.
qk_nope_head_dim – H-layer non-RoPE dimension,
head_dim - qk_rope_head_dim.q_lora_rank – H-layer query latent rank.
o_groups – H-layer grouped output projection groups.
o_lora_rank – H-layer grouped output projection rank per group.
use_qk_norm – Whether the q/kv latents are RMS-normalized (ERNIE 5.5:
True).rope_theta – RoPE base of the D layers and their indexer. A config with
rope_scalingcarries it inrope_parameters["rope_theta"]as well (transformers 5 storesrope_scalingunder that name), so that a savedconfig.jsonhas it where transformers 5 readers look for it.compress_rope_theta – RoPE base of the H layers.
hca_rope_type – H-layer RoPE type;
"rope"is plain RoPE.rotary_scaling_factor – YaRN factor of the H layers when
hca_rope_typeis YaRN;None(absent) readsrope_scaling["factor"], as the released checkpoints carry it, and is 1 when that is absent too.original_max_position_embeddings – YaRN original length of the H layers;
None(absent) readsrope_scaling["original_max_position_embeddings"], and is 4096 when that is absent too.sliding_window – Attention window of H and D layers.
compress_ratios – Per-layer compress ratio (
128H,-2D), decoder then MTP depths.csa_dense_mode – Whether compressed layers run without an indexer (H layers never have one).
hybrid_mla_attention – D-layer attention kind;
"mqa_dsa"is latent MQA with DSA top-k.hybrid_mla_num_attention_heads – D-layer attention heads.
hybrid_mla_q_lora_rank – D-layer query latent rank.
hybrid_mla_kv_lora_rank – D-layer key/value latent rank.
hybrid_mla_qk_nope_head_dim – D-layer non-RoPE query/key dimension.
hybrid_mla_qk_rope_head_dim – D-layer RoPE dimension.
hybrid_mla_v_head_dim – D-layer value dimension.
mqa_latent_rope_adjacent_pairing – Whether D-layer RoPE rotates adjacent channel pairs
(2k, 2k + 1)(True) or the two halves (False).None(absent) readsrope_interleave, the released checkpoints’ name for it, and isFalsewhen that is absent too.index_n_heads – D-layer indexer heads.
index_head_dim – D-layer indexer head dimension.
index_topk – D-layer indexer top-k.
hc_mult – Hyper-connection residual streams.
hc_sinkhorn_iters – Sinkhorn iterations of the hyper-connection mixing matrix.
hc_eps – Hyper-connection epsilon.
n_routed_experts – Routed experts per MoE layer.
num_experts_per_tok – Experts per token.
moe_intermediate_size – Expert FFN width.
n_shared_experts – Shared experts (their width is
n_shared_experts * moe_intermediate_size; 0 when absent).scoring_func – Router score function (ERNIE 5.5:
"sigmoid").norm_topk_prob – Whether the top-k gate values are normalized to sum to one.
routed_scaling_factor – Initial value of the learned per-expert routing scale.
moe_latent_size – Latent width of the routed experts,
Nonefor no latent MoE.latent_moe_use_norm – Whether latent MoE normalizes before the up-projection.
num_nextn_predict_layers – MTP depths.
mtp_shared_last_layer – Whether every MTP depth’s body shares the last decoder layer’s parameters (SD-MTP).
sigmoid_gate_fusion – Whether the attention output gate runs in fp32 and rounds once.
vha_rank – Rank of the VHA head post-mix of H and D layers. ERNIE 5.5 configs do not carry this key;
Nonemeans the architecture’s 16.**kwargs – Passed to :class:
~transformers.PretrainedConfig(token ids, dtype, …).
- Raises:
ValueError – If
kwargsspellsn_routed_experts,first_k_dense_replaceorn_shared_expertsthe way only the reference implementation reads it, with another value (:func:check_ernie55_reference_key_spellings).
Initialization
- model_type#
None
- class bridge.models.ernie.configuration_ernie55.Ernie55LegacyConfig(*args: Any, **kwargs: Any)#
Bases:
bridge.models.ernie.configuration_ernie55.Ernie55Config- Class:
Ernie55Configunder the earliermodel_type"ernie5_5", so thatAutoConfigreads such checkpoints; the keys and the model are the same.
Initialization
- model_type#
None