

'''simple docstring'''




import math
from typing import Any, Callable, List, Optional, Tuple, Union

import numpy as np
import torch

from ...models import TaFilmDecoder
from ...schedulers import DDPMScheduler
from ...utils import is_onnx_available, logging, randn_tensor


if is_onnx_available():
      from ..onnx_utils import OnnxRuntimeModel

from ..pipeline_utils import AudioPipelineOutput, DiffusionPipeline
from .continous_encoder import SpectrogramContEncoder
from .notes_encoder import SpectrogramNotesEncoder


_lowerCAmelCase         =						logging.get_logger(__name__)  # pylint: disable=invalid-name

_lowerCAmelCase         =						256






class   _SCREAMING_SNAKE_CASE   (   __a     ):
 __SCREAMING_SNAKE_CASE					:Any      	=					["""melgan"""]



 def __init__(   self		:   Optional[Any]			,				a__		:   SpectrogramNotesEncoder			,				a__		:   SpectrogramContEncoder			,				a__		:   TaFilmDecoder			,				a__		:   DDPMScheduler			,				a__		:   OnnxRuntimeModel if is_onnx_available() else Any			,				):
      super().__init__()

      # From MELGAN
      __magic_name__						       =    math.log(1E-5      )  # Matches MelGAN training.
      __magic_name__						       =    4.0  # Largest value for most examples
      __magic_name__						       =    128

      self.register_modules(
          notes_encoder=a__			,				continuous_encoder=a__			,				decoder=a__			,				scheduler=a__			,				melgan=a__			,				)



 def 			snake_case__  (   self		:   Optional[Any]			,				a__		:   int			,				a__		:   Tuple=(-1.0, 1.0)			,				a__		:   List[Any]=False      ):
      __magic_name__       ,  __magic_name__						       =    output_range
      if clip:
           __magic_name__						       =    torch.clip(a__			,				self.min_value			,				self.max_value      )
      # Scale to [0, 1].
      __magic_name__						       =    (features - self.min_value) / (self.max_value - self.min_value)
      # Scale to [min_out, max_out].
      return zero_one * (max_out - min_out) + min_out



 def 			snake_case__  (   self		:   Any			,				a__		:   str			,				a__		:   Optional[Any]=(-1.0, 1.0)			,				a__		:   List[Any]=False      ):
      __magic_name__       ,  __magic_name__						       =    input_range
      __magic_name__						       =    torch.clip(a__			,				a__			,				a__      ) if clip else outputs
      # Scale to [0, 1].
      __magic_name__						       =    (outputs - min_out) / (max_out - min_out)
      # Scale to [self.min_value, self.max_value].
      return zero_one * (self.max_value - self.min_value) + self.min_value



 def 			snake_case__  (   self		:   Dict			,				a__		:   Optional[int]			,				a__		:   Any			,				a__		:   List[str]      ):
      __magic_name__						       =    input_tokens > 0
      __magic_name__       ,  __magic_name__						       =    self.notes_encoder(
          encoder_input_tokens=a__			,				encoder_inputs_mask=a__      )

      __magic_name__       ,  __magic_name__						       =    self.continuous_encoder(
          encoder_inputs=a__			,				encoder_inputs_mask=a__      )

      return [(tokens_encoded, tokens_mask), (continuous_encoded, continuous_mask)]



 def 			snake_case__  (   self		:   List[Any]			,				a__		:   Dict			,				a__		:   Tuple			,				a__		:   List[Any]      ):
      __magic_name__						       =    noise_time
      if not torch.is_tensor(a__      ):
           __magic_name__						       =    torch.tensor([timesteps]			,				dtype=torch.long			,				device=input_tokens.device      )
      elif torch.is_tensor(a__      ) and len(timesteps.shape      ) == 0:
           __magic_name__						       =    timesteps[None].to(input_tokens.device      )

      # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
      __magic_name__						       =    timesteps * torch.ones(input_tokens.shape[0]			,				dtype=timesteps.dtype			,				device=timesteps.device      )

      __magic_name__						       =    self.decoder(
          encodings_and_masks=a__			,				decoder_input_tokens=a__			,				decoder_noise_time=a__      )
      return logits



 @torch.no_grad()
 def __call__(   self		:   List[Any]			,				a__		:   List[List[int]]			,				a__		:   Optional[torch.Generator] = None			,				a__		:   int = 100			,				a__		:   bool = True			,				a__		:   str = "numpy"			,				a__		:   Optional[Callable[[int, int, torch.FloatTensor], None]] = None			,				a__		:   int = 1			,				):
      if (callback_steps is None) or (
          callback_steps is not None and (not isinstance(a__			,				a__      ) or callback_steps <= 0)
      ):
           raise ValueError(
               F'''`callback_steps` has to be a positive integer but is {callback_steps} of type'''
               F''' {type(a__      )}.'''      )

      __magic_name__						       =    np.zeros([1, TARGET_FEATURE_LENGTH, self.n_dims]			,				dtype=np.floataa      )
      __magic_name__						       =    np.zeros([1, 0, self.n_dims]			,				np.floataa      )
      __magic_name__						       =    torch.ones((1, TARGET_FEATURE_LENGTH)			,				dtype=a__			,				device=self.device      )

      for i, encoder_input_tokens in enumerate(a__      ):
           if i == 0:
                __magic_name__						       =    torch.from_numpy(pred_mel[:1].copy()      ).to(
                    device=self.device			,				dtype=self.decoder.dtype      )
                # The first chunk has no previous context.
                __magic_name__						       =    torch.zeros((1, TARGET_FEATURE_LENGTH)			,				dtype=a__			,				device=self.device      )
           else:
                # The full song pipeline does not feed in a context feature, so the mask
                # will be all 0s after the feature converter. Because we know we're
                # feeding in a full context chunk from the previous prediction, set it
                # to all 1s.
                __magic_name__						       =    ones

           __magic_name__						       =    self.scale_features(
               a__			,				output_range=[-1.0, 1.0]			,				clip=a__      )

           __magic_name__						       =    self.encode(
               input_tokens=torch.IntTensor([encoder_input_tokens]      ).to(device=self.device      )			,				continuous_inputs=a__			,				continuous_mask=a__			,				)

           # Sample encoder_continuous_inputs shaped gaussian noise to begin loop
           __magic_name__						       =    randn_tensor(
               shape=encoder_continuous_inputs.shape			,				generator=a__			,				device=self.device			,				dtype=self.decoder.dtype			,				)

           # set step values
           self.scheduler.set_timesteps(a__      )

           # Denoising diffusion loop
           for j, t in enumerate(self.progress_bar(self.scheduler.timesteps      )      ):
                __magic_name__						       =    self.decode(
                    encodings_and_masks=a__			,				input_tokens=a__			,				noise_time=t / self.scheduler.config.num_train_timesteps			,				)

                # Compute previous output: x_t -> x_t-1
                __magic_name__						       =    self.scheduler.step(a__			,				a__			,				a__			,				generator=a__      ).prev_sample

           __magic_name__						       =    self.scale_to_features(a__			,				input_range=[-1.0, 1.0]      )
           __magic_name__						       =    mel[:1]
           __magic_name__						       =    mel.cpu().float().numpy()

           __magic_name__						       =    np.concatenate([full_pred_mel, pred_mel[:1]]			,				axis=1      )

           # call the callback, if provided
           if callback is not None and i % callback_steps == 0:
                callback(a__			,				a__      )

           logger.info('''Generated segment'''			,				a__      )

      if output_type == "numpy" and not is_onnx_available():
           raise ValueError(
               '''Cannot return output in \'np\' format if ONNX is not available. Make sure to have ONNX installed or set \'output_type\' to \'mel\'.'''      )
      elif output_type == "numpy" and self.melgan is None:
           raise ValueError(
               '''Cannot return output in \'np\' format if melgan component is not defined. Make sure to define `self.melgan` or set \'output_type\' to \'mel\'.'''      )

      if output_type == "numpy":
           __magic_name__						       =    self.melgan(input_features=full_pred_mel.astype(np.floataa      )      )
      else:
           __magic_name__						       =    full_pred_mel

      if not return_dict:
           return (output,)

      return AudioPipelineOutput(audios=a__      )









