Fix loss_fn_outputs right-aligned slicing in Tinker API path#1367
Merged
CharlieFRuan merged 3 commits intomainfrom Mar 23, 2026
Merged
Fix loss_fn_outputs right-aligned slicing in Tinker API path#1367CharlieFRuan merged 3 commits intomainfrom
CharlieFRuan merged 3 commits intomainfrom
Conversation
After PR #1285 unified the padding layout to left-pad (right-aligned response tensors), the loss_fn_outputs extraction in the Tinker API path still sliced with [:valid_len] (left-aligned), returning padding/prompt logprobs instead of actual response logprobs. Change [:valid_len] to [-valid_len:] at all 4 affected sites in both the FSDP worker and Megatron worker (SFT and RL paths each). Add CPU unit tests that verify right-aligned slicing returns the correct response values and would fail with the old left-aligned slicing. Fixes #1304 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loss_fn_outputsextraction using[:valid_len](left-aligned) on right-aligned tensors, returning padding/prompt logprobs instead of actual response values[-valid_len:]at all 4 affected sites: FSDP worker SFT path, FSDP worker RL path, Megatron worker SFT path, Megatron worker RL pathDetails
After #1285 unified the padding layout to left-pad (right-aligned response tensors), the
loss_fn_outputsextraction in the Tinker API path still used[:valid_len], which grabs values from the left (padding region) instead of the right (actual response region).Example with
action_mask = [0, 0, 1, 1, 1]andaction_log_probs = [pad, pad, real_0, real_1, real_2]:[:3]→[pad, pad, real_0](WRONG)[-3:]→[real_0, real_1, real_2](CORRECT)Affected entrypoints: The Tinker API (
skyrl.tinker.api) — the standard RL training loop discardsloss_fn_outputsand is unaffected.Note that #1285 does not affect the existing bug in the tinker entrypoint, since it calls _to_training_batch(), which also does right padding.
Fixes #1304
🤖 Generated with Claude Code