已关闭
[Bug-Report|缺陷反馈]: 推测op_common.cc复用资源逻辑问题,torch.distributed.all_to_all_single和MC2融合算子内(hccl.alltoallv)串行执行会有报错,反过来没问题问题,请帮忙定位 #165
Beau Howard创建于  6月25日关闭于  7月6日
Beau Howard
Beau Howard
6月25日 创建

Describe the current behavior / 问题描述 (Mandatory / 必填)

在同一进程、同一 HCCL 通信域下,torch.distributed.all_to_all_single(eager 路径,经 ProcessGroupHCCL 走 CCU)与 MC2 融合算子(aclnnAlltoAllvQuantGroupedMatMul,kernel 侧 CCU)串行执行时,调用顺序决定是否报错

  • 先调 dist.all_to_all_single,后调融合算子 → 融合算子执行 aicore error(L1/MTE 内存错误,timeout or trap),报错位置在 torch.npu.synchronize()
  • 反过来,先调融合算子,后调 dist.all_to_all_single → 两者均正常

日志关键差异:先调 all_to_all_single 时,HCCL plog 中会出现 Already have context, skip create 日志(对应 op_common.cc:889TryReuseResourcealgTag 命中了前一次 eager 通信创建的 CCU 资源缓存),反过来则没有此日志且不报错。

推测原因:eager dist.all_to_all_single 执行后,通过 HcclEngineCtxCreate(algTag, CCU) 缓存了 CCU 资源上下文(包含 CCL Buffer 布局、CCU 指令序列等)。后续融合算子在分配 CCU 资源时(HcclAllocComResourceByTilingV2GetOrCreateContext),由于 CCL Buffer 和 CCU 硬件状态(PFE 路由表等)已被 eager 路径按自身通信量编程,融合算子假设的是干净的初始状态,没有清理机制,导致 buffer 越界或路由错误。反过来时,融合算子先在干净状态下执行,eager 路径后执行时 ShouldGoCcuFastLaunch/TryReuseResource 未命中,从头创建全新 CCU 资源,能覆盖旧状态,所以正常。

Environment / 环境信息 (Mandatory / 必填)

950
x86
evb 2P

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

最小复现代码

import torch
import torch_npu
import torch.distributed as dist

# 1. 初始化 HCCL 通信域(只初始化一次)
dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method=...)

# 2. 准备通信数据(MX 场景最易复现,eager 传 packed x+scale,融合算子仅传 x)
# 详见 mc2_test/op_class/aclnnAlltoAllvQuantGroupedMatMul.py

# ===== 报错路径:先 eager 后融合 =====
# Step A: eager all_to_all_single(CCU 路径)
dist.all_to_all_single(output_tensor, input=input_tensor,
                       output_split_sizes=..., input_split_sizes=...)

# Step B: MC2 融合算子(CCU kernel 侧)
# 内部调用 aclnnAlltoAllvQuantGroupedMatMul
output = torch_npu.npu_alltoallv_quant_gmm(gmm_x, gmm_weight, ...)
# → RuntimeError: npuSynchronizeDevice error code 507916
# → aicore error: l1 error info, mte error info, timeout or trap

# ===== 正常路径:先融合后 eager =====
# Step A: MC2 融合算子(在干净 CCU 状态下执行)
output = torch_npu.npu_alltoallv_quant_gmm(gmm_x, gmm_weight, ...)
# → 正常

# Step B: eager all_to_all_single(TryReuseResource 未命中,从头创建 CCU 资源)
dist.all_to_all_single(output_tensor, input=input_tensor, ...)
# → 正常

Describe the expected behavior / 预期结果 (Mandatory / 必填)

同一 HcclComm 下,eager dist.all_to_all_single 和 MC2 融合算子的 CCU alltoallv 应能串行执行而不报错,无论调用顺序如何

# Step A: eager all_to_all_single 正常完成
# HCCL plog 中可以看到资源被缓存:
[DEBUG] Already have context, skip create, ctxSize is xxx    ← op_common.cc:889 TryReuseResource 命中

# Step B: 融合算子执行时 aicore error
RuntimeError: npuSynchronizeDevice: AclrtSynchronizeDeviceWithTimeout, error code is 507916

[ERROR] The error from device(chipId=0, dieId=0), serial number is 10,
  exception occurred during fusion kernel task execution,
  streamId=61, taskId=90, subtasksSubType=20, sqeLength=4, cqeStatus=262144.
  ccu task print, coreNum=1, streamId=61, taskId=90.

  there is an aicore error exception, core id is 0/1/2/3, error code = 0,
  l1 error info: 0x5f95001fefd8,
  mte error info: 0xfdbf7dfd087a9f5e,
  errcode:(0) errorstr: timeout or trap error. subErrType: 0x4.

正常日志(先融合后 eager)

# Step A: 融合算子在干净 CCU 状态下执行,正常
# HCCL plog 中没有 "Already have context" 日志

# Step B: eager all_to_all_single 执行
# ShouldGoCcuFastLaunch: fastLaunchTag 未命中(与 mc2ContextTag 不同命名空间)
# TryReuseResource: algTag 未命中
# → 从头创建 CCU 资源,正常通信

日志对比结论

调用顺序 "Already have context" 日志 结果
eager 先 → 融合后 (eager 创建的 CCU 缓存被后续操作命中或残留影响融合算子) 报错
融合先 → eager 后 (eager 的 TryReuseResource 未命中,全新创建) 正常

Special notes for this issue/备注 (Optional / 选填)

是否有办法在 Python 层(或在融合算子 tiling 阶段)清理/重置 CCU 缓存和 PFE 表,确保融合算子执行时 CCU 硬件状态是干净的?

likedislike
Beau HowardBeau Howard
6月25日 修改了issue 的描述
Beau HowardBeau Howard
6月25日 修改标题为 “[Bug-Report|缺陷反馈]: 推测op_common.cc复用资源逻辑问题,torch.distributed.all_to_all_single和MC2融合算子内(hccl.alltoallv)串行执行会有报错,反过来没问题问题,请帮忙定位”,原标题为“[Bug-Report|缺陷反馈]: torch.distributed.all_to_all_single和MC2融合算子内(hccl.alltoallv)串行执行会有报错,反过来没问题问题,请帮忙定位”
Leewis成员
6月25日 评论:

@libohao6 您好,感谢对于社区的关注与反馈,当前这个issue所提问题已收到,目前已有相关同事分析中,待分析清楚后与您同步;

likedislike
LLeewis成员
6月26日 关联了看板:HCCL
Beau Howard
Beau Howard
6月26日 评论:

[ERROR] RUNTIME(1556897,python3):2026-06-26-10:25:07.416.997 [ccu_device_error_proc.cc:170]1557042 MapFusionCcuErrorCodeForFastRecovery:fusion CCU Launch remote HBM UCE fault occurred: device_id=0, stream_id=61, task_id=90, retCode=550

likedislike
LLeewis成员
6月27日 issue类型由 任务 改变为 缺陷
Beau HowardBeau Howard
7月6日 关闭了 issue
Beau HowardBeau Howard
7月6日 issue状态由 待办的 改变为 已完成
LLeewis成员
15 天前 移除了看板:HCCL