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

Function usp_dit_forward

wan/distributed/xdit_context_parallel.py:99–181  ·  view source on GitHub ↗

x: A list of videos each with shape [C, T, H, W]. t: [B]. context: A list of text embeddings each with shape [L, C].

(
    self,
    x,
    t,
    context,
    seq_len,
    vace_context=None,
    vace_context_scale=1.0,
    clip_fea=None,
    y=None,
)

Source from the content-addressed store, hash-verified

97
98
99def usp_dit_forward(
100 self,
101 x,
102 t,
103 context,
104 seq_len,
105 vace_context=None,
106 vace_context_scale=1.0,
107 clip_fea=None,
108 y=None,
109):
110 """
111 x: A list of videos each with shape [C, T, H, W].
112 t: [B].
113 context: A list of text embeddings each with shape [L, C].
114 """
115 if self.model_type == 'i2v':
116 assert clip_fea is not None and y is not None
117 # params
118 device = self.patch_embedding.weight.device
119 if self.freqs.device != device:
120 self.freqs = self.freqs.to(device)
121
122 if self.model_type != 'vace' and y is not None:
123 x = [torch.cat([u, v], dim=0) for u, v in zip(x, y)]
124
125 # embeddings
126 x = [self.patch_embedding(u.unsqueeze(0)) for u in x]
127 grid_sizes = torch.stack(
128 [torch.tensor(u.shape[2:], dtype=torch.long) for u in x])
129 x = [u.flatten(2).transpose(1, 2) for u in x]
130 seq_lens = torch.tensor([u.size(1) for u in x], dtype=torch.long)
131 assert seq_lens.max() <= seq_len
132 x = torch.cat([
133 torch.cat([u, u.new_zeros(1, seq_len - u.size(1), u.size(2))], dim=1)
134 for u in x
135 ])
136
137 # time embeddings
138 with amp.autocast(dtype=torch.float32):
139 e = self.time_embedding(
140 sinusoidal_embedding_1d(self.freq_dim, t).float())
141 e0 = self.time_projection(e).unflatten(1, (6, self.dim))
142 assert e.dtype == torch.float32 and e0.dtype == torch.float32
143
144 # context
145 context_lens = None
146 context = self.text_embedding(
147 torch.stack([
148 torch.cat([u, u.new_zeros(self.text_len - u.size(0), u.size(1))])
149 for u in context
150 ]))
151
152 if self.model_type != 'vace' and clip_fea is not None:
153 context_clip = self.img_emb(clip_fea) # bs x 257 x dim
154 context = torch.concat([context_clip, context], dim=1)
155
156 # arguments

Callers

nothing calls this directly

Calls 2

sinusoidal_embedding_1dFunction · 0.50
unpatchifyMethod · 0.45

Tested by

no test coverage detected