Fix boolean tensor memory accounting - #4236
Open
Excelius-Wang wants to merge 1 commit into
Open
Conversation
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.
dtype_byte_size(torch.bool)currently returns 1/8, but PyTorch boolean tensors use one byte per element. This undercounts boolean buffers in module-size estimates and can place tensors within amax_memorybudget that is smaller than their actual storage.Return 1 for
torch.bool, reusing the existing sizing and placement paths. Keep the packedCustomDtypeestimates unchanged.A small randomly initialized GPT-2 using Transformers 4.57.6 has two 1 MiB boolean attention buffers. Before this change, Accelerate reports 511,496 bytes for a model with 2,346,504 bytes of parameters and buffers; after the change, the estimate matches. This demonstrates the storage-accounting issue, not a measured production OOM. GPT-2 in Transformers 5.15.1 no longer has these registered buffers.
Validation:
make qualityandgit diff --checkpass.Scope: this corrects boolean tensor accounting. The existing module-splitting path can separately omit a module's own buffers when
no_split_module_classesis not supplied; this patch does not address that behavior or guarantee a hard runtime memory bound.