Closed
【缺陷报告】算子mc2/moe_distribute_combine_v2 #4775
zhangjunkai9Add on Aug 31Closed at Sep 14
weihao18
Sep 1 Comments:
Sep 1 Comments:
你好,建议汇总到具体算子进行集中处理


Sep 2 Change title to "【缺陷报告】算子mc2/moe_distribute_combine_v2", originally titled "【缺陷报告】空指针解引用 - 文件moe_distribute_combine_v2_tiling.cpp - 函数CheckOptionalScalesTensorDim - 行号500".
Sep 2 Change title to "【缺陷报告】算子mc2/moe_distribute_combine_v2", originally titled "【缺陷报告】空指针解引用 - 文件moe_distribute_combine_v2_tiling.cpp - 函数CheckOptionalScalesTensorDim - 行号500".
Sep 2 Modify description of issue
游震
Sep 3 Comments:
Sep 3 Comments:
/assign @tgwsakiko_


Sep 3 Assign tgwsakiko_ as responsible person
Sep 14 Close issue
Sep 14 Added label: resolved
缺陷信息
缺陷描述
函数 CheckOptionalScalesTensorDim 中,expandScaleStorageShape 在第499行由 context->GetOptionalInputShape(EXPAND_SCALES_INDEX) 获取(可选输入,可能返回 nullptr),但在第500行直接解引用 expandScaleStorageShape->GetStorageShape().GetDimNum(),而空指针检查 OP_TILING_CHECK(expandScaleStorageShape == nullptr, ...) 在第501行才执行。解引用在空检查之前,顺序颠倒,若该可选输入不存在(GetOptionalInputShape 返回 nullptr),第500行将解引用空指针导致崩溃。对比同函数中第511-513行 constExpertAlpha1StorageShape 的正确模式(先 if (ptr != nullptr) 再解引用),以及第575-576行 oriXStorageShape 的正确模式,可确认第499-500行为缺陷代码。
同算子问题
1
在 MoeDistributeCombineV2A5Mte::Init 函数中,当 tilingData 的 isMc2Context 标志为 false 时,else 分支在第546行调用 Mc2Kernel::GetWinSize(epWinContext_),而 epWinContext_ 在类定义中初始化为 nullptr(第215行),此时尚未被赋值。epWinContext_ 的赋值发生在 InitCommContext 的 else 分支(第455行),而 InitCommContext 由 InitAttrs(第480行)调用,InitAttrs 在第549行才被调用——即在第546行之后。GetWinSize 函数(moe_distribute_base.h 第472-475行)直接解引用 winContext->winSize,导致空指针解引用。该函数可通过 moe_distribute_combine_v2_apt.cpp、moe_distribute_combine_add_rms_norm_apt.cpp 和 moe_distribute_combine_v3_apt.cpp 三个内核入口函数到达,其中前两个入口使用 GetHcclContext 而非 mc2Context,isMc2Context 为 false,必然触发此缺陷。
事实核查
数据流证据
传播路径:
修复建议
if (isLayered) { const gert::StorageShape *expandScaleStorageShape = context->GetOptionalInputShape(EXPAND_SCALES_INDEX); OP_TILING_CHECK(expandScaleStorageShape == nullptr, OP_LOGE_WITH_INVALID_INPUT(nodeName, "expandScales"), return false); const int64_t expandScaleDim = expandScaleStorageShape->GetStorageShape().GetDimNum(); OP_TILING_CHECK( expandScaleDim != ONE_DIM, OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON(nodeName, "expandScales", std::to_string(expandScaleDim).c_str(), "The shape dim of expandScales must be 1D."), return false); OP_LOGD(nodeName, "expandScales dim0 = %ld", expandScaleStorageShape->GetStorageShape().GetDim(0)); }