(
self,
hidden_states,
encoder_hidden_states=None,
timestep=None,
attention_mask=None,
video_length=None,
self_attention_additional_feats=None,
mode=None,
reference=None,
)
| 382 | ) |
| 383 | |
| 384 | def forward( |
| 385 | self, |
| 386 | hidden_states, |
| 387 | encoder_hidden_states=None, |
| 388 | timestep=None, |
| 389 | attention_mask=None, |
| 390 | video_length=None, |
| 391 | self_attention_additional_feats=None, |
| 392 | mode=None, |
| 393 | reference=None, |
| 394 | ): |
| 395 | norm_hidden_states = ( |
| 396 | self.norm1(hidden_states, timestep) |
| 397 | if self.use_ada_layer_norm |
| 398 | else self.norm1(hidden_states) |
| 399 | ) |
| 400 | if(reference is None): |
| 401 | if self.name: |
| 402 | modify_norm_hidden_states = norm_hidden_states |
| 403 | if mode == "write": |
| 404 | self_attention_additional_feats[self.name]=norm_hidden_states |
| 405 | elif mode == "read" and self_attention_additional_feats: |
| 406 | ref_states = self_attention_additional_feats[self.name] |
| 407 | bank_fea = [ |
| 408 | rearrange( |
| 409 | ref_states.unsqueeze(1).repeat(1, video_length, 1, 1), |
| 410 | "b t l c -> (b t) l c", |
| 411 | ) |
| 412 | ] |
| 413 | modify_norm_hidden_states = torch.cat( |
| 414 | [norm_hidden_states] + bank_fea, dim=1 |
| 415 | ) |
| 416 | |
| 417 | if self.unet_use_cross_frame_attention: |
| 418 | hidden_states = ( |
| 419 | self.attn1( |
| 420 | norm_hidden_states, |
| 421 | attention_mask=attention_mask, |
| 422 | encoder_hidden_states=modify_norm_hidden_states, |
| 423 | video_length=video_length, |
| 424 | ) |
| 425 | + hidden_states |
| 426 | ) |
| 427 | else: |
| 428 | hidden_states = ( |
| 429 | self.attn1( |
| 430 | norm_hidden_states, |
| 431 | encoder_hidden_states=modify_norm_hidden_states, |
| 432 | attention_mask=attention_mask |
| 433 | ) |
| 434 | + hidden_states |
| 435 | ) |
| 436 | else: |
| 437 | if self.unet_use_cross_frame_attention: |
| 438 | hidden_states = ( |
| 439 | self.attn1( |
| 440 | norm_hidden_states, |
| 441 | attention_mask=attention_mask, |
nothing calls this directly
no outgoing calls
no test coverage detected