


import os
import warnings
from typing import List, Optional

from ...tokenization_utils_base import BatchEncoding
from ...utils import logging
from .configuration_rag import RagConfig


__UpperCamelCase				:  Dict      					=							logging.get_logger(__name__)





class  lowerCAmelCase__:






    '''simple docstring'''





    def __init__(	self				:   Optional[Any]       ,   __snake_case				:   Union[str, Any]       ,   __snake_case				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   question_encoder
       UpperCAmelCase_							:      Dict						=   generator
       UpperCAmelCase_							:      List[Any]						=   self.question_encoder





    def 					_lowerCamelCase (	self				:   Optional[int]       ,   __snake_case				:   int	):





       '''simple docstring'''
       if os.path.isfile(__snake_case	):
          raise ValueError(f'''Provided path ({save_directory}) should be a directory, not a file'''	)
       os.makedirs(__snake_case       ,   exist_ok=__snake_case	)
       UpperCAmelCase_							:      Dict						=   os.path.join(__snake_case       ,   '''question_encoder_tokenizer'''	)
       UpperCAmelCase_							:      Any						=   os.path.join(__snake_case       ,   '''generator_tokenizer'''	)
       self.question_encoder.save_pretrained(__snake_case	)
       self.generator.save_pretrained(__snake_case	)





    @classmethod
    def 					_lowerCamelCase (	cls				:   List[Any]       ,   __snake_case				:   Optional[int]       ,   **__snake_case				:   int	):





       '''simple docstring'''
       # dynamically import AutoTokenizer
       from ..auto.tokenization_auto import AutoTokenizer

       UpperCAmelCase_							:      str						=   kwargs.pop('''config'''       ,   __snake_case	)

       if config is None:
          UpperCAmelCase_							:      Tuple						=   RagConfig.from_pretrained(__snake_case	)

       UpperCAmelCase_							:      Any						=   AutoTokenizer.from_pretrained(
           __snake_case       ,   config=config.question_encoder       ,   subfolder='''question_encoder_tokenizer'''	)
       UpperCAmelCase_							:      Any						=   AutoTokenizer.from_pretrained(
           __snake_case       ,   config=config.generator       ,   subfolder='''generator_tokenizer'''	)
       return cls(question_encoder=__snake_case       ,   generator=__snake_case	)





    def __call__(	self				:   Optional[int]       ,   *__snake_case				:   List[Any]       ,   **__snake_case				:   int	):





       '''simple docstring'''
       return self.current_tokenizer(*__snake_case       ,   **__snake_case	)





    def 					_lowerCamelCase (	self				:   int       ,   *__snake_case				:   str       ,   **__snake_case				:   List[Any]	):





       '''simple docstring'''
       return self.generator.batch_decode(*__snake_case       ,   **__snake_case	)





    def 					_lowerCamelCase (	self				:   Optional[Any]       ,   *__snake_case				:   List[str]       ,   **__snake_case				:   Optional[Any]	):





       '''simple docstring'''
       return self.generator.decode(*__snake_case       ,   **__snake_case	)





    def 					_lowerCamelCase (	self				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   self.question_encoder





    def 					_lowerCamelCase (	self				:   List[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.generator





    def 					_lowerCamelCase (	self				:   List[Any]       ,   __snake_case				:   List[str]       ,   __snake_case				:   Optional[List[str]] = None       ,   __snake_case				:   Optional[int] = None       ,   __snake_case				:   Optional[int] = None       ,   __snake_case				:   str = "longest"       ,   __snake_case				:   str = None       ,   __snake_case				:   bool = True       ,   **__snake_case				:   Any       ,   ):





       '''simple docstring'''
       warnings.warn(
           '''`prepare_seq2seq_batch` is deprecated and will be removed in version 5 of 🤗 Transformers. Use the '''
           '''regular `__call__` method to prepare your inputs and the tokenizer under the `with_target_tokenizer` '''
           '''context manager to prepare your targets. See the documentation of your specific tokenizer for more '''
           '''details'''       ,   __snake_case       ,   )
       if max_length is None:
          UpperCAmelCase_							:      Optional[int]						=   self.current_tokenizer.model_max_length
       UpperCAmelCase_							:      Any						=   self(
           __snake_case       ,   add_special_tokens=__snake_case       ,   return_tensors=__snake_case       ,   max_length=__snake_case       ,   padding=__snake_case       ,   truncation=__snake_case       ,   **__snake_case       ,   )
       if tgt_texts is None:
          return model_inputs
       # Process tgt_texts
       if max_target_length is None:
          UpperCAmelCase_							:      Optional[Any]						=   self.current_tokenizer.model_max_length
       UpperCAmelCase_							:      int						=   self(
           text_target=__snake_case       ,   add_special_tokens=__snake_case       ,   return_tensors=__snake_case       ,   padding=__snake_case       ,   max_length=__snake_case       ,   truncation=__snake_case       ,   **__snake_case       ,   )
       UpperCAmelCase_							:      List[str]						=   labels['''input_ids''']
       return model_inputs



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


__UpperCamelCase				:  Any      					=							logging.get_logger(__name__)

__UpperCamelCase				:  Dict      					=							{
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     List[str]			= 'gpt_bigcode'
    A_  :     Optional[Any]			= ['past_key_values']
    A_  :     Optional[int]			= {
        'hidden_size': 'n_embd',
        'max_position_embeddings': 'n_positions',
        'num_attention_heads': 'n_head',
        'num_hidden_layers': 'n_layer',
    }





    def __init__(	self				:   int       ,   __snake_case				:   Dict=50_257       ,   __snake_case				:   List[str]=1_024       ,   __snake_case				:   Dict=768       ,   __snake_case				:   Optional[int]=12       ,   __snake_case				:   str=12       ,   __snake_case				:   List[str]=None       ,   __snake_case				:   List[str]="gelu_pytorch_tanh"       ,   __snake_case				:   Optional[Any]=0.1       ,   __snake_case				:   str=0.1       ,   __snake_case				:   Optional[Any]=0.1       ,   __snake_case				:   List[str]=1E-5       ,   __snake_case				:   Dict=0.02       ,   __snake_case				:   Optional[int]=True       ,   __snake_case				:   Tuple=True       ,   __snake_case				:   Optional[Any]=50_256       ,   __snake_case				:   Optional[Any]=50_256       ,   __snake_case				:   Optional[Any]=True       ,   __snake_case				:   Optional[Any]=True       ,   __snake_case				:   List[Any]=True       ,   **__snake_case				:   List[str]       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   vocab_size
       UpperCAmelCase_							:      int						=   n_positions
       UpperCAmelCase_							:      Any						=   n_embd
       UpperCAmelCase_							:      Union[str, Any]						=   n_layer
       UpperCAmelCase_							:      List[str]						=   n_head
       UpperCAmelCase_							:      List[Any]						=   n_inner
       UpperCAmelCase_							:      Optional[int]						=   activation_function
       UpperCAmelCase_							:      str						=   resid_pdrop
       UpperCAmelCase_							:      Optional[Any]						=   embd_pdrop
       UpperCAmelCase_							:      str						=   attn_pdrop
       UpperCAmelCase_							:      Any						=   layer_norm_epsilon
       UpperCAmelCase_							:      List[str]						=   initializer_range
       UpperCAmelCase_							:      Optional[int]						=   scale_attn_weights
       UpperCAmelCase_							:      Union[str, Any]						=   use_cache
       UpperCAmelCase_							:      Dict						=   attention_softmax_in_fpaa
       UpperCAmelCase_							:      Union[str, Any]						=   scale_attention_softmax_in_fpaa
       UpperCAmelCase_							:      Optional[int]						=   multi_query

       UpperCAmelCase_							:      Optional[Any]						=   bos_token_id
       UpperCAmelCase_							:      Tuple						=   eos_token_id

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