

"""simple docstring"""




import math
from dataclasses import dataclass
from typing import Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, randn_tensor
from .scheduling_utils import SchedulerMixin







@dataclass
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->UnCLIP
class   __lowercase      (     _lowercase       ):
  snake_case_												=							42
  snake_case_												=							None







def 	lowerCAmelCase    (       __UpperCamelCase				,     __UpperCamelCase=0.999				,     __UpperCamelCase="cosine"				,     ):
 '''simple docstring'''





 if alpha_transform_type == "cosine":

  def alpha_bar_fn(__UpperCamelCase   ):
   return math.cos((t + 0.008) / 1.008 * math.pi / 2   ) ** 2

 elif alpha_transform_type == "exp":

  def alpha_bar_fn(__UpperCamelCase   ):
   return math.exp(t * -12.0   )

 else:
  raise ValueError(F"Unsupported alpha_tranform_type: {alpha_transform_type}"   )

 UpperCAmelCase__       :	str        =       []
 for i in range(__UpperCamelCase   ):
  UpperCAmelCase__       :	Dict        =       i / num_diffusion_timesteps
  UpperCAmelCase__       :	str        =       (i + 1) / num_diffusion_timesteps
  betas.append(min(1 - alpha_bar_fn(__UpperCamelCase   ) / alpha_bar_fn(__UpperCamelCase   )				,     __UpperCamelCase   )   )
 return torch.tensor(__UpperCamelCase				,     dtype=torch.floataa   )