'''simple docstring'''




import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
      from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class   _SCREAMING_SNAKE_CASE   :



 def __init__(   self		:   str			,				a__		:   Union[str, Any]			,				a__		:   Dict=13			,				a__		:   List[str]=32			,				a__		:   List[Any]=2			,				a__		:   List[str]=3			,				a__		:   Union[str, Any]=16			,				a__		:   Dict=[1, 2, 1]			,				a__		:   Optional[Any]=[2, 2, 4]			,				a__		:   List[str]=2			,				a__		:   Optional[Any]=2.0			,				a__		:   Union[str, Any]=True			,				a__		:   int=0.0			,				a__		:   int=0.0			,				a__		:   Tuple=0.1			,				a__		:   List[str]="gelu"			,				a__		:   str=False			,				a__		:   Optional[int]=True			,				a__		:   List[Any]=0.02			,				a__		:   Any=1E-5			,				a__		:   int=True			,				a__		:   List[Any]=None			,				a__		:   Dict=True			,				a__		:   Optional[int]=10			,				a__		:   Any=8			,				):
      __magic_name__						       =    parent
      __magic_name__						       =    batch_size
      __magic_name__						       =    image_size
      __magic_name__						       =    patch_size
      __magic_name__						       =    num_channels
      __magic_name__						       =    embed_dim
      __magic_name__						       =    depths
      __magic_name__						       =    num_heads
      __magic_name__						       =    window_size
      __magic_name__						       =    mlp_ratio
      __magic_name__						       =    qkv_bias
      __magic_name__						       =    hidden_dropout_prob
      __magic_name__						       =    attention_probs_dropout_prob
      __magic_name__						       =    drop_path_rate
      __magic_name__						       =    hidden_act
      __magic_name__						       =    use_absolute_embeddings
      __magic_name__						       =    patch_norm
      __magic_name__						       =    layer_norm_eps
      __magic_name__						       =    initializer_range
      __magic_name__						       =    is_training
      __magic_name__						       =    scope
      __magic_name__						       =    use_labels
      __magic_name__						       =    type_sequence_label_size
      __magic_name__						       =    encoder_stride



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

      __magic_name__						       =    None
      if self.use_labels:
           __magic_name__						       =    ids_tensor([self.batch_size]			,				self.type_sequence_label_size      )

      __magic_name__						       =    self.get_config()

      return config, pixel_values, labels



 def 			snake_case__  (   self		:   Optional[int]      ):
      return SwinvaConfig(
          image_size=self.image_size			,				patch_size=self.patch_size			,				num_channels=self.num_channels			,				embed_dim=self.embed_dim			,				depths=self.depths			,				num_heads=self.num_heads			,				window_size=self.window_size			,				mlp_ratio=self.mlp_ratio			,				qkv_bias=self.qkv_bias			,				hidden_dropout_prob=self.hidden_dropout_prob			,				attention_probs_dropout_prob=self.attention_probs_dropout_prob			,				drop_path_rate=self.drop_path_rate			,				hidden_act=self.hidden_act			,				use_absolute_embeddings=self.use_absolute_embeddings			,				path_norm=self.patch_norm			,				layer_norm_eps=self.layer_norm_eps			,				initializer_range=self.initializer_range			,				encoder_stride=self.encoder_stride			,				)



 def 			snake_case__  (   self		:   Optional[int]			,				a__		:   Union[str, Any]			,				a__		:   Union[str, Any]			,				a__		:   Optional[int]      ):
      __magic_name__						       =    SwinvaModel(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )

      __magic_name__						       =    ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths      ) - 1))
      __magic_name__						       =    int(config.embed_dim * 2 ** (len(config.depths      ) - 1)      )

      self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, expected_seq_len, expected_dim)      )



 def 			snake_case__  (   self		:   Optional[Any]			,				a__		:   Optional[Any]			,				a__		:   str			,				a__		:   int      ):
      __magic_name__						       =    SwinvaForMaskedImageModeling(config=a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(
          result.logits.shape			,				(self.batch_size, self.num_channels, self.image_size, self.image_size)      )

      # test greyscale images
      __magic_name__						       =    1
      __magic_name__						       =    SwinvaForMaskedImageModeling(a__      )
      model.to(a__      )
      model.eval()

      __magic_name__						       =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]      )
      __magic_name__						       =    model(a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, 1, self.image_size, self.image_size)      )



 def 			snake_case__  (   self		:   List[str]			,				a__		:   List[str]			,				a__		:   List[Any]			,				a__		:   Any      ):
      __magic_name__						       =    self.type_sequence_label_size
      __magic_name__						       =    SwinvaForImageClassification(a__      )
      model.to(a__      )
      model.eval()
      __magic_name__						       =    model(a__			,				labels=a__      )
      self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.type_sequence_label_size)      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__						       =    self.prepare_config_and_inputs()
      __magic_name__       ,  __magic_name__       ,  __magic_name__						       =    config_and_inputs
      __magic_name__						       =    {'''pixel_values''': pixel_values}
      return config, inputs_dict






