Closed
[Bug-Report|缺陷反馈]: aclnnDequantBias 对非连续出参该拒未拒(资料全标 ×,实测两段返回 0 且一半位置未写入) #8693
liuhanwen8Add on 9 days agoClosed at 5 days ago
9 days ago Added label: bug-report
9 days ago Modify description of issue
9 days ago Modify description of issue
9 days ago Modify description of issue
yuning_chen
9 days ago Comments:
9 days ago Comments:
感谢反馈,问题成立,这条与 #8663(自动生成接口出参非连续静默错值)属于同一根因:op_api / 生成模板只校验 dtype 与 shape,没有按 out 的 view stride 回写,kernel 按连续地址写入。
本条要点:aclnnDequantBias 的唯一出参 out(文档参数表名;示例代码里变量名写作 y,FLOAT16, [40,256])传非连续 view 时:
修复建议:
- 短期:文档与实现口径先对齐——资料已标
×的,实现侧应显式返回ACLNN_ERR_PARAM_INVALID(不能静默返回 0 让调用方拿到错位数据);资料标√但实现不支持的,先改文档; - 长期:op_api 生成模板统一处理——出参非连续时走「算到连续临时 buffer → 按 stride 拷回」,或直接拒绝;
- 出参声明了
AutoContiguous的,必须在 launcher 里真正插入 contiguous 转换,否则属于声明不生效(等价虚标)。
建议与 #8663 / #8661 同一 PR 收敛,避免同一根因多轮返工;修完在本 issue 回贴改动点与验证结果。


9 days ago Assign liuguoyue as responsible person
yuning_chen
9 days ago Comments:
9 days ago Comments:
您好,问题已收到,当前 @liuguoyue 正在处理中。


8 days ago Associated pull request
5 days ago Close issue
5 days ago changed custom state from 待办的 to 已完成
5 days ago Added label: resolved
2 days ago Assign chenjiayi_ as responsible person
chenjiayi_
2 days ago Comments:
2 days ago Comments:
补充说明本问题的跟进安排:
该 issue 已关闭,已补充 assign 给 @chenjiayi_ 复核关闭结论,原责任人 @liuguoyue 保留协同。
当前状态:
- 关闭状态:已完成;复核项:aclnnDequantBias 对非连续出参该拒未拒(资料全标 ×,实测两段返回 0 且一半位置未写入)。
- 我先核对关闭时的结论与当前 master 的实现/资料是否一致。
下一步:
- 复核完成后在本 issue 补充结论。
- 如果还有后续需要,请重新提 issue。


