PyTorch的"torch.cuda.max_memory_alated()"显示的结果与"nvidia-smi"不同?



我目前正在制作自己的自定义GPU报告,并使用torch.cuda.max_memory_allocated(device_id)来获得每个GPU使用的最大内存。但是,我注意到这个数字与我在此过程中运行nvidia-smi时的数字不同。

根据torch.cuda.max_memory_allocated的文档,输出的整数是字节的形式。从我在网上搜索到的将字节数转换为千兆字节数,你应该把它除以1024 ** 3。我现在做的是round(max_mem / (1024 ** 3), 2)

我做计算错误,还是我误解了torch.cuda.max_memory_allocated是如何完全工作的?在整个过程中,我观察到从一个GPU分配的内存约为32GB,但torch.cuda.max_memory_allocated(0) / (1024 ** 3)返回约13.5GB。

发布PyTorch论坛上相同问题的链接。TL; torch.cuda博士。Max_memory_allocated不应该精确地类似于nvidia-smi的输出,因为nvidia-smi实际上保留的内存比实际使用的内存要多。因此,torch.cuda。Max_memory_reserved将与实际输出非常接近(尽管仍然不完全准确)。

https://discuss.pytorch.org/t/pytorchs-torch-cuda-max-memory-allocated-showing-different-results-from-nvidia-smi/165706/2

最新更新