Shortcuts

torch.cuda.memory_allocated

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

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

Parameters

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

Return type

int

注意

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