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

Method forward

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

Source from the content-addressed store, hash-verified

1002 self.gradient_checkpointing = False
1003
1004 def forward(
1005 self,
1006 hidden_states: torch.FloatTensor,
1007 temb: Optional[torch.FloatTensor] = None,
1008 scale: float = 1.0,
1009 num_frames: int = 1,
1010 ) -> Union[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]:
1011 output_states = ()
1012
1013 blocks = zip(self.resnets, self.motion_modules)
1014 for resnet, motion_module in blocks:
1015 if self.training and self.gradient_checkpointing:
1016
1017 def create_custom_forward(module):
1018 def custom_forward(*inputs):
1019 return module(*inputs)
1020
1021 return custom_forward
1022
1023 if is_torch_version(">=", "1.11.0"):
1024 hidden_states = torch.utils.checkpoint.checkpoint(
1025 create_custom_forward(resnet),
1026 hidden_states,
1027 temb,
1028 use_reentrant=False,
1029 )
1030 else:
1031 hidden_states = torch.utils.checkpoint.checkpoint(
1032 create_custom_forward(resnet), hidden_states, temb, scale
1033 )
1034
1035 else:
1036 hidden_states = resnet(hidden_states, temb, scale=scale)
1037 hidden_states = motion_module(hidden_states, num_frames=num_frames)[0]
1038
1039 output_states = output_states + (hidden_states,)
1040
1041 if self.downsamplers is not None:
1042 for downsampler in self.downsamplers:
1043 hidden_states = downsampler(hidden_states, scale=scale)
1044
1045 output_states = output_states + (hidden_states,)
1046
1047 return hidden_states, output_states
1048
1049
1050class CrossAttnDownBlockMotion(nn.Module):

Callers

nothing calls this directly

Calls 1

is_torch_versionFunction · 0.85

Tested by

no test coverage detected