MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / attention

Method attention

sat/sgm/modules/diffusionmodules/model.py:155–166  ·  view source on GitHub ↗
(self, h_: torch.Tensor)

Source from the content-addressed store, hash-verified

153 self.proj_out = torch.nn.Conv2d(in_channels, in_channels, kernel_size=1, stride=1, padding=0)
154
155 def attention(self, h_: torch.Tensor) -> torch.Tensor:
156 h_ = self.norm(h_)
157 q = self.q(h_)
158 k = self.k(h_)
159 v = self.v(h_)
160
161 b, c, h, w = q.shape
162 q, k, v = map(lambda x: rearrange(x, "b c h w -> b 1 (h w) c").contiguous(), (q, k, v))
163 h_ = torch.nn.functional.scaled_dot_product_attention(q, k, v) # scale is dim ** -0.5 per default
164 # compute attention
165
166 return rearrange(h_, "b 1 (h w) c -> b c h w", h=h, w=w, c=c, b=b)
167
168 def forward(self, x, **kwargs):
169 h_ = x

Callers 12

forwardMethod · 0.95
layer_forward_defaultFunction · 0.45
layer_forwardMethod · 0.45
layer_forwardMethod · 0.45
layer_forwardMethod · 0.45
layer_forwardMethod · 0.45
layer_forwardMethod · 0.45
layer_forwardMethod · 0.45
forwardMethod · 0.45
_forwardMethod · 0.45
forwardMethod · 0.45
forwardMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected