Does group norm maintain an running average of mean and variance?

username: Sudarshan_VB
cooked: <p>Does group norm maintain an running average of mean and variance ?</p>

username: kevinj22
cooked: <p>Looking at the code here: <a href="https://pytorch.org/docs/stable/_modules/torch/nn/modules/normalization.html" rel="nofollow noopener">https://pytorch.org/docs/stable/_modules/torch/nn/modules/normalization.html</a></p>
<p>Neither group norm nor layer norm seem to maintain running averages. The description of them suggests they might: <a href="https://pytorch.org/docs/stable/nn.html?highlight=group%20norm#torch.nn.GroupNorm" rel="nofollow noopener">https://pytorch.org/docs/stable/nn.html?highlight=group%20norm#torch.nn.GroupNorm</a></p>
<p>“this layer uses statistics computed from input data in both training and evaluation modes”</p>
<p>Whether or not they are supposed to I don’t know. I don’t see running averages in the tensorflow version of group norm either: <a href="https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/layers/python/layers/normalization.py" rel="nofollow noopener">https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/layers/python/layers/normalization.py</a> (group_norm)</p>
<p>Or layer norm for that matter:</p>
<p><a href="https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/layers/python/layers/layers.py" rel="nofollow noopener">https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/layers/python/layers/layers.py</a> (layer_norm)</p>
<p>As both compute the mean and std for the batch dim, i.e the mean’s shape is (N, 1) in layer norm, tracking a running average doesn’t make sense. Who is to say something similar will be at that exact position in your validation batch?</p>

username: Ardor-Wu
cooked: <p>I also found the doc confusing. How can I freeze running statistics temporality to use other data? Thank you!</p>

username: ignasa007
cooked: <blockquote>
<p>As both compute the mean and std for the batch dim, i.e the mean’s shape is (N, 1) in layer norm, tracking a running average doesn’t make sense. Who is to say something similar will be at that exact position in your validation batch?</p>
</blockquote>
<p>I don’t think this is a good explanation. Sure, for LayerNorm, the computed statistics are of the shape (N,), but they can be used as separate values for updating running statistics of shape (1,). InstanceNorm, for example, computes per-batch and per-channel statistics of shape (N, C). However, this isn’t directly used since, as you mentioned, it would NOT be invariant to batch permutations. Instead statistics of shape (C,) are maintained; see <a href="https://github.com/pytorch/pytorch/blob/134179474539648ba7dee1317959529fbd0e7f89/torch/nn/modules/batchnorm.py#L61" rel="noopener nofollow ugc">_NormBase</a> used by both, BatchNorm and InstanceNorm.</p>
<p>Similar argument holds for GroupNorm. For GroupNorm in particular, the authors explicitly discourage using running statistics; see Section 2 of the paper:</p>
<blockquote>
<p>The pre-computed statistics may also change when the target data distribution changes [45]. These issues lead to inconsistency at training, transferring, and testing time. In addition, as aforementioned, reducing the batch size can have dramatic impact on the estimated batch statistics.</p>
</blockquote>
<p>Similar remarks can also be found in Section 1 of LayerNorm paper. Perhaps, that is the reason running statistics are not computed for these two methods.</p>