class   __lowercase      (     _lowercase						,      _lowercase       ):

  @register_to_config
  def __init__(	self		:      int       ,A		:      List[str] = 1_000       ,A		:      Union[str, Any] = "fixed_small_log"       ,A		:      Optional[int] = True       ,A		:      Optional[Any] = 1.0       ,A		:      str = "epsilon"       ,A		:      Dict = "squaredcos_cap_v2"       ,):






   '''simple docstring'''



   if beta_schedule != "squaredcos_cap_v2":
    raise ValueError("""UnCLIPScheduler only supports `beta_schedule`: \'squaredcos_cap_v2\'"""     )

   UpperCAmelCase__       :	Any        =       betas_for_alpha_bar(__SCREAMING_SNAKE_CASE     )

   UpperCAmelCase__       :	Any        =       1.0 - self.betas
   UpperCAmelCase__       :	Dict        =       torch.cumprod(self.alphas       ,dim=0     )
   UpperCAmelCase__       :	Tuple        =       torch.tensor(1.0     )

   # standard deviation of the initial noise distribution
   UpperCAmelCase__       :	int        =       1.0

   # setable values
   UpperCAmelCase__       :	List[Any]        =       None
   UpperCAmelCase__       :	Tuple        =       torch.from_numpy(np.arange(0       ,__SCREAMING_SNAKE_CASE     )[::-1].copy()     )

   UpperCAmelCase__       :	Tuple        =       variance_type

  def  __lowercase							(	self		:      Optional[int]       ,A		:      Union[str, Any]       ,A		:      Optional[Any] = None     ):






   '''simple docstring'''
   return sample

  def  __lowercase							(	self		:      Union[str, Any]       ,A		:      Optional[int]       ,A		:      str = None     ):






   '''simple docstring'''
   UpperCAmelCase__       :	Tuple        =       num_inference_steps
   UpperCAmelCase__       :	List[Any]        =       (self.config.num_train_timesteps - 1) / (self.num_inference_steps - 1)
   UpperCAmelCase__       :	str        =       (np.arange(0       ,__SCREAMING_SNAKE_CASE     ) * step_ratio).round()[::-1].copy().astype(np.intaa     )
   UpperCAmelCase__       :	Optional[int]        =       torch.from_numpy(__SCREAMING_SNAKE_CASE     ).to(__SCREAMING_SNAKE_CASE     )

  def  __lowercase							(	self		:      Any       ,A		:      List[str]       ,A		:      List[Any]=None       ,A		:      Any=None       ,A		:      int=None     ):






   '''simple docstring'''



   if prev_timestep is None:
    UpperCAmelCase__       :	Optional[int]        =       t - 1

   UpperCAmelCase__       :	Any        =       self.alphas_cumprod[t]
   UpperCAmelCase__       :	List[str]        =       self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.one
   UpperCAmelCase__       :	str        =       1 - alpha_prod_t
   UpperCAmelCase__       :	List[str]        =       1 - alpha_prod_t_prev

   if prev_timestep == t - 1:
    UpperCAmelCase__       :	List[str]        =       self.betas[t]
   else:
    UpperCAmelCase__       :	Any        =       1 - alpha_prod_t / alpha_prod_t_prev

   # For t > 0, compute predicted variance βt (see formula (6) and (7) from https://arxiv.org/pdf/2006.11239.pdf)
   # and sample from it to get previous sample
   # x_{t-1} ~ N(pred_prev_sample, variance) == add variance to pred_sample
   UpperCAmelCase__       :	Optional[Any]        =       beta_prod_t_prev / beta_prod_t * beta

   if variance_type is None:
    UpperCAmelCase__       :	Optional[Any]        =       self.config.variance_type

   # hacks - were probably added for training stability
   if variance_type == "fixed_small_log":
    UpperCAmelCase__       :	Optional[int]        =       torch.log(torch.clamp(__SCREAMING_SNAKE_CASE       ,min=1e-20     )     )
    UpperCAmelCase__       :	Union[str, Any]        =       torch.exp(0.5 * variance     )
   elif variance_type == "learned_range":
    # NOTE difference with DDPM scheduler
    UpperCAmelCase__       :	Dict        =       variance.log()
    UpperCAmelCase__       :	Any        =       beta.log()

    UpperCAmelCase__       :	List[Any]        =       (predicted_variance + 1) / 2
    UpperCAmelCase__       :	Union[str, Any]        =       frac * max_log + (1 - frac) * min_log

   return variance

  def  __lowercase							(	self		:      List[Any]       ,A		:      Optional[Any]       ,A		:      Any       ,A		:      int       ,A		:      Any = None       ,A		:      List[Any]=None       ,A		:      int = True       ,):






   '''simple docstring'''
   UpperCAmelCase__       :	Tuple        =       timestep

   if model_output.shape[1] == sample.shape[1] * 2 and self.variance_type == "learned_range":
    UpperCAmelCase__ ,   UpperCAmelCase__       :	List[Any]        =       torch.split(__SCREAMING_SNAKE_CASE       ,sample.shape[1]       ,dim=1     )
   else:
    UpperCAmelCase__       :	Any        =       None

   # 1. compute alphas, betas
   if prev_timestep is None:
    UpperCAmelCase__       :	str        =       t - 1

   UpperCAmelCase__       :	Optional[int]        =       self.alphas_cumprod[t]
   UpperCAmelCase__       :	List[Any]        =       self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.one
   UpperCAmelCase__       :	Optional[Any]        =       1 - alpha_prod_t
   UpperCAmelCase__       :	List[str]        =       1 - alpha_prod_t_prev

   if prev_timestep == t - 1:
    UpperCAmelCase__       :	Tuple        =       self.betas[t]
    UpperCAmelCase__       :	List[Any]        =       self.alphas[t]
   else:
    UpperCAmelCase__       :	Dict        =       1 - alpha_prod_t / alpha_prod_t_prev
    UpperCAmelCase__       :	Dict        =       1 - beta

   # 2. compute predicted original sample from predicted noise also called
   # "predicted x_0" of formula (15) from https://arxiv.org/pdf/2006.11239.pdf
   if self.config.prediction_type == "epsilon":
    UpperCAmelCase__       :	int        =       (sample - beta_prod_t ** 0.5 * model_output) / alpha_prod_t ** 0.5
   elif self.config.prediction_type == "sample":
    UpperCAmelCase__       :	Tuple        =       model_output
   else:
    raise ValueError(
        f"prediction_type given as {self.config.prediction_type} must be one of `epsilon` or `sample`"
        """ for the UnCLIPScheduler."""     )

   # 3. Clip "predicted x_0"
   if self.config.clip_sample:
    UpperCAmelCase__       :	Optional[Any]        =       torch.clamp(
        __SCREAMING_SNAKE_CASE       ,-self.config.clip_sample_range       ,self.config.clip_sample_range     )

   # 4. Compute coefficients for pred_original_sample x_0 and current sample x_t
   # See formula (7) from https://arxiv.org/pdf/2006.11239.pdf
   UpperCAmelCase__       :	Tuple        =       (alpha_prod_t_prev ** 0.5 * beta) / beta_prod_t
   UpperCAmelCase__       :	str        =       alpha ** 0.5 * beta_prod_t_prev / beta_prod_t

   # 5. Compute predicted previous sample µ_t
   # See formula (7) from https://arxiv.org/pdf/2006.11239.pdf
   UpperCAmelCase__       :	List[str]        =       pred_original_sample_coeff * pred_original_sample + current_sample_coeff * sample

   # 6. Add noise
   UpperCAmelCase__       :	List[Any]        =       0
   if t > 0:
    UpperCAmelCase__       :	str        =       randn_tensor(
        model_output.shape       ,dtype=model_output.dtype       ,generator=__SCREAMING_SNAKE_CASE       ,device=model_output.device     )

    UpperCAmelCase__       :	Optional[int]        =       self._get_variance(
        __SCREAMING_SNAKE_CASE       ,predicted_variance=__SCREAMING_SNAKE_CASE       ,prev_timestep=__SCREAMING_SNAKE_CASE       ,)

    if self.variance_type == "fixed_small_log":
     UpperCAmelCase__       :	Any        =       variance
    elif self.variance_type == "learned_range":
     UpperCAmelCase__       :	Union[str, Any]        =       (0.5 * variance).exp()
    else:
     raise ValueError(
         f"variance_type given as {self.variance_type} must be one of `fixed_small_log` or `learned_range`"
         """ for the UnCLIPScheduler."""     )

    UpperCAmelCase__       :	Dict        =       variance * variance_noise

   UpperCAmelCase__       :	Optional[int]        =       pred_prev_sample + variance

   if not return_dict:
    return (pred_prev_sample,)

   return UnCLIPSchedulerOutput(prev_sample=__SCREAMING_SNAKE_CASE       ,pred_original_sample=__SCREAMING_SNAKE_CASE     )




  def  __lowercase							(	self		:      Optional[Any]       ,A		:      Optional[Any]       ,A		:      Union[str, Any]       ,A		:      int       ,):






   '''simple docstring'''
   UpperCAmelCase__       :	Tuple        =       self.alphas_cumprod.to(device=original_samples.device       ,dtype=original_samples.dtype     )
   UpperCAmelCase__       :	List[Any]        =       timesteps.to(original_samples.device     )

   UpperCAmelCase__       :	List[str]        =       alphas_cumprod[timesteps] ** 0.5
   UpperCAmelCase__       :	Dict        =       sqrt_alpha_prod.flatten()
   while len(sqrt_alpha_prod.shape     ) < len(original_samples.shape     ):
    UpperCAmelCase__       :	Optional[Any]        =       sqrt_alpha_prod.unsqueeze(-1     )

   UpperCAmelCase__       :	List[str]        =       (1 - alphas_cumprod[timesteps]) ** 0.5
   UpperCAmelCase__       :	Any        =       sqrt_one_minus_alpha_prod.flatten()
   while len(sqrt_one_minus_alpha_prod.shape     ) < len(original_samples.shape     ):
    UpperCAmelCase__       :	Optional[int]        =       sqrt_one_minus_alpha_prod.unsqueeze(-1     )

   UpperCAmelCase__       :	Any        =       sqrt_alpha_prod * original_samples + sqrt_one_minus_alpha_prod * noise
   return noisy_samples







"""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   )


