


__lowerCAmelCase			=							2_56
# Modulus to hash a string
__lowerCAmelCase			=							1_00_00_03




def        snake_case_					(  snake_case      ,							snake_case					)  ->    bool:
       lowercase__:       List[Any]        =       len(snake_case					)
       lowercase__:       int        =       len(snake_case					)
       if p_len > t_len:
              return False

       lowercase__:       Tuple        =       0
       lowercase__:       Union[str, Any]        =       0
       lowercase__:       Tuple        =       1

       # Calculating the hash of pattern and substring of text
       for i in range(snake_case					):
              lowercase__:       str        =       (ord(pattern[i]					) + p_hash * alphabet_size) % modulus
              lowercase__:       int        =       (ord(text[i]					) + text_hash * alphabet_size) % modulus
              if i == p_len - 1:
                     continue
              lowercase__:       Optional[Any]        =       (modulus_power * alphabet_size) % modulus

       for i in range(0      ,							t_len - p_len + 1					):
              if text_hash == p_hash and text[i : i + p_len] == pattern:
                     return True
              if i == t_len - p_len:
                     continue
              # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
              lowercase__:       Dict        =       (
                  (text_hash - ord(text[i]					) * modulus_power) * alphabet_size
                  + ord(text[i + p_len]					)
              ) % modulus
       return False




def        snake_case_					(  )  ->    None:
       lowercase__:       Tuple        =       'abc1abc12'
       lowercase__:       Optional[Any]        =       'alskfjaldsabc1abc1abc12k23adsfabcabc'
       lowercase__:       Dict        =       'alskfjaldsk23adsfabcabc'
       assert rabin_karp(snake_case      ,							snake_case					) and not rabin_karp(snake_case      ,							snake_case					)

       # Test 2)
       lowercase__:       Optional[Any]        =       'ABABX'
       lowercase__:       Any        =       'ABABZABABYABABX'
       assert rabin_karp(snake_case      ,							snake_case					)

       # Test 3)
       lowercase__:       int        =       'AAAB'
       lowercase__:       str        =       'ABAAAAAB'
       assert rabin_karp(snake_case      ,							snake_case					)

       # Test 4)
       lowercase__:       List[Any]        =       'abcdabcy'
       lowercase__:       Optional[Any]        =       'abcxabcdabxabcdabcdabcy'
       assert rabin_karp(snake_case      ,							snake_case					)

       # Test 5)
       lowercase__:       Union[str, Any]        =       'Lü'
       lowercase__:       List[Any]        =       'Lüsai'
       assert rabin_karp(snake_case      ,							snake_case					)
       lowercase__:       List[Any]        =       'Lue'
       assert not rabin_karp(snake_case      ,							snake_case					)
       print('Success.'					)


