






"""simple docstring"""






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


SCREAMING_SNAKE_CASE						:						Any					   =       logging.get_logger(__name__)

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





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							int   			=					"""funnel"""
	SCREAMING_SNAKE_CASE_:							Any   			=					{
	    """hidden_size""": """d_model""",
	    """num_attention_heads""": """n_head""",
	}


	def __init__(      self  ,					__a=3_0522  ,					__a=[4, 4, 4]  ,					__a=None  ,					__a=2  ,					__a=768  ,					__a=12  ,					__a=64  ,					__a=3072  ,					__a="gelu_new"  ,					__a=0.1  ,					__a=0.1  ,					__a=0.0  ,					__a=0.1  ,					__a=None  ,					__a=1E-9  ,					__a="mean"  ,					__a="relative_shift"  ,					__a=True  ,					__a=True  ,					__a=True  ,					**__a  ,					):


					"""simple docstring"""

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

					super().__init__(**__a						)


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return sum(self.block_sizes						)


	@num_hidden_layers.setter
	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

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


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return len(self.block_sizes						)






	@num_blocks.setter
	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

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










"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import PoolFormerImageProcessor





class       snake_case_       (    unittest.TestCase       ):



	"""simple docstring"""

	def __init__(      self  ,					__a  ,					__a=7  ,					__a=3  ,					__a=30  ,					__a=400  ,					__a=True  ,					__a=None  ,					__a=0.9  ,					__a=None  ,					__a=True  ,					__a=[0.5, 0.5, 0.5]  ,					__a=[0.5, 0.5, 0.5]  ,					):


					"""simple docstring"""

					A__							 =       size if size is not None else {'shortest_edge': 30}
					A__							 =       crop_size if crop_size is not None else {'height': 30, 'width': 30}
					A__							 =       parent
					A__							 =       batch_size
					A__							 =       num_channels
					A__							 =       min_resolution
					A__							 =       max_resolution
					A__							 =       do_resize_and_center_crop
					A__							 =       size
					A__							 =       crop_pct
					A__							 =       crop_size
					A__							 =       do_normalize
					A__							 =       image_mean
					A__							 =       image_std






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return {
					    "size": self.size,
					    "do_resize_and_center_crop": self.do_resize_and_center_crop,
					    "crop_pct": self.crop_pct,
					    "crop_size": self.crop_size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					}





@require_torch
@require_vision
class       snake_case_       (    _lowerCamelCase    ,							unittest.TestCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[Any]   			=					PoolFormerImageProcessor if is_vision_available() else None


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       PoolFormerImageProcessingTester(self						)


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return self.image_processor_tester.prepare_image_processor_dict()


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class(**self.image_processor_dict						)
					self.assertTrue(hasattr(__a  ,					'do_resize_and_center_crop'						)						)
					self.assertTrue(hasattr(__a  ,					'size'						)						)
					self.assertTrue(hasattr(__a  ,					'crop_pct'						)						)
					self.assertTrue(hasattr(__a  ,					'do_normalize'						)						)
					self.assertTrue(hasattr(__a  ,					'image_mean'						)						)
					self.assertTrue(hasattr(__a  ,					'image_std'						)						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class.from_dict(self.image_processor_dict						)
					self.assertEqual(image_processor.size  ,					{'shortest_edge': 30}						)
					self.assertEqual(image_processor.crop_size  ,					{'height': 30, 'width': 30}						)

					A__							 =       self.image_processing_class.from_dict(self.image_processor_dict  ,					size=42  ,					crop_size=84						)
					self.assertEqual(image_processor.size  ,					{'shortest_edge': 42}						)
					self.assertEqual(image_processor.crop_size  ,					{'height': 84, 'width': 84}						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					pass


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class(**self.image_processor_dict						)
					# create random PIL images
					A__							 =       prepare_image_inputs(self.image_processor_tester  ,					equal_resolution=__a						)
					for image in image_inputs:
									self.assertIsInstance(__a  ,					Image.Image						)

					# Test not batched input
					A__							 =       image_processing(image_inputs[0]  ,					return_tensors='pt'						).pixel_values

					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processing(__a  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class(**self.image_processor_dict						)
					# create random numpy tensors
					A__							 =       prepare_image_inputs(self.image_processor_tester  ,					equal_resolution=__a  ,					numpify=__a						)
					for image in image_inputs:
									self.assertIsInstance(__a  ,					np.ndarray						)

					# Test not batched input
					A__							 =       image_processing(image_inputs[0]  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processing(__a  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       self.image_processing_class(**self.image_processor_dict						)
					# create random PyTorch tensors
					A__							 =       prepare_image_inputs(self.image_processor_tester  ,					equal_resolution=__a  ,					torchify=__a						)
					for image in image_inputs:
									self.assertIsInstance(__a  ,					torch.Tensor						)

					# Test not batched input
					A__							 =       image_processing(image_inputs[0]  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        1,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)

					# Test batched
					A__							 =       image_processing(__a  ,					return_tensors='pt'						).pixel_values
					self.assertEqual(
					    encoded_images.shape  ,					(
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size['height'],
					        self.image_processor_tester.crop_size['width'],
					    )  ,					)


