2727from megatron .core .utils import WrappedTensor , deprecate_inference_params
2828from megatron .core .models .gpt .gpt_model import GPTModel
2929from megatron .core .process_groups_config import ProcessGroupCollection
30+ from megatron .core .transformer .multi_token_prediction import MultiTokenPredictionBlock
3031
3132from .language_transformer_block import LanguageTransformerBlock
3233
@@ -100,7 +101,7 @@ def apply_interleaved_mrope(self, freqs, mrope_section):
100101 freqs_t [..., idx ] = freqs [dim , ..., idx ]
101102 return freqs_t
102103
103- def forward (self , position_ids : torch .Tensor , mrope_section : List [int ]) -> Tensor :
104+ def forward (self , position_ids : torch .Tensor , mrope_section : List [int ], cp_group : Optional [ torch . distributed . ProcessGroup ] = None ) -> Tensor :
104105 """Forward pass of multimodal RoPE embedding.
105106
106107 Args:
@@ -137,10 +138,12 @@ def forward(self, position_ids: torch.Tensor, mrope_section: List[int]) -> Tenso
137138
138139 # shape (seq_length, bs, 1, 2 * dim)
139140 emb = emb [..., None , :].transpose (0 , 1 ).contiguous ()
140- if self .cp_group is not None and self .cp_group .size () > 1 :
141+ if cp_group is None :
142+ cp_group = self .cp_group
143+ if cp_group is not None and cp_group .size () > 1 :
141144 # slice rotary_pos_emb along sequence dimension and select the parition of the current
142145 # CP rank
143- emb = get_pos_emb_on_this_cp_rank (emb , 0 , self . cp_group )
146+ emb = get_pos_emb_on_this_cp_rank (emb , 0 , cp_group )
144147 return emb
145148
146149class Qwen3VLLanguageModule (GPTModel ):
@@ -228,6 +231,7 @@ def __init__(
228231 vocab_size = self .vocab_size ,
229232 max_sequence_length = self .max_sequence_length ,
230233 position_embedding_type = position_embedding_type ,
234+ tp_group = self .pg_collection .tp ,
231235 )
232236 if self .position_embedding_type == 'mrope' and not self .config .multi_latent_attention :
233237 self .rotary_pos_emb = Qwen3VLLanguageRotaryEmbedding (
@@ -258,7 +262,7 @@ def __init__(
258262
259263 if self .mtp_process :
260264 self .mtp = MultiTokenPredictionBlock (
261- config = self .config , spec = self .mtp_block_spec , vp_stage = vp_stage
265+ config = self .config , spec = self .mtp_block_spec , vp_stage = vp_stage , pg_collection = self . pg_collection
262266 )
263267
264268 # Output
@@ -314,18 +318,20 @@ def forward(self, input_ids, position_ids, attention_mask,
314318 visual_pos_masks : Optional [torch .Tensor ] = None ,
315319 deepstack_visual_embeds : Optional [list [torch .Tensor ]] = None ,
316320 * , inference_params = None ,
317- loss_mask = None ):
321+ loss_mask = None ,
322+ padding_mask : Optional [torch .Tensor ] = None ):
318323
319324 inference_context = deprecate_inference_params (inference_context , inference_params )
320325
321- decoder_input , rotary_pos_emb , rotary_pos_cos , rotary_pos_sin , sequence_len_offset = (
326+ decoder_input , rotary_pos_emb , rotary_pos_cos , rotary_pos_sin , sequence_len_offset , padding_mask = (
322327 self ._preprocess (
323328 input_ids = input_ids ,
324329 position_ids = position_ids ,
325330 decoder_input = decoder_input ,
326331 inference_context = inference_context ,
327332 packed_seq_params = packed_seq_params ,
328- )
333+ padding_mask = padding_mask ,
334+ )[:6 ]
329335 )
330336
331337 # Run decoder.
@@ -338,6 +344,7 @@ def forward(self, input_ids, position_ids, attention_mask,
338344 rotary_pos_sin = rotary_pos_sin ,
339345 packed_seq_params = packed_seq_params ,
340346 sequence_len_offset = sequence_len_offset ,
347+ padding_mask = padding_mask ,
341348 visual_pos_masks = visual_pos_masks ,
342349 deepstack_visual_embeds = deepstack_visual_embeds ,
343350 ** (extra_block_kwargs or {}),
0 commit comments