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

Method forward

src/diffusers/models/unets/unet_2d_blocks.py:1082–1111  ·  view source on GitHub ↗
(
        self,
        hidden_states: torch.FloatTensor,
        temb: Optional[torch.FloatTensor] = None,
    )

Source from the content-addressed store, hash-verified

1080 self.gradient_checkpointing = False
1081
1082 def forward(
1083 self,
1084 hidden_states: torch.FloatTensor,
1085 temb: Optional[torch.FloatTensor] = None,
1086 ) -> torch.FloatTensor:
1087 lora_scale = 1.0
1088 hidden_states = self.resnets[0](hidden_states, temb, scale=lora_scale)
1089 for resnet in self.resnets[1:]:
1090 if self.training and self.gradient_checkpointing:
1091
1092 def create_custom_forward(module, return_dict=None):
1093 def custom_forward(*inputs):
1094 if return_dict is not None:
1095 return module(*inputs, return_dict=return_dict)
1096 else:
1097 return module(*inputs)
1098
1099 return custom_forward
1100
1101 ckpt_kwargs: Dict[str, Any] = {"use_reentrant": False} if is_torch_version(">=", "1.11.0") else {}
1102 hidden_states = torch.utils.checkpoint.checkpoint(
1103 create_custom_forward(resnet),
1104 hidden_states,
1105 temb,
1106 **ckpt_kwargs,
1107 )
1108 else:
1109 hidden_states = resnet(hidden_states, temb, scale=lora_scale)
1110
1111 return hidden_states
1112
1113
1114class AttnDownBlock2D(nn.Module):

Callers

nothing calls this directly

Calls 1

is_torch_versionFunction · 0.85

Tested by

no test coverage detected