Merged
feat(quant): add TurboQuant operator #10996
chen-weipeng12Add on Sep 21
feat(quant): add TurboQuant operator #10996
Merged
Merged fromchen-weipeng12/ops-nnfeat/turboquant-9.2.0intocann/ops-nn9.2.0
Pull Request has been successfully merged by CANN-robot.
(Thank you for chen-weipeng12's contribution.)Sep 21 Created pull request, commit 839a7bc2
atomgit-bot
Sep 21 Comments:
Sep 21 Comments:
变更摘要
本 PR 新增 quant/turbo_quant 算子,用于 MLA KV latent 的 4bit 量化:将每个 token 的 latent 做 L2 归一化后映射到 16 个升序码本中心,两个 nibble 打包为一个字节输出 y,并单独输出每 token 的 FLOAT16 L2 范数 scale。算子覆盖 op_graph 原型、op_host 定义/推导/tiling、op_kernel、binary 配置、Torch 扩展与测试文档,支持 ascend910b(Atlas A2)与 ascend910_93(Atlas A3)。
主要改动
- 算子接口定义:在
turbo_quant_def.cpp与turbo_quant_proto.h中注册TurboQuant,输入latent(DT_FLOAT)、centroids(DT_FLOAT),输出y(DT_UINT8)、scale(DT_FLOAT16),并通过同一份OpAICoreConfig挂载到ascend910b与ascend910_93。 - Shape 与数据类型推导:
turbo_quant_infershape.cpp中InferShapeForTurboQuant依据输入[numTokens, headDim]推导y为[numTokens, headDim/2]、scale为[numTokens],并对 rank、numTokens及headDim(仅支持TQ_SUPPORTED_HEAD_DIM=512)做校验,同时InferDataTypeForTurboQuant固定两个输出类型。 - Tiling 策略与数据结构:
turbo_quant_tiling.h定义TurboQuantTilingData(numTokens、tokensPerCore、headDim、packedBytes、tokensPerBatch)及TQ_MAX_TOKENS_PER_BATCH等常量;turbo_quant_tiling.cpp运行时读取GetCoreNumAiv()与 UB 大小,按 token 划分核心并计算批处理 token 数,校验 dtype、centroids形状[16]与uint32上限。 - Kernel 实现:
turbo_quant.h中KernelTurboQuant完成 norm 归约、按中点边界计数的最近码本查找、nibble 打包与scale写出,并采用tokensPerBatch批处理;turbo_quant.cpp为算子入口,从 tiling 读取参数并调用Init/Process。 - 上层接入与配置:新增
ascend910b/ascend910_93的turbo_quant_binary.json,以及 Torch 扩展turbo_quant.py、csrc/turbo_quant.cpp、graph_convert_turbo_quant.py,对外暴露turbo_quant接口与 GE 图转换器,并新增 ACLNN example、op_host/op_kernel UT 与 golden 参考实现。


Incorrect?
atomgit-bot
Sep 21 Comments:
Sep 21 Comments:
Sep 21 Added label: cann-cla/yes
CANN-robot
Sep 21 Comments:
Sep 21 Comments:
145 messages are collapsed here。 See more
Sep 28 Removed label: ci-pipeline-running
Sep 28 Added label: ci-pipeline-passed
Sep 28 Closed associated issue
Sep 28 Merged pull request
CANN-robot
Sep 28 Comments:
Sep 28 Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
背景
TurboQuant 将 MLA 的 KV latent 按 token 归一化后量化为 4bit codebook 索引,并单独输出每个 token 的 FLOAT16 L2 norm,用于 KV cache 的 4bit 压缩。生产路径为
quant/turbo_quant。本 PR 内容
新增turboquant算子
关联的Issue
https://gitcode.com/cann/ops-nn/issues/5714
测试
.pre-commit-config.yaml中 pin 的版本)通过文档更新
新增:
quant/turbo_quant/README.mdquant/turbo_quant/docs/aclnnTurboQuant.mdquant/turbo_quant/docs/torchapi_turbo_quant.md更新(各新增 1 行接口登记):
docs/zh/op_api_list.mddocs/zh/torch_api_list.mddocs/zh/menu_aclnn_api.mddocs/zh/menu_torch_api.md类型标签
AI/Agent生成声明