Skip to content
Proyek

Tentang

Zero-GPU PyTorch Roofline profiler with machine-checked latency-bound certificates (Z3 + Lean 4) under an explicit idealized scheduling model.

Alat pengembangan

Cara angka ini diukur

29 bintang2 Fork +2 dalam 24 jam

Pertumbuhan bintang terukur

dalam 24 jam
+2
dalam 7 hari
Mengumpulkan riwayat
dalam 15 hari
Mengumpulkan riwayat
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

English · 简体中文

Proofline

Zero-GPU Roofline profiler for PyTorch, HuggingFace LLMs/MoEs, GGUF, and ONNX — size GPUs, rank $/1M tok, gate PR latency regressions on CPU CI, and optionally back bounds with Z3 + Lean 4 certificates.

License: MIT Python 3.10+ CI

Before burning GPU hours or writing custom kernels, Proofline inspects PyTorch nn.Modules (FakeTensorMode on zero-VRAM meta tensors), HuggingFace config.json / safetensors headers, .gguf headers, and .onnx graphs strictly on CPU. It outputs concrete bottlenecks, SLO Goodput & hardware cost comparisons, ready-to-run vLLM/SGLang/llama.cpp commands, interactive offline HTML reports, PR diff tables, and optional machine-checked Z3/Lean 4 lower-bound certificates under an explicit idealized roofline/scheduling model.

Quickstart

1. Size GPUs, compare $/1M output tokens, and emit launch commands (zero weight download):

proofline fit deepseek-v3 --gpu 8xb200 --quant fp8 --compare-gpus 8xh200,8xb200,8xmi355x

Actual output (exact MLA kv_lora_rank=512+64 + 3 dense / 58 MoE layers):

[Fit] DeepSeek-V3-671B on 8xB200 (FP8/KV-FP8, L0=4096, gen=512, SLO: TTFT<=1000ms, TPOT<=50ms)
  VRAM weights=624.94 GiB | KV/seq=154.41 MiB | TP=8 DP=1 | fits=True | mode=colocated
  Goodput=152649.7 out tok/s | Cost=$0.0801/1M out tok (fleet $44.00/hr)

[Serving Economics Ranking]
Device               GPUs   SLO?       Mode   Out(tok/s)     $/1M out
----------------------------------------------------------------------
MI355X                  8    yes  colocated   149150.4       0.0670
B200                    8    yes  colocated   152649.7       0.0801
H200                    8    yes  colocated    63492.8       0.1190

[Ready-to-Run Commands]
  vLLM     : vllm serve deepseek-v3 --tensor-parallel-size 8 --max-model-len 4608 --max-num-seqs 4446 --gpu-memory-utilization 0.90 --enable-prefix-caching --enable-chunked-prefill --quantization fp8 --kv-cache-dtype fp8 --enable-expert-parallel
  SGLang   : python -m sglang.launch_server --model-path deepseek-v3 --tp 8 --context-length 4608 --mem-fraction-static 0.88 --chunked-prefill-size 8192 --quantization fp8 --kv-cache-dtype fp8_e5m2 --ep-size 8
  llama.cpp: llama-server -m deepseek-v3-FP8.gguf -c 4608 --parallel 16 -fa on -ngl 999 -ctk q8_0 -ctv q8_0

2. Check any PyTorch module, HuggingFace config.json, .gguf, or .onnx (with HTML report & Z3):

proofline check examples/quickstart_models.py:transformer_block --input 1,256,512 --gpu rtx5090_measured --advise --formal-z3 --html report.html
proofline check ./my-model/config.json --gpu h200 --quant fp8
proofline check ./model.onnx --gpu rtx5090_measured

3. Gate architecture/kernel PRs on CPU CI (exit 1 on regression > 5%):

proofline diff examples/quickstart_models.py:mlp_block examples/quickstart_models.py:transformer_block \
  --input 1,256,512 --gpu rtx5090_measured --markdown --fail-on-regression 5

Python API:

