




import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
		import torch

		from transformers import GPTaLMHeadModel




@require_torch
@require_sentencepiece
@require_tokenizers
class    snake_case__							(unittest.TestCase       ):
				"""simple docstring"""



				@slow
				@unittest.skip("Model is not available."							)
				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					int:
							a   =      "nvidia/megatron-gpt2-345m/"
							if "MYDIR" in os.environ:
										a   =      os.path.join(os.environ["MYDIR"] ,				__lowerCamelCase							)
							a   =      GPTaLMHeadModel.from_pretrained(__lowerCamelCase							)
							model.to(__lowerCamelCase							)
							model.half()

							a   =      torch.tensor(
							    [[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]] ,				device=__lowerCamelCase ,				dtype=torch.long ,				)

							with torch.no_grad():
										a   =      model(__lowerCamelCase							).logits

							a   =      torch.Size((1, 9, 5_02_57)							)
							self.assertEqual(output.shape ,				__lowerCamelCase							)

							a   =      torch.tensor(
							    [
							        4.9_414,
							        -0.2_920,
							        -1.2_148,
							        -4.0_273,
							        -0.5_161,
							        -5.2_109,
							        -1.2_412,
							        -1.8_301,
							        -1.7_734,
							        -4.7_148,
							        -0.2_317,
							        -1.0_811,
							        -2.1_777,
							        0.4_141,
							        -3.7_969,
							        -4.0_586,
							        -2.5_332,
							        -3.3_809,
							        4.3_867,
							    ] ,				device=__lowerCamelCase ,				dtype=torch.half ,				)

							for i in range(19							):
										a   ,		a   =      8 * i // 17, 27_92 * i  # along the diagonal
										a   ,		a   =      output[0, r, c], expected_diag[i]
										a   =      f"""row={r} col={c} computed={computed} expected={expected}"""
										self.assertAlmostEqual(__lowerCamelCase ,				__lowerCamelCase ,				delta=1e-4 ,				msg=__lowerCamelCase							)












import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
		import torch

		from transformers import CamembertModel




@require_torch
@require_sentencepiece
@require_tokenizers
class    snake_case__							(unittest.TestCase       ):
				"""simple docstring"""



				@slow
				def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					List[str]:
							a   =      CamembertModel.from_pretrained("camembert-base"							)
							model.to(__lowerCamelCase							)

							a   =      torch.tensor(
							    [[5, 1_21, 11, 6_60, 16, 7_30, 2_55_43, 1_10, 83, 6]] ,				device=__lowerCamelCase ,				dtype=torch.long ,				)  # J'aime le camembert !
							with torch.no_grad():
										a   =      model(__lowerCamelCase							)["last_hidden_state"]
							a   =      torch.Size((1, 10, 7_68)							)
							self.assertEqual(output.shape ,				__lowerCamelCase							)
							# compare the actual values for a slice.
							a   =      torch.tensor(
							    [[[-0.0_254, 0.0_235, 0.1_027], [0.0_606, -0.1_811, -0.0_418], [-0.1_561, -0.1_127, 0.2_687]]] ,				device=__lowerCamelCase ,				dtype=torch.float ,				)
							# camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
							# camembert.eval()
							# expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

							self.assertTrue(torch.allclose(output[:, :3, :3] ,				__lowerCamelCase ,				atol=1e-4							)							)






