


from manim import *
class  SCREAMING_SNAKE_CASE__  (				lowercase__			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     )		->			Optional[int]:
             a_					:		Optional[int]							=  Rectangle(height=0.5     ,							width=0.5     )
             a_					:		List[Any]							=  Rectangle(height=0.25     ,							width=0.25     )
             a_					:		Optional[Any]							=  Rectangle(height=0.46     ,							width=0.46     ).set_stroke(width=0     )

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

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

             a_					:		Optional[Any]							=  [mem.copy() for i in range(6     )]
             a_					:		List[Any]							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )

             a_					:		List[str]							=  Text('Model'     ,							font_size=2_4     )
             a_					:		int							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             model.move_to([3, -1.0, 0]     )
             self.add(SCREAMING_SNAKE_CASE__     )

             a_					:		Dict							=  []
             a_					:		str							=  []
             a_					:		int							=  []

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

                    a_					:		int							=  Rectangle(height=0.46 / 4     ,							width=0.46 / 3     ).set_stroke(width=0.0     ).set_fill(SCREAMING_SNAKE_CASE__     ,							opacity=0.7     )

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

             self.add(*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     )

             a_					:		Tuple							=  [mem.copy() for i in range(6     )]
             a_					:		Union[str, Any]							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )

             a_					:		Dict							=  Text('Loaded Checkpoint'     ,							font_size=2_4     )
             a_					:		str							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             checkpoint.move_to([3, 0.5, 0]     )

             self.add(SCREAMING_SNAKE_CASE__     )

             a_					:		Dict							=  []
             a_					:		Optional[int]							=  []

             for i, rect in enumerate(SCREAMING_SNAKE_CASE__     ):
                    a_					:		Union[str, Any]							=  fill.copy().set_fill(SCREAMING_SNAKE_CASE__     ,							opacity=0.7     )
                    target.move_to(SCREAMING_SNAKE_CASE__     )
                    ckpt_arr.append(SCREAMING_SNAKE_CASE__     )

                    a_					:		List[str]							=  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(SCREAMING_SNAKE_CASE__     )
             self.add(*SCREAMING_SNAKE_CASE__     ,							*SCREAMING_SNAKE_CASE__     )

             a_					:		List[str]							=  Square(side_length=2.2     )
             key.move_to([-5, 2, 0]     )

             a_					:		Optional[Any]							=  MarkupText(
                 F"""<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"""     ,							font_size=1_8     ,							)

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

             self.add(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[int]							=  MarkupText(
                 F"""<span fgcolor='{BLUE}'>●</span> Checkpoint"""     ,							font_size=1_8     ,							)

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

             a_					:		str							=  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=2_4     ,							)
             step_a.move_to([2, 2, 0]     )

             a_					:		List[Any]							=  [meta_mem.copy() for i in range(6     )]
             a_					:		Optional[Any]							=  [meta_mem.copy() for i in range(6     )]
             a_					:		int							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		Optional[int]							=  VGroup(*SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		Tuple							=  VGroup(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0     )
             a_					:		Dict							=  Text('Disk'     ,							font_size=2_4     )
             a_					:		Optional[Any]							=  Group(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ).arrange(SCREAMING_SNAKE_CASE__     ,							buff=0.5     ,							aligned_edge=SCREAMING_SNAKE_CASE__     )
             disk.move_to([-4.0, -1.25, 0]     )
             self.play(Write(SCREAMING_SNAKE_CASE__     ,							run_time=3     )     ,							Write(SCREAMING_SNAKE_CASE__     ,							run_time=1     )     ,							Create(SCREAMING_SNAKE_CASE__     ,							run_time=1     )     )

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

             self.play(FadeOut(SCREAMING_SNAKE_CASE__     )     )

             a_					:		Optional[Any]							=  MarkupText(F"""Then, the checkpoint is removed from memory\nthrough garbage collection."""     ,							font_size=2_4     )
             step_a.move_to([2, 2, 0]     )

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

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

             self.wait()







import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs






@pytest.mark.parametrize(
    "kwargs, expected"				, [
        ({"num_shards": 0, "max_num_jobs": 1}, []),
        ({"num_shards": 10, "max_num_jobs": 1}, [range(10  )]),
        ({"num_shards": 10, "max_num_jobs": 10}, [range(_lowerCamelCase				, i + 1  ) for i in range(10  )]),
        ({"num_shards": 1, "max_num_jobs": 10}, [range(1  )]),
        ({"num_shards": 10, "max_num_jobs": 3}, [range(0				, 4  ), range(4				, 7  ), range(7				, 10  )]),
        ({"num_shards": 3, "max_num_jobs": 10}, [range(0				, 1  ), range(1				, 2  ), range(2				, 3  )]),
    ]				, )
def 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							List[Any]    =    _distribute_shards(**_lowerCamelCase  )
							assert out == expected






@pytest.mark.parametrize(
    "gen_kwargs, max_num_jobs, expected"				, [
        ({"foo": 0}, 10, [{"foo": 0}]),
        ({"shards": [0, 1, 2, 3]}, 1, [{"shards": [0, 1, 2, 3]}]),
        ({"shards": [0, 1, 2, 3]}, 4, [{"shards": [0]}, {"shards": [1]}, {"shards": [2]}, {"shards": [3]}]),
        ({"shards": [0, 1]}, 4, [{"shards": [0]}, {"shards": [1]}]),
        ({"shards": [0, 1, 2, 3]}, 2, [{"shards": [0, 1]}, {"shards": [2, 3]}]),
    ]				, )
def 				A				(					_lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Optional[int]    =    _split_gen_kwargs(_lowerCamelCase				, _lowerCamelCase  )
							assert out == expected






@pytest.mark.parametrize(
    "gen_kwargs, expected"				, [
        ({"foo": 0}, 1),
        ({"shards": [0]}, 1),
        ({"shards": [0, 1, 2, 3]}, 4),
        ({"shards": [0, 1, 2, 3], "foo": 0}, 4),
        ({"shards": [0, 1, 2, 3], "other": (0, 1)}, 4),
        ({"shards": [0, 1, 2, 3], "shards2": [0, 1]}, RuntimeError),
    ]				, )
def 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							if expected is RuntimeError:
														with pytest.raises(_lowerCamelCase  ):
																					_number_of_shards_in_gen_kwargs(_lowerCamelCase  )
							else:
														_lowerCAmelCase     :							Optional[int]    =    _number_of_shards_in_gen_kwargs(_lowerCamelCase  )
														assert out == expected
