


'''simple docstring'''






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




class 						a__							(				nn.Module    ):





							'''simple docstring'''






							lowercase__     :  int
							lowercase__     :  jnp.dtype      		= jnp.floataa







							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Optional[int]:
														lowerCAmelCase__			  =      nn.Conv(
														    self.out_channels   ,       kernel_size=(3, 3)   ,       strides=(1, 1)   ,       padding=((1, 1), (1, 1))   ,       dtype=self.dtype   ,       )







							def __call__(						self   ,       lowerCamelCase_  )			->				List[str]:
														lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__  ,   lowerCAmelCase__			  =      hidden_states.shape
														lowerCAmelCase__			  =      jax.image.resize(
														    lowerCamelCase_   ,       shape=(batch, height * 2, width * 2, channels)   ,       method='''nearest'''   ,       )
														lowerCAmelCase__			  =      self.conv(lowerCamelCase_  )
														return hidden_states




class 						a__							(				nn.Module    ):





							'''simple docstring'''






							lowercase__     :  int
							lowercase__     :  jnp.dtype      		= jnp.floataa







							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Dict:
														lowerCAmelCase__			  =      nn.Conv(
														    self.out_channels   ,       kernel_size=(3, 3)   ,       strides=(2, 2)   ,       padding=((1, 1), (1, 1))   ,       dtype=self.dtype   ,       )







							def __call__(						self   ,       lowerCamelCase_  )			->				List[Any]:
														# pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
														# hidden_states = jnp.pad(hidden_states, pad_width=pad)
														lowerCAmelCase__			  =      self.conv(lowerCamelCase_  )
														return hidden_states




class 						a__							(				nn.Module    ):





							'''simple docstring'''






							lowercase__     :  int
							lowercase__     :  int      		= None
							lowercase__     :  float      		= 0.0
							lowercase__     :  bool      		= None
							lowercase__     :  jnp.dtype      		= jnp.floataa







							def     __SCREAMING_SNAKE_CASE				(						self  )			->				int:
														lowerCAmelCase__			  =      self.in_channels if self.out_channels is None else self.out_channels

														lowerCAmelCase__			  =      nn.GroupNorm(num_groups=32   ,       epsilon=1e-5  )
														lowerCAmelCase__			  =      nn.Conv(
														    lowerCamelCase_   ,       kernel_size=(3, 3)   ,       strides=(1, 1)   ,       padding=((1, 1), (1, 1))   ,       dtype=self.dtype   ,       )

														lowerCAmelCase__			  =      nn.Dense(lowerCamelCase_   ,       dtype=self.dtype  )

														lowerCAmelCase__			  =      nn.GroupNorm(num_groups=32   ,       epsilon=1e-5  )
														lowerCAmelCase__			  =      nn.Dropout(self.dropout_prob  )
														lowerCAmelCase__			  =      nn.Conv(
														    lowerCamelCase_   ,       kernel_size=(3, 3)   ,       strides=(1, 1)   ,       padding=((1, 1), (1, 1))   ,       dtype=self.dtype   ,       )

														lowerCAmelCase__			  =      self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

														lowerCAmelCase__			  =      None
														if use_nin_shortcut:
																					lowerCAmelCase__			  =      nn.Conv(
																					    lowerCamelCase_   ,       kernel_size=(1, 1)   ,       strides=(1, 1)   ,       padding='''VALID'''   ,       dtype=self.dtype   ,       )







							def __call__(						self   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_=True  )			->				Any:
														lowerCAmelCase__			  =      hidden_states
														lowerCAmelCase__			  =      self.norma(lowerCamelCase_  )
														lowerCAmelCase__			  =      nn.swish(lowerCamelCase_  )
														lowerCAmelCase__			  =      self.conva(lowerCamelCase_  )

														lowerCAmelCase__			  =      self.time_emb_proj(nn.swish(lowerCamelCase_  )  )
														lowerCAmelCase__			  =      jnp.expand_dims(jnp.expand_dims(lowerCamelCase_   ,       1  )   ,       1  )
														lowerCAmelCase__			  =      hidden_states + temb

														lowerCAmelCase__			  =      self.norma(lowerCamelCase_  )
														lowerCAmelCase__			  =      nn.swish(lowerCamelCase_  )
														lowerCAmelCase__			  =      self.dropout(lowerCamelCase_   ,       lowerCamelCase_  )
														lowerCAmelCase__			  =      self.conva(lowerCamelCase_  )

														if self.conv_shortcut is not None:
																					lowerCAmelCase__			  =      self.conv_shortcut(lowerCamelCase_  )

														return hidden_states + residual



'''simple docstring'''






# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


__UpperCAmelCase       							=				[
    '''EAGER''',
    '''AOT_EAGER''',
    '''INDUCTOR''',
    '''NVFUSER''',
    '''AOT_NVFUSER''',
    '''AOT_CUDAGRAPHS''',
    '''OFI''',
    '''FX2TRT''',
    '''ONNXRT''',
    '''IPEX''',
]


def    _snake_case  (	A					,       A=None					,       A=None					,       A=None			)		->       Union[str, Any]:
							lowerCAmelCase__			  =      True
							while ask_again:
														lowerCAmelCase__			  =      input(A			)
														try:
																					if default is not None and len(A			) == 0:
																												return default
																					return convert_value(A			) if convert_value is not None else result
														except Exception:
																					if error_message is not None:
																												print(A			)


def    _snake_case  (	A					,       A=[]					,       A=None					,       A=0			)		->       List[Any]:
							lowerCAmelCase__			  =      BulletMenu(A					,       A			)
							lowerCAmelCase__			  =      menu.run(default_choice=A			)
							return convert_value(A			) if convert_value is not None else result


def    _snake_case  (	A			)		->       Tuple:
							lowerCAmelCase__			  =      int(A			)
							return ComputeEnvironment(['''LOCAL_MACHINE''', '''AMAZON_SAGEMAKER'''][value]			)


def    _snake_case  (	A			)		->       Union[str, Any]:
							lowerCAmelCase__			  =      int(A			)
							return DistributedType(['''NO''', '''MULTI_CPU''', '''MULTI_XPU''', '''MULTI_GPU''', '''MULTI_NPU''', '''TPU'''][value]			)


def    _snake_case  (	A			)		->       str:
							lowerCAmelCase__			  =      int(A			)
							return DynamoBackend(DYNAMO_BACKENDS[value]			).value


def    _snake_case  (	A			)		->       Tuple:
							lowerCAmelCase__			  =      int(A			)
							return PrecisionType(['''no''', '''fp16''', '''bf16''', '''fp8'''][value]			)


def    _snake_case  (	A			)		->       Union[str, Any]:
							lowerCAmelCase__			  =      int(A			)
							return SageMakerDistributedType(['''NO''', '''DATA_PARALLEL''', '''MODEL_PARALLEL'''][value]			)


def    _snake_case  (	A			)		->       List[str]:
							return {"yes": True, "no": False}[value.lower()]






class 						a__							(				argparse.RawDescriptionHelpFormatter    ):





							'''simple docstring'''






							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_  )			->				Dict:
														lowerCAmelCase__			  =      super()._format_usage(lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_  )
														lowerCAmelCase__			  =      usage.replace('''<command> [<args>] '''   ,       ''''''  )
														return usage