






"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowerCAmelCase_		:			str				   =					{
    '''configuration_codegen''': ['''CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''CodeGenConfig''', '''CodeGenOnnxConfig'''],
    '''tokenization_codegen''': ['''CodeGenTokenizer'''],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_		:			Union[str, Any]				   =					['''CodeGenTokenizerFast''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCAmelCase_		:			Optional[int]				   =					[
     '''CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''CodeGenForCausalLM''',
     '''CodeGenModel''',
     '''CodeGenPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_codegen import CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP, CodeGenConfig, CodeGenOnnxConfig
 from .tokenization_codegen import CodeGenTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_codegen_fast import CodeGenTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_codegen import (
      CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
      CodeGenForCausalLM,
      CodeGenModel,
      CodeGenPreTrainedModel,
  )

else:
 import sys

 lowerCAmelCase_		:			Union[str, Any]				   =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)








"""simple docstring"""







from collections import OrderedDict
from dataclasses import fields
from typing import Any, Tuple

import numpy as np

from .import_utils import is_torch_available






def 					_lowerCAmelCase				(					lowerCAmelCase						):







       '''simple docstring'''
       if is_torch_available():
              import torch

              if isinstance(lowerCAmelCase		,					torch.Tensor						):
                     return True

       return isinstance(lowerCAmelCase		,					np.ndarray						)





class      UpperCamelCase_       (				a_     ):



  def 						UpperCamelCase_ (					self )	->	Dict:



         """simple docstring"""





         UpperCAmelCase					=	fields(self )

         # Safety and consistency checks
         if not len(snake_case__ ):
                raise ValueError(f'''{self.__class__.__name__} has no fields.''' )

         UpperCAmelCase					=	getattr(self       ,						class_fields[0].name )
         UpperCAmelCase					=	all(getattr(self       ,						field.name ) is None for field in class_fields[1:] )

         if other_fields_are_none and isinstance(snake_case__       ,						snake_case__ ):
                for key, value in first_field.items():
                       UpperCAmelCase					=	value
         else:
                for field in class_fields:
                       UpperCAmelCase					=	getattr(self       ,						field.name )
                       if v is not None:
                              UpperCAmelCase					=	v



  def __delitem__(					self       ,						*snake_case__       ,						**snake_case__ )	->	Optional[int]:



         """simple docstring"""





         raise Exception(f'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.''' )



  def 						UpperCamelCase_ (					self       ,						*snake_case__       ,						**snake_case__ )	->	List[str]:



         """simple docstring"""





         raise Exception(f'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.''' )



  def 						UpperCamelCase_ (					self       ,						*snake_case__       ,						**snake_case__ )	->	Optional[int]:



         """simple docstring"""





         raise Exception(f'''You cannot use ``pop`` on a {self.__class__.__name__} instance.''' )



  def 						UpperCamelCase_ (					self       ,						*snake_case__       ,						**snake_case__ )	->	Optional[int]:



         """simple docstring"""





         raise Exception(f'''You cannot use ``update`` on a {self.__class__.__name__} instance.''' )



  def __getitem__(					self       ,						snake_case__ )	->	List[Any]:



         """simple docstring"""





         if isinstance(snake_case__       ,						snake_case__ ):
                UpperCAmelCase					=	dict(self.items() )
                return inner_dict[k]
         else:
                return self.to_tuple()[k]



  def __setattr__(					self       ,						snake_case__       ,						snake_case__ )	->	Union[str, Any]:



         """simple docstring"""





         if name in self.keys() and value is not None:
                # Don't call self.__setitem__ to avoid recursion errors
                super().__setitem__(snake_case__       ,						snake_case__ )
         super().__setattr__(snake_case__       ,						snake_case__ )



  def __setitem__(					self       ,						snake_case__       ,						snake_case__ )	->	Tuple:



         """simple docstring"""





         super().__setitem__(snake_case__       ,						snake_case__ )
         # Don't call self.__setattr__ to avoid recursion errors
         super().__setattr__(snake_case__       ,						snake_case__ )



  def 						UpperCamelCase_ (					self )	->	Tuple[Any]:



         """simple docstring"""





         return tuple(self[k] for k in self.keys() )