if __name__ == "__main__":
 test_rabin_karp()






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   __a      :
 def __init__(       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__=13    ,			lowerCAmelCase__=7    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=99    ,			lowerCAmelCase__=32    ,			lowerCAmelCase__=5    ,			lowerCAmelCase__=4    ,			lowerCAmelCase__=37    ,			lowerCAmelCase__="gelu"    ,			lowerCAmelCase__=0.1    ,			lowerCAmelCase__=0.1    ,			lowerCAmelCase__=128    ,			lowerCAmelCase__=32    ,			lowerCAmelCase__=16    ,			lowerCAmelCase__=2    ,			lowerCAmelCase__=0.0_2    ,			lowerCAmelCase__=3    ,			lowerCAmelCase__=4    ,			lowerCAmelCase__=None    ,			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       parent
        lowercase__:       str        =       batch_size
        lowercase__:       Dict        =       seq_length
        lowercase__:       str        =       is_training
        lowercase__:       List[str]        =       use_input_mask
        lowercase__:       str        =       use_token_type_ids
        lowercase__:       Tuple        =       use_labels
        lowercase__:       int        =       vocab_size
        lowercase__:       Dict        =       hidden_size
        lowercase__:       Tuple        =       num_hidden_layers
        lowercase__:       Tuple        =       num_attention_heads
        lowercase__:       List[Any]        =       intermediate_size
        lowercase__:       Dict        =       hidden_act
        lowercase__:       List[str]        =       hidden_dropout_prob
        lowercase__:       str        =       attention_probs_dropout_prob
        lowercase__:       Dict        =       max_position_embeddings
        lowercase__:       Optional[Any]        =       type_vocab_size
        lowercase__:       List[str]        =       type_sequence_label_size
        lowercase__:       Optional[int]        =       initializer_range
        lowercase__:       Optional[int]        =       num_labels
        lowercase__:       Union[str, Any]        =       num_choices
        lowercase__:       int        =       scope
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       Dict        =       ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size			)

        lowercase__:       List[str]        =       None
        if self.use_input_mask:
               lowercase__:       Tuple        =       random_attention_mask([self.batch_size, self.seq_length]			)

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

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

        lowercase__:       Dict        =       self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        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=lowerCAmelCase__    ,			initializer_range=self.initializer_range    ,			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        (
            (
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						
        ):       Tuple        =       self.prepare_config_and_inputs()

        lowercase__:       Optional[int]        =       True
        lowercase__:       Optional[int]        =       floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
        lowercase__:       Union[str, Any]        =       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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    int:




        '''simple docstring'''
        lowercase__:       List[Any]        =       NezhaModel(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       Dict        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__			)
        lowercase__:       Union[str, Any]        =       model(lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__			)
        lowercase__:       str        =       model(lowerCAmelCase__			)
        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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       Dict        =       True
        lowercase__:       Optional[Any]        =       NezhaModel(lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       List[Any]        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			encoder_hidden_states=lowerCAmelCase__    ,			encoder_attention_mask=lowerCAmelCase__    ,			)
        lowercase__:       str        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			encoder_hidden_states=lowerCAmelCase__    ,			)
        lowercase__:       List[str]        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__			)
        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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Any:




        '''simple docstring'''
        lowercase__:       Tuple        =       NezhaForMaskedLM(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       int        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size)			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    List[str]:




        '''simple docstring'''
        lowercase__:       Any        =       NezhaForNextSentencePrediction(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       int        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__    ,			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, 2)			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    List[str]:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       NezhaForPreTraining(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       List[str]        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__    ,			next_sentence_label=lowerCAmelCase__    ,			)
        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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       List[Any]        =       NezhaForQuestionAnswering(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       List[Any]        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			start_positions=lowerCAmelCase__    ,			end_positions=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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       Optional[Any]        =       self.num_labels
        lowercase__:       List[Any]        =       NezhaForSequenceClassification(lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       Union[str, Any]        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels)			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       self.num_labels
        lowercase__:       Dict        =       NezhaForTokenClassification(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       List[str]        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels)			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Dict:




        '''simple docstring'''
        lowercase__:       List[str]        =       self.num_choices
        lowercase__:       str        =       NezhaForMultipleChoice(config=lowerCAmelCase__			)
        model.to(lowerCAmelCase__			)
        model.eval()
        lowercase__:       Optional[Any]        =       input_ids.unsqueeze(1			).expand(-1    ,			self.num_choices    ,			-1			).contiguous()
        lowercase__:       Optional[Any]        =       token_type_ids.unsqueeze(1			).expand(-1    ,			self.num_choices    ,			-1			).contiguous()
        lowercase__:       Optional[Any]        =       input_mask.unsqueeze(1			).expand(-1    ,			self.num_choices    ,			-1			).contiguous()
        lowercase__:       int        =       model(
            lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__    ,			token_type_ids=lowerCAmelCase__    ,			labels=lowerCAmelCase__    ,			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices)			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        lowercase__:       str        =       self.prepare_config_and_inputs()
        (
            (
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						
        ):       str        =       config_and_inputs
        lowercase__:       Union[str, Any]        =       {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
        return config, inputs_dict





@require_torch
class   __a      (   __UpperCamelCase	,	__UpperCamelCase	,	__UpperCamelCase	,	unittest.TestCase				):
 __lowercase			:							List[Any]       					=			(
     (
         NezhaModel,
         NezhaForMaskedLM,
         NezhaForMultipleChoice,
         NezhaForNextSentencePrediction,
         NezhaForPreTraining,
         NezhaForQuestionAnswering,
         NezhaForSequenceClassification,
         NezhaForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 __lowercase			:							Any       					=			(
     {
         'feature-extraction': NezhaModel,
         'fill-mask': NezhaForMaskedLM,
         'question-answering': NezhaForQuestionAnswering,
         'text-classification': NezhaForSequenceClassification,
         'token-classification': NezhaForTokenClassification,
         'zero-shot': NezhaForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __lowercase			:							Dict       					=			True
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__=False			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       Any        =       super()._prepare_for_class(lowerCAmelCase__    ,			lowerCAmelCase__    ,			return_labels=lowerCAmelCase__			)

        if return_labels:
               if model_class in get_values(lowerCAmelCase__			):
                      lowercase__:       int        =       torch.zeros(
                          (self.model_tester.batch_size, self.model_tester.seq_length)    ,			dtype=torch.long    ,			device=lowerCAmelCase__			)
                      lowercase__:       Dict        =       torch.zeros(
                          self.model_tester.batch_size    ,			dtype=torch.long    ,			device=lowerCAmelCase__			)
        return inputs_dict
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       List[Any]        =       NezhaModelTester(self			)
        lowercase__:       Optional[int]        =       ConfigTester(self    ,			config_class=lowerCAmelCase__    ,			hidden_size=37			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        self.config_tester.run_common_tests()
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        lowercase__:       Dict        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        # This regression test was failing with PyTorch < 1.3
        (
            (
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						(
            lowercase__
        )      ,						
        ):       List[Any]        =       self.model_tester.prepare_config_and_inputs_for_decoder()

        lowercase__:       str        =       None

        self.model_tester.create_and_check_model_as_decoder(
            lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       Tuple        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       List[Any]        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_next_sequence_prediction(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       int        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       int        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       Any        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__			)
 @slow
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__:       List[str]        =       NezhaModel.from_pretrained(lowerCAmelCase__			)
               self.assertIsNotNone(lowerCAmelCase__			)
 @slow
 @require_torch_gpu
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        lowercase__      ,						lowercase__:       int        =       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

               lowercase__:       Optional[int]        =       True
               lowercase__:       Optional[int]        =       model_class(config=lowerCAmelCase__			)

               lowercase__:       Dict        =       self._prepare_for_class(lowerCAmelCase__    ,			lowerCAmelCase__			)
               lowercase__:       List[Any]        =       torch.jit.trace(
                   lowerCAmelCase__    ,			(inputs_dict['input_ids'].to('cpu'			), inputs_dict['attention_mask'].to('cpu'			))			)

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





@require_torch
class   __a      (   unittest.TestCase				):
 @slow
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       Optional[Any]        =       NezhaModel.from_pretrained('sijunhe/nezha-cn-base'			)
        lowercase__:       Tuple        =       torch.tensor([[0, 1, 2, 3, 4, 5]]			)
        lowercase__:       Dict        =       torch.tensor([[0, 1, 1, 1, 1, 1]]			)
        with torch.no_grad():
               lowercase__:       Union[str, Any]        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__			)[0]
        lowercase__:       Optional[Any]        =       torch.Size((1, 6, 768)			)
        self.assertEqual(output.shape    ,			lowerCAmelCase__			)
        lowercase__:       Optional[Any]        =       torch.tensor([[[0.0_6_8_5, 0.2_4_4_1, 0.1_1_0_2], [0.0_6_0_0, 0.1_9_0_6, 0.1_3_4_9], [0.0_2_2_1, 0.0_8_1_9, 0.0_5_8_6]]]			)

        self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,			lowerCAmelCase__    ,			atol=1E-4			)			)
 @slow
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[str]:




        '''simple docstring'''
        lowercase__:       int        =       NezhaForMaskedLM.from_pretrained('sijunhe/nezha-cn-base'			)
        lowercase__:       Optional[Any]        =       torch.tensor([[0, 1, 2, 3, 4, 5]]			)
        lowercase__:       Optional[Any]        =       torch.tensor([[1, 1, 1, 1, 1, 1]]			)
        with torch.no_grad():
               lowercase__:       Dict        =       model(lowerCAmelCase__    ,			attention_mask=lowerCAmelCase__			)[0]
        lowercase__:       int        =       torch.Size((1, 6, 21_128)			)
        self.assertEqual(output.shape    ,			lowerCAmelCase__			)
        lowercase__:       Union[str, Any]        =       torch.tensor(
            [[-2.7_9_3_9, -1.7_9_0_2, -2.2_1_8_9], [-2.8_5_8_5, -1.8_9_0_8, -2.3_7_2_3], [-2.6_4_9_9, -1.7_7_5_0, -2.2_5_5_8]]			)

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


