Skip to content

Commit 145cf4b

Browse files
committed
Federate Magpie from AMD-AGI/Magpie
1 parent f6da784 commit 145cf4b

15 files changed

Lines changed: 863 additions & 4 deletions

File tree

‎.claude-plugin/marketplace.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"./skills/local-ai-app-integration",
1919
"./skills/serving-llms-on-instinct",
2020
"./skills/tracelens-analysis-orchestrator",
21-
"./skills/hyperloom-workload-optimizer"
21+
"./skills/hyperloom-workload-optimizer",
22+
"./skills/magpie"
2223
],
2324
"description": "AMD's verified Agent Skills in one plugin: route image/audio through local AI on Ryzen AI, serve LLMs on AMD Instinct GPUs with vLLM, optimize inference throughput with Hyperloom, and analyze GPU kernel and PyTorch trace performance."
2425
}

‎.codex-plugin/plugin.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"./skills/local-ai-app-integration",
2323
"./skills/serving-llms-on-instinct",
2424
"./skills/tracelens-analysis-orchestrator",
25-
"./skills/hyperloom-workload-optimizer"
25+
"./skills/hyperloom-workload-optimizer",
26+
"./skills/magpie"
2627
],
2728
"interface": {
2829
"displayName": "AMD",

‎.cursor-plugin/marketplace.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"./skills/local-ai-app-integration",
1818
"./skills/serving-llms-on-instinct",
1919
"./skills/tracelens-analysis-orchestrator",
20-
"./skills/hyperloom-workload-optimizer"
20+
"./skills/hyperloom-workload-optimizer",
21+
"./skills/magpie"
2122
],
2223
"description": "AMD's verified Agent Skills in one plugin: route image/audio through local AI on Ryzen AI, serve LLMs on AMD Instinct GPUs with vLLM, optimize inference throughput with Hyperloom, and analyze GPU kernel and PyTorch trace performance.",
2324
"author": {

‎.github/federation.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
}
1111
]
1212
},
13+
{
14+
"repo": "AMD-AGI/Magpie",
15+
"license": "MIT",
16+
"skills": [
17+
{
18+
"path": "skills/magpie",
19+
"as": "magpie"
20+
}
21+
]
22+
},
1323
{
1424
"repo": "AMD-AGI/TraceLens",
1525
"license": "MIT",

‎.github/workflows/evals.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
# skill competes against is what its score means: adding a name here
9797
# moves every other skill's number, and that deserves a visible diff.
9898
# Publishing a skill means adding it in both places.
99-
routing_room: "local-ai-use,local-ai-app-integration,serving-llms-on-instinct,tracelens-analysis-orchestrator,hyperloom-workload-optimizer"
99+
routing_room: "local-ai-use,local-ai-app-integration,serving-llms-on-instinct,tracelens-analysis-orchestrator,hyperloom-workload-optimizer,magpie"
100100

101101
# A change to this file is a change to the harness as far as this repo is
102102
# concerned, so it re-runs every skill rather than whatever the diff

‎skills/magpie/.federated.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"source": "amd-agi-magpie",
3+
"repo": "AMD-AGI/Magpie",
4+
"ref": "main",
5+
"commit": "cc85f5d6605220b6cbff17b8e6645f763c646c29",
6+
"path": "skills/magpie",
7+
"license": "MIT",
8+
"content_hash": "9bac90bdb90ae1effe0444fe719112430a7af7e2a6b6dc0ddee05d8464ba024e",
9+
"imported_at": "2026-09-23T23:58:36Z"
10+
}

