





'''simple docstring'''



from manim import *
class 	lowerCamelCase_							(					__snake_case			):







						def 					__lowercase    (  self   :      Optional[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			Rectangle(height=0.5				,    width=0.5				)
													SCREAMING_SNAKE_CASE					:      str     					=			Rectangle(height=0.25				,    width=0.25				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			Rectangle(height=0.46				,    width=0.46				).set_stroke(width=0				)

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

													SCREAMING_SNAKE_CASE					:      List[Any]     					=			[mem.copy() for i in range(4				)]
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			VGroup(*A_				).arrange(A_				,    buff=0				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			Text('''GPU'''				,    font_size=24				)
													SCREAMING_SNAKE_CASE					:      List[str]     					=			Group(A_				,    A_				).arrange(A_				,    buff=0.5				,    aligned_edge=A_				)
													gpu.move_to([-1, -1, 0]				)
													self.add(A_				)

													SCREAMING_SNAKE_CASE					:      Any     					=			[mem.copy() for i in range(6				)]
													SCREAMING_SNAKE_CASE					:      Any     					=			VGroup(*A_				).arrange(A_				,    buff=0				)

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			Text('''Model'''				,    font_size=24				)
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			Group(A_				,    A_				).arrange(A_				,    buff=0.5				,    aligned_edge=A_				)
													model.move_to([3, -1.0, 0]				)
													self.add(A_				)

													SCREAMING_SNAKE_CASE					:      Dict     					=			[]
													SCREAMING_SNAKE_CASE					:      int     					=			[]
													SCREAMING_SNAKE_CASE					:      Tuple     					=			[]

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

																				SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			Rectangle(height=0.46 / 4				,    width=0.46 / 3				).set_stroke(width=0.0				).set_fill(A_				,    opacity=0.7				)

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

													self.add(*A_				,    *A_				,    *A_				)

													SCREAMING_SNAKE_CASE					:      Any     					=			[mem.copy() for i in range(6				)]
													SCREAMING_SNAKE_CASE					:      List[str]     					=			VGroup(*A_				).arrange(A_				,    buff=0				)

													SCREAMING_SNAKE_CASE					:      Dict     					=			Text('''Loaded Checkpoint'''				,    font_size=24				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			Group(A_				,    A_				).arrange(A_				,    buff=0.5				,    aligned_edge=A_				)
													checkpoint.move_to([3, 0.5, 0]				)

													self.add(A_				)

													SCREAMING_SNAKE_CASE					:      int     					=			[]
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			[]

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

																				SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			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(A_				)
													self.add(*A_				,    *A_				)

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

													SCREAMING_SNAKE_CASE					:      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]				)

													self.add(A_				,    A_				)

													SCREAMING_SNAKE_CASE					:      List[str]     					=			MarkupText(
													    F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""				,    font_size=18				,    )

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

													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			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					:      Union[str, Any]     					=			[meta_mem.copy() for i in range(6				)]
													SCREAMING_SNAKE_CASE					:      List[str]     					=			[meta_mem.copy() for i in range(6				)]
													SCREAMING_SNAKE_CASE					:      str     					=			VGroup(*A_				).arrange(A_				,    buff=0				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			VGroup(*A_				).arrange(A_				,    buff=0				)
													SCREAMING_SNAKE_CASE					:      List[str]     					=			VGroup(A_				,    A_				).arrange(A_				,    buff=0				)
													SCREAMING_SNAKE_CASE					:      str     					=			Text('''Disk'''				,    font_size=24				)
													SCREAMING_SNAKE_CASE					:      int     					=			Group(A_				,    A_				).arrange(A_				,    buff=0.5				,    aligned_edge=A_				)
													disk.move_to([-4.0, -1.25, 0]				)
													self.play(Write(A_				,    run_time=3				)				,    Write(A_				,    run_time=1				)				,    Create(A_				,    run_time=1				)				)

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			[]
													for i, rect in enumerate(A_				):
																				SCREAMING_SNAKE_CASE					:      List[Any]     					=			rect.copy()
																				target.generate_target()
																				target.target.move_to(disk_left_col_base[i]				).scale(0.5				)
																				animations.append(MoveToTarget(A_				,    run_time=1.5				)				)
													self.play(*A_				)

													self.play(FadeOut(A_				)				)

													SCREAMING_SNAKE_CASE					:      Any     					=			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(A_				,    run_time=3				)				)

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

													self.wait()









'''simple docstring'''



import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list
@require_torchaudio
@require_sentencepiece
class 	lowerCamelCase_							(					unittest.TestCase			):







						def 					__lowercase    (  self   :      Union[str, Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      int     					=			'''laion/clap-htsat-unfused'''
													SCREAMING_SNAKE_CASE					:      Tuple     					=			tempfile.mkdtemp()







						def 					__lowercase    (  self   :      Tuple				,    **lowerCAmelCase__   :      Dict				):

													"""simple docstring"""
													return RobertaTokenizer.from_pretrained(self.checkpoint				,    **lowerCAmelCase__				)







						def 					__lowercase    (  self   :      int				,    **lowerCAmelCase__   :      str				):

													"""simple docstring"""
													return ClapFeatureExtractor.from_pretrained(self.checkpoint				,    **lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Union[str, Any]				):

													"""simple docstring"""
													shutil.rmtree(self.tmpdirname				)







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      List[str]     					=			self.get_tokenizer()
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			self.get_feature_extractor()

													SCREAMING_SNAKE_CASE					:      List[str]     					=			ClapProcessor(tokenizer=lowerCAmelCase__				,    feature_extractor=lowerCAmelCase__				)

													processor.save_pretrained(self.tmpdirname				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			ClapProcessor.from_pretrained(self.tmpdirname				)

													self.assertEqual(processor.tokenizer.get_vocab()				,    tokenizer.get_vocab()				)
													self.assertIsInstance(processor.tokenizer				,    lowerCAmelCase__				)

													self.assertEqual(processor.feature_extractor.to_json_string()				,    feature_extractor.to_json_string()				)
													self.assertIsInstance(processor.feature_extractor				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Union[str, Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Dict     					=			ClapProcessor(tokenizer=self.get_tokenizer()				,    feature_extractor=self.get_feature_extractor()				)
													processor.save_pretrained(self.tmpdirname				)

													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_tokenizer(bos_token='''(BOS)'''				,    eos_token='''(EOS)'''				)
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_feature_extractor(do_normalize=lowerCAmelCase__				,    padding_value=1.0				)

													SCREAMING_SNAKE_CASE					:      str     					=			ClapProcessor.from_pretrained(
													    self.tmpdirname				,    bos_token='''(BOS)'''				,    eos_token='''(EOS)'''				,    do_normalize=lowerCAmelCase__				,    padding_value=1.0				)

													self.assertEqual(processor.tokenizer.get_vocab()				,    tokenizer_add_kwargs.get_vocab()				)
													self.assertIsInstance(processor.tokenizer				,    lowerCAmelCase__				)

													self.assertEqual(processor.feature_extractor.to_json_string()				,    feature_extractor_add_kwargs.to_json_string()				)
													self.assertIsInstance(processor.feature_extractor				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			self.get_feature_extractor()
													SCREAMING_SNAKE_CASE					:      Tuple     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Tuple     					=			ClapProcessor(tokenizer=lowerCAmelCase__				,    feature_extractor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			floats_list((3, 10_00)				)

													SCREAMING_SNAKE_CASE					:      Any     					=			feature_extractor(lowerCAmelCase__				,    return_tensors='''np'''				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			processor(audios=lowerCAmelCase__				,    return_tensors='''np'''				)

													for key in input_feat_extract.keys():
																				self.assertAlmostEqual(input_feat_extract[key].sum()				,    input_processor[key].sum()				,    delta=1e-2				)







						def 					__lowercase    (  self   :      Any				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Tuple     					=			self.get_feature_extractor()
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			ClapProcessor(tokenizer=lowerCAmelCase__				,    feature_extractor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      int     					=			'''This is a test string'''

													SCREAMING_SNAKE_CASE					:      int     					=			processor(text=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			tokenizer(lowerCAmelCase__				)

													for key in encoded_tok.keys():
																				self.assertListEqual(encoded_tok[key]				,    encoded_processor[key]				)







						def 					__lowercase    (  self   :      Optional[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      str     					=			self.get_feature_extractor()
													SCREAMING_SNAKE_CASE					:      List[str]     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Any     					=			ClapProcessor(tokenizer=lowerCAmelCase__				,    feature_extractor=lowerCAmelCase__				)

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

													SCREAMING_SNAKE_CASE					:      Tuple     					=			processor.batch_decode(lowerCAmelCase__				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			tokenizer.batch_decode(lowerCAmelCase__				)

													self.assertListEqual(lowerCAmelCase__				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Optional[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			self.get_feature_extractor()
													SCREAMING_SNAKE_CASE					:      str     					=			self.get_tokenizer()

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			ClapProcessor(tokenizer=lowerCAmelCase__				,    feature_extractor=lowerCAmelCase__				)

													self.assertListEqual(
													    processor.model_input_names[2:]				,    feature_extractor.model_input_names				,    msg='''`processor` and `feature_extractor` model input names do not match'''				,    )




