Closed
[Documentation|文档反馈]: aclnnDequantSwigluQuant 未声明 groupIndex 非空时 quantScale/quantOffset 的形状约束(按资料构造必 561002) #7582
liuhanwen8Add on  24 days agoClosed at  16 days ago
liuhanwen8
liuhanwen8
24 days ago Create

现象

docs/aclnnDequantSwigluQuant.md 未声明 groupIndexOptional 非空时对 quantScaleOptional / quantOffsetOptional 形状的附加约束,按资料字面构造的合法输入被拒绝(561002)。

资料现状(docs/aclnnDequantSwigluQuant.md):

  1. 参数表 groupIndexOptional 只写「MoE 分组需要的 group_index」、维度写 1,没有写它与 x 首维 / groupNum 的关系;
  2. A2/A3 约束段逐条约束了 weightScale/activationScale/quantScale/quantOffset/quantMode 五个参数,唯独没有 groupIndexOptional;
  3. 同段写「static 时 quantScale / quantOffset 为 1 维、值为 1」。

按第 3 条构造(无 groupIndexOptional)可以正常执行;一旦 groupIndexOptional 非空,同一份 quantScale=[1] 直接被拒 561002。实测 5 种 quantScale/quantOffset 形状全部被拒,资料里没有任何一句能解释该给什么:

场景 groupIndex quantMode quantScale ret1
对照组(资料字面) nullptr static [1] 0
同参数仅加 groupIndex [2] static [1] 561002
试 groupNum 维 [2] static [2,128] 561002
试 static 半维 [2] static [2,64] 561002
试 dynamic 半维 [2] dynamic [128] 561002
试 dynamic 分组半维 [2] dynamic [2,64] 561002

期望

资料补充 groupIndexOptional 非空时的约束:① 形状与取值语义(groupNum 与 x 首维关系、cumsum 还是 per-group count);② 对 quantScale/quantOffset/bias 形状的连带要求(static / dynamic 分别给出);③ 若存在,dtype 组合限制。

环境

  • 硬件:Ascend 910B2(Atlas A2);复现 die 7
  • CANN 9.2.0(ascend-toolkit/latest),npu-smi 26.1.1,Linux aarch64 / glibc 2.35
  • 资料:ops-nn/quant/dequant_swiglu_quant/docs/aclnnDequantSwigluQuant.md,源码提交 711a4f5d

复现步骤

  1. 存为 repro_grp.cpp,编译:g++ -std=c++17 -O1 repro_grp.cpp -I$ASCEND/include -L$ASCEND/lib64 -L$ASCEND/aarch64-linux/lib64 -lascendcl -lnnopbase -lopapi -Wl,--allow-shlib-undefined -o repro_grp。
  2. ./repro_grp nogroup → ret1=0:资料字面的 static 形态可用。
  3. ./repro_grp group → ret1=561002:只增加 groupIndex=[2],其余完全不变;对照资料参数表与 A2/A3 约束段,找不到任何一句说明 groupIndexOptional 会改变 quantScale 的形状。

复现脚本

#include <cstdio>
#include <string>
#include <unistd.h>
#include <vector>
#include "acl/acl.h"
#include "aclnnop/aclnn_dequant_swiglu_quant.h"

static aclTensor *mk(const std::vector<int64_t> &s, void *a, aclDataType dt) {
    std::vector<int64_t> st(s.size(), 1);
    for (int i = (int)s.size() - 2; i >= 0; i--) st[i] = s[i + 1] * st[i + 1];
    return aclCreateTensor(s.data(), s.size(), dt, st.data(), 0, aclFormat::ACL_FORMAT_ND,
                           s.data(), s.size(), a);
}
static int64_t numel(const std::vector<int64_t> &s) {
    int64_t n = 1;
    for (auto v : s) n *= v;
    return n;
}

