



from manim import *

class 	lowerCamelCase_    ( _A						):






						'''simple docstring'''







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Dict )      ->				Optional[Any]:
									A							:					Dict              =						Rectangle(height=0.5	,	width=0.5 )
									A							:					Any              =						Rectangle(height=0.46	,	width=0.46 ).set_stroke(width=0 )

									A							:					Tuple              =						[mem.copy() for i in range(6 )]
									A							:					List[Any]              =						[mem.copy() for i in range(6 )]
									A							:					Optional[int]              =						VGroup(*__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0 )
									A							:					Optional[int]              =						VGroup(*__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0 )
									A							:					int              =						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							:					Any              =						[mem.copy() for i in range(4 )]
									A							:					List[Any]              =						VGroup(*__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0 )
									A							:					List[str]              =						Text("GPU"	,	font_size=24 )
									A							:					List[Any]              =						Group(__lowerCamelCase	,	__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0.5	,	aligned_edge=__lowerCamelCase )
									gpu.move_to([-1, -1, 0] )
									self.add(__lowerCamelCase )

									A							:					int              =						[mem.copy() for i in range(6 )]
									A							:					Optional[Any]              =						VGroup(*__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0 )

									A							:					Optional[Any]              =						Text("Model"	,	font_size=24 )
									A							:					int              =						Group(__lowerCamelCase	,	__lowerCamelCase ).arrange(__lowerCamelCase	,	buff=0.5	,	aligned_edge=__lowerCamelCase )
									model.move_to([3, -1.0, 0] )
									self.add(__lowerCamelCase )

									A							:					List[str]              =						[]
									for i, rect in enumerate(__lowerCamelCase ):
												rect.set_stroke(__lowerCamelCase )
												# target = fill.copy().set_fill(YELLOW, opacity=0.7)
												# target.move_to(rect)
												# self.add(target)

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

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

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

									A							:					List[Any]              =						Text("Loaded Checkpoint"	,	font_size=24 )
									A							:					List[str]              =						Group(__lowerCamelCase	,	__lowerCamelCase ).arrange(__lowerCamelCase	,	aligned_edge=__lowerCamelCase	,	buff=0.4 )
									checkpoint.move_to([3, 0.5, 0] )

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

									A							:					Union[str, 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(__lowerCamelCase	,	__lowerCamelCase )

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

									blue_text.next_to(__lowerCamelCase	,	DOWN * 2.4	,	aligned_edge=key_text.get_left() )

									A							:					Dict              =						MarkupText(
									    F"""Next, a <i><span fgcolor=\"{BLUE}\">second</span></i> model is loaded into memory,\nwith the weights of a <span fgcolor=\"{BLUE}\">single shard</span>."""	,	font_size=24	,	)
									step_a.move_to([2, 2, 0] )
									self.play(Write(__lowerCamelCase )	,	Write(__lowerCamelCase ) )

									self.play(Write(__lowerCamelCase	,	run_time=1 )	,	Create(__lowerCamelCase	,	run_time=1 ) )

									A							:					int              =						[]
									A							:					str              =						[]
									for i, rect in enumerate(__lowerCamelCase ):
												A							:					List[Any]              =						fill.copy().set_fill(__lowerCamelCase	,	opacity=0.7 )
												target.move_to(__lowerCamelCase )
												first_animations.append(GrowFromCenter(__lowerCamelCase	,	run_time=1 ) )

												A							:					Optional[int]              =						target.copy()
												cpu_target.generate_target()
												if i < 5:
															cpu_target.target.move_to(cpu_left_col_base[i + 1] )
												else:
															cpu_target.target.move_to(cpu_right_col_base[i - 5] )
												second_animations.append(MoveToTarget(__lowerCamelCase	,	run_time=1.5 ) )

									self.play(*__lowerCamelCase )
									self.play(*__lowerCamelCase )
									self.wait()




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
							import torch

							from transformers import XLMRobertaModel

@require_sentencepiece
@require_tokenizers
@require_torch
class 	lowerCamelCase_    ( unittest.TestCase						):






						'''simple docstring'''







						@slow
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				Union[str, Any]:
									A							:					Union[str, Any]              =						XLMRobertaModel.from_pretrained("xlm-roberta-base" )
									A							:					Tuple              =						torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]] )
									# The dog is cute and lives in the garden house

									A							:					Tuple              =						torch.Size((1, 12, 7_68) )  # batch_size, sequence_length, embedding_vector_dim
									A							:					List[str]              =						torch.tensor(
									    [[-0.0101, 0.1218, -0.0803, 0.0801, 0.1327, 0.0776, -0.1215, 0.2383, 0.3338, 0.3106, 0.0300, 0.0252]] )
									#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
									#  xlmr.eval()
									#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
									with torch.no_grad():
												A							:					Tuple              =						model(__lowerCamelCase )["last_hidden_state"].detach()
									self.assertEqual(output.shape	,	__lowerCamelCase )
									# compare the actual values for a slice of last dim
									self.assertTrue(torch.allclose(output[:, :, -1]	,	__lowerCamelCase	,	atol=1e-3 ) )







						@slow
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[int] )      ->				int:
									A							:					str              =						XLMRobertaModel.from_pretrained("xlm-roberta-large" )
									A							:					List[Any]              =						torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]] )
									# The dog is cute and lives in the garden house

									A							:					Optional[Any]              =						torch.Size((1, 12, 10_24) )  # batch_size, sequence_length, embedding_vector_dim
									A							:					List[Any]              =						torch.tensor(
									    [[-0.0699, -0.0318, 0.0705, -0.1241, 0.0999, -0.0520, 0.1004, -0.1838, -0.4704, 0.1437, 0.0821, 0.0126]] )
									#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
									#  xlmr.eval()
									#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
									with torch.no_grad():
												A							:					Optional[int]              =						model(__lowerCamelCase )["last_hidden_state"].detach()
									self.assertEqual(output.shape	,	__lowerCamelCase )
									# compare the actual values for a slice of last dim
									self.assertTrue(torch.allclose(output[:, :, -1]	,	__lowerCamelCase	,	atol=1e-3 ) )