





"""simple docstring"""





import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    NezhaForMaskedLM,
							    NezhaForMultipleChoice,
							    NezhaForNextSentencePrediction,
							    NezhaForPreTraining,
							    NezhaForQuestionAnswering,
							    NezhaForSequenceClassification,
							    NezhaForTokenClassification,
							    NezhaModel,
							)
							from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST
class 		SCREAMING_SNAKE_CASE_				:
				"""simple docstring"""




				def __init__(  self	:Any    ,     __lowercase	:Dict    ,     __lowercase	:str=13    ,     __lowercase	:List[Any]=7    ,     __lowercase	:Dict=True    ,     __lowercase	:str=True    ,     __lowercase	:int=True    ,     __lowercase	:Any=True    ,     __lowercase	:Dict=99    ,     __lowercase	:Union[str, Any]=32    ,     __lowercase	:List[str]=5    ,     __lowercase	:Tuple=4    ,     __lowercase	:List[str]=37    ,     __lowercase	:Tuple="gelu"    ,     __lowercase	:Tuple=0.1    ,     __lowercase	:Union[str, Any]=0.1    ,     __lowercase	:Optional[Any]=128    ,     __lowercase	:List[str]=32    ,     __lowercase	:str=16    ,     __lowercase	:List[str]=2    ,     __lowercase	:Optional[Any]=0.02    ,     __lowercase	:Dict=3    ,     __lowercase	:int=4    ,     __lowercase	:Dict=None    ,     ):
											__lowerCamelCase   :   str       =parent
											__lowerCamelCase   :   Union[str, Any]       =batch_size
											__lowerCamelCase   :   str       =seq_length
											__lowerCamelCase   :   Any       =is_training
											__lowerCamelCase   :   Tuple       =use_input_mask
											__lowerCamelCase   :   Tuple       =use_token_type_ids
											__lowerCamelCase   :   str       =use_labels
											__lowerCamelCase   :   Optional[int]       =vocab_size
											__lowerCamelCase   :   int       =hidden_size
											__lowerCamelCase   :   Optional[int]       =num_hidden_layers
											__lowerCamelCase   :   Optional[Any]       =num_attention_heads
											__lowerCamelCase   :   int       =intermediate_size
											__lowerCamelCase   :   Optional[Any]       =hidden_act
											__lowerCamelCase   :   Optional[Any]       =hidden_dropout_prob
											__lowerCamelCase   :   List[str]       =attention_probs_dropout_prob
											__lowerCamelCase   :   Any       =max_position_embeddings
											__lowerCamelCase   :   Union[str, Any]       =type_vocab_size
											__lowerCamelCase   :   str       =type_sequence_label_size
											__lowerCamelCase   :   List[str]       =initializer_range
											__lowerCamelCase   :   Optional[int]       =num_labels
											__lowerCamelCase   :   Optional[int]       =num_choices
											__lowerCamelCase   :   Optional[int]       =scope




				def        __lowercase	(  self	:str      ):
											__lowerCamelCase   :   Any       =ids_tensor([self.batch_size, self.seq_length]    ,     self.vocab_size      )

											__lowerCamelCase   :   Optional[Any]       =None
											if self.use_input_mask:
																		__lowerCamelCase   :   Dict       =random_attention_mask([self.batch_size, self.seq_length]      )

											__lowerCamelCase   :   int       =None
											if self.use_token_type_ids:
																		__lowerCamelCase   :   Optional[Any]       =ids_tensor([self.batch_size, self.seq_length]    ,     self.type_vocab_size      )

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

											__lowerCamelCase   :   List[str]       =self.get_config()

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




				def        __lowercase	(  self	:Tuple      ):
											return NezhaConfig(
											    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    ,     is_decoder=__lowercase    ,     initializer_range=self.initializer_range    ,     )




				def        __lowercase	(  self	:int      ):
											(
											    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    
											)   :   int       =self.prepare_config_and_inputs()

											__lowerCamelCase   :   Optional[int]       =True
											__lowerCamelCase   :   str       =floats_tensor([self.batch_size, self.seq_length, self.hidden_size]      )
											__lowerCamelCase   :   Dict       =ids_tensor([self.batch_size, self.seq_length]    ,     vocab_size=2      )

											return (
											    config,
											    input_ids,
											    token_type_ids,
											    input_mask,
											    sequence_labels,
											    token_labels,
											    choice_labels,
											    encoder_hidden_states,
											    encoder_attention_mask,
											)




				def        __lowercase	(  self	:Optional[Any]    ,     __lowercase	:Dict    ,     __lowercase	:str    ,     __lowercase	:int    ,     __lowercase	:Union[str, Any]    ,     __lowercase	:List[str]    ,     __lowercase	:Dict    ,     __lowercase	:Dict      ):
											__lowerCamelCase   :   List[Any]       =NezhaModel(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   List[str]       =model(__lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase      )
											__lowerCamelCase   :   str       =model(__lowercase    ,     token_type_ids=__lowercase      )
											__lowerCamelCase   :   Any       =model(__lowercase      )
											self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.hidden_size)      )
											self.parent.assertEqual(result.pooler_output.shape    ,     (self.batch_size, self.hidden_size)      )




				def        __lowercase	(  self	:List[Any]    ,     __lowercase	:List[str]    ,     __lowercase	:Optional[Any]    ,     __lowercase	:str    ,     __lowercase	:int    ,     __lowercase	:List[str]    ,     __lowercase	:Dict    ,     __lowercase	:List[Any]    ,     __lowercase	:str    ,     __lowercase	:Tuple    ,     ):
											__lowerCamelCase   :   Any       =True
											__lowerCamelCase   :   Optional[Any]       =NezhaModel(__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Optional[Any]       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     encoder_hidden_states=__lowercase    ,     encoder_attention_mask=__lowercase    ,     )
											__lowerCamelCase   :   Dict       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     encoder_hidden_states=__lowercase    ,     )
											__lowerCamelCase   :   Tuple       =model(__lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase      )
											self.parent.assertEqual(result.last_hidden_state.shape    ,     (self.batch_size, self.seq_length, self.hidden_size)      )
											self.parent.assertEqual(result.pooler_output.shape    ,     (self.batch_size, self.hidden_size)      )




				def        __lowercase	(  self	:Optional[int]    ,     __lowercase	:int    ,     __lowercase	:Dict    ,     __lowercase	:Any    ,     __lowercase	:Optional[Any]    ,     __lowercase	:Union[str, Any]    ,     __lowercase	:Optional[int]    ,     __lowercase	:int      ):
											__lowerCamelCase   :   Optional[Any]       =NezhaForMaskedLM(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Union[str, Any]       =model(__lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase      )
											self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length, self.vocab_size)      )




				def        __lowercase	(  self	:Optional[Any]    ,     __lowercase	:List[Any]    ,     __lowercase	:Any    ,     __lowercase	:int    ,     __lowercase	:Dict    ,     __lowercase	:Any    ,     __lowercase	:Optional[int]    ,     __lowercase	:Tuple      ):
											__lowerCamelCase   :   Tuple       =NezhaForNextSentencePrediction(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Any       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase    ,     )
											self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, 2)      )




				def        __lowercase	(  self	:Dict    ,     __lowercase	:List[Any]    ,     __lowercase	:str    ,     __lowercase	:Optional[int]    ,     __lowercase	:Tuple    ,     __lowercase	:Union[str, Any]    ,     __lowercase	:Any    ,     __lowercase	:Dict      ):
											__lowerCamelCase   :   Union[str, Any]       =NezhaForPreTraining(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Optional[Any]       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase    ,     next_sentence_label=__lowercase    ,     )
											self.parent.assertEqual(result.prediction_logits.shape    ,     (self.batch_size, self.seq_length, self.vocab_size)      )
											self.parent.assertEqual(result.seq_relationship_logits.shape    ,     (self.batch_size, 2)      )




				def        __lowercase	(  self	:Tuple    ,     __lowercase	:Optional[int]    ,     __lowercase	:str    ,     __lowercase	:Optional[Any]    ,     __lowercase	:Dict    ,     __lowercase	:Union[str, Any]    ,     __lowercase	:Dict    ,     __lowercase	:Union[str, Any]      ):
											__lowerCamelCase   :   List[Any]       =NezhaForQuestionAnswering(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   int       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     start_positions=__lowercase    ,     end_positions=__lowercase    ,     )
											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        __lowercase	(  self	:Any    ,     __lowercase	:Any    ,     __lowercase	:Tuple    ,     __lowercase	:Optional[int]    ,     __lowercase	:Optional[int]    ,     __lowercase	:Optional[Any]    ,     __lowercase	:Optional[int]    ,     __lowercase	:Tuple      ):
											__lowerCamelCase   :   List[str]       =self.num_labels
											__lowerCamelCase   :   Tuple       =NezhaForSequenceClassification(__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Optional[Any]       =model(__lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase      )
											self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.num_labels)      )




				def        __lowercase	(  self	:Dict    ,     __lowercase	:int    ,     __lowercase	:List[str]    ,     __lowercase	:List[str]    ,     __lowercase	:Union[str, Any]    ,     __lowercase	:int    ,     __lowercase	:Optional[Any]    ,     __lowercase	:Optional[Any]      ):
											__lowerCamelCase   :   Optional[Any]       =self.num_labels
											__lowerCamelCase   :   Dict       =NezhaForTokenClassification(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   Optional[Any]       =model(__lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase      )
											self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.seq_length, self.num_labels)      )




				def        __lowercase	(  self	:Optional[int]    ,     __lowercase	:List[Any]    ,     __lowercase	:List[Any]    ,     __lowercase	:Any    ,     __lowercase	:Any    ,     __lowercase	:List[str]    ,     __lowercase	:List[str]    ,     __lowercase	:List[Any]      ):
											__lowerCamelCase   :   Tuple       =self.num_choices
											__lowerCamelCase   :   Optional[int]       =NezhaForMultipleChoice(config=__lowercase      )
											model.to(__lowercase      )
											model.eval()
											__lowerCamelCase   :   int       =input_ids.unsqueeze(1      ).expand(-1    ,     self.num_choices    ,     -1      ).contiguous()
											__lowerCamelCase   :   Optional[int]       =token_type_ids.unsqueeze(1      ).expand(-1    ,     self.num_choices    ,     -1      ).contiguous()
											__lowerCamelCase   :   List[str]       =input_mask.unsqueeze(1      ).expand(-1    ,     self.num_choices    ,     -1      ).contiguous()
											__lowerCamelCase   :   Dict       =model(
											    __lowercase    ,     attention_mask=__lowercase    ,     token_type_ids=__lowercase    ,     labels=__lowercase    ,     )
											self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.num_choices)      )




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

