triton-kernel-writing

Practical guidance for writing or reviewing Triton kernels for vLLM. Covers generated code inspection, launching grids, indexing and specialization, tuning workflows, and suggested steps for representative performance validation.

Last repository push
GitHub Stars
97,308
Forks
25,102
Issues / PRs
2,972

Screenshots

A demonstration from skillπ Lab

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "triton-kernel-writing" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-450e684b07fe146cd422204ab3a1edd144d8ef27d00ec4511c8b6a9a9efc2601. Verify the upstream source and version against https://github.com/vllm-project/vllm before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Practical guidance for writing or reviewing Triton kernels for vLLM. Covers generated code inspection, launching grids, indexing and specialization, tuning workflows, and suggested steps for representative performance validation.

5 Downloads

Introduction source: third_party · vllm-project · 0.0.1 Reference

SkillPi interpretation

Tasks
Write or review Triton kernels for vLLM, with practical guidance for generated-code inspection, launch grids, indexing, specialization, tuning, and representative performance validation.
Audience
Not specified in the source documentation.
Inputs and outputs
Not specified in the source documentation.
Software, accounts and paid services
Not specified in the source documentation.
Limits and differences
Not specified in the source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: triton-kernel-writing
description: Write or review Triton kernels for vLLM, with practical guidance for generated-code inspection, launch grids, indexing, specialization, tuning, and representative performance validation.

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.compile as a possible implementation to inspect. Print Inductor's generated code with TORCH_LOGS="output_code" .venv/bin/python <script> or enable torch._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. Use triton.autotune only 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] and grid[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_tokens is commonly 8K or 16K, but users may configure 32K or more. If num_tokens is a grid dimension, it is safe to put it in grid[0] (or tile it).
  • Use int64 for 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-verbose to catch missing variants.
  • Choose accumulation and intermediate dtypes explicitly. Test numerically difficult inputs, not only random, well-scaled tensors.
  • Use $kernel-microbenchmark for benchmark construction, measurement, and interpretation.
  • Benchmark a sweep of num_tokens covering 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.

Current listing version

0.0.1

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value95/100

Highlights

  • 针对vLLM Triton内核编写与审查,解决高性能推理中的核心优化问题
  • 提供生成代码检查、启动网格、索引、特化、调优及性能验证的完整指导
  • 覆盖边界形状验证、数值精度测试和代表性工作负载基准测试
Trigger Precision85/100

Highlights

  • 触发词精准覆盖Triton内核编写、审查及性能验证场景
  • description明确指向vLLM特定需求,边界清晰
Structure and Standards90/100

Highlights

  • Implementation、Launch and Indexing、Validation三大模块划分清晰
  • 每个模块包含具体指导原则和最佳实践
  • frontmatter完整,文档结构规范
Execution Reliability88/100

Highlights

  • 引用官方Triton语义文档,工具来源明确
  • 覆盖主要异常情况(如JIT编译、指针同步、网格限制)
  • 提供具体验证方法和基准测试指导
Evidence Verifiability (mean of the first four)90/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • triton-lang.org

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Not specified in the source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.