@require_torch
class   _SCREAMING_SNAKE_CASE   (   __a		,__a		,unittest.TestCase     ):
 __SCREAMING_SNAKE_CASE					:int      	=					(
     (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
 )
 __SCREAMING_SNAKE_CASE					:Tuple      	=					(
     {"""feature-extraction""": SwinvaModel, """image-classification""": SwinvaForImageClassification}
     if is_torch_available()
     else {}
 )

 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					False
 __SCREAMING_SNAKE_CASE					:List[Any]      	=					False
 __SCREAMING_SNAKE_CASE					:Dict      	=					False
 __SCREAMING_SNAKE_CASE					:Union[str, Any]      	=					False



 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    SwinvaModelTester(self      )
      __magic_name__						       =    ConfigTester(self			,				config_class=a__			,				embed_dim=37      )



 def 			snake_case__  (   self		:   Tuple      ):
      self.config_tester.create_and_test_config_to_json_string()
      self.config_tester.create_and_test_config_to_json_file()
      self.config_tester.create_and_test_config_from_and_save_pretrained()
      self.config_tester.create_and_test_config_with_num_labels()
      self.config_tester.check_config_can_be_init_without_params()
      self.config_tester.check_config_arguments_init()



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*a__      )



 @unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''      )
 def 			snake_case__  (   self		:   str      ):
      pass



 @unittest.skip(reason='''Swinv2 does not use inputs_embeds'''      )
 def 			snake_case__  (   self		:   Union[str, Any]      ):
      pass



 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           self.assertIsInstance(model.get_input_embeddings()			,				(nn.Module)      )
           __magic_name__						       =    model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(a__			,				nn.Linear      )      )



 def 			snake_case__  (   self		:   Union[str, Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(a__      )
           __magic_name__						       =    inspect.signature(model.forward      )
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           __magic_name__						       =    [*signature.parameters.keys()]

           __magic_name__						       =    ['''pixel_values''']
           self.assertListEqual(arg_names[:1]			,				a__      )



 def 			snake_case__  (   self		:   int      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__						       =    True

      for model_class in self.all_model_classes:
           __magic_name__						       =    True
           __magic_name__						       =    False
           __magic_name__						       =    True
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )
           __magic_name__						       =    outputs.attentions
           __magic_name__						       =    len(self.model_tester.depths      )
           self.assertEqual(len(a__      )			,				a__      )

           # check that output_attentions also work using config
           del inputs_dict["output_attentions"]
           __magic_name__						       =    True
           __magic_name__						       =    config.window_size**2
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )
           __magic_name__						       =    outputs.attentions
           self.assertEqual(len(a__      )			,				a__      )

           self.assertListEqual(
               list(attentions[0].shape[-3:]      )			,				[self.model_tester.num_heads[0], window_size_squared, window_size_squared]			,				)
           __magic_name__						       =    len(a__      )

           # Check attention is always last and order is fine
           __magic_name__						       =    True
           __magic_name__						       =    True
           __magic_name__						       =    model_class(a__      )
           model.to(a__      )
           model.eval()
           with torch.no_grad():
                __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )

           if hasattr(self.model_tester			,				'''num_hidden_states_types'''      ):
                __magic_name__						       =    self.model_tester.num_hidden_states_types
           else:
                # also another +1 for reshaped_hidden_states
                __magic_name__						       =    2
           self.assertEqual(out_len + added_hidden_states			,				len(a__      )      )

           __magic_name__						       =    outputs.attentions

           self.assertEqual(len(a__      )			,				a__      )

           self.assertListEqual(
               list(self_attentions[0].shape[-3:]      )			,				[self.model_tester.num_heads[0], window_size_squared, window_size_squared]			,				)



 def 			snake_case__  (   self		:   Any			,				a__		:   Dict			,				a__		:   str			,				a__		:   str			,				a__		:   List[Any]      ):
      __magic_name__						       =    model_class(a__      )
      model.to(a__      )
      model.eval()

      with torch.no_grad():
           __magic_name__						       =    model(**self._prepare_for_class(a__			,				a__      )      )

      __magic_name__						       =    outputs.hidden_states

      __magic_name__						       =    getattr(
          self.model_tester			,				'''expected_num_hidden_layers'''			,				len(self.model_tester.depths      ) + 1      )
      self.assertEqual(len(a__      )			,				a__      )

      # Swinv2 has a different seq_length
      __magic_name__						       =    (
          config.patch_size
          if isinstance(config.patch_size			,				collections.abc.Iterable      )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__						       =    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

      self.assertListEqual(
          list(hidden_states[0].shape[-2:]      )			,				[num_patches, self.model_tester.embed_dim]			,				)

      __magic_name__						       =    outputs.reshaped_hidden_states
      self.assertEqual(len(a__      )			,				a__      )

      __magic_name__       ,  __magic_name__       ,  __magic_name__       ,  __magic_name__						       =    reshaped_hidden_states[0].shape
      __magic_name__						       =    (
          reshaped_hidden_states[0].view(a__			,				a__			,				height * width      ).permute(0			,				2			,				1      )
      )
      self.assertListEqual(
          list(reshaped_hidden_states.shape[-2:]      )			,				[num_patches, self.model_tester.embed_dim]			,				)



 def 			snake_case__  (   self		:   List[Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__						       =    (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size			,				collections.abc.Iterable      )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )

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

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           __magic_name__						       =    True

           self.check_hidden_states_output(a__			,				a__			,				a__			,				a__      )



 def 			snake_case__  (   self		:   Optional[Any]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()
      __magic_name__						       =    3

      __magic_name__						       =    (
          self.model_tester.image_size
          if isinstance(self.model_tester.image_size			,				collections.abc.Iterable      )
          else (self.model_tester.image_size, self.model_tester.image_size)
      )
      __magic_name__						       =    (
          config.patch_size
          if isinstance(config.patch_size			,				collections.abc.Iterable      )
          else (config.patch_size, config.patch_size)
      )

      __magic_name__						       =    image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
      __magic_name__						       =    image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

      for model_class in self.all_model_classes:
           __magic_name__						       =    True
           self.check_hidden_states_output(a__			,				a__			,				a__			,				(padded_height, padded_width)      )

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           __magic_name__						       =    True
           self.check_hidden_states_output(a__			,				a__			,				a__			,				(padded_height, padded_width)      )



 def 			snake_case__  (   self		:   str      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_image_modeling(*a__      )



 def 			snake_case__  (   self		:   Dict      ):
      __magic_name__						       =    self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_image_classification(*a__      )



 @slow
 def 			snake_case__  (   self		:   Any      ):
      for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __magic_name__						       =    SwinvaModel.from_pretrained(a__      )
           self.assertIsNotNone(a__      )



 def 			snake_case__  (   self		:   List[str]      ):
      __magic_name__       ,  __magic_name__						       =    self.model_tester.prepare_config_and_inputs_for_common()

      __magic_name__						       =    _config_zero_init(a__      )
      for model_class in self.all_model_classes:
           __magic_name__						       =    model_class(config=a__      )
           for name, param in model.named_parameters():
                if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
                     self.assertIn(
                         ((param.data.mean() * 1E9).round() / 1E9).item()			,				[0.0, 1.0]			,				msg=F'''Parameter {name} of model {model_class} seems not properly initialized'''			,				)






@require_vision
@require_torch
class   _SCREAMING_SNAKE_CASE   (   unittest.TestCase     ):



 @cached_property
 def 			snake_case__  (   self		:   Optional[Any]      ):
      return (
          AutoImageProcessor.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''      )
          if is_vision_available()
          else None
      )



 @slow
 def 			snake_case__  (   self		:   Optional[int]      ):
      __magic_name__						       =    SwinvaForImageClassification.from_pretrained('''microsoft/swinv2-tiny-patch4-window8-256'''      ).to(
          a__      )
      __magic_name__						       =    self.default_image_processor

      __magic_name__						       =    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
      __magic_name__						       =    image_processor(images=a__			,				return_tensors='''pt'''      ).to(a__      )

      # forward pass
      with torch.no_grad():
           __magic_name__						       =    model(**a__      )

      # verify the logits
      __magic_name__						       =    torch.Size((1, 1000)      )
      self.assertEqual(outputs.logits.shape			,				a__      )
      __magic_name__						       =    torch.tensor([-0.3_947, -0.4_306, 0.0_026]      ).to(a__      )
      self.assertTrue(torch.allclose(outputs.logits[0, :3]			,				a__			,				atol=1E-4      )      )






