pytorch的Gpu内存使用率计算

问题描述 投票:0回答:2

我有一个在服务器上运行的API服务,该服务器通过pytorch和GPU使用机器学习。如何计算一次调用API的GPU内存使用量?

api machine-learning memory-management pytorch gpu
2个回答
0
投票

0
投票

找到了这个解决方案!

# setting device on GPU if available, else CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()

#Additional Info when using cuda
if device.type == 'cuda':
    print(torch.cuda.get_device_name(0))
    print('Memory Usage:')
    print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
    print('Cached:   ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')
© www.soinside.com 2019 - 2024. All rights reserved.