bridge.models.gemma.gemma4_builder#

Model builders for Gemma 4 text models.

Both builders construct the same modules, in the same order, as the legacy Gemma4DenseProvider and Gemma4ModelProvider.

Module Contents#

Classes#

Gemma4DenseModelBuilder

Construct Gemma 4 dense text models on MCore GPTModel.

Gemma4ModelBuilder

Construct Gemma 4 MoE text models on MCore GPTModel.

Functions#

gemma4_moe_layer_spec

Return the Gemma 4 MoE block spec for a builder config or its transformer config.

_install_softcapped_output_layer

_split_rotary_base

Data#

API#

bridge.models.gemma.gemma4_builder._DENSE_DUAL_ROPE_FIELDS#

(‘sliding_window_rope_base’, ‘full_attention_rope_base’, ‘full_attention_rope_partial_factor’)

bridge.models.gemma.gemma4_builder.gemma4_moe_layer_spec(
config: megatron.training.models.gpt.GPTModelConfig | megatron.bridge.models.transformer_config.TransformerConfig,
) → megatron.core.transformer.ModuleSpec#

Return the Gemma 4 MoE block spec for a builder config or its transformer config.

bridge.models.gemma.gemma4_builder._install_softcapped_output_layer(
model: megatron.core.models.gpt.GPTModel,
config: megatron.bridge.models.transformer_config.TransformerConfig,
) → None#
bridge.models.gemma.gemma4_builder._split_rotary_base(
rotary_base: Any,
) → tuple[Any, Any]#
class bridge.models.gemma.gemma4_builder.Gemma4DenseModelBuilder#

Bases: megatron.bridge.models.gpt.gpt_builder.GPTModelBuilder

Construct Gemma 4 dense text models on MCore GPTModel.

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.gpt.GPTModel#

Build a Gemma 4 dense GPTModel with dual RoPE, per-layer embeddings and shared KV.

Parameters:
  • pg_collection – Process groups used for distributed construction.

  • pre_process – Whether to build the embeddings. Defaults to True.

  • post_process – Whether to build the output layer. Defaults to True.

  • vp_stage – Virtual pipeline stage; Gemma 4 dense supports none.

Returns:

The constructed model.

class bridge.models.gemma.gemma4_builder.Gemma4ModelBuilder#

Bases: megatron.bridge.models.gpt.gpt_builder.GPTModelBuilder

Construct Gemma 4 MoE text models on MCore GPTModel.

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.gpt.GPTModel#

Build a Gemma 4 MoE GPTModel with dual RoPE, scaled embeddings and K=V tying.

Parameters:
  • pg_collection – Process groups used for distributed construction.

  • pre_process – Whether to build the embeddings; defaults to the first pipeline stage.

  • post_process – Whether to build the output layer; defaults to the last pipeline stage.

  • vp_stage – Virtual pipeline stage.

Returns:

The constructed model stage.

bridge.models.gemma.gemma4_builder.__all__#

[‘Gemma4DenseModelBuilder’, ‘Gemma4ModelBuilder’, ‘gemma4_moe_layer_spec’]