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




	'''simple docstring'''





	@slow
	@unittest.skip("Model is not available."				)
	def        UpperCamelCase_						( self      :				Any				):
					__A         =				"nvidia/megatron-gpt2-345m/"
					if "MYDIR" in os.environ:
									__A         =				os.path.join(os.environ["MYDIR"]							,A				)
					__A         =				GPTaLMHeadModel.from_pretrained(A				)
					model.to(A				)
					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=A							,dtype=torch.long							,)

					with torch.no_grad():
									__A         =				model(A				).logits

					__A         =				torch.Size((1, 9, 5_02_57)				)
					self.assertEqual(output.shape							,A				)

					__A         =				torch.tensor(
					    [
					        4.94_14,
					        -0.29_20,
					        -1.21_48,
					        -4.02_73,
					        -0.51_61,
					        -5.21_09,
					        -1.24_12,
					        -1.83_01,
					        -1.77_34,
					        -4.71_48,
					        -0.23_17,
					        -1.08_11,
					        -2.17_77,
					        0.41_41,
					        -3.79_69,
					        -4.05_86,
					        -2.53_32,
					        -3.38_09,
					        4.38_67,
					    ]							,device=A							,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(A							,A							,delta=1E-4							,msg=A				)


import torch

from transformers import PreTrainedModel

from .custom_configuration import CustomConfig, NoSuperInitConfig





class 							UpperCAmelCase   (						__SCREAMING_SNAKE_CASE						):




	'''simple docstring'''





	snake_case_      					=  CustomConfig






	def __init__( self      :				Optional[int]							,A      :				List[str]				):
					super().__init__(A				)
					__A         =				torch.nn.Linear(config.hidden_size							,config.hidden_size				)






	def        UpperCamelCase_						( self      :				Union[str, Any]							,A      :				Optional[int]				):
					return self.linear(A				)







	def        UpperCamelCase_						( self      :				Optional[int]							,A      :				int				):
					pass





class 							UpperCAmelCase   (						__SCREAMING_SNAKE_CASE						):




	'''simple docstring'''





	snake_case_      					=  NoSuperInitConfig






	def __init__( self      :				Optional[int]							,A      :				Union[str, Any]				):
					super().__init__(A				)
					__A         =				torch.nn.Linear(config.attribute							,config.attribute				)






	def        UpperCamelCase_						( self      :				str							,A      :				Any				):
					return self.linear(A				)







	def        UpperCamelCase_						( self      :				Tuple							,A      :				int				):
					pass
