



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



						"""simple docstring"""






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

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

												with torch.no_grad():
																		UpperCAmelCase    =	model(SCREAMING_SNAKE_CASE_      ).logits

												UpperCAmelCase    =	torch.Size((1, 9, 5_02_57)      )
												self.assertEqual(output.shape     ,						SCREAMING_SNAKE_CASE_      )

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

												for i in range(19      ):
																		UpperCAmelCase   ,					UpperCAmelCase    =	8 * i // 17, 27_92 * i  # along the diagonal
																		UpperCAmelCase   ,					UpperCAmelCase    =	output[0, r, c], expected_diag[i]
																		UpperCAmelCase    =	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 warnings

from .generation import FlaxGenerationMixin







class    A_    (  SCREAMING_SNAKE_CASE_       ):



						"""simple docstring"""
						# warning at import time
						warnings.warn(
						    """Importing `FlaxGenerationMixin` from `src/transformers/generation_flax_utils.py` is deprecated and will """
						    """be removed in Transformers v5. Import as `from transformers import FlaxGenerationMixin` instead."""			,     SCREAMING_SNAKE_CASE_			,     )