from proofline import (
    GPU_PRESETS,
    analyze,
    analyze_lora_training,
    compare_serving_economics,
    deepseek_v3_config,
    emit_launch_configs,
    load_hf_config,
    prove_lower_bound_z3,
    dag_from_torch_module,
)
from examples.quickstart_models import transformer_block

gpu = GPU_PRESETS["rtx5090_measured"]
rep = analyze(transformer_block(), (1, 256, 512), gpu, dtype="bf16")
z3_cert = prove_lower_bound_z3(dag_from_torch_module(transformer_block(), (1, 256, 512), dtype="bf16", gpu=gpu), gpu)
econ = compare_serving_economics(deepseek_v3_config(), ["8xh200", "8xb200", "8xmi355x"], quant="fp8")
cmds = emit_launch_configs(deepseek_v3_config(), "8xh200", quant="fp8")

Task Commands & Frontends

Proofline provides 8 task-oriented CLI subcommands (while retaining 100% backwards compatibility with all legacy --model / --llm flags):

Command Purpose Supported Targets
proofline check <target> One-shot latency floor, VRAM, bottleneck, --advise, --formal-z3, --html PyTorch file.py:Class(k=v), HF config.json/dir/repo (--online), LLM preset, .gguf, .onnx
proofline fit <target> GPU sizing (4xh200), quant sweep, MoE offload, SLO Goodput, $/1M tok, PD split & launch commands LLM preset, HF config.json/dir/repo, .gguf
proofline diff <A> <B> Side-by-side model or hardware diff (--gpu-b), PR Markdown table, --fail-on-regression PCT Any check target
proofline gap [target] Calibration scorecard (--scorecard), TorchInductor output_code.py fusion-break diff (--inductor-code), Chrome trace attribution (--from-trace) PyTorch model / profiler JSON / Inductor dir
proofline plan <target> --mode lora (LoRA/QLoRA), grpo (RLVR post-training), diffusion (multi-step DiT/CFG), train (6-stage saturation), parallel (6D search) PyTorch module, LLM preset, HF config.json
proofline lint-triton <fn> Pre-GPU static Roofline, SM-wave fill, SMEM limit, pow2, atomic & mask audit @triton.jit kernel (file.py:kernel)
proofline calibrate --measure 15-second live benchmark, --inspect <json>, --submit <json> for community profiles Local CUDA / MPS / CPU
proofline mcp Zero-dependency JSON-RPC 2.0 stdio MCP server exposing 6 diagnostic tools to coding agents Claude Code, Codex, Cursor, Antigravity

Pure-stdlib frontends require zero extra packages:

  • HuggingFace config.json & safetensors (load_hf_config, inspect_safetensors_header): parses local config.json, model folders, local HF cache, or Hub repos (--online), plus .safetensors / .index.json headers with zero tensor loading — supporting Dense/GQA, MLA (DeepSeek-V2/V3/R1, Kimi-K2), Hybrid Dense+MoE (first_k_dense_replace, moe_layer_freq), Sliding Window (Gemma 2/3, Mistral), Hybrid SSM/DeltaNet, and VLMs (vision_config + text_config).
  • Pure-Python ONNX (inspect_onnx_file, analyze_onnx_file): decodes ONNX binary protobuf wire format directly (no onnx package needed) into a ComputeDAG with full Roofline + microarch bounds.
  • GGUF (inspect_gguf_header, analyze_gguf_generation, advise_gguf_graph): zero-load binary GGUF header parser with per-tensor GGML quantization accounting.

What Proofline Computes

Proofline reports three hardware lower bounds assuming unchanged mathematics and numerical precision:

Bound Formula / Model Optimization Target It Represents
T_abs_floor $\max(W_{\text{tot}}/F_{\text{eff}},, Q_{\min}/B,, S_{\text{crit}}\tau_{\text{graph}})$ Cross-layer persistent kernel / SRAM-resident lower bound (Hong–Kung I/O + critical path) under the explicit (F_eff, B, tau) roofline/scheduling axioms and fixed (W, Q) (for algebraic rewrites, see --canonical and --rewrite-opt).
T_stage_fwd / T_stage_train $\sum_{\ell} \max(W_\ell/F_{\text{eff}},, Q_\ell/B,, \tau_{\text{graph}})$ Well-tuned Triton / torch.compile + CUDA Graph execution fusing pointwise/residual chains while respecting tensor dependencies.
T_eager Stage time $+ N_{\text{kernels}} \cdot \tau_{\text{eager}}$ Unfused eager PyTorch dispatch reference line; the gap to T_stage shows how much kernel fusion headroom remains.

