You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes DistillationLoss's empty-sequence validation for multidimensional TensorDict batches. The previous mask.any() check collapsed both the token and remaining batch dimensions after the outer iteration, so an empty sequence was accepted whenever a sibling sequence selected at least one token.
The validation now reduces only the token dimension and checks every resulting per-sequence flag. The same token-dimension value is reused by the existing KL and sequence-length reductions. A transformers-free regression covers a [2, 2] batch where exactly one sequence is empty.
An accepted empty sequence silently received a zero loss because normalization clamps the zero token count. Grouped LLM batches such as [prompts, generations] could therefore hide malformed masks instead of raising the documented validation error.
Bug fix (non-breaking change which fixes an issue)
Validation
python -m pytest test/llm/test_llm_objectives.py -q -k "distillation and not integration": 16 passed
python -m pytest test/llm/test_llm_objectives.py -q -m "not slow and not integration": 69 passed, 1 skipped, 2 deselected
Repository pre-commit hooks on both changed files: all passed (ufmt, flake8, pydocstyle, pyupgrade, codespell, autoflake, docstring checks, and file checks)
git diff --check: passed
Checklist
I have read the CONTRIBUTING guide and CLAUDE.md.
I have updated the tests accordingly.
My change requires a documentation update.
I have updated the documentation accordingly.
AI assistance disclosure
I used OpenAI Codex to help inspect the implementation, construct and run the pristine reproduction, search issues/pull requests/commits and the introducing PR for duplicates, implement the focused fix and regression, run validation, and draft this pull request. I reviewed the diff and reproduced the behavior before submission.
Note: Links to docs will display an error until the docs builds have been completed.
✅ No Failures
As of commit 0fe08b2 with merge base d7659c7 ():
💚 Looks good so far! There are no failures yet. 💚
This comment was automatically generated by Dr. CI and updates every 15 minutes.
meta-claBot
added
the
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
label
Aug 9, 2026
Reviewed rebased head 0fe08b2dd1 plus the current PR discussion (there are no human review threads yet). The fix is correctly scoped: each as_list=True mask retains the remaining batch dimensions plus tokens, so reducing dim=tensordict.ndim - 1 handles only the token axis and the outer .any() detects an empty sequence anywhere in the residual batch. Reusing the same axis for KL summation and normalization keeps those paths aligned. The new multidimensional regression passes locally (1 passed), and git diff --check is clean. No blocking finding from this review.
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
BugFixCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.llm/LLM-related PR, triggers LLM CI testsObjectives
2 participants
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.
Description
Fixes
DistillationLoss's empty-sequence validation for multidimensional TensorDict batches. The previousmask.any()check collapsed both the token and remaining batch dimensions after the outer iteration, so an empty sequence was accepted whenever a sibling sequence selected at least one token.The validation now reduces only the token dimension and checks every resulting per-sequence flag. The same token-dimension value is reused by the existing KL and sequence-length reductions. A transformers-free regression covers a
[2, 2]batch where exactly one sequence is empty.Closes #4081
Motivation and Context
An accepted empty sequence silently received a zero loss because normalization clamps the zero token count. Grouped LLM batches such as
[prompts, generations]could therefore hide malformed masks instead of raising the documented validation error.Types of changes
Validation
python -m pytest test/llm/test_llm_objectives.py -q -k "distillation and not integration": 16 passedpython -m pytest test/llm/test_llm_objectives.py -q -m "not slow and not integration": 69 passed, 1 skipped, 2 deselectedgit diff --check: passedChecklist
AI assistance disclosure
I used OpenAI Codex to help inspect the implementation, construct and run the pristine reproduction, search issues/pull requests/commits and the introducing PR for duplicates, implement the focused fix and regression, run validation, and draft this pull request. I reviewed the diff and reproduced the behavior before submission.