Skip to content

fix(opd): return empty teacher_log_probs slice when response_length == 0 - #2588

Open
Antonioxv wants to merge 1 commit into
THUDM:mainfrom
Antonioxv:fix/opd-empty-response-slice
Open

Antonioxv wants to merge 1 commit into
THUDM:mainfrom
Antonioxv:fix/opd-empty-response-slice

Conversation

@Antonioxv

Copy link
Copy Markdown

Fixes #2587

What does this PR do?

Fixes a zero-length slicing bug in slime/rollout/on_policy_distillation.py (post_process_rewards), and adds a CPU unit test in tests/test_opd_post_process_rewards.py (NUM_GPUS = 0).

Root Cause

When sample.response_length == 0, t_log_prob[-response_length:] evaluates t_log_prob[0:] and slices all prompt teacher log-probabilities instead of an empty torch.float32 tensor.

teacher_log_probs = [
    t_log_prob[-response_length:] if response_length > 0 else t_log_prob[:0]
    for t_log_prob, response_length in zip(teacher_log_probs, response_lengths, strict=False)
]

Verification

  • Confirmed sample.teacher_log_probs.shape == torch.Size([3]) before the fix on a 4-token prompt with response_length=0.
  • Ran python tests/test_opd_post_process_rewards.py -> 2 passed in 0.04s (response_length=0 + mixed [2, 0, 3] batch).

@Antonioxv
Antonioxv marked this pull request as ready for review December 2, 2026 17:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OPD post_process_rewards slices full prompt when response_length == 0

1 participant