MCPcopy Create free account
hub / github.com/huggingface/diffusers / GlobalResponseNorm

Class GlobalResponseNorm

src/diffusers/models/unets/unet_stable_cascade.py:81–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80# from https://github.com/facebookresearch/ConvNeXt-V2/blob/3608f67cc1dae164790c5d0aead7bf2d73d9719b/models/utils.py#L105
81class GlobalResponseNorm(nn.Module):
82 def __init__(self, dim):
83 super().__init__()
84 self.gamma = nn.Parameter(torch.zeros(1, 1, 1, dim))
85 self.beta = nn.Parameter(torch.zeros(1, 1, 1, dim))
86
87 def forward(self, x):
88 agg_norm = torch.norm(x, p=2, dim=(1, 2), keepdim=True)
89 stand_div_norm = agg_norm / (agg_norm.mean(dim=-1, keepdim=True) + 1e-6)
90 return self.gamma * (x * stand_div_norm) + self.beta + x
91
92
93class SDCascadeAttnBlock(nn.Module):

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…