



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


__snake_case						:List[Any]						=					logging.get_logger(__name__)

__snake_case						:Union[str, Any]						=					{
    '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/config.json''',
    '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json''',
    '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/config.json''',
    '''funnel-transformer/medium-base''': '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json''',
    '''funnel-transformer/intermediate''': (
        '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json'''
    ),
    '''funnel-transformer/intermediate-base''': (
        '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json'''
    ),
    '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/config.json''',
    '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json''',
    '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json''',
    '''funnel-transformer/xlarge-base''': '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json''',
}

class    _A	(     __UpperCAmelCase   ):
       UpperCamelCase__  :   Dict						 =						'''funnel'''
       UpperCamelCase__  :   Any						 =						{
           '''hidden_size''': '''d_model''',
           '''num_attention_heads''': '''n_head''',
       }



       def __init__(		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Tuple=30_522					,		__SCREAMING_SNAKE_CASE							:					Union[str, Any]=[4, 4, 4]					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=None					,		__SCREAMING_SNAKE_CASE							:					Tuple=2					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=768					,		__SCREAMING_SNAKE_CASE							:					Dict=12					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=64					,		__SCREAMING_SNAKE_CASE							:					int=3_072					,		__SCREAMING_SNAKE_CASE							:					str="gelu_new"					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=0.1					,		__SCREAMING_SNAKE_CASE							:					Tuple=0.1					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=0.0					,		__SCREAMING_SNAKE_CASE							:					List[str]=0.1					,		__SCREAMING_SNAKE_CASE							:					str=None					,		__SCREAMING_SNAKE_CASE							:					Tuple=1E-9					,		__SCREAMING_SNAKE_CASE							:					List[str]="mean"					,		__SCREAMING_SNAKE_CASE							:					Optional[int]="relative_shift"					,		__SCREAMING_SNAKE_CASE							:					str=True					,		__SCREAMING_SNAKE_CASE							:					int=True					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=True					,		**__SCREAMING_SNAKE_CASE							:					Optional[Any]					,		):


           '''simple docstring'''

           __a							=    vocab_size
           __a							=    block_sizes
           __a							=    [1] * len(__SCREAMING_SNAKE_CASE) if block_repeats is None else block_repeats
           assert len(__SCREAMING_SNAKE_CASE) == len(
               self.block_repeats), "`block_sizes` and `block_repeats` should have the same length."
           __a							=    num_decoder_layers
           __a							=    d_model
           __a							=    n_head
           __a							=    d_head
           __a							=    d_inner
           __a							=    hidden_act
           __a							=    hidden_dropout
           __a							=    attention_dropout
           __a							=    activation_dropout
           __a							=    initializer_range
           __a							=    initializer_std
           __a							=    layer_norm_eps
           assert pooling_type in [
               "mean",
               "max",
           ], F'Got {pooling_type} for `pooling_type` but only \'mean\' and \'max\' are supported.'
           __a							=    pooling_type
           assert attention_type in [
               "relative_shift",
               "factorized",
           ], F'Got {attention_type} for `attention_type` but only \'relative_shift\' and \'factorized\' are supported.'
           __a							=    attention_type
           __a							=    separate_cls
           __a							=    truncate_seq
           __a							=    pool_q_only

           super().__init__(**__SCREAMING_SNAKE_CASE)



       @property
       def 		_lowerCamelCase      (		self							:					List[Any]):


           '''simple docstring'''

           return sum(self.block_sizes)



       @num_hidden_layers.setter
       def 		_lowerCamelCase      (		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Any):


           '''simple docstring'''

           raise NotImplementedError(
               '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.''')



       @property
       def 		_lowerCamelCase      (		self							:					Any):


           '''simple docstring'''

           return len(self.block_sizes)





       @num_blocks.setter
       def 		_lowerCamelCase      (		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]):


           '''simple docstring'''

           raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.''')










import os
import warnings
from typing import List, Optional

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


__snake_case						:int						=					logging.get_logger(__name__)

class    _A	:



       def __init__(		self							:					Any					,		__SCREAMING_SNAKE_CASE							:					Any					,		__SCREAMING_SNAKE_CASE							:					Optional[int]):


           '''simple docstring'''

           __a							=    question_encoder
           __a							=    generator
           __a							=    self.question_encoder



       def 		_lowerCamelCase      (		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Optional[int]):


           '''simple docstring'''

           if os.path.isfile(__SCREAMING_SNAKE_CASE):
               raise ValueError(F'Provided path ({save_directory}) should be a directory, not a file')
           os.makedirs(__SCREAMING_SNAKE_CASE					,		exist_ok=__SCREAMING_SNAKE_CASE)
           __a							=    os.path.join(__SCREAMING_SNAKE_CASE					,		'''question_encoder_tokenizer''')
           __a							=    os.path.join(__SCREAMING_SNAKE_CASE					,		'''generator_tokenizer''')
           self.question_encoder.save_pretrained(__SCREAMING_SNAKE_CASE)
           self.generator.save_pretrained(__SCREAMING_SNAKE_CASE)



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


           '''simple docstring'''

           from ..auto.tokenization_auto import AutoTokenizer

           __a							=    kwargs.pop('''config'''					,		__SCREAMING_SNAKE_CASE)

           if config is None:
               __a							=    RagConfig.from_pretrained(__SCREAMING_SNAKE_CASE)

           __a							=    AutoTokenizer.from_pretrained(
               __SCREAMING_SNAKE_CASE					,		config=config.question_encoder					,		subfolder='''question_encoder_tokenizer''')
           __a							=    AutoTokenizer.from_pretrained(
               __SCREAMING_SNAKE_CASE					,		config=config.generator					,		subfolder='''generator_tokenizer''')
           return cls(question_encoder=__SCREAMING_SNAKE_CASE					,		generator=__SCREAMING_SNAKE_CASE)



       def __call__(		self							:					Dict					,		*__SCREAMING_SNAKE_CASE							:					List[Any]					,		**__SCREAMING_SNAKE_CASE							:					List[Any]):


           '''simple docstring'''

           return self.current_tokenizer(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Optional[Any]					,		*__SCREAMING_SNAKE_CASE							:					Dict					,		**__SCREAMING_SNAKE_CASE							:					Any):


           '''simple docstring'''

           return self.generator.batch_decode(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Optional[int]					,		*__SCREAMING_SNAKE_CASE							:					List[str]					,		**__SCREAMING_SNAKE_CASE							:					List[str]):


           '''simple docstring'''

           return self.generator.decode(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					int):


           '''simple docstring'''

           __a							=    self.question_encoder



       def 		_lowerCamelCase      (		self							:					List[str]):


           '''simple docstring'''

           __a							=    self.generator





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


           '''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'''					,		__SCREAMING_SNAKE_CASE					,		)
           if max_length is None:
               __a							=    self.current_tokenizer.model_max_length
           __a							=    self(
               __SCREAMING_SNAKE_CASE					,		add_special_tokens=__SCREAMING_SNAKE_CASE					,		return_tensors=__SCREAMING_SNAKE_CASE					,		max_length=__SCREAMING_SNAKE_CASE					,		padding=__SCREAMING_SNAKE_CASE					,		truncation=__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE					,		)
           if tgt_texts is None:
               return model_inputs
           # Process tgt_texts
           if max_target_length is None:
               __a							=    self.current_tokenizer.model_max_length
           __a							=    self(
               text_target=__SCREAMING_SNAKE_CASE					,		add_special_tokens=__SCREAMING_SNAKE_CASE					,		return_tensors=__SCREAMING_SNAKE_CASE					,		padding=__SCREAMING_SNAKE_CASE					,		max_length=__SCREAMING_SNAKE_CASE					,		truncation=__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE					,		)
           __a							=    labels['''input_ids''']
           return model_inputs





