[WIP] Skip gradient collection for documents with fewer than two tokens#188
Open
luciaquirke wants to merge 3 commits intomainfrom
Open
[WIP] Skip gradient collection for documents with fewer than two tokens#188luciaquirke wants to merge 3 commits intomainfrom
luciaquirke wants to merge 3 commits intomainfrom
Conversation
Documents with fewer than 2 tokens cannot produce valid next-token labels, and length-0 documents create [N, 0] tensors that hang the model forward pass. In multi-GPU settings, the bin-packing allocator assigned all zero-length documents to a single rank (cost = 0), causing that rank to stall while others completed their NCCL all-reduces. Fix by filtering <2-token documents from batch allocation in _allocate_batches_world. Their gradient index entries remain at the pre-initialized zero value, preserving the dataset-to-score index mapping. Also chunk the normalizer backward hook to process the outer-product matmul in groups of 32 documents, preventing OOM when many short documents pack into a single batch (P tensor scales as N * O * I). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This reverts commit 6b5befe.
Documents with fewer than 2 tokens cannot produce valid next-token labels. Length-0 documents also create [N, 0] tensors that hang the model forward pass. The bin-packing cost function (max_len * batch_size) gives these documents cost=0, assigning all of them to a single rank and causing NCCL timeouts in multi-GPU runs. Skip them in _allocate_batches_world; their gradient index entries remain at the pre-initialized zero value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
I wonder if a print statement is sufficient here? It might silently drown under all the other stuff we log |
Collaborator
Author
What do you suggest? |
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.
Documents with fewer than 2 tokens cannot produce valid next-token labels, and length-0 documents create [N, 0] tensors that hang the model forward pass. In multi-GPU settings, the bin-packing allocator assigned all zero-length documents to a single rank (cost = 0), causing that rank to stall while others completed their NCCL all-reduces.
Fix by filtering <2-token documents from batch allocation in _allocate_batches_world. Their gradient index entries remain at the pre-initialized zero value, preserving the dataset-to-score index mapping.
TODO:
we probably want to update the "is_written" column in scores at these positions to reflect the fact that the 0. gradient is intentional. We may also want to raise an error here unless a --skip_empty_docs flag is given.