
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 	_lowerCAmelCase					(	__a       ):




				def      __a						(					self     )				->      Any:
							lowerCAmelCase_						=	SMALL_MODEL_IDENTIFIER
							lowerCAmelCase_						=	"pt"
							lowerCAmelCase_						=	"tf"




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




				def      __a						(					self				,				_UpperCamelCase     )				->      Dict:
							lowerCAmelCase_						=	TFAutoModel.from_pretrained(self.test_model				,				from_pt=_UpperCamelCase     )
							model_tf.save_pretrained(_UpperCamelCase     )




				def      __a						(					self     )				->      List[str]:
							lowerCAmelCase_						=	"mock_framework"

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

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

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




				def      __a						(					self     )				->      Union[str, Any]:
							# PyTorch checkpoint
							with TemporaryDirectory() as local_pt_ckpt:
										self._setup_pt_ckpt(_UpperCamelCase     )
										lowerCAmelCase_						=	FeaturesManager.determine_framework(_UpperCamelCase     )
										self.assertEqual(_UpperCamelCase				,				self.framework_pt     )

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

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




				def      __a						(					self     )				->      List[str]:
							lowerCAmelCase_						=	MagicMock(return_value=_UpperCamelCase     )
							with patch("transformers.onnx.features.is_tf_available"				,				_UpperCamelCase     ):
										lowerCAmelCase_						=	FeaturesManager.determine_framework(self.test_model     )
										self.assertEqual(_UpperCamelCase				,				self.framework_pt     )

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

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

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





import math






def    lowerCamelCase__				(				__lowerCAmelCase  :  int				):




			"""simple docstring"""


			lowerCAmelCase_						=	0
			lowerCAmelCase_						=	0
			while num > 0:
						lowerCAmelCase_						=	num % 8
						lowerCAmelCase_						=	octal + (remainder * math.floor(math.pow(10    ,							__lowerCAmelCase				)				))
						counter += 1
						lowerCAmelCase_						=	math.floor(num / 8				)  # basically /= 8 without remainder if any
						# This formatting removes trailing '.0' from `octal`.
			return F"""0o{int(__lowerCAmelCase				)}"""






def    lowerCamelCase__				(				):




			"""simple docstring"""


			print("\n2 in octal is:"				)
			print(decimal_to_octal(2				)				)  # = 2
			print("\n8 in octal is:"				)
			print(decimal_to_octal(8				)				)  # = 10
			print("\n65 in octal is:"				)
			print(decimal_to_octal(65				)				)  # = 101
			print("\n216 in octal is:"				)
			print(decimal_to_octal(216				)				)  # = 330
			print("\n512 in octal is:"				)
			print(decimal_to_octal(512				)				)  # = 1000
			print("\n"				)


if __name__ == "__main__":
			main()



