Normalization Operators¶
Every op on this page is used the same way: construct it once, then call it. The
constructor takes what the kernel is compiled with; the call takes the tensors.
Both are documented under each op — __init__ and forward, where forward is
what runs when you call op(...).
Layer norm¶
tileops.ops.norm.layer_norm.LayerNormFwdOp
¶
Layer Normalization operator.
Computes layer normalization over the trailing normalized_shape
axes:
Mirrors torch.nn.functional.layer_norm. normalized_shape
is the only entry point (the manifest spec).
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
normalized_shape(Sequence[int]) –Trailing-axis shape tuple over which the reduction runs (manifest
params.normalized_shape). -
eps(Optional[float], default:DEFAULT_EPS) –Epsilon for numerical stability (manifest
params.eps).Noneuses the PyTorch default1e-5. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply layer normalization.
Parameters:
-
x(Tensor) –Input tensor with trailing shape equal to
normalized_shape. -
weight(Tensor) –Affine scale of shape
normalized_shape. -
bias(Tensor) –Affine shift of shape
normalized_shape.
Returns:
-
Tensor–Normalized tensor of the same shape as x.
Raises:
-
ValueError–Dtypes or devices disagree, or shapes are incompatible with the configured
normalized_shape. Raised from inside the operator, by_eager_forward.
tileops.ops.norm.fused_add_layer_norm.FusedAddLayerNormFwdOp
¶
Fused residual addition and Layer Normalization operator.
Computes the residual sum followed by layer normalization in a single fused kernel:
Returns dual outputs (y, residual_out) so downstream residual connections can
reuse the pre-norm sum without recomputation.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
Note
Supports arbitrary leading dimensions (3-D+) via flatten/unflatten. Handles non-contiguous inputs and non-power-of-two hidden dims by padding to 256-element alignment.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
eps(float, default:1e-05) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply fused residual addition and normalization.
Parameters:
-
x(Tensor) –Input tensor of shape
(*leading, N). -
residual(Tensor) –Residual tensor of the same shape as x.
-
weight(Tensor) –Affine scale of shape \([N]\).
-
bias(Tensor) –Affine shift of shape \([N]\).
Returns:
-
Tensor–(y, residual_out), where residual_out isx + residual, both of the -
Tensor–same shape as x.
Raises:
-
ValueError–Dtypes or shapes disagree. Raised from inside the operator, by
_eager_forward.
RMS norm¶
tileops.ops.norm.rms_norm.RMSNormFwdOp
¶
Standalone Root Mean Square (RMS) Norm operator.
Mirrors torch.nn.functional.rms_norm. Computes::
y = x * rsqrt(mean(x ** 2, trailing_axes) + eps) * weight
where the reduction runs over the trailing len(normalized_shape)
axes; normalized_shape is the only entry point (the manifest spec).
Example
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
normalized_shape(Sequence[int]) –Trailing-axis shape tuple over which the reduction runs (manifest
params.normalized_shape). -
eps(Optional[float], default:DEFAULT_EPS) –Epsilon for numerical stability (manifest
params.eps).Noneselects the same default the signature carries. Normalized here, so a backend is handed the number rather thanNone. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –Whether to autotune (default
False).
forward
¶
Apply RMS normalization over the trailing normalized_shape.
Parameters:
-
x(Tensor) –Input tensor whose trailing shape equals
normalized_shape. -
weight(Tensor) –Affine scale of shape
normalized_shape.
Returns:
-
Tensor–Normalized tensor of the same shape as x.
Raises:
-
ValueError–Dtypes or devices disagree, or shapes are incompatible with the configured
normalized_shape. Raised from inside the operator, by_eager_forward.
tileops.ops.norm.fused_add_rms_norm.FusedAddRMSNormFwdOp
¶
Fused residual addition and RMS Normalization operator.
Computes the residual sum followed by RMS normalization in a single fused kernel:
Returns dual outputs (y, residual_out) so downstream residual connections can
reuse the pre-norm sum without recomputation.
Supported dtypes
torch.float16, torch.bfloat16.
Note
Supports arbitrary leading dimensions (3-D+) via flatten/unflatten. Handles non-contiguous inputs and non-power-of-two hidden dims by padding to 256-element alignment.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
eps(float, default:1e-06) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply fused residual addition and normalization.
Parameters:
-
x(Tensor) –Input tensor of shape
(*leading, N). -
residual(Tensor) –Residual tensor of the same shape as x.
-
weight(Tensor) –Affine scale of shape \([N]\).
Returns:
-
Tensor–(y, residual_out), where residual_out isx + residual, both of the -
Tensor–same shape as x.
Raises:
-
ValueError–Dtypes or shapes disagree. Raised from inside the operator, by
_eager_forward.
Adaptive layer norm¶
tileops.ops.norm.ada_layer_norm.AdaLayerNormFwdOp
¶
Adaptive Layer Normalization (AdaLN) operator.
Applies layer normalization with per-token adaptive scale and shift:
where s (scale) and d (shift) are per-token tensors of shape
(M, N), pre-computed by the caller from a conditioning signal.
Linear projection from the conditioning input to scale/shift is the
caller's responsibility.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
Note
Supports arbitrary leading dimensions (3-D+) via flatten/unflatten. Handles non-contiguous inputs and non-power-of-two hidden dims.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
eps(float, default:1e-05) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply adaptive layer normalization.
Parameters:
-
x(Tensor) –Tensor of shape
(*leading, N). -
scale(Tensor) –Tensor of shape
(*leading, N). -
shift(Tensor) –Tensor of shape
(*leading, N).
Returns:
-
Tensor–Tensor of the same shape as x.
Raises:
-
ValueError–Dtypes or shapes disagree. Raised from inside the operator, by
_eager_forward.
tileops.ops.norm.ada_layer_norm_zero.AdaLayerNormZeroFwdOp
¶
Adaptive Layer Normalization-Zero (AdaLN-Zero) operator.
Applies layer normalization with per-token adaptive scale, shift, and gating:
where s (scale), d (shift), and g (gate) are per-token tensors of shape \([M \times N]\), pre-computed by the caller from a conditioning signal. Linear projection from the conditioning input to scale/shift/gate is the caller's responsibility.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
Note
Supports arbitrary leading dimensions (3-D+) via flatten/unflatten. Handles non-contiguous inputs and non-power-of-two hidden dims.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
eps(float, default:1e-05) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply adaptive layer normalization with zero-init gating.
Parameters:
-
x(Tensor) –Tensor of shape
(*leading, N). -
scale(Tensor) –Tensor of shape
(*leading, N). -
shift(Tensor) –Tensor of shape
(*leading, N). -
gate(Tensor) –Tensor of shape
(*leading, N).
Returns:
-
Tensor–Tensor of the same shape as x.
Raises:
-
ValueError–Dtypes or shapes disagree. Raised from inside the operator, by
_eager_forward.
Batch norm¶
tileops.ops.norm.batch_norm.BatchNormFwdOp
¶
Batch Normalization forward operator (training and inference).
Computes batch normalization over the channel dimension:
where the mean and variance are computed per channel over (N, *spatial)
elements.
Mirrors torch.nn.functional.batch_norm: forward accepts
(input, running_mean, running_var, weight, bias) in PyTorch's
positional order and returns only the normalized output. Internal
mean/rstd computed in training mode stay private; callers needing them
for the backward pass recompute on the original input.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
training(bool, default:False) –Whether the batch statistics come from this call's input, which is also what decides whether the running statistics are written (manifest
params.training). -
momentum(float, default:0.1) –Running-stat update momentum (used in training mode).
-
eps(float, default:1e-05) –Epsilon for numerical stability.
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Run batch normalization forward pass.
The training mode is bound at ctor time. Construct a separate
op instance to switch between training and inference.
Parameters:
-
x(Tensor) –Input tensor of shape
(N, C, *spatial)on CUDA. -
running_mean(Tensor) –Running mean of shape \([C]\) on the same CUDA device as
x, with dtypetorch.float32. Updated in-place during training. -
running_var(Tensor) –Running variance of shape \([C]\) on the same CUDA device as
x, with dtypetorch.float32. Updated in-place during training. -
weight(Tensor) –Affine scale (gamma) of shape \([C]\) on the same CUDA device as
x. -
bias(Tensor) –Affine shift (beta) of shape \([C]\) on the same CUDA device as
x.
Returns:
-
Tensor–Normalized output tensor with the same shape as
x.
tileops.ops.norm.batch_norm.BatchNormBwdOp
¶
Batch Normalization backward operator.
Computes gradients with respect to input, scale, and shift for batch normalization.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Run batch normalization backward pass.
All inputs must reside on the same CUDA device.
Parameters:
-
grad_out(Tensor) –Upstream gradient of shape
(N, C, *spatial). -
x(Tensor) –Original input tensor of shape
(N, C, *spatial). -
weight(Tensor) –Affine scale (gamma) of shape \([C]\) on the same CUDA device as
x. Internally cast totorch.float32for the backward kernel. -
mean(Tensor) –Per-channel batch mean from the forward pass, shape
(C,). Expected astorch.float32. -
rstd(Tensor) –Per-channel reciprocal std from the forward pass, shape \([C]\). Expected as
torch.float32.
Returns:
-
Tensor–Tuple of
(grad_x, grad_weight, grad_bias)wheregrad_x -
Tensor–has the same shape as
x,grad_weighthas shape \([C]\), -
Tensor–and
grad_biashas shape \([C]\).
Group and instance norm¶
tileops.ops.norm.group_norm.GroupNormFwdOp
¶
Group Normalization forward operator.
Computes group normalization over (C/num_groups, *spatial) slices:
where the mean and variance are computed per group over
(C/num_groups, *spatial) elements.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
Note
Supports arbitrary spatial dimensions (1-D, 2-D, 3-D+).
Handles non-contiguous inputs via explicit contiguous() call.
The per-channel affine is applied inside the kernel, so the op does
no post-kernel arithmetic.
weight and bias are one switch: pass both for the affine form,
pass neither for torch.nn.GroupNorm(affine=False). Passing one alone
is an error — the manifest states the same in shape_rules.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
num_groups(int) –Number of groups (manifest
params.num_groups). Must divide C evenly. -
eps(float, default:1e-05) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply group normalization.
Parameters:
-
x(Tensor) –Input tensor of shape
(N, C, *spatial). -
weight(Optional[Tensor], default:None) –Affine scale of shape \([C]\), or
None. -
bias(Optional[Tensor], default:None) –Affine shift of shape \([C]\), or
None.weightandbiasare one switch: give both or neither.
Returns:
-
Tensor–Normalized tensor of the same shape as x.
Raises:
-
ValueError–Only one of
weight/biasis given, dtypes disagree, or a shape is incompatible with x. Raised from inside the operator, by_eager_forward.
tileops.ops.norm.instance_norm.InstanceNormFwdOp
¶
Instance Normalization forward operator.
Computes instance normalization over spatial dimensions for each
(batch, channel) independently:
where the mean and variance are computed over *spatial for each
sample-channel pair, and the trailing affine applies only when weight
and bias are passed. Equivalent to Group Normalization with
num_groups = C.
Supported dtypes
torch.float32, torch.float16, torch.bfloat16.
Note
Supports arbitrary spatial dimensions (1-D, 2-D, 3-D+). The affine
call delegates to GroupNormKernel with one group per channel,
which applies the per-channel affine itself; without affine it
delegates to InstanceNormNoAffineKernel.
__init__
¶
__init__(
use_input_stats=True,
momentum=0.1,
eps=1e-05,
*,
target=None,
kernel_map=None,
tune=False
)
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
use_input_stats(bool, default:True) –Mirrors
torch.nn.functional.instance_norm. WhenTrue(the default), per-instance statistics are computed from the input.Falsenormalizes by the passed running stats, and is implemented for the affine-free call only. -
momentum(float, default:0.1) –Mirrors
torch.nn.functional.instance_norm. Stored on the op instance for API parity with PyTorch but unused: neither path updates the running stats. -
eps(float, default:1e-05) –Epsilon for numerical stability (manifest
params.eps). -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device. -
kernel_map(Optional[Dict[str, Kernel]], default:None) –Optional kernel override dictionary.
-
tune(bool, default:False) –If
True, autotune tile configurations.
forward
¶
Apply instance normalization.
Parameters:
-
x(Tensor) –Input tensor of shape
(N, C, *spatial). -
running_mean(Optional[Tensor], default:None) –Per-channel running mean of shape \([C]\), dtype
torch.float32, onx's device. Required whenuse_input_stats=False. -
running_var(Optional[Tensor], default:None) –Per-channel running variance, same constraints.
-
weight(Optional[Tensor], default:None) –Affine scale of shape \([C]\),
x's dtype. Must be passed together withbias. -
bias(Optional[Tensor], default:None) –Affine shift, same constraints as
weight.
Returns:
-
Tensor–Normalized tensor of the same shape as x.
Raises:
-
ValueError–A dtype mismatches, a shape is incompatible, one half of a pair is passed, or
use_input_stats=Falsewithout running stats. -
NotImplementedError–use_input_stats=Falsecombined with the affine tensors. Both raised from inside the operator, by_eager_forward.