r""" Args: sample (`jnp.ndarray`): (batch, channel, height, width) noisy inputs tensor timestep (`jnp.ndarray` or `float` or `int`): timesteps encoder_hidden_states (`jnp.ndarray`): (batch_size, sequence_length, hidden_size) encoder hidden states
(
self,
sample: jnp.ndarray,
timesteps: Union[jnp.ndarray, float, int],
encoder_hidden_states: jnp.ndarray,
controlnet_cond: jnp.ndarray,
conditioning_scale: float = 1.0,
return_dict: bool = True,
train: bool = False,
)
| 312 | ) |
| 313 | |
| 314 | def __call__( |
| 315 | self, |
| 316 | sample: jnp.ndarray, |
| 317 | timesteps: Union[jnp.ndarray, float, int], |
| 318 | encoder_hidden_states: jnp.ndarray, |
| 319 | controlnet_cond: jnp.ndarray, |
| 320 | conditioning_scale: float = 1.0, |
| 321 | return_dict: bool = True, |
| 322 | train: bool = False, |
| 323 | ) -> Union[FlaxControlNetOutput, Tuple[Tuple[jnp.ndarray, ...], jnp.ndarray]]: |
| 324 | r""" |
| 325 | Args: |
| 326 | sample (`jnp.ndarray`): (batch, channel, height, width) noisy inputs tensor |
| 327 | timestep (`jnp.ndarray` or `float` or `int`): timesteps |
| 328 | encoder_hidden_states (`jnp.ndarray`): (batch_size, sequence_length, hidden_size) encoder hidden states |
| 329 | controlnet_cond (`jnp.ndarray`): (batch, channel, height, width) the conditional input tensor |
| 330 | conditioning_scale (`float`, *optional*, defaults to `1.0`): the scale factor for controlnet outputs |
| 331 | return_dict (`bool`, *optional*, defaults to `True`): |
| 332 | Whether or not to return a [`models.unets.unet_2d_condition_flax.FlaxUNet2DConditionOutput`] instead of a |
| 333 | plain tuple. |
| 334 | train (`bool`, *optional*, defaults to `False`): |
| 335 | Use deterministic functions and disable dropout when not training. |
| 336 | |
| 337 | Returns: |
| 338 | [`~models.unets.unet_2d_condition_flax.FlaxUNet2DConditionOutput`] or `tuple`: |
| 339 | [`~models.unets.unet_2d_condition_flax.FlaxUNet2DConditionOutput`] if `return_dict` is True, otherwise a |
| 340 | `tuple`. When returning a tuple, the first element is the sample tensor. |
| 341 | """ |
| 342 | channel_order = self.controlnet_conditioning_channel_order |
| 343 | if channel_order == "bgr": |
| 344 | controlnet_cond = jnp.flip(controlnet_cond, axis=1) |
| 345 | |
| 346 | # 1. time |
| 347 | if not isinstance(timesteps, jnp.ndarray): |
| 348 | timesteps = jnp.array([timesteps], dtype=jnp.int32) |
| 349 | elif isinstance(timesteps, jnp.ndarray) and len(timesteps.shape) == 0: |
| 350 | timesteps = timesteps.astype(dtype=jnp.float32) |
| 351 | timesteps = jnp.expand_dims(timesteps, 0) |
| 352 | |
| 353 | t_emb = self.time_proj(timesteps) |
| 354 | t_emb = self.time_embedding(t_emb) |
| 355 | |
| 356 | # 2. pre-process |
| 357 | sample = jnp.transpose(sample, (0, 2, 3, 1)) |
| 358 | sample = self.conv_in(sample) |
| 359 | |
| 360 | controlnet_cond = jnp.transpose(controlnet_cond, (0, 2, 3, 1)) |
| 361 | controlnet_cond = self.controlnet_cond_embedding(controlnet_cond) |
| 362 | sample += controlnet_cond |
| 363 | |
| 364 | # 3. down |
| 365 | down_block_res_samples = (sample,) |
| 366 | for down_block in self.down_blocks: |
| 367 | if isinstance(down_block, FlaxCrossAttnDownBlock2D): |
| 368 | sample, res_samples = down_block(sample, t_emb, encoder_hidden_states, deterministic=not train) |
| 369 | else: |
| 370 | sample, res_samples = down_block(sample, t_emb, deterministic=not train) |
| 371 | down_block_res_samples += res_samples |
nothing calls this directly
no test coverage detected