import torch
from torch_memory_saver.testing_utils import get_and_print_npu_memory
pool = torch.npu.MemPool()
with torch.npu.use_mem_pool(pool):
tensor = torch.full((1024 ** 3,), 53, dtype=torch.uint8, device='npu')
get_and_print_npu_memory("Pool-1")
del tensor
get_and_print_npu_memory("Pool-2")
get_and_print_npu_memory("Pool-3")
del pool
torch.npu.empty_cache()
torch.npu.synchronize()
get_and_print_npu_memory("Pool-4")
tensor_2 = torch.full((1024 ** 3,), 53, dtype=torch.uint8, device='npu')
get_and_print_npu_memory("Pool-5")
del tensor_2
torch.npu.empty_cache()
torch.npu.synchronize()
torch.npu.empty_cache()
get_and_print_npu_memory("Pool-6")





请教一个问题,你这个torch_memory_saver工具是怎么在npu环境下跑起来的。原生的0.0.8版本中csrc/torch_memory_saver.cpp应该强依赖于cuda环境
能共享下这个工具npu可用的版本吗?


使用torch自带的接口测试验证:
import torch
import torch_npu
#from torch_memory_saver.testing_utils import get_and_print_npu_memory
def get_and_print_npu_memory(input):
print(f"input={input}....................memory allocated: {torch.npu.memory_allocated()}, torch.cuda.memory_reserved()={torch.npu.memory_reserved()}")
pass
pool = torch.npu.MemPool()
with torch.npu.use_mem_pool(pool):
tensor = torch.full((1024 ** 3,), 53, dtype=torch.uint8, device='npu')
get_and_print_npu_memory("Pool-1")
del tensor
get_and_print_npu_memory("Pool-2")
get_and_print_npu_memory("Pool-3")
del pool
torch.npu.empty_cache()
torch.npu.synchronize()
get_and_print_npu_memory("Pool-4")
tensor_2 = torch.full((1024 ** 3,), 53, dtype=torch.uint8, device='npu')
get_and_print_npu_memory("Pool-5")
del tensor_2
torch.npu.empty_cache()
torch.npu.synchronize()
torch.npu.empty_cache()
get_and_print_npu_memory("Pool-6")




在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
⚠️ 安全信息提醒:请仔细检查提供的文本内容,确保其不包含敏感数据信息,包括但不限于:
在分享配置信息或代码示例时,请将敏感信息脱敏处理,或使用
<TOKEN>等占位符替代原有内容。环境信息
🐛 问题描述
在sglang作为强化学习后端,使用memPool调用劫持后的aclMalloc,可以正常查看,但是删除后无法正常释放物理内存
欢迎加入社区,感谢您对社区的贡献 🎉!