





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



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

           lowerCAmelCase_					:	List[Any]						=   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():
               lowerCAmelCase_					:	str						=   model(UpperCAmelCase			).logits

           lowerCAmelCase_					:	Union[str, Any]						=   torch.Size((1, 9, 5_02_57)			)
           self.assertEqual(output.shape					,			UpperCAmelCase			)

           lowerCAmelCase_					:	Union[str, Any]						=   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=UpperCAmelCase					,			dtype=torch.half					,			)

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









import torch
import torch.nn.functional as F

from diffusers import VQDiffusionScheduler

from .test_schedulers import SchedulerCommonTest

class 		__a							(	__UpperCamelCase      ):
       __snake_case						:   Optional[Any]      =		(VQDiffusionScheduler,)



       def  A							(     self	:   Optional[int]					,			**UpperCAmelCase	:   List[Any]			):
           lowerCAmelCase_					:	Any						=   {
               """num_vec_classes""": 40_97,
               """num_train_timesteps""": 1_00,
           }

           config.update(**UpperCAmelCase			)
           return config



       def  A							(     self	:   str					,			UpperCAmelCase	:   List[Any]			):
           lowerCAmelCase_					:	Union[str, Any]						=   4
           lowerCAmelCase_					:	str						=   8
           lowerCAmelCase_					:	Optional[Any]						=   8

           lowerCAmelCase_					:	str						=   torch.randint(0					,			UpperCAmelCase					,			(batch_size, height * width)			)

           return sample



       @property
       def  A							(     self	:   Optional[int]			):
           assert False



       def  A							(     self	:   int					,			UpperCAmelCase	:   Dict			):
           def model(UpperCAmelCase	:   Union[str, Any]					,			UpperCAmelCase	:   List[str]					,			*UpperCAmelCase	:   List[Any]			):
               lowerCAmelCase_		,		lowerCAmelCase_					:	Tuple						=   sample.shape
               lowerCAmelCase_					:	int						=   torch.rand((batch_size, num_vec_classes - 1, num_latent_pixels)			)
               lowerCAmelCase_					:	str						=   F.log_softmax(logits.double()					,			dim=1			).float()
               return return_value

           return model



       def  A							(     self	:   Union[str, Any]			):
           for timesteps in [2, 5, 1_00, 10_00]:
               self.check_over_configs(num_train_timesteps=UpperCAmelCase			)



       def  A							(     self	:   str			):
           for num_vec_classes in [5, 1_00, 10_00, 40_00]:
               self.check_over_configs(num_vec_classes=UpperCAmelCase			)



       def  A							(     self	:   Optional[Any]			):
           for t in [0, 50, 99]:
               self.check_over_forward(time_step=UpperCAmelCase			)



       def  A							(     self	:   int			):
           pass


