


'''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 		_snake_case					(     unittest.TestCase	):




					@slow
					def 				snake_case__						(      self):
								UpperCAmelCase__  :					List[Any]        =     AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
								UpperCAmelCase__  :					str        =     AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip""")
								model.to(_A)

								from datasets import load_dataset

								UpperCAmelCase__  :					Tuple        =     load_dataset("""nielsr/rvlcdip-demo""")

								UpperCAmelCase__  :					Dict        =     dataset["""train"""][0]["""image"""].convert("""RGB""")

								UpperCAmelCase__  :					Optional[int]        =     image_processor(_A							,							return_tensors="""pt""").to(_A)

								# forward pass
								with torch.no_grad():
											UpperCAmelCase__  :					Tuple        =     model(**_A)
											UpperCAmelCase__  :					Optional[int]        =     outputs.logits

								UpperCAmelCase__  :					Union[str, Any]        =     torch.Size((1, 16))
								self.assertEqual(logits.shape							,							_A)

								UpperCAmelCase__  :					List[str]        =     torch.tensor(
								    [-0.4158, -0.4092, -0.4347]							,							device=_A							,							dtype=torch.float							,							)
								self.assertTrue(torch.allclose(logits[0, :3]							,							_A							,							atol=1e-4))



'''simple docstring'''



import unittest

from transformers import AutoTokenizer, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, slow


if is_flax_available():
		import jax.numpy as jnp

		from transformers import FlaxXLMRobertaModel


@require_sentencepiece
@require_tokenizers
@require_flax
class 		_snake_case					(     unittest.TestCase	):




					@slow
					def 				snake_case__						(      self):
								UpperCAmelCase__  :					Union[str, Any]        =     FlaxXLMRobertaModel.from_pretrained("""xlm-roberta-base""")
								UpperCAmelCase__  :					List[str]        =     AutoTokenizer.from_pretrained("""xlm-roberta-base""")
								UpperCAmelCase__  :					Dict        =     """The dog is cute and lives in the garden house"""
								UpperCAmelCase__  :					Dict        =     jnp.array([tokenizer.encode(_lowerCamelCase)])

								UpperCAmelCase__  :					int        =     (1, 12, 768)  # batch_size, sequence_length, embedding_vector_dim
								UpperCAmelCase__  :					Any        =     jnp.array(
								    [[-0.0101, 0.1218, -0.0803, 0.0801, 0.1327, 0.0776, -0.1215, 0.2383, 0.3338, 0.3106, 0.0300, 0.0252]])

								UpperCAmelCase__  :					Any        =     model(_lowerCamelCase)["""last_hidden_state"""]
								self.assertEqual(output.shape							,							_lowerCamelCase)
								# compare the actual values for a slice of last dim
								self.assertTrue(jnp.allclose(output[:, :, -1]							,							_lowerCamelCase							,							atol=1e-3))