MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / my_forward

Function my_forward

diffusers/examples/community/fresco_v2v.py:300–637  ·  view source on GitHub ↗

Hacked pipe.unet.forward() copied from https://github.com/huggingface/diffusers/blob/v0.19.3/src/diffusers/models/unet_2d_condition.py#L700 if you are using a new version of diffusers, please copy the source code and modify it accordingly (find [HACK] in the code) * restore and retu

(
    self,
    steps=[],
    layers=[0, 1, 2, 3],
    flows=None,
    occs=None,
    correlation_matrix=[],
    intra_weight=1e2,
    iters=20,
    optimize_temporal=True,
    saliency=None,
)

Source from the content-addressed store, hash-verified

298
299
300def my_forward(
301 self,
302 steps=[],
303 layers=[0, 1, 2, 3],
304 flows=None,
305 occs=None,
306 correlation_matrix=[],
307 intra_weight=1e2,
308 iters=20,
309 optimize_temporal=True,
310 saliency=None,
311):
312 """
313 Hacked pipe.unet.forward()
314 copied from https://github.com/huggingface/diffusers/blob/v0.19.3/src/diffusers/models/unet_2d_condition.py#L700
315 if you are using a new version of diffusers, please copy the source code and modify it accordingly (find [HACK] in the code)
316 * restore and return the decoder features
317 * optimize the decoder features
318 * perform background smoothing
319 """
320
321 def forward(
322 sample: torch.FloatTensor,
323 timestep: Union[torch.Tensor, float, int],
324 encoder_hidden_states: torch.Tensor,
325 class_labels: Optional[torch.Tensor] = None,
326 timestep_cond: Optional[torch.Tensor] = None,
327 attention_mask: Optional[torch.Tensor] = None,
328 cross_attention_kwargs: Optional[Dict[str, Any]] = None,
329 added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
330 down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None,
331 mid_block_additional_residual: Optional[torch.Tensor] = None,
332 encoder_attention_mask: Optional[torch.Tensor] = None,
333 return_dict: bool = True,
334 ) -> Union[UNet2DConditionOutput, Tuple]:
335 r"""
336 The [`UNet2DConditionModel`] forward method.
337
338 Args:
339 sample (`torch.FloatTensor`):
340 The noisy input tensor with the following shape `(batch, channel, height, width)`.
341 timestep (`torch.FloatTensor` or `float` or `int`): The number of timesteps to denoise an input.
342 encoder_hidden_states (`torch.FloatTensor`):
343 The encoder hidden states with shape `(batch, sequence_length, feature_dim)`.
344 encoder_attention_mask (`torch.Tensor`):
345 A cross-attention mask of shape `(batch, sequence_length)` is applied to `encoder_hidden_states`. If
346 `True` the mask is kept, otherwise if `False` it is discarded. Mask will be converted into a bias,
347 which adds large negative values to the attention scores corresponding to "discard" tokens.
348 return_dict (`bool`, *optional*, defaults to `True`):
349 Whether or not to return a [`~models.unet_2d_condition.UNet2DConditionOutput`] instead of a plain
350 tuple.
351 cross_attention_kwargs (`dict`, *optional*):
352 A kwargs dictionary that if specified is passed along to the [`AttnProcessor`].
353 added_cond_kwargs: (`dict`, *optional*):
354 A kwargs dictionary containin additional embeddings that if specified are added to the embeddings that
355 are passed along to the UNet blocks.
356
357 Returns:

Callers 1

apply_FRESCO_optFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected