Closed
[Requirement|需求建议]: PyPTO Pro FixPipe 随路量化统一scale参数接口 #2938
gravel1997Add on  Aug 11Closed at  Aug 21
gravel1997
gravel1997Collaborators
Aug 11 Create

Background(背景信息) (Mandatory / 必填)

PyPTO Pro 的 FixPipe 随路量化(在 L0C→GM / L0C→Vec 搬移时内联完成量化/反量化)现有接口使用门槛高:

  • per-tensor 标量量化需用户手动把 float scale 编码成 64 位位模式(struct.pack),再传 pre_quant_scalar;
  • per-channel 量化需用户手动完成约 15 行样板代码:分配 Scaling 内存 tile、从 GM 加载 scale、move 到 Scaling、再手动插入 sync 同步;
  • 参数分散、易错,且缺少对硬件 FixPipe deqTensor 语义([1, N] 逐列)的前端校验。

本需求提出统一 scale 参数接口,按参数类型自动分发到 per-tensor / per-channel / 动态量化路径,隐藏位编码与内存管理细节。

Origin(信息来源) (Mandatory / 必填)

  • 提出方:PyPTO Pro 前端开发团队(随路量化功能评审整改)
  • 业务驱动:大模型推理中的 per-channel 量化场景(如 GLM-4.5 FFN shared expert、MLA prolog quant:INT8×INT8→INT32→FP16 反量化、FP32→INT8 量化)
  • 硬件平台:Ascend 950(FixPipe 支持 deqScalar / deqTensor 随路量化)

Benefit / Necessity(价值/作用) (Optional / 选填)

  • 接口简化:per-tensor 由 2 行位编码 + 传参 → scale=2.0 一行;per-channel 由 15 行样板 → scale=scale_tensor 一行
  • 覆盖三种模式:标量(编译期 float / 运行时标量)、通道([1, N] INT64 Tensor)、动态(运行时 scale)
  • 硬件语义对齐:[1, N] 逐列、N % 16 == 0、N <= 512 解析期校验;[N, 1] 逐行量化解析期拒绝并给出可操作提示
  • 可用性保障:解析期守卫拦截 FixPipe unit-flag 链误用(孤立 Phase store 会挂设备)、自动分配 Mat 中转 tile 与 sync event_id 的地址/事件冲突,避免设备挂起与静默数据错乱

Design(设计方案) (Optional / 选填)

# per-tensor(编译期 float)
pl.store(out_int8, acc, [0, 0], scale=2.0)
# 动态标量(运行时 INT 预编码位 / FP32 自动 bitcast)
pl.store(out_int8, acc, [0, 0], scale=scale_bits)
# per-channel(Tensor 自动走 deqTensor 路径)
scale = torch_npu.npu_trans_quant_param(torch.full((1, 64), 2.0))
pl.store(out_int8, acc, [0, 0], scale=scale)
# Acc→Vec 搬移时量化
pl.move(vec_int8, acc, scale=2.0, acc_to_vec_mode=pl.AccToVecMode.SingleModeVec0)

实现要点:

  • store / store_tile / move 统一 scale 参数,替换已废弃的 pre_quant_scalar / fp_tile
  • 按参数类型分发:float → 编译期标量;FP32 运行时标量 → codegen __builtin_bit_cast 自动重解释位模式;INT 运行时标量 → 预编码位;Tensor [1, N] INT64 → per-channel(deqTensor)
  • 自动分配 Scaling tile(0x0000)与 Mat 中转 tile(动态基址,避开用户 tile)、自动插入 load/sync/move/sync
  • 自动同步 event_id 避开用户已用事件(0..7 硬件空间)
  • 解析期守卫:FixPipe unit-flag 链(孤立 Final / 未闭合 Partial)、用户 Mat tile 地址重叠、用户 sync event_id 别名
likedislike
gravel1997gravel1997Collaborators
Aug 11 Modify description of issue
gravel1997gravel1997Collaborators
Aug 11 Associated pull request
gravel1997gravel1997Collaborators
Aug 11 Assign gravel1997 as responsible person
gravel1997gravel1997Collaborators
Aug 11 Associated pull request
huanyongbenhuanyongben
Aug 17 Associated pull request
gravel1997gravel1997Collaborators
Aug 21 changed custom state from 进行中 to 已解决
gravel1997gravel1997Collaborators
Aug 21 Close issue
LiwenerLiwener
Aug 24 Associated pull request
LiwenerLiwener
Aug 24 Associated pull request
LiwenerLiwener
Aug 24 Deleted associated pull request: feat(pypto_pro): support phase param in pl.move for Acc->Vec unit_flag sync
LiwenerLiwener
Aug 24 Deleted associated pull request: refactor(mutex): Remove internal params from mutex_lock/unlock api