-
Notifications
You must be signed in to change notification settings - Fork 28
Introduce Judger Prompt Component #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Diagnose Prompt Module for Hardware Bottleneck Analysis. | ||
|
|
||
| """ | ||
|
|
||
| __all__: list[str] = [] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,315 @@ | ||||||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||||||
| # | ||||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| # you may not use this file except in compliance with the License. | ||||||
| # You may obtain a copy of the License at | ||||||
| # | ||||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| # | ||||||
| # Unless required by applicable law or agreed to in writing, software | ||||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| # See the License for the specific language governing permissions and | ||||||
| # limitations under the License. | ||||||
|
|
||||||
| """ | ||||||
| Bottleneck Analysis Prompt Builder | ||||||
|
|
||||||
| Provides prompt templates and parsing utilities for LLM-based bottleneck analysis | ||||||
| of NCU profiling metrics. | ||||||
|
|
||||||
| Bottleneck Categories: | ||||||
| - memory: Memory bandwidth is the limiting factor | ||||||
| - compute: Compute throughput is the limiting factor | ||||||
| - underutilized: Neither saturated (<60% both), indicating stalls/occupancy issues | ||||||
|
|
||||||
| Metric definitions are in metric_schema.py. | ||||||
| """ | ||||||
|
|
||||||
| import json | ||||||
| import re | ||||||
| from dataclasses import dataclass, field | ||||||
| from typing import Any | ||||||
|
|
||||||
| from kernel_perf_agent.kernel_opt.diagnose_prompt.metric_schema import ( | ||||||
| GPU_MEMORY_FIELDS, | ||||||
| GPU_SPEC_FIELDS, | ||||||
| NCU_METRIC_SECTIONS, | ||||||
| ) | ||||||
| from kernel_perf_agent.kernel_opt.roofline.ncu_roofline import RooflineResult | ||||||
|
|
||||||
| BOTTLENECK_CATEGORIES = {"memory", "compute", "underutilized"} | ||||||
|
|
||||||
|
|
||||||
| # ============================================================================= | ||||||
| # Data Classes | ||||||
| # ============================================================================= | ||||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class BottleneckResult: | ||||||
| """A single bottleneck analysis.""" | ||||||
|
|
||||||
| category: str | ||||||
| summary: str | ||||||
| reasoning: str | ||||||
| root_causes: list[dict[str, Any]] = field(default_factory=list) | ||||||
| recommended_fixes: list[dict[str, Any]] = field(default_factory=list) | ||||||
|
|
||||||
| def to_dict(self) -> dict[str, Any]: | ||||||
| return { | ||||||
| "category": self.category, | ||||||
| "summary": self.summary, | ||||||
| "reasoning": self.reasoning, | ||||||
| "root_causes": self.root_causes, | ||||||
| "recommended_fixes": self.recommended_fixes, | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| # ============================================================================= | ||||||
| # Prompt Template | ||||||
| # ============================================================================= | ||||||
|
|
||||||
|
|
||||||
| BOTTLENECK_PROMPT = """\ | ||||||
| You are a GPU performance expert analyzing Triton kernel profiling data. | ||||||
|
|
||||||
| ## Task | ||||||
| Analyze the NCU metrics and identify {num_bottlenecks} performance bottleneck(s). For each, classify as: | ||||||
| - **memory**: Memory bandwidth is the limiting factor | ||||||
| - **compute**: Compute throughput is the limiting factor | ||||||
| - **underutilized**: Neither saturated (<60% both), indicating stalls/occupancy issues | ||||||
|
|
||||||
| ## GPU Specifications | ||||||
| {gpu_specs} | ||||||
|
|
||||||
| ## Roofline Analysis | ||||||
| - Bottleneck: {roofline_bottleneck} | ||||||
| - Compute SOL: {compute_sol:.1f}% | ||||||
| - Memory SOL: {memory_sol:.1f}% | ||||||
| - Efficiency: {efficiency:.1f}% | ||||||
| - Headroom: {headroom:.1f}% | ||||||
| - At Roofline: {at_roofline} | ||||||
| - Tensor Cores: {uses_tc} | ||||||
| - Warnings: {roofline_warnings} | ||||||
|
|
||||||
| ## NCU Metrics | ||||||
| {ncu_metrics} | ||||||
|
|
||||||
| ## Kernel Code | ||||||
| ```python | ||||||
| {kernel_code} | ||||||
| ``` | ||||||
|
|
||||||
| ## Output (JSON array, no markdown fence) | ||||||
| [ | ||||||
| {{ | ||||||
| "category": "memory" | "compute" | "underutilized", | ||||||
|
||||||
| "category": "memory" | "compute" | "underutilized", | |
| "category": "memory", |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we aren't doing any custom logic we can just drop to_dict in favor of dataclass asdict