




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






						@slow
						@unittest.skip("""Model is not available."""       )
						def       __lowerCAmelCase(   self						:						Union[str, Any]       ):



									'''simple docstring'''






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

									snake_case__          =						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=__UpperCamelCase					,   dtype=torch.long					,   )

									with torch.no_grad():
												snake_case__          =						model(__UpperCamelCase       ).logits

									snake_case__          =						torch.Size((1, 9, 5_0_2_5_7)       )
									self.assertEqual(output.shape					,   __UpperCamelCase       )

									snake_case__          =						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=__UpperCamelCase					,   dtype=torch.half					,   )

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





'''simple docstring'''

class __magic_name__:






						def __init__(   self						:						List[Any]       ):



									'''simple docstring'''






									snake_case__          =						[]
									snake_case__          =						0
									snake_case__          =						0






						def __str__(   self						:						Union[str, Any]       ):



									'''simple docstring'''






									snake_case__          =						"""<""" + str(self.entries       )[1:-1] + """>"""
									return printed






						def       __lowerCAmelCase(   self						:						List[Any]					,   __UpperCamelCase						:						List[Any]       ):



									'''simple docstring'''






									self.entries.append(__UpperCamelCase       )
									snake_case__          =						self.length + 1






						def       __lowerCAmelCase(   self						:						int       ):



									'''simple docstring'''






									snake_case__          =						self.length - 1
									snake_case__          =						self.entries[self.front]
									# self.front-=1
									# self.entries = self.entries[self.front:]
									snake_case__          =						self.entries[1:]
									return dequeued






						def       __lowerCAmelCase(   self						:						str					,   __UpperCamelCase						:						Optional[Any]       ):



									'''simple docstring'''






									for _ in range(__UpperCamelCase       ):
												self.put(self.get()       )






						def       __lowerCAmelCase(   self						:						List[Any]       ):



									'''simple docstring'''






									return self.entries[0]






						def       __lowerCAmelCase(   self						:						str       ):



									'''simple docstring'''






									return self.length