

import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD







class 				lowercase       ( nn.Module    ):
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				float     =    0.0
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				bool     =    True
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				jnp.dtype     =    jnp.floataa




				def 					a							(      self ):
											snake_case_           =					[]
											snake_case_           =					[]

											for i in range(self.num_layers ):
																		snake_case_           =					self.in_channels if i == 0 else self.out_channels

																		snake_case_           =					FlaxResnetBlockaD(
																		    in_channels=snake_case   ,     out_channels=self.out_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
																		resnets.append(snake_case )

																		snake_case_           =					FlaxTransformeraDModel(
																		    in_channels=self.out_channels   ,     n_heads=self.num_attention_heads   ,     d_head=self.out_channels // self.num_attention_heads   ,     depth=1   ,     use_linear_projection=self.use_linear_projection   ,     only_cross_attention=self.only_cross_attention   ,     use_memory_efficient_attention=self.use_memory_efficient_attention   ,     dtype=self.dtype   ,     )
																		attentions.append(snake_case )

											snake_case_           =					resnets
											snake_case_           =					attentions

											if self.add_downsample:
																		snake_case_           =					FlaxDownsampleaD(self.out_channels   ,     dtype=self.dtype )




				def __call__(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case=True ):
											snake_case_           =					()

											for resnet, attn in zip(self.resnets   ,     self.attentions ):
																		snake_case_           =					resnet(snake_case   ,     snake_case   ,     deterministic=snake_case )
																		snake_case_           =					attn(snake_case   ,     snake_case   ,     deterministic=snake_case )
																		output_states += (hidden_states,)

											if self.add_downsample:
																		snake_case_           =					self.downsamplers_a(snake_case )
																		output_states += (hidden_states,)

											return hidden_states, output_states







class 				lowercase       ( nn.Module    ):
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				float     =    0.0
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				bool     =    True
				__SCREAMING_SNAKE_CASE      :				jnp.dtype     =    jnp.floataa




				def 					a							(      self ):
											snake_case_           =					[]

											for i in range(self.num_layers ):
																		snake_case_           =					self.in_channels if i == 0 else self.out_channels

																		snake_case_           =					FlaxResnetBlockaD(
																		    in_channels=snake_case   ,     out_channels=self.out_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
																		resnets.append(snake_case )
											snake_case_           =					resnets

											if self.add_downsample:
																		snake_case_           =					FlaxDownsampleaD(self.out_channels   ,     dtype=self.dtype )




				def __call__(      self   ,     snake_case   ,     snake_case   ,     snake_case=True ):
											snake_case_           =					()

											for resnet in self.resnets:
																		snake_case_           =					resnet(snake_case   ,     snake_case   ,     deterministic=snake_case )
																		output_states += (hidden_states,)

											if self.add_downsample:
																		snake_case_           =					self.downsamplers_a(snake_case )
																		output_states += (hidden_states,)

											return hidden_states, output_states







class 				lowercase       ( nn.Module    ):
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				float     =    0.0
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				bool     =    True
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				jnp.dtype     =    jnp.floataa




				def 					a							(      self ):
											snake_case_           =					[]
											snake_case_           =					[]

											for i in range(self.num_layers ):
																		snake_case_           =					self.in_channels if (i == self.num_layers - 1) else self.out_channels
																		snake_case_           =					self.prev_output_channel if i == 0 else self.out_channels

																		snake_case_           =					FlaxResnetBlockaD(
																		    in_channels=resnet_in_channels + res_skip_channels   ,     out_channels=self.out_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
																		resnets.append(snake_case )

																		snake_case_           =					FlaxTransformeraDModel(
																		    in_channels=self.out_channels   ,     n_heads=self.num_attention_heads   ,     d_head=self.out_channels // self.num_attention_heads   ,     depth=1   ,     use_linear_projection=self.use_linear_projection   ,     only_cross_attention=self.only_cross_attention   ,     use_memory_efficient_attention=self.use_memory_efficient_attention   ,     dtype=self.dtype   ,     )
																		attentions.append(snake_case )

											snake_case_           =					resnets
											snake_case_           =					attentions

											if self.add_upsample:
																		snake_case_           =					FlaxUpsampleaD(self.out_channels   ,     dtype=self.dtype )




				def __call__(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case=True ):
											for resnet, attn in zip(self.resnets   ,     self.attentions ):
																		# pop res hidden states
																		snake_case_           =					res_hidden_states_tuple[-1]
																		snake_case_           =					res_hidden_states_tuple[:-1]
																		snake_case_           =					jnp.concatenate((hidden_states, res_hidden_states)   ,     axis=-1 )

																		snake_case_           =					resnet(snake_case   ,     snake_case   ,     deterministic=snake_case )
																		snake_case_           =					attn(snake_case   ,     snake_case   ,     deterministic=snake_case )

											if self.add_upsample:
																		snake_case_           =					self.upsamplers_a(snake_case )

											return hidden_states







class 				lowercase       ( nn.Module    ):
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				float     =    0.0
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				bool     =    True
				__SCREAMING_SNAKE_CASE      :				jnp.dtype     =    jnp.floataa




				def 					a							(      self ):
											snake_case_           =					[]

											for i in range(self.num_layers ):
																		snake_case_           =					self.in_channels if (i == self.num_layers - 1) else self.out_channels
																		snake_case_           =					self.prev_output_channel if i == 0 else self.out_channels

																		snake_case_           =					FlaxResnetBlockaD(
																		    in_channels=resnet_in_channels + res_skip_channels   ,     out_channels=self.out_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
																		resnets.append(snake_case )

											snake_case_           =					resnets

											if self.add_upsample:
																		snake_case_           =					FlaxUpsampleaD(self.out_channels   ,     dtype=self.dtype )




				def __call__(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case=True ):
											for resnet in self.resnets:
																		# pop res hidden states
																		snake_case_           =					res_hidden_states_tuple[-1]
																		snake_case_           =					res_hidden_states_tuple[:-1]
																		snake_case_           =					jnp.concatenate((hidden_states, res_hidden_states)   ,     axis=-1 )

																		snake_case_           =					resnet(snake_case   ,     snake_case   ,     deterministic=snake_case )

											if self.add_upsample:
																		snake_case_           =					self.upsamplers_a(snake_case )

											return hidden_states







class 				lowercase       ( nn.Module    ):
				__SCREAMING_SNAKE_CASE      :				int
				__SCREAMING_SNAKE_CASE      :				float     =    0.0
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				int     =    1
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				bool     =    False
				__SCREAMING_SNAKE_CASE      :				jnp.dtype     =    jnp.floataa




				def 					a							(      self ):
											# there is always at least one resnet
											snake_case_           =					[
											    FlaxResnetBlockaD(
											        in_channels=self.in_channels   ,     out_channels=self.in_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
											]

											snake_case_           =					[]

											for _ in range(self.num_layers ):
																		snake_case_           =					FlaxTransformeraDModel(
																		    in_channels=self.in_channels   ,     n_heads=self.num_attention_heads   ,     d_head=self.in_channels // self.num_attention_heads   ,     depth=1   ,     use_linear_projection=self.use_linear_projection   ,     use_memory_efficient_attention=self.use_memory_efficient_attention   ,     dtype=self.dtype   ,     )
																		attentions.append(snake_case )

																		snake_case_           =					FlaxResnetBlockaD(
																		    in_channels=self.in_channels   ,     out_channels=self.in_channels   ,     dropout_prob=self.dropout   ,     dtype=self.dtype   ,     )
																		resnets.append(snake_case )

											snake_case_           =					resnets
											snake_case_           =					attentions




				def __call__(      self   ,     snake_case   ,     snake_case   ,     snake_case   ,     snake_case=True ):
											snake_case_           =					self.resnets[0](snake_case   ,     snake_case )
											for attn, resnet in zip(self.attentions   ,     self.resnets[1:] ):
																		snake_case_           =					attn(snake_case   ,     snake_case   ,     deterministic=snake_case )
																		snake_case_           =					resnet(snake_case   ,     snake_case   ,     deterministic=snake_case )

											return hidden_states







from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, OptionalDependencyNotAvailable, is_torch_available, is_transformers_available
from .timesteps import (
    fastaa_timesteps,
    smartaa_timesteps,
    smartaa_timesteps,
    smartaaa_timesteps,
    smartaaa_timesteps,
    superaa_timesteps,
    superaa_timesteps,
    superaaa_timesteps,
)







@dataclass
class 				lowercase       ( lowercase_    ):
				__SCREAMING_SNAKE_CASE      :				Union[List[PIL.Image.Image], np.ndarray]
				__SCREAMING_SNAKE_CASE      :				Optional[List[bool]]
				__SCREAMING_SNAKE_CASE      :				Optional[List[bool]]


try:
					if not (is_transformers_available() and is_torch_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
					from .pipeline_if import IFPipeline
					from .pipeline_if_imgaimg import IFImgaImgPipeline
					from .pipeline_if_imgaimg_superresolution import IFImgaImgSuperResolutionPipeline
					from .pipeline_if_inpainting import IFInpaintingPipeline
					from .pipeline_if_inpainting_superresolution import IFInpaintingSuperResolutionPipeline
					from .pipeline_if_superresolution import IFSuperResolutionPipeline
					from .safety_checker import IFSafetyChecker
					from .watermark import IFWatermarker




