Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ The aim of `flashinfer_benchmark.py` is to provide a single framework for benchm
## Overview

This framework provides tools to:
- Benchmark FlashInfer's Attention, GEMM, MOE, Norm, Quantization, Sampling, RoPE, and Mamba API performance from different kernel backends such as FlashAttention2/3, cuDNN, cuBLAS, CUTLASS, CuTe-DSL, TensorRT-LLM, and Triton
- Benchmark FlashInfer's Attention, GEMM, MOE, Norm, Quantization, Sampling, RoPE, Mamba, and GDN API performance from different kernel backends such as FlashAttention2/3, cuDNN, cuBLAS, CUTLASS, CuTe-DSL, TensorRT-LLM, and Triton
- Compare performance across different configurations
- Batch performance test multiple test cases

Currently supports testing attention, gemm, fused MOE, normalization, quantization, sampling, RoPE, and Mamba APIs:
Currently supports testing attention, gemm, fused MOE, normalization, quantization, sampling, RoPE, Mamba, and GDN (Gated Delta Net) APIs:
- Attention:
- `BatchDecodeWithPagedKVCacheWrapper` - Decode attention with paged KV cache.
- Also supports computationally similar `cudnn_batch_decode_with_kv_cache` and `trtllm_batch_decode_with_kv_cache`.
Expand Down Expand Up @@ -77,6 +77,10 @@ Currently supports testing attention, gemm, fused MOE, normalization, quantizati
- `rope_quantize_fp8_append_paged_kv_cache` - RoPE with FP8 quantization and paged KV cache append (SM8.9+).
- Mamba (Selective State Space Models):
- `selective_state_update` - Selective state update for Mamba layers (generation phase). Supports both single-token prediction (STP) and multi-token prediction (MTP) via `--cache_steps`. Backends: `flashinfer` (CUDA, architecture-specific kernels for base/SM90/SM100+) and `triton` (reference).
- GDN (Gated Delta Net linear attention, SM90+):
- `gated_delta_rule_decode` - Single-token (T=1) gated delta rule decode. `--state_layout` selects between `gated_delta_rule_decode_pretranspose` ([B, HV, V, K] state, default) and `gated_delta_rule_decode` ([B, HV, K, V] state). `--state_dtype bfloat16` selects the BF16 state kernels (head_size=128, pretranspose only). Backends: `flashinfer` (CuTe-DSL) and `triton` (reference).
- `gated_delta_rule_mtp` - Multi-token (T>=2) gated delta rule for speculative-decoding verification, with a state pool + indices. `--state_dtype float32` uses `gated_delta_rule_mtp`; `--state_dtype bfloat16` uses the BF16 MTP kernel via `gated_delta_rule_decode_pretranspose`. Backends: `flashinfer`, `triton`.
- `chunk_gated_delta_rule` - Chunked GDN prefill over varlen sequences (uniform per-sequence length `--s_qo`). Backends: `flashinfer` (SM90 C++ / SM100 CuTe-DSL) and `fla` (flash-linear-attention Triton baseline, perf-only).

## Quick Start
### Single Test Run
Expand Down Expand Up @@ -445,6 +449,31 @@ mpirun -np 8 python benchmarks/flashinfer_benchmark.py \
| `--dt_softplus` | Apply softplus to dt before use |
| `--backends` | Backends to test: `flashinfer` (default), `triton` (reference). Refcheck compares against Triton reference |

### GDN Flags
Applies to `gated_delta_rule_decode`, `gated_delta_rule_mtp`, and `chunk_gated_delta_rule` (SM90+).

| Flag | Description |
|-------------------------------|-------------------------------------------------------------------------------------------------------------|
| `--batch_size` | Decode/MTP: number of concurrent requests. Prefill: number of sequences |
| `--num_q_heads` | Number of query heads. Default: 16 |
| `--num_k_heads` | Number of key heads. Default: 16 |
| `--num_v_heads` | Number of value heads (GVA when > `num_q_heads`). Default: 32 |
| `--head_size` | Head dimension (K = V = head_size). Default: 128 |
| `--input_dtype` | Data type for q/k/v/a/b tensors: `bfloat16` (default) or `float16` |
| `--state_dtype` | Recurrent state dtype: `float32` (default) or `bfloat16` (BF16 state kernels; decode/MTP, head_size=128, pretranspose) |
| `--state_layout` | Decode only: `pretranspose` ([B, HV, V, K], default) or `nontranspose` ([B, HV, K, V]) |
| `--pool_mode` | `single` (default, read == write slots) or `split` (pool of 2B; reads slots [0..B), writes [B..2B)) |
| `--seq_len` | MTP only: tokens per request (>= 2). Default: 2 |
| `--s_qo` | Prefill only: per-sequence length (uniform). Default: 2048 |
| `--update_state` | MTP only: write the final state back (`disable_state_update=False`). BF16 state always updates in-place |
| `--cache_intermediate_states` | MTP with `float32` state only: cache per-token intermediate states |
| `--no_qk_l2norm` | Decode/MTP: disable in-kernel Q/K L2 normalization |
| `--backends` | Decode/MTP: `flashinfer` (default), `triton`. Prefill: `flashinfer` (default), `fla` (requires `pip install flash-linear-attention`; perf-only, excluded from refcheck) |

Notes:
- Refcheck compares against the torch reference in `tests/gdn/reference_delta_rule.py`.
- Prefill pre-L2-normalizes k and calls the kernel with `use_qk_l2norm_in_kernel=False` so the kernel and reference see identical inputs.

## `flashinfer_benchmark.py` Routine & Backend Support Matrix
The following table summarizes the support surface of each routine & backend's on various [CUDA Compute Capabilities](https://developer.nvidia.com/cuda-gpus).

Expand Down Expand Up @@ -516,6 +545,9 @@ Legend:
| **rope_quantize_fp8** | | | | cuda | cuda | cuda | cuda | cuda |
| **rope_quantize_fp8_append_paged_kv_cache** | | | | cuda | cuda | cuda | cuda | cuda |
| **selective_state_update** | flashinfer, triton | flashinfer, triton | flashinfer, triton | flashinfer, triton | flashinfer, triton | flashinfer, triton | flashinfer, triton | flashinfer, triton |
| **gated_delta_rule_decode** | | | | | flashinfer, triton | flashinfer, triton | flashinfer, triton | triton |
| **gated_delta_rule_mtp** | | | | | flashinfer, triton | flashinfer, triton | flashinfer, triton | triton |
| **chunk_gated_delta_rule** | | | | | flashinfer, fla | flashinfer, fla | flashinfer, fla | |

Backend Legend:
- fa2: FlashAttention2
Expand All @@ -533,4 +565,5 @@ Backend Legend:
- cute-dsl: FlashInfer CuTe-DSL kernels (Blackwell SM10.0+)
- moe_a2a: MoE All-to-All communication (requires mpirun, Blackwell SM10.0+ with MNNVL)
- allreduce: AllReduce fusion communication (requires mpirun, Blackwell SM10.0+ with MNNVL)
- triton: Triton reference kernels (used for Mamba selective_state_update)
- triton: Triton reference kernels (used for Mamba selective_state_update and GDN decode/MTP)
- fla: flash-linear-attention Triton kernels (GDN prefill baseline)
Loading
Loading