



'''simple docstring'''
from manim import *






class 							lowercase__	(							lowercase   ):





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







							'''simple docstring'''
							_UpperCamelCase					:		Any 				=   Rectangle(height=0.5 ,width=0.5 )
							_UpperCamelCase					:		Tuple 				=   Rectangle(height=0.4_6 ,width=0.4_6 ).set_stroke(width=0 )

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

							_UpperCamelCase					:		Optional[Any] 				=   [mem.copy() for i in range(1 )]
							_UpperCamelCase					:		int 				=   VGroup(*lowerCamelCase__ ).arrange(lowerCamelCase__ ,buff=0 )
							_UpperCamelCase					:		Any 				=   Text('GPU' ,font_size=24 )
							_UpperCamelCase					:		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__ )

							_UpperCamelCase					:		int 				=   [mem.copy() for i in range(6 )]
							_UpperCamelCase					:		Dict 				=   VGroup(*lowerCamelCase__ ).arrange(lowerCamelCase__ ,buff=0 )

							_UpperCamelCase					:		Optional[Any] 				=   Text('Model' ,font_size=24 )
							_UpperCamelCase					:		int 				=   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 ) ,)

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

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

							_UpperCamelCase					:		Tuple 				=   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__ )

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

													if i == 0:
																			cpu_target.target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT ) ,buff=0.0_2 ,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'''




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 		UpperCAmelCase_      (  unittest.TestCase		):





     @slow
     def 							__UpperCAmelCase      ( self       :      str    )				->  List[str]:
        lowerCAmelCase     =			XLMRobertaModel.from_pretrained('xlm-roberta-base'    )
        lowerCAmelCase     =			torch.tensor([[0, 5_8_1, 1_0_2_6_9, 8_3, 9_9_9_4_2, 1_3_6, 6_0_7_4_2, 2_3, 7_0, 8_0_5_8_3, 1_8_2_7_6, 2]]    )
        # The dog is cute and lives in the garden house

        lowerCAmelCase     =			torch.Size((1, 1_2, 7_6_8)    )  # batch_size, sequence_length, embedding_vector_dim
        lowerCAmelCase     =			torch.tensor(
            [[-0.0_101, 0.1_218, -0.0_803, 0.0_801, 0.1_327, 0.0_776, -0.1_215, 0.2_383, 0.3_338, 0.3_106, 0.0_300, 0.0_252]]    )
        #  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():
           lowerCAmelCase     =			model(UpperCAmelCase__    )['last_hidden_state'].detach()
        self.assertEqual(output.shape    ,      UpperCAmelCase__    )
        # compare the actual values for a slice of last dim
        self.assertTrue(torch.allclose(output[:, :, -1]    ,      UpperCAmelCase__    ,      atol=1E-3    )    )





     @slow
     def 							__UpperCAmelCase      ( self       :      List[Any]    )				->  Tuple:
        lowerCAmelCase     =			XLMRobertaModel.from_pretrained('xlm-roberta-large'    )
        lowerCAmelCase     =			torch.tensor([[0, 5_8_1, 1_0_2_6_9, 8_3, 9_9_9_4_2, 1_3_6, 6_0_7_4_2, 2_3, 7_0, 8_0_5_8_3, 1_8_2_7_6, 2]]    )
        # The dog is cute and lives in the garden house

        lowerCAmelCase     =			torch.Size((1, 1_2, 1_0_2_4)    )  # batch_size, sequence_length, embedding_vector_dim
        lowerCAmelCase     =			torch.tensor(
            [[-0.0_699, -0.0_318, 0.0_705, -0.1_241, 0.0_999, -0.0_520, 0.1_004, -0.1_838, -0.4_704, 0.1_437, 0.0_821, 0.0_126]]    )
        #  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():
           lowerCAmelCase     =			model(UpperCAmelCase__    )['last_hidden_state'].detach()
        self.assertEqual(output.shape    ,      UpperCAmelCase__    )
        # compare the actual values for a slice of last dim
        self.assertTrue(torch.allclose(output[:, :, -1]    ,      UpperCAmelCase__    ,      atol=1E-3    )    )





