
def  A			(   lowercase = 998_001					)  ->    Any:
		'''simple docstring'''

		for number in range(n - 1       ,			9_999       ,			-1					):
				UpperCamelCase            =	str(lowercase					)

				# checks whether 'str_number' is a palindrome.
				if str_number == str_number[::-1]:
						UpperCamelCase            =	999

						# if 'number' is a product of two 3-digit numbers
						# then number is the answer otherwise fetch next number.
						while divisor != 99:
								if (number % divisor == 0) and (len(str(number // divisor					)					) == 3.0):
										return number
								divisor -= 1
		raise ValueError('That number is larger than our acceptable range.'					)


if __name__ == "__main__":
					print(F'''{solution() = }''')


import os
import sys
from pathlib import Path

import pytest

from datasets import Dataset, IterableDataset
from datasets.distributed import split_dataset_by_node

from .utils import execute_subprocess_async, get_torch_dist_unique_port, require_torch




def 		A						(  ):




			"""simple docstring"""


			UpperCAmelCase__		:Tuple 		=    Dataset.from_dict({'i': range(17							)}							)
			UpperCAmelCase__		:Optional[Any] 		=    len(SCREAMING_SNAKE_CASE							)
			UpperCAmelCase__		:Dict 		=    3
			UpperCAmelCase__		:List[str] 		=    [
			    split_dataset_by_node(SCREAMING_SNAKE_CASE     ,						rank=SCREAMING_SNAKE_CASE     ,						world_size=SCREAMING_SNAKE_CASE							) for rank in range(SCREAMING_SNAKE_CASE							)
			]
			assert sum(len(SCREAMING_SNAKE_CASE							) for ds in datasets_per_rank							) == full_size
			assert len({tuple(x.values()							) for ds in datasets_per_rank for x in ds}							) == full_size




def 		A						(  ):




			"""simple docstring"""


			def gen():
						return ({"i": i} for i in range(17							))

			UpperCAmelCase__		:Union[str, Any] 		=    3
			UpperCAmelCase__		:Union[str, Any] 		=    IterableDataset.from_generator(SCREAMING_SNAKE_CASE							)
			UpperCAmelCase__		:Union[str, Any] 		=    len(list(SCREAMING_SNAKE_CASE							)							)
			UpperCAmelCase__		:Dict 		=    [
			    split_dataset_by_node(SCREAMING_SNAKE_CASE     ,						rank=SCREAMING_SNAKE_CASE     ,						world_size=SCREAMING_SNAKE_CASE							) for rank in range(SCREAMING_SNAKE_CASE							)
			]
			assert sum(len(list(SCREAMING_SNAKE_CASE							)							) for ds in datasets_per_rank							) == full_size
			assert len({tuple(x.values()							) for ds in datasets_per_rank for x in ds}							) == full_size




@pytest.mark.parametrize('shards_per_node'     ,						[1, 2, 3]							)
def 		A						(  SCREAMING_SNAKE_CASE							):




			"""simple docstring"""


			def gen(SCREAMING_SNAKE_CASE							):
						for shard in shards:
									yield from ({"i": i, "shard": shard} for i in range(17							))

			UpperCAmelCase__		:int 		=    3
			UpperCAmelCase__		:Any 		=    shards_per_node * world_size
			UpperCAmelCase__		:int 		=    {'shards': [f"""shard_{shard_idx}.txt""" for shard_idx in range(SCREAMING_SNAKE_CASE							)]}
			UpperCAmelCase__		:Optional[Any] 		=    IterableDataset.from_generator(SCREAMING_SNAKE_CASE     ,						gen_kwargs=SCREAMING_SNAKE_CASE							)
			UpperCAmelCase__		:Tuple 		=    len(list(SCREAMING_SNAKE_CASE							)							)
			assert full_ds.n_shards == world_size * shards_per_node
			UpperCAmelCase__		:Optional[Any] 		=    [
			    split_dataset_by_node(SCREAMING_SNAKE_CASE     ,						rank=SCREAMING_SNAKE_CASE     ,						world_size=SCREAMING_SNAKE_CASE							) for rank in range(SCREAMING_SNAKE_CASE							)
			]
			assert [ds.n_shards for ds in datasets_per_rank] == [shards_per_node] * world_size
			assert sum(len(list(SCREAMING_SNAKE_CASE							)							) for ds in datasets_per_rank							) == full_size
			assert len({tuple(x.values()							) for ds in datasets_per_rank for x in ds}							) == full_size




def 		A						(  ):




			"""simple docstring"""


			def gen():
						return ({"i": i} for i in range(17							))

			UpperCAmelCase__		:Tuple 		=    2
			UpperCAmelCase__		:List[str] 		=    IterableDataset.from_generator(SCREAMING_SNAKE_CASE							)
			UpperCAmelCase__		:str 		=    len(list(SCREAMING_SNAKE_CASE							)							)

			UpperCAmelCase__		:List[str] 		=    split_dataset_by_node(SCREAMING_SNAKE_CASE     ,						rank=0     ,						world_size=SCREAMING_SNAKE_CASE							).shuffle(seed=42							)
			assert len(list(SCREAMING_SNAKE_CASE							)							) == 1 + full_size // world_size
			with pytest.raises(SCREAMING_SNAKE_CASE							):
						split_dataset_by_node(SCREAMING_SNAKE_CASE     ,						rank=0     ,						world_size=SCREAMING_SNAKE_CASE							).shuffle()

			UpperCAmelCase__		:Dict 		=    split_dataset_by_node(full_ds.shuffle(seed=42							)     ,						rank=0     ,						world_size=SCREAMING_SNAKE_CASE							)
			assert len(list(SCREAMING_SNAKE_CASE							)							) == 1 + full_size // world_size
			with pytest.raises(SCREAMING_SNAKE_CASE							):
						split_dataset_by_node(full_ds.shuffle()     ,						rank=0     ,						world_size=SCREAMING_SNAKE_CASE							)




@pytest.mark.parametrize('streaming'     ,						[False, True]							)
@require_torch
@pytest.mark.skipif(os.name == 'nt'     ,						reason='execute_subprocess_async doesn\'t support windows'							)
@pytest.mark.integration
def 		A						(  SCREAMING_SNAKE_CASE							):




			"""simple docstring"""


			UpperCAmelCase__		:Dict 		=    2
			UpperCAmelCase__		:str 		=    get_torch_dist_unique_port()
			UpperCAmelCase__		:Optional[int] 		=    Path(SCREAMING_SNAKE_CASE							).resolve().parent / 'distributed_scripts' / 'launch_torch_distributed.py'
			UpperCAmelCase__		:Any 		=    f"""
        -m torch.distributed.launch
        --nproc_per_node={nproc_per_node}
        --master_port={master_port}
        {test_script}
    """.split()
			UpperCAmelCase__		:Optional[int] 		=    f"""
        --streaming={streaming}
    """.split()
			UpperCAmelCase__		:Optional[Any] 		=    [sys.executable] + distributed_args + args
			execute_subprocess_async(SCREAMING_SNAKE_CASE     ,						env=os.environ.copy()							)




@pytest.mark.parametrize(
    'nproc_per_node, num_workers'     ,						[
        (2, 2),  # each node has 2 shards and each worker has 1 shards
        (3, 2),  # each node uses all the shards but skips examples, and each worker has 2 shards
    ]     ,						)
@require_torch
@pytest.mark.skipif(os.name == 'nt'     ,						reason='execute_subprocess_async doesn\'t support windows'							)
@pytest.mark.integration
def 		A						(  SCREAMING_SNAKE_CASE     ,						SCREAMING_SNAKE_CASE							):




			"""simple docstring"""


			UpperCAmelCase__		:List[str] 		=    True
			UpperCAmelCase__		:Optional[Any] 		=    get_torch_dist_unique_port()
			UpperCAmelCase__		:Union[str, Any] 		=    Path(SCREAMING_SNAKE_CASE							).resolve().parent / 'distributed_scripts' / 'launch_torch_distributed.py'
			UpperCAmelCase__		:Union[str, Any] 		=    f"""
        -m torch.distributed.launch
        --nproc_per_node={nproc_per_node}
        --master_port={master_port}
        {test_script}
    """.split()
			UpperCAmelCase__		:Union[str, Any] 		=    f"""
        --streaming={streaming}
        --num_workers={num_workers}
    """.split()
			UpperCAmelCase__		:List[Any] 		=    [sys.executable] + distributed_args + args
			execute_subprocess_async(SCREAMING_SNAKE_CASE     ,						env=os.environ.copy()							)





