Memory Viz Y-Axis Uses SI Units (GB) Instead of Binary Units (GiB)
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.5k
- PR merge metrics
- PR metrics pending
Description
## 🐛 Describe the bug
The CUDA memory visualization tool (`torch/utils/viz/MemoryViz.js`) has an inconsistency between how memory sizes are displayed in tooltips vs. the y-axis labels:
- **Tooltips**: Use binary units (KiB, MiB, GiB) with base 1024 ✅
- **Y-axis labels**: Use SI units (K, M, G) with base 1000 ❌
This causes a ~7.4% discrepancy, which is confusing to users. For example, a 1 GiB allocation (1,073,741,824 bytes) shown in a tooltip would appear at approximately `1.07G` on the y-axis instead of `1G`.
(This issue was found by @nanz-nv originally.)
## Root Cause
In `torch/utils/viz/MemoryViz.js`:
1. The `formatSize()` function correctly uses binary units (1024-based):
```javascript
function formatSize(num) {
const units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi'];
for (const unit of units) {
if (Math.abs(num) < 1024.0) {
return `${num.toFixed(1)}${unit}B (${orig} bytes)`;
}
num /= 1024.0;
}
// ...
}
```
2. However, the y-axis uses `d3.format('.3s')` which applies SI prefixes (1000-based):
```javascript
const yaxis = axisLeft(yscale).tickFormat(d3.format('.3s'));
```
## Proposed Fix
Create a new `formatAxisSize()` function that reuses `formatSize()` for consistency:
```javascript
function formatAxisSize(num) {
// Compact format for y-axis labels, reusing formatSize logic
// but without the parenthetical bytes suffix
return formatSize(num).split(' ')[0];
}
```
Then update the y-axis formatter:
```javascript
const yaxis = axisLeft(yscale).tickFormat(formatAxisSize);
```
## Why This Matters
- GPU memory is inherently binary (powers of 2)
- Users expect consistent units when correlating visual position with tooltip values
- Memory profilers and tools (nvidia-smi, OS memory monitors) universally use binary units for RAM/VRAM
## Versions
- PyTorch: main branch
- File: `torch/utils/viz/MemoryViz.js`
cc @ptrblck @msaroufim @eqy @jerryzh168 @tinglvv @nWEIdia @robieta @chaekit @guotuofeng @guyang3532 @dzhulgakov @davidberard98 @briancoutinho @sraikund16 @sanrise @mwootton @zdevito
### Versions
```
Collecting environment information...
PyTorch version: 2.10.0a0+b558c986e8.nv25.11
Is debug build: False
CUDA used to build PyTorch: 13.0
ROCM used to build PyTorch: N/A
OS: Ubuntu 24.04.3 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 3.31.6
Libc version: glibc-2.39
Python version: 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-119-generic-x86_64-with-glibc2.39
Is CUDA available: True
CUDA runtime version: 13.0.88
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA Graphics Device
Nvidia driver version: 580.95.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.15.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.15.0
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A
CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 52 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 32
On-line CPU(s) list: 0-31
Vendor ID: AuthenticAMD
Model name: AMD EPYC 9124 16-Core Processor
CPU family: 25
Model: 17
Thread(s) per core: 2
Core(s) per socket: 16
Socket(s): 1
Stepping: 1
Frequency boost: enabled
CPU(s) scaling MHz: 46%
CPU max MHz: 3711.9141
CPU min MHz: 1500.0000
BogoMIPS: 6000.12
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization: AMD-V
L1d cache: 512 KiB (16 instances)
L1i cache: 512 KiB (16 instances)
L2 cache: 16 MiB (16 instances)
L3 cache: 64 MiB (4 instances)
NUMA node(s): 1
NUMA node0 CPU(s): 0-31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Vulnerable
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Not affected; BHI: Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Versions of relevant libraries:
[pip3] intel-openmp==2021.4.0
[pip3] mkl==2021.1.1
[pip3] mkl-devel==2021.1.1
[pip3] mkl-include==2021.1.1
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.1.0
[pip3] nvidia-cudnn-frontend==1.15.0
[pip3] nvtx==0.2.13
[pip3] onnx==1.18.0
[pip3] onnx-ir==0.1.12
[pip3] onnxscript==0.5.6
[pip3] optree==0.17.0
[pip3] pytorch-triton==3.5.0+gitde3506d2
[pip3] tbb==2021.13.1
[pip3] torch==2.10.0a0+b558c986e8.nv25.11
[pip3] torch_tensorrt==2.10.0a0
[pip3] torchao==0.14.0+git
[pip3] torchdata==0.11.0
[pip3] torchprofile==0.0.4
[pip3] torchtitan==0.1.0
[pip3] torchvision==0.25.0a0+7a13ad0f
[pip3] triton_kernels==1.0.0+nv25.11
[conda] Could not collect
```
Contributor guide
Assessment
This issue has not been assessed yet.