int main(int argc, char **argv) {
    bool grp = argc > 1 && std::string(argv[1]) == "group";
    const int64_t G = 2, H = 128;
    std::vector<int64_t> xs{4, H}, ys{4, H / 2}, ss{4}, qs{1};   // static: quantScale=[1]
    aclInit(nullptr);
    aclrtSetDevice(0);
    aclrtStream stream = nullptr;
    aclrtCreateStream(&stream);
    void *xd, *wsd, *asd, *bd, *qd, *od, *gd, *yd, *sd;
    aclrtMalloc(&xd, numel(xs) * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&wsd, H * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&asd, 16, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&bd, (grp ? G : 1) * H * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&qd, 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&od, 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&gd, G * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&yd, numel(ys), ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&sd, numel(ss) * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    std::vector<int32_t> xh(numel(xs), 3);
    std::vector<float> wsh(H, 1), ash(4, 1), ov(1, 0.0f), qv(1, 1.0f);
    std::vector<float> bh((grp ? G : 1) * H, 0);
    std::vector<int64_t> gv{2, 4};
    aclrtMemcpy(xd, numel(xs) * 4, xh.data(), numel(xs) * 4, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(wsd, H * 4, wsh.data(), H * 4, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(asd, 16, ash.data(), 16, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(bd, bh.size() * 4, bh.data(), bh.size() * 4, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(qd, 4, qv.data(), 4, ACL_MEMCPY_HOST_TO_DEVICE);
    aclrtMemcpy(od, 4, ov.data(), 4, ACL_MEMCPY_HOST_TO_DEVICE);
    if (grp) aclrtMemcpy(gd, G * 4, gv.data(), G * 4, ACL_MEMCPY_HOST_TO_DEVICE);
    aclTensor *x = mk(xs, xd, ACL_INT32), *ws = mk({H}, wsd, ACL_FLOAT);
    aclTensor *as = mk({4, 1}, asd, ACL_FLOAT);
    aclTensor *b = grp ? mk({G, H}, bd, ACL_FLOAT) : mk({H}, bd, ACL_FLOAT);
    aclTensor *q = mk(qs, qd, ACL_FLOAT), *o = mk(qs, od, ACL_FLOAT);
    aclTensor *g = grp ? mk({G}, gd, ACL_INT64) : nullptr;
    aclTensor *y = mk(ys, yd, ACL_INT8), *s = mk(ss, sd, ACL_FLOAT);
    uint64_t wsp = 0;
    aclOpExecutor *e = nullptr;
    char qm[] = "static";
    int r1 = (int)aclnnDequantSwigluQuantGetWorkspaceSize(x, ws, as, b, q, o, g, true, qm, y, s, &wsp, &e);
    printf("%s : groupIndex=%s quantScale=[1] ret1=%d\n",
           grp ? "group  " : "nogroup", grp ? "[2]" : "nullptr", r1);
    fflush(stdout);
    _exit(0);
}

实测输出:

nogroup : groupIndex=nullptr quantScale=[1] ret1=0
group   : groupIndex=[2] quantScale=[1] ret1=561002

影响

  • 资料没有可构造的合法形态 → 接入方只能试错,且失败码是 561002(内部 tiling 错误),看起来像算子缺陷而非「我传错了」;MoE 场景 groupIndex 是主用入口,缺这一条会让该分支基本不可用;
  • 与同接口另一条 issue(出参尺寸未校验导致越界写)不重叠:那条是实现缺陷,本条是资料缺声明。

建议

在 docs/aclnnDequantSwigluQuant.md 的 A2/A3 约束段补一条 groupIndexOptional 专项说明:分组语义(cumsum / count)、groupNum 与 x 首维的关系、非空时 quantScale/quantOffset/bias 的形状要求(static / dynamic 分别给出),并给一个可运行样例。

likedislike
liuhanwen8liuhanwen8
24 days ago Added label: documentation
yuning_chen
yuning_chenCollaborators
24 days ago Comments:

初步分析

感谢反馈。

现象理解:
资料未声明 groupIndex 非空时 quantScale/quantOffset 的形状;按资料字面 [1] 构造会被 561002 拒绝。

当前判断:初步判断,待复现确认。
偏文档缺口。无 groupIndex 可按 static[1] 通过,加上 groupIndex 后同参数被拒。

涉及范围:
docs/aclnnDequantSwigluQuant.md 与 group 路径形状校验。

下一步:
补齐 groupIndex 非空时的 scale/offset 形状约束,并与实现/错误码对齐。

likedislike
yuning_chenyuning_chenCollaborators
24 days ago Assign east_yang as responsible person
yuning_chen
yuning_chenCollaborators
24 days ago Comments:

您好,该问题已收到,当前问题 @east_yang 正在处理中

likedislike
east_yang
east_yangCollaborators
19 days ago Comments:

/unassign @east_yang

likedislike
CANN-robotCANN-robotCollaborators
19 days ago Removed responsible person east_yang
east_yang
east_yangCollaborators
19 days ago Comments:
likedislike
CANN-robotCANN-robotCollaborators
19 days ago Assign fengying555682 as responsible person
east_yang
east_yangCollaborators
19 days ago Comments:

/assign @guijianwei

likedislike
CANN-robot
CANN-robotCollaborators
19 days ago Comments:

Notice

This issue can not be assigned to guijianwei. Please try to assign to the repository members.

likedislike
fengying555682fengying555682Collaborators
18 days ago Assign guijianwei as responsible person
fengying555682fengying555682Collaborators
18 days ago Removed responsible person fengying555682
guijianweiguijianweiCollaborators
18 days ago Assign jzj007 as responsible person
guijianweiguijianweiCollaborators
18 days ago Removed responsible person guijianwei
jzj007jzj007Collaborators
17 days ago Associated pull request
CANN-robotCANN-robotCollaborators
16 days ago Close issue
CANN-robotCANN-robotCollaborators
16 days ago Added label: resolved