ISSUE DESCRIPTION OPD losses error for Megatron when i use megatron for compute losses…
- User
ISSUE DESCRIPTION
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
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /verl, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the problematic file. Let's first check the overall structure.
- Assistant
Let me look at the specific file mentioned in the issue.
- Assistant
Let me find the correct path.
- Assistant
The correct path is
/verl/verl/trainer/distillation/megatron/losses.py. Let me open it. - Assistant
Let me see the full file to understand the issue better, particularly around line 248.
- Assistant
Let me see the rest of the file.
- Assistant
Let me see the rest of the file.
- Assistant
Now let me look at the
preprocess_bshd_enginefunction to understand what format it expects: - Assistant
Let me examine the
preprocess_bshd_enginefunction to understand what input shape it expects. - Assistant
Let me search for
preprocess_bshd_enginein this file. - Assistant
Let me examine the
preprocess_bshd_enginefunction to understand what it expects and why it's failing with the shape [b, length, 64]. - Assistant
Let me continue reading the function to understand the issue better.
- Assistant
Now I understand the issue. The
preprocess_bshd_enginefunction expects a nested tensor where each element is 1D (shape(seq_len,)), butteacher_topk_log_probsandteacher_topk_idsare 3D tensors with shape(bsz, seqlen, topk)where each nested element is 2D(seq_len, topk). The function creates output tensors of shape(batch_size, local_max_seqlen)and tries to assign 2D slices into them, which causes a shape mismatch.Let me search for all callers of
preprocess_bshd_engineto understand the impact of any changes: - Assistant
Let me check what the input to
preprocess_bshd_enginelooks like in the model_forward.py: - Assistant
Let me look at
preprocess_thd_engineto see how it handles the nested tensors: - Assistant
Let me look at
preprocess_thd_engineto understand how it handles multi-dimensional nested tensors: - Assistant
Let me continue reading
preprocess_thd_engineto see how it handles nested tensors with extra dimensions: - Assistant
Let me continue reading the function:
- Assistant
Now I have a clear understanding of the issue. Let me read the full
preprocess_bshd_enginefunction to implement the fix: - Assistant
Let me see the rest of the function:
- Assistant
Now I have a clear understanding of the issue. The
preprocess_bshd_enginefunction assumes the input nested tensor has 1D elements (shape(seq_len,)), butteacher_topk_log_probsandteacher_topk_idshave 2D elements (shape(seq_len, topk)). The function creates 2D output tensors(batch_size, local_max_seqlen)which can't accommodate the extra dimension.The fix is to make
preprocess_bshd_enginehandle multi-dimensional nested tensor elements, similar to howpreprocess_thd_enginealready does.Let me implement the fix:
- Assistant
Let me verify the changes by scrolling through the modified section:
- Assistant
Good, the changes look correct. Now let me verify that the changes are backward-compatible by checking the git diff:
- Assistant
The diff looks clean and focused. Now let me create a test script to verify the fix works:
- Assistant
The import chain is complex and requires many megatron dependencies. Let me try a different approach - directly test the logic:
- Assistant
All tests pass. The fix correctly handles both1D and2D nested tensors. Let me also test with the exact scenario from the issue - a teacher_topk_log_probs with shape [b, length, 64]:
- Assistant
Now let me check if there are existing tests in the repository:
- Assistant
Let me check the relevant test files:
- Assistant
Let me check the other test file and see if it tests anything related to
preprocess_bshd_engine: - Assistant
Let me run the first test to see if it passes:
- Assistant
All existing tests pass. Let me also test the
need_rollpath to make sure it works correctly with extra dimensions: - Assistant
All tests pass. Let me clean up the temporary test files:
- Assistant
Let me verify the final state of the changes one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →