Teacher log-probs seems to be misaligned in loss compute
First, thanks for open-sourcing RLCSD method.
I may have found an issue in the distillation loss compute. The teacher signal seems to be derived from misaligned log-probs. Teacher batches are packed on the driver using the global-batch max response length, but the actor recovers the response window position using the micro-batch max response length. Whenever a micro-batch does not contain the globally longest response (which is almost every micro-batch after DP sharding + dynamic micro-batching), every teacher log-prob in it is shifted by the difference.
This means only when the global longest response happens to be included in the current micro batch, the teacher signal is aligned. Is this an expected behaviour? Thanks.
For detail:
Packing (driver side): _build_teacher_batch_from_prompts lays out every row as [left-pad | prompt | response | right-pad]. Responses always start at the same column max_prompt_len, and the tensor width is max_prompt_len + R_T where R_T is the max response length over the whole training batch:
https://github.com/THU-BPM/RLCSD/blob/a3c6e85ff8064006135b619249fcfe11190926b6/src/self_distill_main.py#L446-L497
Reading (actor side): _align_compact_response_tensor re-derives the window start as tensor_width − max(response_mask.sum()) over the current micro-batch:
https://github.com/THU-BPM/RLCSD/blob/a3c6e85ff8064006135b619249fcfe11190926b6/third_party/verl/verl/workers/actor/dp_actor.py#L561-L577
Thanks very much for the detailed report and for tracing the issue through both the driver-side packing and actor-side reading paths.
You are correct. The teacher responses were packed using the batch-level maximum response length, while the actor inferred the response start using the maximum response length of the current micro-batch. Since DP sharding and dynamic micro-batching preserve the original sequence width, this could shift the teacher log-probs whenever the current micro-batch did not contain a globally longest response. This was not expected behavior.
We have fixed the issue in commit 83bbd06 (https://github.com/THU-BPM/RLCSD/commit/83bbd069ee8a88bc8465cfb284c1bc50c7e592a7). The actor now derives each response’s predictor positions from the actual attended span instead of the micro-batch maximum response length.
We are currently working on rerunning the affected experiments to evaluate the impact, and we will update the reported results once the reruns are complete. Thanks again for catching this and providing such a clear analysis.