
'''simple docstring'''

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





	@slow
	@unittest.skip("Model is not available."							)
	def 							__SCREAMING_SNAKE_CASE					(   self     :    str							):


				"""simple docstring"""

				lowerCAmelCase__									=							"nvidia/megatron-gpt2-345m/"
				if "MYDIR" in os.environ:
							lowerCAmelCase__									=							os.path.join(os.environ["MYDIR"] ,							__magic_name__							)
				lowerCAmelCase__									=							GPTaLMHeadModel.from_pretrained(__magic_name__							)
				model.to(__magic_name__							)
				model.half()

				lowerCAmelCase__									=							torch.tensor(
				    [[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]] ,							device=__magic_name__ ,							dtype=torch.long ,							)

				with torch.no_grad():
							lowerCAmelCase__									=							model(__magic_name__							).logits

				lowerCAmelCase__									=							torch.Size((1, 9, 50257)							)
				self.assertEqual(output.shape ,							__magic_name__							)

				lowerCAmelCase__									=							torch.tensor(
				    [
				        4.9414,
				        -0.2920,
				        -1.2148,
				        -4.0273,
				        -0.5161,
				        -5.2109,
				        -1.2412,
				        -1.8301,
				        -1.7734,
				        -4.7148,
				        -0.2317,
				        -1.0811,
				        -2.1777,
				        0.4141,
				        -3.7969,
				        -4.0586,
				        -2.5332,
				        -3.3809,
				        4.3867,
				    ] ,							device=__magic_name__ ,							dtype=torch.half ,							)

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







'''simple docstring'''

UpperCAmelCase__				:	List[str]					=						"\n# Transformers installation\n! pip install transformers datasets evaluate\n# To install from source instead of the last release, comment the command above and uncomment the following one.\n# ! pip install git+https://github.com/huggingface/transformers.git\n"

UpperCAmelCase__				:	Any					=						[{"type": "code", "content": INSTALL_CONTENT}]
UpperCAmelCase__				:	Union[str, Any]					=						{
    "{processor_class}": "FakeProcessorClass",
    "{model_class}": "FakeModelClass",
    "{object_class}": "FakeObjectClass",
}