@require_torch
class 		SCREAMING_SNAKE_CASE_				(     snake_case__							,	snake_case__							,	snake_case__							,	unittest.TestCase ):
				"""simple docstring"""
				__snake_case :							Dict									=		(
				    (
				        NezhaModel,
				        NezhaForMaskedLM,
				        NezhaForMultipleChoice,
				        NezhaForNextSentencePrediction,
				        NezhaForPreTraining,
				        NezhaForQuestionAnswering,
				        NezhaForSequenceClassification,
				        NezhaForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				__snake_case :							int									=		(
				    {
				        """feature-extraction""": NezhaModel,
				        """fill-mask""": NezhaForMaskedLM,
				        """question-answering""": NezhaForQuestionAnswering,
				        """text-classification""": NezhaForSequenceClassification,
				        """token-classification""": NezhaForTokenClassification,
				        """zero-shot""": NezhaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				__snake_case :							List[str]									=		True




				def        __lowercase	(  self	:List[str]    ,     __lowercase	:Optional[int]    ,     __lowercase	:str    ,     __lowercase	:Optional[Any]=False      ):
											__lowerCamelCase   :   Union[str, Any]       =super()._prepare_for_class(__lowercase    ,     __lowercase    ,     return_labels=__lowercase      )

											if return_labels:
																		if model_class in get_values(__lowercase      ):
																									__lowerCamelCase   :   Any       =torch.zeros(
																									    (self.model_tester.batch_size, self.model_tester.seq_length)    ,     dtype=torch.long    ,     device=__lowercase      )
																									__lowerCamelCase   :   Any       =torch.zeros(
																									    self.model_tester.batch_size    ,     dtype=torch.long    ,     device=__lowercase      )
											return inputs_dict




				def        __lowercase	(  self	:Union[str, Any]      ):
											__lowerCamelCase   :   Tuple       =NezhaModelTester(self      )
											__lowerCamelCase   :   Tuple       =ConfigTester(self    ,     config_class=__lowercase    ,     hidden_size=37      )




				def        __lowercase	(  self	:int      ):
											self.config_tester.run_common_tests()




				def        __lowercase	(  self	:int      ):
											__lowerCamelCase   :   List[str]       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__lowercase      )




				def        __lowercase	(  self	:Tuple      ):
											__lowerCamelCase   :   Optional[Any]       =self.model_tester.prepare_config_and_inputs_for_decoder()
											self.model_tester.create_and_check_model_as_decoder(*__lowercase      )




				def        __lowercase	(  self	:Any      ):
											# This regression test was failing with PyTorch < 1.3
											(
											    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    (
											    __lowerCamelCase
											)     ,    
											)   :   Dict       =self.model_tester.prepare_config_and_inputs_for_decoder()

											__lowerCamelCase   :   Union[str, Any]       =None

											self.model_tester.create_and_check_model_as_decoder(
											    __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     __lowercase    ,     )




				def        __lowercase	(  self	:List[Any]      ):
											__lowerCamelCase   :   Dict       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__lowercase      )




				def        __lowercase	(  self	:Tuple      ):
											__lowerCamelCase   :   List[str]       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_multiple_choice(*__lowercase      )




				def        __lowercase	(  self	:str      ):
											__lowerCamelCase   :   Tuple       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_next_sequence_prediction(*__lowercase      )




				def        __lowercase	(  self	:Any      ):
											__lowerCamelCase   :   List[Any]       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_pretraining(*__lowercase      )




				def        __lowercase	(  self	:Optional[Any]      ):
											__lowerCamelCase   :   Tuple       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*__lowercase      )




				def        __lowercase	(  self	:Optional[int]      ):
											__lowerCamelCase   :   Tuple       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*__lowercase      )




				def        __lowercase	(  self	:Union[str, Any]      ):
											__lowerCamelCase   :   Optional[Any]       =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__lowercase      )




				@slow
				def        __lowercase	(  self	:Optional[Any]      ):
											for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowerCamelCase   :   Tuple       =NezhaModel.from_pretrained(__lowercase      )
																		self.assertIsNotNone(__lowercase      )




				@slow
				@require_torch_gpu
				def        __lowercase	(  self	:Optional[int]      ):
											__lowerCamelCase     ,    __lowerCamelCase   :   List[str]       =self.model_tester.prepare_config_and_inputs_for_common()
											for model_class in self.all_model_classes:
																		# NezhaForMultipleChoice behaves incorrectly in JIT environments.
																		if model_class == NezhaForMultipleChoice:
																									return

																		__lowerCamelCase   :   Optional[Any]       =True
																		__lowerCamelCase   :   Optional[Any]       =model_class(config=__lowercase      )

																		__lowerCamelCase   :   int       =self._prepare_for_class(__lowercase    ,     __lowercase      )
																		__lowerCamelCase   :   Tuple       =torch.jit.trace(
																		    __lowercase    ,     (inputs_dict['''input_ids'''].to('''cpu'''      ), inputs_dict['''attention_mask'''].to('''cpu'''      ))      )

																		with tempfile.TemporaryDirectory() as tmp:
																									torch.jit.save(__lowercase    ,     os.path.join(__lowercase    ,     '''bert.pt'''      )      )
																									__lowerCamelCase   :   Any       =torch.jit.load(os.path.join(__lowercase    ,     '''bert.pt'''      )    ,     map_location=__lowercase      )
																									loaded(inputs_dict['''input_ids'''].to(__lowercase      )    ,     inputs_dict['''attention_mask'''].to(__lowercase      )      )

