





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




 """simple docstring"""



 @slow
 @unittest.skip('Model is not available.'     )
 def 	_lowerCamelCase (	self	:							List[str]     ):
        __UpperCamelCase	=  'nvidia/megatron-gpt2-345m/'
        if "MYDIR" in os.environ:
               __UpperCamelCase	=  os.path.join(os.environ['MYDIR']							,     __A     )
        __UpperCamelCase	=  GPTaLMHeadModel.from_pretrained(__A     )
        model.to(__A     )
        model.half()

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

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

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

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

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







'''simple docstring'''
a__							:							int			='''
# Transformers installation
! pip install transformers datasets evaluate
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/transformers.git
'''

a__							:							List[Any]			=[{'''type''': '''code''', '''content''': INSTALL_CONTENT}]
a__							:							Dict			={
    '''{processor_class}''': '''FakeProcessorClass''',
    '''{model_class}''': '''FakeModelClass''',
    '''{object_class}''': '''FakeObjectClass''',
}
