"""simple docstring"""



from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch



@require_torch
@require_tf
class      _A	(						_UpperCAmelCase					):




    """simple docstring"""




    def  lowercase					(		self							:     int    )    ->       int:
         __snake_case				=							SMALL_MODEL_IDENTIFIER
         __snake_case				=							'''pt'''
         __snake_case				=							'''tf'''
    def  lowercase					(		self							:     Any	,      A_							:     List[Any]    )    ->       Optional[int]:
         __snake_case				=							AutoModel.from_pretrained(self.test_model    )
         model_pt.save_pretrained(A_    )
    def  lowercase					(		self							:     Optional[Any]	,      A_							:     Dict    )    ->       Dict:
         __snake_case				=							TFAutoModel.from_pretrained(self.test_model	,      from_pt=A_    )
         model_tf.save_pretrained(A_    )
    def  lowercase					(		self							:     Dict    )    ->       List[str]:
         __snake_case				=							'''mock_framework'''

         # Framework provided - return whatever the user provides
         __snake_case				=							FeaturesManager.determine_framework(self.test_model	,      A_    )
         self.assertEqual(A_	,      A_    )

         # Local checkpoint and framework provided - return provided framework
         # PyTorch checkpoint
         with TemporaryDirectory() as local_pt_ckpt:
              self._setup_pt_ckpt(A_    )
              __snake_case				=							FeaturesManager.determine_framework(A_	,      A_    )
              self.assertEqual(A_	,      A_    )

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
              self._setup_tf_ckpt(A_    )
              __snake_case				=							FeaturesManager.determine_framework(A_	,      A_    )
              self.assertEqual(A_	,      A_    )
    def  lowercase					(		self							:     int    )    ->       Dict:
         # PyTorch checkpoint
         with TemporaryDirectory() as local_pt_ckpt:
              self._setup_pt_ckpt(A_    )
              __snake_case				=							FeaturesManager.determine_framework(A_    )
              self.assertEqual(A_	,      self.framework_pt    )

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
              self._setup_tf_ckpt(A_    )
              __snake_case				=							FeaturesManager.determine_framework(A_    )
              self.assertEqual(A_	,      self.framework_tf    )

         # Invalid local checkpoint
         with TemporaryDirectory() as local_invalid_ckpt:
              with self.assertRaises(A_    ):
                   __snake_case				=							FeaturesManager.determine_framework(A_    )







    def  lowercase					(		self							:     Optional[int]    )    ->       List[Any]:
         __snake_case				=							MagicMock(return_value=A_    )
         with patch('''transformers.onnx.features.is_tf_available'''	,      A_    ):
              __snake_case				=							FeaturesManager.determine_framework(self.test_model    )
              self.assertEqual(A_	,      self.framework_pt    )

         # PyTorch not in environment -> use TensorFlow
         __snake_case				=							MagicMock(return_value=A_    )
         with patch('''transformers.onnx.features.is_torch_available'''	,      A_    ):
              __snake_case				=							FeaturesManager.determine_framework(self.test_model    )
              self.assertEqual(A_	,      self.framework_tf    )

         # Both in environment -> use PyTorch
         __snake_case				=							MagicMock(return_value=A_    )
         __snake_case				=							MagicMock(return_value=A_    )
         with patch('''transformers.onnx.features.is_tf_available'''	,      A_    ), patch(
             '''transformers.onnx.features.is_torch_available'''	,      A_    ):
              __snake_case				=							FeaturesManager.determine_framework(self.test_model    )
              self.assertEqual(A_	,      self.framework_pt    )

         # Both not in environment -> raise error
         __snake_case				=							MagicMock(return_value=A_    )
         __snake_case				=							MagicMock(return_value=A_    )
         with patch('''transformers.onnx.features.is_tf_available'''	,      A_    ), patch(
             '''transformers.onnx.features.is_torch_available'''	,      A_    ):
              with self.assertRaises(A_    ):
                   __snake_case				=							FeaturesManager.determine_framework(self.test_model    )
"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


__lowercase		:		Dict														=							{
    "configuration_vision_text_dual_encoder": ["VisionTextDualEncoderConfig"],
    "processing_vision_text_dual_encoder": ["VisionTextDualEncoderProcessor"],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase		:		Optional[int]														=							["VisionTextDualEncoderModel"]


try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase		:		Optional[int]														=							["FlaxVisionTextDualEncoderModel"]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowercase		:		Any														=							["TFVisionTextDualEncoderModel"]


if TYPE_CHECKING:
       from .configuration_vision_text_dual_encoder import VisionTextDualEncoderConfig
       from .processing_vision_text_dual_encoder import VisionTextDualEncoderProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_vision_text_dual_encoder import VisionTextDualEncoderModel

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_flax_vision_text_dual_encoder import FlaxVisionTextDualEncoderModel

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_vision_text_dual_encoder import TFVisionTextDualEncoderModel


else:
       import sys

       __lowercase		:		Tuple														=							_LazyModule(__name__, globals()["__file__"], _import_structure)