





'''simple docstring'''




from manim import *


class 			SCREAMING_SNAKE_CASE   (A__							):


					def 							SCREAMING_SNAKE_CASE  (						self):

										'''simple docstring'''






										__A						:			Union[str, Any]								=	Rectangle(height=0.5						,     width=0.5)
										__A						:			Optional[Any]								=	Rectangle(height=0.46						,     width=0.46).set_stroke(width=0)

										__A						:			str								=	[mem.copy() for i in range(6)]
										__A						:			str								=	[mem.copy() for i in range(6)]
										__A						:			int								=	VGroup(*lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0)
										__A						:			Optional[Any]								=	VGroup(*lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0)
										__A						:			Union[str, Any]								=	VGroup(lowerCamelCase__						,     lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0)
										__A						:			Tuple								=	Text('CPU'						,     font_size=24)
										__A						:			Tuple								=	Group(lowerCamelCase__						,     lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0.5						,     aligned_edge=lowerCamelCase__)
										cpu.move_to([-2.5, -0.5, 0])
										self.add(lowerCamelCase__)

										__A						:			Optional[Any]								=	[mem.copy() for i in range(1)]
										__A						:			Optional[Any]								=	VGroup(*lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0)
										__A						:			Tuple								=	Text('GPU'						,     font_size=24)
										__A						:			Dict								=	Group(lowerCamelCase__						,     lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0.5						,     aligned_edge=lowerCamelCase__)
										gpu.align_to(lowerCamelCase__						,     lowerCamelCase__)
										gpu.set_x(gpu.get_x() - 1)

										self.add(lowerCamelCase__)

										__A						:			Tuple								=	[mem.copy() for i in range(6)]
										__A						:			List[str]								=	VGroup(*lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0)

										__A						:			List[Any]								=	Text('Model'						,     font_size=24)
										__A						:			List[Any]								=	Group(lowerCamelCase__						,     lowerCamelCase__).arrange(lowerCamelCase__						,     buff=0.5						,     aligned_edge=lowerCamelCase__)
										model.move_to([3, -1.0, 0])

										self.play(
										    Create(lowerCamelCase__						,     run_time=1)						,     Create(lowerCamelCase__						,     run_time=1)						,     Create(lowerCamelCase__						,     run_time=1)						,     )

										__A						:			str								=	MarkupText(
										    F'First, an empty model skeleton is loaded\ninto <span fgcolor=\'{YELLOW}\'>memory</span> without using much RAM.'						,     font_size=24						,     )

										__A						:			Any								=	Square(side_length=2.2)
										key.move_to([-5, 2, 0])

										__A						:			List[Any]								=	MarkupText(
										    F'<b>Key:</b>\n\n<span fgcolor=\'{YELLOW}\'>●</span> Empty Model'						,     font_size=18						,     )

										key_text.move_to([-5, 2.4, 0])

										step_a.move_to([2, 2, 0])
										self.play(Write(lowerCamelCase__						,     run_time=2.5)						,     Write(lowerCamelCase__)						,     Write(lowerCamelCase__))

										self.add(lowerCamelCase__)

										__A						:			List[Any]								=	[]
										__A						:			int								=	[]
										__A						:			Dict								=	[]
										for i, rect in enumerate(lowerCamelCase__):
															__A						:			List[str]								=	Rectangle(height=0.46						,     width=0.46).set_stroke(width=0.0).set_fill(lowerCamelCase__						,     opacity=0.7)
															cpu_target.move_to(lowerCamelCase__)
															cpu_target.generate_target()
															__A						:			int								=	0.46 / 4
															__A						:			Any								=	0.46 / 3

															if i == 0:
																				cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT)						,     buff=0.02						,     direction=lowerCamelCase__)
																				cpu_target.target.set_x(cpu_target.target.get_x() + 0.1)
															elif i == 3:
																				cpu_target.target.next_to(cpu_targs[0].target						,     direction=lowerCamelCase__						,     buff=0.0)
															else:
																				cpu_target.target.next_to(cpu_targs[i - 1].target						,     direction=lowerCamelCase__						,     buff=0.0)
															cpu_targs.append(lowerCamelCase__)

															first_animations.append(rect.animate(run_time=0.5).set_stroke(lowerCamelCase__))
															second_animations.append(MoveToTarget(lowerCamelCase__						,     run_time=1.5))

										self.play(*lowerCamelCase__)
										self.play(*lowerCamelCase__)

										self.wait()






'''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 			SCREAMING_SNAKE_CASE   (a__							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			Optional[int]								=	SMALL_MODEL_IDENTIFIER
          __A						:			Any								=	'pt'
          __A						:			str								=	'tf'


     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase):

          '''simple docstring'''






          __A						:			Any								=	AutoModel.from_pretrained(self.test_model)
          model_pt.save_pretrained(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self						,     _UpperCAmelCase):

          '''simple docstring'''






          __A						:			Union[str, Any]								=	TFAutoModel.from_pretrained(self.test_model						,     from_pt=_UpperCAmelCase)
          model_tf.save_pretrained(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						:			Union[str, Any]								=	'mock_framework'

          # Framework provided - return whatever the user provides
          __A						:			Union[str, Any]								=	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)
               __A						:			List[str]								=	FeaturesManager.determine_framework(_UpperCAmelCase						,     _UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     _UpperCAmelCase)

          # TensorFlow checkpoint
          with TemporaryDirectory() as local_tf_ckpt:
               self._setup_tf_ckpt(_UpperCAmelCase)
               __A						:			Tuple								=	FeaturesManager.determine_framework(_UpperCAmelCase						,     _UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     _UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          with TemporaryDirectory() as local_pt_ckpt:
               self._setup_pt_ckpt(_UpperCAmelCase)
               __A						:			Optional[int]								=	FeaturesManager.determine_framework(_UpperCAmelCase)
               self.assertEqual(_UpperCAmelCase						,     self.framework_pt)

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

          # Invalid local checkpoint
          with TemporaryDirectory() as local_invalid_ckpt:
               with self.assertRaises(_UpperCAmelCase):
                    __A						:			Tuple								=	FeaturesManager.determine_framework(_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






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

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

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

          # Both not in environment -> raise error
          __A						:			List[str]								=	MagicMock(return_value=_UpperCAmelCase)
          __A						:			Tuple								=	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):
                    __A						:			int								=	FeaturesManager.determine_framework(self.test_model)