



'''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 							__lowercase    (							self      : Any	):
									_a  :   Optional[int]				 =							"nvidia/megatron-gpt2-345m/"
									if "MYDIR" in os.environ:
											_a  :   Optional[Any]				 =							os.path.join(os.environ['MYDIR']			,lowerCAmelCase__	)
									_a  :   Tuple				 =							GPTaLMHeadModel.from_pretrained(lowerCAmelCase__	)
									model.to(lowerCAmelCase__	)
									model.half()

									_a  :   Optional[int]				 =							torch.tensor(
									    [[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]			,device=lowerCAmelCase__			,dtype=torch.long			,)

									with torch.no_grad():
											_a  :   Optional[int]				 =							model(lowerCAmelCase__	).logits

									_a  :   Optional[Any]				 =							torch.Size((1, 9, 50257)	)
									self.assertEqual(output.shape			,lowerCAmelCase__	)

									_a  :   Any				 =							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=lowerCAmelCase__			,dtype=torch.half			,)

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









'''simple docstring'''

from __future__ import annotations

class 			__magic_name__		:







							def __init__(							self      : List[Any]			,_UpperCAmelCase      : int	):
									_a  :   Tuple				 =							value
									_a  :   Node | None				 =							None
									_a  :   Node | None				 =							None

class 			__magic_name__		:
							lowerCAmelCase :					int







							def __init__(							self      : Union[str, Any]	):
									_a  :   Tuple				 =							0







							def 							__lowercase    (							self      : Tuple			,_UpperCAmelCase      : Node | None			,_UpperCAmelCase      : int	):
									if node is None:
											return

									if path_sum == self.target:
											self.paths += 1

									if node.left:
											self.depth_first_search(node.left			,path_sum + node.left.value	)
									if node.right:
											self.depth_first_search(node.right			,path_sum + node.right.value	)







							def 							__lowercase    (							self      : Union[str, Any]			,_UpperCAmelCase      : Node | None			,_UpperCAmelCase      : int | None = None	):
									if node is None:
											return 0
									if target is not None:
											_a  :   Any				 =							target

									self.depth_first_search(_UpperCAmelCase			,node.value	)
									self.path_sum(node.left	)
									self.path_sum(node.right	)

									return self.paths


if __name__ == "__main__":
							import doctest

							doctest.testmod()




