


'''simple docstring'''






from typing import Callable, Dict, Optional, Tuple

import torch
from torch import nn
from torch.distributions import (
    AffineTransform,
    Distribution,
    Independent,
    NegativeBinomial,
    Normal,
    StudentT,
    TransformedDistribution,
)




class 						a__							(				a__    ):





							'''simple docstring'''






							def __init__(						self   ,       lowerCamelCase_   ,       lowerCamelCase_=None   ,       lowerCamelCase_=None   ,       lowerCamelCase_=0  )			->				Optional[int]:
														lowerCAmelCase__			  =      1.0 if scale is None else scale
														lowerCAmelCase__			  =      0.0 if loc is None else loc

														super().__init__(lowerCamelCase_   ,       [AffineTransform(loc=self.loc   ,       scale=self.scale   ,       event_dim=lowerCamelCase_  )]  )







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Optional[int]:
														return self.base_dist.mean * self.scale + self.loc







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Dict:
														return self.base_dist.variance * self.scale**2







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				str:
														return self.variance.sqrt()




class 						a__							(				nn.Module    ):





							'''simple docstring'''






							def __init__(						self   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       **lowerCamelCase_  )			->				None:
														super().__init__(**lowerCamelCase_  )
														lowerCAmelCase__			  =      args_dim
														lowerCAmelCase__			  =      nn.ModuleList([nn.Linear(lowerCamelCase_   ,       lowerCamelCase_  ) for dim in args_dim.values()]  )
														lowerCAmelCase__			  =      domain_map







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				Tuple[torch.Tensor]:
														lowerCAmelCase__			  =      [proj(lowerCamelCase_  ) for proj in self.proj]

														return self.domain_map(*lowerCamelCase_  )




class 						a__							(				nn.Module    ):





							'''simple docstring'''






							def __init__(						self   ,       lowerCamelCase_  )			->				Any:
														super().__init__()
														lowerCAmelCase__			  =      function







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_   ,       *lowerCamelCase_  )			->				int:
														return self.function(lowerCamelCase_   ,       *lowerCamelCase_  )




class 						a__							:





							'''simple docstring'''






							lowercase__     :  type
							lowercase__     :  int
							lowercase__     :  Dict[str, int]







							def __init__(						self   ,       lowerCamelCase_ = 1  )			->				None:
														lowerCAmelCase__			  =      dim
														lowerCAmelCase__			  =      {k: dim * self.args_dim[k] for k in self.args_dim}







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				Union[str, Any]:
														if self.dim == 1:
																					return self.distribution_class(*lowerCamelCase_  )
														else:
																					return Independent(self.distribution_class(*lowerCamelCase_  )   ,       1  )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_   ,       lowerCamelCase_ = None   ,       lowerCamelCase_ = None   ,       )			->				Distribution:
														lowerCAmelCase__			  =      self._base_distribution(lowerCamelCase_  )
														if loc is None and scale is None:
																					return distr
														else:
																					return AffineTransformed(lowerCamelCase_   ,       loc=lowerCamelCase_   ,       scale=lowerCamelCase_   ,       event_dim=self.event_dim  )







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Tuple:
														return () if self.dim == 1 else (self.dim,)







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				int:
														return len(self.event_shape  )







							@property
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				float:
														return 0.0







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				nn.Module:
														return ParameterProjection(
														    in_features=lowerCamelCase_   ,       args_dim=self.args_dim   ,       domain_map=LambdaLayer(self.domain_map  )   ,       )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       *lowerCamelCase_  )			->				List[Any]:
														raise NotImplementedError()







							@staticmethod
							def     __SCREAMING_SNAKE_CASE				(						lowerCamelCase_  )			->				torch.Tensor:
														return (x + torch.sqrt(torch.square(lowerCamelCase_  ) + 4.0  )) / 2.0




class 						a__							(				a__    ):





							'''simple docstring'''






							lowercase__     :  Dict[str, int]      		= {"df": 1, "loc": 1, "scale": 1}
							lowercase__     :  type      		= StudentT







							@classmethod
							def     __SCREAMING_SNAKE_CASE				(						cls   ,       lowerCamelCase_   ,       lowerCamelCase_   ,       lowerCamelCase_  )			->				int:
														lowerCAmelCase__			  =      cls.squareplus(lowerCamelCase_  ).clamp_min(torch.finfo(scale.dtype  ).eps  )
														lowerCAmelCase__			  =      2.0 + cls.squareplus(lowerCamelCase_  )
														return df.squeeze(-1  ), loc.squeeze(-1  ), scale.squeeze(-1  )




class 						a__							(				a__    ):





							'''simple docstring'''






							lowercase__     :  Dict[str, int]      		= {"loc": 1, "scale": 1}
							lowercase__     :  type      		= Normal







							@classmethod
							def     __SCREAMING_SNAKE_CASE				(						cls   ,       lowerCamelCase_   ,       lowerCamelCase_  )			->				Dict:
														lowerCAmelCase__			  =      cls.squareplus(lowerCamelCase_  ).clamp_min(torch.finfo(scale.dtype  ).eps  )
														return loc.squeeze(-1  ), scale.squeeze(-1  )




class 						a__							(				a__    ):





							'''simple docstring'''






							lowercase__     :  Dict[str, int]      		= {"total_count": 1, "logits": 1}
							lowercase__     :  type      		= NegativeBinomial







							@classmethod
							def     __SCREAMING_SNAKE_CASE				(						cls   ,       lowerCamelCase_   ,       lowerCamelCase_  )			->				int:
														lowerCAmelCase__			  =      cls.squareplus(lowerCamelCase_  )
														return total_count.squeeze(-1  ), logits.squeeze(-1  )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				Distribution:
														lowerCAmelCase__  ,   lowerCAmelCase__			  =      distr_args
														if self.dim == 1:
																					return self.distribution_class(total_count=lowerCamelCase_   ,       logits=lowerCamelCase_  )
														else:
																					return Independent(self.distribution_class(total_count=lowerCamelCase_   ,       logits=lowerCamelCase_  )   ,       1  )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_   ,       lowerCamelCase_ = None   ,       lowerCamelCase_ = None  )			->				Distribution:
														lowerCAmelCase__  ,   lowerCAmelCase__			  =      distr_args

														if scale is not None:
																					# See scaling property of Gamma.
																					logits += scale.log()

														return self._base_distribution((total_count, logits)  )



'''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