multimodalart HF Staff commited on
Commit
b1625c2
·
verified ·
1 Parent(s): a0b973f

Upload diffcve/modules/vae_blocks.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. diffcve/modules/vae_blocks.py +12 -3
diffcve/modules/vae_blocks.py CHANGED
@@ -233,9 +233,18 @@ class MemoryEfficientAttnBlock(nn.Module):
233
  weights = torch.softmax(weights, dim=2)
234
  out = torch.bmm(weights, v)
235
  else:
236
- out = xformers.ops.memory_efficient_attention(
237
- q, k, v, attn_bias=None, scale=(int(c) ** (-0.5)), op=self.attention_op
238
- )
 
 
 
 
 
 
 
 
 
239
 
240
  h_ = (
241
  out.permute(0,2,1)
 
233
  weights = torch.softmax(weights, dim=2)
234
  out = torch.bmm(weights, v)
235
  else:
236
+ try:
237
+ out = xformers.ops.memory_efficient_attention(
238
+ q, k, v, attn_bias=None, scale=(int(c) ** (-0.5)), op=self.attention_op
239
+ )
240
+ except NotImplementedError:
241
+ # No xformers kernel for this shape on this GPU (e.g. the VAE
242
+ # mid-block's single 512-dim head on Blackwell, where the
243
+ # torch-backed FA2 path caps head_dim at 256). Fall back to the
244
+ # mathematically-identical dense attention.
245
+ weights = torch.bmm(q, k.transpose(1, 2)) * (int(c) ** -0.5)
246
+ weights = torch.softmax(weights, dim=2)
247
+ out = torch.bmm(weights, v)
248
 
249
  h_ = (
250
  out.permute(0,2,1)