bridge.models.minimax_m3.modeling_minimax_m3_vl#
MiniMax-M3 vision-language model components.
The released MiniMax-M3 checkpoint predates the native Transformers model implementation. Keeping the small vision stack local lets the Bridge support the full published checkpoint across the supported Transformers range while preserving its legacy parameter namespace exactly.
Module Contents#
Classes#
Conv3d patch embedding used by the MiniMax-M3 vision tower. |
|
Build MiniMax-M3’s temporal/height/width rotary embeddings. |
|
CLIP-style self-attention with MiniMax-M3 3D RoPE, kept within each image or video segment. |
|
GELU feed-forward block for the vision tower. |
|
Pre-norm MiniMax-M3 vision transformer layer. |
|
Container preserving the checkpoint’s |
|
MiniMax-M3 Conv3d + 3D-RoPE vision encoder. |
|
Wrapper preserving the checkpoint’s |
|
Biased GELU MLP with the released projector parameter names. |
|
Frozen checkpoint tensor with a conventional |
|
Checkpoint-only state for one Lightning Indexer layer. |
|
MiniMax-M3 vision tower, projectors, and Megatron language model. |
Functions#
Read a field from either a config object or a plain dictionary. |
|
Data#
API#
- bridge.models.minimax_m3.modeling_minimax_m3_vl._config_value(
- config: Any,
- name: str,
- default: Any = None,
Read a field from either a config object or a plain dictionary.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionPatchEmbeddings(config: Any)#
Bases:
torch.nn.ModuleConv3d patch embedding used by the MiniMax-M3 vision tower.
Initialization
- forward(pixel_values: torch.Tensor) torch.Tensor#
Embed flattened image/video patches.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3Vision3DRotaryEmbedding(
- head_dim: int,
- *,
- theta: float,
- spatial_merge_size: int,
Bases:
torch.nn.ModuleBuild MiniMax-M3’s temporal/height/width rotary embeddings.
Initialization
- forward(
- grid_thw: torch.Tensor,
- *,
- device: torch.device,
- dtype: torch.dtype,
Return cosine and sine tables in spatial-merge patch order.
- bridge.models.minimax_m3.modeling_minimax_m3_vl._rotate_half(hidden_states: torch.Tensor) torch.Tensor#
- bridge.models.minimax_m3.modeling_minimax_m3_vl._apply_vision_rope(
- query: torch.Tensor,
- key: torch.Tensor,
- cosine: torch.Tensor,
- sine: torch.Tensor,
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionAttention(config: Any)#
Bases:
torch.nn.ModuleCLIP-style self-attention with MiniMax-M3 3D RoPE, kept within each image or video segment.
Initialization
- forward(
- hidden_states: torch.Tensor,
- position_embeddings: tuple[torch.Tensor, torch.Tensor],
- *,
- segment_lengths: collections.abc.Sequence[int],
Apply non-causal vision self-attention within each image or video segment.
- Parameters:
hidden_states – Packed patch features of shape
[batch, sequence, hidden].position_embeddings – Cosine and sine tables for the packed patches.
segment_lengths – Patch count of each image or video segment, in packing order. A patch attends only to patches of its own segment, as in Transformers’ MiniMax-M3-VL vision attention.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionMLP(config: Any)#
Bases:
torch.nn.ModuleGELU feed-forward block for the vision tower.
Initialization
- forward(hidden_states: torch.Tensor) torch.Tensor#
Apply the vision MLP.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionEncoderLayer(config: Any)#
Bases:
torch.nn.ModulePre-norm MiniMax-M3 vision transformer layer.
Initialization
- forward(
- hidden_states: torch.Tensor,
- position_embeddings: tuple[torch.Tensor, torch.Tensor],
- *,
- segment_lengths: collections.abc.Sequence[int],
Apply attention and MLP residual blocks.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionEncoder(config: Any)#
Bases:
torch.nn.ModuleContainer preserving the checkpoint’s
encoder.layersnamespace.Initialization
- forward(
- hidden_states: torch.Tensor,
- position_embeddings: tuple[torch.Tensor, torch.Tensor],
- *,
- segment_lengths: collections.abc.Sequence[int],
Run all vision transformer layers.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionModel(config: Any, *, spatial_merge_size: int)#
Bases:
torch.nn.ModuleMiniMax-M3 Conv3d + 3D-RoPE vision encoder.
Initialization
- forward(
- pixel_values: torch.Tensor,
- image_grid_thw: torch.Tensor,
Return unprojected patch features with shape
[1, patches, hidden].Each
image_grid_thwrow (an image or a video segment) is its own attention segment, so packed images and videos never attend to one another.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VisionTower(config: Any, *, spatial_merge_size: int)#
Bases:
torch.nn.ModuleWrapper preserving the checkpoint’s
vision_tower.vision_modelpath.Initialization
- forward(
- pixel_values: torch.Tensor,
- image_grid_thw: torch.Tensor,
Encode image or video patches.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3ProjectorMLP(
- input_size: int,
- hidden_size: int,
- output_size: int,
- *,
- bias: bool,
Bases:
torch.nn.ModuleBiased GELU MLP with the released projector parameter names.
Initialization
- forward(hidden_states: torch.Tensor) torch.Tensor#
Project vision features.
- class bridge.models.minimax_m3.modeling_minimax_m3_vl._MiniMaxM3CheckpointWeight(
- shape: tuple[int, ...],
- *,
- dtype: torch.dtype,
Bases:
torch.nn.ModuleFrozen checkpoint tensor with a conventional
weightleaf.Initialization
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3LightningIndexerState(config: Any)#
Bases:
torch.nn.ModuleCheckpoint-only state for one Lightning Indexer layer.
Megatron currently executes full causal attention instead of MiniMax-M3’s block-sparse selection path. Keeping these tensors as frozen parameters makes checkpoint conversion lossless without adding trainable parameters or coupling the shared conversion path to the source checkpoint.
Initialization
- class bridge.models.minimax_m3.modeling_minimax_m3_vl.MiniMaxM3VLModel(
- config: Any,
- pre_process: bool = True,
- post_process: bool = True,
- vp_stage: int | None = None,
- *,
- build_language_model: Callable[..., megatron.core.models.gpt.GPTModel] | None = None,
- pg_collection: megatron.core.process_groups_config.ProcessGroupCollection | None = None,
Bases:
megatron.core.transformer.module.MegatronModuleMiniMax-M3 vision tower, projectors, and Megatron language model.
- Parameters:
config – The provider, or the vision-language transformer config of a builder-backed model config. Either one carries the vision config, the token IDs, the projector shape and the Lightning Indexer layout.
pre_process – Whether to build the vision tower, the projectors and the embeddings.
post_process – Whether to build the language-model output layer.
vp_stage – Virtual pipeline stage.
build_language_model – Builds the language model from
pre_process,post_processandvp_stage. Defaults to the provider’sprovide_language_model().pg_collection – Process groups a builder passes. Defaults to the provider’s.
Initialization
- property decoder: torch.nn.Module | None#
Expose the text decoder for Megatron-Core inference inspection.
- set_input_tensor(
- input_tensor: torch.Tensor | list[torch.Tensor],
Set the pipeline input tensor on the language model.
- _project_vision(
- pixel_values: torch.Tensor,
- grid_thw: torch.Tensor,
- get_image_features(
- pixel_values: torch.Tensor,
- image_grid_thw: torch.Tensor,
Encode and project image patches into language-model tokens.
- get_video_features(
- pixel_values_videos: torch.Tensor,
- video_grid_thw: torch.Tensor,
Encode and project video patches into language-model tokens.
- static _scatter_features(
- inputs_embeds: torch.Tensor,
- input_ids: torch.Tensor | None,
- *,
- token_id: int,
- features: torch.Tensor | None,
- modality: str,
- forward(
- input_ids: torch.LongTensor | None = None,
- attention_mask: torch.Tensor | None = None,
- position_ids: torch.LongTensor | None = None,
- inputs_embeds: torch.Tensor | None = None,
- pixel_values: torch.Tensor | None = None,
- pixel_values_videos: torch.Tensor | None = None,
- image_grid_thw: torch.Tensor | None = None,
- video_grid_thw: torch.Tensor | None = None,
- mm_token_type_ids: 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,
- extra_block_kwargs: dict[str, Any] | None = None,
- *,
- inference_params: megatron.core.inference.contexts.BaseInferenceContext | None = None,
- loss_mask: torch.Tensor | None = None,
Run the multimodal forward path and return a CP-local mask when supplied.
- freeze(
- *,
- freeze_language_model: bool,
- freeze_vision_model: bool,
- freeze_vision_projection: bool,
Freeze selected VLM components.
- bridge.models.minimax_m3.modeling_minimax_m3_vl.__all__#
[‘MiniMaxM3LightningIndexerState’, ‘MiniMaxM3VLModel’, ‘MiniMaxM3VisionModel’]