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
I'll investigate the Megatron OPD losses code and how
preprocess_bshd_engineexpects its inputs so we can fix the dimension mismatch. - Assistant
I'll verify nested tensor shapes and test the fix.
- Assistant
Using each nested tensor element's trailing dimensions to fix
preprocess_bshd_enginefor multi-dimensional inputs like top-k log probs. - Assistant
The issue is that
preprocess_bshd_engineonly handled 1D nested tensors ([batch, seqlen]), while OPD teacher top-k tensors are 2D per sequence ([batch, seqlen, topk]).Root cause
In
compute_forward_kl_topk(Megatron path), whendata_format == "bshd":teacher_topk_log_probs_cp_split, *_ = preprocess_bshd_engine(teacher_topk_log_probs, pre_process=True) teacher_topk_ids_cp_split, *_ = preprocess_bshd_engine(teacher_topk_ids, pre_process=True)teacher_topk_log_probsis a nested tensor with elements shaped[seqlen, 64], butpreprocess_bshd_enginealways allocated[batch, local_seqlen]output buffers. Assigninginput_ids[i]([seqlen, 64]) intoinput_ids_bshd[i, :seqlen_i]([seqlen]) caused the shape error.The THD path already worked because preserves trailing dimensions via .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.