
"""simple docstring"""




from typing import Optional, Tuple, Union

import flax
import flax.linen as nn
import jax
import jax.numpy as jnp
from flax.core.frozen_dict import FrozenDict

from ..configuration_utils import ConfigMixin, flax_register_to_config
from ..utils import BaseOutput
from .embeddings_flax import FlaxTimestepEmbedding, FlaxTimesteps
from .modeling_flax_utils import FlaxModelMixin
from .unet_ad_blocks_flax import (
    FlaxCrossAttnDownBlockaD,
    FlaxDownBlockaD,
    FlaxUNetMidBlockaDCrossAttn,
)







@flax.struct.dataclass
class     lowercase(_lowercase       ):
     __snake_case:	jnp.ndarray
     __snake_case:	jnp.ndarray







class     lowercase(nn.Module       ):
     __snake_case:	int
     __snake_case:	Tuple[int]						=     (16, 32, 96, 256)
     __snake_case:	jnp.dtype						=     jnp.floataa



     def 			lowercase__  (							self   )		->     Dict:







         """simple docstring"""



         a__		=			nn.Conv(
             self.block_out_channels[0]     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)

         a__		=			[]
         for i in range(len(self.block_out_channels   ) - 1   ):
             a__		=			self.block_out_channels[i]
             a__		=			self.block_out_channels[i + 1]
             a__		=			nn.Conv(
                 __SCREAMING_SNAKE_CASE     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)
             blocks.append(__SCREAMING_SNAKE_CASE   )
             a__		=			nn.Conv(
                 __SCREAMING_SNAKE_CASE     ,				kernel_size=(3, 3)     ,				strides=(2, 2)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)
             blocks.append(__SCREAMING_SNAKE_CASE   )
         a__		=			blocks

         a__		=			nn.Conv(
             self.conditioning_embedding_channels     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)




     def __call__(							self     ,				__SCREAMING_SNAKE_CASE   )		->     Any:







         """simple docstring"""



         a__		=			self.conv_in(__SCREAMING_SNAKE_CASE   )
         a__		=			nn.silu(__SCREAMING_SNAKE_CASE   )

         for block in self.blocks:
             a__		=			block(__SCREAMING_SNAKE_CASE   )
             a__		=			nn.silu(__SCREAMING_SNAKE_CASE   )

         a__		=			self.conv_out(__SCREAMING_SNAKE_CASE   )

         return embedding







