bridge.models.qwen.modeling_qwen4_exp.model#

Qwen4-Exp integration with the unmodified Megatron-Core Hybrid decoder.

Module Contents#

Classes#

Qwen4ExpLayerSubmodules

Core layer submodules plus the model-specific lexical embedding.

Qwen4ExpTransformerLayer

Inject PLE before reading the gated residual streams.

Qwen4ExpGatedDeltaNet

Keep the SiLU convolution while using a separate sigmoid output gate.

Qwen4ExpHybridStack

Core hybrid execution with Qwen4-Exp’s learned output stream mixer.

_Qwen4ExpMultimodalRotaryEmbedding

Adapt explicit VLM positions to HybridModel’s rotary invocation.

Qwen4ExpHybridModel

Prepare lexical inputs and residual streams for the Core Hybrid decoder.

API#

class bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpLayerSubmodules#

Bases: megatron.core.transformer.transformer_layer.TransformerLayerSubmodules

Core layer submodules plus the model-specific lexical embedding.

per_layer_embedding: megatron.core.transformer.spec_utils.ModuleSpec | type#

None

class bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpTransformerLayer(
config: megatron.bridge.models.qwen.modeling_qwen4_exp.model_config.Qwen4ExpTransformerConfig,
submodules: bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpLayerSubmodules,
*args: object,
**kwargs: object,
)#

Bases: megatron.core.transformer.transformer_layer.HyperConnectionTransformerLayer

Inject PLE before reading the gated residual streams.

Initialization

_forward_attention(
hidden_states: torch.Tensor,
*args: object,
**kwargs: object,
) → tuple[torch.Tensor, torch.Tensor | None]#
class bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpGatedDeltaNet#

Bases: megatron.core.ssm.gated_delta_net.GatedDeltaNet

Keep the SiLU convolution while using a separate sigmoid output gate.

_apply_gated_norm(x: torch.Tensor, gate: torch.Tensor) → torch.Tensor#
class bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpHybridStack(
config: megatron.bridge.models.qwen.modeling_qwen4_exp.model_config.Qwen4ExpTransformerConfig,
submodules: megatron.core.models.hybrid.hybrid_block.HybridStackSubmodules,
**kwargs: object,
)#

Bases: megatron.core.models.hybrid.hybrid_block.HybridStack

Core hybrid execution with Qwen4-Exp’s learned output stream mixer.

Initialization

class bridge.models.qwen.modeling_qwen4_exp.model._Qwen4ExpMultimodalRotaryEmbedding#

Bases: megatron.bridge.models.qwen_vl.modelling_qwen3_vl.rope.Qwen3VLMultimodalRotaryEmbedding

Adapt explicit VLM positions to HybridModel’s rotary invocation.

position_ids: torch.Tensor | None#

None

packed_seq_params: megatron.core.packed_seq_params.PackedSeqParams | None#

None

forward(
max_seq_len: int,
*,
packed_seq: bool = False,
cp_group: torch.distributed.ProcessGroup | None = None,
) → torch.Tensor#
class bridge.models.qwen.modeling_qwen4_exp.model.Qwen4ExpHybridModel(
config: megatron.bridge.models.qwen.modeling_qwen4_exp.model_config.Qwen4ExpTransformerConfig,
*,
rotary_percent: float,
rotary_base: int,
mrope_section: list[int] | None = None,
seq_len_interpolation_factor: float | None = None,
**kwargs: object,
)#

Bases: megatron.core.models.hybrid.hybrid_model.HybridModel

Prepare lexical inputs and residual streams for the Core Hybrid decoder.

Every hybrid position keeps the original attention-plus-MLP decoder block, including both gated residual connections. PLE layer numbers and checkpoint parameter indices therefore remain unchanged.

Initialization

classmethod estimate_flops(
config: megatron.bridge.models.qwen.modeling_qwen4_exp.model_config.Qwen4ExpModelConfig,
*,
total_real_tokens_in_batch: float,
seqlen_squared_sum_in_batch: float,
) → float#

Compose block forward estimates and logits without allocating a model.

forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor,
attention_mask: torch.Tensor | None,
decoder_input: torch.Tensor | None = None,
labels: torch.Tensor | None = None,
inference_context: megatron.core.inference.contexts.BaseInferenceContext | None = None,
runtime_gather_output: bool | None = None,
*,
packed_seq_params: megatron.core.packed_seq_params.PackedSeqParams | None = None,
padding_mask: torch.Tensor | None = None,
**kwargs: object,
) → torch.Tensor#

Execute the language decoder, retaining raw IDs for PLE with VLM embeddings.