code: 
  import inspect
  import unittest
  
  from transformers import is_torch_available, is_vision_available
  from transformers.models.auto import get_values
  from transformers.testing_utils import require_torch, slow, torch_device
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
  							import torch
  
  							from transformers import MODEL_MAPPING, PoolFormerConfig, PoolFormerForImageClassification, PoolFormerModel
  							from transformers.models.poolformer.modeling_poolformer import POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
  							from PIL import Image
  
  							from transformers import PoolFormerImageProcessor
  
  
  
  
  
  class 						lowerCamelCase			(					__lowerCamelCase				):
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[Any] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.config_class(**self.inputs_dict )
  				self.parent.assertTrue(hasattr(lowercase      ,    '''hidden_sizes''' ) )
  				self.parent.assertTrue(hasattr(lowercase      ,    '''num_encoder_blocks''' ) )
  
  
  
  
  
  class 						lowerCamelCase			:
  
  
  
  
  
  
  
  	def __init__(    self			:Union[str, Any]      ,    lowercase			:Union[str, Any]      ,    lowercase			:Any=1_3      ,    lowercase			:Optional[Any]=6_4      ,    lowercase			:Any=3      ,    lowercase			:List[Any]=4      ,    lowercase			:Optional[int]=[2, 2, 2, 2]      ,    lowercase			:Optional[Any]=[8, 4, 2, 1]      ,    lowercase			:Optional[int]=[1_6, 3_2, 6_4, 1_2_8]      ,    lowercase			:Union[str, Any]=[1, 4, 8, 1_6]      ,    lowercase			:Dict=False      ,    lowercase			:Any=True      ,    lowercase			:Union[str, Any]="gelu"      ,    lowercase			:List[Any]=0.1      ,    lowercase			:List[str]=0.02      ,    lowercase			:Any=3      ,    lowercase			:int=None      ,    )		->			Dict:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   parent
  				SCREAMING_SNAKE_CASE    	=   batch_size
  				SCREAMING_SNAKE_CASE    	=   image_size
  				SCREAMING_SNAKE_CASE    	=   num_channels
  				SCREAMING_SNAKE_CASE    	=   num_encoder_blocks
  				SCREAMING_SNAKE_CASE    	=   sr_ratios
  				SCREAMING_SNAKE_CASE    	=   depths
  				SCREAMING_SNAKE_CASE    	=   hidden_sizes
  				SCREAMING_SNAKE_CASE    	=   downsampling_rates
  				SCREAMING_SNAKE_CASE    	=   is_training
  				SCREAMING_SNAKE_CASE    	=   use_labels
  				SCREAMING_SNAKE_CASE    	=   hidden_act
  				SCREAMING_SNAKE_CASE    	=   hidden_dropout_prob
  				SCREAMING_SNAKE_CASE    	=   initializer_range
  				SCREAMING_SNAKE_CASE    	=   num_labels
  				SCREAMING_SNAKE_CASE    	=   scope
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[int] )		->			Optional[int]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )
  
  				SCREAMING_SNAKE_CASE    	=   None
  				if self.use_labels:
  							SCREAMING_SNAKE_CASE    	=   ids_tensor([self.batch_size, self.image_size, self.image_size]      ,    self.num_labels )
  
  				SCREAMING_SNAKE_CASE    	=   PoolFormerConfig(
  				    image_size=self.image_size      ,    num_channels=self.num_channels      ,    num_encoder_blocks=self.num_encoder_blocks      ,    depths=self.depths      ,    hidden_sizes=self.hidden_sizes      ,    hidden_act=self.hidden_act      ,    hidden_dropout_prob=self.hidden_dropout_prob      ,    initializer_range=self.initializer_range      ,    )
  
  				return config, pixel_values, labels
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:List[str]      ,    lowercase			:Any      ,    lowercase			:int      ,    lowercase			:List[str] )		->			Any:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   PoolFormerModel(config=lowercase )
  				model.to(lowercase )
  				model.eval()
  				SCREAMING_SNAKE_CASE    	=   model(lowercase )
  				SCREAMING_SNAKE_CASE    	=   SCREAMING_SNAKE_CASE    	=   self.image_size // 32.0
  				self.parent.assertEqual(
  				    result.last_hidden_state.shape      ,    (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width) )
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[Any] )		->			str:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.prepare_config_and_inputs()
  				SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   config_and_inputs
  				SCREAMING_SNAKE_CASE    	=   {'''pixel_values''': pixel_values}
  				return config, inputs_dict
  
  
  
  
  
  @require_torch
  class 						lowerCamelCase			(					__lowerCamelCase   ,		__lowerCamelCase   ,		unittest.TestCase				):
  	UpperCamelCase_     :				Tuple								=  (PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
  	UpperCamelCase_     :				Union[str, Any]								=  (
  	    {'feature-extraction': PoolFormerModel, 'image-classification': PoolFormerForImageClassification}
  	    if is_torch_available()
  	    else {}
  	)
  
  	UpperCamelCase_     :				Dict								=  False
  	UpperCamelCase_     :				Dict								=  False
  	UpperCamelCase_     :				Dict								=  False
  	UpperCamelCase_     :				Optional[Any]								=  False
  	UpperCamelCase_     :				Any								=  False
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Tuple )		->			List[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   PoolFormerModelTester(self )
  				SCREAMING_SNAKE_CASE    	=   PoolFormerConfigTester(self      ,    config_class=lowercase )
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:str )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				self.config_tester.run_common_tests()
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[Any] )		->			Optional[int]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_model(*lowercase )
  
  
  
  
  
  
  
  	@unittest.skip('''PoolFormer does not use inputs_embeds''' )
  	def    snake_case__    (    self			:Any )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass
  
  
  
  
  
  
  
  	@unittest.skip('''PoolFormer does not have get_input_embeddings method and get_output_embeddings methods''' )
  	def    snake_case__    (    self			:Dict )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[int] )		->			Dict:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				def check_hidden_states_output(lowercase			:str      ,    lowercase			:Union[str, Any]      ,    lowercase			:Dict ):
  							SCREAMING_SNAKE_CASE    	=   model_class(lowercase )
  							model.to(lowercase )
  							model.eval()
  
  							with torch.no_grad():
  										SCREAMING_SNAKE_CASE    	=   model(**self._prepare_for_class(lowercase      ,    lowercase ) )
  
  							SCREAMING_SNAKE_CASE    	=   outputs.hidden_states
  
  							SCREAMING_SNAKE_CASE    	=   self.model_tester.num_encoder_blocks
  							self.assertEqual(len(lowercase )      ,    lowercase )
  
  							# verify the first hidden states (first block)
  							self.assertListEqual(
  							    list(hidden_states[0].shape[-3:] )      ,    [
  							        self.model_tester.hidden_sizes[0],
  							        self.model_tester.image_size // 4,
  							        self.model_tester.image_size // 4,
  							    ]      ,    )
  
  				SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   self.model_tester.prepare_config_and_inputs_for_common()
  
  				for model_class in self.all_model_classes:
  							SCREAMING_SNAKE_CASE    	=   True
  							check_hidden_states_output(lowercase      ,    lowercase      ,    lowercase )
  
  							# check that output_hidden_states also work using config
  							del inputs_dict["output_hidden_states"]
  							SCREAMING_SNAKE_CASE    	=   True
  
  							check_hidden_states_output(lowercase      ,    lowercase      ,    lowercase )
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Tuple )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				if not self.model_tester.is_training:
  							return
  
  				SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   self.model_tester.prepare_config_and_inputs_for_common()
  				SCREAMING_SNAKE_CASE    	=   True
  
  				for model_class in self.all_model_classes:
  							if model_class in get_values(lowercase ):
  										continue
  							SCREAMING_SNAKE_CASE    	=   model_class(lowercase )
  							model.to(lowercase )
  							model.train()
  							SCREAMING_SNAKE_CASE    	=   self._prepare_for_class(lowercase      ,    lowercase      ,    return_labels=lowercase )
  							SCREAMING_SNAKE_CASE    	=   model(**lowercase ).loss
  							loss.backward()
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Any )		->			Optional[int]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   self.model_tester.prepare_config_and_inputs_for_common()
  
  				for model_class in self.all_model_classes:
  							SCREAMING_SNAKE_CASE    	=   model_class(lowercase )
  							SCREAMING_SNAKE_CASE    	=   inspect.signature(model.forward )
  							# signature.parameters is an OrderedDict => so arg_names order is deterministic
  							SCREAMING_SNAKE_CASE    	=   [*signature.parameters.keys()]
  
  							SCREAMING_SNAKE_CASE    	=   ['''pixel_values''']
  							self.assertListEqual(arg_names[:1]      ,    lowercase )
  
  
  
  
  
  
  
  	@slow
  	def    snake_case__    (    self			:Any )		->			Optional[Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  							SCREAMING_SNAKE_CASE    	=   PoolFormerModel.from_pretrained(lowercase )
  							self.assertIsNotNone(lowercase )
  
  
  
  def       a			(   )    ->Dict:
  
  
  
  
  			'''simple docstring'''
  
  
  			SCREAMING_SNAKE_CASE    	=   Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
  			return image
  
  
  
  
  
  @require_torch
  class 						lowerCamelCase			(					unittest.TestCase				):
  
  
  
  
  
  
  
  	@slow
  	def    snake_case__    (    self			:Optional[int] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   PoolFormerImageProcessor()
  				SCREAMING_SNAKE_CASE    	=   PoolFormerForImageClassification.from_pretrained('''sail/poolformer_s12''' ).to(lowercase )
  
  				SCREAMING_SNAKE_CASE    	=   image_processor(images=prepare_img()      ,    return_tensors='''pt''' ).to(lowercase )
  
  				# forward pass
  				with torch.no_grad():
  							SCREAMING_SNAKE_CASE    	=   model(**lowercase )
  
  				# verify the logits
  				SCREAMING_SNAKE_CASE    	=   torch.Size((1, 1_0_0_0) )
  				self.assertEqual(outputs.logits.shape      ,    lowercase )
  
  				SCREAMING_SNAKE_CASE    	=   torch.tensor([-0.61_13, 0.16_85, -0.04_92] ).to(lowercase )
  				self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,    lowercase      ,    atol=1e-4 ) )
