-
Notifications
You must be signed in to change notification settings - Fork 273
Add GDN benchmarking #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add GDN benchmarking #501
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """ | ||
| Chart generation for linear attention benchmark results. | ||
|
|
||
| Reads the CSV emitted by the shmoo runner (one --format_output line per | ||
| (backend, batch, seqlen) case) and generates one comparison chart per batch | ||
| size, with Forward and Backward TFLOPS panels side by side — same style as | ||
| the SDPA training benchmark charts. | ||
|
|
||
| python plot_results.py results/gdn/b300/gdn_labench.csv \ | ||
| --output-dir results/gdn/b300 --gpu-name B300 --cudnn-version 9.24.0 | ||
| """ | ||
|
|
||
| import argparse | ||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
| import matplotlib | ||
|
|
||
| matplotlib.use("Agg") | ||
| import matplotlib.pyplot as plt | ||
| import seaborn as sns | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| # Backend display configuration; `order` fixes both bar grouping and legend order. | ||
| BACKEND_CONFIG = { | ||
| "fla": {"name": "FLA (Triton)", "color": "#FF8C00", "order": 0}, | ||
| "flash_qla": {"name": "FlashQLA (TileLang)", "color": "#6495ED", "order": 1}, | ||
| "cudnn": {"name": "cuDNN", "color": "#76b900", "order": 2}, | ||
| } | ||
|
|
||
| LABEL_FONT_SIZE = 10 | ||
| LEGEND_FONT_SIZE = 8 | ||
| TITLE_FONT_SIZE = 12 | ||
| BAR_LABEL_FONT_SIZE = 6 | ||
|
|
||
| CSV_COLUMNS = [ | ||
| "case_tag", | ||
| "backend", | ||
| "variant", | ||
| "batch_size", | ||
| "seqlen", | ||
| "num_q_heads", | ||
| "num_kv_heads", | ||
| "head_dim", | ||
| "fwd_ms", | ||
| "bwd_ms", | ||
| "fwd_tflops", | ||
| "bwd_tflops", | ||
| "max_diff", | ||
| "num_iters", | ||
| ] | ||
|
|
||
|
|
||
| def get_backend_display_name(backend: str, cudnn_version: str = None) -> str: | ||
| base_name = BACKEND_CONFIG.get(backend, {}).get("name", backend) | ||
| if backend == "cudnn" and cudnn_version: | ||
| base_name = f"{base_name} {cudnn_version}" | ||
| return base_name | ||
|
|
||
|
|
||
| def generate_charts(df: pd.DataFrame, output_dir: Path, gpu_name: str = "", cudnn_version: str = None, variant: str = "gdn", batch_sizes: list = None) -> list: | ||
| output_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| df = df[df["variant"] == variant].copy() | ||
| if batch_sizes: | ||
| df = df[df["batch_size"].isin(batch_sizes)].copy() | ||
| if df.empty: | ||
| raise ValueError(f"No rows for variant {variant!r}") | ||
|
|
||
| df["backend_display"] = df["backend"].map(lambda b: get_backend_display_name(b, cudnn_version=cudnn_version)) | ||
| df["backend_order"] = df["backend"].map(lambda b: BACKEND_CONFIG.get(b, {}).get("order", 99)) | ||
|
|
||
| palette = {} | ||
| for _, row in df[["backend", "backend_display"]].drop_duplicates().iterrows(): | ||
| palette[row["backend_display"]] = BACKEND_CONFIG.get(row["backend"], {}).get("color", "gray") | ||
|
|
||
| saved_paths = [] | ||
| for batch_size in sorted(df["batch_size"].unique()): | ||
| sub = df[df["batch_size"] == batch_size].copy() | ||
| sub.sort_values(["seqlen", "backend_order"], inplace=True) | ||
| hue_order = list(sub.sort_values("backend_order")["backend_display"].drop_duplicates()) | ||
|
|
||
| fwd_df = sub[sub["fwd_tflops"] > 0] | ||
| bwd_df = sub[sub["bwd_tflops"] > 0] | ||
| has_fwd = not fwd_df.empty | ||
| has_bwd = not bwd_df.empty | ||
|
|
||
| if has_fwd and has_bwd: | ||
| fig, (ax_fwd, ax_bwd) = plt.subplots(1, 2, figsize=(14, 6), dpi=150) | ||
| elif has_fwd: | ||
| fig, ax_fwd = plt.subplots(1, 1, figsize=(10, 6), dpi=150) | ||
| ax_bwd = None | ||
| else: | ||
| fig, ax_bwd = plt.subplots(1, 1, figsize=(10, 6), dpi=150) | ||
| ax_fwd = None | ||
|
|
||
| heads = sub["num_q_heads"].iloc[0] | ||
| head_dim = sub["head_dim"].iloc[0] | ||
| gpu_info = f" ({gpu_name})" if gpu_name else "" | ||
| fig.suptitle( | ||
| f"{variant.upper()} Linear Attention (BF16) — Batch = {batch_size}, Heads = {heads}, d = {head_dim}{gpu_info}", | ||
| fontsize=TITLE_FONT_SIZE, | ||
| ) | ||
|
|
||
| for ax, pass_df, pass_name, y_col in ( | ||
| (ax_fwd, fwd_df, "Forward", "fwd_tflops"), | ||
| (ax_bwd, bwd_df, "Backward", "bwd_tflops"), | ||
| ): | ||
| if ax is None or pass_df.empty: | ||
| continue | ||
| sns.barplot( | ||
| data=pass_df, | ||
| x="seqlen", | ||
| y=y_col, | ||
| hue="backend_display", | ||
| hue_order=hue_order, | ||
| ax=ax, | ||
| palette=palette, | ||
| edgecolor="black", | ||
| linewidth=0.5, | ||
| errorbar=None, | ||
| ) | ||
| ax.set_xlabel("Sequence Length", fontsize=LABEL_FONT_SIZE) | ||
| ax.set_ylabel("TFLOPS", fontsize=LABEL_FONT_SIZE) | ||
| ax.set_title(pass_name, fontsize=TITLE_FONT_SIZE) | ||
| ax.legend(title="Backend", fontsize=LEGEND_FONT_SIZE) | ||
| ax.tick_params(axis="x", rotation=45) | ||
| for container in ax.containers: | ||
| ax.bar_label(container, fmt="%.0f", fontsize=BAR_LABEL_FONT_SIZE) | ||
|
|
||
| plt.tight_layout() | ||
| output_path = output_dir / f"{variant}_b{batch_size}.png" | ||
| plt.savefig(output_path, dpi=150, bbox_inches="tight") | ||
| plt.close() | ||
| saved_paths.append(output_path) | ||
| print(f"Chart saved to {output_path}") | ||
|
|
||
| return saved_paths | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | ||
| parser.add_argument("csv", type=Path, help="Results CSV from the shmoo runner") | ||
| parser.add_argument("--output-dir", type=Path, default=None, help="Output directory (default: alongside the CSV)") | ||
| parser.add_argument("--gpu-name", default="", help="GPU name for the chart title") | ||
| parser.add_argument("--cudnn-version", default=None, help="cuDNN backend version for the legend (e.g. 9.24.0)") | ||
| parser.add_argument("--variant", default="gdn", help="Linear attention variant to plot") | ||
| parser.add_argument("--batch-sizes", default=None, help="Comma-separated batch sizes to plot (default: all in the CSV)") | ||
| args = parser.parse_args() | ||
| batch_sizes = [int(b) for b in args.batch_sizes.split(",")] if args.batch_sizes else None | ||
|
|
||
| df = pd.read_csv(args.csv) | ||
| missing = [c for c in CSV_COLUMNS if c not in df.columns] | ||
| if missing: | ||
| raise ValueError(f"CSV is missing expected columns: {missing}") | ||
|
|
||
| output_dir = args.output_dir if args.output_dir is not None else args.csv.parent | ||
| generate_charts(df, output_dir, gpu_name=args.gpu_name, cudnn_version=args.cudnn_version, variant=args.variant, batch_sizes=batch_sizes) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
benchmark/linear_attention/results/gdn/b300/gdn_20260806.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| case_tag,backend,variant,batch_size,seqlen,num_q_heads,num_kv_heads,head_dim,fwd_ms,bwd_ms,fwd_tflops,bwd_tflops,max_diff,num_iters | ||
| fla_B1_T2048,fla,gdn,1,2048,64,64,128,0.217,0.649,89,89,0.000000,20 | ||
| flash_qla_B1_T2048,flash_qla,gdn,1,2048,64,64,128,0.102,0.352,190,165,0.000000,20 | ||
| cudnn_B1_T2048,cudnn,gdn,1,2048,64,64,128,0.098,0.279,196,208,0.000000,20 | ||
| fla_B1_T4096,fla,gdn,1,4096,64,64,128,0.416,1.260,93,92,0.000000,20 | ||
| flash_qla_B1_T4096,flash_qla,gdn,1,4096,64,64,128,0.186,0.677,208,171,0.000000,20 | ||
| cudnn_B1_T4096,cudnn,gdn,1,4096,64,64,128,0.129,0.428,301,271,0.000000,20 | ||
| fla_B1_T8192,fla,gdn,1,8192,64,64,128,0.796,2.490,97,93,0.000000,20 | ||
| flash_qla_B1_T8192,flash_qla,gdn,1,8192,64,64,128,0.347,1.342,223,173,0.000000,20 | ||
| cudnn_B1_T8192,cudnn,gdn,1,8192,64,64,128,0.187,0.721,414,321,0.000000,20 | ||
| fla_B1_T16384,fla,gdn,1,16384,64,64,128,1.567,4.957,99,94,0.000000,20 | ||
| flash_qla_B1_T16384,flash_qla,gdn,1,16384,64,64,128,0.674,2.648,229,175,0.000000,20 | ||
| cudnn_B1_T16384,cudnn,gdn,1,16384,64,64,128,0.305,1.309,506,354,0.000000,20 | ||
| fla_B1_T32768,fla,gdn,1,32768,64,64,128,3.119,9.976,99,93,0.000000,20 | ||
| flash_qla_B1_T32768,flash_qla,gdn,1,32768,64,64,128,1.329,5.294,233,175,0.000000,20 | ||
| cudnn_B1_T32768,cudnn,gdn,1,32768,64,64,128,0.529,2.494,585,372,0.000000,20 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 36203
🌐 Web query:
QwenLM FlashQLA GitHub README benchmark instructions pinned dependencies release notes API alignment💡 Result:
FlashQLA is a high-performance linear attention library by QwenLM designed to accelerate Gated Delta Networks (GDN) [1]. Benchmark Instructions To benchmark FlashQLA, you must have the required dependencies installed, including flash-linear-attention (FLA) and flashinfer [2][3]. The benchmark scripts are located in the benchmark directory [2][4]. For example, to run the gated delta rule benchmark, ensure the correct versions are installed and run the script [2][4]: pip install flash_linear_attention==0.5.0 flashinfer-python==0.6.13 python benchmark/bench_gated_delta_rule.py Detailed benchmark results for H200 (SM90) and GB200 (SM100) are available in the repository's benchmark directory [2][5]. Pinned Dependencies The project enforces specific dependency versions for compatibility [1]. As of version 0.1.2, these include: - torch: >=2.8 [1] - tilelang: ==0.1.9 [1] - apache-tvm-ffi: ==0.1.9 [1] - flash_linear_attention: ==0.5.0 (for comparison/API alignment) [2][3] Release Notes - v0.1.2 (July 2026): Added forward pass support for SM120 (Blackwell) architectures and established the library as a backend for the flash-linear-attention GDN, enabling plug-and-play acceleration [1]. - v0.1.1 (June 2026): Introduced intra-card sequence parallelism for the backward pass and added SM100 architecture support [5][1]. This release also upgraded the tilelang dependency to v0.1.9 and aligned entry function signatures with the latest flash-linear-attention interface [5][6][1]. API Alignment FlashQLA is aligned with the flash-linear-attention (FLA) API, allowing it to serve as a high-performance backend [1]. The high-level API is accessed via chunk_gated_delta_rule, and the low-level API provides separate forward (chunk_gated_delta_rule_fwd) and backward (chunk_gated_delta_rule_bwd) functions, mirroring standard interfaces used in linear attention research [1].
Citations:
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 36099
🌐 Web query:
QwenLM FlashQLA GitHub README benchmark pinned dependencies release notes API alignment💡 Result:
FlashQLA is a high-performance linear attention kernel library developed by QwenLM that leverages the TileLang compiler to optimize GDN (Gated Delta Network) Chunked Prefill operations [1][2]. Key technical aspects include: Benchmarks: The library demonstrates significant performance improvements over the FLA (Flash Linear Attention) Triton kernel, achieving 2-3x speedup in forward passes and 2x speedup in backward passes on NVIDIA Hopper (SM90) and Blackwell (SM100) architectures [2][3]. Detailed benchmark results for H200 and GB200 systems are provided in the repository's benchmark directory [3]. Pinned Dependencies: The project maintains strict dependency requirements to ensure compatibility with its TileLang-based kernels. According to setup.py and README documentation, the library requires: - Python >= 3.10 [4] - PyTorch >= 2.8 [2][4] - TileLang == 0.1.9 [4] - Apache-tvm-ffi == 0.1.9 [4] - CUDA 12.8 or above [2] Release Notes & Alignment: Recent updates, such as v0.1.1, introduced support for the SM100 architecture and the state_v_first parameter [5][3]. A key focus in recent releases has been aligning the entry function signatures with the latest interfaces from the flash-linear-attention library, ensuring better interoperability [5][3]. API: FlashQLA provides both high-level and low-level APIs [1][6]: - High-level: Access via chunk_gated_delta_rule, which handles the core forward/backward computations and state management [1]. - Low-level: Access via separate chunk_gated_delta_rule_fwd and chunk_gated_delta_rule_bwd functions for fine-grained control over forward and backward passes [1]. The project is released under the MIT License [1][4].
Citations:
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 2459
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 406
🏁 Script executed:
Repository: NVIDIA/cudnn-frontend
Length of output: 8408
Pin the complete benchmark dependency set.
Pin the FlashQLA tag or commit,
flash-linear-attention==0.5.0, and all transitive dependencies. FlashQLA v0.1.2 requirestilelang==0.1.9andapache-tvm-ffi==0.1.9. Also pin thecudnn-frontendsource clone. Record the tested versions in a constraints or lock file to keep benchmark results comparable across rebuilds.🤖 Prompt for AI Agents
Source: MCP tools