guychuk commited on
Commit
75d1863
·
verified ·
1 Parent(s): e58c676

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +82 -174
README.md CHANGED
@@ -1,145 +1,19 @@
1
  ---
2
- license: apache-2.0
3
- language:
4
- - en
5
- - code
6
  pretty_name: Kernel-Opt RL (vLLM / SGLang / FlashInfer)
7
- size_categories:
8
- - 10K<n<100K
9
- task_categories:
10
- - text-generation
11
- tags:
12
- - cuda
13
- - triton
14
- - gpu-kernels
15
- - kernel-optimization
16
- - reinforcement-learning
17
- - autotuning
18
- - vllm
19
- - sglang
20
- - flashinfer
21
  configs:
22
- - config_name: kernel_commits
23
- data_files:
24
- - split: train
25
- path: kernel_commits/train-*
26
- - split: test
27
- path: kernel_commits/test-*
28
- - config_name: tuned_configs
29
- data_files:
30
- - split: train
31
- path: tuned_configs/train-*
32
- - split: test
33
- path: tuned_configs/test-*
34
- dataset_info:
35
- - config_name: kernel_commits
36
- features:
37
- - name: repo
38
- dtype: string
39
- - name: commit
40
- dtype: string
41
- - name: date
42
- dtype: string
43
- - name: pr_number
44
- dtype: int64
45
- - name: pr_url
46
- dtype: string
47
- - name: title
48
- dtype: string
49
- - name: message
50
- dtype: string
51
- - name: path
52
- dtype: string
53
- - name: language
54
- dtype: string
55
- - name: license
56
- dtype: string
57
- - name: before_code
58
- dtype: string
59
- - name: after_code
60
- dtype: string
61
- - name: diff
62
- dtype: string
63
- - name: lines_added
64
- dtype: int64
65
- - name: lines_removed
66
- dtype: int64
67
- - name: files_in_commit
68
- dtype: int64
69
- - name: models_mentioned
70
- list: string
71
- - name: hardware_mentioned
72
- list: string
73
- - name: speedup_claims
74
- list: string
75
- - name: prompt
76
- dtype: string
77
- - name: pr_body
78
- dtype: string
79
- - name: gains
80
- dtype: string
81
- - name: kernel_speedup
82
- dtype: float64
83
- - name: e2e_speedup
84
- dtype: float64
85
- splits:
86
- - name: train
87
- num_bytes: 141593657
88
- num_examples: 1365
89
- - name: test
90
- num_bytes: 19848276
91
- num_examples: 152
92
- download_size: 48021541
93
- dataset_size: 161441933
94
- - config_name: tuned_configs
95
- features:
96
- - name: repo
97
- dtype: string
98
- - name: commit
99
- dtype: string
100
- - name: config_path
101
- dtype: string
102
- - name: kernel_file
103
- dtype: string
104
- - name: kernel_name
105
- dtype: string
106
- - name: kernel_source
107
- dtype: string
108
- - name: license
109
- dtype: string
110
- - name: device_name
111
- dtype: string
112
- - name: dtype
113
- dtype: string
114
- - name: block_shape
115
- dtype: string
116
- - name: triton_version
117
- dtype: string
118
- - name: shape
119
- dtype: string
120
- - name: M
121
- dtype: int64
122
- - name: candidate_models
123
- list: string
124
- - name: best_config
125
- dtype: string
126
- - name: prompt
127
- dtype: string
128
- - name: config_pr_url
129
- dtype: string
130
- - name: config_pr_gains
131
- dtype: string
132
- - name: speedup_vs_default
133
- dtype: float64
134
- splits:
135
- - name: train
136
- num_bytes: 401472046
137
- num_examples: 17561
138
- - name: test
139
- num_bytes: 34195181
140
- num_examples: 1726
141
- download_size: 26844202
142
- dataset_size: 435667227
143
  ---
144
 
145
  # Kernel-Opt RL
@@ -152,11 +26,12 @@ concrete deployment (model shape, GPU, dtype, batch size), choose the optimizati
152
  Inference engines ship one generic kernel and specialize it per model and per GPU. Most of that
