
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 						UpperCamelCase__							(				self				):
       lowerCamelCase		:     List[str]          =				"""nvidia/megatron-gpt2-345m/"""
       if "MYDIR" in os.environ:
        lowerCamelCase		:     List[Any]          =				os.path.join(os.environ["""MYDIR"""]   ,  __magic_name__				)
       lowerCamelCase		:     Union[str, Any]          =				GPTaLMHeadModel.from_pretrained(__magic_name__				)
       model.to(__magic_name__				)
       model.half()

       lowerCamelCase		:     List[Any]          =				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=__magic_name__   ,  dtype=torch.long   ,  )

       with torch.no_grad():
        lowerCamelCase		:     Any          =				model(__magic_name__				).logits

       lowerCamelCase		:     Any          =				torch.Size((1, 9, 5_0_2_5_7)				)
       self.assertEqual(output.shape   ,  __magic_name__				)

       lowerCamelCase		:     List[str]          =				torch.tensor(
           [
               4.9_414,
               -0.2_920,
               -1.2_148,
               -4.0_273,
               -0.5_161,
               -5.2_109,
               -1.2_412,
               -1.8_301,
               -1.7_734,
               -4.7_148,
               -0.2_317,
               -1.0_811,
               -2.1_777,
               0.4_141,
               -3.7_969,
               -4.0_586,
               -2.5_332,
               -3.3_809,
               4.3_867,
           ]   ,  device=__magic_name__   ,  dtype=torch.half   ,  )

       for i in range(1_9				):
        lowerCamelCase      ,   lowerCamelCase		:     Dict          =				8 * i // 1_7, 2_7_9_2 * i  # along the diagonal
        lowerCamelCase      ,   lowerCamelCase		:     Dict          =				output[0, r, c], expected_diag[i]
        lowerCamelCase		:     Tuple          =				F'''row={r} col={c} computed={computed} expected={expected}'''
        self.assertAlmostEqual(__magic_name__   ,  __magic_name__   ,  delta=1e-4   ,  msg=__magic_name__				)






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


_lowerCamelCase        ={
    """configuration_tvlt""": ["""TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TvltConfig"""],
    """feature_extraction_tvlt""": ["""TvltFeatureExtractor"""],
    """processing_tvlt""": ["""TvltProcessor"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _lowerCamelCase        =[
          """TVLT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """TvltModel""",
          """TvltForPreTraining""",
          """TvltForAudioVisualClassification""",
          """TvltPreTrainedModel""",
      ]

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      _lowerCamelCase        =["""TvltImageProcessor"""]


if TYPE_CHECKING:
      from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
      from .processing_tvlt import TvltProcessor
      from .feature_extraction_tvlt import TvltFeatureExtractor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tvlt import (
                TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TvltForAudioVisualClassification,
                TvltForPreTraining,
                TvltModel,
                TvltPreTrainedModel,
            )

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_tvlt import TvltImageProcessor


else:
      import sys

      _lowerCamelCase        =_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