Pure metadata view ops (view, reshape, permute, transpose, slice, unfold, chunk) contribute 0 FLOP, 0 B, and 0 kernel launches, while non-contiguous copy-triggering reshapes are detected automatically.

Each bottleneck tag maps directly to an actionable engineering knob:

  • compute: Reduce FLOPs or raise arithmetic intensity; faster Tensor Cores / FP8 directly help.
  • memory: Fuse operators and tile activations in SRAM; reducing MACs alone helps little.
  • serial: Shorten sequential depth or fuse across recurrent steps; upgrading raw TFLOP/s barely moves runtime.

Installation

Core analyzer (CPU-only compatible, zero GPU or NumPy needed):

pip install git+https://github.com/kongtou20070406/proofline.git

Include Z3 SMT + SymPy symbolic certification:

pip install "proofline[formal] @ git+https://github.com/kongtou20070406/proofline.git"

For local Lean 4 verification, install Lean 4 (>= v4.34.1, lean in PATH or PROOFLINE_LEAN_BIN).

Hardware Presets & Calibration Scorecard

Proofline ships 34 built-in presets (accepting multi-GPU Nx prefixes like 4xh200, 8xb200, 2xrtx5090_measured or any calibrated .json path):

Preset Vendor / Arch SMs/Cores VRAM L2 / Cache BF16 / FP32 Peak Mem BW Status
rtx5090_measured NVIDIA sm120 170 32 GiB 96 MB 195.7 / 95.0 TF 1,508 GB/s Measured
rtx5090 NVIDIA sm120 170 32 GiB 96 MB 209.5* / 104.8 TF 1,792 GB/s Spec
rtx_pro_6000 / rtx5080 NVIDIA sm120 188 / 84 96 / 16 GiB 128 / 64 MB 252.0 / 112.5 TF 1,792 / 960 GB/s Spec
h200 / h100 NVIDIA sm90 132 141 / 80 GiB 50 MB 989.4 / 67.0 TF 4,800 / 3,350 GB/s Spec
b300 / gb200 / b200 NVIDIA sm100 160 / 148 288 / 192 GiB 128 MB 2,500 / 2,250 TF 8,000 GB/s Spec
l40s / a100 / l4 / a10g / t4 NVIDIA 142–40 48–16 GiB 96–4 MB 362–65 TF 2,039–300 GB/s Spec
mi355x / mi325x / mi300x AMD cdna4/3 256 / 304 288 / 256 / 192 GiB 256 MB 2,500 / 1,307 TF 8,000 / 6,000 / 5,300 GB/s Spec
ascend_910c / ascend_910b Huawei DaVinci 48 / 24 128 / 64 GiB 64 / 32 MB 800 / 320 TF 3,200 / 1,200 GB/s Spec
tpu_v6e / tpu_v5p Google TPU 2 / 8 MXUs 31.25 / 95 GiB 64 / 128 MB 918 / 459 TF 1,638 / 2,765 GB/s Spec
apple_m4_pro_measured Apple apple_m4 16 24 GiB 24 MB 5.99 / 5.26 TF 213.5 GB/s Measured (profiles/apple-m4-pro.json)
apple_m3_measured Apple apple_m3 10 16 GiB 8 MB 2.53 / 2.32 TF 85.8 GB/s Measured (profiles/apple-m3.json)
m4_ultra / m3_ultra / m4_max / apple_m4 Apple Silicon 80 / 40 / 10 256–16 GiB 96–12 MB 33.2–4.1 TF 819–120 GB/s Spec
cpu_epyc_9654 / cpu_xeon_8592 x86 AVX-512/AMX 96 / 64 512 GiB 384 / 320 MB 5.5 / 4.8 TF 460 / 307 GB/s Spec

