CoolFace
Modelpublic

Nathan9/xcodec_mini_infer

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
norm.py29 linesDownload Raw Back to modules
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the license found in the5# LICENSE file in the root directory of this source tree.6 7"""Normalization modules."""8 9import typing as tp10 11import einops12import torch13from torch import nn14 15 16class ConvLayerNorm(nn.LayerNorm):17    """18    Convolution-friendly LayerNorm that moves channels to last dimensions19    before running the normalization and moves them back to original position right after.20    """21    def __init__(self, normalized_shape: tp.Union[int, tp.List[int], torch.Size], **kwargs):22        super().__init__(normalized_shape, **kwargs)23 24    def forward(self, x):25        x = einops.rearrange(x, 'b ... t -> b t ...')26        x = super().forward(x)27        x = einops.rearrange(x, 'b t ... -> b ... t')28        return29