

'''simple docstring'''

from manim import *






class    snake_case     (      lowercase_		):






				"""simple docstring"""



				def   a__					(    self       )     ->							str:
											SCREAMING_SNAKE_CASE_				=				Rectangle(height=0.5,     width=0.5       )
											SCREAMING_SNAKE_CASE_				=				Rectangle(height=0.25,     width=0.25       )
											SCREAMING_SNAKE_CASE_				=				Rectangle(height=0.46,     width=0.46       ).set_stroke(width=0       )

											SCREAMING_SNAKE_CASE_				=				[mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				[mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				VGroup(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				Text('CPU',     font_size=24       )
											SCREAMING_SNAKE_CASE_				=				Group(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0.5,     aligned_edge=_lowercase       )
											cpu.move_to([-2.5, -0.5, 0]       )
											self.add(_lowercase       )

											SCREAMING_SNAKE_CASE_				=				[mem.copy() for i in range(4       )]
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				Text('GPU',     font_size=24       )
											SCREAMING_SNAKE_CASE_				=				Group(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0.5,     aligned_edge=_lowercase       )
											gpu.move_to([-1, -1, 0]       )
											self.add(_lowercase       )

											SCREAMING_SNAKE_CASE_				=				[mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )

											SCREAMING_SNAKE_CASE_				=				Text('Model',     font_size=24       )
											SCREAMING_SNAKE_CASE_				=				Group(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0.5,     aligned_edge=_lowercase       )
											model.move_to([3, -1.0, 0]       )
											self.add(_lowercase       )

											SCREAMING_SNAKE_CASE_				=				[]
											SCREAMING_SNAKE_CASE_				=				[]
											SCREAMING_SNAKE_CASE_				=				[]

											for i, rect in enumerate(_lowercase       ):
																		rect.set_stroke(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				Rectangle(height=0.46 / 4,     width=0.46 / 3       ).set_stroke(width=0.0       ).set_fill(_lowercase,     opacity=0.7       )

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

											self.add(*_lowercase,     *_lowercase,     *_lowercase       )

											SCREAMING_SNAKE_CASE_				=				[mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )

											SCREAMING_SNAKE_CASE_				=				Text('Loaded Checkpoint',     font_size=24       )
											SCREAMING_SNAKE_CASE_				=				Group(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0.5,     aligned_edge=_lowercase       )
											checkpoint.move_to([3, 0.5, 0]       )

											self.add(_lowercase       )

											SCREAMING_SNAKE_CASE_				=				[]
											SCREAMING_SNAKE_CASE_				=				[]

											for i, rect in enumerate(_lowercase       ):
																		SCREAMING_SNAKE_CASE_				=				fill.copy().set_fill(_lowercase,     opacity=0.7       )
																		target.move_to(_lowercase       )
																		ckpt_arr.append(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				target.copy()
																		if i < 5:
																									cpu_target.move_to(cpu_left_col_base[i + 1]       )
																		else:
																									cpu_target.move_to(cpu_right_col_base[i - 5]       )
																		ckpt_cpu_arr.append(_lowercase       )
											self.add(*_lowercase,     *_lowercase       )

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

											SCREAMING_SNAKE_CASE_				=				MarkupText(
											    f"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model""",     font_size=18,     )

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

											self.add(_lowercase,     _lowercase       )

											SCREAMING_SNAKE_CASE_				=				MarkupText(
											    f"""<span fgcolor='{BLUE}'>●</span> Checkpoint""",     font_size=18,     )

											blue_text.next_to(_lowercase,     DOWN * 2.4,     aligned_edge=key_text.get_left()       )
											self.add(_lowercase       )

											SCREAMING_SNAKE_CASE_				=				MarkupText(
											    f"""Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device.""",     font_size=24,     )
											step_a.move_to([2, 2, 0]       )

											SCREAMING_SNAKE_CASE_				=				[meta_mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				[meta_mem.copy() for i in range(6       )]
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				VGroup(*_lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				VGroup(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0       )
											SCREAMING_SNAKE_CASE_				=				Text('Disk',     font_size=24       )
											SCREAMING_SNAKE_CASE_				=				Group(_lowercase,     _lowercase       ).arrange(_lowercase,     buff=0.5,     aligned_edge=_lowercase       )
											disk.move_to([-4.0, -1.25, 0]       )
											self.play(Write(_lowercase,     run_time=3       ),     Write(_lowercase,     run_time=1       ),     Create(_lowercase,     run_time=1       )       )

											SCREAMING_SNAKE_CASE_				=				[]
											for i, rect in enumerate(_lowercase       ):
																		SCREAMING_SNAKE_CASE_				=				rect.copy()
																		target.generate_target()
																		target.target.move_to(disk_left_col_base[i]       ).scale(0.5       )
																		animations.append(MoveToTarget(_lowercase,     run_time=1.5       )       )
											self.play(*_lowercase       )

											self.play(FadeOut(_lowercase       )       )

											SCREAMING_SNAKE_CASE_				=				MarkupText(f"""Then, the checkpoint is removed from memory\nthrough garbage collection.""",     font_size=24       )
											step_a.move_to([2, 2, 0]       )

											self.play(Write(_lowercase,     run_time=3       )       )

											self.play(
											    FadeOut(_lowercase,     _lowercase,     *_lowercase,     *_lowercase       ),     )

											self.wait()








'''simple docstring'''

import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


SCREAMING_SNAKE_CASE							:				int     	=			get_tests_dir("fixtures")
SCREAMING_SNAKE_CASE							:				str     	=			get_tests_dir("fixtures/dummy_feature_extractor_config.json")
SCREAMING_SNAKE_CASE							:				str     	=			get_tests_dir("fixtures/dummy-config.json")






class    snake_case     (      unittest.TestCase		):






				"""simple docstring"""



				def   a__					(    self       )     ->							str:
											SCREAMING_SNAKE_CASE_				=				0



				def   a__					(    self       )     ->							Tuple:
											SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained('facebook/wav2vec2-base-960h'       )
											self.assertIsInstance(_lowercase,     _lowercase       )



				def   a__					(    self       )     ->							List[str]:
											SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase       )
											self.assertIsInstance(_lowercase,     _lowercase       )



				def   a__					(    self       )     ->							str:
											with tempfile.TemporaryDirectory() as tmpdirname:
																		SCREAMING_SNAKE_CASE_				=				WavaVecaConfig()

																		# remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase       ).to_dict()

																		config_dict.pop('feature_extractor_type'       )
																		SCREAMING_SNAKE_CASE_				=				WavaVecaFeatureExtractor(**_lowercase       )

																		# save in new folder
																		model_config.save_pretrained(_lowercase       )
																		config.save_pretrained(_lowercase       )

																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase       )

																		# make sure private variable is not incorrectly saved
																		SCREAMING_SNAKE_CASE_				=				json.loads(config.to_json_string()       )
																		self.assertTrue('_processor_class' not in dict_as_saved       )

											self.assertIsInstance(_lowercase,     _lowercase       )



				def   a__					(    self       )     ->							int:
											SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase       )
											self.assertIsInstance(_lowercase,     _lowercase       )



				def   a__					(    self       )     ->							Any:
											with self.assertRaisesRegex(
											    _lowercase,     'bert-base is not a local folder and is not a valid model identifier'       ):
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained('bert-base'       )



				def   a__					(    self       )     ->							List[Any]:
											with self.assertRaisesRegex(
											    _lowercase,     R'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'       ):
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase,     revision='aaaaaa'       )



				def   a__					(    self       )     ->							List[Any]:
											with self.assertRaisesRegex(
											    _lowercase,     'hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.',     ):
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained('hf-internal-testing/config-no-model'       )



				def   a__					(    self       )     ->							List[str]:
											# If remote code is not set, we will time out when asking whether to load the model.
											with self.assertRaises(_lowercase       ):
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
																		    'hf-internal-testing/test_dynamic_feature_extractor'       )
											# If remote code is disabled, we can't load this config.
											with self.assertRaises(_lowercase       ):
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
																		    'hf-internal-testing/test_dynamic_feature_extractor',     trust_remote_code=_lowercase       )

											SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
											    'hf-internal-testing/test_dynamic_feature_extractor',     trust_remote_code=_lowercase       )
											self.assertEqual(feature_extractor.__class__.__name__,     'NewFeatureExtractor'       )

											# Test feature extractor can be reloaded.
											with tempfile.TemporaryDirectory() as tmp_dir:
																		feature_extractor.save_pretrained(_lowercase       )
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase,     trust_remote_code=_lowercase       )
											self.assertEqual(reloaded_feature_extractor.__class__.__name__,     'NewFeatureExtractor'       )



				def   a__					(    self       )     ->							int:
											try:
																		AutoConfig.register('custom',     _lowercase       )
																		AutoFeatureExtractor.register(_lowercase,     _lowercase       )
																		# Trying to register something existing in the Transformers library will raise an error
																		with self.assertRaises(_lowercase       ):
																									AutoFeatureExtractor.register(_lowercase,     _lowercase       )

																		# Now that the config is registered, it can be used as any other config with the auto-API
																		SCREAMING_SNAKE_CASE_				=				CustomFeatureExtractor.from_pretrained(_lowercase       )
																		with tempfile.TemporaryDirectory() as tmp_dir:
																									feature_extractor.save_pretrained(_lowercase       )
																									SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(_lowercase       )
																									self.assertIsInstance(_lowercase,     _lowercase       )

											finally:
																		if "custom" in CONFIG_MAPPING._extra_content:
																									del CONFIG_MAPPING._extra_content["custom"]
																		if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
																									del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]





				def   a__					(    self       )     ->							str:






											class    snake_case     (      lowercase_		):






															"""simple docstring"""
															_a    	=     True

											try:
																		AutoConfig.register('custom',     _lowercase       )
																		AutoFeatureExtractor.register(_lowercase,     _lowercase       )
																		# If remote code is not set, the default is to use local
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
																		    'hf-internal-testing/test_dynamic_feature_extractor'       )
																		self.assertEqual(feature_extractor.__class__.__name__,     'NewFeatureExtractor'       )
																		self.assertTrue(feature_extractor.is_local       )

																		# If remote code is disabled, we load the local one.
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
																		    'hf-internal-testing/test_dynamic_feature_extractor',     trust_remote_code=_lowercase       )
																		self.assertEqual(feature_extractor.__class__.__name__,     'NewFeatureExtractor'       )
																		self.assertTrue(feature_extractor.is_local       )

																		# If remote is enabled, we load from the Hub
																		SCREAMING_SNAKE_CASE_				=				AutoFeatureExtractor.from_pretrained(
																		    'hf-internal-testing/test_dynamic_feature_extractor',     trust_remote_code=_lowercase       )
																		self.assertEqual(feature_extractor.__class__.__name__,     'NewFeatureExtractor'       )
																		self.assertTrue(not hasattr(_lowercase,     'is_local'       )       )

											finally:
																		if "custom" in CONFIG_MAPPING._extra_content:
																									del CONFIG_MAPPING._extra_content["custom"]
																		if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
																									del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]





