





'''simple docstring'''


from ..utils import DummyObject, requires_backends

class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				str								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Dict:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Union[str, Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				List[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				List[str]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				str:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[int]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				List[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				str								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				str								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Tuple:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				List[str]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				List[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				int								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				str:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				int								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				List[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Dict:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Dict:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Union[str, Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[int]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				List[str]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Union[str, Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Tuple:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Dict:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Optional[Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[int]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				List[str]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[int]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Optional[Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Union[str, Any]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				str								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				List[str]:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Tuple								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Any:
     requires_backends(self      ,  ["sentencepiece"]		)







class  lowerCAmelCase_		(		metaclass=__magic_name__		):
 __lowerCamelCase    :				Union[str, Any]								=       ["sentencepiece"]




 def __init__(						self      ,  *_lowerCAmelCase      ,  **_lowerCAmelCase		)     ->				Union[str, Any]:
     requires_backends(self      ,  ["sentencepiece"]		)






'''simple docstring'''







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

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .embeddings import GaussianFourierProjection, TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin
from .unet_ad_blocks import get_down_block, get_mid_block, get_out_block, get_up_block
@dataclass
class 						UpperCamelCase__       (			SCREAMING_SNAKE_CASE_						):



     """simple docstring"""






     __magic_name__           =     42
class 						UpperCamelCase__       (			SCREAMING_SNAKE_CASE_     ,       SCREAMING_SNAKE_CASE_						):



     """simple docstring"""






     @register_to_config
     def __init__(			self   ,						snake_case__ = 6_5536   ,						snake_case__ = None   ,						snake_case__ = 2   ,						snake_case__ = 2   ,						snake_case__ = 0   ,						snake_case__ = "fourier"   ,						snake_case__ = True   ,						snake_case__ = False   ,						snake_case__ = 0.0   ,						snake_case__ = ("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")   ,						snake_case__ = ("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")   ,						snake_case__ = "UNetMidBlock1D"   ,						snake_case__ = None   ,						snake_case__ = (32, 32, 64)   ,						snake_case__ = None   ,						snake_case__ = 8   ,						snake_case__ = 1   ,						snake_case__ = False   ,						):

            '''simple docstring'''

            super().__init__()
            _lowerCAmelCase     :				Optional[int]       =							sample_size

            # time
            if time_embedding_type == "fourier":
                   _lowerCAmelCase     :				Tuple       =							GaussianFourierProjection(
                       embedding_size=8   ,						set_W_to_weight=snake_case__   ,						log=snake_case__   ,						flip_sin_to_cos=snake_case__ )
                   _lowerCAmelCase     :				List[Any]       =							2 * block_out_channels[0]
            elif time_embedding_type == "positional":
                   _lowerCAmelCase     :				Optional[Any]       =							Timesteps(
                       block_out_channels[0]   ,						flip_sin_to_cos=snake_case__   ,						downscale_freq_shift=snake_case__ )
                   _lowerCAmelCase     :				Optional[int]       =							block_out_channels[0]

            if use_timestep_embedding:
                   _lowerCAmelCase     :				Any       =							block_out_channels[0] * 4
                   _lowerCAmelCase     :				List[str]       =							TimestepEmbedding(
                       in_channels=snake_case__   ,						time_embed_dim=snake_case__   ,						act_fn=snake_case__   ,						out_dim=block_out_channels[0]   ,						)

            _lowerCAmelCase     :				Tuple       =							nn.ModuleList([] )
            _lowerCAmelCase     :				Tuple       =							None
            _lowerCAmelCase     :				Optional[Any]       =							nn.ModuleList([] )
            _lowerCAmelCase     :				str       =							None

            # down
            _lowerCAmelCase     :				List[str]       =							in_channels
            for i, down_block_type in enumerate(snake_case__ ):
                   _lowerCAmelCase     :				str       =							output_channel
                   _lowerCAmelCase     :				Any       =							block_out_channels[i]

                   if i == 0:
                          input_channel += extra_in_channels

                   _lowerCAmelCase     :				Tuple       =							i == len(snake_case__ ) - 1

                   _lowerCAmelCase     :				List[str]       =							get_down_block(
                       snake_case__   ,						num_layers=snake_case__   ,						in_channels=snake_case__   ,						out_channels=snake_case__   ,						temb_channels=block_out_channels[0]   ,						add_downsample=not is_final_block or downsample_each_block   ,						)
                   self.down_blocks.append(snake_case__ )

            # mid
            _lowerCAmelCase     :				List[str]       =							get_mid_block(
                snake_case__   ,						in_channels=block_out_channels[-1]   ,						mid_channels=block_out_channels[-1]   ,						out_channels=block_out_channels[-1]   ,						embed_dim=block_out_channels[0]   ,						num_layers=snake_case__   ,						add_downsample=snake_case__   ,						)

            # up
            _lowerCAmelCase     :				Union[str, Any]       =							list(reversed(snake_case__ ) )
            _lowerCAmelCase     :				List[Any]       =							reversed_block_out_channels[0]
            if out_block_type is None:
                   _lowerCAmelCase     :				Tuple       =							out_channels
            else:
                   _lowerCAmelCase     :				Tuple       =							block_out_channels[0]

            for i, up_block_type in enumerate(snake_case__ ):
                   _lowerCAmelCase     :				int       =							output_channel
                   _lowerCAmelCase     :				Dict       =							(
                       reversed_block_out_channels[i + 1] if i < len(snake_case__ ) - 1 else final_upsample_channels
                   )

                   _lowerCAmelCase     :				Union[str, Any]       =							i == len(snake_case__ ) - 1

                   _lowerCAmelCase     :				Tuple       =							get_up_block(
                       snake_case__   ,						num_layers=snake_case__   ,						in_channels=snake_case__   ,						out_channels=snake_case__   ,						temb_channels=block_out_channels[0]   ,						add_upsample=not is_final_block   ,						)
                   self.up_blocks.append(snake_case__ )
                   _lowerCAmelCase     :				List[str]       =							output_channel

            # out
            _lowerCAmelCase     :				Tuple       =							norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4   ,						32 )
            _lowerCAmelCase     :				Any       =							get_out_block(
                out_block_type=snake_case__   ,						num_groups_out=snake_case__   ,						embed_dim=block_out_channels[0]   ,						out_channels=snake_case__   ,						act_fn=snake_case__   ,						fc_dim=block_out_channels[-1] // 4   ,						)







     def a						(			self   ,						snake_case__   ,						snake_case__   ,						snake_case__ = True   ,						):

            '''simple docstring'''

            _lowerCAmelCase     :				Optional[int]       =							timestep
            if not torch.is_tensor(snake_case__ ):
                   _lowerCAmelCase     :				Optional[int]       =							torch.tensor([timesteps]   ,						dtype=torch.long   ,						device=sample.device )
            elif torch.is_tensor(snake_case__ ) and len(timesteps.shape ) == 0:
                   _lowerCAmelCase     :				List[Any]       =							timesteps[None].to(sample.device )

            _lowerCAmelCase     :				int       =							self.time_proj(snake_case__ )
            if self.config.use_timestep_embedding:
                   _lowerCAmelCase     :				Optional[int]       =							self.time_mlp(snake_case__ )
            else:
                   _lowerCAmelCase     :				List[str]       =							timestep_embed[..., None]
                   _lowerCAmelCase     :				Dict       =							timestep_embed.repeat([1, 1, sample.shape[2]] ).to(sample.dtype )
                   _lowerCAmelCase     :				Tuple       =							timestep_embed.broadcast_to((sample.shape[:1] + timestep_embed.shape[1:]) )

            # 2. down
            _lowerCAmelCase     :				str       =							()
            for downsample_block in self.down_blocks:
                   _lowerCAmelCase      ,  _lowerCAmelCase     :				Union[str, Any]       =							downsample_block(hidden_states=snake_case__   ,						temb=snake_case__ )
                   down_block_res_samples += res_samples

            # 3. mid
            if self.mid_block:
                   _lowerCAmelCase     :				Any       =							self.mid_block(snake_case__   ,						snake_case__ )

            # 4. up
            for i, upsample_block in enumerate(self.up_blocks ):
                   _lowerCAmelCase     :				Union[str, Any]       =							down_block_res_samples[-1:]
                   _lowerCAmelCase     :				Union[str, Any]       =							down_block_res_samples[:-1]
                   _lowerCAmelCase     :				Union[str, Any]       =							upsample_block(snake_case__   ,						res_hidden_states_tuple=snake_case__   ,						temb=snake_case__ )

            # 5. post-process
            if self.out_block:
                   _lowerCAmelCase     :				Optional[Any]       =							self.out_block(snake_case__   ,						snake_case__ )

            if not return_dict:
                   return (sample,)

            return UNetaDOutput(sample=snake_case__ )

