常用观测接口
常用观测接口
import torch
print(torch.cuda.memory_allocated() / 2**30) # 张量占用 GiB
print(torch.cuda.memory_reserved() / 2**30) # 缓存池占用 GiB
print(torch.cuda.max_memory_allocated() / 2**30) # 峰值(自上次重置)
print(torch.cuda.memory_summary()) # 分配器分块明细峰值观测的起止
峰值观测的起止
torch.cuda.reset_peak_memory_stats() # 压测前重置
# ... 跑一组请求 ...
print(torch.cuda.max_memory_allocated() / 2**30)reserved 明显高于 allocated 属正常缓存行为;empty_cache() 可归还缓存,但频繁调用会带来重新申请的开销。