





"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


A	     =					logging.get_logger(__name__)

A	     =					{
    '''edbeeching/decision-transformer-gym-hopper-medium''': (
        '''https://huggingface.co/edbeeching/decision-transformer-gym-hopper-medium/resolve/main/config.json'''
    ),
    # See all DecisionTransformer models at https://huggingface.co/models?filter=decision_transformer
}




class 			__lowercase     (     _UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase					=					'''decision_transformer'''
					__lowerCAmelCase					=					['''past_key_values''']
					__lowerCAmelCase					=					{
					    '''max_position_embeddings''': '''n_positions''',
					    '''num_attention_heads''': '''n_head''',
					    '''num_hidden_layers''': '''n_layer''',
					}







					def __init__(  self		,     _UpperCAmelCase=17		,     _UpperCAmelCase=4		,     _UpperCAmelCase=128		,     _UpperCAmelCase=4096		,     _UpperCAmelCase=True		,     _UpperCAmelCase=1		,     _UpperCAmelCase=1024		,     _UpperCAmelCase=3		,     _UpperCAmelCase=1		,     _UpperCAmelCase=None		,     _UpperCAmelCase="relu"		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=0.1		,     _UpperCAmelCase=1e-5		,     _UpperCAmelCase=0.0_2		,     _UpperCAmelCase=True		,     _UpperCAmelCase=True		,     _UpperCAmelCase=50256		,     _UpperCAmelCase=50256		,     _UpperCAmelCase=False		,     _UpperCAmelCase=False		,     **_UpperCAmelCase		,     ):
									__a	:  int         =					state_dim
									__a	:  Dict         =					act_dim
									__a	:  Optional[int]         =					hidden_size
									__a	:  Dict         =					max_ep_len
									__a	:  Any         =					action_tanh
									__a	:  Any         =					vocab_size
									__a	:  int         =					n_positions
									__a	:  Dict         =					n_layer
									__a	:  Optional[int]         =					n_head
									__a	:  List[str]         =					n_inner
									__a	:  Tuple         =					activation_function
									__a	:  Dict         =					resid_pdrop
									__a	:  Dict         =					embd_pdrop
									__a	:  Any         =					attn_pdrop
									__a	:  str         =					layer_norm_epsilon
									__a	:  Optional[Any]         =					initializer_range
									__a	:  Dict         =					scale_attn_weights
									__a	:  List[str]         =					use_cache
									__a	:  Any         =					scale_attn_by_inverse_layer_idx
									__a	:  Optional[Any]         =					reorder_and_upcast_attn

									__a	:  Tuple         =					bos_token_id
									__a	:  List[Any]         =					eos_token_id

									super().__init__(bos_token_id=_UpperCAmelCase		,     eos_token_id=_UpperCAmelCase		,     **_UpperCAmelCase       )






"""simple docstring"""






import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A	     =					logging.get_logger(__name__)
A	     =					{'''vocab_file''': '''spiece.model'''}

A	     =					{
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    }
}

