2 |
3 |

4 |
5 | [](https://bench.flashinfer.ai/docs/)
6 | [](https://github.com/flashinfer-ai/flashinfer-bench/blob/main/LICENCE)
7 | [](https://pypi.org/project/flashinfer-bench/)
8 |
9 | **Building the Virtuous Cycle for AI-driven LLM Systems**
10 |
11 | [Get Started](#get-started) | [Documentation](https://bench.flashinfer.ai/docs/) | [Blogpost](https://flashinfer.ai/2025/10/21/flashinfer-bench.html)
12 | | [Slack (#flashinfer-bench)](https://join.slack.com/t/flashinfer/shared_invite/zt-379wct3hc-D5jR~1ZKQcU00WHsXhgvtA)
13 |
14 | **FlashInfer-Bench** is a benchmark suite and production workflow designed to build a virtuous cycle of self-improving AI systems.
15 |
16 | It is part of a broader initiative to build the *virtuous cycle of AI improving AI systems* — enabling AI agents and engineers to collaboratively optimize the very kernels that power large language models.
17 |
18 | ## Installation
19 |
20 | Install FlashInfer-Bench with pip:
21 |
22 | ```bash
23 | pip install flashinfer-bench
24 | ```
25 |
26 | Import FlashInfer-Bench:
27 |
28 | ```python
29 | import flashinfer_bench as fib
30 |
31 | print(fib.__version__)
32 | ```
33 |
34 | ## Get Started
35 |
36 | This [guide](https://bench.flashinfer.ai/docs/start/quick_start) shows you how to use FlashInfer-Bench python module with the FlashInfer-Trace dataset.
37 |
38 | ## FlashInfer Trace Dataset
39 |
40 | We provide an official dataset called **FlashInfer-Trace** with kernels and workloads in real-world AI system deployment environments. FlashInfer-Bench can use this dataset to measure and compare the performance of kernels. It follows the [FlashInfer Trace Schema](https://bench.flashinfer.ai/docs/flashinfer-trace).
41 |
42 | The official dataset is on HuggingFace: https://huggingface.co/datasets/flashinfer-ai/flashinfer-trace
43 |
44 | ## Collaborators
45 |
46 | Our collaborators include:
47 |
48 |
49 |
50 | [

](https://github.com/NVIDIA/TensorRT-LLM)
51 |
52 | [

](https://github.com/gpu-mode)
53 |
54 | [

](https://github.com/sgl-project/sglang)
55 |
56 | [

](https://github.com/vllm-project/vllm)
57 |
58 | [

](https://www.bosch.com/)
59 |
60 |
61 |
--------------------------------------------------------------------------------
/flashinfer_bench/integration/patch_manager.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 |
3 | import importlib
4 | from dataclasses import dataclass
5 | from typing import Any, Callable, Dict, Literal, Optional, Tuple
6 |
7 | Kind = Literal["function", "method", "callable"]
8 |
9 |
10 | @dataclass
11 | class PatchSpec:
12 | path: str
13 | kind: Kind
14 | name: str
15 | ctx_key: Optional[str] = None
16 |
17 |
18 | class PatchManager:
19 | """Responsible for: resolve target, replace attr, restore original."""
20 |
21 | def __init__(self) -> None:
22 | # (owner_obj, attr_name) -> original
23 | self._originals: Dict[Tuple[object, str], Any] = {}
24 |
25 | def _resolve(self, path: str) -> Tuple[object, str, Any]:
26 | """
27 | Resolve a dotted path to (owner, attr, original_attr).
28 | Works for module functions or class attributes (methods).
29 | """
30 | parts = path.split(".")
31 | # greedily import the longest module prefix
32 | for i in range(len(parts), 0, -1):
33 | mod_name = ".".join(parts[:i])
34 | try:
35 | mod = importlib.import_module(mod_name)
36 | owner: object = mod
37 | rest = parts[i:]
38 | break
39 | except Exception:
40 | continue
41 | else:
42 | raise ImportError(f"Cannot import any module from '{path}'")
43 |
44 | # descend attributes to find owner of the final attribute
45 | for j in range(len(rest) - 1):
46 | owner = getattr(owner, rest[j])
47 |
48 | attr_name = rest[-1] if rest else None
49 | if attr_name is None:
50 | raise AttributeError(f"Path '{path}' has no attribute segment")
51 |
52 | original = getattr(owner, attr_name)
53 | return owner, attr_name, original
54 |
55 | def patch(
56 | self,
57 | spec: PatchSpec,
58 | wrapper_factory: Callable[[PatchSpec, Callable[..., Any]], Callable[..., Any]],
59 | ) -> bool:
60 | """Install a wrapper on target; return True if success, False if target missing."""
61 | try:
62 | owner, attr, original = self._resolve(spec.path)
63 | except Exception:
64 | return False # target not present in this env; silently ignore
65 |
66 | key = (owner, attr)
67 | if key in self._originals:
68 | return True # already patched (idempotent)
69 |
70 | wrapper = wrapper_factory(spec, original)
71 | setattr(owner, attr, wrapper)
72 | self._originals[key] = original
73 | return True
74 |
75 | def unpatch_all(self) -> None:
76 | """Restore all originals."""
77 | for (owner, attr), original in list(self._originals.items()):
78 | try:
79 | setattr(owner, attr, original)
80 | except Exception:
81 | pass
82 | self._originals.clear()
83 |
84 |
85 | _manager = PatchManager()
86 |
87 |
88 | def get_manager() -> PatchManager:
89 | return _manager
90 |
--------------------------------------------------------------------------------
/web/apps/web/app/kernels/[name]/page.tsx:
--------------------------------------------------------------------------------
1 | import { Suspense } from "react"
2 | import { notFound } from "next/navigation"
3 | import { getDefinition, getSolutionsForDefinition, getTracesForDefinition, getAllDefinitions } from "@/lib/data-loader"
4 | import { computeCorrectnessSummaryForSolutions, computeFastPCurvesForSolutions, type BaselineConfig } from "@/lib/analytics"
5 | import baselinesData from "@/data/baselines"
6 | import { DefinitionHeader } from "./header"
7 | import { AxesSignatureSection } from "./axes-sig"
8 | import { ConstraintsSection } from "./constraints"
9 | import { DefinitionReference } from "./reference"
10 | import { SolutionsSection } from "./solutions"
11 |
12 | export async function generateStaticParams() {
13 | const definitions = await getAllDefinitions()
14 | return definitions.map((definition) => ({
15 | name: definition.name,
16 | }))
17 | }
18 |
19 | export default async function TraceDetailPage({
20 | params
21 | }: {
22 | params: Promise<{ name: string }>
23 | }) {
24 | const { name } = await params
25 | const definition = await getDefinition(name)
26 |
27 | if (!definition) {
28 | notFound()
29 | }
30 |
31 | const [solutions, traces] = await Promise.all([
32 | getSolutionsForDefinition(definition.name),
33 | getTracesForDefinition(definition.name)
34 | ])
35 |
36 | const baselineConfig = (baselinesData as Record