Merged
feat(interpreter): Interpreter python script remove ml_dtypes #5854
dingbo929Add on Sep 2
feat(interpreter): Interpreter python script remove ml_dtypes #5854
Merged
dingbo929Add on Sep 2
dingbo929
dingbo929Collaborators
Sep 2

移除精度工具的python脚本对于第三方库ml_dtypes的依赖,bf16等数据类型的解析用二进制解码方式实现

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for dingbo929's contribution.)
dingbo929dingbo929Collaborators
Sep 2 Created pull request, commit 1d5c1fc6
dingbo929dingbo929Collaborators
Sep 2 Associated issue: [Task|任务跟踪]: 精度工具python脚本移除ml_dtypes的第三方库的依赖
atomgit-bot
atomgit-bot
Sep 2 Comments:

变更摘要

本 PR 旨在移除精度校验工具(tools/verifier/ 下的 Python 脚本)对第三方库 ml_dtypes 的依赖:不再直接使用 ml_dtypes.int4、ml_dtypes.float8_e4m3fn、ml_dtypes.bfloat16 作为 numpy 读取类型,而是将 INT4/FP8/BF16 等打包类型统一按原始存储字节(np.uint8/np.uint16)读入,再在 tensor_diff.py 中新增的 decode_tensor_data 函数里以二进制解码方式还原为 int8/float32 数值。同时将 _get_compare_config 的入参从 numpy dtype 对象改为数据类型名称字符串,并新增 --atol/--rtol 命令行参数支持容差覆盖。

主要改动

  • 移除 ml_dtypes 依赖并调整 dtype 映射:parse_dump_tensors.py 与 pass_compare.py 删除 import ml_dtypes,将 _data_type_full_mapping/_dtype_dict 中 INT4、FP8、BF16 分别映射为 np.uint8、np.uint8、np.uint16(原始存储类型),并把 pass_compare.py 中两处重复的 dtype_dict 合并为模块级字典 _dtype_dict。

  • 新增二进制解码逻辑 decode_tensor_data:tensor_diff.py 中新增 decode_tensor_data(data, dtype_name) 函数及配套解码器——_decode_int4(从 uint8 低 4 位符号解码为 int8)、_decode_fp8(基于预构建的 _FP8_E4M3FN_LUT 查找表解码为 float32,含 NaN 特殊值处理)和 _decode_bf16(uint16 左移 16 位后按 float32 视图还原);非打包类型原样返回。

  • 对比流程接入解码:parse_dump_tensors.py(VerifyRes 与 CompactDumpTensorInfoParser)和 pass_compare.py(compare_* 相关读取路径)在 np.fromfile 读入原始数据后均调用 decode_tensor_data 进行解码,再执行 reshape 与后续对比。

  • 对比配置改为按 dtype 名称判定:_get_compare_config 入参由 dtype 对象改为字符串,按名称区分整型(精确匹配 rtol=0, atol=0)、FP32/DOUBLE(标准容差 1e-3)及其他低精度浮点(放宽容差 1e-2);tensor_diff.py 同时新增 import numpy as np 依赖。

  • 新增容差覆盖命令行参数:parse_dump_tensors.py 的 parse_arguments 增加 --atol/--rtol(默认 None),在 main 中写入全局变量 ATOL_OVERRIDE/RTOL_OVERRIDE,_get_compare_config 在推导默认值后据此覆盖,并输出对应日志。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 2 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 2 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 2 Comments:

CLA Signature Pass

dingbo929, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robotCollaborators
Sep 2 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/pypto ✅ tsungl4, DCGDDD (2/2) ✅ tsungl4 (1/1)
tools/verifier ✅ tsungl4, DCGDDD (2/2) ✅ tsungl4 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

dingbo929, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Sep 2 Set xinweiliu,cam_bxh,dai-zhentao,lululu40888,shi-dingkun,gguuaanngg,codehjp423,gaoxiang618,wangzheng97,DCGDDD,syfeng,jason_yuan_ye,foundea,ym-HW,hw_zhangzhiqi,yinjie27_,congqiannan,zhangyuebing,tsungl4,gaoxingwang,zhiweiyuan,caodongdong,make_pto,zhoubotcam,linjiashu,wangbing110,WenboCodes as approver
CANN-robotCANN-robotCollaborators
Sep 2 Set gaoxiang618,DCGDDD,yinjie27_,tsungl4,make_pto,linjiashu as approver
dingbo929
dingbo929Collaborators
Sep 2 Comments:

compile

likedislike
dingbo929dingbo929Collaborators
Sep 2 Pre merge succeeded (commit_id: 20701e72def1a6bf725088b5cba2ac873c716e49)
CANN-robot
CANN-robotCollaborators
Sep 2 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 2 Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 3 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Sep 3 Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
Sep 3 Added label: cann-cla/yes
5 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 3 Added label: cann-cla/yes
dingbo929
dingbo929Collaborators
Sep 3 Comments:

compile

likedislike
dingbo929dingbo929Collaborators
Sep 3 Pre merge succeeded (commit_id: 4f752ae2adea2d4d7ad317016afdee275696689f)
CANN-robot
CANN-robotCollaborators
Sep 3 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 3 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 3 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 3 Added label: ci-pipeline-passed
lidongsheng
lidongshengCollaborators
Sep 3 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 3 Added label: approved
杨旭
杨旭Collaborators
Sep 4 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 4 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 4 Merged pull request