延迟生成 benchmark 形状#19
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the benchmark script to lazily initialize shape configurations via a new build_shape_configs function, preventing CUDA tensor creation at import time. It also introduces a new test suite that uses AST parsing to verify this behavior. The review feedback suggests using ast.literal_eval to safely and compatibly extract the default argument value from the AST in the test file.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| ) | ||
|
|
||
| self.assertEqual(builder.args.args[0].arg, "device") | ||
| self.assertEqual(builder.args.defaults[0].value, "cuda") |
There was a problem hiding this comment.
在测试中,直接使用 builder.args.defaults[0].value 来获取默认值虽然在 Python 3.8+ 中可行,但使用 ast.literal_eval 是一种更通用、更安全且兼容性更好的方式来解析 AST 中的字面量值。建议将其替换为 ast.literal_eval(builder.args.defaults[0])。
| self.assertEqual(builder.args.defaults[0].value, "cuda") | |
| self.assertEqual(ast.literal_eval(builder.args.defaults[0]), "cuda") |
该 PR 优化 benchmark 形状生成时机,避免导入脚本时提前展开大量测试组合,使工具脚本在参数检查和帮助输出场景下更轻量。
这个修改面向沐曦 GPU 适配场景中比较容易影响开发、构建或验证稳定性的环节,把原来需要人工排查的问题前移到工具链、运行前检查或基准脚本中处理。实现上保持对现有默认行为的兼容,只在检测到明确配置、输入或环境异常时给出更直接的诊断,避免引入额外运行依赖,也方便维护者独立审阅该分支。
已在沐曦算力环境中完成对应分支验证,验证记录包含真实运行日志、命令输出和失败路径检查,本地归档目录为:E:/Documents/muxi/测试报告/FlashMLA_real_maca_validation_20260608。提交分支:
mengz/lazy-benchmark-shapes,目标仓库:MetaX-MACA/FlashMLA。