





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




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

							UpperCamelCase__								=						torch.tensor(
							    [[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]     ,   device=__lowerCAmelCase     ,   dtype=torch.long     ,   )

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

							UpperCamelCase__								=						torch.Size((1, 9, 50_257)							)
							self.assertEqual(output.shape     ,   __lowerCAmelCase							)

							UpperCamelCase__								=						torch.tensor(
							    [
							        4.9_4_1_4,
							        -0.2_9_2_0,
							        -1.2_1_4_8,
							        -4.0_2_7_3,
							        -0.5_1_6_1,
							        -5.2_1_0_9,
							        -1.2_4_1_2,
							        -1.8_3_0_1,
							        -1.7_7_3_4,
							        -4.7_1_4_8,
							        -0.2_3_1_7,
							        -1.0_8_1_1,
							        -2.1_7_7_7,
							        0.4_1_4_1,
							        -3.7_9_6_9,
							        -4.0_5_8_6,
							        -2.5_3_3_2,
							        -3.3_8_0_9,
							        4.3_8_6_7,
							    ]     ,   device=__lowerCAmelCase     ,   dtype=torch.half     ,   )

							for i in range(19							):
									UpperCamelCase__	,      UpperCamelCase__								=						8 * i // 17, 2_792 * 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(__lowerCAmelCase     ,   __lowerCAmelCase     ,   delta=1E-4     ,   msg=__lowerCAmelCase							)












from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase 	=      {"configuration_visual_bert": ["VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "VisualBertConfig"]}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowerCAmelCase 	=      [
				    "VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "VisualBertForMultipleChoice",
				    "VisualBertForPreTraining",
				    "VisualBertForQuestionAnswering",
				    "VisualBertForRegionToPhraseAlignment",
				    "VisualBertForVisualReasoning",
				    "VisualBertLayer",
				    "VisualBertModel",
				    "VisualBertPreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_visual_bert import (
								    VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
								    VisualBertForMultipleChoice,
								    VisualBertForPreTraining,
								    VisualBertForQuestionAnswering,
								    VisualBertForRegionToPhraseAlignment,
								    VisualBertForVisualReasoning,
								    VisualBertLayer,
								    VisualBertModel,
								    VisualBertPreTrainedModel,
								)


else:
				import sys

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





