CoolFace
Apppublic

souging/TRELLIS_TextTo3D

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
norm.py25 linesDownload Raw Back to modules
1import torch2import torch.nn as nn3 4 5class LayerNorm32(nn.LayerNorm):6    def forward(self, x: torch.Tensor) -> torch.Tensor:7        return super().forward(x.float()).type(x.dtype)8    9 10class GroupNorm32(nn.GroupNorm):11    """12    A GroupNorm layer that converts to float32 before the forward pass.13    """14    def forward(self, x: torch.Tensor) -> torch.Tensor:15        return super().forward(x.float()).type(x.dtype)16    17    18class ChannelLayerNorm32(LayerNorm32):19    def forward(self, x: torch.Tensor) -> torch.Tensor:20        DIM = x.dim()21        x = x.permute(0, *range(2, DIM), 1).contiguous()22        x = super().forward(x)23        x = x.permute(0, DIM-1, *range(1, DIM-1)).contiguous()24        return x25