Python wrappers
Public Python APIs implemented by this engine symbols.Autograd node for Group Normalization.
Computes per-(batch, group) mean and reciprocal standard
deviation over the channels-in-group () plus all spatial axes,
then normalises and applies a per-channel (not per-group) affine
. The saved
statistics are required by the backward closed-form;
spatial_dims_ retains the per-axis spatial sizes so the
backward can recompute the reduction count.
Inherits FuncOp<GroupNormBackward, 3> with three saved-input
slots — x, gamma, and beta.
Math
Let denote the group containing channel (so
) and write
. For each (b, g) pair:
Mean and variance use the biased estimator.
References
Wu & He, "Group Normalization" (ECCV 2018, arXiv:1803.08494).
Attributes
schema_v1OpSchemaname="group_norm", version=1, amp_policy=ForceFP32, produces_grad=true).saved_mean_Storage(batch, group) mean , shape (B*G,).saved_rstd_Storage(batch, group) reciprocal standard deviation , shape (B*G,).B_, C_, G_intx.shape().spatial_dims_std::vector<int>[S_0, S_1, ...] retained so the backward can recompute the spatial reduction count.Notes
Thread safety: instances are created once during forward and consumed once during backward — no concurrent access expected.
Static methods
1forward
→TensorImplPtrint forward(const int & x, const int & gamma, const int & beta, int num_groups, double eps)Run the forward pass.
Computes per-(batch, group) statistics, normalises x,
applies the per-channel affine, caches saved_mean_ and
saved_rstd_, and (when grad mode is on) registers this
as the grad_fn of the returned output.
Parameters
xTensorImplPtr(B, C, S_0, ...). Rank must be >= 2.gammaTensorImplPtr(C,).betaTensorImplPtr(C,).num_groupsintG; must divide C evenly.epsdoubleReturns
TensorImplPtrNormalised output, same shape as x.
Raises
ShapeMismatchC is not divisible by num_groups or if gamma and beta do not have shape (C,).Methods
1Compute gradients for the three saved inputs.
Returns {dx, d_gamma, d_beta} in the saved-input order using
the cached statistics. Closed-form summary (per channel ):
and the input gradient follows the standard GN backward formula
restricted to each (b, g) group.
Parameters
grad_outStorageReturns
std::vector<Storage>Three-element vector {dx, d_gamma, d_beta}.