已关闭
[Bug]: 使用sglang卸载权重,无法卸载,导致relax框架无法使用共卡模型 #2005
leanfy创建于  5月19日关闭于  6月29日
leanfy
leanfy
5月19日 创建

在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。

⚠️ 安全信息提醒:请仔细检查提供的文本内容,确保其不包含敏感数据信息,包括但不限于:

  • API 令牌或密钥
  • 密码或身份验证凭证
  • 私有网址或接口地址
  • 个人或机密数据
  • ...

在分享配置信息或代码示例时,请将敏感信息脱敏处理,或使用 <TOKEN> 等占位符替代原有内容。

环境信息

例如:
- 操作系统 Ubuntu
- 昇腾硬件信息 910C-752
- CANN软件版本  8.5.1 
- 安装的对应软件版本 
torch==2.9.0+cpu
torch_memory_saver==0.0.8
torch_npu==2.9.0.post1+gitee7ba04
torchao==0.9.0
torchaudio==2.9.0
torchvision==0.24.0
transformers==4.57.3
sgl_kernel_npu==2026.5.1
sglang==0.5.9
sglang-router==0.3.2

🐛 问题描述

在sglang作为强化学习后端,使用memPool调用劫持后的aclMalloc,可以正常查看,但是删除后无法正常释放物理内存

欢迎加入社区,感谢您对社区的贡献 🎉!

likedislike
ascend-robotascend-robot成员
5月19日 添加了label:bug
leanfy
leanfy
5月19日 评论:

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")

likedislike
leanfy
leanfy
5月19日 评论:

验证代码说明.png

likedislike
xuyun15成员
5月21日 评论:

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

likedislike
xuyun15成员
5月21日 评论:

使用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")
likedislike
Xxuyun15成员
5月21日 issue状态由 TODO 改变为 WIP
xuyun15成员
5月21日 评论:

现状:
image.png
预期:
image.png

likedislike
Xxuyun15成员
6月10日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月24日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月24日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月24日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月24日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月24日 关联了pull request:[new feature] add ~mempool() with emptyCache
Xxuyun15成员
6月29日 issue状态由 WIP 改变为 DONE
Xxuyun15成员
6月29日 关闭了 issue
ascend-robotascend-robot成员
6月29日 添加了label:resolved