@flax_register_to_config
class     lowercase(nn.Module    ,						_lowercase    ,						_lowercase       ):
     __snake_case:	int						=     32
     __snake_case:	int						=     4
     __snake_case:	Tuple[str]						=     (
         "CrossAttnDownBlock2D",
         "CrossAttnDownBlock2D",
         "CrossAttnDownBlock2D",
         "DownBlock2D",
     )
     __snake_case:	Union[bool, Tuple[bool]]						=     False
     __snake_case:	Tuple[int]						=     (320, 640, 1280, 1280)
     __snake_case:	int						=     2
     __snake_case:	Union[int, Tuple[int]]						=     8
     __snake_case:	Optional[Union[int, Tuple[int]]]						=     None
     __snake_case:	int						=     1280
     __snake_case:	float						=     0.0
     __snake_case:	bool						=     False
     __snake_case:	jnp.dtype						=     jnp.floataa
     __snake_case:	bool						=     True
     __snake_case:	int						=     0
     __snake_case:	str						=     "rgb"
     __snake_case:	Tuple[int]						=     (16, 32, 96, 256)



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     FrozenDict:







         """simple docstring"""



         a__		=			(1, self.in_channels, self.sample_size, self.sample_size)
         a__		=			jnp.zeros(__SCREAMING_SNAKE_CASE     ,				dtype=jnp.floataa   )
         a__		=			jnp.ones((1,)     ,				dtype=jnp.intaa   )
         a__		=			jnp.zeros((1, 1, self.cross_attention_dim)     ,				dtype=jnp.floataa   )
         a__		=			(1, 3, self.sample_size * 8, self.sample_size * 8)
         a__		=			jnp.zeros(__SCREAMING_SNAKE_CASE     ,				dtype=jnp.floataa   )

         a__	,     a__		=			jax.random.split(__SCREAMING_SNAKE_CASE   )
         a__		=			{'params': params_rng, 'dropout': dropout_rng}

         return self.init(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )["params"]



     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         a__		=			self.block_out_channels
         a__		=			block_out_channels[0] * 4

         # If `num_attention_heads` is not defined (which is the case for most models)
         # it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
         # The reason for this behavior is to correct for incorrectly named variables that were introduced
         # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
         # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
         # which is why we correct for the naming here.
         a__		=			self.num_attention_heads or self.attention_head_dim

         # input
         a__		=			nn.Conv(
             block_out_channels[0]     ,				kernel_size=(3, 3)     ,				strides=(1, 1)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)

         # time
         a__		=			FlaxTimesteps(
             block_out_channels[0]     ,				flip_sin_to_cos=self.flip_sin_to_cos     ,				freq_shift=self.config.freq_shift   )
         a__		=			FlaxTimestepEmbedding(__SCREAMING_SNAKE_CASE     ,				dtype=self.dtype   )

         a__		=			FlaxControlNetConditioningEmbedding(
             conditioning_embedding_channels=block_out_channels[0]     ,				block_out_channels=self.conditioning_embedding_out_channels     ,				)

         a__		=			self.only_cross_attention
         if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             a__		=			(only_cross_attention,) * len(self.down_block_types   )

         if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             a__		=			(num_attention_heads,) * len(self.down_block_types   )

         # down
         a__		=			[]
         a__		=			[]

         a__		=			block_out_channels[0]

         a__		=			nn.Conv(
             __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
         controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

         for i, down_block_type in enumerate(self.down_block_types   ):
             a__		=			output_channel
             a__		=			block_out_channels[i]
             a__		=			i == len(__SCREAMING_SNAKE_CASE   ) - 1

             if down_block_type == "CrossAttnDownBlock2D":
                 a__		=			FlaxCrossAttnDownBlockaD(
                     in_channels=__SCREAMING_SNAKE_CASE     ,				out_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_layers=self.layers_per_block     ,				num_attention_heads=num_attention_heads[i]     ,				add_downsample=not is_final_block     ,				use_linear_projection=self.use_linear_projection     ,				only_cross_attention=only_cross_attention[i]     ,				dtype=self.dtype     ,				)
             else:
                 a__		=			FlaxDownBlockaD(
                     in_channels=__SCREAMING_SNAKE_CASE     ,				out_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_layers=self.layers_per_block     ,				add_downsample=not is_final_block     ,				dtype=self.dtype     ,				)

             down_blocks.append(__SCREAMING_SNAKE_CASE   )

             for _ in range(self.layers_per_block   ):
                 a__		=			nn.Conv(
                     __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
                 controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

             if not is_final_block:
                 a__		=			nn.Conv(
                     __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
                 controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

         a__		=			down_blocks
         a__		=			controlnet_down_blocks

         # mid
         a__		=			block_out_channels[-1]
         a__		=			FlaxUNetMidBlockaDCrossAttn(
             in_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_attention_heads=num_attention_heads[-1]     ,				use_linear_projection=self.use_linear_projection     ,				dtype=self.dtype     ,				)

         a__		=			nn.Conv(
             __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)




     def __call__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE = 1.0     ,				__SCREAMING_SNAKE_CASE = True     ,				__SCREAMING_SNAKE_CASE = False     ,				)		->     Union[FlaxControlNetOutput, Tuple]:







         """simple docstring"""



         a__		=			self.controlnet_conditioning_channel_order
         if channel_order == "bgr":
             a__		=			jnp.flip(__SCREAMING_SNAKE_CASE     ,				axis=1   )

         # 1. time
         if not isinstance(__SCREAMING_SNAKE_CASE     ,				jnp.ndarray   ):
             a__		=			jnp.array([timesteps]     ,				dtype=jnp.intaa   )
         elif isinstance(__SCREAMING_SNAKE_CASE     ,				jnp.ndarray   ) and len(timesteps.shape   ) == 0:
             a__		=			timesteps.astype(dtype=jnp.floataa   )
             a__		=			jnp.expand_dims(__SCREAMING_SNAKE_CASE     ,				0   )

         a__		=			self.time_proj(__SCREAMING_SNAKE_CASE   )
         a__		=			self.time_embedding(__SCREAMING_SNAKE_CASE   )

         # 2. pre-process
         a__		=			jnp.transpose(__SCREAMING_SNAKE_CASE     ,				(0, 2, 3, 1)   )
         a__		=			self.conv_in(__SCREAMING_SNAKE_CASE   )

         a__		=			jnp.transpose(__SCREAMING_SNAKE_CASE     ,				(0, 2, 3, 1)   )
         a__		=			self.controlnet_cond_embedding(__SCREAMING_SNAKE_CASE   )
         sample += controlnet_cond

         # 3. down
         a__		=			(sample,)
         for down_block in self.down_blocks:
             if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
                 a__	,     a__		=			down_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )
             else:
                 a__	,     a__		=			down_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )
             down_block_res_samples += res_samples

         # 4. mid
         a__		=			self.mid_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )

         # 5. contronet blocks
         a__		=			()
         for down_block_res_sample, controlnet_block in zip(__SCREAMING_SNAKE_CASE     ,				self.controlnet_down_blocks   ):
             a__		=			controlnet_block(__SCREAMING_SNAKE_CASE   )
             controlnet_down_block_res_samples += (down_block_res_sample,)

         a__		=			controlnet_down_block_res_samples

         a__		=			self.controlnet_mid_block(__SCREAMING_SNAKE_CASE   )

         # 6. scaling
         a__		=			[sample * conditioning_scale for sample in down_block_res_samples]
         mid_block_res_sample *= conditioning_scale

         if not return_dict:
             return (down_block_res_samples, mid_block_res_sample)

         return FlaxControlNetOutput(
             down_block_res_samples=__SCREAMING_SNAKE_CASE     ,				mid_block_res_sample=__SCREAMING_SNAKE_CASE   )