*RTX 5090 theoretical datasheet peaks (sm120, 170 SMs @ 2.41 GHz, 512-bit 28 Gbps GDDR7 = 1,792 GB/s): dense BF16/FP16 Tensor Core is 209.5 TF with FP32 accumulation (PyTorch/cuBLAS default; rtx5090_measured reaches 195.7 TF = 93.4%, FP32 95.0/104.8 TF = 90.6%, GDDR7 1,508/1,792 GB/s = 84.2%) and 419.0 TF with FP16 accumulation or dense FP8 (838.0 TF dense NVFP4 / 2:4 sparse FP8).

Datasheet Roofline vs. Measured Hardware Scorecard (proofline gap --scorecard, mean datasheet attainment 85.1%, gap closed by 15s proofline calibrate --measure):

Workload Device Spec Floor (us) Calibrated (us) Measured (us) Attainment
GEMM (4096^3, bf16) RTX5090 656.0 702.3 702.3 93.4%
GEMM (4096^3, fp32) RTX5090 1,311.4 1,446.7 1,446.7 90.7%
GDDR7 STREAM Copy (512 MB) RTX5090 571.4 679.0 679.0 84.2%
GEMM (4096^3, bf16) Apple-M4-Pro 21,144.5 22,956.2 22,956.0 92.1%
Unified Memory Copy (256 MB) Apple-M4-Pro 1,875.5 2,398.3 2,398.3 78.2%
GEMM (4096^3, bf16) Apple-M3 38,715.2 54,216.6 54,217.0 71.4%
Unified Memory Copy (256 MB) Apple-M3 5,120.0 5,967.4 5,967.4 85.8%

Contribute your hardware profile in two commands:

proofline calibrate --measure --out profiles/my-gpu.json
proofline calibrate --submit profiles/my-gpu.json

LLM, MoE, MLA, Serving Economics & Post-Training

  • Autoregressive Prefill + Decode, MLA, Sliding Window & Hybrid MoE (proofline/llm_moe.py): Models dense GQA/MQA/MHA, MLA (kv_lora_rank + qk_rope_head_dim compressed KV cache — cutting DeepSeek-V3 KV memory ~57× vs. naive MHA), Sliding Window (Gemma-3 alternating global/local KV caps), Hybrid Dense+MoE (first_k_dense_replace, moe_layer_freq), 3:1 Gated-DeltaNet + QSA sparse attention (Qwen3.8-Flash-Next, Qwen3.5-122B-A10B), VLMs (num_images), and Top-$K$ MoE skew / tiered GPU-VRAM + Host-DDR5 offload (-ot ".ffn_.*_exps.=CPU").
  • Continuous Batching, Prefix Cache, PD Disaggregation & $/1M tok (analyze_serving_slo, compare_serving_economics): Searches (TP, DP) layouts and active batch sizes under (TTFT, TPOT) SLOs with KV pool fragmentation and prefix/radix cache hits, compares Colocated vs. Prefill/Decode disaggregation, ranks hardware fleets by $/1M output tokens, and emits copy-pasteable vllm, sglang, llama-server, and torchrun commands (emit_launch_configs).
  • LoRA / QLoRA, GRPO Post-Training & Multi-Step Diffusion (proofline/training_and_concurrency.py): Models frozen quantized base weights (nf4/fp8/bf16) + low-rank adapter states (analyze_lora_training), 3-phase GRPO/RLVR steps (Rollout Gen + Ref Logprob + Policy Update, analyze_grpo_step), and multi-step CFG Diffusion/Video pipelines (analyze_diffusion_generation).

