Skip to content
class

GlobalResponseNormBackward

GlobalResponseNormBackward

Autograd node for Global Response Normalization (GRN), as used in ConvNeXt V2.

For 4-D input of shape (N, C, H, W), GRN first computes the per (n, c) L2 norm over the spatial axes, then normalises each channel's norm by the mean across channels, and finally applies a learned per-channel affine that modulates the input rather than replacing it:

Gn,c=∥xn,c,:,:∥2,Nn,c=Gn,c1C∑c′Gn,c′+ϵ G_{n,c} = \|x_{n,c,:,:}\|_2, \qquad N_{n,c} = \frac{G_{n,c}}{\frac{1}{C}\sum_{c'} G_{n,c'} + \epsilon} yn,c,h,w=γc (xn,c,h,w Nn,c)+βc+xn,c,h,w y_{n,c,h,w} = \gamma_c \,(x_{n,c,h,w}\,N_{n,c}) + \beta_c + x_{n,c,h,w}

(The trailing +x+ x residual matches the ConvNeXt-V2 paper; the affine is applied to the modulated signal rather than to x^\hat{x}.) saved_Nx_ stores NN broadcast to the per-spatial shape needed by the backward closed-form.

Inherits FuncOp<GlobalResponseNormBackward, 3> with three saved-input slots — x, gamma, and beta.

References

Woo et al., "ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders" (CVPR 2023, arXiv:2301.00808).

Attributes

schema_v1OpSchema
Registered schema (name="global_response_norm", version=1, amp_policy=ForceFP32, produces_grad=true).
eps_double
Numerical-stability constant in the per-channel normalisation denominator. Default: 1e-6.
saved_Nx_Storage
Normalised global response NN, shape (N, C, 1, 1).

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & x, const int & gamma, const int & beta, double eps)

Run the forward pass.

Computes the per (n, c) L2 spatial norm, normalises it by the per-image mean across channels, modulates x by the result, applies the per-channel affine + residual, caches saved_Nx_, and (when grad mode is on) registers this as the grad_fn of the returned output.

Parameters

xTensorImplPtr
4-D input tensor of shape (N, C, H, W).
gammaTensorImplPtr
Per-channel scale of shape (C,).
betaTensorImplPtr
Per-channel shift of shape (C,).
epsdouble
Numerical-stability constant in the cross-channel mean.

Returns

TensorImplPtr

Normalised output, same shape as x.

Methods

2
fn

apply

→std::vector<Storage>
int apply(int grad_out)

Compute gradients for the three saved inputs.

Returns {dx, d_gamma, d_beta} in the saved-input order using the cached saved_Nx_.

Parameters

grad_outStorage
Incoming gradient, same shape as the forward output.

Returns

std::vector<Storage>

Three-element vector {dx, d_gamma, d_beta}.

fn

release_own_saved

void release_own_saved()