‎skills/magpie/SKILL.md‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
name: magpie
3+
description: Benchmarks LLM inference and drives GPU kernel optimization with Magpie. Use when the user wants to benchmark vLLM, SGLang, or Atom; capture torch traces; post-process inference traces with TraceLens into prefill/decode and roofline reports; identify top bottleneck kernels or map profiler names to source; analyze or compare HIP, CUDA, PyTorch, or Triton kernels; validate and rank optimized variants; run local, container, or Ray workloads; or mentions Magpie, TraceLens, gap analysis, TTFT, TPOT, kernel evaluation, or AMD GPU optimization.
4+
---
5+
6+
# Magpie
7+
8+
Use Magpie for three connected jobs:
9+
10+
1. Benchmark an inference workload and collect throughput, latency, and traces.
11+
2. Analyze or compare GPU kernels for correctness and performance.
12+
3. Drive an optimization loop from a benchmark bottleneck to source, candidate kernels, and end-to-end validation.
13+
14+
Describe only capabilities supported by the checked-out Magpie version. Do not infer support for an unverified ROCm, GPU, framework, or experimental integration.
15+
16+
## Choose the workflow
17+
18+
| User goal | Workflow |
19+
|---|---|
20+
| Evaluate one implementation | `analyze` |
21+
| Rank two or more implementations | `compare` |
22+
| Measure model-serving performance | `benchmark` |
23+
| Find expensive kernels in existing traces | standalone gap analysis |
24+
| Explain a profiled inference workload | benchmark → TraceLens post-processing → stage/roofline review |
25+
| Optimize an end-to-end workload | benchmark → TraceLens/gap analysis → source mapping → analyze/compare → re-benchmark |
26+
27+
Use a YAML config for reproducible or multi-step work. Use inline CLI arguments for small exploratory runs.
28+
29+
## Preflight
30+
31+
1. Locate the Magpie repository or installed package.
32+
2. Check the local interface before constructing commands:
33+
34+
```bash
35+
magpie --help
36+
magpie analyze --help
37+
magpie compare --help
38+
magpie benchmark --help
39+
magpie --gpu-info
40+
```
41+
42+
3. Check required tools, model access, GPU visibility, writable output space, and container or Ray access as applicable.
43+
4. Read the repository compatibility matrix before making version claims. Treat ROCm or hardware not listed there as unverified until tested.
44+
5. Record the exact config, model revision, image, environment variables, GPU allocation, and Magpie commit for benchmark comparisons.
45+
46+
Run from the Magpie repository root, install with `pip install -e .`, or use `python -m Magpie` when the `magpie` entry point is unavailable.
47+
48+
## Analyze a kernel
49+
50+
Prefer a config when correctness or profiler settings matter:
51+
52+
```bash
53+
magpie analyze --kernel-config path/to/kernel.yaml
54+
```
55+
56+
For a quick single-kernel run:
57+
58+
```bash
59+
magpie analyze path/to/kernel.hip --type hip --testcase "./run_test.sh"
60+
```
61+
62+
Supported public kernel types are `hip`, `cuda`, `pytorch`, and `triton`. Use `--no-perf` only when the user wants correctness or execution validation without profiling.
63+
64+
Do not equate successful execution with numerical correctness. Supply a representative testcase whenever an optimized result will be accepted or rejected.
65+
66+
## Compare kernel variants
67+
68+
Compare at least two implementations and identify the baseline explicitly:
69+
70+
```bash
71+
magpie compare --kernel-config path/to/compare.yaml
72+
```
73+
74+
Keep inputs, tolerances, warmup, iteration count, GPU allocation, and profiler settings identical across candidates. Reject candidates that fail correctness before considering performance rankings.
75+
76+
For PyTorch without a testcase, Magpie's built-in check only verifies that each result is finite; it does not prove numerical equivalence between variants. Require a testcase for numerical validation.
77+
78+
## Benchmark inference
79+
80+
Prefer a checked-in benchmark config:
81+
82+
```bash
83+
magpie benchmark --benchmark-config path/to/benchmark.yaml
84+
```
85+
86+
The stable public CLI supports `vllm`, `sglang`, and `atom`. It supports direct `docker` and `local` run modes; use YAML configuration and the repository's Ray examples for distributed execution. Do not advertise integrations that exist only in internal enums or partial code paths as stable.
87+
88+
Enable profiling deliberately: profiler runs perturb latency and should not replace a clean baseline. Compare throughput, completed requests, TTFT, TPOT, ITL, and end-to-end latency using equivalent workloads.
89+
90+
## Post-process traces with TraceLens
91+
92+
Enable TraceLens in the profiled benchmark YAML; torch traces are its required input:
93+
94+
```yaml
95+
benchmark:
96+
profiler:
97+
torch_profiler:
98+
enabled: true
99+
tracelens:
100+
enabled: true
101+
analysis_mode: inference
102+
analysis_stages: all
103+
export_format: csv
104+
```
105+
106+
Use `analysis_mode: inference` for vLLM/SGLang. It splits the rank-0 trace into `prefilldecode`, `decode`, and `prefill` stages when available, runs TraceLens post-processing, and writes full stage reports plus compact `*_kernel_roofline_simple.csv` files under the benchmark workspace's `tracelens/` directory. For direct PyTorch trace reporting, use `analysis_mode: pytorch`.
107+
108+
Open the compact roofline CSVs first. Rank rows by `kernel_time_ms_sum` or `time_pct`; then use `roofline_bound`, arithmetic intensity, achieved TFLOP/s or TB/s, and `pct_roofline_mean` to form an optimization hypothesis. Confirm `benchmark_report.json.tracelens_analysis` has outputs and no error before treating post-processing as successful. Use `analysis_mode: pytorch` when the task specifically needs the legacy direct single-rank or multi-rank collective reports.
109+
110+
Magpie's integrated TraceLens stage produces CSV/Excel analysis artifacts, not an agent-written `analysis.md`. If the user requests a prioritized agentic report, pass the captured trace to the separate `tracelens-analysis-orchestrator` skill when installed; keep that result distinct from Magpie's benchmark report.
111+
112+
## Analyze existing traces and find source
113+
114+
Run standalone gap analysis with `--trace-dir` directly on `benchmark`:
115+
116+
```bash
117+
magpie benchmark \
118+
--trace-dir path/to/torch_trace \
119+
--top-k 20 \
120+
--find-kernel-sources \
121+
--kernel-source-repos path/to/repository
122+
```
123+
124+
Do not insert a `gap-analysis` positional token; it is not a CLI subcommand. Inspect the generated aggregate and per-rank CSVs, and preserve source-mapping confidence rather than assuming every normalized kernel name maps uniquely.
125+
126+
## Drive the optimization loop
127+
128+
1. Run an unprofiled baseline benchmark and save its config and report.
129+
2. Repeat with torch profiling and TraceLens inference post-processing enabled.
130+
3. Review stage-level TraceLens roofline summaries to classify dominant operations and likely compute, memory, or communication limits.
131+
4. Run gap analysis over the representative steady-state window to rank concrete kernels.
132+
5. Select bottlenecks by total contribution, not only single-dispatch duration.
133+
6. Map the selected kernel to source and an executable testcase.
134+
7. Generate isolated candidate implementations; preserve the baseline.
135+
8. Use `analyze` for iteration, then `compare` with correctness gates to rank candidates.
136+
9. Re-run the original unprofiled benchmark with the winning candidate and the same workload. Report both kernel-level and end-to-end changes, including regressions.
137+
138+
Stop before claiming success if correctness is unproven, the benchmark inputs changed, the source mapping is uncertain, or the end-to-end improvement is within run-to-run noise.
139+
140+
## Use MCP tools when available
141+
142+
Prefer Magpie MCP tools for structured agent workflows such as hardware inspection, kernel discovery, config generation, analyze/compare, optimization suggestions, result lookup, report comparison, Ray job management, and benchmark batches.
143+
144+
Do not pass a CLI `analyze_report.json` wrapper directly to an MCP tool that expects one result object's `performance_state` and `performance_result`. Do not assume every CLI option exists in MCP; kernel-source enrichment is currently exposed by the CLI gap-analysis path.
145+
146+
## Additional resources
147+
148+
- Full CLI reference: [reference.md](reference.md)
149+
- Copy-paste command examples: [examples.md](examples.md)