CI Performance Gate, HTML Reports & MCP Server

  • Zero-GPU GitHub Actions PR Regression Gate (.github/actions/proofline-gate/action.yml): Runs on standard free CPU runners in seconds, posts a Markdown delta table to $GITHUB_STEP_SUMMARY, and exits non-zero when latency floor regresses beyond max-regression-pct.
  • Single-File Offline HTML Reports (--html report.html): Generates a zero-dependency interactive HTML document with an SVG Log-Log Roofline scatter plot (hover/click each stage for FLOPs, Q bytes, and arithmetic intensity), Optimization Waterfall bar chart, launch commands, and economics/diff tables.
  • Built-in Coding-Agent MCP Server (proofline mcp): Zero-dependency JSON-RPC 2.0 stdio server exposing proofline_check, proofline_fit, proofline_diff, proofline_advise, proofline_plan, and proofline_lint_triton directly to coding agents.
  • TorchInductor Fusion-Break Diff & @triton.jit Pre-Flight Linter: analyze_inductor_gap parses TorchInductor output_code.py to count extra launches and intermediate HBM spills vs. canonical $G^*$; proofline lint-triton statically flags SM wave starvation, SMEM overflow, non-power-of-two BLOCK_* dims, global atomics, and unmasked loads before launching on GPU.

Microarchitecture, Precision, Graph Advisor & Multi-GPU Parallelism

  • 5-Wall Microarchitecture & Cross-Hardware Compare (--compare-gpus --microarch): Models SM wave quantization / TPU MXU padding, three-unit execution roofs (Tensor Core / FP32 ALU / SFU), 3-level memory hierarchy (SMEM+TMEM / L2 / HBM), grid/cluster sync barriers, and pigeonhole VRAM offload (--kv-cache-gb).
  • Precision Sweeps, L2 Residency & Exact Rewrites (--precision-sweep, --rewrite-opt, --canonical): Sweeps FP32/BF16/FP8/INT8/INT4 + 2:4 sparsity while keeping norm/softmax ops in high precision; normalizes models into implementation-invariant canonical optimal DAG $G^*$ (zero/identity cleanup, CSE, MatMul assoc DP, sibling GEMM fusion, FlashAttention collapse, Conv+BN folding) and emits executable torch.fx.GraphModules via optimize_fx_module.
  • Zero-Config Custom CUDA/Triton Synthesis (proofline/auto_custom.py): Automatically traces unseen @triton.jit kernels (via Python AST + grid evaluation), torch.autograd.Function extensions (sibling pure-PyTorch ref discovery or signature synthesis), and TORCH_LIBRARY ops without manual registration.
  • Computation-Graph Optimization Waterfall & Training/Concurrency (--advise, --train-saturate, --pack-jobs, --dist, --recommend-parallel): Ranks graph rewrites by saved microseconds, detects recurrent L2 weight reuse (B_free), attributes offline torch.profiler Chrome traces into 4 buckets, plans 6-stage training saturation + multi-job packing, and models 6D distributed parallelism (DP/ZeRO/FSDP, TP+SP, CP, PP, EP) with Ring/Tree vs. NCCL 2.27/2.28 symmetric-memory collectives (Every Microsecond Matters, arXiv:2607.16100).

Machine-Checked Certificates & Explicit Assumptions (Z3 + SymPy + Lean 4)

Proofline couples empirical CPU tracing with machine-checked certificates inside an explicit idealized roofline and scheduling model. These certificates verify arithmetic and logical consistency under the model's axioms—they do not independently verify real silicon microcode, driver behavior, or compiler passes. Every bound rests on three explicit assumption layers:

  1. DAG trace fidelity: FakeTensorMode / FX / ONNX / HF config parsing faithfully captures runtime ops, tensor shapes, and dependencies (untraced Python side effects or dynamic data-dependent control flow fall outside the trace).
  2. Compulsory work & I/O ($W, Q$): accounted FLOPs and memory traffic are unavoidable under the fixed algorithm, precision, or declared exact rewrite family $\mathcal{R}_{\text{exact}}$.
  3. Idealized hardware model: abstract machine constants ($F_{\text{eff}}, B, \text{L2}, N_{\text{SM}}, \tau$) and scheduling/cache/fusion axioms match the target hardware and compiler regime.

Within that explicit model:

Contributing & License

Contributions, hardware calibration profiles (proofline calibrate --measure --out profiles/<device>.json), and issue reports are welcome — see CONTRIBUTING.md. Released under the MIT License.

Jelajahi proyek terkait

Memuat…