


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

 '''simple docstring'''

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

       snake_case_       =      torch.tensor(
           [[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]		,      device=_UpperCAmelCase		,      dtype=torch.long		,      )

       with torch.no_grad():
             snake_case_       =      model(_UpperCAmelCase					).logits

       snake_case_       =      torch.Size((1, 9, 5_02_57)					)
       self.assertEqual(output.shape		,      _UpperCAmelCase					)

       snake_case_       =      torch.tensor(
           [
               4.9_414,
               -0.2_920,
               -1.2_148,
               -4.0_273,
               -0.5_161,
               -5.2_109,
               -1.2_412,
               -1.8_301,
               -1.7_734,
               -4.7_148,
               -0.2_317,
               -1.0_811,
               -2.1_777,
               0.4_141,
               -3.7_969,
               -4.0_586,
               -2.5_332,
               -3.3_809,
               4.3_867,
           ]		,      device=_UpperCAmelCase		,      dtype=torch.half		,      )

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



def        __lowerCAmelCase    (SCREAMING_SNAKE_CASE					)->  int:




      """simple docstring"""

      if number != int(SCREAMING_SNAKE_CASE					):
            raise ValueError('''factorial() only accepts integral values'''					)
      if number < 0:
            raise ValueError('''factorial() not defined for negative values'''					)
      snake_case_       =      1
      for i in range(1					,					number + 1					):
            value *= i
      return value






def        __lowerCAmelCase    (SCREAMING_SNAKE_CASE					)->  int:




      """simple docstring"""

      if not isinstance(SCREAMING_SNAKE_CASE					,					SCREAMING_SNAKE_CASE					):
            raise ValueError('''factorial() only accepts integral values'''					)
      if n < 0:
            raise ValueError('''factorial() not defined for negative values'''					)
      return 1 if n == 0 or n == 1 else n * factorial(n - 1					)


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   UpperCAmelCase			=    int(input("""Enter a positive integer: """).strip() or 0)
   print(f'''factorial{n} is {factorial(n)}''')