
'''simple docstring'''
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
				from transformers import TvltImageProcessor

if is_speech_available():
				from transformers import TvltFeatureExtractor

from transformers import TvltProcessor


@require_torch
class       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							def 	lowercase							(self  )					->       List[str]:
														_snake_case       =  '''ZinengTang/tvlt-base'''
														_snake_case       =  tempfile.mkdtemp()

							def 	lowercase							(self  ,  **UpperCAmelCase  )					->       int:
														return TvltImageProcessor.from_pretrained(self.checkpoint  ,  **a_  )

							def 	lowercase							(self  ,  **UpperCAmelCase  )					->       str:
														return TvltFeatureExtractor.from_pretrained(self.checkpoint  ,  **a_  )

							def 	lowercase							(self  )					->       List[str]:
														shutil.rmtree(self.tmpdirname  )

							def 	lowercase							(self  )					->       Union[str, Any]:
														_snake_case       =  self.get_image_processor()
														_snake_case       =  self.get_feature_extractor()

														_snake_case       =  TvltProcessor(image_processor=a_  ,  feature_extractor=a_  )
														processor.save_pretrained(self.tmpdirname  )
														_snake_case       =  TvltProcessor.from_pretrained(self.tmpdirname  )

														self.assertIsInstance(processor.feature_extractor  ,  a_  )
														self.assertIsInstance(processor.image_processor  ,  a_  )

							def 	lowercase							(self  )					->       str:
														_snake_case       =  self.get_image_processor()
														_snake_case       =  self.get_feature_extractor()

														_snake_case       =  TvltProcessor(image_processor=a_  ,  feature_extractor=a_  )

														_snake_case       =  np.ones([12000]  )

														_snake_case       =  feature_extractor(a_  ,  return_tensors="""np"""  )
														_snake_case       =  processor(audio=a_  ,  return_tensors="""np"""  )

														for key in audio_dict.keys():
																					self.assertAlmostEqual(audio_dict[key].sum()  ,  input_processor[key].sum()  ,  delta=1e-2  )

							def 	lowercase							(self  )					->       Tuple:
														_snake_case       =  self.get_image_processor()
														_snake_case       =  self.get_feature_extractor()

														_snake_case       =  TvltProcessor(image_processor=a_  ,  feature_extractor=a_  )

														_snake_case       =  np.ones([3, 224, 224]  )

														_snake_case       =  image_processor(a_  ,  return_tensors="""np"""  )
														_snake_case       =  processor(images=a_  ,  return_tensors="""np"""  )

														for key in image_dict.keys():
																					self.assertAlmostEqual(image_dict[key].sum()  ,  input_processor[key].sum()  ,  delta=1e-2  )

							def 	lowercase							(self  )					->       Dict:
														_snake_case       =  self.get_image_processor()
														_snake_case       =  self.get_feature_extractor()

														_snake_case       =  TvltProcessor(image_processor=a_  ,  feature_extractor=a_  )

														_snake_case       =  np.ones([12000]  )
														_snake_case       =  np.ones([3, 224, 224]  )

														_snake_case       =  processor(audio=a_  ,  images=a_  )

														self.assertListEqual(list(inputs.keys()  )  ,  ["""audio_values""", """audio_mask""", """pixel_values""", """pixel_mask"""]  )

														# test if it raises when no input is passed
														with pytest.raises(a_  ):
																					processor()





							def 	lowercase							(self  )					->       Tuple:
														_snake_case       =  self.get_image_processor()
														_snake_case       =  self.get_feature_extractor()

														_snake_case       =  TvltProcessor(image_processor=a_  ,  feature_extractor=a_  )

														self.assertListEqual(
														    processor.model_input_names  ,  image_processor.model_input_names + feature_extractor.model_input_names  ,  msg="""`processor` and `image_processor`+`feature_extractor` model input names do not match"""  ,  )




'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCAmelCase												=	logging.get_logger(__name__)

__lowerCAmelCase												=	{
    'shi-labs/nat-mini-in1k-224': 'https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json',
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class       _lowerCAmelCase   (   __snake_case					,							__snake_case				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						"nat"

							lowerCAmelCase_ 						=						{
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}

							def __init__(self  ,  UpperCAmelCase=4  ,  UpperCAmelCase=3  ,  UpperCAmelCase=64  ,  UpperCAmelCase=[3, 4, 6, 5]  ,  UpperCAmelCase=[2, 4, 8, 16]  ,  UpperCAmelCase=7  ,  UpperCAmelCase=3.0  ,  UpperCAmelCase=True  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=0.1  ,  UpperCAmelCase="gelu"  ,  UpperCAmelCase=0.02  ,  UpperCAmelCase=1e-5  ,  UpperCAmelCase=0.0  ,  UpperCAmelCase=None  ,  UpperCAmelCase=None  ,  **UpperCAmelCase  ,  )					->       str:
														super().__init__(**UpperCAmelCase  )

														_snake_case       =  patch_size
														_snake_case       =  num_channels
														_snake_case       =  embed_dim
														_snake_case       =  depths
														_snake_case       =  len(UpperCAmelCase  )
														_snake_case       =  num_heads
														_snake_case       =  kernel_size
														_snake_case       =  mlp_ratio
														_snake_case       =  qkv_bias
														_snake_case       =  hidden_dropout_prob
														_snake_case       =  attention_probs_dropout_prob
														_snake_case       =  drop_path_rate
														_snake_case       =  hidden_act
														_snake_case       =  layer_norm_eps
														_snake_case       =  initializer_range
														# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
														# this indicates the channel dimension after the last stage of the model
														_snake_case       =  int(embed_dim * 2 ** (len(UpperCAmelCase  ) - 1)  )
														_snake_case       =  layer_scale_init_value
														_snake_case       =  ["""stem"""] + [f"""stage{idx}""" for idx in range(1  ,  len(UpperCAmelCase  ) + 1  )]
														_snake_case,							_snake_case       =  get_aligned_output_features_output_indices(
														    out_features=UpperCAmelCase  ,  out_indices=UpperCAmelCase  ,  stage_names=self.stage_names  )