bridge.models.ernie.ernie55_builder#

Builder for ERNIE 5.5: Megatron-Core’s Hybrid builder constructing :class:Ernie55HybridModel stages.

Module Contents#

Classes#

Ernie55ModelBuilder

Build every pipeline (and virtual pipeline) stage of ERNIE 5.5 as :class:Ernie55HybridModel.

Data#

API#

bridge.models.ernie.ernie55_builder.__all__#

[‘Ernie55ModelBuilder’]

class bridge.models.ernie.ernie55_builder.Ernie55ModelBuilder(
model_config: megatron.bridge.models.ernie.ernie55_config.Ernie55ModelConfig,
)#

Bases: megatron.bridge.models.hybrid.hybrid_builder.BridgeHybridModelBuilder

Build every pipeline (and virtual pipeline) stage of ERNIE 5.5 as :class:Ernie55HybridModel.

Each stage is the ERNIE model class, whether or not it holds the output layer: its constructor applies the ERNIE contract (eager fp32 hyper-connections, the multimax head and its gradient-norm group, which every stage must register, SD-MTP sharing and the H/D attention check) before DDP, the optimizer or a checkpoint load see the parameters.

Meth:

build_distributed_models additionally rejects the wrappers that would split the SD-MTP shared parameters (Megatron-FSDP, torch FSDP2, meta-device initialization) before building, and checks after wrapping that every MTP alias is still the decoder’s parameter.

Initialization

_resolve_hybrid_stack_spec() → megatron.core.transformer.ModuleSpec#

The ERNIE 5.5 stack spec: :func:ernie55_hybrid_stack_spec, or the configured ERNIE spec.

Raises:

TypeError – If hybrid_stack_spec resolves to a stack other than :class:Ernie55HybridStack.

build_model(
pg_collection: megatron.core.process_groups_config.ProcessGroupCollection,
pre_process: bool | None = None,
post_process: bool | None = None,
vp_stage: int | None = None,
) → megatron.core.models.hybrid.hybrid_model.HybridModel#

Build one ERNIE 5.5 stage.

Parameters:
  • pg_collection – Process groups used to construct the model.

  • pre_process – Whether this stage holds the embedding (default: first pipeline stage).

  • post_process – Whether this stage holds the output layer (default: last pipeline stage).

  • vp_stage – Virtual pipeline stage to construct.

Returns:

An :class:Ernie55HybridModel stage.

Raises:

ValueError – If vocab_size is unset or the configuration would pad the vocabulary.

build_distributed_models(
pg_collection: megatron.core.process_groups_config.ProcessGroupCollection,
ddp_config: Any = None,
*args: Any,
**kwargs: Any,
) → list[megatron.core.models.hybrid.hybrid_model.HybridModel]#

Build and wrap every stage; keep the SD-MTP parameters shared.

Arguments are Megatron-Core’s HybridModelBuilder.build_distributed_models arguments.

Raises:
  • ValueError – If SD-MTP is combined with Megatron-FSDP, torch FSDP2 or meta-device initialization.

  • RuntimeError – If wrapping replaced a shared MTP parameter.