A	     =					{
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

A	     =					'''▁'''




class 			__lowercase     (     _UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase					=					VOCAB_FILES_NAMES
					__lowerCAmelCase					=					PRETRAINED_VOCAB_FILES_MAP
					__lowerCAmelCase					=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES







					def __init__(  self		,     _UpperCAmelCase		,     _UpperCAmelCase=True		,     _UpperCAmelCase=True		,     _UpperCAmelCase=False		,     _UpperCAmelCase="[CLS]"		,     _UpperCAmelCase="[SEP]"		,     _UpperCAmelCase="<unk>"		,     _UpperCAmelCase="[SEP]"		,     _UpperCAmelCase="<pad>"		,     _UpperCAmelCase="[CLS]"		,     _UpperCAmelCase="[MASK]"		,     _UpperCAmelCase = None		,     **_UpperCAmelCase		,     ):
									# Mask token behave like a normal word, i.e. include the space before it and
									# is included in the raw text, there should be a match in a non-normalized sentence.
									__a	:  int         =					(
									    AddedToken(_UpperCAmelCase		,     lstrip=_UpperCAmelCase		,     rstrip=_UpperCAmelCase		,     normalized=_UpperCAmelCase       )
									    if isinstance(_UpperCAmelCase		,     _UpperCAmelCase       )
									    else mask_token
									)

									__a	:  Any         =					{} if sp_model_kwargs is None else sp_model_kwargs

									super().__init__(
									    do_lower_case=_UpperCAmelCase		,     remove_space=_UpperCAmelCase		,     keep_accents=_UpperCAmelCase		,     bos_token=_UpperCAmelCase		,     eos_token=_UpperCAmelCase		,     unk_token=_UpperCAmelCase		,     sep_token=_UpperCAmelCase		,     pad_token=_UpperCAmelCase		,     cls_token=_UpperCAmelCase		,     mask_token=_UpperCAmelCase		,     sp_model_kwargs=self.sp_model_kwargs		,     **_UpperCAmelCase		,     )

									__a	:  Tuple         =					do_lower_case
									__a	:  Optional[Any]         =					remove_space
									__a	:  Optional[Any]         =					keep_accents
									__a	:  Union[str, Any]         =					vocab_file

									__a	:  List[str]         =					spm.SentencePieceProcessor(**self.sp_model_kwargs       )
									self.sp_model.Load(_UpperCAmelCase       )







					@property
					def 	_lowerCamelCase						(  self       ):
									return len(self.sp_model       )







					def 	_lowerCamelCase						(  self       ):
									__a	:  Any         =					{self.convert_ids_to_tokens(_UpperCAmelCase       ): i for i in range(self.vocab_size       )}
									vocab.update(self.added_tokens_encoder       )
									return vocab







					def __getstate__(  self       ):
									__a	:  str         =					self.__dict__.copy()
									__a	:  Tuple         =					None
									return state







					def __setstate__(  self		,     _UpperCAmelCase       ):
									__a	:  Any         =					d

									# for backward compatibility
									if not hasattr(self		,     '''sp_model_kwargs'''       ):
													__a	:  Optional[Any]         =					{}

									__a	:  Dict         =					spm.SentencePieceProcessor(**self.sp_model_kwargs       )
									self.sp_model.Load(self.vocab_file       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									if self.remove_space:
													__a	:  Any         =					''' '''.join(inputs.strip().split()       )
									else:
													__a	:  Tuple         =					inputs
									__a	:  Union[str, Any]         =					outputs.replace('''``'''		,     '''"'''       ).replace('''\'\''''		,     '''"'''       )

									if not self.keep_accents:
													__a	:  List[str]         =					unicodedata.normalize('''NFKD'''		,     _UpperCAmelCase       )
													__a	:  Optional[int]         =					''''''.join([c for c in outputs if not unicodedata.combining(_UpperCAmelCase       )]       )
									if self.do_lower_case:
													__a	:  Optional[Any]         =					outputs.lower()

									return outputs







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									__a	:  int         =					self.preprocess_text(_UpperCAmelCase       )
									__a	:  Tuple         =					self.sp_model.encode(_UpperCAmelCase		,     out_type=_UpperCAmelCase       )
									__a	:  int         =					[]
									for piece in pieces:
													if len(_UpperCAmelCase       ) > 1 and piece[-1] == str(''','''       ) and piece[-2].isdigit():
																	__a	:  List[str]         =					self.sp_model.EncodeAsPieces(piece[:-1].replace(_UpperCAmelCase		,     ''''''       )       )
																	if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
																					if len(cur_pieces[0]       ) == 1:
																									__a	:  Tuple         =					cur_pieces[1:]
																					else:
																									__a	:  Optional[Any]         =					cur_pieces[0][1:]
																	cur_pieces.append(piece[-1]       )
																	new_pieces.extend(_UpperCAmelCase       )
													else:
																	new_pieces.append(_UpperCAmelCase       )

									return new_pieces







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									return self.sp_model.PieceToId(_UpperCAmelCase       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									return self.sp_model.IdToPiece(_UpperCAmelCase       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									__a	:  List[str]         =					[]
									__a	:  str         =					''''''
									__a	:  Any         =					False
									for token in tokens:
													# make sure that special tokens are not decoded using sentencepiece model
													if token in self.all_special_tokens:
																	if not prev_is_special:
																					out_string += " "
																	out_string += self.sp_model.decode(_UpperCAmelCase       ) + token
																	__a	:  Tuple         =					True
																	__a	:  Tuple         =					[]
													else:
																	current_sub_tokens.append(_UpperCAmelCase       )
																	__a	:  Optional[int]         =					False
									out_string += self.sp_model.decode(_UpperCAmelCase       )
									return out_string.strip()







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = None       ):
									__a	:  int         =					[self.sep_token_id]
									__a	:  Union[str, Any]         =					[self.cls_token_id]
									if token_ids_a is None:
													return cls + token_ids_a + sep
									return cls + token_ids_a + sep + token_ids_a + sep







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = None		,     _UpperCAmelCase = False       ):

									if already_has_special_tokens:
													return super().get_special_tokens_mask(
													    token_ids_a=_UpperCAmelCase		,     token_ids_a=_UpperCAmelCase		,     already_has_special_tokens=_UpperCAmelCase       )

									if token_ids_a is not None:
													return [1] + ([0] * len(_UpperCAmelCase       )) + [1] + ([0] * len(_UpperCAmelCase       )) + [1]
									return [1] + ([0] * len(_UpperCAmelCase       )) + [1]







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = None       ):
									__a	:  Union[str, Any]         =					[self.sep_token_id]
									__a	:  Tuple         =					[self.cls_token_id]

									if token_ids_a is None:
													return len(cls + token_ids_a + sep       ) * [0]
									return len(cls + token_ids_a + sep       ) * [0] + len(token_ids_a + sep       ) * [1]







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase		,     _UpperCAmelCase = None       ):
									if not os.path.isdir(_UpperCAmelCase       ):
													logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""       )
													return
									__a	:  List[str]         =					os.path.join(
									    _UpperCAmelCase		,     (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']       )

									if os.path.abspath(self.vocab_file       ) != os.path.abspath(_UpperCAmelCase       ) and os.path.isfile(self.vocab_file       ):
													copyfile(self.vocab_file		,     _UpperCAmelCase       )
									elif not os.path.isfile(self.vocab_file       ):
													with open(_UpperCAmelCase		,     '''wb'''       ) as fi:
																	__a	:  Any         =					self.sp_model.serialized_model_proto()
																	fi.write(_UpperCAmelCase       )

									return (out_vocab_file,)