153
  specialization is not new code. It is **autotuned launch parameters** checked in as JSON
154
  (`E=8,N=14336,device_name=NVIDIA_H100_80GB_HBM3.json`), plus a stream of **perf commits** that rewrite
155
- kernels for specific models and hardware. This dataset turns both into training signal.
 
156
 
157
  ## Subsets
158
 
159
- ### `tuned_configs`: kernel + deployment → best launch config (verifiable)
160
 
161
  | | |
162
  |---|---|
@@ -166,70 +41,102 @@ kernels for specific models and hardware. This dataset turns both into training
166
  | kernels | `fused_moe_kernel` (vLLM + SGLang), `fused_moe_kernel_gptq_awq`, `_w8a8_triton_block_scaled_mm`, `_w8a8_block_fp8_matmul`, `_w8a8_block_int8_matmul`, `_selective_scan_update_kernel` |
167
  | dtypes | bf16/fp16, fp8_w8a8 (per-tensor + 128×128 block), int8_w8a8, int8_w8a16, int4_w4a16 |
168
  | M (tokens) | 1 … 262,144 |
 
169
 
170
- One row is one (config file, batch size M) entry. `prompt` is ready to use: it contains the Triton kernel
171
- source, the hardware, the problem shape, and the MoE models whose shape matches under TP/EP
172
- (`candidate_models`, resolved against 32 MoE model configs on the Hub). `best_config` is the
173
- autotuned answer (`BLOCK_SIZE_M/N/K`, `GROUP_SIZE_M`, `num_warps`, `num_stages`, …).
174
 
175
- Fields: `repo, commit, config_path, kernel_file, kernel_name, kernel_source, device_name, dtype,
176
- block_shape, triton_version, shape (JSON), M, candidate_models, best_config (JSON), prompt`.
 
 
177
 
178
  **Split:** grouped by config filename (hash), so a given (shape, GPU, dtype) never appears in both
179
  train and test, whatever the repo, Triton version or M.
180
 
181
- ### `kernel_commits`: before → after kernel rewrites from perf commits
182
 
183
  | | |
184
  |---|---|
185
- | rows | 1,529 file-level pairs (1,376 train / 153 test) from 873 commits |
186
  | languages | CUDA (`.cu/.cuh`), C++, Triton, CuTe DSL |
187
  | date range | 2023-04 → 2026-10 |
 
188
 
189
  Selected from non-merge commits that touch kernel directories and carry a performance signal in the
190
  title (`[Perf]`, optimize, speedup, faster, tune, throughput, latency, …), excluding build, CI, docs,
191
  tests and reverts. Only modified kernel files are kept: ≤10 per commit, ≤120 KB per file, ≤800 changed
192
- lines. Each row is tagged with the `models_mentioned` (DeepSeek, Qwen, Kimi, Mamba, GLM, …), the
193
- `hardware_mentioned` (SM90/SM100/SM120, B200, H100, MI355X, CPU, …), and the `speedup_claims` parsed
194
- from the message.
195
 
196
- Fields: `repo, commit, date, pr_number, pr_url, title, message, path, language, before_code,
197
- after_code, diff, lines_added, lines_removed, files_in_commit, models_mentioned,
198
- hardware_mentioned, speedup_claims`.
 
 
 
 
 
 
199
 
200
  **Split:** temporal. The newest ~10% of rows are test (2026-10-18 onward), the code least likely to be in
201
  a model's pretraining data.
202
 
 
 
 
 
 
 
 
 
 
 
 
203
  ## Using it for RL
204
 
