





'''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   lowercase__    (      self				:      int )				->						str:


					"""simple docstring"""

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

					__snake_case				:			Optional[int]       			=    torch.tensor(
					    [[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]     ,			device=__magic_name__     ,			dtype=torch.long     ,			)

					with torch.no_grad():
								__snake_case				:			Optional[int]       			=    model(__magic_name__ ).logits

					__snake_case				:			Tuple       			=    torch.Size((1, 9, 5_02_57) )
					self.assertEqual(output.shape     ,			__magic_name__ )

					__snake_case				:			Union[str, Any]       			=    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 ):
								__snake_case			,    __snake_case				:			Optional[Any]       			=    8 * i // 17, 27_92 * i  # along the diagonal
								__snake_case			,    __snake_case				:			Optional[Any]       			=    output[0, r, c], expected_diag[i]
								__snake_case				:			Union[str, Any]       			=    f'''row={r} col={c} computed={computed} expected={expected}'''
								self.assertAlmostEqual(__magic_name__     ,			__magic_name__     ,			delta=1E-4     ,			msg=__magic_name__ )









'''simple docstring'''






def 				_a	(					_lowerCamelCase   )   ->							bool:



			"""simple docstring"""


			__snake_case				:			Optional[Any]       			=    [list(_lowerCamelCase   ) for row in matrix]
			if matrix and isinstance(_lowerCamelCase						,  _lowerCamelCase   ):
						if isinstance(matrix[0]						,  _lowerCamelCase   ):
									__snake_case				:			str       			=    0
									for row in matrix:
												if prev_len == 0:
															__snake_case				:			Dict       			=    len(_lowerCamelCase   )
															__snake_case				:			List[Any]       			=    True
												else:
															__snake_case				:			Union[str, Any]       			=    prev_len == len(_lowerCamelCase   )
						else:
									__snake_case				:			List[Any]       			=    True
			else:
						__snake_case				:			List[str]       			=    False

			return result







def 				_a	(					_lowerCamelCase   )   ->							None:



			"""simple docstring"""


			if check_matrix(_lowerCamelCase   ) and len(_lowerCamelCase   ) > 0:
						__snake_case				:			List[str]       			=    [list(_lowerCamelCase   ) for row in a]
						__snake_case				:			Optional[Any]       			=    len(_lowerCamelCase   )
						if isinstance(a[0]						,  _lowerCamelCase   ):
									__snake_case				:			Tuple       			=    len(a[0]   )
						else:
									for dat in a:
												print(_lowerCamelCase   )
									return

						# horizotal printing increasing
						for i in range(0						,  _lowerCamelCase   ):
									print(a[0][i]   )
						# vertical printing down
						for i in range(1						,  _lowerCamelCase   ):
									print(a[i][mat_col - 1]   )
						# horizotal printing decreasing
						if mat_row > 1:
									for i in range(mat_col - 2						,  -1						,  -1   ):
												print(a[mat_row - 1][i]   )
        # vertical printing up
						for i in range(mat_row - 2						,  0						,  -1   ):
									print(a[i][0]   )
						__snake_case				:			Union[str, Any]       			=    [row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
						if len(_lowerCamelCase   ) > 0:
									spiral_print_clockwise(_lowerCamelCase   )
						else:
									return
			else:
						print("""Not a valid matrix"""   )
						return







def 				_a	(					_lowerCamelCase   )   ->							list[int]:



			"""simple docstring"""


			if matrix:
						return list(matrix.pop(0   )   ) + spiral_traversal(list(zip(*_lowerCamelCase   )   )[::-1]   )
			else:
						return []


# driver code
if __name__ == "__main__":
	import doctest

	doctest.testmod()

	__UpperCamelCase										=  [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
	spiral_print_clockwise(a)


