Merged
feat(ops-direct-invoke): 将 DSL 性能节点接入原五阶段优化工作流 #236
小杨发发Add on Oct 29
feat(ops-direct-invoke): 将 DSL 性能节点接入原五阶段优化工作流 #236
Merged
Merged fromyyw323/cannbotcodex/dsl-perf-integrationintocann/cannbotmaster
Total: 20 files changed+839-45
| @@ -16,6 +16,7 @@ | |||
| 16 | "agents": [ | 16 | "agents": [ |
| 17 | "./agents/ops-direct-invoke-architect.md", | 17 | "./agents/ops-direct-invoke-architect.md", |
| 18 | "./agents/ops-direct-invoke-developer.md", | 18 | "./agents/ops-direct-invoke-developer.md", |
| 19 | - "./agents/ops-direct-invoke-verifier.md" | 19 | + "./agents/ops-direct-invoke-verifier.md", |
| 20 | + "./agents/ops-direct-invoke-perf-coordinator.md" | ||
| 20 | ] | 21 | ] |
| 21 | } | 22 | } |
| @@ -43,6 +43,9 @@ opencode | |||
| 43 | 43 | ||
| 44 | 详细安装参数见 [README](README.md#安装详解)。 | 44 | 详细安装参数见 [README](README.md#安装详解)。 |
| 45 | 45 | ||
| 46 | + | ||
| 47 | +DSL 全流程自动执行性能优化并回集成,替换原性能摸底。初始问卷会按安装版本的性能 Skill 确认优化轮数或目标、对标和环境;恢复时沿用有效确认。优化结果见本轮 `perf-optimize/run/`,最终版本及证据索引见 `perf-optimize/HANDOFF.md`。无有效收益时按原规则保留基线,实际结论以报告为准。 | ||
| 48 | + | ||
| 46 | ## DSL 版本与回退 | 49 | ## DSL 版本与回退 |
| 47 | 50 | ||
| 48 | 新 DSL 工作流会创建独立本地代码仓,每轮修改在验证前提交;并行 Unit 使用独立 worktree。`WORK_DIR` 保持工作流目录,代码与测试使用脚本返回的 `CODE_DIR`。失败版本会保留;需要恢复时指定完整 SHA,恢复后重新验证。 | 51 | 新 DSL 工作流会创建独立本地代码仓,每轮修改在验证前提交;并行 Unit 使用独立 worktree。`WORK_DIR` 保持工作流目录,代码与测试使用脚本返回的 `CODE_DIR`。失败版本会保留;需要恢复时指定完整 SHA,恢复后重新验证。 |
| @@ -24,7 +24,7 @@ | |||
| 24 | ### 【2026-10-14】 | 24 | ### 【2026-10-14】 |
| 25 | 25 | ||
| 26 | - DSL 全量精度验证后新增 [review-fix 子图](skills/ops-direct-invoke/workflows/cannbot-dsl/review-fix.yaml):由 Agent 通过统一 code_versions 管理 Git 基线、候选提交与恢复,review_fix 脚本只读核对基线提交及冻结资产,检视一次,通过检视报告与修复报告逐项记录置信度 ≥80 的有效意见,由验收者核对实际改动,并复跑全部 case;验收未通过时由 harness 按节点预算重试。本轮功能失败先恢复已验证基线;有预算时返回失败重试,最后一轮可在恢复提交全量复验后验收基线托底,并在交付中明确整改未通过。组装中断可安全重试;回归中断由 Agent 保持候选源码不变并补齐验证,不计作完整功能失败。 | 26 | - DSL 全量精度验证后新增 [review-fix 子图](skills/ops-direct-invoke/workflows/cannbot-dsl/review-fix.yaml):由 Agent 通过统一 code_versions 管理 Git 基线、候选提交与恢复,review_fix 脚本只读核对基线提交及冻结资产,检视一次,通过检视报告与修复报告逐项记录置信度 ≥80 的有效意见,由验收者核对实际改动,并复跑全部 case;验收未通过时由 harness 按节点预算重试。本轮功能失败先恢复已验证基线;有预算时返回失败重试,最后一轮可在恢复提交全量复验后验收基线托底,并在交付中明确整改未通过。组装中断可安全重试;回归中断由 Agent 保持候选源码不变并补齐验证,不计作完整功能失败。 |
| 27 | -- 固定子图随主图组装到本轮目录;性能摸底、文档和交付统一使用修复后通过的版本或恢复的基线。安装、启动与恢复命令不变。 | 27 | +- 固定子图随主图组装到本轮目录;性能优化与回集成、文档和交付统一使用修复后通过的版本或恢复的基线。安装、启动与恢复命令不变。 |
| 28 | 28 | ||
| 29 | ### 【2026-10-13】 | 29 | ### 【2026-10-13】 |
| 30 | 30 | ||
| @@ -34,7 +34,7 @@ | |||
| 34 | ### 【2026-09-30】 | 34 | ### 【2026-09-30】 |
| 35 | 35 | ||
| 36 | - 新增 **CANNBot-DSL 算子开发支持**:按开发语言选择 DSL 工作流,支持设计、动态实现子图生成、开发与验收。 | 36 | - 新增 **CANNBot-DSL 算子开发支持**:按开发语言选择 DSL 工作流,支持设计、动态实现子图生成、开发与验收。 |
| 37 | -- DSL 的环境节点记录环境证据,在本轮 `cannbot-dsl/docs/` 根目录内定位开发指南与 API 正文,记录实际入口供后续节点使用,不限定语言目录或子目录布局;性能摸底完成后再生成最终版本的文档。 | 37 | +- DSL 的环境节点记录环境证据,在本轮 `cannbot-dsl/docs/` 根目录内定位开发指南与 API 正文,记录实际入口供后续节点使用,不限定语言目录或子目录布局;性能优化与回集成完成后再生成最终版本的文档。 |
| 38 | - 提供 `ops-direct-invoke-maintain`,按模块记录工作流设计与维护约定。 | 38 | - 提供 `ops-direct-invoke-maintain`,按模块记录工作流设计与维护约定。 |
| 39 | - 回归测试随维护 Skill 分发,修改工作流后运行完整测试;检查自身脚本和 harness 调用衔接,不重复验证框架内部调度。 | 39 | - 回归测试随维护 Skill 分发,修改工作流后运行完整测试;检查自身脚本和 harness 调用衔接,不重复验证框架内部调度。 |
| 40 | - 安装与使用统一见 [QUICKSTART.md](QUICKSTART.md)。 | 40 | - 安装与使用统一见 [QUICKSTART.md](QUICKSTART.md)。 |
| @@ -106,7 +106,7 @@ PM 入口随 `ops-direct-invoke` Skill 安装,角色与 Skill 路径见安装 | |||
| 106 | 106 | ||
| 107 | 插件的 [ops-direct-invoke Skill](skills/ops-direct-invoke/SKILL.md) 是主会话按算子任务加载的 PM 入口,负责需求对齐、流程编排与交付组织。PM 职责作用于承接完整任务的主会话,节点职责由子 Agent 角色和 task 定义。 | 107 | 插件的 [ops-direct-invoke Skill](skills/ops-direct-invoke/SKILL.md) 是主会话按算子任务加载的 PM 入口,负责需求对齐、流程编排与交付组织。PM 职责作用于承接完整任务的主会话,节点职责由子 Agent 角色和 task 定义。 |
| 108 | 108 | ||
| 109 | -主会话从用户的原始算子需求进入该 Skill,完成需求与环境对齐后编排工作流。子 Agent 在 Workflow YAML 落盘后由 harness 拉起,按自身角色和节点任务执行,按需读取模板或脚本资源。`agents/` 定义 `ops-direct-invoke-architect`、`ops-direct-invoke-developer`、`ops-direct-invoke-verifier` 三个角色,分别安装为 Codex 的 TOML 或 OpenCode、Claude 的 Markdown 角色配置。CANNBot-DSL 的“环境检查”“需求分析”“黑盒设计”“代码检视”等节点按工作性质分配给这些角色。 | 109 | +主会话从用户的原始算子需求进入该 Skill,完成需求与环境对齐后编排工作流。子 Agent 在 Workflow YAML 落盘后由 harness 拉起,按自身角色和节点任务执行,按需读取模板或脚本资源。`agents/` 定义 `ops-direct-invoke-architect`、`ops-direct-invoke-developer`、`ops-direct-invoke-verifier` 角色,分别安装为 Codex 的 TOML 或 OpenCode、Claude 的 Markdown 角色配置。CANNBot-DSL 的“环境检查”“需求分析”“黑盒设计”“代码检视”等节点按工作性质分配给这些角色。 |
| 110 | 110 | ||
| 111 | 每个任务、每轮 Workflow 独立存放 YAML 和运行记录: | 111 | 每个任务、每轮 Workflow 独立存放 YAML 和运行记录: |
| 112 | 112 | ||
| @@ -251,3 +251,10 @@ ops-direct-invoke/ | |||
| 251 | ├── repo-test-develop-kirin/ | 251 | ├── repo-test-develop-kirin/ |
| 252 | └── repo-env-check-kirin/ | 252 | └── repo-env-check-kirin/ |
| 253 | ``` | 253 | ``` |
| 254 | + | ||
| 255 | + | ||
| 256 | +### DSL 性能扩展 | ||
| 257 | + | ||
| 258 | +DSL 在检视修复后直接进入性能优化子图,由 `ops-direct-invoke-perf-coordinator` 编排已安装的原性能 Skill,独立 verifier 验收。优化能力及依赖随本插件安装;不另做摸底,也不复制内部优化策略。功能库存沿用生成测试,候选隔离执行,最终回集成版本通过后再生成文档与交付。详细交接契约由性能任务维护。 | ||
| 259 | + | ||
| 260 | +知识库增强沿原性能 Skill 的可选契约:已有 cannbot-knowledge 时复用,不可用记录原因,以无知识增强模式继续。既有 AscendC 工作流保持原范围。 | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +--- | ||
| 2 | +name: ops-direct-invoke-perf-coordinator | ||
| 3 | +description: 性能编排者,组织独立优化阶段并交接最终实现与证据 | ||
| 4 | +mode: all | ||
| 5 | +--- | ||
| 6 | + | ||
| 7 | +# 性能编排者 | ||
| 8 | + | ||
| 9 | +在 harness 派发的任务边界内组织性能优化,按任务指定的能力契约派发阶段代理、管理阶段交接和恢复。允许使用当前客户端的通用子代理能力;每次派发明确职责、绝对输入输出路径和授权写集。不能替阶段代理执行算法设计、候选修改或设备采集,也不能承担外层独立验收。 | ||
| 10 | + | ||
| 11 | +外层节点状态、重试和最终裁决属于 harness;内部业务状态只通过被调用能力的公开接口推进。只恢复同一任务的有效输入和产物,不通过重建运行规避预算。不得派发其他开发工作流、修改已确认需求、冻结测试、Golden、阈值或外层调度状态。 | ||
| 12 | + | ||
| 13 | +所有中间产物放在任务指定的 WORK_DIR 范围。原工程修改只经授权的回集成步骤完成,保留优化前记录和失败候选证据。任务外环境、共享源码、其他运行和全局配置不在写入范围内。 | ||
| @@ -33,6 +33,20 @@ | |||
| 33 | "vendor/cannbot-skills/ops/ops-simulator", | 33 | "vendor/cannbot-skills/ops/ops-simulator", |
| 34 | "vendor/cannbot-skills/ops/ops-kirin-simulator", | 34 | "vendor/cannbot-skills/ops/ops-kirin-simulator", |
| 35 | "vendor/cannbot-skills/ops/ops-spec-gen", | 35 | "vendor/cannbot-skills/ops/ops-spec-gen", |
| 36 | - "vendor/cannbot-skills/ops/ops-design-paradigms" | 36 | + "vendor/cannbot-skills/ops/ops-design-paradigms", |
| 37 | + "plugins-official/ops-perf-optimize/skills/ascendc-performance-review", | ||
| 38 | + "plugins-official/ops-perf-optimize/skills/ops-perf-acceptance-criteria", | ||
| 39 | + "plugins-official/ops-perf-optimize/skills/ops-perf-analysis", | ||
| 40 | + "plugins-official/ops-perf-optimize/skills/ops-perf-baseline-evaluate", | ||
| 41 | + "plugins-official/ops-perf-optimize/skills/ops-perf-implementation", | ||
| 42 | + "plugins-official/ops-perf-optimize/skills/ops-perf-optimize-workflow", | ||
| 43 | + "plugins-official/ops-perf-optimize/skills/ops-perf-postprocess", | ||
| 44 | + "plugins-official/ops-perf-optimize/skills/ops-perf-preparation", | ||
| 45 | + "plugins-official/ops-perf-optimize/skills/ops-perf-profile-feature-extractor", | ||
| 46 | + "vendor/cannbot-skills/ops/ops-theoretical-performance-estimation", | ||
| 47 | + "vendor/cannbot-skills/ops/ascendc-perf-optimize", | ||
| 48 | + "vendor/cannbot-skills/ops/ascendc-blaze-migration", | ||
| 49 | + "vendor/cannbot-skills/ops/ascendc-sync-audit", | ||
| 50 | + "vendor/cannbot-skills/ops/ascendc-registry-invoke-template" | ||
| 37 | ] | 51 | ] |
| 38 | } | 52 | } |
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | ## 模块范围 | 3 | ## 模块范围 |
| 4 | 4 | ||
| 5 | -插件 `agents/` 下的三个角色定义,以及安装器为不同客户端生成的对应角色配置。角色职责与 `ops-direct-invoke` Skill 中的介绍保持一致。 | 5 | +插件 `agents/` 下的角色定义,以及安装器为不同客户端生成的对应角色配置。角色职责与 `ops-direct-invoke` Skill 中的介绍保持一致。 |
| 6 | 6 | ||
| 7 | ## 设计思想 | 7 | ## 设计思想 |
| 8 | 8 | ||
| @@ -41,3 +41,8 @@ developer 负责实际功能验证、性能测量等执行工作并交付完整 | |||
| 41 | 3. 不因新增工作阶段就新增角色或将现有角色固定在该阶段;按规划探索、具体执行、验收的工作性质选择已有身份。 | 41 | 3. 不因新增工作阶段就新增角色或将现有角色固定在该阶段;按规划探索、具体执行、验收的工作性质选择已有身份。 |
| 42 | 4. 角色名称是 task 与客户端配置之间的引用契约。修改名称时同步核对 task、workflow、动态子图生成器和安装声明,确保实际客户端能加载对应角色。 | 42 | 4. 角色名称是 task 与客户端配置之间的引用契约。修改名称时同步核对 task、workflow、动态子图生成器和安装声明,确保实际客户端能加载对应角色。 |
| 43 | 5. 修改角色源文件后,核对安装生成的配置是否同步。客户端格式可以不同,但身份、职责和权限语义应一致;遵循入口中的安装副本维护要求。 | 43 | 5. 修改角色源文件后,核对安装生成的配置是否同步。客户端格式可以不同,但身份、职责和权限语义应一致;遵循入口中的安装副本维护要求。 |
| 44 | + | ||
| 45 | + | ||
| 46 | +### 扩展编排身份 | ||
| 47 | + | ||
| 48 | +性能扩展采用专用编排角色,这是普通 developer 禁止派发代理与外部能力需要内部编排之间的职责隔离。角色仅定义编排权限,不绑定阶段算法;实际 Skill 与路径由 task 指定。内部阶段遵循原能力契约,外层仍由 harness 和独立 verifier 裁决。此例外不放宽其他角色权限。 | ||
Aplugins-official/ops-direct-invoke/skills/ops-direct-invoke-maintain/test/ut/dsl_performance/test.py+357-0
| @@ -0,0 +1,357 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +"""Exercise the DSL inventory and the installed optimization request boundary.""" | ||
| 12 | + | ||
| 13 | +import csv | ||
| 14 | +import importlib.util | ||
| 15 | +import json | ||
| 16 | +import os | ||
| 17 | +import shutil | ||
| 18 | +import subprocess | ||
| 19 | +import sys | ||
| 20 | +import tempfile | ||
| 21 | +import unittest | ||
| 22 | +from pathlib import Path | ||
| 23 | + | ||
| 24 | +import yaml | ||
| 25 | + | ||
| 26 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | ||
| 27 | +from support import SCRIPTS, run_tests | ||
| 28 | + | ||
| 29 | +spec = importlib.util.spec_from_file_location( | ||
| 30 | + "perf_adapter", SCRIPTS / "prepare_dsl_performance.py" | ||
| 31 | +) | ||
| 32 | +adapter = importlib.util.module_from_spec(spec) | ||
| 33 | +spec.loader.exec_module(adapter) | ||
| 34 | +REPO = SCRIPTS.parents[4] | ||
| 35 | +PERF = REPO / "plugins-official/ops-perf-optimize/skills/ops-perf-optimize-workflow" | ||
| 36 | + | ||
| 37 | + | ||
| 38 | +class InventoryTests(unittest.TestCase): | ||
| 39 | + def candidate_arguments(self, root): | ||
| 40 | + args = [ | ||
| 41 | + sys.executable, | ||
| 42 | + str(SCRIPTS / "run_dsl_performance_case.py"), | ||
| 43 | + "--candidate-root", | ||
| 44 | + str(root), | ||
| 45 | + "--execution-map", | ||
| 46 | + str(self.work / "perf-optimize/inputs/execution-map.json"), | ||
| 47 | + "--case-id", | ||
| 48 | + "blackbox", | ||
| 49 | + "--entry", | ||
| 50 | + "operators.reduce_sum.reduce_sum:run", | ||
| 51 | + "--device", | ||
| 52 | + "npu", | ||
| 53 | + ] | ||
| 54 | + return args | ||
| 55 | + | ||
| 56 | + def check_request_freeze(self, request, args): | ||
| 57 | + # Synthetic package identity exercises the real freeze API without an NPU. | ||
| 58 | + package = self.tests / "cannbotdsl_case_contract.py" | ||
| 59 | + environment = { | ||
| 60 | + "schema_version": 1, | ||
| 61 | + "dsl_version": "unit-test-fixture", | ||
| 62 | + "package_files": [ | ||
| 63 | + { | ||
| 64 | + "path": str(package.resolve()), | ||
| 65 | + "sha256": adapter.sha(package.read_bytes()), | ||
| 66 | + } | ||
| 67 | + ], | ||
| 68 | + } | ||
| 69 | + (request.parent / "dsl-environment.json").write_text( | ||
| 70 | + json.dumps(environment), encoding="utf-8" | ||
| 71 | + ) | ||
| 72 | + output = request.parent / "run" | ||
| 73 | + result = subprocess.run( | ||
| 74 | + args + ["freeze", "--request", str(request), "--output-dir", str(output)], | ||
| 75 | + capture_output=True, | ||
| 76 | + text=True, | ||
| 77 | + encoding="utf-8", | ||
| 78 | + ) | ||
| 79 | + self.assertEqual(result.returncode, 0, result.stderr) | ||
| 80 | + manifest = json.loads( | ||
| 81 | + (output / "run-manifest.json").read_text(encoding="utf-8") | ||
| 82 | + ) | ||
| 83 | + self.assertEqual(manifest["collections"]["functional_full"]["count"], 3) | ||
| 84 | + self.assertEqual(manifest["collections"]["performance_full"]["count"], 3) | ||
| 85 | + frozen = Path(manifest["collections"]["functional_full"]["case_manifest"]) | ||
| 86 | + self.assertEqual( | ||
| 87 | + (frozen.parent / "testcase.csv").read_bytes(), | ||
| 88 | + (self.tests / "testcase.csv").read_bytes(), | ||
| 89 | + ) | ||
| 90 | + | ||
| 91 | + def request_arguments(self, request): | ||
| 92 | + create = [ | ||
| 93 | + "create-request", | ||
| 94 | + "--request", | ||
| 95 | + str(request), | ||
| 96 | + "--operator-name", | ||
| 97 | + "reduce_sum", | ||
| 98 | + "--code-dir", | ||
| 99 | + str(self.tests.parent), | ||
| 100 | + "--backend", | ||
| 101 | + "cannbot_dsl", | ||
| 102 | + "--dsl-repo-root", | ||
| 103 | + str(self.work), | ||
| 104 | + "--dsl-entrypoint", | ||
| 105 | + "operators.reduce_sum.reduce_sum:run", | ||
| 106 | + "--dsl-execution-mode", | ||
| 107 | + "jit", | ||
| 108 | + "--target-soc", | ||
| 109 | + "Ascend950", | ||
| 110 | + "--functional-mode", | ||
| 111 | + "existing", | ||
| 112 | + "--functional-cases", | ||
| 113 | + str(request.parent / "inputs/functional"), | ||
| 114 | + "--performance-cases", | ||
| 115 | + str(request.parent / "inputs/performance.csv"), | ||
| 116 | + "--cann-env-command", | ||
| 117 | + "inherit", | ||
| 118 | + "--confirmed-by", | ||
| 119 | + "unit-test-fixture", | ||
| 120 | + ] | ||
| 121 | + return create | ||
| 122 | + | ||
| 123 | + def setUp(self): | ||
| 124 | + self.temp = tempfile.TemporaryDirectory() | ||
| 125 | + self.addCleanup(self.temp.cleanup) | ||
| 126 | + self.work = Path(self.temp.name) | ||
| 127 | + design = self.work / "design/doc" | ||
| 128 | + design.mkdir(parents=True) | ||
| 129 | + (design / "spec.yaml").write_text("op:\n name: reduce_sum\n", encoding="utf-8") | ||
| 130 | + self.tests = self.work / "operators/reduce_sum/test" | ||
| 131 | + self.tests.mkdir(parents=True) | ||
| 132 | + for name in ( | ||
| 133 | + "test_reduce_sum.py", | ||
| 134 | + "reduce_sum_golden.py", | ||
| 135 | + "cannbotdsl_case_contract.py", | ||
| 136 | + ): | ||
| 137 | + (self.tests / name).write_text("# frozen test asset\n", encoding="utf-8") | ||
| 138 | + self.rows = [ | ||
| 139 | + dict( | ||
| 140 | + sheet=sheet, | ||
| 141 | + case_id=sheet, | ||
| 142 | + status="active", | ||
| 143 | + expected="match_golden", | ||
| 144 | + seed="41", | ||
| 145 | + inputs_json='{"x":{"shape":[17]}}', | ||
| 146 | + assertions_json='[{"kind":"execution","repeat":2}]', | ||
| 147 | + ) | ||
| 148 | + for sheet in ("blackbox", "whitebox", "tdd") | ||
| 149 | + ] | ||
| 150 | + self.write_rows() | ||
| 151 | + | ||
| 152 | + def write_rows(self): | ||
| 153 | + with (self.tests / "testcase.csv").open( | ||
| 154 | + "w", encoding="utf-8", newline="" | ||
| 155 | + ) as stream: | ||
| 156 | + writer = csv.DictWriter(stream, fieldnames=list(self.rows[0])) | ||
| 157 | + writer.writeheader() | ||
| 158 | + writer.writerows(self.rows) | ||
| 159 | + | ||
| 160 | + def test_frozen_assets_and_sequence_preserved_and_retry_idempotent(self): | ||
| 161 | + original = (self.tests / "testcase.csv").read_bytes() | ||
| 162 | + first = adapter.prepare(self.work) | ||
| 163 | + self.assertEqual(first, adapter.prepare(self.work)) | ||
| 164 | + copied = self.work / "perf-optimize/inputs/functional/testcase.csv" | ||
| 165 | + self.assertEqual(copied.read_bytes(), original) | ||
| 166 | + with (copied.parent / "cases.csv").open(encoding="utf-8") as stream: | ||
| 167 | + cases = list(csv.DictReader(stream)) | ||
| 168 | + self.assertEqual(cases[0]["assertions_json"], self.rows[0]["assertions_json"]) | ||
| 169 | + self.assertEqual( | ||
| 170 | + first["cases"][0]["arguments"][:4], | ||
| 171 | + ["--sheet", "blackbox", "--case-id", "blackbox"], | ||
| 172 | + ) | ||
| 173 | + | ||
| 174 | + def test_separate_code_root_preserves_workflow_and_freezes_actual_tests(self): | ||
| 175 | + code = self.work / "code" | ||
| 176 | + code.mkdir() | ||
| 177 | + shutil.move(str(self.work / "operators"), str(code / "operators")) | ||
| 178 | + self.tests = code / "operators/reduce_sum/test" | ||
| 179 | + mapping = adapter.prepare(self.work, code) | ||
| 180 | + self.assertEqual(Path(mapping["casebook"]["path"]), self.tests / "testcase.csv") | ||
| 181 | + self.assertTrue( | ||
| 182 | + (self.work / "perf-optimize/inputs/execution-map.json").is_file() | ||
| 183 | + ) | ||
| 184 | + self.assertFalse((code / "perf-optimize").exists()) | ||
| 185 | + self.assertEqual(mapping, adapter.prepare(self.work, code)) | ||
| 186 | + self.rows[0]["seed"] = "99" | ||
| 187 | + self.write_rows() | ||
| 188 | + with self.assertRaisesRegex(ValueError, "stale"): | ||
| 189 | + adapter.prepare(self.work, code) | ||
| 190 | + | ||
| 191 | + def test_error_checks_retained_but_not_timed(self): | ||
| 192 | + self.rows[0]["expected"] = "raises_error:BAD_SHAPE" | ||
| 193 | + self.write_rows() | ||
| 194 | + adapter.prepare(self.work) | ||
| 195 | + folder = self.work / "perf-optimize/inputs" | ||
| 196 | + with (folder / "performance.csv").open(encoding="utf-8") as stream: | ||
| 197 | + perf = list(csv.DictReader(stream)) | ||
| 198 | + self.assertEqual({row["case_id"] for row in perf}, {"whitebox", "tdd"}) | ||
| 199 | + with (folder / "functional/cases.csv").open(encoding="utf-8") as stream: | ||
| 200 | + functional = list(csv.DictReader(stream)) | ||
| 201 | + self.assertEqual(functional[0]["expected_error"], "") | ||
| 202 | + self.assertEqual(functional[0]["execution_kind"], "host_only") | ||
| 203 | + self.assertEqual( | ||
| 204 | + functional[0]["host_assertion"], "original_runner:raises_error:BAD_SHAPE" | ||
| 205 | + ) | ||
| 206 | + | ||
| 207 | + def test_changed_input_rejected_without_overwriting_snapshot(self): | ||
| 208 | + adapter.prepare(self.work) | ||
| 209 | + path = self.work / "perf-optimize/inputs/execution-map.json" | ||
| 210 | + frozen = path.read_bytes() | ||
| 211 | + self.rows[0]["seed"] = "43" | ||
| 212 | + self.write_rows() | ||
| 213 | + with self.assertRaisesRegex(ValueError, "stale"): | ||
| 214 | + adapter.prepare(self.work) | ||
| 215 | + self.assertEqual(path.read_bytes(), frozen) | ||
| 216 | + | ||
| 217 | + def test_missing_group_duplicate_and_unknown_semantics_rejected(self): | ||
| 218 | + for change in ("group", "duplicate", "semantics"): | ||
| 219 | + with self.subTest(change=change): | ||
| 220 | + rows = [dict(row) for row in self.rows] | ||
| 221 | + if change == "group": | ||
| 222 | + rows[-1]["status"] = "excluded" | ||
| 223 | + elif change == "duplicate": | ||
| 224 | + rows[-1]["case_id"] = rows[0]["case_id"] | ||
| 225 | + else: | ||
| 226 | + rows[-1]["expected"] = "arbitrary_success" | ||
| 227 | + original = self.rows | ||
| 228 | + self.rows = rows | ||
| 229 | + self.write_rows() | ||
| 230 | + with self.assertRaises(ValueError): | ||
| 231 | + adapter.prepare(self.work) | ||
| 232 | + self.rows = original | ||
| 233 | + | ||
| 234 | + def test_real_request_creator_and_validator_accept_adapter_inventory(self): | ||
| 235 | + adapter.prepare(self.work) | ||
| 236 | + request = self.work / "perf-optimize/optimization-request.json" | ||
| 237 | + args = [sys.executable, str(PERF / "scripts/prepare_case_sets.py")] | ||
| 238 | + create = self.request_arguments(request) | ||
| 239 | + result = subprocess.run( | ||
| 240 | + args + create, capture_output=True, text=True, encoding="utf-8" | ||
| 241 | + ) | ||
| 242 | + self.assertEqual(result.returncode, 0, result.stderr) | ||
| 243 | + result = subprocess.run( | ||
| 244 | + args + ["validate-request", "--request", str(request)], | ||
| 245 | + capture_output=True, | ||
| 246 | + text=True, | ||
| 247 | + encoding="utf-8", | ||
| 248 | + ) | ||
| 249 | + self.assertEqual(result.returncode, 0, result.stderr) | ||
| 250 | + self.check_request_freeze(request, args) | ||
| 251 | + performance = request.parent / "inputs/performance.csv" | ||
| 252 | + performance.write_text( | ||
| 253 | + performance.read_text(encoding="utf-8").replace( | ||
| 254 | + ",device,", ",host_only,", 1 | ||
| 255 | + ), | ||
| 256 | + encoding="utf-8", | ||
| 257 | + ) | ||
| 258 | + result = subprocess.run( | ||
| 259 | + args | ||
| 260 | + + [ | ||
| 261 | + "freeze", | ||
| 262 | + "--request", | ||
| 263 | + str(request), | ||
| 264 | + "--output-dir", | ||
| 265 | + str(request.parent / "invalid-run"), | ||
| 266 | + ], | ||
| 267 | + capture_output=True, | ||
| 268 | + text=True, | ||
| 269 | + encoding="utf-8", | ||
| 270 | + ) | ||
| 271 | + self.assertNotEqual(result.returncode, 0) | ||
| 272 | + self.assertIn("must contain device cases", result.stdout + result.stderr) | ||
| 273 | + data = json.loads(request.read_text(encoding="utf-8")) | ||
| 274 | + data["confirmation"]["status"] = "pending" | ||
| 275 | + request.write_text(json.dumps(data), encoding="utf-8") | ||
| 276 | + result = subprocess.run( | ||
| 277 | + args + ["validate-request", "--request", str(request)], capture_output=True | ||
| 278 | + ) | ||
| 279 | + self.assertNotEqual(result.returncode, 0) | ||
| 280 | + | ||
| 281 | + def test_candidate_runner_ignores_original_pythonpath_and_rejects_changed_tests( | ||
| 282 | + self, | ||
| 283 | + ): | ||
| 284 | + (self.tests / "test_reduce_sum.py").write_text( | ||
| 285 | + "import os,importlib\n" | ||
| 286 | + "assert importlib.import_module(os.environ['CANNBOTDSL_OP_MODULE']).run() == 'candidate'\n", | ||
| 287 | + encoding="utf-8", | ||
| 288 | + ) | ||
| 289 | + adapter.prepare(self.work) | ||
| 290 | + with tempfile.TemporaryDirectory() as directory: | ||
| 291 | + root = Path(directory) | ||
| 292 | + candidate = root / "operators/reduce_sum" | ||
| 293 | + candidate.mkdir(parents=True) | ||
| 294 | + (candidate / "reduce_sum.py").write_text( | ||
| 295 | + "def run(): return 'candidate'\n", encoding="utf-8" | ||
| 296 | + ) | ||
| 297 | + (self.tests.parent / "reduce_sum.py").write_text( | ||
| 298 | + "def run(): return 'original'\n", encoding="utf-8" | ||
| 299 | + ) | ||
| 300 | + shutil.copytree(self.tests, candidate / "test") | ||
| 301 | + args = self.candidate_arguments(root) | ||
| 302 | + env = {**os.environ, "PYTHONPATH": str(self.work)} | ||
| 303 | + result = subprocess.run( | ||
| 304 | + args, env=env, capture_output=True, text=True, encoding="utf-8" | ||
| 305 | + ) | ||
| 306 | + self.assertEqual(result.returncode, 0, result.stderr) | ||
| 307 | + wrong = list(args) | ||
| 308 | + wrong[wrong.index("--entry") + 1] = "original.reduce_sum:run" | ||
| 309 | + result = subprocess.run( | ||
| 310 | + wrong, env=env, capture_output=True, text=True, encoding="utf-8" | ||
| 311 | + ) | ||
| 312 | + self.assertNotEqual(result.returncode, 0) | ||
| 313 | + self.assertIn("frozen operator identity", result.stderr) | ||
| 314 | + result = subprocess.run( | ||
| 315 | + args + ["--error-matcher", "json"], | ||
| 316 | + env=env, | ||
| 317 | + capture_output=True, | ||
| 318 | + text=True, | ||
| 319 | + encoding="utf-8", | ||
| 320 | + ) | ||
| 321 | + self.assertNotEqual(result.returncode, 0) | ||
| 322 | + self.assertIn("matcher import escaped", result.stderr) | ||
| 323 | + (candidate / "test/reduce_sum_golden.py").write_text( | ||
| 324 | + "# modified\n", encoding="utf-8" | ||
| 325 | + ) | ||
| 326 | + result = subprocess.run( | ||
| 327 | + args, env=env, capture_output=True, text=True, encoding="utf-8" | ||
| 328 | + ) | ||
| 329 | + self.assertNotEqual(result.returncode, 0) | ||
| 330 | + self.assertIn("changed frozen", result.stderr) | ||
| 331 | + | ||
| 332 | + def test_assembled_child_and_registered_role(self): | ||
| 333 | + script = SCRIPTS / "assemble_workflow.py" | ||
| 334 | + output = self.work / "workflow.yaml" | ||
| 335 | + result = subprocess.run( | ||
| 336 | + [ | ||
| 337 | + sys.executable, | ||
| 338 | + str(script), | ||
| 339 | + "--template", | ||
| 340 | + str(SCRIPTS.parent / "workflows/cannbot-dsl/op-dev.yaml"), | ||
| 341 | + "--output", | ||
| 342 | + str(output), | ||
| 343 | + ], | ||
| 344 | + capture_output=True, | ||
| 345 | + text=True, | ||
| 346 | + encoding="utf-8", | ||
| 347 | + ) | ||
| 348 | + self.assertEqual(result.returncode, 0, result.stderr) | ||
| 349 | + graph = yaml.safe_load(output.read_text(encoding="utf-8")) | ||
| 350 | + node = next(n for n in graph["nodes"] if n["id"] == "performance") | ||
| 351 | + child = yaml.safe_load((self.work / node["file"]).read_text(encoding="utf-8")) | ||
| 352 | + executor = child["nodes"][0]["executor"] | ||
| 353 | + self.assertTrue((SCRIPTS.parents[2] / "agents" / (executor + ".md")).is_file()) | ||
| 354 | + | ||
| 355 | + | ||
| 356 | +if __name__ == "__main__": | ||
| 357 | + run_tests() | ||
| @@ -120,6 +120,14 @@ PM 按调度 Skill 的要求等待、查询和转发进度,不持续通读产 | |||
| 120 | 120 | ||
| 121 | 缺少必要信息、权限或外部条件时如实汇报,不反复执行相同的无效流程。最终说明交付位置、验证结果和限制;模拟执行及接口回归不等于真实 Agent 或设备验证通过。 | 121 | 缺少必要信息、权限或外部条件时如实汇报,不反复执行相同的无效流程。最终说明交付位置、验证结果和限制;模拟执行及接口回归不等于真实 Agent 或设备验证通过。 |
| 122 | 122 | ||
| 123 | +### DSL 性能优化接入 | ||
| 124 | + | ||
| 125 | +DSL op-dev 用原 `ops-perf-optimize-workflow` 替换摸底节点。PM 在首次需求对齐时读取实际安装版本的请求接入规则,收集轮数或可计算目标、对标来源、Python/CANN、SoC 与 JIT/AOT 模式;已有有效确认直接复用,记录到本轮需求中。不要硬编码轮数或把环境的 full/compile_only 当成 JIT/AOT。无交互运行必须提供这些已确认输入。 | ||
| 126 | + | ||
| 127 | +主图的 performance 是静态子图;harness 调度专用 perf-coordinator 与独立 verifier。性能编排者只在该任务内部按原 Skill 派发通用阶段代理,外层 PM、developer 和其他节点的权限不变。阶段业务状态使用原 Skill 公开接口,外层状态仍由 harness 管理。恢复保留同一请求、run 和已用预算,不清空内部状态。 | ||
| 128 | + | ||
| 129 | +性能输入适配与输出契约见 `tasks/cannbot-dsl/性能优化.yaml`。确定性库存转换使用 `scripts/prepare_dsl_performance.py`;功能全集来自冻结原用例,设备性能集合使用相同 case 的原输入配方。性能结果在 `perf-optimize/run/`,最终交接是 `perf-optimize/HANDOFF.md`;文档与交付使用回集成后的版本及证据,优化前 `review-fix/selected.json` 保留为来源记录。 | ||
| 130 | + | ||
| 123 | ## DSL 代码版本管理 | 131 | ## DSL 代码版本管理 |
| 124 | 132 | ||
| 125 | 新 DSL 运行采用 [代码版本协议](references/code-versions.md):由创建工作区节点初始化 `$WORK_DIR/code`,代码读写与测试使用 `CODE_DIR`,报告与 harness 状态仍在 `WORK_DIR`。所有代码写入节点按每轮尝试记录 Git 基线、提交与验证证据;并行 Unit 使用独立 worktree,汇合后重验。已有运行 YAML 与目录不迁移,启动新一轮使用此契约。`rollback_to` 仍为返工调度,Git 恢复必须指定完整 SHA。 | 133 | 新 DSL 运行采用 [代码版本协议](references/code-versions.md):由创建工作区节点初始化 `$WORK_DIR/code`,代码读写与测试使用 `CODE_DIR`,报告与 harness 状态仍在 `WORK_DIR`。所有代码写入节点按每轮尝试记录 Git 基线、提交与验证证据;并行 Unit 使用独立 worktree,汇合后重验。已有运行 YAML 与目录不迁移,启动新一轮使用此契约。`rollback_to` 仍为返工调度,Git 恢复必须指定完整 SHA。 |
| @@ -446,6 +446,7 @@ def assemble_complete_workflow(definition, base): | |||
| 446 | DSL_ROLES = frozenset( | 446 | DSL_ROLES = frozenset( |
| 447 | { | 447 | { |
| 448 | "ops-direct-invoke-architect", | 448 | "ops-direct-invoke-architect", |
| 449 | + "ops-direct-invoke-perf-coordinator", | ||
| 449 | "ops-direct-invoke-developer", | 450 | "ops-direct-invoke-developer", |
| 450 | "ops-direct-invoke-verifier", | 451 | "ops-direct-invoke-verifier", |
| 451 | } | 452 | } |
Aplugins-official/ops-direct-invoke/skills/ops-direct-invoke/scripts/prepare_dsl_performance.py+205-0
| @@ -0,0 +1,205 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# ---------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ---------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +"""Adapt the frozen DSL casebook without changing its recipes or test semantics.""" | ||
| 13 | + | ||
| 14 | +import argparse | ||
| 15 | +import csv | ||
| 16 | +import hashlib | ||
| 17 | +import io | ||
| 18 | +import json | ||
| 19 | +import logging | ||
| 20 | +import re | ||
| 21 | +import sys | ||
| 22 | +from pathlib import Path | ||
| 23 | + | ||
| 24 | +import yaml | ||
| 25 | + | ||
| 26 | +SHEETS = {"blackbox", "whitebox", "tdd"} | ||
| 27 | +IGNORED = {"__pycache__", ".pytest_cache", "testcase_output", ".git"} | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +def write_frozen_inputs(work, payload, mapping): | ||
| 31 | + output = work / "perf-optimize/inputs" | ||
| 32 | + # Compare the entire snapshot before writing; a retry must never replace frozen input. | ||
| 33 | + if output.exists(): | ||
| 34 | + existing = { | ||
| 35 | + path.relative_to(output).as_posix(): path.read_bytes() | ||
| 36 | + for path in output.rglob("*") | ||
| 37 | + if path.is_file() | ||
| 38 | + } | ||
| 39 | + if existing != payload: | ||
| 40 | + raise ValueError( | ||
| 41 | + "stale performance inputs; preserve the run and resolve changed inputs" | ||
| 42 | + ) | ||
| 43 | + return mapping | ||
| 44 | + for name, data in payload.items(): | ||
| 45 | + target = output / name | ||
| 46 | + target.parent.mkdir(parents=True, exist_ok=True) | ||
| 47 | + target.write_bytes(data) | ||
| 48 | + return mapping | ||
| 49 | + | ||
| 50 | + | ||
| 51 | +def execution_mapping(tests, op, normalized, payload): | ||
| 52 | + mapping = { | ||
| 53 | + "schema_version": 1, | ||
| 54 | + "casebook": { | ||
| 55 | + "path": str(tests / "testcase.csv"), | ||
| 56 | + "sha256": sha((tests / "testcase.csv").read_bytes()), | ||
| 57 | + }, | ||
| 58 | + "operator": op, | ||
| 59 | + "runner_relative": f"operators/{op}/test/test_{op}.py", | ||
| 60 | + "module": f"operators.{op}.{op}", | ||
| 61 | + "cases": [ | ||
| 62 | + { | ||
| 63 | + "case_id": row["case_id"], | ||
| 64 | + "sheet": row["sheet"], | ||
| 65 | + "execution_kind": row["execution_kind"], | ||
| 66 | + "arguments": [ | ||
| 67 | + "--sheet", | ||
| 68 | + row["sheet"], | ||
| 69 | + "--case-id", | ||
| 70 | + row["case_id"], | ||
| 71 | + "--device", | ||
| 72 | + "npu", | ||
| 73 | + "--require-accelerator", | ||
| 74 | + ], | ||
| 75 | + } | ||
| 76 | + for row in normalized | ||
| 77 | + ], | ||
| 78 | + "assets": {key: sha(value) for key, value in payload.items()}, | ||
| 79 | + } | ||
| 80 | + return mapping | ||
| 81 | + | ||
| 82 | + | ||
| 83 | +def read_casebook(tests): | ||
| 84 | + with (tests / "testcase.csv").open(encoding="utf-8-sig", newline="") as stream: | ||
| 85 | + reader = csv.DictReader(stream) | ||
| 86 | + fields = list(reader.fieldnames or []) | ||
| 87 | + rows = list(reader) | ||
| 88 | + if not {"sheet", "case_id", "status", "expected", "seed", "inputs_json"} <= set( | ||
| 89 | + fields | ||
| 90 | + ): | ||
| 91 | + raise ValueError("casebook missing required DSL columns") | ||
| 92 | + active = [row for row in rows if row["status"] == "active"] | ||
| 93 | + if {row["sheet"] for row in active} != SHEETS: | ||
| 94 | + raise ValueError("active blackbox, whitebox and tdd groups are required") | ||
| 95 | + ids = [row["case_id"] for row in active] | ||
| 96 | + if any(not item for item in ids) or len(set(ids)) != len(ids): | ||
| 97 | + raise ValueError("case IDs must be nonempty and globally unique") | ||
| 98 | + extra = [ | ||
| 99 | + key | ||
| 100 | + for key in ("execution_kind", "expected_error", "host_assertion") | ||
| 101 | + if key not in fields | ||
| 102 | + ] | ||
| 103 | + normalized = [] | ||
| 104 | + for row in active: | ||
| 105 | + json.loads(row["inputs_json"]) | ||
| 106 | + if row.get("assertions_json"): | ||
| 107 | + json.loads(row["assertions_json"]) | ||
| 108 | + kind = classify(row) | ||
| 109 | + item = {**row, "execution_kind": kind} | ||
| 110 | + item.setdefault("expected_error", "") | ||
| 111 | + item.setdefault("host_assertion", "") | ||
| 112 | + if row["expected"].startswith("raises_error:"): | ||
| 113 | + item["expected_error"] = "" | ||
| 114 | + item["host_assertion"] = "original_runner:" + row["expected"] | ||
| 115 | + normalized.append(item) | ||
| 116 | + device = [row for row in normalized if row["execution_kind"] == "device"] | ||
| 117 | + if not device: | ||
| 118 | + raise ValueError("no device cases available for performance optimization") | ||
| 119 | + return fields, extra, normalized, device | ||
| 120 | + | ||
| 121 | + | ||
| 122 | +def sha(data): | ||
| 123 | + return hashlib.sha256(data).hexdigest() | ||
| 124 | + | ||
| 125 | + | ||
| 126 | +def csv_bytes(fields, rows): | ||
| 127 | + stream = io.StringIO(newline="") | ||
| 128 | + writer = csv.DictWriter(stream, fieldnames=fields, lineterminator="\n") | ||
| 129 | + writer.writeheader() | ||
| 130 | + writer.writerows(rows) | ||
| 131 | + return stream.getvalue().encode("utf-8") | ||
| 132 | + | ||
| 133 | + | ||
| 134 | +def classify(row): | ||
| 135 | + expected = row.get("expected", "") | ||
| 136 | + kind = row.get("execution_kind", "") | ||
| 137 | + if expected.startswith("raises_error:"): | ||
| 138 | + if kind not in ("", "expected_error"): | ||
| 139 | + raise ValueError("error case cannot be a device performance case") | ||
| 140 | + # The generation runner matches symbolic codes through its error matcher. | ||
| 141 | + # The performance protocol's expected_error means a literal substring. | ||
| 142 | + # Use its non-timed assertion route instead of inventing an error message. | ||
| 143 | + return "host_only" | ||
| 144 | + if kind == "host_only": | ||
| 145 | + if not row.get("host_assertion"): | ||
| 146 | + raise ValueError("host_only requires an explicit host_assertion") | ||
| 147 | + return kind | ||
| 148 | + if kind not in ("", "device"): | ||
| 149 | + raise ValueError(f"unsupported execution_kind: {kind}") | ||
| 150 | + if expected not in ("match_golden", "match_golden_nan", "assertions"): | ||
| 151 | + raise ValueError(f"unsupported expected outcome: {expected}") | ||
| 152 | + return "device" | ||
| 153 | + | ||
| 154 | + | ||
| 155 | +def prepare(work, code_dir=None): | ||
| 156 | + work = work.resolve() | ||
| 157 | + spec = yaml.safe_load((work / "design/doc/spec.yaml").read_text(encoding="utf-8")) | ||
| 158 | + op = spec["op"]["name"] | ||
| 159 | + if not isinstance(op, str) or not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", op): | ||
| 160 | + raise ValueError("spec.op.name must be a Python identifier") | ||
| 161 | + source = code_dir.resolve() if code_dir is not None else work | ||
| 162 | + tests = source / "operators" / op / "test" | ||
| 163 | + for name in (f"test_{op}.py", f"{op}_golden.py", "testcase.csv"): | ||
| 164 | + if not (tests / name).is_file(): | ||
| 165 | + raise ValueError(f"missing test asset: {name}") | ||
| 166 | + fields, extra, normalized, device = read_casebook(tests) | ||
| 167 | + payload = {} | ||
| 168 | + for path in sorted(tests.rglob("*")): | ||
| 169 | + relative = path.relative_to(tests) | ||
| 170 | + if any(part in IGNORED for part in relative.parts): | ||
| 171 | + continue | ||
| 172 | + if path.is_symlink(): | ||
| 173 | + raise ValueError(f"test asset symlink is not frozen: {path}") | ||
| 174 | + if path.is_file(): | ||
| 175 | + payload["functional/" + relative.as_posix()] = path.read_bytes() | ||
| 176 | + payload["functional/cases.csv"] = csv_bytes(fields + extra, normalized) | ||
| 177 | + payload["performance.csv"] = csv_bytes(fields + extra, device) | ||
| 178 | + mapping = execution_mapping(tests, op, normalized, payload) | ||
| 179 | + payload["execution-map.json"] = ( | ||
| 180 | + json.dumps(mapping, ensure_ascii=False, indent=2) + "\n" | ||
| 181 | + ).encode("utf-8") | ||
| 182 | + return write_frozen_inputs(work, payload, mapping) | ||
| 183 | + | ||
| 184 | + | ||
| 185 | +def main(): | ||
| 186 | + parser = argparse.ArgumentParser(description=__doc__) | ||
| 187 | + parser.add_argument("--work-dir", type=Path, required=True) | ||
| 188 | + parser.add_argument( | ||
| 189 | + "--code-dir", type=Path, help="source root returned by code_versions status" | ||
| 190 | + ) | ||
| 191 | + args = parser.parse_args() | ||
| 192 | + try: | ||
| 193 | + result = prepare(args.work_dir, args.code_dir) | ||
| 194 | + except (ValueError, KeyError, OSError) as error: | ||
| 195 | + parser.exit(1, f"{error}\n") | ||
| 196 | + output = logging.Logger("dsl_performance.inventory", level=logging.INFO) | ||
| 197 | + output.addHandler(logging.StreamHandler(sys.stdout)) | ||
| 198 | + output.info( | ||
| 199 | + "%s", | ||
| 200 | + json.dumps({"operator": result["operator"], "cases": len(result["cases"])}), | ||
| 201 | + ) | ||
| 202 | + | ||
| 203 | + | ||
| 204 | +if __name__ == "__main__": | ||
| 205 | + main() | ||
Aplugins-official/ops-direct-invoke/skills/ops-direct-invoke/scripts/run_dsl_performance_case.py+119-0
| @@ -0,0 +1,119 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# ---------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ---------------------------------------------------------------------------- | ||
| 11 | + | ||
| 12 | +"""Run a frozen functional case against an isolated candidate's original entry.""" | ||
| 13 | + | ||
| 14 | +import argparse | ||
| 15 | +import hashlib | ||
| 16 | +import importlib | ||
| 17 | +import json | ||
| 18 | +import logging | ||
| 19 | +import os | ||
| 20 | +from pathlib import Path | ||
| 21 | +import runpy | ||
| 22 | +import sys | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +def validate_frozen_assets(root, runner, mapping): | ||
| 26 | + for name, expected in mapping["assets"].items(): | ||
| 27 | + if not name.startswith("functional/") or name == "functional/cases.csv": | ||
| 28 | + continue | ||
| 29 | + relative = Path(name).relative_to("functional") | ||
| 30 | + asset = (runner.parent / relative).resolve(strict=True) | ||
| 31 | + if not asset.is_relative_to(root): | ||
| 32 | + raise ValueError("test asset escapes candidate root") | ||
| 33 | + if hashlib.sha256(asset.read_bytes()).hexdigest() != expected: | ||
| 34 | + raise ValueError(f"candidate changed frozen test asset: {relative}") | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +def isolate_imports(root, runner, mapping): | ||
| 38 | + original = Path(mapping["casebook"]["path"]).parents[3].resolve() | ||
| 39 | + os.chdir(root) | ||
| 40 | + search_paths = [] | ||
| 41 | + for item in sys.path: | ||
| 42 | + if not item: | ||
| 43 | + continue | ||
| 44 | + resolved = Path(item).resolve() | ||
| 45 | + if resolved.is_relative_to(original) or resolved.is_relative_to(root): | ||
| 46 | + continue | ||
| 47 | + search_paths.append(item) | ||
| 48 | + sys.path[:] = [str(root), str(runner.parent), *search_paths] | ||
| 49 | + os.environ["PYTHONPATH"] = str(root) | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +def execute(root, mapping_path, case_id, entry, device, error_matcher=None): | ||
| 53 | + root = root.resolve(strict=True) | ||
| 54 | + mapping = json.loads(mapping_path.read_text(encoding="utf-8")) | ||
| 55 | + selected = [case for case in mapping["cases"] if case["case_id"] == case_id] | ||
| 56 | + if len(selected) != 1: | ||
| 57 | + raise ValueError("case_id must identify exactly one frozen case") | ||
| 58 | + runner = (root / mapping["runner_relative"]).resolve(strict=True) | ||
| 59 | + if not runner.is_relative_to(root): | ||
| 60 | + raise ValueError("runner escapes candidate root") | ||
| 61 | + validate_frozen_assets(root, runner, mapping) | ||
| 62 | + isolate_imports(root, runner, mapping) | ||
| 63 | + if ":" in entry: | ||
| 64 | + entry_module, entry = entry.split(":", 1) | ||
| 65 | + if entry_module != mapping["module"]: | ||
| 66 | + raise ValueError("entry module differs from frozen operator identity") | ||
| 67 | + os.environ["CANNBOTDSL_OP_MODULE"] = mapping["module"] | ||
| 68 | + os.environ["CANNBOTDSL_OP_ENTRY"] = entry | ||
| 69 | + os.environ.pop("CANNBOTDSL_ERROR_MATCHER", None) | ||
| 70 | + if error_matcher: | ||
| 71 | + matcher = importlib.import_module(error_matcher) | ||
| 72 | + if not Path(matcher.__file__).resolve(strict=True).is_relative_to(root): | ||
| 73 | + raise ValueError("error matcher import escaped candidate root") | ||
| 74 | + os.environ["CANNBOTDSL_ERROR_MATCHER"] = error_matcher | ||
| 75 | + module = importlib.import_module(mapping["module"]) | ||
| 76 | + loaded = Path(module.__file__).resolve(strict=True) | ||
| 77 | + if not loaded.is_relative_to(root): | ||
| 78 | + raise ValueError("operator import escaped candidate root") | ||
| 79 | + if not callable(getattr(module, entry, None)): | ||
| 80 | + raise ValueError("candidate public entry is not callable") | ||
| 81 | + identity = { | ||
| 82 | + "candidate_root": str(root), | ||
| 83 | + "module_path": str(loaded), | ||
| 84 | + "source_sha256": hashlib.sha256(loaded.read_bytes()).hexdigest(), | ||
| 85 | + "case_id": case_id, | ||
| 86 | + } | ||
| 87 | + evidence = logging.Logger("dsl_performance.candidate", level=logging.INFO) | ||
| 88 | + evidence.addHandler(logging.StreamHandler(sys.stdout)) | ||
| 89 | + evidence.info("%s", json.dumps(identity)) | ||
| 90 | + arguments = list(selected[0]["arguments"]) | ||
| 91 | + arguments[arguments.index("--device") + 1] = device | ||
| 92 | + sys.argv = [str(runner), *arguments] | ||
| 93 | + runpy.run_path(str(runner), run_name="__main__") | ||
| 94 | + | ||
| 95 | + | ||
| 96 | +def main(): | ||
| 97 | + parser = argparse.ArgumentParser(description=__doc__) | ||
| 98 | + parser.add_argument("--candidate-root", type=Path, required=True) | ||
| 99 | + parser.add_argument("--execution-map", type=Path, required=True) | ||
| 100 | + parser.add_argument("--case-id", required=True) | ||
| 101 | + parser.add_argument("--entry", required=True) | ||
| 102 | + parser.add_argument("--device", required=True) | ||
| 103 | + parser.add_argument("--error-matcher") | ||
| 104 | + args = parser.parse_args() | ||
| 105 | + try: | ||
| 106 | + execute( | ||
| 107 | + args.candidate_root, | ||
| 108 | + args.execution_map, | ||
| 109 | + args.case_id, | ||
| 110 | + args.entry, | ||
| 111 | + args.device, | ||
| 112 | + args.error_matcher, | ||
| 113 | + ) | ||
| 114 | + except (ValueError, KeyError, OSError) as error: | ||
| 115 | + parser.exit(1, f"{error}\n") | ||
| 116 | + | ||
| 117 | + | ||
| 118 | +if __name__ == "__main__": | ||
| 119 | + main() | ||
| @@ -2,6 +2,9 @@ title: 交付|汇总最终产物 | |||
| 2 | goal: | 2 | goal: |
| 3 | - 汇总当前算子的全部交付件与验收证据,形成可追溯交付清单。 | 3 | - 汇总当前算子的全部交付件与验收证据,形成可追溯交付清单。 |
| 4 | approach: | 4 | approach: |
| 5 | +- 读取 $WORK_DIR/perf-optimize/HANDOFF.md 与其引用的最终回集成证据,以最终源码、构建及加载身份编写文档和交付。优化前 selected.json 与 precision 报告仅作为历史来源;不引用淘汰候选或过期 | ||
| 6 | + Native/AOT 产物。 | ||
| 7 | + | ||
| 5 | - 交付源码与测试取自最终 CODE_DIR;用 `code_versions.py --work-dir "$WORK_DIR" status --bundle <交付目录>/code-history.bundle` 导出完整历史和清单,附 versioning 证据及 references/code-versions.md 中的独立恢复说明。DELIVERY.md 记录最终完整 SHA 与 bundle 摘要。 | 8 | - 交付源码与测试取自最终 CODE_DIR;用 `code_versions.py --work-dir "$WORK_DIR" status --bundle <交付目录>/code-history.bundle` 导出完整历史和清单,附 versioning 证据及 references/code-versions.md 中的独立恢复说明。DELIVERY.md 记录最终完整 SHA 与 bundle 摘要。 |
| 6 | - 读取本 Skill 的 `references/code-versions.md`,按其中协议处理版本;本节点 ID 为 `delivery`(Unit 以生成节点 ID 为准)。用 `code_versions.py --work-dir "$WORK_DIR" status --node <节点ID>` 获取 CODE_DIR,WORK_DIR 始终保持为原工作流目录。 | 9 | - 读取本 Skill 的 `references/code-versions.md`,按其中协议处理版本;本节点 ID 为 `delivery`(Unit 以生成节点 ID 为准)。用 `code_versions.py --work-dir "$WORK_DIR" status --node <节点ID>` 获取 CODE_DIR,WORK_DIR 始终保持为原工作流目录。 |
| 7 | - 按已确认需求清单中的交付绝对路径,交付验收通过的源码、测试、文档、Native 产物及验证证据。 | 10 | - 按已确认需求清单中的交付绝对路径,交付验收通过的源码、测试、文档、Native 产物及验证证据。 |
| @@ -10,12 +13,14 @@ approach: | |||
| 10 | - 在交付目录下写入 DELIVERY.md,并将相同索引保存在 `$WORK_DIR/DELIVERY.md`;列出交付件、运行、导出与复验入口、Native 产物及其验证证据、限制和未解决的非阻断事项。 | 13 | - 在交付目录下写入 DELIVERY.md,并将相同索引保存在 `$WORK_DIR/DELIVERY.md`;列出交付件、运行、导出与复验入口、Native 产物及其验证证据、限制和未解决的非阻断事项。 |
| 11 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 | 14 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 |
| 12 | procedure: | 15 | procedure: |
| 16 | +- 核对当前源码和交付产物身份与性能节点选定的最终回集成版本一致;性能报告来自 perf-optimize/run/,未引用旧 performance/performance-report.md。 | ||
| 17 | + | ||
| 13 | - 读取本 Skill 的 `references/code-versions.md`,通过本节点 status 取得 CODE_DIR;审查提交、依赖版本、冻结输入及原始证据的一致性。发生代码写入的节点须完成协议中的 verifier 登记;不得将 checkpoint 成功视作验证或验收通过。 | 18 | - 读取本 Skill 的 `references/code-versions.md`,通过本节点 status 取得 CODE_DIR;审查提交、依赖版本、冻结输入及原始证据的一致性。发生代码写入的节点须完成协议中的 verifier 登记;不得将 checkpoint 成功视作验证或验收通过。 |
| 14 | - 核对独立副本复跑通过,实际加载的源码、测试及辅助模块来自交付目录,交付位置及版本与需求清单和本次验收记录一致。 | 19 | - 核对独立副本复跑通过,实际加载的源码、测试及辅助模块来自交付目录,交付位置及版本与需求清单和本次验收记录一致。 |
| 15 | - 核对 `DELIVERY.md` 所列交付件均可定位到真实文件。 | 20 | - 核对 `DELIVERY.md` 所列交付件均可定位到真实文件。 |
| 16 | - 核对必需的功能、精度、性能、文档及上游验收证据齐备且相互对应;未将未通过的节点或测试描述为已通过。 | 21 | - 核对必需的功能、精度、性能、文档及上游验收证据齐备且相互对应;未将未通过的节点或测试描述为已通过。 |
| 17 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 | 22 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 |
| 18 | acceptance: | 23 | acceptance: |
| 19 | -- 'test -s "$WORK_DIR/DELIVERY.md"' | 24 | +- test -s "$WORK_DIR/DELIVERY.md" |
| 20 | out_of_scope: | 25 | out_of_scope: |
| 21 | - 不新增实现功能,不把未通过的节点或测试描述为已通过。 | 26 | - 不新增实现功能,不把未通过的节点或测试描述为已通过。 |
| @@ -1,28 +1,52 @@ | |||
| 1 | -title: M6|性能摸底 | 1 | +title: 性能优化|原 Skill 五阶段优化与回集成 |
| 2 | goal: | 2 | goal: |
| 3 | -- 在最终交付的算子实现上,完成全量适用 case 的性能摸底及 MFU、MBU 计算。 | 3 | +- 优化已通过精度与检视修复的 DSL 实现,交付满足原性能 Skill 完成条件的最终版本及可追溯证据。 |
| 4 | approach: | 4 | approach: |
| 5 | -- 读取本 Skill 的 `references/code-versions.md`,本节点 ID 为 `performance`;通过 `code_versions.py --work-dir "$WORK_DIR" status --node performance` 获取 CODE_DIR,WORK_DIR 保持原值。按协议在修改前 begin、验证前 checkpoint,并用 verify 保存当前提交的验证证据。 | 5 | +- 读取 references/code-versions.md,使用 harness 提供的完整节点 ID,通过 code_versions.py status 获取 CODE_DIR,WORK_DIR 保持原值。核对 review-fix/selected.json 的 commit 与当前代码仓 HEAD 一致;原 Skill 的隔离候选沿用其版本协议,不直接写主代码仓。 |
| 6 | -- 先读取 $WORK_DIR/review-fix/selected.json,核对其 commit 与当前 HEAD 一致及整改/托底结论。采集脚本产生新提交后,核对 operators/ 子树与选定版本完全相同,记录选定源码 SHA 与最终完整代码 SHA 的关联;算子源码变化时停止并返回上游验证。 | 6 | +- 加载实际安装的 ops-perf-optimize-workflow,解析其真实 SKILL_DIR 和 scripts 绝对路径,完整读取其工作流契约。不要加载注册式工程的 perf-optimize.yaml,不以本子图文件位置推导性能 |
| 7 | -- 读取已验收的 `$WORK_DIR/environment/soc-info.yaml`、`$WORK_DIR/design/doc/REQUIREMENTS.md`、`$WORK_DIR/design/doc/DESIGN.md` 及 `$CODE_DIR/operators/<op>/test/testcase.csv`;列出 blackbox、whitebox、tdd 三组全部 active case,正常计算用例全部测量,预期异常或无设备计算等不适用项记录原因,不自造输入或按 shape 去重遗漏 case。 | 7 | + Skill 路径。 |
| 8 | -- 在 `$CODE_DIR/scripts/performance/` 编写单进程串行采集脚本:以 `$CODE_DIR` 为 `PYTHONPATH`,按 `CANNBOTDSL_OP_MODULE=operators.<op>.<op>` 导入算子公开入口(入口非 `run` 时按 `CANNBOTDSL_OP_ENTRY`);复用原 case 的输入/输出配方、seed 与 `<op>_golden.py` 的 `make_inputs`,沿用必要的预处理及输出参数约定。调用序列保持原顺序,按调用位置记录和统计;输入准备、输出初始化及必要的状态恢复放在计时区间外。 | 8 | +- 消费 $WORK_DIR/review-fix/selected.json、运行入口、$WORK_DIR/design/doc/spec.yaml、DESIGN.md、environment/environment.yaml、env_selected_soc.yaml |
| 9 | -- 每个适用 case 只执行并采集一次,调用序列仅按原顺序执行一轮,不预热、不重复采样、不另行遍历预编译。优先沿用上游执行记录中最终交付版本的 `CANNBOTDSL_CACHE_DIR`,保持原解释器、CANN/DSL、设备及编译选项;未提供可用缓存时使用本次 `$WORK_DIR/performance/` 下的独立目录。缓存未命中由正常调用触发编译,记录实际缓存目录及命中/编译证据,Host 编译耗时不计入设备耗时。采集环境不得设置 `CANNBOTDSL_DUMP_*`、`CANNBOTDSL_PRINT_*`、`CANNBOTDSL_REUSE_ASCENDC`、`CANNBOTDSL_PIPE_STAGE`,被测代码不得残留 `cbd.print` 或 `dump_*`。 | 9 | + 和已确认需求。用 spec.op.name 定位 operators/<op>;DSL 参考仓为 $WORK_DIR/cannbot-dsl。full/compile_only 是环境能力,不是 jit/aot;从实际构建/入口记录取得执行模式。缺少优化配置或模式时本节点阻塞,由 |
| 10 | -- 用 msprof 包裹采集脚本:`msprof --aic-metrics=PipeUtilization --task-time=on --ai-core=on --application=<采集脚本及参数> --output=$WORK_DIR/performance/msprof_all_cases`;固定设备型号与 `ASCEND_RT_VISIBLE_DEVICES`,不与其他进程共用设备。标记用例分组、case_id 及序列调用位置,关联原始设备任务。 | 10 | + PM 补齐,不编造确认。 |
| 11 | -- 保留全部设备 kernel 及源码启动点的对应关系,单独标识名称为 `metadata` 的算子;主算子为单 kernel 时使用其 `Task Duration`,多 kernel 时使用本次主算子完整设备执行区间的耗时。名称为 `metadata` 的算子范围的耗时不纳入统计,输入准备、Host 编译和测试辅助任务也不计入;保留原始样本并说明主算子的计时边界。 | 11 | +- 用选定 Python 执行本入口 scripts/prepare_dsl_performance.py --work-dir "$WORK_DIR" --code-dir "$CODE_DIR"。该脚本把冻结测试适配到 perf-optimize/inputs/functional/cases.csv、performance.csv |
| 12 | -- 由执行 Agent 根据算子语义、设计及实际 case 推导主算子的有效 FLOPs 与有效读写 Bytes,与排除名称为 `metadata` 的算子后的计时范围一致,直接使用 `soc-info.yaml` 中对应计算单元、精度及稠密/稀疏口径的峰值算力和主存峰值带宽。按 `MFU = 有效 FLOPs / (本次耗时秒数 × 峰值 FLOP/s) × 100%`、`MBU = 有效 Bytes / (本次耗时秒数 × 峰值 Byte/s) × 100%` 计算;统一单位,仅采用额定频率口径,不采集或修正实时频率,不对已有峰值算力再次乘频率。报告列出工作量推导、参数和来源,MBU 注明按有效访存量估算及本次缓存条件;无法可靠计算的指标标记 N/A 并说明原因,不用流水忙碌比例代替 MFU/MBU。 | 12 | + 与 execution-map.json;原 testcase.csv、runner、Golden 和辅助模块保留。原 raises_error:错误码 用例映射为非计时的 host_only,host_assertion 保留原 runner 判定,expected_error 留空; |
| 13 | -- 记录受管采集脚本路径与提交 SHA,将 msprof 原始输出、逐例单次样本、缓存与运行记录、命令、退出码、设备与驱动环境及实现/用例版本保存到 `$WORK_DIR/performance/`,汇总报告固定为 `$WORK_DIR/performance/performance-report.md`。主表覆盖全部 active case,列出分组/case_id、Shape/DType、状态、不适用原因、主算子耗时及 MFU/MBU;对已确认性能目标仅作事实对照,不作达标放行判定。 | 13 | + 由原异常属性或 CANNBOTDSL_ERROR_MATCHER 验证错误码,不把错误码当作异常消息子串,阶段取证时记录实际异常匹配依据。 |
| 14 | -- 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 | 14 | +- 已有 perf-optimize/optimization-request.json 时调用原 prepare_case_sets.py validate-request 并复用匹配的确认。首次调用原 create-request:backend=cannbot_dsl、code_dir=$CODE_DIR/operators/<op>、dsl.repo_root=$WORK_DIR/cannbot-dsl、entrypoint=原 |
| 15 | -- 采集脚本提交后,以该提交运行本节点采集验证;若此前精度证据绑定不同提交,使用相同冻结测试入口补齐当前提交的精度验证证据,之后才交付该版本,不将旧 SHA 的通过记录标为当前版本通过。 | 15 | + module:callable、execution_mode=原 jit/aot、functional_mode=existing、functional_cases=inputs/functional、performance_cases=inputs/performance.csv;所有参数使用绝对路径。优化目标、轮数、对标、环境及其他选项来自有效需求/确认,未指定的默认由安装版本 |
| 16 | + Skill 的接入规则取得,不硬编码或声称用户逐项确认。request 字段来源记录在 HANDOFF.md。 | ||
| 17 | +- 按原 Skill 五阶段及 task-prompts.md 派发;每阶段 INPUT_ARTIFACTS 附原规格、职责相关设计、原运行配置、execution-map.json 和原测试资产绝对路径。功能 case 用 | ||
| 18 | + sheet + case_id 调用固定 runner,不虚构 pytest nodeid。性能 case 使用同一原始输入配方、seed、调用序列、重复和状态恢复要求,完整 target launches 按原采样协议计时;不得将序列拆成无关单次调用。 | ||
| 19 | +- 前处理建立隔离项目根,保持 operators/<op>/ 包层级、原公开入口和全部共享依赖;code_dir 只界定算子源码范围,不代表 Python 导入根。沿抽取映射复制依赖,原测试在候选的同相对路径执行,PYTHONPATH | ||
| 20 | + 只指向候选项目根;参考仓和原 WORK_DIR 均不能作为候选 import 后备。在实际执行进程中取证 __file__、源码、构建与加载身份,候选错误匹配器亦遵循同一隔离要求。 | ||
| 21 | +- 功能逐例复验使用本入口 scripts/run_dsl_performance_case.py --candidate-root <隔离项目根> --execution-map "$WORK_DIR/perf-optimize/inputs/execution-map.json" | ||
| 22 | + --case-id <原case_id> --entry <原module:callable> --device <原设备>,需要时传 --error-matcher <原匹配器模块>;包装器保持原 runner/Golden 资产并核验候选 import | ||
| 23 | + 来源。它只执行功能用例,不能作为正式性能采集器或替代原 Skill 的编译/加载门禁。 | ||
| 24 | +- 本轮原 Skill OUTPUT_DIR 固定为 $WORK_DIR/perf-optimize/run。已有 manifest/state 时按原公开 inspect/verify 和恢复协议继续,不重建冻结输入、不清空状态、不重开轮数。知识库不可用按原 | ||
| 25 | + Skill 记录 kb_unavailable 并继续。 | ||
| 26 | +- 回集成写入 CODE_DIR 前按代码版本协议 begin,--allow 仅授权算子源码及明确依赖,禁止覆盖冻结测试;回写完成后 checkpoint,通过 verify 执行原冻结功能全集及原 Skill 的最终验证,记录当前完整 SHA 的证据,由独立 verifier 登记验收。 | ||
| 27 | +- 执行至原 Skill 的后处理回集成通过;仅在授权 operators/<op> 及已明确依赖范围内回写,保护冻结测试。Native/AOT 产物按最终源码重新生成和验证。保留生成阶段证据,不能把优化前结果冒充优化后结果;无有效收益按原规则保留基线。 | ||
| 28 | +- 按原 workflow_state.py finish/verify 协议结束并复核实际完成状态,将最终 verify 标准输出和退出码保存在 perf-optimize/run/verify-result.json 与 | ||
| 29 | + verify-exit.txt;成功要求原 Skill 完整门禁,不能只凭退出码或局部轮次。写 perf-optimize/HANDOFF.md:请求及确认来源、run/state/report 路径、优化前 selected.json | ||
| 30 | + 来源、最终保留源码/构建/加载身份、回写映射、功能和性能全集证据、目标达成/结束原因、未解决项及下游运行入口。阶段报告仍由原 Skill 管理,不另造状态机。 | ||
| 16 | procedure: | 31 | procedure: |
| 17 | -- 按 `references/code-versions.md` 核对当前提交、允许路径、冻结输入及原始证据;有代码写入时由 verifier 登记通过,提交成功不等于测试或验收通过。 | 32 | +- 通过完整节点 ID 的 status 核对 CODE_DIR、最终 SHA、冻结测试及本轮 verify 证据;HANDOFF.md 必须对应已验收的最终提交,不以优化前 selected.json 的通过记录替代。 |
| 18 | -- 核对报告覆盖三组全部 active case,正常计算用例均已测量,不适用项有依据;输入/输出配方、seed、预处理和调用序列沿用原 case,未自造输入或遗漏同 shape 的不同用例。 | 33 | +- 独立审查 perf-optimize/HANDOFF.md 及其引用的真实原始产物;只读核对执行端保存的原 workflow_state.py verify 输出、退出码及原始证据身份;verifier 不调用会写状态的 |
| 19 | -- 审查采集脚本和执行记录,确认每个适用 case 仅采集一次,序列仅执行一轮且按调用位置对应,无预热、重复采样或额外预编译;实际使用的缓存目录与命中/编译情况有记录,环境无缓存旁路或回读调试操作,设备固定且无并发竞争。 | 34 | + verify/finish,确认 verify 退出码为 0 且输出 status=valid,核对终态为 success、五阶段与原完成条件齐全。缺证据、过期、未完成、失败或等待输入均不得放行。 |
| 20 | -- 对照 msprof 原始数据核对 case 与全部设备任务,确认耗时属于当前交付实现;单 kernel 使用主算子的 Task Duration,多 kernel 使用本次主算子完整设备执行区间,名称为 `metadata` 的算子范围的耗时未纳入统计,输入准备、Host 编译及测试辅助任务也未计入。 | 35 | +- 对照原 testcase.csv 与 execution-map.json 核对三个功能分组、case 身份、输入配方、序列、精度阈值和非设备分类完整;不得通过子集性能改善掩盖原功能集合缺失或退化。审查实际执行日志与原 |
| 21 | -- 核对主算子的有效 FLOPs/Bytes 与排除名称为 `metadata` 的算子后的计时边界一致,推导、峰值参数引用、单位换算及 MFU/MBU 公式正确;仅采用 `soc-info.yaml` 的额定规格口径,未重复乘频率或使用流水忙碌比例,MBU 缓存条件明确,N/A 有理由。不以耗时或利用率高低判定通过,不重复上板执行;证据不足时退回补齐。 | 36 | + Skill 门禁,不重复跑同一批设备采集。 |
| 22 | -- 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 | 37 | +- 核对最终原入口实际导入、构建与加载身份对应回集成后的源码,候选证据未借用原实现;最终 Native/AOT 产物与源码一致。优化前 selected.json 只证明输入来源,不作为优化后的版本验收依据。 |
| 38 | +- 核对按原 Skill 冻结的目标和停止规则判定,并如实区分基线保留、有效收益及目标未达;外层没有加轮或放宽门槛。请求确认无效、原输入变化或恢复身份不匹配时拒绝通过。 | ||
| 39 | +- 验收报告写入 $WORK_DIR/.workflow/reports/,文件名包含完整节点 ID;不修改执行者报告或业务/调度状态。 | ||
| 23 | acceptance: | 40 | acceptance: |
| 24 | -- 'test -s "$WORK_DIR/performance/performance-report.md"' | 41 | +- test -s "$WORK_DIR/perf-optimize/inputs/execution-map.json" |
| 25 | -- 'find "$WORK_DIR/performance" -maxdepth 1 -type d -name "msprof_*" | grep -q .' | 42 | +- test -s "$WORK_DIR/perf-optimize/optimization-request.json" |
| 43 | +- test -s "$WORK_DIR/perf-optimize/run/run-manifest.json" | ||
| 44 | +- test -s "$WORK_DIR/perf-optimize/run/workflow-state.json" | ||
| 45 | +- test -s "$WORK_DIR/perf-optimize/run/性能调优报告.md" | ||
| 46 | +- test -s "$WORK_DIR/perf-optimize/run/integration/VERIFY_REPORT.md" | ||
| 47 | +- test -s "$WORK_DIR/perf-optimize/HANDOFF.md" | ||
| 48 | +- test -s "$WORK_DIR/perf-optimize/run/verify-result.json" | ||
| 49 | +- test -s "$WORK_DIR/perf-optimize/run/verify-exit.txt" | ||
| 26 | out_of_scope: | 50 | out_of_scope: |
| 27 | -- 不做性能优化,不修改算子实现、测试用例或性能测量数据。 | 51 | +- 不修改需求、规格、原设计、冻结用例/Golden/阈值、优化前 selected.json 或外层 harness 状态。不新增独立性能摸底或绕过原 Skill 门禁。 |
| 28 | -- 不修改已冻结的规格、Golden、测试阈值或设计事实,不改写上游硬件资料,仅为绑定新增采集脚本后的完整 SHA 复用既有冻结入口执行精度复验,不修改精度判据。 | 52 | +- 外层执行者承担性能编排,阶段代理按原 Skill 执行,外层 verifier 独立裁决;不得自行宣布外层验收通过。 |
| @@ -3,17 +3,20 @@ goal: | |||
| 3 | - 为最终算子实现补齐接口、构建、运行、约束和验证文档。 | 3 | - 为最终算子实现补齐接口、构建、运行、约束和验证文档。 |
| 4 | approach: | 4 | approach: |
| 5 | - 读取本 Skill 的 `references/code-versions.md`,按其中协议处理版本;本节点 ID 为 `documentation`(Unit 以生成节点 ID 为准)。用 `code_versions.py --work-dir "$WORK_DIR" status --node <节点ID>` 获取 CODE_DIR,WORK_DIR 始终保持为原工作流目录。 | 5 | - 读取本 Skill 的 `references/code-versions.md`,按其中协议处理版本;本节点 ID 为 `documentation`(Unit 以生成节点 ID 为准)。用 `code_versions.py --work-dir "$WORK_DIR" status --node <节点ID>` 获取 CODE_DIR,WORK_DIR 始终保持为原工作流目录。 |
| 6 | -- 读取 $WORK_DIR/review-fix/selected.json,围绕最终选定版本编写文档;基线托底时如实说明风格整改未通过及未解决意见,不引用失败候选的性能或功能结果。 | 6 | +- 读取 $WORK_DIR/perf-optimize/HANDOFF.md 与其引用的最终回集成证据,以最终源码、构建及加载身份编写文档和交付。优化前 selected.json 与 precision 报告仅作为历史来源;不引用淘汰候选或过期 |
| 7 | + Native/AOT 产物。 | ||
| 8 | +- 读取 $WORK_DIR/perf-optimize/HANDOFF.md,围绕最终选定版本编写文档;基线托底时如实说明风格整改未通过及未解决意见,不引用失败候选的性能或功能结果。 | ||
| 7 | - 基于已通过验收的规格、设计、实现和测试证据编写文档,并标明环境与目标 SoC。 | 9 | - 基于已通过验收的规格、设计、实现和测试证据编写文档,并标明环境与目标 SoC。 |
| 8 | - 将文档及其来源索引保存到 `$WORK_DIR/documentation/`;文档中的命令和路径须与交付代码一致。 | 10 | - 将文档及其来源索引保存到 `$WORK_DIR/documentation/`;文档中的命令和路径须与交付代码一致。 |
| 9 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 | 11 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 |
| 10 | procedure: | 12 | procedure: |
| 11 | - 读取本 Skill 的 `references/code-versions.md`,通过本节点 status 取得 CODE_DIR;审查提交、依赖版本、冻结输入及原始证据的一致性。发生代码写入的节点须完成协议中的 verifier 登记;不得将 checkpoint 成功视作验证或验收通过。 | 13 | - 读取本 Skill 的 `references/code-versions.md`,通过本节点 status 取得 CODE_DIR;审查提交、依赖版本、冻结输入及原始证据的一致性。发生代码写入的节点须完成协议中的 verifier 登记;不得将 checkpoint 成功视作验证或验收通过。 |
| 12 | -- 核对交付件或报告的选定源码、模式和证据与 review-fix/selected.json 一致;最终完整 SHA 以性能节点当前提交为准,核对 operators/ 子树与选定版本一致及该最终 SHA 的复验记录;基线托底与正常整改结论分别表述。 | 14 | +- 核对当前源码和交付产物身份与性能节点选定的最终回集成版本一致;性能报告来自 perf-optimize/run/,未引用旧 performance/performance-report.md。 |
| 15 | +- 核对交付件或报告的源码提交、选定模式和证据与 perf-optimize/HANDOFF.md 一致;基线托底与正常整改结论分别表述。 | ||
| 13 | - 核对文档覆盖适用范围、参数、边界、构建运行步骤和验证结果,且与当前实现一致。 | 16 | - 核对文档覆盖适用范围、参数、边界、构建运行步骤和验证结果,且与当前实现一致。 |
| 14 | - 抽查文档中的命令和路径与交付代码真实对应。 | 17 | - 抽查文档中的命令和路径与交付代码真实对应。 |
| 15 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 | 18 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 |
| 16 | acceptance: | 19 | acceptance: |
| 17 | -- 'find "$WORK_DIR/documentation" -name "*.md" -size +0 | grep -q .' | 20 | +- find "$WORK_DIR/documentation" -name "*.md" -size +0 | grep -q . |
| 18 | out_of_scope: | 21 | out_of_scope: |
| 19 | - 不修改算子实现、测试用例或性能测量结果。 | 22 | - 不修改算子实现、测试用例或性能测量结果。 |
| @@ -4,6 +4,7 @@ goal: | |||
| 4 | approach: | 4 | approach: |
| 5 | - 读取启动前已确认的 `$WORK_DIR/需求分析.md`、原始任务及输入约束,整理为下游规格所需的需求记录;本节点不重新调用交互式需求对齐 Skill。 | 5 | - 读取启动前已确认的 `$WORK_DIR/需求分析.md`、原始任务及输入约束,整理为下游规格所需的需求记录;本节点不重新调用交互式需求对齐 Skill。 |
| 6 | - 在 `$WORK_DIR/design/doc/REQUIREMENTS.md` 记录接口、输入输出、目标环境、精度与性能要求、边界条件和未决事项的来源。 | 6 | - 在 `$WORK_DIR/design/doc/REQUIREMENTS.md` 记录接口、输入输出、目标环境、精度与性能要求、边界条件和未决事项的来源。 |
| 7 | +- 保留启动前已确认的性能优化目标或轮数、对标来源、环境、SoC 和实际 JIT/AOT 模式及确认来源,供性能节点创建原 Skill 请求;已有有效请求记录其路径。不用默认值覆盖用户明确选择,缺少必要确认时终止并报告 PM。 | ||
| 7 | - 发现影响规格生成的缺项或冲突时记录来源与影响并终止本节点,不自行决定,也不在运行中等待用户答复。 | 8 | - 发现影响规格生成的缺项或冲突时记录来源与影响并终止本节点,不自行决定,也不在运行中等待用户答复。 |
| 8 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 | 9 | - 将本节点执行过程记录写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID;业务产物仍写入本任务约定的位置。 |
| 9 | procedure: | 10 | procedure: |
| @@ -11,6 +12,6 @@ procedure: | |||
| 11 | - 核对接口、约束和验收口径与确认记录一致;仍有影响规格的缺项或冲突时不通过,标注阻塞不等于需求已就绪。 | 12 | - 核对接口、约束和验收口径与确认记录一致;仍有影响规格的缺项或冲突时不通过,标注阻塞不等于需求已就绪。 |
| 12 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 | 13 | - 将验收结论与证据写入 `$WORK_DIR/.workflow/reports/`,文件名包含节点 ID。 |
| 13 | acceptance: | 14 | acceptance: |
| 14 | -- 'test -s "$WORK_DIR/design/doc/REQUIREMENTS.md"' | 15 | +- test -s "$WORK_DIR/design/doc/REQUIREMENTS.md" |
| 15 | out_of_scope: | 16 | out_of_scope: |
| 16 | - 不生成 `spec.yaml`、设计方案、测试用例或算子实现。 | 17 | - 不生成 `spec.yaml`、设计方案、测试用例或算子实现。 |
| @@ -110,14 +110,11 @@ nodes: | |||
| 110 | depends_on: | 110 | depends_on: |
| 111 | - precision-validation | 111 | - precision-validation |
| 112 | - id: performance | 112 | - id: performance |
| 113 | - task_type: normal | 113 | + task_type: subgraph |
| 114 | - yaml: ../../tasks/cannbot-dsl/性能优化.yaml | 114 | + template: performance.yaml |
| 115 | + file: perf-optimize/workflow.yaml | ||
| 115 | depends_on: | 116 | depends_on: |
| 116 | - review-fix | 117 | - review-fix |
| 117 | - executor: ops-direct-invoke-developer | ||
| 118 | - verifier: ops-direct-invoke-verifier | ||
| 119 | - max_retries: 3 | ||
| 120 | - on_exhaust: exit | ||
| 121 | - id: documentation | 118 | - id: documentation |
| 122 | task_type: normal | 119 | task_type: normal |
| 123 | yaml: ../../tasks/cannbot-dsl/文档生成.yaml | 120 | yaml: ../../tasks/cannbot-dsl/文档生成.yaml |
Aplugins-official/ops-direct-invoke/skills/ops-direct-invoke/workflows/cannbot-dsl/performance.yaml+22-0
| @@ -0,0 +1,22 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +use_when: CANNBotDSL 通过精度与检视修复后的性能优化和回集成 | ||
| 12 | +workflow: dsl-performance | ||
| 13 | +max_parallel: 1 | ||
| 14 | +nodes: | ||
| 15 | +- id: optimize | ||
| 16 | + task_type: normal | ||
| 17 | + yaml: ../../tasks/cannbot-dsl/性能优化.yaml | ||
| 18 | + depends_on: [] | ||
| 19 | + executor: ops-direct-invoke-perf-coordinator | ||
| 20 | + verifier: ops-direct-invoke-verifier | ||
| 21 | + max_retries: 0 | ||
| 22 | + on_exhaust: exit | ||
Mplugins-official/ops-direct-invoke/skills/ops-direct-invoke/workflows/cannbot-dsl/review-fix.yaml+1-1
| @@ -1,5 +1,5 @@ | |||
| 1 | # CANNBot-DSL 全量精度验证后的可读性检视与修复子图 | 1 | # CANNBot-DSL 全量精度验证后的可读性检视与修复子图 |
| 2 | -use_when: 已完成全量精度验证的 CANNBotDSL 算子,在性能摸底前检视并修复可读性 | 2 | +use_when: 已完成全量精度验证的 CANNBotDSL 算子,在性能优化前检视并修复可读性 |
| 3 | workflow: review-fix | 3 | workflow: review-fix |
| 4 | max_parallel: 1 | 4 | max_parallel: 1 |
| 5 | nodes: | 5 | nodes: |
| @@ -106,7 +106,7 @@ for (const source of ['repository', 'package']) { | |||
| 106 | const agents = join(box.target, clientDirectory, 'agents'); | 106 | const agents = join(box.target, clientDirectory, 'agents'); |
| 107 | const extension = tool === 'codex' ? '.toml' : '.md'; | 107 | const extension = tool === 'codex' ? '.toml' : '.md'; |
| 108 | assert.deepEqual(readdirSync(agents).filter((name) => name.startsWith('ops-direct-invoke-')).sort(), | 108 | assert.deepEqual(readdirSync(agents).filter((name) => name.startsWith('ops-direct-invoke-')).sort(), |
| 109 | - ['architect', 'developer', 'verifier'].map((name) => `ops-direct-invoke-${name}${extension}`)); | 109 | + ['architect', 'developer', 'perf-coordinator', 'verifier'].map((name) => `ops-direct-invoke-${name}${extension}`)); |
| 110 | assert.ok(existsSync(join(agents, `perf-optimize${extension}`))); | 110 | assert.ok(existsSync(join(agents, `perf-optimize${extension}`))); |
| 111 | const instructionsPath = join(box.target, tool === 'claude' ? 'CLAUDE.md' : 'AGENTS.md'); | 111 | const instructionsPath = join(box.target, tool === 'claude' ? 'CLAUDE.md' : 'AGENTS.md'); |
| 112 | const instructions = readFileSync(instructionsPath, 'utf8'); | 112 | const instructions = readFileSync(instructionsPath, 'utf8'); |
| @@ -490,10 +490,12 @@ test('ops-direct-invoke assembles and installs from a self-contained source layo | |||
| 490 | cpSync(join(repository, 'LICENSE'), join(isolated, 'LICENSE')); | 490 | cpSync(join(repository, 'LICENSE'), join(isolated, 'LICENSE')); |
| 491 | cpSync(join(repository, 'plugins-official/LICENSE'), join(isolated, 'plugins-official/LICENSE')); | 491 | cpSync(join(repository, 'plugins-official/LICENSE'), join(isolated, 'plugins-official/LICENSE')); |
| 492 | cpSync(join(repository, sourceDirectory), join(isolated, sourceDirectory), { recursive: true }); | 492 | cpSync(join(repository, sourceDirectory), join(isolated, sourceDirectory), { recursive: true }); |
| 493 | - // Share the declared framework, domain Skills and separately initialized performance plugin. | 493 | + // Explicit performance dependency is shipped alongside the generation plugin. |
| 494 | + cpSync(join(repository, 'plugins-official/ops-perf-optimize'), | ||
| 495 | + join(isolated, 'plugins-official/ops-perf-optimize'), { recursive: true }); | ||
| 496 | + // Only the common framework and domain Skill repository are shared with the source tree. | ||
| 494 | symlinkSync(join(repository, 'harness'), join(isolated, 'harness'), 'dir'); | 497 | symlinkSync(join(repository, 'harness'), join(isolated, 'harness'), 'dir'); |
| 495 | symlinkSync(join(repository, 'vendor'), join(isolated, 'vendor'), 'dir'); | 498 | symlinkSync(join(repository, 'vendor'), join(isolated, 'vendor'), 'dir'); |
| 496 | - symlinkSync(join(repository, 'plugins-official', performance), join(isolated, 'plugins-official', performance), 'dir'); | ||
| 497 | assert.equal(existsSync(join(isolated, 'plugins-community')), false); | 499 | assert.equal(existsSync(join(isolated, 'plugins-community')), false); |
| 498 | const bundles = assemblePlugins(isolated, join(box.root, 'dist'), [basename(sourceDirectory)]); | 500 | const bundles = assemblePlugins(isolated, join(box.root, 'dist'), [basename(sourceDirectory)]); |
| 499 | assert.equal(bundles.length, 1); | 501 | assert.equal(bundles.length, 1); |
| @@ -366,7 +366,14 @@ for (const source of sources) { | |||
| 366 | assert.equal(existsSync(join(installedSkill, "SKILL.md")), true, name); | 366 | assert.equal(existsSync(join(installedSkill, "SKILL.md")), true, name); |
| 367 | assertSkillInstallation(installedSkill, source, "ops-direct-invoke", name); | 367 | assertSkillInstallation(installedSkill, source, "ops-direct-invoke", name); |
| 368 | } | 368 | } |
| 369 | - assert.equal(record.agents.length, 3); | 369 | + const declaredAgents = JSON.parse(readFileSync(join(repositoryRoot, "plugins-official", "ops-direct-invoke", ".claude-plugin", "plugin.json"), "utf8")).agents; |
| 370 | + assert.equal(record.agents.length, declaredAgents.length); | ||
| 371 | + const coordinator = tool === "codex" ? "ops-direct-invoke-perf-coordinator.toml" : "ops-direct-invoke-perf-coordinator.md"; | ||
| 372 | + assert.equal(existsSync(join(root, "agents", coordinator)), true); | ||
| 373 | + for (const name of ["ops-perf-optimize-workflow", "ops-perf-baseline-evaluate", "ops-perf-preparation", "ops-perf-analysis", "ops-perf-implementation", "ops-perf-postprocess", "ops-perf-acceptance-criteria"]) { | ||
| 374 | + assert.equal(existsSync(join(skillRoot(target, tool), name, "SKILL.md")), true, name); | ||
| 375 | + assertSkillInstallation(join(skillRoot(target, tool), name), source, "ops-direct-invoke", name); | ||
| 376 | + } | ||
| 370 | assert.equal(record.sourcePackage, sourcePackage); | 377 | assert.equal(record.sourcePackage, sourcePackage); |
| 371 | assert.equal(record.source.kind, source); | 378 | assert.equal(record.source.kind, source); |
| 372 | assert.equal(record.skillInstallMode, source === "repository" ? "symlink" : "copy"); | 379 | assert.equal(record.skillInstallMode, source === "repository" ? "symlink" : "copy"); |