Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion models/latte.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def forward(self, x):
x = (attn @ v).transpose(1, 2).reshape(B, N, C)

else:
raise NotImplemented
raise NotImplementedError

x = self.proj(x)
x = self.proj_drop(x)
Expand Down Expand Up @@ -369,6 +369,8 @@ def forward(self,

if self.extras == 2:
c = timestep_spatial + y_spatial
elif self.extras == 78:
c = timestep_spatial + text_embedding_spatial
else:
c = timestep_spatial
x = self.final_layer(x, c)
Expand Down
8 changes: 6 additions & 2 deletions models/latte_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def forward(self, x):
q, k, v = qkv.unbind(0) # make torchscript happy (cannot use tensor as tuple)

if self.attention_mode == 'xformers': # cause loss nan while using with amp
x = xformers.ops.memory_efficient_attention(q, k, v).reshape(B, N, C)
# https://github.com/facebookresearch/xformers/blob/e8bd8f932c2f48e3a3171d06749eecbbf1de420c/xformers/ops/fmha/__init__.py#L135
q_xf = q.transpose(1,2).contiguous()
k_xf = k.transpose(1,2).contiguous()
v_xf = v.transpose(1,2).contiguous()
x = xformers.ops.memory_efficient_attention(q_xf, k_xf, v_xf).reshape(B, N, C)

elif self.attention_mode == 'flash':
# cause loss nan while using with amp
Expand All @@ -73,7 +77,7 @@ def forward(self, x):
x = (attn @ v).transpose(1, 2).reshape(B, N, C)

else:
raise NotImplemented
raise NotImplementedError

x = self.proj(x)
x = self.proj_drop(x)
Expand Down