


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



    """simple docstring"""






    @slow
    @unittest.skip('Model is not available.'       )
    def _a   (     self       )    ->			Union[str, Any]:
         __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(
             [[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]   ,  device=A_   ,  dtype=torch.long   ,  )

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

         __UpperCamelCase       				=torch.Size((1, 9, 50257)       )
         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(19       ):
              __UpperCamelCase				, __UpperCamelCase       				=8 * i // 17, 2792 * 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_       )









def 		_UpperCAmelCase							(     SCREAMING_SNAKE_CASE__     :   Union[str, Any]     ,	SCREAMING_SNAKE_CASE__     :   int							):
     if n < 0:
          return 0
     # table[i] represents the number of ways to get to amount i
     __UpperCamelCase       				=[0] * (n + 1)

     # There is exactly 1 way to get to zero(You pick no coins).
     __UpperCamelCase       				=1

     # Pick all coins one by one and update table[] values
     # after the index greater than or equal to the value of the
     # picked coin
     for coin_val in s:
          for j in range(SCREAMING_SNAKE_CASE__     ,	n + 1							):
               table[j] += table[j - coin_val]

     return table[n]


if __name__ == "__main__":
   import doctest

   doctest.testmod()





