mmpretrain icon indicating copy to clipboard operation
mmpretrain copied to clipboard

[Performance] Speed of different LayerNorm2d implementations

Open mzr1996 opened this issue 1 year ago • 1 comments

In MMCLS, we use permute + F.layer_norm to implement LayerNorm2d. https://github.com/open-mmlab/mmclassification/blob/d2e505415040bf5329ab218bb6fe3d899f176cd5/mmcls/models/backbones/convnext.py#L35-L40 However, in ConvNeXt official repo, they use a more intuitional implementation.

        elif self.data_format == "channels_first":
            u = x.mean(1, keepdim=True)
            s = (x - u).pow(2).mean(1, keepdim=True)
            x = (x - u) / torch.sqrt(s + self.eps)
            x = self.weight[:, None, None] * x + self.bias[:, None, None]
            return x

We need a speed comparision between both implementations.

mzr1996 avatar Jul 26 '22 11:07 mzr1996

GropuNorm(num_group=1) also acts as LayerNorm2d, which is used in PoolFormer.

Ezra-Yu avatar Aug 01 '22 09:08 Ezra-Yu

@Ezra-Yu Interesting, Do we have the speed comparision between different implements yet?

chuong98 avatar Oct 11 '22 00:10 chuong98