
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 						snake_case_     ( self						:    Union[str, Any]			):
          __lowercase						:     Optional[int]		      =    '''nvidia/megatron-gpt2-345m/'''
          if "MYDIR" in os.environ:
              __lowercase						:     str		      =    os.path.join(os.environ['''MYDIR''']			,    _snake_case			)
          __lowercase						:     Optional[Any]		      =    GPTaLMHeadModel.from_pretrained(_snake_case			)
          model.to(_snake_case			)
          model.half()

          __lowercase						:     List[Any]		      =    torch.tensor(
              [[101, 7110, 1005, 1056, 2023, 1_1333, 1_7413, 1029, 102]]			,    device=_snake_case			,    dtype=torch.long			,    )

          with torch.no_grad():
              __lowercase						:     int		      =    model(_snake_case			).logits

          __lowercase						:     Any		      =    torch.Size((1, 9, 5_0257)			)
          self.assertEqual(output.shape			,    _snake_case			)

          __lowercase						:     List[str]		      =    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=_snake_case			,    dtype=torch.half			,    )

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




from __future__ import annotations

from collections import Counter


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[int]:
    __lowercase						:     Any		      =    [True] * n
    __lowercase						:     str		      =    False
    __lowercase						:     int		      =    False
    __lowercase						:     List[Any]		      =    True

    for i in range(3		,   int(n**0.5 + 1		)		,   2		):
        __lowercase						:     List[str]		      =    i * 2
        while index < n:
            __lowercase						:     List[Any]		      =    False
            __lowercase						:     Dict		      =    index + i

    __lowercase						:     Tuple		      =    [2]

    for i in range(3		,   __lowerCAmelCase		,   2		):
        if is_prime[i]:
            primes.append(__lowerCAmelCase		)

    return primes


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  list[list[int]]:
    __lowercase						:     Optional[int]		      =    str(__lowerCAmelCase		)
    __lowercase						:     List[str]		      =    []
    __lowercase						:     int		      =    ['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']

    for duplicate in Counter(__lowerCAmelCase		) - Counter(set(__lowerCAmelCase		)		):
        __lowercase						:     Union[str, Any]		      =    [int(number_str.replace(__lowerCAmelCase		,   __lowerCAmelCase		)		) for digit in digits]
        replacements.append(__lowerCAmelCase		)

    return replacements


def       UpperCAmelCase_					(  __lowerCAmelCase = 8		)	->  int:
    __lowercase						:     Tuple		      =    set()

    # Filter primes with less than 3 replaceable digits
    __lowercase						:     int		      =    {
        x for x in set(prime_sieve(1_000_000		)		) if len(str(__lowerCAmelCase		)		) - len(set(str(__lowerCAmelCase		)		)		) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        __lowercase						:     str		      =    digit_replacements(__lowerCAmelCase		)

        for family in replacements:
            numbers_checked.update(__lowerCAmelCase		)
            __lowercase						:     List[Any]		      =    primes.intersection(__lowerCAmelCase		)

            if len(__lowerCAmelCase		) != family_length:
                continue

            return min(__lowerCAmelCase		)

    return -1


if __name__ == "__main__":
 print(solution())


