OPD losses error for Megatron when i use megatron for compute losses the code position…
- User
OPD losses error for Megatron when i use megatron for compute losses the code position is: /verl/trainer/distillation/megatron/losses.py Line 248 teacher_topk_log_probs_cp_split, *_ = preprocess_bshd_engine(teacher_topk_log_probs, pre_process=True)
the teacher_topk_log_probs is [b, length, 64] but preprocess_bshd_engine this function need [n, length] dim, so error happens
Interface
No new interfaces are introduced.
- Assistant
Investigating the Megatron OPD loss path and how
preprocess_bshd_engineexpects its inputs. - Assistant
Extending
preprocess_bshd_engineto handle trailing dimensions (e.g. top-k), matchingpreprocess_thd_engine. - Assistant
Fixing
position_idsexpansion for tensors with trailing dimensions. - Assistant
The failure came from
preprocess_bshd_engineassuming each nested sequence is 1D[length], while OPD teacher top-k tensors are 3D[batch, length, topk](e.g.[b, length, 64]).preprocess_thd_enginealready supports trailing dimensions viainput_ids.shape[1:], butpreprocess_bshd_enginedid not.Fix
Updated
preprocess_bshd_engineinverl/models/mcore/util.pyto:- Read trailing dimensions from each nested row (
input_ids[0].shape[1:], e.g.(64,)for top-k). - Allocate the output as
[batch, local_seqlen, *trailing_dims]instead of[batch, local_seqlen]. - Pad along the sequence dimension for CP splitting with the correct trailing shape.
- Expand
position_idsto match trailing dims (the oldexpand_as(input_ids_bshd)failed wheninput_ids_bshdwas 3D).
No changes were needed in
megatron/losses.py— the calls there are correct oncepreprocess_bshd_enginehandles multi-dimensional nested tensors.Verified locally with mocked Megatron for:
- 1D nested tensors
[b, length](unchanged behavior)
- Read trailing dimensions from each nested row (
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.