


from math import loga







def     _lowercase							(  __lowerCamelCase      :       int      )	-> List[str]:





     '''simple docstring'''





     if a < 0:
          raise ValueError('''Input value must be a positive integer'''      )
     elif isinstance(UpperCamelCase__		,UpperCamelCase__      ):
          raise TypeError('''Input value must be a \'int\' type'''      )
     return 0 if (a == 0) else int(loga(a & -a      )      )


if __name__ == "__main__":
   import doctest

   doctest.testmod()





'''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 ):





							def    snake_case__    (   self					:				str						)				->						Any:
								__UpperCAmelCase      					=      SMALL_MODEL_IDENTIFIER
								__UpperCAmelCase      					=      '''pt'''
								__UpperCAmelCase      					=      '''tf'''





							def    snake_case__    (   self					:				int  ,		__a					:				int						)				->						Union[str, Any]:
								__UpperCAmelCase      					=      AutoModel.from_pretrained(self.test_model						)
								model_pt.save_pretrained(__a						)





							def    snake_case__    (   self					:				Any  ,		__a					:				Optional[int]						)				->						Tuple:
								__UpperCAmelCase      					=      TFAutoModel.from_pretrained(self.test_model  ,		from_pt=__a						)
								model_tf.save_pretrained(__a						)





							def    snake_case__    (   self					:				Dict						)				->						Dict:
								__UpperCAmelCase      					=      '''mock_framework'''

								# Framework provided - return whatever the user provides
								__UpperCAmelCase      					=      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						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a  ,		__a						)
									self.assertEqual(__a  ,		__a						)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
									self._setup_tf_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a  ,		__a						)
									self.assertEqual(__a  ,		__a						)





							def    snake_case__    (   self					:				Dict						)				->						List[str]:
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
									self._setup_pt_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a						)
									self.assertEqual(__a  ,		self.framework_pt						)

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

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






							def    snake_case__    (   self					:				str						)				->						Union[str, Any]:
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								with patch('''transformers.onnx.features.is_tf_available'''  ,		__a						):
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
									self.assertEqual(__a  ,		self.framework_pt						)

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

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

								# Both not in environment -> raise error
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								__UpperCAmelCase      					=      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						):
										__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
