



import os
from itertools import chain
from random import randrange, shuffle

import pytest

from .sola import PokerHand

_lowercase     							=						(
    '''4S 3H 2C 7S 5H''',
    '''9D 8H 2C 6S 7H''',
    '''2D 6D 9D TH 7D''',
    '''TC 8C 2S JH 6C''',
    '''JH 8S TH AH QH''',
    '''TS KS 5S 9S AC''',
    '''KD 6S 9D TH AD''',
    '''KS 8D 4D 9S 4S''',  # pair
    '''8C 4S KH JS 4D''',  # pair
    '''QH 8H KD JH 8S''',  # pair
    '''KC 4H KS 2H 8D''',  # pair
    '''KD 4S KC 3H 8S''',  # pair
    '''AH 8S AS KC JH''',  # pair
    '''3H 4C 4H 3S 2H''',  # 2 pairs
    '''5S 5D 2C KH KH''',  # 2 pairs
    '''3C KH 5D 5S KH''',  # 2 pairs
    '''AS 3C KH AD KH''',  # 2 pairs
    '''7C 7S 3S 7H 5S''',  # 3 of a kind
    '''7C 7S KH 2H 7H''',  # 3 of a kind
    '''AC KH QH AH AS''',  # 3 of a kind
    '''2H 4D 3C AS 5S''',  # straight (low ace)
    '''3C 5C 4C 2C 6H''',  # straight
    '''6S 8S 7S 5H 9H''',  # straight
    '''JS QS 9H TS KH''',  # straight
    '''QC KH TS JS AH''',  # straight (high ace)
    '''8C 9C 5C 3C TC''',  # flush
    '''3S 8S 9S 5S KS''',  # flush
    '''4C 5C 9C 8C KC''',  # flush
    '''JH 8H AH KH QH''',  # flush
    '''3D 2H 3H 2C 2D''',  # full house
    '''2H 2C 3S 3H 3D''',  # full house
    '''KH KC 3S 3H 3D''',  # full house
    '''JC 6H JS JD JH''',  # 4 of a kind
    '''JC 7H JS JD JH''',  # 4 of a kind
    '''JC KH JS JD JH''',  # 4 of a kind
    '''2S AS 4S 5S 3S''',  # straight flush (low ace)
    '''2D 6D 3D 4D 5D''',  # straight flush
    '''5C 6C 3C 7C 4C''',  # straight flush
    '''JH 9H TH KH QH''',  # straight flush
    '''JH AH TH KH QH''',  # royal flush (high ace straight flush)
)

