



"""simple docstring"""
import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
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, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
      from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor



class    SCREAMING_SNAKE_CASE__						:

   def __init__(     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE=13   ,  _SCREAMING_SNAKE_CASE=32   ,  _SCREAMING_SNAKE_CASE=3   ,  _SCREAMING_SNAKE_CASE=4   ,  _SCREAMING_SNAKE_CASE=[10, 20, 30, 40]   ,  _SCREAMING_SNAKE_CASE=[2, 2, 3, 2]   ,  _SCREAMING_SNAKE_CASE=True   ,  _SCREAMING_SNAKE_CASE=True   ,  _SCREAMING_SNAKE_CASE=37   ,  _SCREAMING_SNAKE_CASE="gelu"   ,  _SCREAMING_SNAKE_CASE=10   ,  _SCREAMING_SNAKE_CASE=0.02   ,  _SCREAMING_SNAKE_CASE=["stage2", "stage3", "stage4"]   ,  _SCREAMING_SNAKE_CASE=[2, 3, 4]   ,  _SCREAMING_SNAKE_CASE=None   ,  )						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			:      str			=			parent
    UpperCAmelCase			:      Union[str, Any]			=			batch_size
    UpperCAmelCase			:      Tuple			=			image_size
    UpperCAmelCase			:      Any			=			num_channels
    UpperCAmelCase			:      List[Any]			=			num_stages
    UpperCAmelCase			:      str			=			hidden_sizes
    UpperCAmelCase			:      Union[str, Any]			=			depths
    UpperCAmelCase			:      Union[str, Any]			=			is_training
    UpperCAmelCase			:      Any			=			use_labels
    UpperCAmelCase			:      Optional[int]			=			intermediate_size
    UpperCAmelCase			:      Optional[Any]			=			hidden_act
    UpperCAmelCase			:      List[str]			=			num_labels
    UpperCAmelCase			:      List[str]			=			initializer_range
    UpperCAmelCase			:      List[Any]			=			out_features
    UpperCAmelCase			:      Any			=			out_indices
    UpperCAmelCase			:      Any			=			scope

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    UpperCAmelCase			:      int			=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

    UpperCAmelCase			:      str			=			None
    if self.use_labels:
     UpperCAmelCase			:      Optional[int]			=			ids_tensor([self.batch_size]   ,  self.num_labels		)

    UpperCAmelCase			:      Optional[int]			=			self.get_config()

    return config, pixel_values, labels

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    return ConvNextVaConfig(
        num_channels=self.num_channels   ,  hidden_sizes=self.hidden_sizes   ,  depths=self.depths   ,  num_stages=self.num_stages   ,  hidden_act=self.hidden_act   ,  is_decoder=__a   ,  initializer_range=self.initializer_range   ,  out_features=self.out_features   ,  out_indices=self.out_indices   ,  num_labels=self.num_labels   ,  )

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase			:      Union[str, Any]			=			ConvNextVaModel(config=__a		)
    model.to(__a		)
    model.eval()
    UpperCAmelCase			:      Union[str, Any]			=			model(__a		)
    # expected last hidden states: B, C, H // 32, W // 32
    self.parent.assertEqual(
        result.last_hidden_state.shape   ,  (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)   ,  )

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Optional[int]:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			ConvNextVaForImageClassification(__a		)
    model.to(__a		)
    model.eval()
    UpperCAmelCase			:      Optional[int]			=			model(__a   ,  labels=__a		)
    self.parent.assertEqual(result.logits.shape   ,  (self.batch_size, self.num_labels)		)

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Tuple:





    '''simple docstring'''




    UpperCAmelCase			:      Union[str, Any]			=			ConvNextVaBackbone(config=__a		)
    model.to(__a		)
    model.eval()
    UpperCAmelCase			:      List[str]			=			model(__a		)

    # verify hidden states
    self.parent.assertEqual(len(result.feature_maps		)   ,  len(config.out_features		)		)
    self.parent.assertListEqual(list(result.feature_maps[0].shape		)   ,  [self.batch_size, self.hidden_sizes[1], 4, 4]		)

    # verify channels
    self.parent.assertEqual(len(model.channels		)   ,  len(config.out_features		)		)
    self.parent.assertListEqual(model.channels   ,  config.hidden_sizes[1:]		)

    # verify backbone works with out_features=None
    UpperCAmelCase			:      Dict			=			None
    UpperCAmelCase			:      str			=			ConvNextVaBackbone(config=__a		)
    model.to(__a		)
    model.eval()
    UpperCAmelCase			:      Union[str, Any]			=			model(__a		)

    # verify feature maps
    self.parent.assertEqual(len(result.feature_maps		)   ,  1		)
    self.parent.assertListEqual(list(result.feature_maps[0].shape		)   ,  [self.batch_size, self.hidden_sizes[-1], 1, 1]		)

    # verify channels
    self.parent.assertEqual(len(model.channels		)   ,  1		)
    self.parent.assertListEqual(model.channels   ,  [config.hidden_sizes[-1]]		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      int			=			self.prepare_config_and_inputs()
    UpperCAmelCase			:      int			=			config_and_inputs
    UpperCAmelCase			:      str			=			{"pixel_values": pixel_values}
    return config, inputs_dict




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      List[Any]			=			self.prepare_config_and_inputs()
    UpperCAmelCase			:      int			=			config_and_inputs
    UpperCAmelCase			:      Optional[int]			=			{"pixel_values": pixel_values, "labels": labels}
    return config, inputs_dict



@require_torch
class    SCREAMING_SNAKE_CASE__						(      _UpperCamelCase   ,    _UpperCamelCase   ,    unittest.TestCase				):
   __lowerCAmelCase						:     Tuple		=		(
       (
           ConvNextVaModel,
           ConvNextVaForImageClassification,
           ConvNextVaBackbone,
       )
       if is_torch_available()
       else ()
   )
   __lowerCAmelCase						:     List[Any]		=		(
       {"feature-extraction": ConvNextVaModel, "image-classification": ConvNextVaForImageClassification}
       if is_torch_available()
       else {}
   )

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

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      List[Any]			=			ConvNextVaModelTester(self		)
    UpperCAmelCase			:      Dict			=			ConfigTester(self   ,  config_class=__a   ,  has_text_modality=__a   ,  hidden_size=37		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    self.create_and_test_config_common_properties()
    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 			SCREAMING_SNAKE_CASE  (     self		)						->   str:





    '''simple docstring'''




    return

   @unittest.skip(reason="""ConvNextV2 does not use inputs_embeds"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    pass

   @unittest.skip(reason="""ConvNextV2 does not support input and output embeddings"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    pass

   @unittest.skip(reason="""ConvNextV2 does not use feedforward chunking"""		)
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    pass

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    if not self.model_tester.is_training:
     return

    for model_class in self.all_model_classes:
     UpperCAmelCase			:      Tuple			=			self.model_tester.prepare_config_and_inputs_with_labels()
     UpperCAmelCase			:      Any			=			True

     if model_class.__name__ in [
         *get_values(__a		),
         *get_values(__a		),
     ]:
      continue

     UpperCAmelCase			:      Tuple			=			model_class(__a		)
     model.to(__a		)
     model.train()
     UpperCAmelCase			:      List[str]			=			self._prepare_for_class(__a   ,  __a   ,  return_labels=__a		)
     UpperCAmelCase			:      Optional[Any]			=			model(**__a		).loss
     loss.backward()

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[int]:





    '''simple docstring'''




    if not self.model_tester.is_training:
     return

    for model_class in self.all_model_classes:
     UpperCAmelCase			:      Tuple			=			self.model_tester.prepare_config_and_inputs_with_labels()
     UpperCAmelCase			:      Dict			=			False
     UpperCAmelCase			:      Optional[int]			=			True

     if (
         model_class.__name__
         in [*get_values(__a		), *get_values(__a		)]
         or not model_class.supports_gradient_checkpointing
     ):
      continue

     UpperCAmelCase			:      List[Any]			=			model_class(__a		)
     model.to(__a		)
     model.gradient_checkpointing_enable()
     model.train()
     UpperCAmelCase			:      Optional[int]			=			self._prepare_for_class(__a   ,  __a   ,  return_labels=__a		)
     UpperCAmelCase			:      Optional[int]			=			model(**__a		).loss
     loss.backward()

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      int			=			self.model_tester.prepare_config_and_inputs_for_common()

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

     UpperCAmelCase			:      Tuple			=			["pixel_values"]
     self.assertListEqual(arg_names[:1]   ,  __a		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      int			=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__a		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Tuple:





    '''simple docstring'''




    def check_hidden_states_output(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		):
     UpperCAmelCase			:      int			=			model_class(__a		)
     model.to(__a		)
     model.eval()

     with torch.no_grad():
      UpperCAmelCase			:      List[Any]			=			model(**self._prepare_for_class(__a   ,  __a		)		)

     UpperCAmelCase			:      List[Any]			=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

     UpperCAmelCase			:      Optional[Any]			=			self.model_tester.num_stages
     self.assertEqual(len(__a		)   ,  expected_num_stages + 1		)

     # ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
     self.assertListEqual(
         list(hidden_states[0].shape[-2:]		)   ,  [self.model_tester.image_size // 4, self.model_tester.image_size // 4]   ,  )

    UpperCAmelCase			:      Dict			=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     UpperCAmelCase			:      Dict			=			True
     check_hidden_states_output(__a   ,  __a   ,  __a		)

     # check that output_hidden_states also work using config
     del inputs_dict["output_hidden_states"]
     UpperCAmelCase			:      Optional[int]			=			True

     check_hidden_states_output(__a   ,  __a   ,  __a		)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Optional[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      int			=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*__a		)




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase			:      Any			=			ConvNextVaModel.from_pretrained(__a		)
     self.assertIsNotNone(__a		)

def    _snake_case		(		):
 UpperCAmelCase			:      Dict			=			Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
 return image



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

   @cached_property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[str]:





    '''simple docstring'''




    return AutoImageProcessor.from_pretrained("""facebook/convnextv2-tiny-1k-224"""		) if is_vision_available() else None




   @slow
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			ConvNextVaForImageClassification.from_pretrained("""facebook/convnextv2-tiny-1k-224"""		).to(__a		)

    UpperCAmelCase			:      List[Any]			=			self.default_image_processor
    UpperCAmelCase			:      Optional[Any]			=			prepare_img()
    UpperCAmelCase			:      List[Any]			=			preprocessor(images=__a   ,  return_tensors="""pt"""		).to(__a		)

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

    # verify the logits
    UpperCAmelCase			:      Union[str, Any]			=			torch.Size((1, 1000)		)
    self.assertEqual(outputs.logits.shape   ,  __a		)

    UpperCAmelCase			:      Union[str, Any]			=			torch.tensor([0.9996, 0.1966, -0.4386]		).to(__a		)
    self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,  __a   ,  atol=1E-4		)		)





"""simple docstring"""
import gc
import inspect
import unittest

import torch
from parameterized import parameterized

from diffusers import PriorTransformer
from diffusers.utils import floats_tensor, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin


enable_full_determinism()



class    SCREAMING_SNAKE_CASE__						(      UpperCAmelCase__   ,    unittest.TestCase				):
   __lowerCAmelCase						:     int		=		PriorTransformer
   __lowerCAmelCase						:     Dict		=		'hidden_states'

   @property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    UpperCAmelCase			:      Tuple			=			4
    UpperCAmelCase			:      Optional[Any]			=			8
    UpperCAmelCase			:      Union[str, Any]			=			7

    UpperCAmelCase			:      Any			=			floats_tensor((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      List[Any]			=			floats_tensor((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      List[Any]			=			floats_tensor((batch_size, num_embeddings, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    return {
        "hidden_states": hidden_states,
        "timestep": 2,
        "proj_embedding": proj_embedding,
        "encoder_hidden_states": encoder_hidden_states,
    }

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE=0		)						->   Any:





    '''simple docstring'''




    torch.manual_seed(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Any			=			4
    UpperCAmelCase			:      Any			=			8
    UpperCAmelCase			:      List[Any]			=			7

    UpperCAmelCase			:      Any			=			torch.randn((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      List[Any]			=			torch.randn((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      str			=			torch.randn((batch_size, num_embeddings, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    return {
        "hidden_states": hidden_states,
        "timestep": 2,
        "proj_embedding": proj_embedding,
        "encoder_hidden_states": encoder_hidden_states,
    }

   @property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   List[Any]:





    '''simple docstring'''




    return (4, 8)

   @property
   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    return (4, 8)

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[int]			=			{
        """num_attention_heads""": 2,
        """attention_head_dim""": 4,
        """num_layers""": 2,
        """embedding_dim""": 8,
        """num_embeddings""": 7,
        """additional_embeddings""": 4,
    }
    UpperCAmelCase			:      Tuple			=			self.dummy_input
    return init_dict, inputs_dict

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Dict:





    '''simple docstring'''




    UpperCAmelCase			,	UpperCAmelCase			:      Optional[Any]			=			PriorTransformer.from_pretrained(
        """hf-internal-testing/prior-dummy"""   ,  output_loading_info=_SCREAMING_SNAKE_CASE		)
    self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)
    self.assertEqual(len(loading_info["""missing_keys"""]		)   ,  0		)

    model.to(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Dict			=			model(**self.dummy_input		)[0]

    assert hidden_states is not None, "Make sure output is not None"

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    UpperCAmelCase			,	UpperCAmelCase			:      Tuple			=			self.prepare_init_args_and_inputs_for_common()

    UpperCAmelCase			:      str			=			self.model_class(**_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      List[str]			=			inspect.signature(model.forward		)
    # signature.parameters is an OrderedDict => so arg_names order is deterministic
    UpperCAmelCase			:      Union[str, Any]			=			[*signature.parameters.keys()]

    UpperCAmelCase			:      int			=			["""hidden_states""", """timestep"""]
    self.assertListEqual(arg_names[:2]   ,  _SCREAMING_SNAKE_CASE		)




   def 			SCREAMING_SNAKE_CASE  (     self		)						->   Any:





    '''simple docstring'''




    UpperCAmelCase			:      Optional[Any]			=			PriorTransformer.from_pretrained("""hf-internal-testing/prior-dummy"""		)
    UpperCAmelCase			:      Dict			=			model.to(_SCREAMING_SNAKE_CASE		)

    if hasattr(_SCREAMING_SNAKE_CASE   ,  """set_default_attn_processor"""		):
     model.set_default_attn_processor()

    UpperCAmelCase			:      str			=			self.get_dummy_seed_input()

    with torch.no_grad():
     UpperCAmelCase			:      str			=			model(**_SCREAMING_SNAKE_CASE		)[0]

    UpperCAmelCase			:      Dict			=			output[0, :5].flatten().cpu()
    print(_SCREAMING_SNAKE_CASE		)

    # Since the VAE Gaussian prior's generator is seeded on the appropriate device,
    # the expected output slices are not the same for CPU and GPU.
    UpperCAmelCase			:      Dict			=			torch.tensor([-1.3436, -0.2870, 0.7538, 0.4368, -0.0239]		)
    self.assertTrue(torch_all_close(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  rtol=1E-2		)		)



@slow
class    SCREAMING_SNAKE_CASE__						(      unittest.TestCase				):

   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE=1   ,  _SCREAMING_SNAKE_CASE=768   ,  _SCREAMING_SNAKE_CASE=77   ,  _SCREAMING_SNAKE_CASE=0		)						->   int:





    '''simple docstring'''




    torch.manual_seed(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Optional[Any]			=			batch_size
    UpperCAmelCase			:      int			=			embedding_dim
    UpperCAmelCase			:      Tuple			=			num_embeddings

    UpperCAmelCase			:      Optional[Any]			=			torch.randn((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    UpperCAmelCase			:      str			=			torch.randn((batch_size, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Dict			=			torch.randn((batch_size, num_embeddings, embedding_dim)		).to(_SCREAMING_SNAKE_CASE		)

    return {
        "hidden_states": hidden_states,
        "timestep": 2,
        "proj_embedding": proj_embedding,
        "encoder_hidden_states": encoder_hidden_states,
    }

   def 			SCREAMING_SNAKE_CASE  (     self		)						->   int:





    '''simple docstring'''




    super().tearDown()
    gc.collect()
    torch.cuda.empty_cache()




   @parameterized.expand(
       [
           # fmt: off
           [13, [-0.5861,  0.1283, -0.0931,  0.0882,  0.4476,  0.1329, -0.0498,  0.0640]],
           [37, [-0.4913,  0.0110, -0.0483,  0.0541,  0.4954, -0.0170,  0.0354,  0.1651]],
           # fmt: on
       ]		)
   def 			SCREAMING_SNAKE_CASE  (     self   ,  _SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE		)						->   Any:





    '''simple docstring'''




    UpperCAmelCase			:      Dict			=			PriorTransformer.from_pretrained("""kandinsky-community/kandinsky-2-1-prior"""   ,  subfolder="""prior"""		)
    model.to(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Any			=			self.get_dummy_seed_input(seed=_SCREAMING_SNAKE_CASE		)

    with torch.no_grad():
     UpperCAmelCase			:      Any			=			model(**_SCREAMING_SNAKE_CASE		)[0]

    assert list(sample.shape		) == [1, 768]

    UpperCAmelCase			:      int			=			sample[0, :8].flatten().cpu()
    print(_SCREAMING_SNAKE_CASE		)
    UpperCAmelCase			:      Optional[int]			=			torch.tensor(_SCREAMING_SNAKE_CASE		)

    assert torch_all_close(_SCREAMING_SNAKE_CASE   ,  _SCREAMING_SNAKE_CASE   ,  atol=1E-3		)
