torch.cuda.memory_stats β€” PyTorch 2.7 documentation (original) (raw)

torch.cuda.memory_stats(device=None)[source][source]ΒΆ

Return a dictionary of CUDA memory allocator statistics for a given device.

The return value of this function is a dictionary of statistics, each of which is a non-negative integer.

Core statistics:

For these core statistics, values are broken down as follows.

Pool type:

Metric type:

In addition to the core statistics, we also provide some simple event counters:

The caching allocator can be configured via ENV to not split blocks larger than a defined size (see Memory Management section of the Cuda Semantics documentation). This helps avoid memory fragmentation but may have a performance penalty. Additional outputs to assist with tuning and evaluating impact:

The caching allocator can be configured via ENV to round memory allocations in order to reduce fragmentation. Sometimes the overhead from rounding can be higher than the fragmentation it helps reduce. The following stat can be used to check if rounding adds too much overhead:

Parameters

device (torch.device or int, optional) – selected device. Returns statistics for the current device, given by current_device(), if device is None (default).

Return type

dict[str, Any]