_lowercase     							=						(
    ('''2H 3H 4H 5H 6H''', '''KS AS TS QS JS''', '''Loss'''),
    ('''2H 3H 4H 5H 6H''', '''AS AD AC AH JD''', '''Win'''),
    ('''AS AH 2H AD AC''', '''JS JD JC JH 3D''', '''Win'''),
    ('''2S AH 2H AS AC''', '''JS JD JC JH AD''', '''Loss'''),
    ('''2S AH 2H AS AC''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''AS 3S 4S 8S 2S''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''2H 3H 5H 6H 7H''', '''2S 3H 4H 5S 6C''', '''Win'''),
    ('''2S 3H 4H 5S 6C''', '''3D 4C 5H 6H 2S''', '''Tie'''),
    ('''2S 3H 4H 5S 6C''', '''AH AC 5H 6H AS''', '''Win'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H AS''', '''Loss'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H 7S''', '''Win'''),
    ('''6S AD 7H 4S AS''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S AH 4H 5S KC''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S 3H 6H 7S 9C''', '''7H 3C TH 6H 9S''', '''Loss'''),
    ('''4S 5H 6H TS AC''', '''3S 5H 6H TS AC''', '''Win'''),
    ('''2S AH 4H 5S 6C''', '''AD 4C 5H 6H 2C''', '''Tie'''),
    ('''AS AH 3H AD AC''', '''AS AH 2H AD AC''', '''Win'''),
    ('''AH AC 5H 5C QS''', '''AH AC 5H 5C KS''', '''Loss'''),
    ('''AH AC 5H 5C QS''', '''KH KC 5H 5C QS''', '''Win'''),
    ('''7C 7S KH 2H 7H''', '''3C 3S AH 2H 3H''', '''Win'''),
    ('''3C 3S AH 2H 3H''', '''7C 7S KH 2H 7H''', '''Loss'''),
    ('''6H 5H 4H 3H 2H''', '''5H 4H 3H 2H AH''', '''Win'''),
    ('''5H 4H 3H 2H AH''', '''5H 4H 3H 2H AH''', '''Tie'''),
    ('''5H 4H 3H 2H AH''', '''6H 5H 4H 3H 2H''', '''Loss'''),
    ('''AH AD KS KC AC''', '''AH KD KH AC KC''', '''Win'''),
    ('''2H 4D 3C AS 5S''', '''2H 4D 3C 6S 5S''', '''Loss'''),
    ('''2H 3S 3C 3H 2S''', '''3S 3C 2S 2H 2D''', '''Win'''),
    ('''4D 6D 5D 2D JH''', '''3S 8S 3H TC KH''', '''Loss'''),
    ('''4S 6C 8S 3S 7S''', '''AD KS 2D 7D 7C''', '''Loss'''),
    ('''6S 4C 7H 8C 3H''', '''5H JC AH 9D 9C''', '''Loss'''),
    ('''9D 9H JH TC QH''', '''3C 2S JS 5C 7H''', '''Win'''),
    ('''2H TC 8S AD 9S''', '''4H TS 7H 2C 5C''', '''Win'''),
    ('''9D 3S 2C 7S 7C''', '''JC TD 3C TC 9H''', '''Loss'''),
)

_lowercase     							=						(
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', True),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', False),
    ('''AS 3S 4S 8S 2S''', True),
)

_lowercase     							=						(
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', False),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', True),
)

_lowercase     							=						(
    ('''2H 4D 3C AS 5S''', True, [5, 4, 3, 2, 14]),
    ('''2H 5D 3C AS 5S''', False, [14, 5, 5, 3, 2]),
    ('''JH QD KC AS TS''', False, [14, 13, 12, 11, 10]),
    ('''9D 3S 2C 7S 7C''', False, [9, 7, 7, 3, 2]),
)

_lowercase     							=						(
    ('''JH AH TH KH QH''', 0),
    ('''JH 9H TH KH QH''', 0),
    ('''JC KH JS JD JH''', 7),
    ('''KH KC 3S 3H 3D''', 6),
    ('''8C 9C 5C 3C TC''', 0),
    ('''JS QS 9H TS KH''', 0),
    ('''7C 7S KH 2H 7H''', 3),
    ('''3C KH 5D 5S KH''', 2),
    ('''QH 8H KD JH 8S''', 1),
    ('''2D 6D 9D TH 7D''', 0),
)

_lowercase     							=						(
    ('''JH AH TH KH QH''', 23),
    ('''JH 9H TH KH QH''', 22),
    ('''JC KH JS JD JH''', 21),
    ('''KH KC 3S 3H 3D''', 20),
    ('''8C 9C 5C 3C TC''', 19),
    ('''JS QS 9H TS KH''', 18),
    ('''7C 7S KH 2H 7H''', 17),
    ('''3C KH 5D 5S KH''', 16),
    ('''QH 8H KD JH 8S''', 15),
    ('''2D 6D 9D TH 7D''', 14),
)






def      _A				()  ->List[str]:



			'''simple docstring'''







			lowerCamelCase__							,lowerCamelCase__ :      Union[str, Any]								=		randrange(len(UpperCamelCase ) ), randrange(len(UpperCamelCase ) )
			lowerCamelCase__ :      int								=		["""Loss""", """Tie""", """Win"""][(play >= oppo) + (play > oppo)]
			lowerCamelCase__							,lowerCamelCase__ :      List[Any]								=		SORTED_HANDS[play], SORTED_HANDS[oppo]
			return hand, other, expected






