write-triton-layernorm-kernel

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

A guide for writing a Triton GPU program that performs row-wise layer normalization, which standardizes values in each row, and its RMSNorm variant.

In plain words
What is it for?
Use it to implement or debug fused LayerNorm or RMSNorm GPU code, including versions with scaling parameters, residual additions, or a backward pass.
Why use it?
It helps avoid mistakes in numerical calculations, padding, scaling, and handling rows whose size does not fit the program block.

Skill for Claude CodeCodex

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

Good fit Use it to implement or debug fused LayerNorm or RMSNorm GPU code, including versions with scaling parameters, residual additions, or a backward pass.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/tensormux/kernel-skills/write-triton-layernorm-kernel
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.

Any agent
npx skills add tensormux/kernel-skills --skill write-triton-layernorm-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-layernorm-kernel

README.md
[![agentmods](https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-triton-layernorm-kernel.svg)](https://agentmods.dev/skills/tensormux/kernel-skills/write-triton-layernorm-kernel)
Your own site
<a href="https://agentmods.dev/skills/tensormux/kernel-skills/write-triton-layernorm-kernel"><img src="https://agentmods.dev/badge/skills/tensormux/kernel-skills/write-triton-layernorm-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 3,009 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.03009
Opus 5 $0.00000 $0.01504
Sonnet 5 $0.00000 $0.00602
Haiku 4.5 $0.00000 $0.00301

Measured 8d ago against content hash 2444ec23f016, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

write-triton-layernorm-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 8d 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-layernorm-kernel/SKILL.md · 160 lines

How it starts

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

Skill: Write a Triton LayerNorm Kernel

Purpose

Guide the agent through implementing a correct, numerically stable row-wise layer normalization kernel in Triton. This covers mean and variance computation with fp32 accumulation, epsilon handling, affine transform with gamma/beta, the RMSNorm variant, masking for hidden dimensions not divisible by BLOCK_SIZE, and pointer arithmetic for 1D affine parameters applied to 2D or higher-rank inputs.


Use this when

  • You need a fused forward LayerNorm that avoids separate mean, variance, normalize, and scale passes — i.e., a single kernel reading each row once (or twice for a two-pass approach).
  • You need an RMSNorm variant (no mean subtraction, only RMS scaling) that is not available in your framework's kernel library.
  • You need a custom LayerNorm that fuses a downstream or upstream operation (e.g., fusing the residual add into the LayerNorm input).
  • You require the backward pass and intend to write a custom autograd function — knowing how the forward is structured is a prerequisite.
  • torch.nn.LayerNorm with torch.compile is not achieving the expected fusion or is producing numerical issues you need to diagnose.

Do not use this when

  • The normalized shape maps to a standard torch.nn.LayerNorm call and no fusion is needed. torch.compile will fuse the LayerNorm efficiently.
  • The hidden dimension is very small (< 64). Warp-level reductions in CUDA (via vendor libraries) are more efficient at this size.
  • You need training with a custom backward pass for a non-standard normalization variant. Prefer implementing the full custom kernel with saved statistics before committing to a Triton forward-only version.
  • The normalization is over a non-contiguous dimension. This skill covers row-wise normalization (last dimension). Normalizing over other axes requires a different decomposition.

Inputs the agent should gather first

Before writing any code, confirm:

  1. Input shape — (N, H) for 2D, or (B, T, H) for sequence inputs. Which dimension is normalized? (Assume last dimension H unless stated otherwise.)
  2. Hidden dimension H — fixed or dynamic? Is H a power of 2? Is H always divisible by BLOCK_SIZE?
  3. Input dtype — fp16, bf16, or fp32. Accumulation for mean and variance must be fp32.
  4. Affine transform — does the kernel apply learned gamma and beta parameters? Are they 1D tensors of shape (H,)?
  5. RMSNorm vs LayerNorm — LayerNorm subtracts mean and divides by std; RMSNorm skips mean subtraction and uses RMS of activations.
  6. Epsilon value — typically 1e-5 or 1e-6. Confirm whether it is added inside or outside the square root (both are used in practice — they differ numerically).
  7. Forward-only or training — if training, the mean and inverse-std (rstd) must be saved for the backward pass.
  8. Residual fusion — is there a residual to add before normalization (pre-norm pattern)?

Read the full file on GitHub · 160 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. 8d ago First seen · 160 lines · 0 tokens per session scan A 2444ec23f016

Subscribe to this mod's changes

write-triton-layernorm-kernel is a skill published in the GitHub repository tensormux/kernel-skills (74 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 3,009 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

fba-simulator

Run Flux Balance Analysis (FBA) and related constraint-based simulations using COBRApy. Covers standard FBA, parsimonious FBA (pFBA), Flux Variability Analysis (FVA), loopless FBA, gene/reaction knockouts, and carbon source swapping. Outputs flux distributions and CSV files.

aiming-lab/AutoResearchClaw · 69 tokens

flux-analyzer

Analyse FBA flux distributions to extract biological insights. Covers gene essentiality, phenotypic phase planes, flux sampling, pathway-level aggregation, secretion product prediction, and production of publication- quality figures.

aiming-lab/AutoResearchClaw · 44 tokens

gsmm-validator

Validate a COBRApy genome-scale metabolic model for mass/charge balance, stoichiometric consistency, biomass producibility, dead-end metabolites, thermodynamic loops, and GPR rule formatting. Outputs a structured validation report with errors and warnings.

aiming-lab/AutoResearchClaw · 52 tokens

gsmm-builder

Build or load a genome-scale metabolic model (GSMM) using COBRApy. Covers loading from BIGG, constructing minimal models from scratch, setting medium constraints, and exporting validated .json model files.

aiming-lab/AutoResearchClaw · 45 tokens

stat-result-validator

Validate statistical research outputs for formulation quality, method-to- problem alignment, theory presence, experimental evidence, fair comparison, artifact completeness, and final-claim consistency.

aiming-lab/AutoResearchClaw · 36 tokens

statistical-problem-formulation

Formulate statistical research problems with formal notation, target parameters, assumptions, hypotheses, evaluation criteria, and theory targets.

aiming-lab/AutoResearchClaw · 30 tokens