MCPcopy Create free account
hub / github.com/MeiGen-AI/MultiTalk / rope_apply

Function rope_apply

wan/modules/model.py:43–70  ·  view source on GitHub ↗
(x, grid_sizes, freqs)

Source from the content-addressed store, hash-verified

41
42@amp.autocast(enabled=False)
43def rope_apply(x, grid_sizes, freqs):
44 n, c = x.size(2), x.size(3) // 2
45
46 # split freqs
47 freqs = freqs.split([c - 2 * (c // 3), c // 3, c // 3], dim=1)
48
49 # loop over samples
50 output = []
51 for i, (f, h, w) in enumerate(grid_sizes.tolist()):
52 seq_len = f * h * w
53
54 # precompute multipliers
55 x_i = torch.view_as_complex(x[i, :seq_len].to(torch.float64).reshape(
56 seq_len, n, -1, 2))
57 freqs_i = torch.cat([
58 freqs[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
59 freqs[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),
60 freqs[2][:w].view(1, 1, w, -1).expand(f, h, w, -1)
61 ],
62 dim=-1).reshape(seq_len, 1, -1)
63
64 # apply rotary embedding
65 x_i = torch.view_as_real(x_i * freqs_i).flatten(2)
66 x_i = torch.cat([x_i, x[i, seq_len:]])
67
68 # append to collection
69 output.append(x_i)
70 return torch.stack(output).float()
71
72
73class WanRMSNorm(nn.Module):

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected