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

Method forward

src/diffusers/models/autoencoders/vae.py:140–182  ·  view source on GitHub ↗

r"""The forward method of the `Encoder` class.

(self, sample: torch.FloatTensor)

Source from the content-addressed store, hash-verified

138 self.gradient_checkpointing = False
139
140 def forward(self, sample: torch.FloatTensor) -> torch.FloatTensor:
141 r"""The forward method of the `Encoder` class."""
142
143 sample = self.conv_in(sample)
144
145 if self.training and self.gradient_checkpointing:
146
147 def create_custom_forward(module):
148 def custom_forward(*inputs):
149 return module(*inputs)
150
151 return custom_forward
152
153 # down
154 if is_torch_version(">=", "1.11.0"):
155 for down_block in self.down_blocks:
156 sample = torch.utils.checkpoint.checkpoint(
157 create_custom_forward(down_block), sample, use_reentrant=False
158 )
159 # middle
160 sample = torch.utils.checkpoint.checkpoint(
161 create_custom_forward(self.mid_block), sample, use_reentrant=False
162 )
163 else:
164 for down_block in self.down_blocks:
165 sample = torch.utils.checkpoint.checkpoint(create_custom_forward(down_block), sample)
166 # middle
167 sample = torch.utils.checkpoint.checkpoint(create_custom_forward(self.mid_block), sample)
168
169 else:
170 # down
171 for down_block in self.down_blocks:
172 sample = down_block(sample)
173
174 # middle
175 sample = self.mid_block(sample)
176
177 # post-process
178 sample = self.conv_norm_out(sample)
179 sample = self.conv_act(sample)
180 sample = self.conv_out(sample)
181
182 return sample
183
184
185class Decoder(nn.Module):

Callers

nothing calls this directly

Calls 1

is_torch_versionFunction · 0.85

Tested by

no test coverage detected