



"""simple docstring"""

import unittest

from diffusers import FlaxAutoencoderKL
from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax

from .test_modeling_common_flax import FlaxModelTesterMixin


if is_flax_available():
     import jax




@require_flax
class  _UpperCAmelCase (    _a					,  unittest.TestCase):
 _lowerCAmelCase     :    int	      =	FlaxAutoencoderKL

 @property
 def 		_snake_case      (  self	: Tuple       ):
     snake_case_				:  List[Any]       =			4
     snake_case_				:  Any       =			3
     snake_case_				:  str       =			(32, 32)

     snake_case_				:  Tuple       =			jax.random.PRNGKey(0       )
     snake_case_				:  Any       =			jax.random.uniform(_A						,  ((batch_size, num_channels) + sizes)       )

     return {"sample": image, "prng_key": prng_key}






 def 		_snake_case      (  self	: Union[str, Any]       ):
     snake_case_				:  Optional[Any]       =			{
         '''block_out_channels''': [32, 64],
         '''in_channels''': 3,
         '''out_channels''': 3,
         '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
         '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
         '''latent_channels''': 4,
     }
     snake_case_				:  str       =			self.dummy_input
     return init_dict, inputs_dict










"""simple docstring"""

import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
     import torch

     from transformers import AutoModelForImageClassification

if is_vision_available():
     from transformers import AutoImageProcessor




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

 @slow
 def 		_snake_case      (  self	: List[Any]       ):
     snake_case_				:  List[Any]       =			AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''       )
     snake_case_				:  List[Any]       =			AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''       )
     model.to(lowercase_       )

     from datasets import load_dataset

     snake_case_				:  str       =			load_dataset('''nielsr/rvlcdip-demo'''       )

     snake_case_				:  Tuple       =			dataset['''train'''][0]['''image'''].convert('''RGB'''       )

     snake_case_				:  Union[str, Any]       =			image_processor(lowercase_						,  return_tensors='''pt'''       ).to(lowercase_       )

     # forward pass
     with torch.no_grad():
         snake_case_				:  List[Any]       =			model(**lowercase_       )
         snake_case_				:  int       =			outputs.logits

     snake_case_				:  Any       =			torch.Size((1, 16)       )
     self.assertEqual(logits.shape						,  lowercase_       )

     snake_case_				:  Any       =			torch.tensor(
         [-0.41_58, -0.40_92, -0.43_47]						,  device=lowercase_						,  dtype=torch.float						,  )
     self.assertTrue(torch.allclose(logits[0, :3]						,  lowercase_						,  atol=1E-4       )       )





