Skip to content

Commit 421f40e

Browse files
milesialpytorchmergebot
authored andcommitted
Use binary units for CUDA memory summary (#91854)
To reduce confusion, use for example `KiB` instead of `KB` since we're talking powers of 2 and not 10. https://en.wikipedia.org/wiki/Byte#Multiple-byte_units ``` import torch x = torch.zeros(1024 * 1024, dtype=torch.uint8, device='cuda') print(torch.cuda.memory_summary()) ``` ``` |===========================================================================| | PyTorch CUDA memory summary, device ID 0 | |---------------------------------------------------------------------------| | CUDA OOMs: 0 | cudaMalloc retries: 0 | |===========================================================================| | Metric | Cur Usage | Peak Usage | Tot Alloc | Tot Freed | |---------------------------------------------------------------------------| | Allocated memory | 1024 KiB | 1024 KiB | 1024 KiB | 0 B | | from large pool | 0 KiB | 0 KiB | 0 KiB | 0 B | | from small pool | 1024 KiB | 1024 KiB | 1024 KiB | 0 B | |---------------------------------------------------------------------------| | Active memory | 1024 KiB | 1024 KiB | 1024 KiB | 0 B | | from large pool | 0 KiB | 0 KiB | 0 KiB | 0 B | | from small pool | 1024 KiB | 1024 KiB | 1024 KiB | 0 B | |---------------------------------------------------------------------------| ``` Pull Request resolved: #91854 Approved by: https://github.com/ngimel
1 parent b8057aa commit 421f40e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

torch/cuda/memory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,15 @@ def memory_summary(device: Union[Device, int] = None, abbreviated: bool = False)
453453
stats = memory_stats(device=device)
454454

455455
def _format_size(sz, pref_sz):
456-
prefixes = ["B ", "KB", "MB", "GB", "TB", "PB"]
456+
prefixes = ["B ", "KiB", "MiB", "GiB", "TiB", "PiB"]
457457
prefix = prefixes[0]
458458
for new_prefix in prefixes[1:]:
459459
if pref_sz < 768 * 1024:
460460
break
461461
prefix = new_prefix
462462
sz //= 1024
463463
pref_sz /= 1024
464-
return "{:7d} {}".format(sz, prefix)
464+
return "{:6d} {}".format(sz, prefix)
465465

466466
def _format_count(cnt, pref_cnt):
467467
prefixes = [" ", "K", "M"]

0 commit comments

Comments
 (0)