205
- **`tuned_configs`** gives a verifiable reward without any execution harness:
206
- - *offline proxy*: score the predicted config against `best_config`. Exact match is sparse, so partial
207
- credit per parameter (or log-distance on the power-of-two tile sizes) works better.
208
- - *on hardware*: launch `kernel_source` with the predicted config at the given shape and reward
209
- `t_best / t_pred`. Note that the tuned config is only the best among the tuner's search space, so a
210
- model can beat it.
211
-
212
- **`kernel_commits`** suits:
213
- - *edit-style RL / SFT warm start*: `before_code` + `title` (+ model/hardware context) → `after_code`;
214
- - *preference pairs*: (`before_code`, `after_code`) as (rejected, chosen) for the stated workload;
215
- - *execution reward*: compile, check correctness and benchmark through an execution environment such as
216
  [KernelGYM](https://github.com/hkust-nlp/KernelGYM). Watch for reward hacking (timer exploits, cached
217
  outputs; see the [CUDA-L1](https://github.com/ornith-ai/CUDA-L1) notes).
218
 
219
  ```python
220
  from datasets import load_dataset
221
- ds = load_dataset("guychuk/kernel-opt-rl", "tuned_configs", split="train")
222
- print(ds[0]["prompt"]); print(ds[0]["best_config"])
223
  ```
224
 
 
 
 
225
  ## Limitations
226
 
227
- - Tuned configs record only the *winner*, not the full latency table, so offline rewards are a proxy.
 
228
  - `candidate_models` comes from shape matching (`E == experts`, `N == intermediate / TP`, or
229
  `E == experts / EP`). Shapes are shared across models, e.g. DeepSeek-V3, Kimi-K2 and MiMo-V2-Flash.
230
- - Commit messages from squash merges often omit the PR body, so `speedup_claims` is sparse. The
231
- `pr_url` points to the full benchmark discussion.
232
- - Snapshots are from each repo's HEAD at build time (see `commit`). Rebuild with `build.py` for fresher data.
 
 
 
 
 
 
 
 
 
233
 
234
  ## Related datasets
235
 
@@ -238,6 +145,7 @@ print(ds[0]["prompt"]); print(ds[0]["best_config"])
238
  [Nemotron-SFT-CUDA-v1](https://huggingface.co/datasets/nvidia/Nemotron-SFT-CUDA-v1) (CUDA SFT with tests),
239
  [CUDA-L1](https://github.com/ornith-ai/CUDA-L1) (RL-optimized KernelBench solutions per GPU).
240
 
241
- ## License
242
 
243
- Source code is from vLLM, SGLang and FlashInfer, all Apache-2.0. This compilation is Apache-2.0.
 
 
1
  ---
2
+ license: [apache-2.0, bsd-3-clause, mit]
3
+ language: [en, code]
 
 
4
  pretty_name: Kernel-Opt RL (vLLM / SGLang / FlashInfer)
5
+ size_categories: [10K<n<100K]
6
+ task_categories: [text-generation]
7
+ tags: [cuda, triton, gpu-kernels, kernel-optimization, reinforcement-learning, autotuning, vllm, sglang, flashinfer]
 
 
 
 
 
 
 
 
 
 
 
8
  configs:
9
+ - config_name: tuned_configs
10
+ data_files:
11
+ - {split: train, path: tuned_configs/train-*}
12
+ - {split: test, path: tuned_configs/test-*}
13
+ - config_name: kernel_commits
14
+ data_files:
15
+ - {split: train, path: kernel_commits/train-*}
16
+ - {split: test, path: kernel_commits/test-*}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ---
18
 
19
  # Kernel-Opt RL
 
26
  Inference engines ship one generic kernel and specialize it per model and per GPU. Most of that
27
  specialization is not new code. It is **autotuned launch parameters** checked in as JSON
28
  (`E=8,N=14336,device_name=NVIDIA_H100_80GB_HBM3.json`), plus a stream of **perf commits** that rewrite
29
+ kernels for specific models and hardware. This dataset turns both into RL tasks, with the **benchmark
30
+ gains reported in each PR description** extracted as structured measurements.
31
 
32
  ## Subsets
33
 
34
+ ### `tuned_configs`: kernel + deployment → best launch config
35
 
36
  | | |
37
  |---|---|
 
41
  | kernels | `fused_moe_kernel` (vLLM + SGLang), `fused_moe_kernel_gptq_awq`, `_w8a8_triton_block_scaled_mm`, `_w8a8_block_fp8_matmul`, `_w8a8_block_int8_matmul`, `_selective_scan_update_kernel` |
42
  | dtypes | bf16/fp16, fp8_w8a8 (per-tensor + 128×128 block), int8_w8a8, int8_w8a16, int4_w4a16 |
43
  | M (tokens) | 1 … 262,144 |
44
+ | documented gains | 148 tuning PRs traced, 66 with benchmark tables; `speedup_vs_default` on 399 rows from 46 config files (median 1.30×, p10 1.03×, p90 1.98×) |
45
 
46
+ One row is one (config file, batch size M) entry. `prompt` contains the Triton kernel source, the
47
+ hardware, the problem shape and the MoE models whose shape matches under TP/EP (`candidate_models`,
48
+ resolved against 32 MoE model configs on the Hub). It asks for a JSON config. `best_config` is the
49
+ autotuned answer.
50
 
51
+ Gain fields: `config_pr_url` is the newest PR that added or changed the config file. `config_pr_gains`
52
+ holds all measurements extracted from that PR. `speedup_vs_default` is the documented speedup of the
53
+ tuned config over vLLM/SGLang's default heuristic at this exact M. It is set only when the attribution
54
+ is unambiguous: the GPU and shape match, and multiple matching rows agree within 5%.
55
 
56
  **Split:** grouped by config filename (hash), so a given (shape, GPU, dtype) never appears in both
57
  train and test, whatever the repo, Triton version or M.
58
 
59
+ ### `kernel_commits`: optimize a kernel file the way the real perf PR did
60
 
61
  | | |
62
  |---|---|
63
+ | rows | 1,517 file-level tasks (1,365 train / 152 test) from 850 PRs |
64
  | languages | CUDA (`.cu/.cuh`), C++, Triton, CuTe DSL |
65
  | date range | 2023-04 → 2026-10 |
66
+ | documented gains | 529 PRs with benchmark numbers → 913 rows; `kernel_speedup` on 596 rows (median 1.33×, p10 1.02×, p90 4.25×), `e2e_speedup` on 556 rows |
67
 
68
  Selected from non-merge commits that touch kernel directories and carry a performance signal in the
69
  title (`[Perf]`, optimize, speedup, faster, tune, throughput, latency, …), excluding build, CI, docs,
70
  tests and reverts. Only modified kernel files are kept: ≤10 per commit, ≤120 KB per file, ≤800 changed
71
+ lines.
 
 
72
 
73
+ `prompt` gives the goal (the PR title, which plays the role of the issue in SWE-RL), the target hardware
74
+ and models, and the full `before_code`. It asks for **SEARCH/REPLACE edits**. The PR body is withheld
75
+ from the prompt because it usually describes the fix. The reference answer is `after_code` / `diff`.
76
+ Prompt lengths: median ~21K chars (~6K tokens), p90 ~74K chars. Filter on `len(prompt)` for short-context
77
+ RL.
78
+
79
+ Other fields: `models_mentioned`, `hardware_mentioned`, `speedup_claims` (regex over the commit
80
+ message), `pr_body`, `gains` (structured measurements from the PR), `kernel_speedup` / `e2e_speedup`
81
+ (median documented speedup at kernel and end-to-end scope), `license`.
82
 
83
  **Split:** temporal. The newest ~10% of rows are test (2026-10-18 onward), the code least likely to be in
84
  a model's pretraining data.
85
 
86
+ ### `gains` / `config_pr_gains` format
87
+
88
+ A JSON list of measurements extracted from the PR description:
89
+ `{scope: "kernel"|"e2e", hardware, model, shape, batch_size, metric, unit, higher_is_better, baseline,
90
+ optimized, stated_speedup, speedup}`. `speedup` is computed in code from baseline/optimized and
91
+ normalized so that > 1 means the PR is better. When a PR states only a ratio, `stated_speedup` is used.
92
+ Extraction was done by `Qwen3-235B-A22B-Instruct-2507`, with `gpt-oss-120b` as a fallback for very long
93
+ tables, using an extract-only prompt (no computed numbers). Audit: in 98.8% of extracted
94
+ baseline/optimized pairs, both values appear verbatim in the PR text. The remainder were mostly averages
95
+ of repeated runs. Extraction failed for 5 PRs (malformed model output), which have empty `gains`.
96
+
97
  ## Using it for RL
98
 
99
+ Rewards live in [`code/reward.py`](code/reward.py):
100
+
101
+ - **`tuned_configs`**: `config_reward` is deliberately a stub, because the partial-credit scheme is a design choice. Compare the parsed JSON config to `best_config` as an offline proxy (exact match is
102
+ sparse, so use partial credit or log-distance on the power-of-two tile sizes). `speedup_vs_default`
103
+ tells you how much a config actually matters for that row and can weight the reward. On hardware,
104
+ launch `kernel_source` with the predicted config and reward `t_best / t_pred`. The tuned config is
105
+ only the best within the tuner's search space, so it can be beaten.
106
+ - **`kernel_commits`**: `patch_reward(completion, before_code, after_code)` follows SWE-RL. It returns −1 if
107
+ the edits are malformed or don't apply, and otherwise the `difflib` similarity between the changed lines
108
+ and the real commit's. Validated on this data: the oracle edit scores 1.0 on 98.7% of rows and ≥ 0.95 on
109
+ all but one. For an execution reward, run through an environment such as
110
  [KernelGYM](https://github.com/hkust-nlp/KernelGYM). Watch for reward hacking (timer exploits, cached
111
  outputs; see the [CUDA-L1](https://github.com/ornith-ai/CUDA-L1) notes).
112
 
113
  ```python
114
  from datasets import load_dataset
115
+ ds = load_dataset("guychuk/kernel-opt-rl", "kernel_commits", split="train")
116
+ ds = ds.filter(lambda r: len(r["prompt"]) < 32_000 and r["kernel_speedup"]) # short, with documented gains
117
  ```
118
 
119
+ Both subsets have a plain-string `prompt` column. TRL's `GRPOTrainer` forwards the other columns
120
+ (`best_config`, `before_code`, `after_code`, …) to reward functions as keyword arguments.
121
+
122
  ## Limitations
123
 
124
+ - Tuned configs record only the *winner*, not the full latency table, so offline config rewards are a
125
+ proxy. `speedup_vs_default` covers only rows whose PR documented that exact M.
126
  - `candidate_models` comes from shape matching (`E == experts`, `N == intermediate / TP`, or
127
  `E == experts / EP`). Shapes are shared across models, e.g. DeepSeek-V3, Kimi-K2 and MiMo-V2-Flash.
128
+ - PR gains are self-reported by the authors, on their hardware and benchmark setup, and are not reproduced.
129
+ - Snapshots are from each repo's HEAD at build time (see `commit`). Rebuild for fresher data.
130
+
131
+ ## Licensing
132
+
133
+ All code comes from vLLM, SGLang and FlashInfer (all Apache-2.0). Some vendored files carry their own
134
+ licenses. Each row has a `license` field taken from the file header (Apache-2.0: 1,481 commit rows and all
135
+ config rows; BSD-3-Clause / BSD: 35; MIT: 1). Files under non-open-source licenses (the NVIDIA TensorRT
136
+ Source Code License Agreement and NVIDIA proprietary headers) are **excluded**. License and copyright
137
+ headers in the code are kept verbatim. The upstream `LICENSE` and `NOTICE` files are in
138
+ [`licenses/`](licenses/), as Apache-2.0 §4 requires. The compilation itself is released under
139
+ Apache-2.0. PR descriptions are quoted from public GitHub PRs and linked via `pr_url`.
140
 
141
  ## Related datasets
142
 
 
145
  [Nemotron-SFT-CUDA-v1](https://huggingface.co/datasets/nvidia/Nemotron-SFT-CUDA-v1) (CUDA SFT with tests),
146
  [CUDA-L1](https://github.com/ornith-ai/CUDA-L1) (RL-optimized KernelBench solutions per GPU).
147
 
148
+ ## Reproduce
149
 
150
+ The build code is in [`code/`](code/). `uv run build.py --push <repo_id>` clones the three repos as blobless clones, mines configs and commits,
151
+ fetches PR descriptions with `gh`, extracts gains via HF Inference Providers (cached), and pushes.