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 code and how
preprocess_bshd_engineexpects its inputs. - Assistant
Extending
preprocess_bshd_engineto handle trailing dimensions (e.g. topk), matchingpreprocess_thd_engine. - Assistant
The failure comes from a shape mismatch in
preprocess_bshd_engine: OPD passes teacher top-k tensors as nested[batch, seq_len, topk](e.g.[b, length, 64]), but that helper only handled 1D nested values[seq_len].preprocess_thd_enginealready supports trailing dims viashape = list(input_ids.shape[1:]);preprocess_bshd_enginedid not.Fix in
verl/models/mcore/util.py:- Trailing dims — Read
trailing_dimsfrom the first sequence (e.g.topk=64). - Output buffer — Allocate
(batch_size, local_max_seqlen, *trailing_dims)instead of(batch_size, local_max_seqlen). - CP padding — Pad with
torch.zeros(max_seqlen, *trailing_dims, ...)so padded sequences keep the top-k dimension. position_ids— Useexpand(batch_size, local_max_seqlen)instead of , which breaks when the tensor is 3D.
- Trailing dims — Read
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.