MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / forward

Method forward

src/diffusers/models/unets/unet_3d_blocks.py:1504–1569  ·  view source on GitHub ↗
(
        self,
        hidden_states: torch.FloatTensor,
        res_hidden_states_tuple: Tuple[torch.FloatTensor, ...],
        temb: Optional[torch.FloatTensor] = None,
        upsample_size=None,
        scale: float = 1.0,
        num_frames: int = 1,
    )

Source from the content-addressed store, hash-verified

1502 self.resolution_idx = resolution_idx
1503
1504 def forward(
1505 self,
1506 hidden_states: torch.FloatTensor,
1507 res_hidden_states_tuple: Tuple[torch.FloatTensor, ...],
1508 temb: Optional[torch.FloatTensor] = None,
1509 upsample_size=None,
1510 scale: float = 1.0,
1511 num_frames: int = 1,
1512 ) -> torch.FloatTensor:
1513 is_freeu_enabled = (
1514 getattr(self, "s1", None)
1515 and getattr(self, "s2", None)
1516 and getattr(self, "b1", None)
1517 and getattr(self, "b2", None)
1518 )
1519
1520 blocks = zip(self.resnets, self.motion_modules)
1521
1522 for resnet, motion_module in blocks:
1523 # pop res hidden states
1524 res_hidden_states = res_hidden_states_tuple[-1]
1525 res_hidden_states_tuple = res_hidden_states_tuple[:-1]
1526
1527 # FreeU: Only operate on the first two stages
1528 if is_freeu_enabled:
1529 hidden_states, res_hidden_states = apply_freeu(
1530 self.resolution_idx,
1531 hidden_states,
1532 res_hidden_states,
1533 s1=self.s1,
1534 s2=self.s2,
1535 b1=self.b1,
1536 b2=self.b2,
1537 )
1538
1539 hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1)
1540
1541 if self.training and self.gradient_checkpointing:
1542
1543 def create_custom_forward(module):
1544 def custom_forward(*inputs):
1545 return module(*inputs)
1546
1547 return custom_forward
1548
1549 if is_torch_version(">=", "1.11.0"):
1550 hidden_states = torch.utils.checkpoint.checkpoint(
1551 create_custom_forward(resnet),
1552 hidden_states,
1553 temb,
1554 use_reentrant=False,
1555 )
1556 else:
1557 hidden_states = torch.utils.checkpoint.checkpoint(
1558 create_custom_forward(resnet), hidden_states, temb
1559 )
1560
1561 else:

Callers

nothing calls this directly

Calls 2

apply_freeuFunction · 0.85
is_torch_versionFunction · 0.85

Tested by

no test coverage detected