


from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers import (
           TFConvBertForMaskedLM,
           TFConvBertForMultipleChoice,
           TFConvBertForQuestionAnswering,
           TFConvBertForSequenceClassification,
           TFConvBertForTokenClassification,
           TFConvBertModel,
       )

class       __magic_name__	:


     def __init__(      self							:     List[str]							,	lowerCamelCase__							:     Tuple							,	lowerCamelCase__							:     str=13							,	lowerCamelCase__							:     Tuple=7							,	lowerCamelCase__							:     Optional[int]=True							,	lowerCamelCase__							:     int=True							,	lowerCamelCase__							:     Union[str, Any]=True							,	lowerCamelCase__							:     Dict=True							,	lowerCamelCase__							:     List[Any]=99							,	lowerCamelCase__							:     Optional[int]=32							,	lowerCamelCase__							:     int=2							,	lowerCamelCase__							:     str=4							,	lowerCamelCase__							:     Optional[Any]=37							,	lowerCamelCase__							:     str="gelu"							,	lowerCamelCase__							:     str=0.1							,	lowerCamelCase__							:     Union[str, Any]=0.1							,	lowerCamelCase__							:     Union[str, Any]=512							,	lowerCamelCase__							:     List[Any]=16							,	lowerCamelCase__							:     Optional[Any]=2							,	lowerCamelCase__							:     Any=0.02							,	lowerCamelCase__							:     Any=3							,	lowerCamelCase__							:     int=4							,	lowerCamelCase__							:     Any=None							,	)  ->      List[str]:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[int]          =   parent
      UpperCamelCase__					:    Union[str, Any]          =   13
      UpperCamelCase__					:    Union[str, Any]          =   7
      UpperCamelCase__					:    Dict          =   True
      UpperCamelCase__					:    Tuple          =   True
      UpperCamelCase__					:    Any          =   True
      UpperCamelCase__					:    str          =   True
      UpperCamelCase__					:    Tuple          =   99
      UpperCamelCase__					:    Union[str, Any]          =   384
      UpperCamelCase__					:    Tuple          =   2
      UpperCamelCase__					:    List[str]          =   4
      UpperCamelCase__					:    Optional[int]          =   37
      UpperCamelCase__					:    Any          =   '''gelu'''
      UpperCamelCase__					:    Any          =   0.1
      UpperCamelCase__					:    Optional[Any]          =   0.1
      UpperCamelCase__					:    Tuple          =   512
      UpperCamelCase__					:    Union[str, Any]          =   16
      UpperCamelCase__					:    List[str]          =   2
      UpperCamelCase__					:    Tuple          =   0.02
      UpperCamelCase__					:    Union[str, Any]          =   3
      UpperCamelCase__					:    List[Any]          =   4
      UpperCamelCase__					:    List[Any]          =   128
      UpperCamelCase__					:    Optional[Any]          =   2
      UpperCamelCase__					:    Dict          =   9
      UpperCamelCase__					:    Dict          =   1
      UpperCamelCase__					:    int          =   None


     def      UpperCAmelCase__	(      self							:     List[str]			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   ids_tensor([self.batch_size, self.seq_length]							,	self.vocab_size			)

      UpperCamelCase__					:    Union[str, Any]          =   None
      if self.use_input_mask:
       UpperCamelCase__					:    Any          =   random_attention_mask([self.batch_size, self.seq_length]			)

      UpperCamelCase__					:    Optional[Any]          =   None
      if self.use_token_type_ids:
       UpperCamelCase__					:    List[str]          =   ids_tensor([self.batch_size, self.seq_length]							,	self.type_vocab_size			)

      UpperCamelCase__					:    Any          =   None
      UpperCamelCase__					:    Optional[Any]          =   None
      UpperCamelCase__					:    Any          =   None
      if self.use_labels:
       UpperCamelCase__					:    List[Any]          =   ids_tensor([self.batch_size]							,	self.type_sequence_label_size			)
       UpperCamelCase__					:    int          =   ids_tensor([self.batch_size, self.seq_length]							,	self.num_labels			)
       UpperCamelCase__					:    List[str]          =   ids_tensor([self.batch_size]							,	self.num_choices			)

      UpperCamelCase__					:    int          =   ConvBertConfig(
          vocab_size=self.vocab_size							,	hidden_size=self.hidden_size							,	num_hidden_layers=self.num_hidden_layers							,	num_attention_heads=self.num_attention_heads							,	intermediate_size=self.intermediate_size							,	hidden_act=self.hidden_act							,	hidden_dropout_prob=self.hidden_dropout_prob							,	attention_probs_dropout_prob=self.attention_probs_dropout_prob							,	max_position_embeddings=self.max_position_embeddings							,	type_vocab_size=self.type_vocab_size							,	initializer_range=self.initializer_range							,	return_dict=lowerCamelCase__							,	)

      return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


     def      UpperCAmelCase__	(      self							:     Any							,	lowerCamelCase__							:     Tuple							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     int							,	lowerCamelCase__							:     Optional[int]							,	lowerCamelCase__							:     List[Any]			)  ->      int:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[Any]          =   TFConvBertModel(config=lowerCamelCase__			)
      UpperCamelCase__					:    Any          =   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

      UpperCamelCase__					:    Tuple          =   [input_ids, input_mask]
      UpperCamelCase__					:    Dict          =   model(lowerCamelCase__			)

      UpperCamelCase__					:    List[str]          =   model(lowerCamelCase__			)

      self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)			)


     def      UpperCAmelCase__	(      self							:     int							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Optional[int]							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     Tuple							,	lowerCamelCase__							:     Dict							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Dict			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    Dict          =   TFConvBertForMaskedLM(config=lowerCamelCase__			)
      UpperCamelCase__					:    Optional[int]          =   {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }
      UpperCamelCase__					:    Tuple          =   model(lowerCamelCase__			)
      self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.vocab_size)			)


     def      UpperCAmelCase__	(      self							:     Tuple							,	lowerCamelCase__							:     Optional[int]							,	lowerCamelCase__							:     str							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     List[str]			)  ->      int:





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   self.num_labels
      UpperCamelCase__					:    Optional[int]          =   TFConvBertForSequenceClassification(config=lowerCamelCase__			)
      UpperCamelCase__					:    Tuple          =   {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }

      UpperCamelCase__					:    Dict          =   model(lowerCamelCase__			)
      self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.num_labels)			)


     def      UpperCAmelCase__	(      self							:     Optional[int]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     str							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     Dict							,	lowerCamelCase__							:     Union[str, Any]			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    int          =   self.num_choices
      UpperCamelCase__					:    Optional[Any]          =   TFConvBertForMultipleChoice(config=lowerCamelCase__			)
      UpperCamelCase__					:    List[Any]          =   tf.tile(tf.expand_dims(lowerCamelCase__							,	1			)							,	(1, self.num_choices, 1)			)
      UpperCamelCase__					:    List[Any]          =   tf.tile(tf.expand_dims(lowerCamelCase__							,	1			)							,	(1, self.num_choices, 1)			)
      UpperCamelCase__					:    int          =   tf.tile(tf.expand_dims(lowerCamelCase__							,	1			)							,	(1, self.num_choices, 1)			)
      UpperCamelCase__					:    int          =   {
          '''input_ids''': multiple_choice_inputs_ids,
          '''attention_mask''': multiple_choice_input_mask,
          '''token_type_ids''': multiple_choice_token_type_ids,
      }
      UpperCamelCase__					:    Any          =   model(lowerCamelCase__			)
      self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.num_choices)			)


     def      UpperCAmelCase__	(      self							:     Optional[int]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     int							,	lowerCamelCase__							:     Optional[int]							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Dict							,	lowerCamelCase__							:     str			)  ->      Optional[int]:





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   self.num_labels
      UpperCamelCase__					:    Any          =   TFConvBertForTokenClassification(config=lowerCamelCase__			)
      UpperCamelCase__					:    Dict          =   {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }
      UpperCamelCase__					:    Dict          =   model(lowerCamelCase__			)
      self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.num_labels)			)


     def      UpperCAmelCase__	(      self							:     List[str]							,	lowerCamelCase__							:     int							,	lowerCamelCase__							:     List[Any]							,	lowerCamelCase__							:     List[Any]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     Optional[int]							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     Any			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    Dict          =   TFConvBertForQuestionAnswering(config=lowerCamelCase__			)
      UpperCamelCase__					:    List[str]          =   {
          '''input_ids''': input_ids,
          '''attention_mask''': input_mask,
          '''token_type_ids''': token_type_ids,
      }

      UpperCamelCase__					:    Optional[int]          =   model(lowerCamelCase__			)
      self.parent.assertEqual(result.start_logits.shape							,	(self.batch_size, self.seq_length)			)
      self.parent.assertEqual(result.end_logits.shape							,	(self.batch_size, self.seq_length)			)


     def      UpperCAmelCase__	(      self							:     int			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    int          =   self.prepare_config_and_inputs()
      (
          (
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				(
          UpperCamelCase__
      )       ,				
      )					:    List[Any]          =   config_and_inputs
      UpperCamelCase__					:    str          =   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
      return config, inputs_dict



@require_tf
class       __magic_name__	(     __lowerCAmelCase					,				__lowerCAmelCase					,				unittest.TestCase):
     A:		Dict			=      (
         (
             TFConvBertModel,
             TFConvBertForMaskedLM,
             TFConvBertForQuestionAnswering,
             TFConvBertForSequenceClassification,
             TFConvBertForTokenClassification,
             TFConvBertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     A:		List[Any]			=      (
         {
             "feature-extraction": TFConvBertModel,
             "fill-mask": TFConvBertForMaskedLM,
             "question-answering": TFConvBertForQuestionAnswering,
             "text-classification": TFConvBertForSequenceClassification,
             "token-classification": TFConvBertForTokenClassification,
             "zero-shot": TFConvBertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     A:		List[str]			=      False
     A:		int			=      False
     A:		List[Any]			=      False


     def      UpperCAmelCase__	(      self							:     Optional[Any]			)  ->      Dict:





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   TFConvBertModelTester(self			)
      UpperCamelCase__					:    str          =   ConfigTester(self							,	config_class=lowerCamelCase__							,	hidden_size=37			)


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      Optional[int]:





      '''simple docstring'''






      self.config_tester.run_common_tests()


     def      UpperCAmelCase__	(      self							:     str			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    str          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     Dict			)  ->      Dict:





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     str			)  ->      int:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[Any]          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     Optional[int]			)  ->      int:





      '''simple docstring'''






      UpperCamelCase__					:    Tuple          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     Union[str, Any]			)  ->      List[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    List[Any]          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      Union[str, Any]:





      '''simple docstring'''






      UpperCamelCase__					:    List[Any]          =   self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__			)


     @slow
     def      UpperCAmelCase__	(      self							:     Any			)  ->      Tuple:





      '''simple docstring'''






      UpperCamelCase__       ,				UpperCamelCase__					:    Tuple          =   self.model_tester.prepare_config_and_inputs_for_common()
      UpperCamelCase__					:    Union[str, Any]          =   True
      UpperCamelCase__					:    Optional[Any]          =   True

      if hasattr(lowerCamelCase__							,	'''use_cache'''			):
       UpperCamelCase__					:    int          =   True

      UpperCamelCase__					:    Dict          =   getattr(self.model_tester							,	'''encoder_seq_length'''							,	self.model_tester.seq_length			)
      UpperCamelCase__					:    List[str]          =   getattr(self.model_tester							,	'''key_length'''							,	lowerCamelCase__			)

      for model_class in self.all_model_classes:
       UpperCamelCase__					:    Tuple          =   self._prepare_for_class(lowerCamelCase__							,	lowerCamelCase__			)
       UpperCamelCase__					:    Union[str, Any]          =   model_class(lowerCamelCase__			)
       UpperCamelCase__					:    Any          =   len(model(lowerCamelCase__			)			)

       with tempfile.TemporaryDirectory() as tmpdirname:
        model.save_pretrained(lowerCamelCase__							,	saved_model=lowerCamelCase__			)
        UpperCamelCase__					:    Any          =   os.path.join(lowerCamelCase__							,	'''saved_model'''							,	'''1'''			)
        UpperCamelCase__					:    Any          =   tf.keras.models.load_model(lowerCamelCase__			)
        UpperCamelCase__					:    Union[str, Any]          =   model(lowerCamelCase__			)

        if self.is_encoder_decoder:
         UpperCamelCase__					:    int          =   outputs['''encoder_hidden_states''']
         UpperCamelCase__					:    List[Any]          =   outputs['''encoder_attentions''']
        else:
         UpperCamelCase__					:    Optional[Any]          =   outputs['''hidden_states''']
         UpperCamelCase__					:    Optional[int]          =   outputs['''attentions''']

        self.assertEqual(len(lowerCamelCase__			)							,	lowerCamelCase__			)

        UpperCamelCase__					:    List[Any]          =   getattr(
            self.model_tester							,	'''expected_num_hidden_layers'''							,	self.model_tester.num_hidden_layers + 1			)

        self.assertEqual(len(lowerCamelCase__			)							,	lowerCamelCase__			)
        self.assertListEqual(
            list(output_hidden_states[0].shape[-2:]			)							,	[self.model_tester.seq_length, self.model_tester.hidden_size]							,	)

        self.assertEqual(len(lowerCamelCase__			)							,	self.model_tester.num_hidden_layers			)
        self.assertListEqual(
            list(output_attentions[0].shape[-3:]			)							,	[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]							,	)


     @slow
     def      UpperCAmelCase__	(      self							:     Tuple			)  ->      Union[str, Any]:





      '''simple docstring'''






      UpperCamelCase__					:    str          =   TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''			)
      self.assertIsNotNone(lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     int			)  ->      int:





      '''simple docstring'''






      UpperCamelCase__       ,				UpperCamelCase__					:    int          =   self.model_tester.prepare_config_and_inputs_for_common()
      UpperCamelCase__					:    str          =   True
      UpperCamelCase__					:    Optional[int]          =   getattr(self.model_tester							,	'''decoder_seq_length'''							,	self.model_tester.seq_length			)
      UpperCamelCase__					:    str          =   getattr(self.model_tester							,	'''encoder_seq_length'''							,	self.model_tester.seq_length			)
      UpperCamelCase__					:    str          =   getattr(self.model_tester							,	'''key_length'''							,	lowerCamelCase__			)
      UpperCamelCase__					:    Dict          =   getattr(self.model_tester							,	'''key_length'''							,	lowerCamelCase__			)

      def check_decoder_attentions_output(lowerCamelCase__							:     Any			):
       UpperCamelCase__					:    Optional[int]          =   len(lowerCamelCase__			)
       self.assertEqual(out_len % 2							,	0			)
       UpperCamelCase__					:    List[str]          =   outputs.decoder_attentions
       self.assertEqual(len(lowerCamelCase__			)							,	self.model_tester.num_hidden_layers			)
       self.assertListEqual(
           list(decoder_attentions[0].shape[-3:]			)							,	[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]							,	)

      def check_encoder_attentions_output(lowerCamelCase__							:     Tuple			):
       UpperCamelCase__					:    Optional[int]          =   [
           t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
       ]
       self.assertEqual(len(lowerCamelCase__			)							,	self.model_tester.num_hidden_layers			)
       self.assertListEqual(
           list(attentions[0].shape[-3:]			)							,	[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]							,	)

      for model_class in self.all_model_classes:
       UpperCamelCase__					:    Union[str, Any]          =   True
       UpperCamelCase__					:    Optional[Any]          =   False
       UpperCamelCase__					:    str          =   model_class(lowerCamelCase__			)
       UpperCamelCase__					:    List[Any]          =   model(self._prepare_for_class(lowerCamelCase__							,	lowerCamelCase__			)			)
       UpperCamelCase__					:    str          =   len(lowerCamelCase__			)
       self.assertEqual(config.output_hidden_states							,	lowerCamelCase__			)
       check_encoder_attentions_output(lowerCamelCase__			)

       if self.is_encoder_decoder:
        UpperCamelCase__					:    Any          =   model_class(lowerCamelCase__			)
        UpperCamelCase__					:    int          =   model(self._prepare_for_class(lowerCamelCase__							,	lowerCamelCase__			)			)
        self.assertEqual(config.output_hidden_states							,	lowerCamelCase__			)
        check_decoder_attentions_output(lowerCamelCase__			)

       # Check that output attentions can also be changed via the config
       del inputs_dict["output_attentions"]
       UpperCamelCase__					:    Optional[Any]          =   True
       UpperCamelCase__					:    Any          =   model_class(lowerCamelCase__			)
       UpperCamelCase__					:    Tuple          =   model(self._prepare_for_class(lowerCamelCase__							,	lowerCamelCase__			)			)
       self.assertEqual(config.output_hidden_states							,	lowerCamelCase__			)
       check_encoder_attentions_output(lowerCamelCase__			)

       # Check attention is always last and order is fine
       UpperCamelCase__					:    List[str]          =   True
       UpperCamelCase__					:    int          =   True
       UpperCamelCase__					:    List[Any]          =   model_class(lowerCamelCase__			)
       UpperCamelCase__					:    int          =   model(self._prepare_for_class(lowerCamelCase__							,	lowerCamelCase__			)			)

       self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)							,	len(lowerCamelCase__			)			)
       self.assertEqual(model.config.output_hidden_states							,	lowerCamelCase__			)
       check_encoder_attentions_output(lowerCamelCase__			)



@require_tf
class       __magic_name__	(     unittest.TestCase):


     @slow
     def      UpperCAmelCase__	(      self							:     Optional[Any]			)  ->      Optional[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    Union[str, Any]          =   TFConvBertModel.from_pretrained('''YituTech/conv-bert-base'''			)
      UpperCamelCase__					:    Optional[int]          =   tf.constant([[0, 1, 2, 3, 4, 5]]			)
      UpperCamelCase__					:    Optional[Any]          =   model(lowerCamelCase__			)[0]

      UpperCamelCase__					:    Dict          =   [1, 6, 768]
      self.assertEqual(output.shape							,	lowerCamelCase__			)

      UpperCamelCase__					:    Tuple          =   tf.constant(
          [
              [
                  [-0.0347_5493, -0.468_6034, -0.3063_8832],
                  [0.2263_7248, -0.2698_8646, -0.742_3424],
                  [0.1032_4868, -0.4501_3508, -0.5828_0784],
              ]
          ]			)
      tf.debugging.assert_near(output[:, :3, :3]							,	lowerCamelCase__							,	atol=1E-4			)






from typing import TYPE_CHECKING

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


__UpperCamelCase       :       Optional[int]						       =				{
    "configuration_rag": ["RagConfig"],
    "retrieval_rag": ["RagRetriever"],
    "tokenization_rag": ["RagTokenizer"],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       Optional[int]						       =				[
           "RagModel",
           "RagPreTrainedModel",
           "RagSequenceForGeneration",
           "RagTokenForGeneration",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       List[Any]						       =				[
           "TFRagModel",
           "TFRagPreTrainedModel",
           "TFRagSequenceForGeneration",
           "TFRagTokenForGeneration",
       ]


if TYPE_CHECKING:
       from .configuration_rag import RagConfig
       from .retrieval_rag import RagRetriever
       from .tokenization_rag import RagTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_rag import RagModel, RagPreTrainedModel, RagSequenceForGeneration, RagTokenForGeneration

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_rag import (
                  TFRagModel,
                  TFRagPreTrainedModel,
                  TFRagSequenceForGeneration,
                  TFRagTokenForGeneration,
              )

else:
       import sys

       __UpperCamelCase       :       List[Any]						       =				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