‎skills/magpie/evals/evals.json‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"evaluations": [
3+
{
4+
"id": "magpie-analyze-simple-hip-kernel",
5+
"skill_should_trigger": true,
6+
"prompt": "Use Magpie to prepare an analyze run for the existing examples/simple_hip_test/analyze_default.yaml fixture. Inspect the fixture and write analyze_plan.md with the exact command and an explanation of what the testcase validates. Do not compile or execute the kernel, install dependencies, or change the fixture, and do not claim that correctness or performance was measured.",
7+
"workspace": "evals/files/analyze-simple-hip",
8+
"expected_behavior": [
9+
"Use Magpie analyze with examples/simple_hip_test/analyze_default.yaml and explain that the testcase exit code is what validates vector-add correctness"
10+
],
11+
"unexpected_behavior": [
12+
"Compile or execute the HIP kernel, install dependencies, or claim measured correctness or performance results"
13+
],
14+
"logs_contain": [
15+
"magpie analyze"
16+
],
17+
"files_exist": [
18+
"analyze_plan.md"
19+
]
20+
},
21+
{
22+
"id": "magpie-compare-hip-variants",
23+
"skill_should_trigger": true,
24+
"prompt": "Use Magpie to prepare a comparison of these two existing HIP kernels: baseline/vector_add.hip and candidate/vector_add.hip. Write compare.yaml and give each implementation its own working_dir, hipcc compile_command, and testcase_command so Magpie builds and tests two separate binaries. Tell me the exact Magpie command, and treat correctness as a hard gate before any performance ranking. Keep the baseline as a named config entry instead of passing --baseline, because the comparison report does not consume that CLI selection. Do not compile or execute the kernels, and do not name a winner.",
25+
"workspace": "evals/files/compare-hip-variants",
26+
"expected_behavior": [
27+
"Configure two independent Magpie compare candidates with separate working directories, compile commands, and testcase commands",
28+
"Require correctness before performance ranking, without relying on the --baseline CLI option"
29+
],
30+
"unexpected_behavior": [
31+
"Compile or execute either HIP kernel, or claim measured results or a winner"
32+
],
33+
"logs_contain": [
34+
"magpie compare"
35+
],
36+
"files_exist": [
37+
"compare.yaml"
38+
]
39+
},
40+
{
41+
"id": "magpie-benchmark-optimization-plan",
42+
"skill_should_trigger": true,
43+
"prompt": "I have a slow vLLM workload on AMD GPUs. Use Magpie to write benchmark_plan.md describing the shortest safe workflow from a clean baseline benchmark to profiling and TraceLens or gap analysis, then kernel analyze/compare, then a final clean benchmark. This environment has no model weights and no runnable benchmark setup, so do not install, download, or execute anything, and do not invent measured results.",
44+
"expected_behavior": [
45+
"Plan a clean baseline, a separate profiled run with TraceLens or gap analysis, correctness-gated kernel evaluation, and a final clean end-to-end benchmark"
46+
],
47+
"unexpected_behavior": [
48+
"Run a benchmark, install or download anything, or claim measured results"
49+
],
50+
"files_exist": [
51+
"benchmark_plan.md"
52+
]
53+
},
54+
{
55+
"id": "magpie-benchmark-vllm-ttft",
56+
"skill_should_trigger": true,
57+
"prompt": "Benchmark vLLM throughput and time-to-first-token for Llama 3 on this box, and capture torch traces while it runs."
58+
},
59+
{
60+
"id": "magpie-compare-hip-softmax-kernels",
61+
"skill_should_trigger": true,
62+
"prompt": "I have two HIP implementations of a softmax kernel. Which one is faster, and is the optimized one still numerically correct?"
63+
},
64+
{
65+
"id": "magpie-bottleneck-kernel-to-source",
66+
"skill_should_trigger": true,
67+
"prompt": "Find the top bottleneck kernels in my inference workload and map the profiler names back to the source that generates them."
68+
},
69+
{
70+
"id": "magpie-rank-triton-attention-variants",
71+
"skill_should_trigger": true,
72+
"prompt": "Rank these three Triton attention kernel variants against each other and validate the winner end to end."
73+
},
74+
{
75+
"id": "magpie-benchmark-then-optimize-kernel",
76+
"skill_should_trigger": true,
77+
"prompt": "Benchmark SGLang on this node, then rank two candidate HIP kernels for the biggest bottleneck and validate the winner."
78+
},
79+
{
80+
"id": "magpie-write-a-cuda-transpose",
81+
"skill_should_trigger": false,
82+
"prompt": "Write a CUDA kernel that transposes a matrix, and explain the shared-memory tiling."
83+
},
84+
{
85+
"id": "magpie-mi300x-spec-question",
86+
"skill_should_trigger": false,
87+
"prompt": "What is the theoretical peak FP16 throughput of an MI300X on paper?"
88+
}
89+
]
90+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Simple vector_add — default correctness backend (testcase exit-code)
2+
# Usage:
3+
# cd /path/to/Magpie
4+
# python -m Magpie analyze -k examples/simple_hip_test/analyze_default.yaml --no-perf
5+
kernel:
6+
id: "vector_add"
7+
type: hip
8+
source_files:
9+
- "./vector_add.hip"
10+
compile_command: "hipcc -g -O2 -o vector_add vector_add.hip"
11+
testcase_command: "./vector_add"
12+
working_dir: "examples/simple_hip_test"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Simple HIP vector_add kernel for Magpie correctness testing.
2+
// Compile: hipcc -g -O2 -o vector_add vector_add.hip
3+
#include <hip/hip_runtime.h>
4+
#include <cstdio>
5+
#include <cstdlib>
6+
#include <cmath>
7+
8+
__global__ void vector_add(const float* a, const float* b, float* c, int n) {
9+
int idx = blockIdx.x * blockDim.x + threadIdx.x;
10+
if (idx < n) {
11+
c[idx] = a[idx] + b[idx];
12+
}
13+
}
14+
15+
int main() {
16+
const int N = 1024;
17+
const size_t bytes = N * sizeof(float);
18+
19+
float *h_a = (float*)malloc(bytes);
20+
float *h_b = (float*)malloc(bytes);
21+
float *h_c = (float*)malloc(bytes);
22+
23+
for (int i = 0; i < N; i++) {
24+
h_a[i] = static_cast<float>(i);
25+
h_b[i] = static_cast<float>(i * 2);
26+
}
27+
28+
float *d_a, *d_b, *d_c;
29+
hipMalloc(&d_a, bytes);
30+
hipMalloc(&d_b, bytes);
31+
hipMalloc(&d_c, bytes);
32+
33+
hipMemcpy(d_a, h_a, bytes, hipMemcpyHostToDevice);
34+
hipMemcpy(d_b, h_b, bytes, hipMemcpyHostToDevice);
35+
36+
int blockSize = 256;
37+
int gridSize = (N + blockSize - 1) / blockSize;
38+
hipLaunchKernelGGL(vector_add, dim3(gridSize), dim3(blockSize), 0, 0,
39+
d_a, d_b, d_c, N);
40+
41+
hipMemcpy(h_c, d_c, bytes, hipMemcpyDeviceToHost);
42+
43+
int errors = 0;
44+
for (int i = 0; i < N; i++) {
45+
float expected = h_a[i] + h_b[i];
46+
if (fabs(h_c[i] - expected) > 1e-5f) {
47+
fprintf(stderr, "Mismatch at %d: got %f, expected %f\n",
48+
i, h_c[i], expected);
49+
errors++;
50+
}
51+
}
52+
53+
hipFree(d_a);
54+
hipFree(d_b);
55+
hipFree(d_c);
56+
free(h_a);
57+
free(h_b);
58+
free(h_c);
59+
60+
if (errors == 0) {
61+
printf("PASSED: All %d elements correct.\n", N);
62+
return 0;
63+
} else {
64+
printf("FAILED: %d errors.\n", errors);
65+
return 1;
66+
}
67+
}

0 commit comments

Comments
 (0)