style_context: 
  import json
  import os
  import unittest
  
  from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import (
      VOCAB_FILES_NAMES,
      GPTNeoXJapaneseTokenizer,
  )
  from transformers.testing_utils import require_tokenizers, slow
  
  from ...test_tokenization_common import TokenizerTesterMixin
  
  
  
  
  
  @require_tokenizers
  class 						lowerCamelCase			(					__lowerCamelCase   ,		unittest.TestCase				):
  	UpperCamelCase_     :				List[str]								=  GPTNeoXJapaneseTokenizer
  	UpperCamelCase_     :				List[Any]								=  False
  	UpperCamelCase_     :				int								=  {'do_clean_text': False, 'add_prefix_space': False}
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[int] )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				super().setUp()
  
  				SCREAMING_SNAKE_CASE    	=   [
  				    '''こん''',
  				    '''こんに''',
  				    '''にちは''',
  				    '''ばんは''',
  				    '''世界,㔺界''',
  				    '''、''',
  				    '''。''',
  				    '''<BR>''',
  				    '''<SP>''',
  				    '''<TAB>''',
  				    '''<URL>''',
  				    '''<EMAIL>''',
  				    '''<TEL>''',
  				    '''<DATE>''',
  				    '''<PRICE>''',
  				    '''<BLOCK>''',
  				    '''<KIGOU>''',
  				    '''<U2000U2BFF>''',
  				    '''<|emoji1|>''',
  				    '''<unk>''',
  				    '''<|startoftext|>''',
  				    '''<|endoftext|>''',
  				]
  				SCREAMING_SNAKE_CASE    	=   {'''emoji''': {'''\ud83d\ude00''': '''<|emoji1|>'''}, '''emoji_inv''': {'''<|emoji1|>''': '''\ud83d\ude00'''}}  # 😀
  				SCREAMING_SNAKE_CASE    	=   {'''unk_token''': '''<unk>'''}
  
  				SCREAMING_SNAKE_CASE    	=   os.path.join(self.tmpdirname      ,    VOCAB_FILES_NAMES['''vocab_file'''] )
  				SCREAMING_SNAKE_CASE    	=   os.path.join(self.tmpdirname      ,    VOCAB_FILES_NAMES['''emoji_file'''] )
  				with open(self.vocab_file      ,    '''w'''      ,    encoding='''utf-8''' ) as vocab_writer:
  							vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens] ) )
  				with open(self.emoji_file      ,    '''w''' ) as emoji_writer:
  							emoji_writer.write(json.dumps(lowercase ) )
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Dict      ,    **lowercase			:Optional[int] )		->			int:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				kwargs.update(self.special_tokens_map )
  				return GPTNeoXJapaneseTokenizer.from_pretrained(self.tmpdirname      ,    **lowercase )
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Dict      ,    lowercase			:Union[str, Any] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   '''こんにちは、世界。 \nこんばんは、㔺界。😀'''
  				SCREAMING_SNAKE_CASE    	=   '''こんにちは、世界。 \nこんばんは、世界。😀'''
  				return input_text, output_text
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[int]      ,    lowercase			:Union[str, Any] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE	,       SCREAMING_SNAKE_CASE    	=   self.get_input_output_texts(lowercase )
  				SCREAMING_SNAKE_CASE    	=   tokenizer.encode(lowercase      ,    add_special_tokens=lowercase )
  				SCREAMING_SNAKE_CASE    	=   tokenizer.decode(lowercase      ,    clean_up_tokenization_spaces=lowercase )
  				return text, ids
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Dict )		->			int:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass  # TODO add if relevant
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:List[str] )		->			List[str]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass  # TODO add if relevant
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[Any] )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass  # TODO add if relevant
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Optional[Any] )		->			Dict:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.get_tokenizer()
  
  				# Testing tokenization
  				SCREAMING_SNAKE_CASE    	=   '''こんにちは、世界。　こんばんは、㔺界。'''
  				SCREAMING_SNAKE_CASE    	=   ['''こん''', '''にちは''', '''、''', '''世界''', '''。''', '''<SP>''', '''こん''', '''ばんは''', '''、''', '''㔺界''', '''。''']
  				SCREAMING_SNAKE_CASE    	=   tokenizer.tokenize(lowercase )
  				self.assertListEqual(lowercase      ,    lowercase )
  
  				# Testing conversion to ids without special tokens
  				SCREAMING_SNAKE_CASE    	=   [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
  				SCREAMING_SNAKE_CASE    	=   tokenizer.convert_tokens_to_ids(lowercase )
  				self.assertListEqual(lowercase      ,    lowercase )
  
  				# Testing conversion to ids with special tokens
  				SCREAMING_SNAKE_CASE    	=   tokens + [tokenizer.unk_token]
  				SCREAMING_SNAKE_CASE    	=   [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 1_9]
  				SCREAMING_SNAKE_CASE    	=   tokenizer.convert_tokens_to_ids(lowercase )
  				self.assertListEqual(lowercase      ,    lowercase )
  
  
  
  
  
  
  
  	@slow
  	def    snake_case__    (    self			:str )		->			Union[str, Any]:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				SCREAMING_SNAKE_CASE    	=   self.tokenizer_class.from_pretrained('''abeja/gpt-neox-japanese-2.7b''' )
  
  				SCREAMING_SNAKE_CASE    	=   tokenizer.encode('''ありがとう。'''      ,    add_special_tokens=lowercase )
  				SCREAMING_SNAKE_CASE    	=   tokenizer.encode('''どういたしまして。'''      ,    add_special_tokens=lowercase )
  
  				SCREAMING_SNAKE_CASE    	=   tokenizer.build_inputs_with_special_tokens(lowercase )
  				SCREAMING_SNAKE_CASE    	=   tokenizer.build_inputs_with_special_tokens(lowercase      ,    lowercase )
  
  				assert encoded_sentence == ids_a
  				assert encoded_pair == ids_a + ids_a
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:List[Any] )		->			Dict:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass
  
  
  
  
  
  
  
  	def    snake_case__    (    self			:Any )		->			str:
  
  
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  
  				pass