refactor: move power engines into infx / 将功耗引擎迁入 infx - #2941
Conversation
将单节点及多节点功耗引擎迁入 infx.results.power,合并共享的积分和产物处理逻辑,并保留旧命令及导入入口。 补充兼容性、精度及原子写入失败测试,并同步中英文架构文档。
|
Claude finished @adibarra's task in 5m 59s —— View job PR Review — refactor: move power engines into infx
LGTM - no blocking issues found Verified via direct comparison against
Note: I could not execute the pytest suite locally (command not permitted in this session's allowed tools), so verification above is from static comparison; the |
There was a problem hiding this comment.
Looks good — this is a faithful, mechanical refactor: the single-node and multinode power engines were moved into infx/results/power/{single_node,multinode}.py with shared helpers (benchmark-window parsing, per-device integration, atomic JSON write, audit-metric rounding) factored into infx/results/power/common.py, and utils/aggregate_power*.py reduced to compatibility shims that alias sys.modules to the new modules. Diffing the moved code against the pre-refactor originals (via git diff -C) confirms no logic changes — only extraction into shared helpers and delegation. infx/results/fixed_sequence.py and utils/agentic/aggregation/power_adapter.py now import the engines directly from infx.results.power, removing the prior reverse-dependency from infx into utils, and utils/test_aggregate_power.py adds coverage for CLI compatibility (legacy script, -m utils.aggregate_power, and the packaged -m infx.results.power.* entrypoints) plus atomic-write-failure and audit-precision cases.
Extended reasoning...
Overview
This PR moves two power-processing engines (utils/aggregate_power.py for single-node GPU telemetry, utils/aggregate_power_multinode.py for multinode srt-slurm DCGM artifacts) into infx/results/power/single_node.py and infx/results/power/multinode.py, extracting genuinely shared logic (benchmark-window loading/validation, per-device trapezoidal power integration, atomic JSON writes, audit-metric rounding, and the patch_power_metrics/with_power_metrics transform) into a new infx/results/power/common.py. The old utils/aggregate_power*.py files become thin compatibility shims that import the new module and do sys.modules[__name__] = <new module>, which correctly preserves both from utils.aggregate_power import X and direct-script-execution behavior. Two consumers (infx/results/fixed_sequence.py, utils/agentic/aggregation/power_adapter.py) were updated to import the engines directly from infx.results.power, eliminating the previous infx → utils reverse dependency described in the PR body. Documentation (docs/architecture.md/_zh.md) was updated to match. infx/results/power.py was renamed (100% similarity, confirmed via git diff -C) to infx/results/power/__init__.py with no content change.
Security risks
None identified. This is a pure internal code-organization refactor of an offline power/energy telemetry post-processing pipeline (reads CSV/JSON artifacts, writes JSON results). No new external inputs, no auth/crypto/permission logic, no network or shell execution introduced. The sys.modules[__name__] = module aliasing pattern in the compat shims is unusual but well-understood — it only affects Python's own import resolution within this repo's process, not any trust boundary.
Level of scrutiny
I diffed the actual moved code against the pre-refactor versions using git diff -C -C (copy detection) rather than trusting the description, and confirmed the multinode engine is 97% similar (only the shared-helper delegation changed) and the single-node engine is 83% similar (helper functions literally cut and pasted into common.py, call sites updated to delegate) — no behavioral hunks beyond that. I also read the new common.py, single_node.py, and the compat shims in full, and checked that infx/results/fixed_sequence.py's import-failure test in utils/test_process_result.py was updated to match the new import path (power.multinode) used internally. This is exactly the kind of change (large line count, but low actual risk, single well-scoped refactor, heavily tested) that warrants approval once verified rather than deferral.
Other factors
The PR author's own validation (274 shared behavior tests, 626 JSON artifact comparisons, 28 new tests including standalone-package execution and induced-fault detection) is consistent with what the diff shows, and the new utils/test_aggregate_power.py includes concrete regression coverage for the compatibility surface (running via legacy script path, -m utils.aggregate_power, and the new -m infx.results.power.single_node/multinode entrypoints, plus atomic-rename-failure and audit-precision-rounding cases). I was not able to execute the test suite myself in this sandbox (test execution is blocked), so approval here rests on manual line-by-line diff verification rather than a live test run, but that verification was thorough enough to have high confidence given the mechanical nature of the change.
Description / 说明
Power processing still lived in
utils, requiringinfx.resultsto import legacy scripts. Move both engines intoinfx.results.power.single_nodeandinfx.results.power.multinode; keep the old scripts as compatibility entrypoints and import the engines directly from fixed-sequence and AgentX adapters.Share benchmark-window parsing, per-device integration, aggregate replacement, and audit serialization. Keep each telemetry format's validation and failure policy separate. Existing commands, imports, JSON contracts, strict/best-effort behavior, and recipe inputs remain compatible. No new runtime dependencies or installation step.
功耗处理原先仍位于
utils,导致infx.results需要反向导入旧脚本。本次将两种引擎迁入infx.results.power.single_node和infx.results.power.multinode,保留旧脚本作为兼容入口,并让固定序列和 AgentX 适配器直接导入包内引擎。统一基准窗口解析、单设备积分、聚合结果替换和审计序列化,同时保留各遥测格式的校验及失败策略。现有命令、导入路径、JSON 契约、严格模式/尽力处理行为及配方输入保持兼容,无需新增运行时依赖或安装步骤。
Validation / 验证
Same 274 behavior tests pass on the frozen base and refactor. An additional two tests execute the new package without any legacy scripts or site packages.
Compared 626 JSON artifacts across 192 cases and 108 CLI calls: identical artifacts, exit codes, stdout, and diagnostics after normalizing checkout/temp paths and moved traceback frames.
Added 28 cases using existing fixtures and independent expected values: CLI compatibility, missing telemetry, strictness, audit precision, and atomic aggregate/sidecar write failures. Isolated mutations that doubled energy, published before atomic rename, or lost audit precision were all caught.
Result-processing CI command, run locally: 292 passed in 7.31s.
Full local suite: 1,251 tests + 207 subtests passed in 14.07s, with four workers.
在冻结的基线和重构后代码上运行相同的 274 项行为测试,均通过;另有两项测试在没有旧脚本和 site packages 的环境中执行新包入口。
对比 192 个用例产生的 626 份 JSON 产物及 108 次 CLI 调用:归一化检出目录、临时路径和迁移后的 traceback 栈帧后,产物、退出码、标准输出及诊断一致。
复用现有夹具,使用独立确定的预期值新增 28 个用例,覆盖 CLI 兼容性、缺失遥测、严格模式、审计精度以及聚合结果/附属文件的原子写入失败。在隔离副本中故意引入能量翻倍、原子重命名前发布和精度丢失,测试均能检出。
本地运行结果处理 CI 命令:292 项通过,耗时 7.31 秒。
完整本地测试集:四个 worker 下,1,251 项测试及 207 项子测试通过,耗时 14.07 秒。
Scope / 范围
infxpackage series after refactor: centralize results in infx and speed up tests / 集中结果处理并加速测试 #2940. / 延续 refactor: centralize results in infx and speed up tests / 集中结果处理并加速测试 #2940 之后的infx包整理工作。Note
Medium Risk
Large code move touches published benchmark energy metrics and validation sidecars; behavior is intended to be identical but regressions would affect power study gating and aggregate JSON contracts.
Overview
Moves single-node and multinode GPU power validation/aggregation out of
utils/aggregate_power*.pyintoinfx.results.power(common.py,single_node,multinode), so result builders no longer depend on legacyutilsscripts.Wires
infx.results.fixed_sequenceand the AgentXpower_adapterto importrun, audit helpers, and invalid-fallback payloads from the package (e.g.invalid_validation_payloadinstead of ad-hoc_validation_payload/_empty_integration).Keeps
utils/aggregate_power.pyandutils/aggregate_power_multinode.pyas thin compatibility shims (sys.modules[__name__] = single_node|multinode) and documentspython -m infx.results.power.single_node|multinodeas first-class entrypoints.Extends tests with subprocess CLI parity (in-repo vs legacy module vs package-only tree),
REQUIRE_POWERstrictness, and atomic write-failure behavior; updates EN/ZH architecture docs for the new layout.Reviewed by Cursor Bugbot for commit 19e2bf4. Bugbot is set up for automated code reviews on this repo. Configure here.