





"""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  _UpperCAmelCase  (   UpperCAmelCase__		):



      '''simple docstring'''

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       List[Any]										=  SMALL_MODEL_IDENTIFIER
        A_  :       Union[str, Any]										=  'pt'
        A_  :       List[Any]										=  'tf'

      def 					lowerCamelCase_			(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       int										=  AutoModel.from_pretrained(self.test_model  )
        model_pt.save_pretrained(snake_case_  )

      def 					lowerCamelCase_			(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       int										=  TFAutoModel.from_pretrained(self.test_model					,      from_pt=snake_case_  )
        model_tf.save_pretrained(snake_case_  )

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       Any										=  'mock_framework'

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

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

        # TensorFlow checkpoint
        with TemporaryDirectory() as local_tf_ckpt:
          self._setup_tf_ckpt(snake_case_  )
          A_  :       List[str]										=  FeaturesManager.determine_framework(snake_case_					,      snake_case_  )
          self.assertEqual(snake_case_					,      snake_case_  )

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        with TemporaryDirectory() as local_pt_ckpt:
          self._setup_pt_ckpt(snake_case_  )
          A_  :       Tuple										=  FeaturesManager.determine_framework(snake_case_  )
          self.assertEqual(snake_case_					,      self.framework_pt  )

        # TensorFlow checkpoint
        with TemporaryDirectory() as local_tf_ckpt:
          self._setup_tf_ckpt(snake_case_  )
          A_  :       List[Any]										=  FeaturesManager.determine_framework(snake_case_  )
          self.assertEqual(snake_case_					,      self.framework_tf  )

        # Invalid local checkpoint
        with TemporaryDirectory() as local_invalid_ckpt:
          with self.assertRaises(snake_case_  ):
            A_  :       Union[str, Any]										=  FeaturesManager.determine_framework(snake_case_  )

      def 					lowerCamelCase_			(     self  ):

        """simple docstring"""

        A_  :       List[str]										=  MagicMock(return_value=snake_case_  )
        with patch('transformers.onnx.features.is_tf_available'					,      snake_case_  ):
          A_  :       Union[str, Any]										=  FeaturesManager.determine_framework(self.test_model  )
          self.assertEqual(snake_case_					,      self.framework_pt  )

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

        # Both in environment -> use PyTorch
        A_  :       Union[str, Any]										=  MagicMock(return_value=snake_case_  )
        A_  :       List[str]										=  MagicMock(return_value=snake_case_  )
        with patch('transformers.onnx.features.is_tf_available'					,      snake_case_  ), patch(
            'transformers.onnx.features.is_torch_available'					,      snake_case_  ):
          A_  :       Any										=  FeaturesManager.determine_framework(self.test_model  )
          self.assertEqual(snake_case_					,      self.framework_pt  )

        # Both not in environment -> raise error
        A_  :       Tuple										=  MagicMock(return_value=snake_case_  )
        A_  :       Optional[Any]										=  MagicMock(return_value=snake_case_  )
        with patch('transformers.onnx.features.is_tf_available'					,      snake_case_  ), patch(
            'transformers.onnx.features.is_torch_available'					,      snake_case_  ):
          with self.assertRaises(snake_case_  ):
            A_  :       Tuple										=  FeaturesManager.determine_framework(self.test_model  )






"""simple docstring"""




def 						UpperCAmelCase__		(     _UpperCAmelCase					):






  """simple docstring"""





  A_  :       List[str]										=  hex_num.strip()
  if not hex_num:
    raise ValueError('No value was passed to the function'					)

  A_  :       Any										=  hex_num[0] == '-'
  if is_negative:
    A_  :       Optional[Any]										=  hex_num[1:]

  try:
    A_  :       Tuple										=  int(_UpperCAmelCase ,					16					)
  except ValueError:
    raise ValueError('Invalid value was passed to the function'					)

  A_  :       Union[str, Any]										=  ''
  while int_num > 0:
    A_  :       Optional[Any]										=  str(int_num % 2					) + bin_str
    int_num >>= 1

  return int(('-' + bin_str) if is_negative else bin_str					)


if __name__ == "__main__":
   import doctest

   doctest.testmod()