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

Method __init__

sat/sgm/modules/autoencoding/magvit2_pytorch.py:333–364  ·  view source on GitHub ↗
(
        self,
        *,
        dim,
        dim_cond: Optional[int] = None,
        causal=False,
        dim_head=32,
        heads=8,
        flash=False,
        dropout=0.0,
        num_memory_kv=4,
    )

Source from the content-addressed store, hash-verified

331class Attention(Module):
332 @beartype
333 def __init__(
334 self,
335 *,
336 dim,
337 dim_cond: Optional[int] = None,
338 causal=False,
339 dim_head=32,
340 heads=8,
341 flash=False,
342 dropout=0.0,
343 num_memory_kv=4,
344 ):
345 super().__init__()
346 dim_inner = dim_head * heads
347
348 self.need_cond = exists(dim_cond)
349
350 if self.need_cond:
351 self.norm = AdaptiveRMSNorm(dim, dim_cond=dim_cond)
352 else:
353 self.norm = RMSNorm(dim)
354
355 self.to_qkv = nn.Sequential(
356 nn.Linear(dim, dim_inner * 3, bias=False), Rearrange("b n (qkv h d) -> qkv b h n d", qkv=3, h=heads)
357 )
358
359 assert num_memory_kv > 0
360 self.mem_kv = nn.Parameter(torch.randn(2, heads, num_memory_kv, dim_head))
361
362 self.attend = Attend(causal=causal, dropout=dropout, flash=flash)
363
364 self.to_out = nn.Sequential(Rearrange("b h n d -> b n (h d)"), nn.Linear(dim_inner, dim, bias=False))
365
366 @beartype
367 def forward(self, x, mask: Optional[Tensor] = None, cond: Optional[Tensor] = None):

Callers

nothing calls this directly

Calls 4

AdaptiveRMSNormClass · 0.85
existsFunction · 0.70
RMSNormClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected