Magpie API reference#
2026-07-08
6 min read time
Magpie exposes three public interfaces: a command-line interface (CLI), a set of configuration files, and a Model Context Protocol (MCP) server for AI agents. This page documents each interface, including command names, parameters, and expected behavior.
Note
You can invoke the CLI either as magpie <command> or as
python -m Magpie <command>. Both forms accept the same arguments.
Command-line interface#
Global options#
The following options apply to every command and are passed before the subcommand.
Option |
Type |
Default |
Description |
|---|---|---|---|
|
path |
|
Framework configuration file |
|
flag |
off |
Enable verbose (DEBUG) logging |
|
flag |
off |
Print detected GPU and toolchain info, then exit |
|
|
|
Execution environment |
|
int |
from config |
Number of concurrent workers |
|
string |
from config |
Docker image for the container environment |
Example:
# Show detected GPU information and exit
magpie --gpu-info
magpie analyze#
Evaluate a single kernel for correctness against a testcase, then optionally profile its performance.
magpie analyze [kernels ...] [options]
Argument / option |
Type |
Default |
Description |
|---|---|---|---|
|
path(s) |
none |
Kernel source file(s) to analyze |
|
path |
none |
Kernel configuration file (alternative to positional kernels) |
|
string |
none |
Testcase command used to verify correctness |
|
|
|
Kernel type |
|
string |
auto |
Custom compile command |
|
flag |
off |
Skip performance profiling |
|
path |
|
Output directory for reports |
Example:
magpie analyze --kernel-config Magpie/kernel_config.yaml.example
magpie compare#
Evaluate and rank multiple kernel implementations against a baseline.
magpie compare [kernels ...] [options]
Argument / option |
Type |
Default |
Description |
|---|---|---|---|
|
path(s) |
none |
Kernel files to compare |
|
path |
none |
Kernel configuration file |
|
string |
none |
Testcase command (optional) |
|
|
|
Kernel type |
|
int |
|
Index of the baseline kernel |
|
flag |
off |
Skip performance profiling |
|
path |
|
Output directory for reports |
Example:
magpie compare --kernel-config examples/ck_grouped_gemm_compare.yaml
magpie benchmark#
Run a framework-level benchmark (vLLM, SGLang, or Atom) with optional profiling, or run standalone gap analysis on existing traces.
magpie benchmark [framework] [options]
Argument / option |
Type |
Default |
Description |
|---|---|---|---|
|
|
none |
Framework to benchmark |
|
path |
none |
Benchmark configuration file |
|
string |
none |
Model name or path |
|
|
|
Model precision |
|
int |
|
Tensor parallel size |
|
int |
|
Request concurrency |
|
int |
|
Input sequence length |
|
int |
|
Output sequence length |
|
flag |
off |
Enable the torch profiler |
|
flag |
off |
Enable the system profiler (rocprof/ncu) |
|
|
|
Run in a container or directly on the host |
|
string |
from config |
Override the Docker image |
|
string |
auto-clone |
Path to an InferenceX installation |
|
string |
none |
InferenceX benchmark script name |
|
int |
|
Benchmark timeout in seconds |
|
path |
|
Output directory for reports |
Standalone gap analysis options#
When --trace-dir is provided, benchmark runs gap analysis on existing torch
traces instead of launching a benchmark.
Option |
Type |
Default |
Description |
|---|---|---|---|
|
path |
none |
Run gap analysis on this |
|
int |
|
Number of top bottleneck kernels to report |
|
float |
|
Start of the analysis window (0-100) |
|
float |
|
End of the analysis window (0-100) |
|
float |
|
Minimum event duration to include, in microseconds |
|
string(s) |
all |
Event categories to include (for example, |
|
string(s) |
none |
Event categories to exclude |
|
flag |
off |
Skip per-rank CSV generation |
|
flag |
off |
Find kernel source files and test commands (AMD kernels) |
|
string(s) |
none |
Repository paths to search for kernel sources |
Example:
magpie benchmark --benchmark-config examples/benchmarks/benchmark_vllm_dsr1.yaml
Configuration reference#
Magpie is driven by YAML configuration files. See
Magpie/config.yaml
and
Magpie/kernel_config.yaml.example
for complete, commented examples.
Framework configuration (config.yaml)#
Section |
Purpose |
|---|---|
|
Device selection and hardware control (power/frequency) |
|
Execution environment (local, container, or Ray) and worker settings |
|
Default compile behavior |
|
Correctness backend (testcase or Accordo) and tolerances |
|
Profiler backend ( |
|
Performance metric weights and winner selection for compare mode |
|
InferenceX path, image mapping, and default profiler flags |
|
Log level ( |
Kernel configuration#
A kernel configuration file can define a single kernel: or multiple
kernels:, plus optional override sections:
Key |
Purpose |
|---|---|
|
A single kernel entry (path, type, testcase, compile command) |
|
A list of kernel entries for compare mode |
|
Overrides framework-level profiler settings |
|
Overrides framework-level correctness settings |
|
Ray cluster settings (implies |
|
Scheduler-level overrides (environment, workers, and so on) |
MCP server#
Start the MCP server with:
python -m Magpie.mcp
A sample client configuration is available at
Magpie/mcp/config.json.
All tools return JSON-formatted strings.
Available tools#
The MCP server exposes the following tools to AI agents.
Tool |
Description |
|---|---|
|
Analyze a kernel for correctness and performance |
|
Compare multiple kernel implementations |
|
Query GPU hardware specifications |
|
Configure GPU power and frequency |
|
Scan a project and suggest analyzable kernels/configs |
|
Suggest performance optimizations from analyze output |
|
Generate a kernel config YAML for analyze |
|
Run a vLLM/SGLang/Atom benchmark with optional profiling |
|
Run gap analysis on existing torch profiler traces |
|
List available Docker images per framework/architecture |
|
List previous benchmark workspaces and summaries |
|
Read detailed results from a specific benchmark run |
|
Compare TraceLens reports across benchmark runs |
Selected tool signatures#
The following examples show key parameters. All parameters have sensible defaults unless noted.
hardware_spec
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
GPU device ID to query |
|
bool |
|
Return info for all available GPUs |
Returns JSON with vendor, architecture, power, clocks, temperature, and memory.
analyze
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
string |
required |
Path to the kernel source file ( |
|
string |
required |
Command to run the testcase |
|
string |
|
|
|
string |
kernel’s dir |
Working directory |
|
string |
auto |
Custom compile command |
|
bool |
|
Run performance profiling |
|
string |
|
|
|
string |
auto |
|
|
string |
auto |
|
|
various |
see defaults |
Accordo kernel name, binaries, tolerances, and timeout |
Returns JSON with compiling_state, correctness_state, performance_state, a
score (0.0-1.0), and detailed per-stage results.
Note
For the full parameter list of every tool, inspect the tool docstrings in
Magpie/mcp/server.py,
which are surfaced to MCP clients automatically.