Skip to content

fix: print_gpu_mem divides by 2e30 instead of 2**30 - #2056

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
faisalhacks:fix-print-gpu-mem-gib
Nov 25, 2026
Merged

jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
faisalhacks:fix-print-gpu-mem-gib

Conversation

@faisalhacks

Copy link
Copy Markdown

Description

print_gpu_mem (exported from transformer_lens.utilities) divides the allocated byte count by 2e30 instead of 2**30. 2e30 is 2 x 10^30, not 2^30 bytes per GiB, so the function prints 0.0 GiB allocated on GPU. for any realistic allocation (a 3 GiB allocation prints 0.0). This changes the divisor to 2**30 so the number matches the "GiB" label.

Test: tests/unit/utilities/test_gpu_utils.py patches torch.cuda.memory_allocated (so it runs on CPU-only CI) and checks that 3 GiB prints 3.0 GiB and 2^29 bytes prints 0.5 GiB. Both tests fail on current dev (it prints 0.0).

No open issue for this; found by reading transformer_lens/utilities against the function's own output label.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Before / after, with torch.cuda.memory_allocated returning 3 GiB:

Before After
step ~ 0.0 GiB allocated on GPU. step ~ 3.0 GiB allocated on GPU.

Checklist:

  • I have commented my code, particularly in hard-to-understand areas (one-line change, no comment needed)
  • I have made corresponding changes to the documentation (none needed)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (only the new tests/unit/utilities/test_gpu_utils.py was run: 2 passed, and both fail without the fix; the full suite was not run)
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

🤖 Generated with Claude Code

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 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faisalhacks Excellent catch here, this is approved assuming it passes CI

@jlarson4
jlarson4 merged commit 1929d74 into TransformerLensOrg:dev Nov 25, 2026
61 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants