






'''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						):




 @slow
 @unittest.skip("Model is not available."						)
 def 							_snake_case				(		self						)      ->							Optional[Any]:
     _lowerCAmelCase		     = "nvidia/megatron-gpt2-345m/"
     if "MYDIR" in os.environ:
         _lowerCAmelCase		     = os.path.join(os.environ["MYDIR"]     ,       _lowerCAmelCase						)
     _lowerCAmelCase		     = GPTaLMHeadModel.from_pretrained(_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.half()

     _lowerCAmelCase		     = torch.tensor(
         [[101, 7110, 1005, 1056, 2023, 11333, 17413, 1029, 102]]     ,       device=_lowerCAmelCase     ,       dtype=torch.long     ,       )

     with torch.no_grad():
         _lowerCAmelCase		     = model(_lowerCAmelCase						).logits

     _lowerCAmelCase		     = torch.Size((1, 9, 50257)						)
     self.assertEqual(output.shape     ,       _lowerCAmelCase						)

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

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









'''simple docstring'''


def 		__a(SCREAMING_SNAKE_CASE_					:   List[Any]						,    SCREAMING_SNAKE_CASE_					:   str      ):



    '''simple docstring'''





    if n < 0:
        return 0
    # table[i] represents the number of ways to get to amount i
    _lowerCAmelCase		     = [0] * (n + 1)

    # There is exactly 1 way to get to zero(You pick no coins).
    _lowerCAmelCase		     = 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()


