triton-kernel-writing
Skill683 starsChanged 19 days agoApache-2.0View on GitHub
Write or review Triton kernels for vLLM, with practical guidance for generated-code inspection, launch grids, indexing, specialization, tuning, and representative performance validation. Use when adding, modifying, optimizing, or reviewing a `@triton.jit` kernel in vLLM.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- guqiong96/Lvllmword for word, first seen Oct 8, 2026
- vllm-project/vllmword for word, first seen Oct 8, 2026
Other versions2 projects use a version of this.
Word for word · 2
- vllm-project/vllm★ 97k100% same
- guqiong96/Lvllm★ 475100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- tests/AGENTS.mdAGENTS.md
- check-api-compatSkill
- ci-fails-buildkiteSkill
- debug-imaSkill
- kernel-microbenchmarkSkill
- model-microbenchmarkSkill
- model-recipesSkill
- pr-checklistSkill
- transformers-upgradeSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Check it when behavior may differ from Python or NumPy, especially type promotion, integer division and modulo, casts, broadcasting, and …
- Very specific: line 15
Use the Triton kernel generated by torch.compile as a possible implementation to inspect.
- Very specific: line 25
Avoid unintended runtime JIT compilation.
- Very specific: line 46
Use int64 for offset arithmetic when an index can exceed 32-bit range, especially for KV-cache addressing.
- Distinctive: line 55
Check correctness at boundary shapes and at sizes that exercise masks and large offsets.
- Very specific: line 61
Use $kernel-microbenchmark for benchmark construction, measurement, and interpretation.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Triton Kernel Writing
Implementation
- Follow the official Triton semantics. Check it when behavior may differ from Python or NumPy, especially type promotion, integer division and modulo, casts, broadcasting, and variable scoping.
- Use the Triton kernel generated by
torch.compileas a possible implementation to inspect. Print Inductor's generated code withTORCH_LOGS="output_code" .venv/bin/python <script>or enabletorch._logging.set_logs(output_code=True)before the compiled function runs. Treat generated code as a reference, not as proof of correctness or optimality. - Find reasonable defaults for compile-time knobs such as
BLOCK_SIZE, or use a small, legible heuristic when workloads need different choices. Usetriton.autotuneonly when tuning is critical to performance, such as for a matrix multiplication. Otherwise prioritize simple code and fast startup. - Avoid unintended runtime JIT compilation. Put unimportant runtime integer
scalars in
do_not_specialize, especially values that alternate between 0 and 1. Pointer alignment also affects specialization: an offset tensor view can trigger a new variant after warmup used an aligned allocation. For scalar-only pointers whose alignment provides no useful optimization, use@triton.jit(do_not_specialize_on_alignment=["end_ptr"]). Retain alignment specialization when vectorized accesses benefit from it. See the Triton JIT options. - The Triton compiler does not guarantee safe ordering when a kernel writes to
a pointer and subsequently reads from the same pointer. This pattern must
have a
tl.debug_barrier()between the write and read. The barrier synchronizes threads in the block; it does not synchronize separate program instances.
Launch and Indexing
grid[1]andgrid[2]must be at most 65,535. Choose or flatten the grid order so those dimensions cannot exceed the limit for supported shapes. For example,num_tokensis commonly 8K or 16K, but users may configure 32K or more. Ifnum_tokensis a grid dimension, it is safe to put it ingrid[0](or tile it).- Use
int64for offset arithmetic when an index can exceed 32-bit range, especially for KV-cache addressing. Cast operands before multiplication or addition so an intermediate does not overflow in 32-bit arithmetic. - A
[num_tokens, num_heads]grid can be a good low-latency mapping for decode, but it can be very slow for prefill. If the kernel serves prefill, consider tiling tokens or otherwise increasing the work and locality per program.
Validation
- Check correctness at boundary shapes and at sizes that exercise masks and
large offsets. Include offset tensor views, not only fresh allocations.
Warm aligned buffers, then exercise offset views with vLLM's
--jit-monitor-mode error --jit-monitor-verboseto catch missing variants. - Choose accumulation and intermediate dtypes explicitly. Test numerically difficult inputs, not only random, well-scaled tensors.
- Use
$kernel-microbenchmarkfor benchmark construction, measurement, and interpretation. - Benchmark a sweep of
num_tokenscovering decode and representative prefill workloads. Include relevant head counts and dimensions when they affect the launch shape, and do not select an implementation or tuning heuristic from a single setup. - Include compilation or autotuning overhead when evaluating startup behavior; report steady-state kernel performance separately.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

