Prhub

#47209 [ROCm][Bugfix] Fix Triton "out of resource: shared memory" Error In One-Shot LoRA MoE

原始 PR 作者 micah-wil 合并时间 2026-07-01 14:24 文件变更 1 提交数 2 评论 0 代码增减 +9 / -0

执行摘要

修复 ROCm LoRA MoE Triton 核显存不足错误

PR body 指出,在 MI300 和 MI325 上运行 LoRA 测试 test_gpt_oss_lora 时,Triton 核因共享内存不足 (Required: 69632 bytes, Hardware limit: 65536 bytes) 而失败。错误提示需要减小 block 大小或 num_stages。由于共享内存限制是平台特定的,需要根据平台能力动态调整。

建议合并。该 PR 修复了一个具体的运行时错误,改动简洁且经过平台隔离,逻辑正确。

讨论亮点

仅有一条来自 jeejeelee 的批准评论 "LGTM, thank you",无实质性讨论。

实现拆解

  1. 新增导入:在 vllm/lora/ops/triton_ops/fused_moe_lora_op.py 中导入 get_max_shared_memory_bytes 函数,用于获取设备最大共享内存字节数。
  2. 添加 fallback 逻辑:在 _run_fused_moe_lora_one_shot 函数中,当 num_stages = 3 且平台是 CUDA 类平台时,查询设备共享内存上限。若小于 68KB,则将 num_stages 降低至 2,从而减少共享内存需求。
  3. 平台保护:使用 current_platform.is_cuda_alike() 检查,确保该 fallback 仅应用于 CUDA 类平台,避免在非 CUDA 平台上调用 get_max_shared_memory_bytes 可能引发错误。
文件 模块 状态 重要度
vllm/lora/ops/triton_ops/fused_moe_lora_op.py LoRA 算子 modified 4.51

关键符号

_run_fused_moe_lora_one_shot

关键源码片段

vllm/lora/ops/triton_ops/fused_moe_lora_op.py bugfix

核心修复文件:新增共享内存检测和降级逻辑,解决 LoRA MoE 在 AMD GPU 上的共享内存溢出。

# vllm/lora/ops/triton_ops/fused_moe_lora_op.pyfrom vllm.platforms import current_platform
from vllm.utils.mem_utils import get_max_shared_memory_bytes # 新增导入def _run_fused_moe_lora_one_shot(...):
    # ... 前面的逻辑确定 block_n, nw, ns
    if hidden_size >= 4096:
        block_n, nw, ns = 128, 8, 3
    else:
        block_n, nw, ns = 128, 4, 3
​
    # 修复共享内存溢出:若设备最大共享内存小于 68KB,则降级为 2 级流水线
    if current_platform.is_cuda_alike():
        max_shmem_bytes = 68 * 1024
        if get_max_shared_memory_bytes(device.index) < max_shmem_bytes:
            ns = min(ns, 2) # 将 num_stages 限制为 2

评论区精华

PR 审核 other

jeejeelee 批准 PR,无额外评论。

结论:PR 获得批准,无需进一步修改。 · 已解决

风险与影响

风险极低。变更仅 9 行,加在一个已有 fallback 分支内,且仅在共享内存不足时才触发,不影响正常路径。对 non-CUDA 平台完全隔离。可能的风险是 get_max_shared_memory_bytes 在某些罕见平台上表现异常,但 is_cuda_alike() 已提供保护。

影响范围小。仅修复了 AMD GPU 上特定 Triton 核的共享内存溢出问题,使 LoRA MoE 功能在受限 GPU 上可用。对其他平台无影响。

平台特定修复 低风险小改动

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论