



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




      """simple docstring"""




      @slow
      @unittest.skip('Model is not available.'			)
      def 	SCREAMING_SNAKE_CASE__					( self							: Dict			):
        lowerCAmelCase_  :							Dict								=					'nvidia/megatron-gpt2-345m/'
        if "MYDIR" in os.environ:
          lowerCAmelCase_  :							Union[str, Any]								=					os.path.join(os.environ['MYDIR']       ,     SCREAMING_SNAKE_CASE_			)
        lowerCAmelCase_  :							int								=					GPTaLMHeadModel.from_pretrained(SCREAMING_SNAKE_CASE_			)
        model.to(SCREAMING_SNAKE_CASE_			)
        model.half()

        lowerCAmelCase_  :							Dict								=					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=SCREAMING_SNAKE_CASE_       ,     dtype=torch.long       ,     )

        with torch.no_grad():
          lowerCAmelCase_  :							Tuple								=					model(SCREAMING_SNAKE_CASE_			).logits

        lowerCAmelCase_  :							List[Any]								=					torch.Size((1, 9, 5_0_2_5_7)			)
        self.assertEqual(output.shape       ,     SCREAMING_SNAKE_CASE_			)

        lowerCAmelCase_  :							Tuple								=					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=SCREAMING_SNAKE_CASE_       ,     dtype=torch.half       ,     )

        for i in range(1_9			):
          lowerCAmelCase_		,lowerCAmelCase_  :							List[str]								=					8 * i // 1_7, 2_7_9_2 * i  # along the diagonal
          lowerCAmelCase_		,lowerCAmelCase_  :							Optional[int]								=					output[0, r, c], expected_diag[i]
          lowerCAmelCase_  :							List[Any]								=					F"row={r} col={c} computed={computed} expected={expected}"
          self.assertAlmostEqual(SCREAMING_SNAKE_CASE_       ,     SCREAMING_SNAKE_CASE_       ,     delta=1E-4       ,     msg=SCREAMING_SNAKE_CASE_			)










"""simple docstring"""







import unittest
from timeit import timeit

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  lowerCAmelCase_  :							Any								=					first_num if first_num >= second_num else second_num
  lowerCAmelCase_  :							Union[str, Any]								=					max_num
  while (common_mult % first_num > 0) or (common_mult % second_num > 0):
    common_mult += max_num
  return common_mult

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  return b if a == 0 else greatest_common_divisor(b % a       ,  lowerCAmelCase__		)

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  return first_num // greatest_common_divisor(lowerCAmelCase__       ,  lowerCAmelCase__		) * second_num

def 							UpperCamelCase_       (       )		->  Dict:

  """simple docstring"""




  lowerCAmelCase_  :							str								=					(
      'from __main__ import least_common_multiple_slow, least_common_multiple_fast'
  )
  print(
      'least_common_multiple_slow():'       ,  timeit('least_common_multiple_slow(1000, 999)'       ,  setup=lowerCAmelCase__		)       ,  )
  print(
      'least_common_multiple_fast():'       ,  timeit('least_common_multiple_fast(1000, 999)'       ,  setup=lowerCAmelCase__		)       ,  )







class  UpperCamelCase__  (      unittest.TestCase    ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE    							=	(
          (10, 20),
          (13, 15),
          (4, 31),
          (10, 42),
          (43, 34),
          (5, 12),
          (12, 25),
          (10, 25),
          (6, 9),
      )
      _SCREAMING_SNAKE_CASE    							=	(20, 195, 124, 210, 1462, 60, 300, 50, 18)



      def 	SCREAMING_SNAKE_CASE__					( self							: List[str]			):
        for i, (first_num, second_num) in enumerate(self.test_inputs			):
          lowerCAmelCase_  :							Union[str, Any]								=					least_common_multiple_slow(SCREAMING_SNAKE_CASE_       ,     SCREAMING_SNAKE_CASE_			)
          lowerCAmelCase_  :							Any								=					least_common_multiple_fast(SCREAMING_SNAKE_CASE_       ,     SCREAMING_SNAKE_CASE_			)
          with self.subTest(i=SCREAMING_SNAKE_CASE_			):
            self.assertEqual(SCREAMING_SNAKE_CASE_       ,     self.expected_results[i]			)
            self.assertEqual(SCREAMING_SNAKE_CASE_       ,     self.expected_results[i]			)


if __name__ == "__main__":
     benchmark()
     unittest.main()





