write-triton-softmax-kernel

write-triton-softmax-kernel is a skill for Claude Code, Codex from tensormux/kernel-skills. It costs 0 tokens per session (2,951 once invoked), scanned A, original, MIT.

A guide for writing a Triton GPU program that calculates softmax across each row, including masked softmax for attention models.

In plain words
What is it for?
Use it to implement or debug fused row-wise softmax, masked attention softmax, or softmax combined with scaling or neighboring operations.
Why use it?
It helps keep the calculation numerically stable and handle masks and row sizes correctly while combining related operations into one GPU program.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/tensormux/kernel-skills/write-triton-softmax-kernel
Any agent
npx skills add tensormux/kernel-skills --skill write-triton-softmax-kernel
Clone the repo
git clone --depth 1 https://github.com/tensormux/kernel-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for write-triton-softmax-kernel

README.md
[![agentmods](https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-triton-softmax-kernel.svg)](https://agentmods.dev/skills/tensormux/kernel-skills/write-triton-softmax-kernel)
Your own site
<a href="https://agentmods.dev/skills/tensormux/kernel-skills/write-triton-softmax-kernel"><img src="https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-triton-softmax-kernel.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,951 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02951
Opus 5 $0.00000 $0.01476
Sonnet 5 $0.00000 $0.00590
Haiku 4.5 $0.00000 $0.00295

Measured 7d ago against content hash 90b122156965, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

write-triton-softmax-kernel scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/triton/write-triton-softmax-kernel/SKILL.md · 153 lines

How it starts

The opening of the file, as written. The whole thing — 153 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Skill: Write a Triton Softmax Kernel

Purpose

Guide the agent through implementing a numerically stable, performant row-wise softmax kernel in Triton. This covers single-program-per-row assignment, online max+sum reduction with tl.max/tl.sum, masking for rows wider than BLOCK_SIZE, fp32 accumulation to avoid overflow and precision loss, and the masked softmax variant for attention.


Use this when

  • You need a fused softmax that avoids a separate max-reduction kernel pass and a separate division pass — i.e., you want a single kernel that reads each row once.
  • You need a masked softmax (attention mask applied before the exp) and PyTorch's built-in path is not fusing the mask application correctly.
  • You are fusing softmax with a preceding or following elementwise operation (e.g., scale by 1/sqrt(d_k) before softmax, or multiply output by values V immediately after).
  • The row dimension is large enough that a per-row kernel is worthwhile (row_size >= 256 is a reasonable floor). Below this, torch.nn.functional.softmax is likely faster.

Do not use this when

  • The input is a standard 2D or 3D tensor with no mask and no fusion requirement. torch.nn.functional.softmax backed by cuDNN or torch.compile will handle this efficiently.
  • The softmax dimension is across rows rather than within rows (i.e., column-wise softmax). The per-row strategy does not apply without transposing the problem.
  • The row size is very small (< 64). A warp-level reduction in CUDA or a fused torch.compile graph is more efficient.
  • You need a stable online-softmax for arbitrarily long sequences in a streaming fashion — this requires a more complex multi-block reduction strategy beyond a single-program-per-row approach.

Inputs the agent should gather first

Before writing any code, confirm:

  1. Input shape — (N, D) or (B, H, N, D) or similar. Which dimension is the softmax applied over?
  2. Row dimension size D — is it fixed (compile-time constant), or dynamic? Is it always a power of 2?
  3. Input dtype — fp16, bf16, or fp32. Accumulation dtype must be fp32 regardless.
  4. Whether a mask is applied — additive mask (large negative values added before softmax) or boolean mask (invalid positions should be treated as -inf)?
  5. Whether to fuse a downstream operation — e.g., multiply by a V matrix tile, apply dropout, or write to a specific output layout.
  6. Whether the row fits in one BLOCK_SIZE — or whether a loop over multiple blocks per row is needed.
  7. Hardware target — relevant for choosing BLOCK_SIZE and deciding whether to use triton.autotune.

Read the full file on GitHub · 153 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 153 lines · 0 tokens per session scan A 90b122156965

Subscribe to this mod's changes

write-triton-softmax-kernel is a skill published in the GitHub repository tensormux/kernel-skills (73 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,951 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

hashgraph-online/awesome-codex-plugins · 53 tokens

ring:adopting-lib-commons-huma-wrapper

Adopting the lib-commons/v5 shared Huma (OAS 3.1) OpenAPI wrapper + RFC 9457 problem model (commons/net/http/{openapi,problem}) in a Lerian Go service: wire openapi.New/ServeSpec + problem.Install (central >=500 scrub) on BOTH runtime and spec-gen paths, the per-rail problem.MapError flex seam, and rename-only spec…

LerianStudio/ring · 142 tokens

cutedsl_megamoe

Skill "cutedsl_megamoe" from flashinfer-ai/flashinfer, covering updating the cutedsl megamoe kernel src, layout, when the kernel team drops a new version of src/ and what not to update here.

flashinfer-ai/flashinfer · 0 tokens

ai-ml-development

AI and machine learning development with PyTorch, TensorFlow, and LLM integration. Use when building ML models, training pipelines, fine-tuning LLMs, or implementing AI features.

travisjneuman/.claude · 43 tokens

triton-kernel-optimization

This skill should be used when writing or tuning Triton GPU kernels, including autotuning block sizes, coalesced accesses, tiled matmul, fused ops, reductions, flash-attention style kernels, quantization, custom gradients, and profiling.

AMD-AGI/Apex · 56 tokens

ort

ONNX Runtime in Rust via the ort crate (2.x): loading sessions, configuring CPU/CoreML/CUDA execution providers, tensor I/O with ndarray, async-safe spawnblocking wrapping, global thread-pool init, and debugging provider/opset issues.

bobmatnyc/claude-mpm-skills · 54 tokens