


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):
					@slow
					@unittest.skip('Model is not available.'  )
					def 	a			(						self       :						Any  )							->					int:



											'''simple docstring'''





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

											__magic_name__					=      torch.tensor(
											    [[1_0_1, 7_1_1_0, 1_0_0_5, 1_0_5_6, 2_0_2_3, 1_1_3_3_3, 1_7_4_1_3, 1_0_2_9, 1_0_2]]	,      device=_lowerCAmelCase	,      dtype=torch.long	,      )

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

											__magic_name__					=      torch.Size((1, 9, 5_0_2_5_7)  )
											self.assertEqual(output.shape	,      _lowerCAmelCase  )

											__magic_name__					=      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=_lowerCAmelCase	,      dtype=torch.half	,      )

											for i in range(1_9  ):
																	__magic_name__		,      __magic_name__					=      8 * i // 1_7, 2_7_9_2 * i  # along the diagonal
																	__magic_name__		,      __magic_name__					=      output[0, r, c], expected_diag[i]
																	__magic_name__					=      F'''row={r} col={c} computed={computed} expected={expected}'''
																	self.assertAlmostEqual(_lowerCAmelCase	,      _lowerCAmelCase	,      delta=1E-4	,      msg=_lowerCAmelCase  )





from ..utils import DummyObject, requires_backends

class      __snake_case				(   metaclass=_UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:       str								=			["torch", "transformers", "k_diffusion"]
					def __init__(						self       :						Tuple	,      *_lowerCAmelCase       :						Union[str, Any]	,      **_lowerCAmelCase       :						Union[str, Any]  )							->					Dict:



											'''simple docstring'''





											requires_backends(self	,      ['torch', 'transformers', 'k_diffusion']  )
					@classmethod
					def 	a			(						cls       :						Optional[int]	,      *_lowerCAmelCase       :						Any	,      **_lowerCAmelCase       :						Optional[Any]  )							->					Optional[Any]:



											'''simple docstring'''





											requires_backends(cls	,      ['torch', 'transformers', 'k_diffusion']  )







					@classmethod
					def 	a			(						cls       :						Union[str, Any]	,      *_lowerCAmelCase       :						Tuple	,      **_lowerCAmelCase       :						str  )							->					Tuple:



											'''simple docstring'''





											requires_backends(cls	,      ['torch', 'transformers', 'k_diffusion']  )

