'''simple docstring'''





import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch




@require_torch
class 	__A				:



				@property
				def  _lowercase						(self   :   int			):
									return self.get_dummy_input()



				@property
				def  _lowercase						(self   :   Any			):
									if self.block_type == "down":
														return (4, 32, 16, 16)
									elif self.block_type == "mid":
														return (4, 32, 32, 32)
									elif self.block_type == "up":
														return (4, 32, 64, 64)

									raise ValueError(f"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."""			)



				def  _lowercase						(self   :   Tuple       ,      __a   :   List[str]=True       ,      __a   :   Any=False       ,      __a   :   List[Any]=False       ,      __a   :   Any=False       ,      ):
									UpperCAmelCase_	   =       4
									UpperCAmelCase_	   =       32
									UpperCAmelCase_	   =       (32, 32)

									UpperCAmelCase_	   =       torch.manual_seed(0			)
									UpperCAmelCase_	   =       torch.device(__a			)
									UpperCAmelCase_	   =       (batch_size, num_channels) + sizes
									UpperCAmelCase_	   =       randn_tensor(__a       ,      generator=__a       ,      device=__a			)
									UpperCAmelCase_	   =       {"hidden_states": hidden_states}

									if include_temb:
														UpperCAmelCase_	   =       128
														UpperCAmelCase_	   =       randn_tensor((batch_size, temb_channels)       ,      generator=__a       ,      device=__a			)

									if include_res_hidden_states_tuple:
														UpperCAmelCase_	   =       torch.manual_seed(1			)
														UpperCAmelCase_	   =       (randn_tensor(__a       ,      generator=__a       ,      device=__a			),)

									if include_encoder_hidden_states:
														UpperCAmelCase_	   =       floats_tensor((batch_size, 32, 32)			).to(__a			)

									if include_skip_sample:
														UpperCAmelCase_	   =       randn_tensor(((batch_size, 3) + sizes)       ,      generator=__a       ,      device=__a			)

									return dummy_input



				def  _lowercase						(self   :   Tuple			):
									UpperCAmelCase_	   =       {
									    "in_channels": 32,
									    "out_channels": 32,
									    "temb_channels": 128,
									}
									if self.block_type == "up":
														UpperCAmelCase_	   =       32

									if self.block_type == "mid":
														init_dict.pop("out_channels"			)

									UpperCAmelCase_	   =       self.dummy_input
									return init_dict, inputs_dict



				def  _lowercase						(self   :   Tuple       ,      __a   :   Any			):
									UpperCAmelCase_   ,			UpperCAmelCase_	   =       self.prepare_init_args_and_inputs_for_common()
									UpperCAmelCase_	   =       self.block_class(**__a			)
									unet_block.to(__a			)
									unet_block.eval()

									with torch.no_grad():
														UpperCAmelCase_	   =       unet_block(**__a			)

									if isinstance(__a       ,      __a			):
														UpperCAmelCase_	   =       output[0]

									self.assertEqual(output.shape       ,      self.output_shape			)

									UpperCAmelCase_	   =       output[0, -1, -3:, -3:]
									UpperCAmelCase_	   =       torch.tensor(__a			).to(__a			)
									assert torch_all_close(output_slice.flatten()       ,      __a       ,      atol=5E-3			)






				@unittest.skipIf(torch_device == "mps"       ,      "Training is not supported in mps"			)
				def  _lowercase						(self   :   Dict			):
									UpperCAmelCase_   ,			UpperCAmelCase_	   =       self.prepare_init_args_and_inputs_for_common()
									UpperCAmelCase_	   =       self.block_class(**__a			)
									model.to(__a			)
									model.train()
									UpperCAmelCase_	   =       model(**__a			)

									if isinstance(__a       ,      __a			):
														UpperCAmelCase_	   =       output[0]

									UpperCAmelCase_	   =       torch.device(__a			)
									UpperCAmelCase_	   =       randn_tensor(output.shape       ,      device=__a			)
									UpperCAmelCase_	   =       torch.nn.functional.mse_loss(__a       ,      __a			)
									loss.backward()





'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
    import numpy as np
    import tensorflow as tf

    from transformers import TFCamembertModel




@require_tf
@require_sentencepiece
@require_tokenizers
class 	__A				(			unittest.TestCase     ):



    @slow
    def  _lowercase						(self   :   Dict			):
         UpperCAmelCase_	   =       TFCamembertModel.from_pretrained("jplu/tf-camembert-base"			)

         UpperCAmelCase_	   =       tf.convert_to_tensor(
             [[5, 121, 11, 660, 16, 730, 25543, 110, 83, 6]]       ,      dtype=tf.intaa       ,      )  # J'aime le camembert !"

         UpperCAmelCase_	   =       model(__a			)["last_hidden_state"]
         UpperCAmelCase_	   =       tf.TensorShape((1, 10, 768)			)
         self.assertEqual(output.shape       ,      __a			)
         # compare the actual values for a slice.
         UpperCAmelCase_	   =       tf.convert_to_tensor(
             [[[-0.02_54, 0.02_35, 0.10_27], [0.06_06, -0.18_11, -0.04_18], [-0.15_61, -0.11_27, 0.26_87]]]       ,      dtype=tf.floataa       ,      )
         # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
         # camembert.eval()
         # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

         self.assertTrue(np.allclose(output[:, :3, :3].numpy()       ,      expected_slice.numpy()       ,      atol=1E-4			)			)




