bridge.models.ernie.ernie55_builder#
Builder for ERNIE 5.5: Megatron-Core’s Hybrid builder constructing :class:Ernie55HybridModel stages.
Module Contents#
Classes#
Build every pipeline (and virtual pipeline) stage of ERNIE 5.5 as :class: |
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.BridgeHybridModelBuilderBuild 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_modelsadditionally 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_specresolves 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,
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:
Ernie55HybridModelstage.- Raises:
ValueError – If
vocab_sizeis 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,
Build and wrap every stage; keep the SD-MTP parameters shared.
Arguments are Megatron-Core’s
HybridModelBuilder.build_distributed_modelsarguments.- Raises:
ValueError – If SD-MTP is combined with Megatron-FSDP, torch FSDP2 or meta-device initialization.
RuntimeError – If wrapping replaced a shared MTP parameter.