T2.1 算子编译诊断 CLI & T2.2 Pass Diff 工具 & T2.5 Adapter 层健壮性 - #55
Conversation
Implement PassDiagnostic to run TTIR and triton-linalg pipelines pass by
pass, saving before/after IR snapshots, failure diagnostics, summary.json,
and best-effort MLIR op/location.
Add triton_anchor.diagnose CLI with file input and --python
MODULE:FUNCTION runtime TTIR generation, and register triton-anchor-diagnose
console script in setup.py and pyproject.toml.
Add diagnostics unit tests, user documentation, T2.1 implementation
reports, and a retained failing inline-asm sample source.
Add python-frontend and input-parse diagnostic handling before pass
execution. Update CLI output, summaries, tests, runnable failure
samples, and diagnostics documentation. Remove the superseded T2.1
analysis document.
Implement PassDiagnostic to run TTIR and triton-linalg pipelines pass by
pass, saving before/after IR snapshots, failure diagnostics, summary.json,
and best-effort MLIR op/location.
Add triton_anchor.diagnose CLI with file input and --python
MODULE:FUNCTION runtime TTIR generation, and register triton-anchor-diagnose
console script in setup.py and pyproject.toml.
Add diagnostics unit tests, user documentation, T2.1 implementation
reports, and a retained failing inline-asm sample source.
Add python-frontend and input-parse diagnostic handling before pass
execution. Update CLI output, summaries, tests, runnable failure
samples, and diagnostics documentation. Remove the superseded T2.1
analysis document.
Extend PassDiagnostic to capture per-pass timing, IR size changes, and RSS sampling when running adapter pipelines (triton-linalg / triton-shared). All metrics flow into the existing triton-anchor-diagnose CLI and summary.json. Changes: - python/triton_anchor/diagnostics.py: add duration_ms/before_ir_bytes/ after_ir_bytes/ir_delta_bytes/peak_rss_bytes to PassRunRecord; add total_duration_ms/input_ir_bytes/output_ir_bytes/peak_rss_bytes/slowest_pass to PassDiagnosticResult; wire collection in _diagnose_pipeline loop - python/triton_anchor/diagnose.py: display metrics in _print_result - python/triton_anchor/tests/test_diagnostics.py: add 2 tests for metrics - docs/t2_5_adapter_robustness_review.md: design writeup Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Add t2_5_adapter_observability.md: usage, metrics, changed files, test results, implementation details, design decision, task context, and follow-up work - Remove t2_5_adapter_robustness_review.md (content merged above) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add Sophgo PPLIR and external-stage diagnostic coverage, update CLI support, tests, docs, and the PPLIR failure sample. Keep generated diagnostic outputs and build artifacts untracked.
There was a problem hiding this comment.
Pull request overview
This PR introduces a pass-level diagnostics framework for Triton Anchor compilation pipelines, adds a dedicated CLI entry point (triton-anchor-diagnose), and documents/validates the workflow via unit tests and example failure kernels.
Changes:
- Add
PassDiagnostic/StageDiagnosticinfrastructure to run pipelines pass-by-pass, snapshot IR, capture diagnostics, and write structuredsummary.json. - Add
triton-anchor-diagnoseCLI supporting file-based MLIR/TTIR inputs and--python MODULE:FUNCTIONTTIR generation for TTIR-only diagnostics. - Add tests, user-facing docs, and example “bad kernels” to demonstrate/validate failure localization across TTIR, triton-linalg, and Sophgo PPLIR.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| setup.py | Registers triton-anchor-diagnose console script entry point. |
| python/triton_anchor/diagnostics.py | Implements pass/stage diagnostic core, stderr capture, MLIR location/op extraction, and summary recording. |
| python/triton_anchor/diagnose.py | Implements CLI argument parsing, input loading / python frontend flow, and human-readable output printing. |
| python/triton_anchor/tests/test_diagnostics.py | Adds unit tests covering pass failure identification, location extraction, CLI behavior, and metrics. |
| python/triton_anchor/init.py | Re-exports PassDiagnostic and StageDiagnostic from the package. |
| ops-diagnose-cli/test/anchor_diag_bad_pplir_kernel.py | Example kernel to trigger Sophgo PPLIR pipeline failure for validation. |
| ops-diagnose-cli/test/anchor_diag_bad_kernels.py | Example kernel to trigger adapter-lowering failure for validation. |
| ops-diagnose-cli/test/anchor_diag_bad_frontend_kernel.py | Example kernel to trigger python-frontend failure for validation. |
| ops-diagnose-cli/docs/T2.1-implementation-and-test-results.md | Implementation/test report for T2.1 workflow and artifacts. |
| docs/t2_5_adapter_observability.md | Documents adapter observability metrics and their interpretation. |
| docs/diagnostics.md | User-facing documentation for diagnostics capabilities, usage, and boundaries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _find_location_match(text: str) -> Optional[re.Match[str]]: | ||
| patterns = [ | ||
| r'loc\("(?P<file>[^"]+)":(?P<line>\d+):(?P<column>\d+)\)', | ||
| r'(?P<file>[^\s:"\']+\.m?lir):(?P<line>\d+):(?P<column>\d+)', | ||
| r'(?P<file><[^>]+>):(?P<line>\d+):(?P<column>\d+)', | ||
| r'(?P<line>\d+):(?P<column>\d+)', | ||
| ] |
| def _constant_key_to_index(key: str, arg_names: list[str]) -> int: | ||
| if key.isdigit(): | ||
| return int(key) | ||
| if key in arg_names: | ||
| return arg_names.index(key) | ||
| raise ValueError( | ||
| f"constant key '{key}' is not an argument name or index; " | ||
| f"available args: {', '.join(arg_names) if arg_names else '<unknown>'}" | ||
| ) |
|
|
||
| ## 提供的指标 | ||
|
|
||
| 指标的采集范围是 **Adapter 层**:从 TTIR 进入 Adapter 开始,到 Linalg IR 输出为止(即 `--pipeline triton-linalg` 的 15 个 pass)。不包含 TTIR 优化阶段、PPLIR 及后续编译阶段。 |
|
|
||
| **这是使用这些指标时最需要注意的一点。** | ||
|
|
||
| 指标采集**不调用** adapter 的 `convert()`(它内部把 15 个 pass 塞进一个 `pass_manager` 一次 `pm.run()` 跑完,是黑盒,中间插不进埋点)。诊断路径走的是 `build_triton_linalg_pass_descriptors()`——它把 adapter 那条流水线**逐 pass 手抄成了一份独立的 descriptor 列表**,诊断时按这份列表逐个 pass 单独跑并埋点。 |
| | --- | --- | | ||
| | `python/triton_anchor/__init__.py` | 导出诊断相关能力,使 `triton_anchor` 包对外暴露新增诊断模块。 | | ||
| | `setup.py` | 注册 `console_scripts`,安装后生成 `triton-anchor-diagnose` 命令;同时保留原有 adapter entry point。 | | ||
| | `pyproject.toml` | 同步注册 `[project.scripts]`,避免不同安装方式下 CLI 命令未生成。 | |
| `pyproject.toml` 中新增: | ||
|
|
||
| ```toml | ||
| [project.scripts] | ||
| triton-anchor-diagnose = "triton_anchor.diagnose:main" | ||
| ``` | ||
|
|
||
| 由于仓库同时存在 `setup.py` 和 PEP 621 `[project]` 元数据,两个位置都注册可以避免安装方式差异导致命令没有生成。 | ||
|
|
| def _run_with_stderr_capture(pm: Any, mod: Any) -> str: | ||
| saved_stderr_fd = os.dup(2) | ||
| original: Optional[Exception] = None | ||
| with tempfile.TemporaryFile(mode="w+b") as captured: | ||
| try: | ||
| os.dup2(captured.fileno(), 2) | ||
| try: | ||
| pm.run(mod) | ||
| except Exception as exc: | ||
| original = exc | ||
| finally: | ||
| os.dup2(saved_stderr_fd, 2) | ||
| finally: | ||
| os.close(saved_stderr_fd) | ||
|
|
||
| captured.seek(0) | ||
| diagnostic_text = captured.read().decode("utf-8", errors="replace") | ||
|
|
||
| if original is not None: | ||
| raise _CapturedPassError(original, diagnostic_text) from original | ||
| return diagnostic_text |
| def _capture_stderr(fn): | ||
| saved_stderr_fd = os.dup(2) | ||
| original: Exception | None = None | ||
| result = None | ||
| with tempfile.TemporaryFile(mode="w+b") as captured: | ||
| try: | ||
| os.dup2(captured.fileno(), 2) | ||
| try: | ||
| result = fn() | ||
| except Exception as exc: | ||
| original = exc | ||
| finally: | ||
| os.dup2(saved_stderr_fd, 2) | ||
| finally: | ||
| os.close(saved_stderr_fd) | ||
|
|
||
| captured.seek(0) | ||
| diagnostic_text = captured.read().decode("utf-8", errors="replace") | ||
|
|
||
| if original is not None: | ||
| raise _CapturedInputError(original, diagnostic_text) from original | ||
| return result, diagnostic_text |
| OK: pipeline triton-linalg completed, 9/9 passes executed. | ||
| total duration: 342.56 ms | ||
| input IR: 1523 bytes | ||
| output IR: 2847 bytes | ||
| peak RSS: 87.34 MB | ||
| slowest pass: #7 triton_to_linalg (189.23 ms) | ||
| summary: ./out/summary.json |
| FAILED: pipeline triton-linalg failed at pass 4/9: pointer_strength_reduction | ||
| pass duration: 23.45 ms | ||
| before IR: 1523 bytes | ||
| total duration (up to failure): 98.76 ms | ||
| peak RSS: 65.21 MB | ||
| location: kernel.py:12:8 | ||
| operation: tt.load | ||
| summary: ./out/summary.json | ||
| ``` |
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
Codex AI 自动审查
审查摘要
本次变更新增逐 pass 编译诊断 CLI、结构化结果和 Adapter 指标,且当前 14-pass triton-linalg descriptor 与 adapter 实现一致。本地确定性 CI 检查在合并提交上完成 fresh wheel 构建、Sophgo CModel JIT smoke、FlagGems 样本及性能比较,但未覆盖新增诊断的真实失败集成。审查确认一个会破坏并发进程 stderr 的实现缺陷,以及自动 JIT hook 文档与实际仓库变更不一致。 贡献者目标与实现情况
需要处理的问题1. [中风险] 并发诊断会破坏进程 stderr 路由
2. [中风险] 自动 JIT 诊断覆盖仅有文档声明,缺少仓库内调用集成
3. [低风险] Adapter 指标文档中的 pass 总数和示例与实现不一致
可点击代码定位链接固定到本次测试提交,便于提交者修复和审核者核对代码功能;已验证行号的问题链接到具体行,仅能确认文件的问题链接到文件并标注行号待核对。
验证情况
剩余风险
变更文件查看变更文件
|
No description provided.