@require_torch
class 		SCREAMING_SNAKE_CASE_				(     unittest.TestCase ):
				"""simple docstring"""




				@slow
				def        __lowercase	(  self	:Union[str, Any]      ):
											__lowerCamelCase   :   str       =NezhaModel.from_pretrained('''sijunhe/nezha-cn-base'''      )
											__lowerCamelCase   :   Dict       =torch.tensor([[0, 1, 2, 3, 4, 5]]      )
											__lowerCamelCase   :   Union[str, Any]       =torch.tensor([[0, 1, 1, 1, 1, 1]]      )
											with torch.no_grad():
																		__lowerCamelCase   :   str       =model(__lowercase    ,     attention_mask=__lowercase      )[0]
											__lowerCamelCase   :   Optional[Any]       =torch.Size((1, 6, 768)      )
											self.assertEqual(output.shape    ,     __lowercase      )
											__lowerCamelCase   :   Dict       =torch.tensor([[[0.0685, 0.2441, 0.1102], [0.0600, 0.1906, 0.1349], [0.0221, 0.0819, 0.0586]]]      )

											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,     __lowercase    ,     atol=1e-4      )      )




				@slow
				def        __lowercase	(  self	:Union[str, Any]      ):
											__lowerCamelCase   :   Optional[int]       =NezhaForMaskedLM.from_pretrained('''sijunhe/nezha-cn-base'''      )
											__lowerCamelCase   :   Tuple       =torch.tensor([[0, 1, 2, 3, 4, 5]]      )
											__lowerCamelCase   :   Optional[int]       =torch.tensor([[1, 1, 1, 1, 1, 1]]      )
											with torch.no_grad():
																		__lowerCamelCase   :   Optional[Any]       =model(__lowercase    ,     attention_mask=__lowercase      )[0]
											__lowerCamelCase   :   Tuple       =torch.Size((1, 6, 2_1128)      )
											self.assertEqual(output.shape    ,     __lowercase      )
											__lowerCamelCase   :   Tuple       =torch.tensor(
											    [[-2.7939, -1.7902, -2.2189], [-2.8585, -1.8908, -2.3723], [-2.6499, -1.7750, -2.2558]]      )

											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,     __lowercase    ,     atol=1e-4      )      )











"""simple docstring"""





# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool
class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							int									=		"""philschmid/bart-large-cnn-samsum"""
				__snake_case :							Optional[int]									=		(
				    """This is a tool that summarizes an English text. It takes an input `text` containing the text to summarize, """
				    """and returns a summary of the text."""
				)
				__snake_case :							Dict									=		"""summarizer"""
				__snake_case :							str									=		AutoTokenizer
				__snake_case :							List[str]									=		AutoModelForSeqaSeqLM

				__snake_case :							List[Any]									=		["""text"""]
				__snake_case :							Dict									=		["""text"""]




				def        __lowercase	(  self	:int    ,     __lowercase	:List[Any]      ):
											return self.pre_processor(__lowercase    ,     return_tensors='''pt'''    ,     truncation=__lowercase      )




				def        __lowercase	(  self	:Optional[int]    ,     __lowercase	:Optional[int]      ):
											return self.model.generate(**__lowercase      )[0]




				def        __lowercase	(  self	:List[Any]    ,     __lowercase	:str      ):
											return self.pre_processor.decode(__lowercase    ,     skip_special_tokens=__lowercase    ,     clean_up_tokenization_spaces=__lowercase      )




