Merged
fix: expose KernelPreference members on Python 3.12 #116
fix: expose KernelPreference members on Python 3.12 #116
Merged
pengpeng7872Add on 16 days ago
pengpeng7872
pengpeng7872
16 days ago

【合入来源】

【修改方案】

base 补丁 _add_enum_member 为 KernelPreference 动态注入 NPU/CPU 成员时,只写入了枚举内部映射(_member_map_ / _value2member_map_ / _member_names_),没有安装类属性。

Python 3.12 移除了 EnumType.__getattr__(属性查找不再回落查 _member_map_),因此成员仅存在于映射中时,KernelPreference.NPU 会抛 AttributeError。受影响路径包括 resolve_backend() 的分发表与 mx_formats 的 _validate_kernel_preference,即 Python 3.12 上所有 NPU MX 分发/校验场景。

修复:在写入映射后,通过 type.__setattr__ 同时安装类属性。不能使用普通 setattr(EnumType.__setattr__ 会拒绝已存在于 _member_map_ 的名字);映射仍需保留,因为迭代、按值查找与 pickle 都依赖它。类对象身份不变,已有 checkpoint 的序列化/反序列化行为不变。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

  • 最小复现:Python 3.11.6 下仅写映射即可通过属性访问;Python 3.12.16 下失败,加入 type.__setattr__ 后 getattr / 迭代 / 按值查找均正常;
  • 与 PR #100 联合验证(Atlas 950 / CANN 9.2.1 / Python 3.12.16):test/upstream/quantization/test_qat.py 14 passed;回归子集 mxfp8_training + mx_ops + w8a16_qat 67 passed;
  • Python 3.10/3.11 行为不变(该属性安装是幂等且向后兼容的)。

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request has been successfully merged by ascend-robot.
(Thank you for pengpeng7872's contribution.)
pengpeng7872pengpeng7872
16 days ago Created pull request, commit 5167d7e3
pengpeng7872pengpeng7872
16 days ago Modify description of pull request
ascend-robotascend-robotCollaborators
16 days ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
16 days ago 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.


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-Ascend/torchao-ascend ✅ wangzhenwu, wanglijun55 (2/2) ✅ wanglijun55 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
pengpeng7872pengpeng7872
16 days ago Modify description of pull request
pengpeng7872pengpeng7872
16 days ago Modify description of pull request
pengpeng7872pengpeng7872
16 days ago Modify description of pull request
pengpeng7872pengpeng7872
16 days ago Associated issue: [Feature]: MXFakeQuantizedLinear 不支持 weight-only(仅权重)量化
pengpeng7872
pengpeng7872
16 days ago Comments:

compile

likedislike
AtlasAccountAtlasAccountCollaborators
16 days ago Added label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
16 days ago Removed label: ci-pipeline-running
AtlasAccountAtlasAccountCollaborators
16 days ago Added label: ci-pipeline-passed
AtlasAccount
AtlasAccountCollaborators
16 days ago Comments:
流水线 PR-pipeline_torchao_npu#170 [ commitID:3f25f8e7 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_x86 ✅ COMPLETED >>>
恶意代码检查 Antipoison ✅ COMPLETED >>>
编码安全与规范检查 pre-commit ✅ COMPLETED >>>
开源片段检查 SCA ✅ COMPLETED >>>
流水线 PR-pipeline_torchao_npu ✅ COMPLETED >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, wanglijun55, wss_321]评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
pengpeng7872pengpeng7872
13 days ago Associated issue: [Bug]: KernelPreference 动态注入的成员在 Python 3.12 下无法通过属性访问
pengpeng7872pengpeng7872
13 days ago Deleted associated issue: [Feature]: MXFakeQuantizedLinear 不支持 weight-only(仅权重)量化
wanglijun55
wanglijun55Collaborators
12 days ago Comments:

/approve

likedislike
ascend-robotascend-robotCollaborators
12 days ago Added label: approved
pengpeng7872pengpeng7872
9 days ago Modify description of pull request
pengpeng7872
pengpeng7872
9 days ago Comments:

@lizhihai137 @chujinjin 二位老师好,麻烦有空帮看下这个 MR:单文件 +7 行(在 _add_enum_member 写完枚举内部映射后,用 type.__setattr__ 补装类属性,修复 Python 3.12 下 KernelPreference.NPU 属性访问抛 AttributeError),对应 issue #58,复现与验证数据都在 MR 描述里。

目前 CI 已绿、wanglijun55 老师 11-17 已 /approve,仅差 1 个 lgtm。

likedislike
Kuteriod
KuteriodCollaborators
7 days ago Comments:

/lgtm

likedislike
ascend-robotascend-robotCollaborators
7 days ago Added label: lgtm
ascend-robotascend-robotCollaborators
7 days ago Merged pull request