Skip to main content

torchnorm

Fused Triton kernels for normalisation layers. Drop-in replacements for PyTorch's norm modules with automatic dispatch to optimised CUDA kernels when triton is available.

Installation

pip install torchnorm            # PyTorch fallback only
pip install "torchnorm[triton]"  # with Triton fused kernels

From source:

git clone https://github.com/liodon-ai/torchnorm
cd torchnorm
pip install -e ".[triton]"

Modules

RMSNorm

Root Mean Square Layer Normalisation (Zhang & Sennrich, 2019). Used in LLaMA, Mistral, Gemma, Qwen, Falcon, and most modern LLMs.

from torchnorm import RMSNorm

norm = RMSNorm(dim=4096).cuda()
x = torch.randn(4, 512, 4096, device="cuda", dtype=torch.float16)
out = norm(x)  # fused Triton kernel on CUDA, PyTorch fallback elsewhere

The fused kernel reads each element once, computes the RMS, and applies the weight in a single pass — no intermediate allocation.

FusedAddRMSNorm

Fuses the residual add and RMSNorm into one kernel. Canonical pattern in transformer pre-norm blocks:

from torchnorm import FusedAddRMSNorm

norm = FusedAddRMSNorm(dim=4096).cuda()

# Instead of:
#   residual = x + residual
#   hidden   = rms_norm(residual)

# Write:
hidden, residual = norm(x, residual)

Returns both the normalised output and the updated residual so the next block can use it directly.

LayerNorm

Layer Normalisation (Ba et al., 2016). Identical interface to torch.nn.LayerNorm.

from torchnorm import LayerNorm

norm = LayerNorm(768, bias=False).cuda()   # BERT-style, no bias
out  = norm(x)

GroupNorm

Group Normalisation (Wu & He, 2018). Standard for diffusion UNets and CNNs.

from torchnorm import GroupNorm

norm = GroupNorm(num_groups=32, num_channels=512).cuda()
out  = norm(x)   # x: (N, C, H, W)

InstanceNorm

Instance Normalisation (Ulyanov et al., 2016). Normalises each sample–channel pair over spatial dims. Standard in style transfer.

from torchnorm import InstanceNorm

norm = InstanceNorm(num_features=512, affine=True).cuda()
out  = norm(x)   # x: (N, C, H, W) or (N, C)

ScaleNorm

ScaleNorm (Nguyen & Salazar, 2019). L2-normalises and scales by a single learnable scalar. Cheaper than LayerNorm — no mean subtraction, no per-element parameters.

from torchnorm import ScaleNorm

norm = ScaleNorm(dim=512).cuda()
out  = norm(x)

Dispatch logic

Every module auto-selects the fastest available path:

Condition Path
CUDA tensor + triton installed Fused Triton kernel
CPU tensor or triton not installed PyTorch (F.rms_norm, F.layer_norm, …)

No flags to set. Installing triton is the only opt-in required.

Compatibility

Python ≥ 3.9
PyTorch ≥ 2.0
Triton ≥ 2.1 (optional)
CUDA any version supported by your PyTorch build
Project Focus Install
Liger Kernel Full training suite: RMSNorm + RoPE + SwiGLU + CrossEntropy + model patching pip install liger-kernel
flash-attn Flash Attention + fused ops including LayerNorm build from source
torchembed Companion library: RoPE (rotate-half & adjacent-pairs), ALiBi, patch, categorical embeddings pip install torchembed

torchnorm vs Liger Kernel: Liger patches entire model classes at import time — ideal when you want the full optimization suite with use_liger_kernel=True. torchnorm provides individual nn.Module drop-ins without model patching — useful when building custom architectures or when you only need the norm layers.

Part of the Liodon AI stack

  • torchembed — fused kernels for embedding layers (RoPE, patch, categorical)
  • torchnorm — fused kernels for normalisation layers

Metadata

Release files for torchnorm 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for torchnorm 0.1.2
File Interpreter ABI Platform Actions
torchnorm-0.1.2-py3-none-any.whl Python 3 none any Details for torchnorm-0.1.2-py3-none-any.whl

Release files / torchnorm-0.1.2-py3-none-any.whl

Download URL torchnorm-0.1.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bca26fec4d73eb2e86688ead1040d8d25a25b3744638248216799acbf3bed3c
BLAKE2b-256 checksum
How to use checksums
1a5dffc108d36a8ebd8d7a51ba325aad01cd0ba4b3cf79db4c9bb91ece62acf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for torchnorm 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page