Pull Request已成功合入, 合并人@ascend-robot
(感谢 code_mingming 的贡献)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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/msmodelslim | ✅ 周容辰, rookie_hongchuan, yejiajun (3/2) | ✅ 周容辰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
code_mingming, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Ascend docs pipeline is running...


compile


Ascend docs pipeline is running...


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_msmodelslim | ✅ | >>> |
| 恶意代码检查 | Antipoison_MindStudio-ModelSlim | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck_MindStudio-ModelSlim | ✅ | >>> |
| 开源片段检查 | SCA_MindStudio-ModelSlim | ✅ | >>> |
| 开发者测试 | UT_msmodelslim | ✅ | >>> |
| PreSmoke_msmodelslim | ✅ | >>> | |
| 流水线 | PR-pipeline_msmodelslim | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


变更摘要
此 PR 旨在适配新构建方案,使项目能够在目标 MindStudio 镜像内通过命令行完成一键式构建与单元测试。主要改动包括:重写 build.py 构建脚本引入 BuildManager 类统一管理依赖拉取、编译、测试流程;修复因 pydantic>=2.13 与 Python 3.11 行为变化导致的若干单元测试断言失败;并补充 pytest-mock 测试依赖。
主要改动
- 构建脚本重构 (
build.py): 新增统一的BuildManager类,支持python build.py(完整构建)、python build.py test(单元测试)、python build.py local(跳过依赖下载)等命令行模式,集成依赖安装、torch_npu冲突检测、产物归档等流程。 - pydantic>=2.13 兼容修复:
AscendV1QuantFormatConfig与MindIEQuantFormatConfig的ext字段采用exclude_if约定空值不序列化,对应测试用例test_model_dump_include_empty_ext_when_ext_default中model_dump()断言调整为assert not dumped.get("ext")。 - Python 3.11 枚举 f-string 兼容修复:
_build_quant_tips相关测试断言从仅检查QuantType.XXX.value改为同时兼容str(QuantType.XXX),适配 Python 3.11 中Enum类f-string渲染行为变化(输出变为完整限定名而非值)。 - 测试依赖补充: 在
test/requirements.txt中新增pytest-mock,满足test_quant_scheme.py用例中使用mockerfixture 的依赖需求。


代码审查
审查总结
按优先级统计本次审查发现:
- P0:0 个
- P1:0 个
- P2:0 个
- P3:2 个(均为可选改进,不影响正确性)
各文件审查结论
| 文件 | 结论 |
|---|---|
build.py |
1 个 P3:argparse choices 中包含冗余空列表 [] |
docs/zh/common/testing_guide.md |
无问题,新增 pip install pytest-mock 与 test/requirements.txt 一致 |
test/cases/app/naive_quantization/test_application_helpers.py |
无问题,py311 枚举 f-string 兼容性修复正确 |
test/cases/format/ascendV1_format/test_ascendV1.py |
无问题,pydantic >= 2.13 exclude_if 兼容性修复正确 |
test/cases/format/mindie_format/test_mindie.py |
无问题,同上 |
test/requirements.txt |
1 个 P3:部分依赖未固定版本(可选改进) |
整体风险评估
低风险。 本次变更主要完成以下工作:
build.py新增一键构建与测试能力,依赖安装逻辑清晰,命令行参数解析正确;- 三处测试修复均针对 py311 / pydantic >= 2.13 的兼容性问题,修复方式正确且向后兼容;
test/requirements.txt将测试依赖正式化,与文档testing_guide.md保持一致。
未发现正确性、安全、可靠性或破坏性变更问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 2 |
💬 仅评论


🔵 Low Priority
在 build.py 第 56 行,argparse.ArgumentParser.add_argument 的 choices 参数被设置为 [[], 'local', 'test']。其中 [] 是一个空列表对象,不是一个字符串选项。
由于 nargs='*',argparse 对每个收集到的参数值逐一检查 value in choices。空列表 [] 永远不会等于任何字符串参数,因此这个选项实际上不会被匹配,是冗余的。
实际影响: 当用户传入非法命令时,argparse 的错误消息会包含 [],例如:
[] 出现在错误提示中对用户造成困惑,看起来像是显示了两个合法选项 local 和 test 之外还有一个空选项。
建议:将 choices=[[], 'local', 'test'] 改为 choices=['local', 'test'],移除冗余的空列表选项。nargs='*' 本身已允许零参数场景(通过 default=[] 配合),无需在 choices 中显式声明空列表。
| 56
| - choices=[ |
|
56 | + choices=['local', 'test'], |


🔵 Low Priority
test/requirements.txt 中部分关键依赖未固定版本号:pytest、pytest-mock、coverage、pyyaml 均未使用版本约束。
主要风险在于 pyyaml — 该库历史上有多个安全漏洞(CVE-2017-18342、CVE-2020-1747 等),涉及 yaml.load() 任意代码执行。虽然项目本身使用 yaml_safe_load(见 msmodelslim/utils/security.py),但如果环境中安装了包含已知漏洞的旧版本 pyyaml,仍存在一定风险。
testing_guide.md 中列出了 pip install pyyaml(同样未固定版本),两者一致,但最佳实践是固定已知安全的版本(如 pyyaml>=6.0)。
建议:建议对 pyyaml 添加最低版本约束 pyyaml>=6.0。对于其他测试工具(pytest、pytest-mock、coverage),如希望严格可复现,也可考虑固定版本或使用下限约束。


/lgtm


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


PR 提交说明
1. 影响面评估
接口变更(按需): 无
输出件变更(按需): 无
非兼容变更(按需): 无
SIG 评审结论(按需): 无
2. 修改描述
修改背景(可选):(问题现象、使用场景等)
修改目的:(本 PR 要达成什么目标)
新构建方案适配,支持命令行在预期mindstudio镜像内完成构建与测试
修改内容:(按「概念 - 变化」分条,示例:core/算法:新增 SmoothQuant 离群值抑制)
构建脚本修改:
build.py支持一键式构建和UT执行UT修复:
test/cases/format/compressed_tensors_format/quantization/test_quant_scheme.py中依赖了pytest-mock,更新到资料里3. 功能验证
冒烟由 CI 门禁检查,无需填写「冒烟是否通过」。
复现步骤(可选):
# 在此粘贴可复现命令4. 自检(请逐项确认,不适用标 N/A)
典型安全编码问题
DT