'''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 	_UpperCAmelCase       (				_UpperCamelCase       :      Tuple  )      -> Any:
    if is_torch_available():
        import torch

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

    return isinstance(_UpperCamelCase,  np.ndarray  )




class       __UpperCAmelCase							(							_UpperCamelCase	):





       '''simple docstring'''



       def    __A			( self					)						->	int:
           A_      =  fields(self					)

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

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

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

       def __delitem__( self       ,	*_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)						->	Dict:
           raise Exception(F'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''					)

       def    __A			( self       ,	*_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)						->	Any:
           raise Exception(F'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''					)

       def    __A			( self       ,	*_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)						->	Union[str, Any]:
           raise Exception(F'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''					)

       def    __A			( self       ,	*_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)						->	List[Any]:
           raise Exception(F'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''					)

       def __getitem__( self       ,	_SCREAMING_SNAKE_CASE					)						->	Any:
           if isinstance(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					):
               A_      =  dict(self.items()					)
               return inner_dict[k]
           else:
               return self.to_tuple()[k]

       def __setattr__( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           if name in self.keys() and value is not None:
               # Don't call self.__setitem__ to avoid recursion errors
               super().__setitem__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)
           super().__setattr__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)

       def __setitem__( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	List[str]:
           # Will raise a KeyException if needed
           super().__setitem__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)
           # Don't call self.__setattr__ to avoid recursion errors
           super().__setattr__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Tuple[Any]:
           return tuple(self[k] for k in self.keys()					)







'''simple docstring'''




from typing import Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_openai import OpenAIGPTTokenizer


__snake_case  : Union[str, Any]		       =    logging.get_logger(__name__)

__snake_case  : Union[str, Any]		       =    {'vocab_file': 'vocab.json', 'merges_file': 'merges.txt', 'tokenizer_file': 'tokenizer.json'}

__snake_case  : List[str]		       =    {
    'vocab_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/vocab.json'},
    'merges_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/merges.txt'},
    'tokenizer_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/tokenizer.json'},
}

__snake_case  : Optional[int]		       =    {
    'openai-gpt': 512,
}




class       __UpperCAmelCase							(							_UpperCamelCase	):





       '''simple docstring'''



       __lowercase   :   int  					=							VOCAB_FILES_NAMES
       __lowercase   :   int  					=							PRETRAINED_VOCAB_FILES_MAP
       __lowercase   :   str  					=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __lowercase   :   Optional[Any]  					=							['input_ids', 'attention_mask']
       __lowercase   :   List[Any]  					=							OpenAIGPTTokenizer

       def __init__( self       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE=None       ,	_SCREAMING_SNAKE_CASE="<unk>"       ,	**_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           super().__init__(_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	tokenizer_file=_SCREAMING_SNAKE_CASE       ,	unk_token=_SCREAMING_SNAKE_CASE       ,	**_SCREAMING_SNAKE_CASE					)

       @property
       def    __A			( self					)						->	Optional[Any]:
           return True

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE = None					)						->	Tuple[str]:
           A_      =  self._tokenizer.model.save(_SCREAMING_SNAKE_CASE       ,	name=_SCREAMING_SNAKE_CASE					)
           return tuple(_SCREAMING_SNAKE_CASE					)






