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

Function rope_apply

wan/modules/multitalk_model.py:54–76  ·  view source on GitHub ↗
(x, grid_sizes, freqs)

Source from the content-addressed store, hash-verified

52
53@amp.autocast(enabled=False)
54def rope_apply(x, grid_sizes, freqs):
55 s, n, c = x.size(1), x.size(2), x.size(3) // 2
56
57 freqs = freqs.split([c - 2 * (c // 3), c // 3, c // 3], dim=1)
58
59 output = []
60 for i, (f, h, w) in enumerate(grid_sizes.tolist()):
61 seq_len = f * h * w
62
63 x_i = torch.view_as_complex(x[i, :s].to(torch.float64).reshape(
64 s, n, -1, 2))
65 freqs_i = torch.cat([
66 freqs[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
67 freqs[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),
68 freqs[2][:w].view(1, 1, w, -1).expand(f, h, w, -1)
69 ],
70 dim=-1).reshape(seq_len, 1, -1)
71 freqs_i = freqs_i.to(device=x_i.device)
72 x_i = torch.view_as_real(x_i * freqs_i).flatten(2)
73 x_i = torch.cat([x_i, x[i, seq_len:]])
74
75 output.append(x_i)
76 return torch.stack(output).float()
77
78
79class WanRMSNorm(nn.Module):

Callers 1

forwardMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected