



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






	'''simple docstring'''

	@slow
	@unittest.skip("""Model is not available."""					)
	def      lowercase__							(  self		:  int					)     ->			str:




								'''simple docstring'''





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

								lowerCAmelCase__  =   torch.tensor(
								    [[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]   ,		device=snake_case_   ,		dtype=torch.long   ,		)

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

								lowerCAmelCase__  =   torch.Size((1, 9, 5_0257)					)
								self.assertEqual(output.shape   ,		snake_case_					)

								lowerCAmelCase__  =   torch.tensor(
								    [
								        4.9_4_1_4,
								        -0.2_9_2_0,
								        -1.2_1_4_8,
								        -4.0_2_7_3,
								        -0.5_1_6_1,
								        -5.2_1_0_9,
								        -1.2_4_1_2,
								        -1.8_3_0_1,
								        -1.7_7_3_4,
								        -4.7_1_4_8,
								        -0.2_3_1_7,
								        -1.0_8_1_1,
								        -2.1_7_7_7,
								        0.4_1_4_1,
								        -3.7_9_6_9,
								        -4.0_5_8_6,
								        -2.5_3_3_2,
								        -3.3_8_0_9,
								        4.3_8_6_7,
								    ]   ,		device=snake_case_   ,		dtype=torch.half   ,		)

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






'''simple docstring'''

from __future__ import annotations


def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[int | float])    ->		int | float:



						"""simple docstring"""

						if len(_lowerCAmelCase) == 0:
												raise ValueError("find_max() arg is an empty sequence")
						snake_case :       Any				=    nums[0]
						for x in nums:
												if x > max_num:
																		snake_case :       int				=    x
						return max_num


if __name__ == "__main__":
						import doctest

						doctest.testmod(verbose=True)





