评价此页

torch.cuda.memory.memory_allocated#

torch.cuda.memory.memory_allocated(device=None)[源代码]#

返回给定设备上张量当前占用的 GPU 内存(以字节为单位)。

参数

device (torch.deviceint, 可选) – 选择的设备。如果 deviceNone(默认),则返回当前设备(由 current_device() 指定)的统计信息。

返回类型

int

注意

这可能比 nvidia-smi 显示的数量少,因为一些未使用的内存可能被缓存分配器占用,并且需要创建一些上下文到 GPU 上。有关 GPU 内存管理的更多详细信息,请参阅 内存管理