"""simple docstring"""




from typing import Optional, Tuple, Union

import flax
import flax.linen as nn
import jax
import jax.numpy as jnp
from flax.core.frozen_dict import FrozenDict

from ..configuration_utils import ConfigMixin, flax_register_to_config
from ..utils import BaseOutput
from .embeddings_flax import FlaxTimestepEmbedding, FlaxTimesteps
from .modeling_flax_utils import FlaxModelMixin
from .unet_ad_blocks_flax import (
    FlaxCrossAttnDownBlockaD,
    FlaxDownBlockaD,
    FlaxUNetMidBlockaDCrossAttn,
)







@flax.struct.dataclass
class     lowercase(_lowercase       ):
     __snake_case:	jnp.ndarray
     __snake_case:	jnp.ndarray







class     lowercase(nn.Module       ):
     __snake_case:	int
     __snake_case:	Tuple[int]						=     (16, 32, 96, 256)
     __snake_case:	jnp.dtype						=     jnp.floataa



     def 			lowercase__  (							self   )		->     Dict:







         """simple docstring"""



         a__		=			nn.Conv(
             self.block_out_channels[0]     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)

         a__		=			[]
         for i in range(len(self.block_out_channels   ) - 1   ):
             a__		=			self.block_out_channels[i]
             a__		=			self.block_out_channels[i + 1]
             a__		=			nn.Conv(
                 __SCREAMING_SNAKE_CASE     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)
             blocks.append(__SCREAMING_SNAKE_CASE   )
             a__		=			nn.Conv(
                 __SCREAMING_SNAKE_CASE     ,				kernel_size=(3, 3)     ,				strides=(2, 2)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)
             blocks.append(__SCREAMING_SNAKE_CASE   )
         a__		=			blocks

         a__		=			nn.Conv(
             self.conditioning_embedding_channels     ,				kernel_size=(3, 3)     ,				padding=((1, 1), (1, 1))     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)




     def __call__(							self     ,				__SCREAMING_SNAKE_CASE   )		->     Any:







         """simple docstring"""



         a__		=			self.conv_in(__SCREAMING_SNAKE_CASE   )
         a__		=			nn.silu(__SCREAMING_SNAKE_CASE   )

         for block in self.blocks:
             a__		=			block(__SCREAMING_SNAKE_CASE   )
             a__		=			nn.silu(__SCREAMING_SNAKE_CASE   )

         a__		=			self.conv_out(__SCREAMING_SNAKE_CASE   )

         return embedding







