Repository navigation
fix: print_gpu_mem divides by 2e30 instead of 2**30 - #2056
Merged
jlarson4 merged 1 commit intoNov 25, 2026
Merged
Conversation
print_gpu_mem divided torch.cuda.memory_allocated() by 2e30 (2 x 10^30) rather than 2**30, so it printed 0.0 GiB for any realistic allocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jlarson4
approved these changes
Nov 25, 2026
jlarson4
left a comment
Collaborator
There was a problem hiding this comment.
@faisalhacks Excellent catch here, this is approved assuming it passes CI
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.
Description
print_gpu_mem(exported fromtransformer_lens.utilities) divides the allocated byte count by2e30instead of2**30.2e30is2 x 10^30, not 2^30 bytes per GiB, so the function prints0.0 GiB allocated on GPU.for any realistic allocation (a 3 GiB allocation prints0.0). This changes the divisor to2**30so the number matches the "GiB" label.Test:
tests/unit/utilities/test_gpu_utils.pypatchestorch.cuda.memory_allocated(so it runs on CPU-only CI) and checks that 3 GiB prints3.0 GiBand 2^29 bytes prints0.5 GiB. Both tests fail on currentdev(it prints0.0).No open issue for this; found by reading
transformer_lens/utilitiesagainst the function's own output label.Type of change
Screenshots
Before / after, with
torch.cuda.memory_allocatedreturning 3 GiB:step ~ 0.0 GiB allocated on GPU.step ~ 3.0 GiB allocated on GPU.Checklist:
tests/unit/utilities/test_gpu_utils.pywas run: 2 passed, and both fail without the fix; the full suite was not run)🤖 Generated with Claude Code