def      _A				(UpperCamelCase		:      int = 100 )  ->Union[str, Any]:



			'''simple docstring'''







			return (generate_random_hand() for _ in range(UpperCamelCase ))






@pytest.mark.parametrize("""hand, expected"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      str      ,			UpperCamelCase		:      Any )  ->Dict:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase )._is_flush() == expected






@pytest.mark.parametrize("""hand, expected"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      Tuple      ,			UpperCamelCase		:      Union[str, Any] )  ->Union[str, Any]:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase )._is_straight() == expected






@pytest.mark.parametrize("""hand, expected, card_values"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      str      ,			UpperCamelCase		:      str      ,			UpperCamelCase		:      Optional[int] )  ->Tuple:



			'''simple docstring'''







			lowerCamelCase__ :      Union[str, Any]								=		PokerHand(UpperCamelCase )
			assert player._is_five_high_straight() == expected
			assert player._card_values == card_values






@pytest.mark.parametrize("""hand, expected"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      int      ,			UpperCamelCase		:      List[Any] )  ->List[Any]:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase )._is_same_kind() == expected






@pytest.mark.parametrize("""hand, expected"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      Any      ,			UpperCamelCase		:      List[str] )  ->Any:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase )._hand_type == expected






@pytest.mark.parametrize("""hand, other, expected"""      ,			UpperCamelCase )
def      _A				(UpperCamelCase		:      Tuple      ,			UpperCamelCase		:      List[Any]      ,			UpperCamelCase		:      str )  ->Union[str, Any]:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase ).compare_with(PokerHand(UpperCamelCase ) ) == expected






@pytest.mark.parametrize("""hand, other, expected"""      ,			generate_random_hands() )
def      _A				(UpperCamelCase		:      Tuple      ,			UpperCamelCase		:      Dict      ,			UpperCamelCase		:      Any )  ->int:



			'''simple docstring'''







			assert PokerHand(UpperCamelCase ).compare_with(PokerHand(UpperCamelCase ) ) == expected






def      _A				()  ->Tuple:



			'''simple docstring'''







			lowerCamelCase__ :      Tuple								=		[PokerHand(UpperCamelCase ) for hand in SORTED_HANDS]
			lowerCamelCase__ :      Union[str, Any]								=		poker_hands.copy()
			shuffle(UpperCamelCase )
			lowerCamelCase__ :      Any								=		chain(sorted(UpperCamelCase ) )
			for index, hand in enumerate(UpperCamelCase ):
						assert hand == poker_hands[index]






def      _A				()  ->List[str]:



			'''simple docstring'''







			lowerCamelCase__ :      Optional[int]								=		[PokerHand("""2D AC 3H 4H 5S""" ), PokerHand("""2S 3H 4H 5S 6C""" )]
			pokerhands.sort(reverse=UpperCamelCase )
			assert pokerhands[0].__str__() == "2S 3H 4H 5S 6C"






def      _A				()  ->str:



			'''simple docstring'''







			lowerCamelCase__ :      str								=		PokerHand("""2C 4S AS 3D 5C""" )
			lowerCamelCase__ :      List[Any]								=		True
			lowerCamelCase__ :      Dict								=		[5, 4, 3, 2, 14]
			for _ in range(10 ):
						assert pokerhand._is_five_high_straight() == expected
						assert pokerhand._card_values == expected_card_values






def      _A				()  ->List[Any]:



			'''simple docstring'''







			lowerCamelCase__ :      int								=		0
			lowerCamelCase__ :      Any								=		os.path.abspath(os.path.dirname(UpperCamelCase ) )
			lowerCamelCase__ :      Dict								=		os.path.join(UpperCamelCase      ,			"""poker_hands.txt""" )
			with open(UpperCamelCase ) as file_hand:
						for line in file_hand:
									lowerCamelCase__ :      str								=		line[:14].strip()
									lowerCamelCase__ :      Dict								=		line[15:].strip()
									lowerCamelCase__							,lowerCamelCase__ :      Union[str, Any]								=		PokerHand(UpperCamelCase ), PokerHand(UpperCamelCase )
									lowerCamelCase__ :      Optional[Any]								=		player.compare_with(UpperCamelCase )
									if output == "Win":
												answer += 1
			assert answer == 376








import inspect
import unittest

from transformers import MobileViTVaConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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 MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation, MobileViTVaModel
				from transformers.models.mobilevitva.modeling_mobilevitva import (
				    MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
				    make_divisible,
				)


if is_vision_available():
				from PIL import Image

				from transformers import MobileViTImageProcessor
class 				__A					( A_      ):





			def        _snake_case    (self				):
						lowerCamelCase__ :      Dict								=		self.config_class(**self.inputs_dict				)
						self.parent.assertTrue(hasattr(__magic_name__							,    """width_multiplier"""				)				)







class 				__A					:





			def __init__(self							,    __magic_name__							,    __magic_name__=13							,    __magic_name__=64							,    __magic_name__=2							,    __magic_name__=3							,    __magic_name__="swish"							,    __magic_name__=3							,    __magic_name__=32							,    __magic_name__=0.1							,    __magic_name__=0.02							,    __magic_name__=True							,    __magic_name__=True							,    __magic_name__=10							,    __magic_name__=None							,    __magic_name__=0.25							,    __magic_name__=0.0							,    __magic_name__=0.0							,    ):
						lowerCamelCase__ :      Optional[Any]								=		parent
						lowerCamelCase__ :      List[Any]								=		batch_size
						lowerCamelCase__ :      Optional[Any]								=		image_size
						lowerCamelCase__ :      Union[str, Any]								=		patch_size
						lowerCamelCase__ :      Dict								=		num_channels
						lowerCamelCase__ :      Optional[Any]								=		make_divisible(512 * width_multiplier							,    divisor=8				)
						lowerCamelCase__ :      str								=		hidden_act
						lowerCamelCase__ :      Union[str, Any]								=		conv_kernel_size
						lowerCamelCase__ :      int								=		output_stride
						lowerCamelCase__ :      Tuple								=		classifier_dropout_prob
						lowerCamelCase__ :      Optional[Any]								=		use_labels
						lowerCamelCase__ :      Tuple								=		is_training
						lowerCamelCase__ :      List[Any]								=		num_labels
						lowerCamelCase__ :      str								=		initializer_range
						lowerCamelCase__ :      Optional[Any]								=		scope
						lowerCamelCase__ :      Tuple								=		width_multiplier
						lowerCamelCase__ :      List[Any]								=		ffn_dropout
						lowerCamelCase__ :      Union[str, Any]								=		attn_dropout





			def        _snake_case    (self				):
						lowerCamelCase__ :      Optional[int]								=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

						lowerCamelCase__ :      str								=		None
						lowerCamelCase__ :      List[Any]								=		None
						if self.use_labels:
									lowerCamelCase__ :      Tuple								=		ids_tensor([self.batch_size]							,    self.num_labels				)
									lowerCamelCase__ :      List[Any]								=		ids_tensor([self.batch_size, self.image_size, self.image_size]							,    self.num_labels				)

						lowerCamelCase__ :      int								=		self.get_config()

						return config, pixel_values, labels, pixel_labels





			def        _snake_case    (self				):
						return MobileViTVaConfig(
						    image_size=self.image_size							,    patch_size=self.patch_size							,    num_channels=self.num_channels							,    hidden_act=self.hidden_act							,    conv_kernel_size=self.conv_kernel_size							,    output_stride=self.output_stride							,    classifier_dropout_prob=self.classifier_dropout_prob							,    initializer_range=self.initializer_range							,    width_multiplier=self.width_multiplier							,    ffn_dropout=self.ffn_dropout_prob							,    attn_dropout=self.attn_dropout_prob							,    )





			def        _snake_case    (self							,    __magic_name__							,    __magic_name__							,    __magic_name__							,    __magic_name__				):
						lowerCamelCase__ :      Any								=		MobileViTVaModel(config=__magic_name__				)
						model.to(__magic_name__				)
						model.eval()
						lowerCamelCase__ :      Optional[Any]								=		model(__magic_name__				)
						self.parent.assertEqual(
						    result.last_hidden_state.shape							,    (
						        self.batch_size,
						        self.last_hidden_size,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )							,    )





			def        _snake_case    (self							,    __magic_name__							,    __magic_name__							,    __magic_name__							,    __magic_name__				):
						lowerCamelCase__ :      List[str]								=		self.num_labels
						lowerCamelCase__ :      Optional[int]								=		MobileViTVaForImageClassification(__magic_name__				)
						model.to(__magic_name__				)
						model.eval()
						lowerCamelCase__ :      Dict								=		model(__magic_name__							,    labels=__magic_name__				)
						self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.num_labels)				)





			def        _snake_case    (self							,    __magic_name__							,    __magic_name__							,    __magic_name__							,    __magic_name__				):
						lowerCamelCase__ :      Dict								=		self.num_labels
						lowerCamelCase__ :      Any								=		MobileViTVaForSemanticSegmentation(__magic_name__				)
						model.to(__magic_name__				)
						model.eval()
						lowerCamelCase__ :      Optional[int]								=		model(__magic_name__				)
						self.parent.assertEqual(
						    result.logits.shape							,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )							,    )
						lowerCamelCase__ :      Dict								=		model(__magic_name__							,    labels=__magic_name__				)
						self.parent.assertEqual(
						    result.logits.shape							,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )							,    )





			def        _snake_case    (self				):
						lowerCamelCase__ :      Any								=		self.prepare_config_and_inputs()
						lowerCamelCase__							,lowerCamelCase__							,lowerCamelCase__							,lowerCamelCase__ :      List[str]								=		config_and_inputs
						lowerCamelCase__ :      str								=		{"""pixel_values""": pixel_values}
						return config, inputs_dict







@require_torch
class 				__A					( A_					, A_					, unittest.TestCase      ):
			UpperCamelCase					:Optional[Any]     =			(
			    (MobileViTVaModel, MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation)
			    if is_torch_available()
			    else ()
			)

			UpperCamelCase					:List[Any]     =			(
			    {
			        '''feature-extraction''': MobileViTVaModel,
			        '''image-classification''': MobileViTVaForImageClassification,
			        '''image-segmentation''': MobileViTVaForSemanticSegmentation,
			    }
			    if is_torch_available()
			    else {}
			)

			UpperCamelCase					:List[Any]     =			False
			UpperCamelCase					:int     =			False
			UpperCamelCase					:Optional[int]     =			False
			UpperCamelCase					:int     =			False





			def        _snake_case    (self				):
						lowerCamelCase__ :      Optional[int]								=		MobileViTVaModelTester(self				)
						lowerCamelCase__ :      Optional[int]								=		MobileViTVaConfigTester(self							,    config_class=__magic_name__							,    has_text_modality=__magic_name__				)





			def        _snake_case    (self				):
						self.config_tester.run_common_tests()





			@unittest.skip(reason="""MobileViTV2 does not use inputs_embeds"""				)
			def        _snake_case    (self				):
						pass





			@unittest.skip(reason="""MobileViTV2 does not support input and output embeddings"""				)
			def        _snake_case    (self				):
						pass





			@unittest.skip(reason="""MobileViTV2 does not output attentions"""				)
			def        _snake_case    (self				):
						pass





			@require_torch_multi_gpu
			@unittest.skip(reason="""Got `CUDA error: misaligned address` for tests after this one being run."""				)
			def        _snake_case    (self				):
						pass





			@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""				)
			def        _snake_case    (self				):
						pass





			def        _snake_case    (self				):
						lowerCamelCase__							,lowerCamelCase__ :      Union[str, Any]								=		self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									lowerCamelCase__ :      List[Any]								=		model_class(__magic_name__				)
									lowerCamelCase__ :      Optional[Any]								=		inspect.signature(model.forward				)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									lowerCamelCase__ :      Union[str, Any]								=		[*signature.parameters.keys()]

									lowerCamelCase__ :      Union[str, Any]								=		["""pixel_values"""]
									self.assertListEqual(arg_names[:1]							,    __magic_name__				)





			def        _snake_case    (self				):
						lowerCamelCase__ :      int								=		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__magic_name__				)





			def        _snake_case    (self				):
						def check_hidden_states_output(__magic_name__							,    __magic_name__							,    __magic_name__				):
									lowerCamelCase__ :      Dict								=		model_class(__magic_name__				)
									model.to(__magic_name__				)
									model.eval()

									with torch.no_grad():
												lowerCamelCase__ :      Optional[int]								=		model(**self._prepare_for_class(__magic_name__							,    __magic_name__				)				)

									lowerCamelCase__ :      str								=		outputs.hidden_states

									lowerCamelCase__ :      Dict								=		5
									self.assertEqual(len(__magic_name__				)							,    __magic_name__				)

									# MobileViTV2's feature maps are of shape (batch_size, num_channels, height, width)
									# with the width and height being successively divided by 2.
									lowerCamelCase__ :      Dict								=		2
									for i in range(len(__magic_name__				)				):
												self.assertListEqual(
												    list(hidden_states[i].shape[-2:]				)							,    [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]							,    )
												divisor *= 2

									self.assertEqual(self.model_tester.output_stride							,    divisor // 2				)

						lowerCamelCase__							,lowerCamelCase__ :      Optional[Any]								=		self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									lowerCamelCase__ :      Any								=		True
									check_hidden_states_output(__magic_name__							,    __magic_name__							,    __magic_name__				)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									lowerCamelCase__ :      Tuple								=		True

									check_hidden_states_output(__magic_name__							,    __magic_name__							,    __magic_name__				)





			def        _snake_case    (self				):
						lowerCamelCase__ :      Tuple								=		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*__magic_name__				)





			def        _snake_case    (self				):
						lowerCamelCase__ :      List[Any]								=		self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_semantic_segmentation(*__magic_name__				)





			@slow
			def        _snake_case    (self				):
						for model_name in MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowerCamelCase__ :      int								=		MobileViTVaModel.from_pretrained(__magic_name__				)
									self.assertIsNotNone(__magic_name__				)







def      _A				()  ->List[Any]:



			'''simple docstring'''







			lowerCamelCase__ :      Tuple								=		Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
			return image
@require_torch
@require_vision
class 				__A					( unittest.TestCase      ):





			@cached_property
			def        _snake_case    (self				):
						return (
						    MobileViTImageProcessor.from_pretrained("""apple/mobilevitv2-1.0-imagenet1k-256"""				)
						    if is_vision_available()
						    else None
						)





			@slow
			def        _snake_case    (self				):
						lowerCamelCase__ :      str								=		MobileViTVaForImageClassification.from_pretrained("""apple/mobilevitv2-1.0-imagenet1k-256"""				).to(
						    __magic_name__				)

						lowerCamelCase__ :      Union[str, Any]								=		self.default_image_processor
						lowerCamelCase__ :      Any								=		prepare_img()
						lowerCamelCase__ :      Optional[Any]								=		image_processor(images=__magic_name__							,    return_tensors="""pt"""				).to(__magic_name__				)

						# forward pass
						with torch.no_grad():
									lowerCamelCase__ :      List[str]								=		model(**__magic_name__				)

						# verify the logits
						lowerCamelCase__ :      List[Any]								=		torch.Size((1, 1000)				)
						self.assertEqual(outputs.logits.shape							,    __magic_name__				)

						lowerCamelCase__ :      Optional[Any]								=		torch.tensor([-1.63_36E00, -7.32_04E-02, -5.18_83E-01]				).to(__magic_name__				)

						self.assertTrue(torch.allclose(outputs.logits[0, :3]							,    __magic_name__							,    atol=1E-4				)				)





			@slow
			def        _snake_case    (self				):
						lowerCamelCase__ :      Optional[int]								=		MobileViTVaForSemanticSegmentation.from_pretrained("""shehan97/mobilevitv2-1.0-voc-deeplabv3"""				)
						lowerCamelCase__ :      Dict								=		model.to(__magic_name__				)

						lowerCamelCase__ :      str								=		MobileViTImageProcessor.from_pretrained("""shehan97/mobilevitv2-1.0-voc-deeplabv3"""				)

						lowerCamelCase__ :      str								=		prepare_img()
						lowerCamelCase__ :      str								=		image_processor(images=__magic_name__							,    return_tensors="""pt"""				).to(__magic_name__				)

						# forward pass
						with torch.no_grad():
									lowerCamelCase__ :      Dict								=		model(**__magic_name__				)
						lowerCamelCase__ :      List[str]								=		outputs.logits

						# verify the logits
						lowerCamelCase__ :      Tuple								=		torch.Size((1, 21, 32, 32)				)
						self.assertEqual(logits.shape							,    __magic_name__				)

						lowerCamelCase__ :      Any								=		torch.tensor(
						    [
						        [[7.08_63, 7.15_25, 6.82_01], [6.69_31, 6.87_70, 6.89_33], [6.29_78, 7.03_66, 6.96_36]],
						        [[-3.71_34, -3.67_12, -3.66_75], [-3.58_25, -3.35_49, -3.47_77], [-3.34_35, -3.39_79, -3.28_57]],
						        [[-2.93_29, -2.80_03, -2.73_69], [-3.05_64, -2.47_80, -2.02_07], [-2.68_89, -1.92_98, -1.76_40]],
						    ]							,    device=__magic_name__							,    )

						self.assertTrue(torch.allclose(logits[0, :3, :3, :3]							,    __magic_name__							,    atol=1E-4				)				)





			@slow
			def        _snake_case    (self				):
						lowerCamelCase__ :      Union[str, Any]								=		MobileViTVaForSemanticSegmentation.from_pretrained("""shehan97/mobilevitv2-1.0-voc-deeplabv3"""				)
						lowerCamelCase__ :      List[Any]								=		model.to(__magic_name__				)

						lowerCamelCase__ :      Optional[int]								=		MobileViTImageProcessor.from_pretrained("""shehan97/mobilevitv2-1.0-voc-deeplabv3"""				)

						lowerCamelCase__ :      Union[str, Any]								=		prepare_img()
						lowerCamelCase__ :      Dict								=		image_processor(images=__magic_name__							,    return_tensors="""pt"""				).to(__magic_name__				)

						# forward pass
						with torch.no_grad():
									lowerCamelCase__ :      List[str]								=		model(**__magic_name__				)

						lowerCamelCase__ :      str								=		outputs.logits.detach().cpu()

						lowerCamelCase__ :      Optional[int]								=		image_processor.post_process_semantic_segmentation(outputs=__magic_name__							,    target_sizes=[(50, 60)]				)
						lowerCamelCase__ :      List[Any]								=		torch.Size((50, 60)				)
						self.assertEqual(segmentation[0].shape							,    __magic_name__				)

						lowerCamelCase__ :      List[str]								=		image_processor.post_process_semantic_segmentation(outputs=__magic_name__				)
						lowerCamelCase__ :      int								=		torch.Size((32, 32)				)
						self.assertEqual(segmentation[0].shape							,    __magic_name__				)



