


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


    @slow
    @unittest.skip("Model is not available."   )
    def        __a							(					self   ):
          UpperCamelCase__  =    "nvidia/megatron-gpt2-345m/"
          if "MYDIR" in os.environ:
                UpperCamelCase__  =    os.path.join(os.environ["MYDIR"]  , a   )
          UpperCamelCase__  =    GPTaLMHeadModel.from_pretrained(a   )
          model.to(a   )
          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=a  , dtype=torch.long  , )

          with torch.no_grad():
                UpperCamelCase__  =    model(a   ).logits

          UpperCamelCase__  =    torch.Size((1, 9, 5_02_57)   )
          self.assertEqual(output.shape  , a   )

          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=a  , 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(a  , a  , delta=1e-4  , msg=a   )










'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


a__  : Any				=	{
    'configuration_codegen': ['CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CodeGenConfig', 'CodeGenOnnxConfig'],
    'tokenization_codegen': ['CodeGenTokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a__  : Tuple				=	['CodeGenTokenizerFast']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a__  : Dict				=	[
      'CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST',
      'CodeGenForCausalLM',
      'CodeGenModel',
      'CodeGenPreTrainedModel',
  ]

if TYPE_CHECKING:
  from .configuration_codegen import CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP, CodeGenConfig, CodeGenOnnxConfig
  from .tokenization_codegen import CodeGenTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_codegen_fast import CodeGenTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_codegen import (
        CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
        CodeGenForCausalLM,
        CodeGenModel,
        CodeGenPreTrainedModel,
    )

else:
  import sys

  a__  : Optional[int]				=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