@flax_register_to_config
class     lowercase(nn.Module    ,						_lowercase    ,						_lowercase       ):
     __snake_case:	int						=     32
     __snake_case:	int						=     4
     __snake_case:	Tuple[str]						=     (
         "CrossAttnDownBlock2D",
         "CrossAttnDownBlock2D",
         "CrossAttnDownBlock2D",
         "DownBlock2D",
     )
     __snake_case:	Union[bool, Tuple[bool]]						=     False
     __snake_case:	Tuple[int]						=     (320, 640, 1280, 1280)
     __snake_case:	int						=     2
     __snake_case:	Union[int, Tuple[int]]						=     8
     __snake_case:	Optional[Union[int, Tuple[int]]]						=     None
     __snake_case:	int						=     1280
     __snake_case:	float						=     0.0
     __snake_case:	bool						=     False
     __snake_case:	jnp.dtype						=     jnp.floataa
     __snake_case:	bool						=     True
     __snake_case:	int						=     0
     __snake_case:	str						=     "rgb"
     __snake_case:	Tuple[int]						=     (16, 32, 96, 256)



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     FrozenDict:







         """simple docstring"""



         a__		=			(1, self.in_channels, self.sample_size, self.sample_size)
         a__		=			jnp.zeros(__SCREAMING_SNAKE_CASE     ,				dtype=jnp.floataa   )
         a__		=			jnp.ones((1,)     ,				dtype=jnp.intaa   )
         a__		=			jnp.zeros((1, 1, self.cross_attention_dim)     ,				dtype=jnp.floataa   )
         a__		=			(1, 3, self.sample_size * 8, self.sample_size * 8)
         a__		=			jnp.zeros(__SCREAMING_SNAKE_CASE     ,				dtype=jnp.floataa   )

         a__	,     a__		=			jax.random.split(__SCREAMING_SNAKE_CASE   )
         a__		=			{'params': params_rng, 'dropout': dropout_rng}

         return self.init(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )["params"]



     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         a__		=			self.block_out_channels
         a__		=			block_out_channels[0] * 4

         # If `num_attention_heads` is not defined (which is the case for most models)
         # it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
         # The reason for this behavior is to correct for incorrectly named variables that were introduced
         # when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
         # Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
         # which is why we correct for the naming here.
         a__		=			self.num_attention_heads or self.attention_head_dim

         # input
         a__		=			nn.Conv(
             block_out_channels[0]     ,				kernel_size=(3, 3)     ,				strides=(1, 1)     ,				padding=((1, 1), (1, 1))     ,				dtype=self.dtype     ,				)

         # time
         a__		=			FlaxTimesteps(
             block_out_channels[0]     ,				flip_sin_to_cos=self.flip_sin_to_cos     ,				freq_shift=self.config.freq_shift   )
         a__		=			FlaxTimestepEmbedding(__SCREAMING_SNAKE_CASE     ,				dtype=self.dtype   )

         a__		=			FlaxControlNetConditioningEmbedding(
             conditioning_embedding_channels=block_out_channels[0]     ,				block_out_channels=self.conditioning_embedding_out_channels     ,				)

         a__		=			self.only_cross_attention
         if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             a__		=			(only_cross_attention,) * len(self.down_block_types   )

         if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             a__		=			(num_attention_heads,) * len(self.down_block_types   )

         # down
         a__		=			[]
         a__		=			[]

         a__		=			block_out_channels[0]

         a__		=			nn.Conv(
             __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
         controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

         for i, down_block_type in enumerate(self.down_block_types   ):
             a__		=			output_channel
             a__		=			block_out_channels[i]
             a__		=			i == len(__SCREAMING_SNAKE_CASE   ) - 1

             if down_block_type == "CrossAttnDownBlock2D":
                 a__		=			FlaxCrossAttnDownBlockaD(
                     in_channels=__SCREAMING_SNAKE_CASE     ,				out_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_layers=self.layers_per_block     ,				num_attention_heads=num_attention_heads[i]     ,				add_downsample=not is_final_block     ,				use_linear_projection=self.use_linear_projection     ,				only_cross_attention=only_cross_attention[i]     ,				dtype=self.dtype     ,				)
             else:
                 a__		=			FlaxDownBlockaD(
                     in_channels=__SCREAMING_SNAKE_CASE     ,				out_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_layers=self.layers_per_block     ,				add_downsample=not is_final_block     ,				dtype=self.dtype     ,				)

             down_blocks.append(__SCREAMING_SNAKE_CASE   )

             for _ in range(self.layers_per_block   ):
                 a__		=			nn.Conv(
                     __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
                 controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

             if not is_final_block:
                 a__		=			nn.Conv(
                     __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)
                 controlnet_down_blocks.append(__SCREAMING_SNAKE_CASE   )

         a__		=			down_blocks
         a__		=			controlnet_down_blocks

         # mid
         a__		=			block_out_channels[-1]
         a__		=			FlaxUNetMidBlockaDCrossAttn(
             in_channels=__SCREAMING_SNAKE_CASE     ,				dropout=self.dropout     ,				num_attention_heads=num_attention_heads[-1]     ,				use_linear_projection=self.use_linear_projection     ,				dtype=self.dtype     ,				)

         a__		=			nn.Conv(
             __SCREAMING_SNAKE_CASE     ,				kernel_size=(1, 1)     ,				padding='VALID'     ,				kernel_init=nn.initializers.zeros_init()     ,				bias_init=nn.initializers.zeros_init()     ,				dtype=self.dtype     ,				)




     def __call__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE = 1.0     ,				__SCREAMING_SNAKE_CASE = True     ,				__SCREAMING_SNAKE_CASE = False     ,				)		->     Union[FlaxControlNetOutput, Tuple]:







         """simple docstring"""



         a__		=			self.controlnet_conditioning_channel_order
         if channel_order == "bgr":
             a__		=			jnp.flip(__SCREAMING_SNAKE_CASE     ,				axis=1   )

         # 1. time
         if not isinstance(__SCREAMING_SNAKE_CASE     ,				jnp.ndarray   ):
             a__		=			jnp.array([timesteps]     ,				dtype=jnp.intaa   )
         elif isinstance(__SCREAMING_SNAKE_CASE     ,				jnp.ndarray   ) and len(timesteps.shape   ) == 0:
             a__		=			timesteps.astype(dtype=jnp.floataa   )
             a__		=			jnp.expand_dims(__SCREAMING_SNAKE_CASE     ,				0   )

         a__		=			self.time_proj(__SCREAMING_SNAKE_CASE   )
         a__		=			self.time_embedding(__SCREAMING_SNAKE_CASE   )

         # 2. pre-process
         a__		=			jnp.transpose(__SCREAMING_SNAKE_CASE     ,				(0, 2, 3, 1)   )
         a__		=			self.conv_in(__SCREAMING_SNAKE_CASE   )

         a__		=			jnp.transpose(__SCREAMING_SNAKE_CASE     ,				(0, 2, 3, 1)   )
         a__		=			self.controlnet_cond_embedding(__SCREAMING_SNAKE_CASE   )
         sample += controlnet_cond

         # 3. down
         a__		=			(sample,)
         for down_block in self.down_blocks:
             if isinstance(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
                 a__	,     a__		=			down_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )
             else:
                 a__	,     a__		=			down_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )
             down_block_res_samples += res_samples

         # 4. mid
         a__		=			self.mid_block(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				deterministic=not train   )

         # 5. contronet blocks
         a__		=			()
         for down_block_res_sample, controlnet_block in zip(__SCREAMING_SNAKE_CASE     ,				self.controlnet_down_blocks   ):
             a__		=			controlnet_block(__SCREAMING_SNAKE_CASE   )
             controlnet_down_block_res_samples += (down_block_res_sample,)

         a__		=			controlnet_down_block_res_samples

         a__		=			self.controlnet_mid_block(__SCREAMING_SNAKE_CASE   )

         # 6. scaling
         a__		=			[sample * conditioning_scale for sample in down_block_res_samples]
         mid_block_res_sample *= conditioning_scale

         if not return_dict:
             return (down_block_res_samples, mid_block_res_sample)

         return FlaxControlNetOutput(
             down_block_res_samples=__SCREAMING_SNAKE_CASE     ,				mid_block_res_sample=__SCREAMING_SNAKE_CASE   )