chenjiayi_
2 days ago Comments:
2 days ago Comments:
补充说明本问题的后续处理:
已修复并随关联 PR 合入。
处理结果:
- !14378:feat(quant): dequant_bias 支持非连续 Tensor(手写 aclnn 连续化+回写,修复 #8693)
验证:
- 关联 PR(2026-11-16)已合入,变更可从 PR 记录追溯。
- 本次以 PR 记录与 issue 讨论核对为主,未重新执行复现或真机验证。
说明:合入分支与版本以 PR 记录为准;如仍有问题,请重新提 issue 并附版本、shape 与日志。
如果还有后续需要,请重新提 issue。


11 hours ago Removed responsible person chenjiayi_
更新说明
stride=2时,若连续写入numel=10240个结果,按 stride 读回恰有一半落在未写区,与实测5120/10240吻合;若只写一半则应出现 3/4 未写。本次实测为:storage写满 10240 个、与连续基线逐元素相同 10240/10240,即写满连续前缀、忽略 stride。原「只写 5120 个」的表述已就地更正。outputDtype=1,不是groupSize,已更正。63513a9e之后对 arch35 路径新增了输出 storage shape 必须等于x的[M,N]校验,本用例storage=[40,512]预测会被该路径拦截。上述复现结果来自 CANN 9.2.0/9.3.0 安装件;若要宣称 master 已修,需补自构建 master 的实跑。[Bug-Report|缺陷反馈]: aclnnDequantBias 对非连续出参该拒未拒(资料全标 ×,实测两段返回 0 且一半位置未写入)
现象
aclnnDequantBias的唯一出参out(文档参数表名;示例代码里变量名写作y,FLOAT16,[40,256])传非连续 view 时:out[40,256]/{512,2}/[40,512]0/0@5120 got=0xFBFFmax_offset= 20478,小于numel(storage)= 20480,view 合法(非越界)0/10240,全部写满且数值正确,排除构造与用法问题@5120(第 20 行首),属固定错位模式期望
docs/aclnnDequantBias.md的参数表把x/weightScale/activateScaleOptional/biasOptional/out的非连续Tensor 列全部标为 ×,即明确声明不支持非连续。
那么
aclnnDequantBiasGetWorkspaceSize应在参数校验阶段识别出out的 stride 带空洞,返回
ACLNN_ERR_PARAM_INVALID(161002)。op_host/dequant_bias_def.cpp里也没有.AutoContiguous(),与资料「不支持」一致。实测返回
0—— 既没拒绝,也没算对:调用方拿到 0 会认为成功,实际 buffer 一半是旧值。根因(物理内存实证)
dump 出参 buffer 物理内容:
算子算出全部 10240 个正确结果(等于
out的 view numel),并按连续行主序写满 storage 前 10240 个位置,但完全忽略出参 stride,按连续行主序写进 buffer 起始处(即
y的 stride{512,2}完全未参与寻址)。按 stride 读回时一半偏移落在未写区 → 读到哨兵,即「一半未写」的成因。
环境
cann/ops-nn@9b3be291(origin/master),算子quant/dequant_biasACLNNTYPE aclnn,无op_host/op_api/(op_api 由 op def 自动生成)5120/10240未写、@5120 got=0xFBFF),非偶发复现步骤
repro.cpp,编译:g++ -std=c++17 -O1 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase -Wl,--allow-shlib-undefined./repro 0 11(0 为 device,11 = 先跑基线再把y设为非连续)y哨兵 0/10240→ 非连续y哨兵 5120/10240、[FAIL] y(按stride) 不一致 5120/10240 @5120 got=0xFBFF want=0x3C00复现脚本
#include <cstdio> #include <cmath> #include <vector> #include <cstdint> #include <unistd.h> #include "acl/acl.h" #include "aclnn/acl_meta.h" #include "aclnnop/aclnn_dequant_bias.h" static aclrtStream gStm; static int64_t Nel(const std::vector<int64_t>& s){int64_t n=1;for(auto v:s)n*=v;return n;} static std::vector<int64_t> Cs(const std::vector<int64_t>& v){std::vector<int64_t> s(v.size(),1); for(int64_t i=(int64_t)v.size()-2;i>=0;i--) s[i]=s[i+1]*v[i+1]; return s;} static int64_t MaxOff(const std::vector<int64_t>& v,const std::vector<int64_t>& st){ int64_t m=0; for(size_t i=0;i<v.size();i++) m+=(v[i]-1)*st[i]; return m;} static aclTensor* Mk(const std::vector<int64_t>& v,const std::vector<int64_t>& st, const std::vector<int64_t>& ss,aclDataType dt,void* d){ return aclCreateTensor(v.data(),(uint64_t)v.size(),dt,st.data(),0,ACL_FORMAT_ND, ss.data(),(uint64_t)ss.size(),d);} static void* Up(void* h,size_t n){void* p=nullptr; aclrtMalloc(&p,n,ACL_MEM_MALLOC_HUGE_FIRST); aclrtMemcpy(p,n,h,n,ACL_MEMCPY_HOST_TO_DEVICE); return p;} // 按 stride 铺 T 类型;keep=1 填正常序列,keep=0 全填 sent template<class T> static void* Lay(const std::vector<int64_t>& v,const std::vector<int64_t>& st, const std::vector<int64_t>& ss,T sent,int keep,const std::vector<T>& vals){ std::vector<T> h((size_t)Nel(ss),sent); std::vector<int64_t> ix(v.size(),0); for(int64_t lin=0,nv=Nel(v);lin<nv;lin++){ int64_t off=0; for(size_t j=0;j<v.size();j++) off+=ix[j]*st[j]; if(keep) h[(size_t)off]=vals[(size_t)(lin%(int64_t)vals.size())]; for(int64_t j=(int64_t)v.size()-1;j>=0;j--){ if(++ix[(size_t)j]<v[j]) break; ix[(size_t)j]=0; } } return Up(h.data(),h.size()*sizeof(T)); } template<class T> static std::vector<T> Rd(void* d,const std::vector<int64_t>& v, const std::vector<int64_t>& st,const std::vector<int64_t>& ss){ std::vector<T> h((size_t)Nel(ss)), o; std::vector<int64_t> ix(v.size(),0); aclrtMemcpy(h.data(),h.size()*sizeof(T),d,h.size()*sizeof(T),ACL_MEMCPY_DEVICE_TO_HOST); for(int64_t lin=0,nv=Nel(v);lin<nv;lin++){ int64_t off=0; for(size_t j=0;j<v.size();j++) off+=ix[j]*st[j]; o.push_back(h[(size_t)off]); for(int64_t j=(int64_t)v.size()-1;j>=0;j--){ if(++ix[(size_t)j]<v[j]) break; ix[(size_t)j]=0; } } return o; } static std::vector<uint16_t> g_b; static bool g_have=false; // mode 0 基线 / 1 y 末维切片 static void Run(int mode) { std::vector<int64_t> iS={40,256}, wS={256}, aS={40}, bS={256}, yS={40,256}; std::vector<int64_t> stY=Cs(yS), ssY=yS; if(mode==1){ stY={512,2}; ssY={40,512}; } if(mode) printf(" [构造] y mo=%lld < storage=%lld %s\n", (long long)MaxOff(yS,stY),(long long)Nel(ssY),MaxOff(yS,stY)<Nel(ssY)?"合法":"非法"); std::vector<int32_t> iv((size_t)Nel(iS),1); std::vector<float> wv((size_t)Nel(wS),1.0f), av((size_t)Nel(aS),1.0f), bv((size_t)Nel(bS),0.0f); void* di=Up(iv.data(),iv.size()*4); void* dw=Up(wv.data(),wv.size()*4); void* da=Up(av.data(),av.size()*4); void* dbt=Up(bv.data(),bv.size()*4); void* dY=Lay<uint16_t>(yS,stY,ssY,0xFBFF,0,g_b); aclTensor* ti=Mk(iS,Cs(iS),iS,ACL_INT32,di); aclTensor* tw=Mk(wS,Cs(wS),wS,ACL_FLOAT,dw); aclTensor* ta=Mk(aS,Cs(aS),aS,ACL_FLOAT,da); aclTensor* tb=Mk(bS,Cs(bS),bS,ACL_FLOAT,dbt); aclTensor* tY=Mk(yS,stY,ssY,ACL_FLOAT16,dY); uint64_t ws=0; aclOpExecutor* ex=nullptr; int r1=(int)aclnnDequantBiasGetWorkspaceSize(ti,tw,ta,tb,1,tY,&ws,&ex); int r2=-1; if(r1==0){ void* wp=nullptr; if(ws)aclrtMalloc(&wp,ws,ACL_MEM_MALLOC_HUGE_FIRST); r2=(int)aclnnDequantBias(wp,ws,ex,gStm); aclrtSynchronizeStream(gStm); if(wp)aclrtFree(wp); } printf("[%-12s] ret=%d/%d\n", mode==0?"基线":"y 切片", r1,r2); if(r2!=0){ printf(" (第二段失败)\n"); return; } std::vector<uint16_t> y=Rd<uint16_t>(dY,yS,stY,ssY); int s=0; for(auto v:y) if(v==0xFBFF) s++; printf(" y哨兵 %d/%zu\n",s,y.size()); if(mode==0){ g_b=y; g_have=true; // 基线写满度结论 printf(" >>> 基线%s\n", s==0?"全部写满":"存在未写区,需查"); return; } if(!g_have){ printf(" [ABORT] 无基线\n"); return; } int bad=0,first=-1; for(size_t i=0;i<y.size();i++) if(y[i]!=g_b[i]){bad++;if(first<0)first=(int)i;} if(bad) printf(" [FAIL] y(按stride) 不一致 %d/%zu @%d got=0x%04X want=0x%04X\n", bad,y.size(),first,first>=0?y[first]:0,first>=0?g_b[first]:0); else printf(" [ OK ] y(按stride) 一致(%zu)\n",y.size()); } int main(int argc,char** argv){ int dev=(argc>1)?atoi(argv[1]):0, mode=(argc>2)?atoi(argv[2]):0; aclInit(nullptr); aclrtSetDevice(dev); aclrtCreateStream(&gStm); printf("=== aclnnDequantBias 出参非连续 mode=%d ===\n",mode); if(mode>=10){ Run(0); if(g_have){ printf("--- 基线 OK -> mode=%d ---\n",mode-10); Run(mode-10);} } else Run(mode); fflush(stdout); _exit(0); }实测输出:
@5120 got=0xFBFF即预填哨兵未被覆盖。CPU 标杆对照
CPU 参考(
input=1、weight=1.0、activation=1.0、bias=0.0、outputDtype=1⇒ 三条反量化式同值y=1.0,FP16 位模式0x3C00):基线 0/10240 一致,同一构造非连续 5120/10240 未写(@5120 got=0xFBFF)。⇒ 连续通路逐元素正确,缺陷只在非连续通路。
影响
DequantBias用于量化推理的反量化偏置叠加,y直接进入后续计算。非连续时一半位置留旧值,结果静默错误且返回码为 0,上游无法感知。
ScaledMaskedSoftmax)、#8686/#8687(SwiGlu族)、#8688/#8689(SituGlu族)同型:资料已声明不支持,实现既未拒绝也未算对。
ACLNNTYPE aclnn+ 出参 stride 未参与寻址。建议
GetWorkspaceSize增加出参非连续校验,y的 stride 与连续 stride 不一致即返回 161002.AutoContiguous()并同步把资料的×改为√y传带空洞 stride,断言第一段返回非 0(当前应拒绝)