


"""simple docstring"""


import inspect
import unittest

from transformers import RegNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
		import jax
		import jax.numpy as jnp

		from transformers.models.regnet.modeling_flax_regnet import FlaxRegNetForImageClassification, FlaxRegNetModel

if is_vision_available():
		from PIL import Image

		from transformers import AutoImageProcessor
class snake_case      (  unittest.TestCase):







		def __init__(					self      :       List[Any]    ,   a__      :       int    ,   a__      :       int=3    ,   a__      :       Tuple=32    ,   a__      :       Optional[Any]=3    ,   a__      :       Optional[Any]=10    ,   a__      :       Optional[int]=[10, 20, 30, 40]    ,   a__      :       List[Any]=[1, 1, 2, 1]    ,   a__      :       Optional[Any]=True    ,   a__      :       List[Any]=True    ,   a__      :       Dict="relu"    ,   a__      :       int=3    ,   a__      :       Optional[int]=None    ,   )       ->						str:





						'''simple docstring'''







						_A					  =			parent
						_A					  =			batch_size
						_A					  =			image_size
						_A					  =			num_channels
						_A					  =			embeddings_size
						_A					  =			hidden_sizes
						_A					  =			depths
						_A					  =			is_training
						_A					  =			use_labels
						_A					  =			hidden_act
						_A					  =			num_labels
						_A					  =			scope
						_A					  =			len(a__		)







		def  a_ (					self      :       List[Any]		)       ->						List[str]:





						'''simple docstring'''







						_A					  =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

						_A					  =			self.get_config()

						return config, pixel_values







		def  a_ (					self      :       str		)       ->						Union[str, Any]:





						'''simple docstring'''







						return RegNetConfig(
						    num_channels=self.num_channels    ,   embeddings_size=self.embeddings_size    ,   hidden_sizes=self.hidden_sizes    ,   depths=self.depths    ,   hidden_act=self.hidden_act    ,   num_labels=self.num_labels    ,   image_size=self.image_size    ,   )







		def  a_ (					self      :       List[Any]    ,   a__      :       Union[str, Any]    ,   a__      :       Optional[Any]		)       ->						Tuple:





						'''simple docstring'''







						_A					  =			FlaxRegNetModel(config=a__		)
						_A					  =			model(a__		)

						# Output shape (b, c, h, w)
						self.parent.assertEqual(
						    result.last_hidden_state.shape    ,   (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)    ,   )







		def  a_ (					self      :       List[Any]    ,   a__      :       List[str]    ,   a__      :       Optional[Any]		)       ->						Dict:





						'''simple docstring'''







						_A					  =			self.num_labels
						_A					  =			FlaxRegNetForImageClassification(config=a__		)
						_A					  =			model(a__		)
						self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)		)







		def  a_ (					self      :       Any		)       ->						int:





						'''simple docstring'''







						_A					  =			self.prepare_config_and_inputs()
						_A  ,		_A					  =			config_and_inputs
						_A					  =			{"pixel_values": pixel_values}
						return config, inputs_dict





@require_flax
class snake_case      (  _UpperCamelCase     ,				unittest.TestCase):
		__UpperCamelCase           =			(FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

		__UpperCamelCase           =			False
		__UpperCamelCase           =			False
		__UpperCamelCase           =			False







		def  a_ (					self      :       Dict		)       ->						None:





						'''simple docstring'''







						_A					  =			FlaxRegNetModelTester(self		)
						_A					  =			ConfigTester(self    ,   config_class=a__    ,   has_text_modality=a__		)







		def  a_ (					self      :       str		)       ->						Any:





						'''simple docstring'''







						self.create_and_test_config_common_properties()
						self.config_tester.create_and_test_config_to_json_string()
						self.config_tester.create_and_test_config_to_json_file()
						self.config_tester.create_and_test_config_from_and_save_pretrained()
						self.config_tester.create_and_test_config_with_num_labels()
						self.config_tester.check_config_can_be_init_without_params()
						self.config_tester.check_config_arguments_init()







		def  a_ (					self      :       int		)       ->						Dict:





						'''simple docstring'''







						return







		def  a_ (					self      :       Optional[int]		)       ->						Union[str, Any]:





						'''simple docstring'''







						_A					  =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*a__		)







		def  a_ (					self      :       Optional[Any]		)       ->						List[str]:





						'''simple docstring'''







						_A					  =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*a__		)







		@unittest.skip(reason="RegNet does not use inputs_embeds"		)
		def  a_ (					self      :       Optional[Any]		)       ->						List[Any]:





						'''simple docstring'''







						pass







		@unittest.skip(reason="RegNet does not support input and output embeddings"		)
		def  a_ (					self      :       List[str]		)       ->						Tuple:





						'''simple docstring'''







						pass







		def  a_ (					self      :       int		)       ->						int:





						'''simple docstring'''







						_A  ,		_A					  =			self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										_A					  =			model_class(a__		)
										_A					  =			inspect.signature(model.__call__		)
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										_A					  =			[*signature.parameters.keys()]

										_A					  =			["pixel_values"]
										self.assertListEqual(arg_names[:1]    ,   a__		)







		def  a_ (					self      :       str		)       ->						Optional[Any]:





						'''simple docstring'''







						def check_hidden_states_output(a__      :       List[Any]    ,   a__      :       str    ,   a__      :       Union[str, Any]		):
										_A					  =			model_class(a__		)

										_A					  =			model(**self._prepare_for_class(a__    ,   a__		)		)

										_A					  =			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										_A					  =			self.model_tester.num_stages
										self.assertEqual(len(a__		)    ,   expected_num_stages + 1		)

						_A  ,		_A					  =			self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										_A					  =			True
										check_hidden_states_output(a__    ,   a__    ,   a__		)

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										_A					  =			True

										check_hidden_states_output(a__    ,   a__    ,   a__		)







		def  a_ (					self      :       Union[str, Any]		)       ->						List[str]:





						'''simple docstring'''







						_A  ,		_A					  =			self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										with self.subTest(model_class.__name__		):
														_A					  =			self._prepare_for_class(a__    ,   a__		)
														_A					  =			model_class(a__		)

														@jax.jit
														def model_jitted(a__      :       Dict    ,   **a__      :       List[Any]		):
																		return model(pixel_values=a__    ,   **a__		)

														with self.subTest("JIT Enabled"		):
																		_A					  =			model_jitted(**a__		).to_tuple()

														with self.subTest("JIT Disabled"		):
																		with jax.disable_jit():
																						_A					  =			model_jitted(**a__		).to_tuple()

														self.assertEqual(len(a__		)    ,   len(a__		)		)
														for jitted_output, output in zip(a__    ,   a__		):
																		self.assertEqual(jitted_output.shape    ,   output.shape		)






def      a__ (				)	->	Optional[int]:
				_A					  =			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"   )
				return image




@require_flax
class snake_case      (  unittest.TestCase):







		@cached_property
		def  a_ (					self      :       Optional[int]		)       ->						Optional[int]:





						'''simple docstring'''







						return AutoImageProcessor.from_pretrained("facebook/regnet-y-040"		) if is_vision_available() else None







		@slow
		def  a_ (					self      :       str		)       ->						List[Any]:





						'''simple docstring'''







						_A					  =			FlaxRegNetForImageClassification.from_pretrained("facebook/regnet-y-040"		)

						_A					  =			self.default_image_processor
						_A					  =			prepare_img()
						_A					  =			image_processor(images=a__    ,   return_tensors="np"		)

						_A					  =			model(**a__		)

						# verify the logits
						_A					  =			(1, 10_00)
						self.assertEqual(outputs.logits.shape    ,   a__		)

						_A					  =			jnp.array([-0.4_1_8_0, -1.5_0_5_1, -3.4_8_3_6]		)

						self.assertTrue(jnp.allclose(outputs.logits[0, :3]    ,   a__    ,   atol=1E-4		)		)



"""simple docstring"""


import random
import unittest

from torch.utils.data import BatchSampler, DataLoader, IterableDataset

from accelerate import Accelerator
from accelerate.data_loader import (
    BatchSamplerShard,
    DataLoaderDispatcher,
    DataLoaderShard,
    IterableDatasetShard,
    SkipBatchSampler,
    SkipDataLoader,
    skip_first_batches,
)
class snake_case      (  _UpperCamelCase):







		def __init__(					self      :       Optional[int]    ,   a__      :       str=0.0_1    ,   a__      :       str=10_00		)       ->						int:





						'''simple docstring'''







						_A					  =			p_stop
						_A					  =			max_length







		def __iter__(					self      :       Any		)       ->						Optional[Any]:





						'''simple docstring'''







						_A					  =			0
						_A					  =			False
						while not stop and count < self.max_length:
										yield count
										count += 1
										_A					  =			random.random() < self.p_stop





class snake_case      (  unittest.TestCase):







		def  a_ (					self      :       List[Any]    ,   a__      :       Union[str, Any]    ,   a__      :       Union[str, Any]    ,   a__      :       List[str]=False    ,   a__      :       str=True		)       ->						Union[str, Any]:





						'''simple docstring'''







						_A					  =			[
						    BatchSamplerShard(a__    ,   2    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)
						    for i in range(2		)
						]
						_A					  =			[list(a__		) for batch_sampler_shard in batch_sampler_shards]
						if not split_batches:
										self.assertListEqual([len(a__		) for shard in batch_sampler_shards]    ,   [len(a__		) for e in expected]		)
						self.assertListEqual(a__    ,   a__		)







		def  a_ (					self      :       List[Any]		)       ->						str:





						'''simple docstring'''







						_A					  =			BatchSampler(range(24		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 22, 23]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						_A					  =			BatchSampler(range(24		)    ,   batch_size=3    ,   drop_last=a__		)
						# Expected shouldn't change
						self.check_batch_sampler_shards(a__    ,   a__		)

						# Check the shards when the dataset is a round multiple of batch size but not total batch size.
						_A					  =			BatchSampler(range(21		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [0, 1, 2]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						_A					  =			BatchSampler(range(21		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						# Check the shards when the dataset is not a round multiple of batch size but has a multiple of
						# num_processes batch.
						_A					  =			BatchSampler(range(22		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 0, 1]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						_A					  =			BatchSampler(range(22		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						# Check the shards when the dataset is not a round multiple of batch size but and has not a multiple of
						# num_processes batch.
						_A					  =			BatchSampler(range(20		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 0]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [1, 2, 3]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						_A					  =			BatchSampler(range(20		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__		)

						# Check the shards when the dataset is very small.
						_A					  =			BatchSampler(range(2		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[[[0, 1, 0]], [[1, 0, 1]]]
						self.check_batch_sampler_shards(a__    ,   a__		)

						_A					  =			BatchSampler(range(2		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[[], []]
						self.check_batch_sampler_shards(a__    ,   a__		)







		def  a_ (					self      :       int		)       ->						int:





						'''simple docstring'''







						_A					  =			BatchSampler(range(24		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [22, 23]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						_A					  =			BatchSampler(range(24		)    ,   batch_size=4    ,   drop_last=a__		)
						# Expected shouldn't change
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size.
						_A					  =			BatchSampler(range(22		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [0, 1]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						_A					  =			BatchSampler(range(22		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size or num_processes.
						_A					  =			BatchSampler(range(21		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 0]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [1, 2]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						_A					  =			BatchSampler(range(21		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						# Check the shards when the dataset is very small.
						_A					  =			BatchSampler(range(2		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[[[0, 1]], [[0, 1]]]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)

						_A					  =			BatchSampler(range(2		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[[], []]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__		)







		def  a_ (					self      :       List[str]		)       ->						List[str]:





						'''simple docstring'''







						_A					  =			BatchSampler(range(24		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21, 22, 23]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(24		)    ,   batch_size=3    ,   drop_last=a__		)
						# Expected shouldn't change
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						# Check the shards when the dataset is a round multiple of batch size but not total batch size.
						_A					  =			BatchSampler(range(21		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(21		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size but has a multiple of
						# num_processes batch.
						_A					  =			BatchSampler(range(22		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19, 20]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17], [21]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(22		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size but and has not a multiple of
						# num_processes batch.
						_A					  =			BatchSampler(range(20		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14], [18, 19]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(20		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1, 2], [6, 7, 8], [12, 13, 14]],
						    [[3, 4, 5], [9, 10, 11], [15, 16, 17]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						# Check the shards when the dataset is very small.
						_A					  =			BatchSampler(range(2		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[[[0, 1]], []]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(2		)    ,   batch_size=3    ,   drop_last=a__		)
						_A					  =			[[], []]
						self.check_batch_sampler_shards(a__    ,   a__    ,   even_batches=a__		)







		def  a_ (					self      :       List[str]		)       ->						str:





						'''simple docstring'''







						_A					  =			BatchSampler(range(24		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19], [22, 23]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(24		)    ,   batch_size=4    ,   drop_last=a__		)
						# Expected shouldn't change
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size.
						_A					  =			BatchSampler(range(22		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20, 21]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(22		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						# Check the shards when the dataset is not a round multiple of batch size or num_processes.
						_A					  =			BatchSampler(range(21		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17], [20]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(21		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[
						    [[0, 1], [4, 5], [8, 9], [12, 13], [16, 17]],
						    [[2, 3], [6, 7], [10, 11], [14, 15], [18, 19]],
						]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						# Check the shards when the dataset is very small.
						_A					  =			BatchSampler(range(2		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[[[0, 1]], []]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)

						_A					  =			BatchSampler(range(2		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			[[], []]
						self.check_batch_sampler_shards(a__    ,   a__    ,   split_batches=a__    ,   even_batches=a__		)







		def  a_ (					self      :       Union[str, Any]		)       ->						str:





						'''simple docstring'''







						_A					  =			[[0, 1, 2], [3, 4], [5, 6, 7, 8], [9, 10, 11], [12, 13]]
						_A					  =			[BatchSamplerShard(a__    ,   2    ,   a__    ,   even_batches=a__		) for i in range(2		)]

						self.assertEqual(len(batch_sampler_shards[0]		)    ,   3		)
						self.assertEqual(len(batch_sampler_shards[1]		)    ,   2		)

						self.assertListEqual(list(batch_sampler_shards[0]		)    ,   [[0, 1, 2], [5, 6, 7, 8], [12, 13]]		)
						self.assertListEqual(list(batch_sampler_shards[1]		)    ,   [[3, 4], [9, 10, 11]]		)







		def  a_ (					self      :       Optional[int]    ,   a__      :       Optional[int]    ,   a__      :       Tuple    ,   a__      :       Optional[int]    ,   a__      :       Union[str, Any]=False    ,   a__      :       int=2    ,   a__      :       List[Any]=False		)       ->						str:





						'''simple docstring'''







						random.seed(a__		)
						_A					  =			list(a__		)

						_A					  =			[
						    IterableDatasetShard(
						        a__    ,   batch_size=a__    ,   drop_last=a__    ,   num_processes=a__    ,   process_index=a__    ,   split_batches=a__    ,   )
						    for i in range(a__		)
						]
						_A					  =			[]
						for iterable_dataset_shard in iterable_dataset_shards:
										# Since our random iterable dataset will be... random... we need to use a seed to get reproducible results.
										random.seed(a__		)
										iterable_dataset_lists.append(list(a__		)		)

						_A					  =			batch_size // num_processes if split_batches else batch_size
						# All iterable dataset shard should have the same length, a round multiple of shard_batch_size
						_A					  =			iterable_dataset_lists[0]
						for l in iterable_dataset_lists[1:]:
										self.assertEqual(len(a__		)    ,   len(a__		)		)
										self.assertTrue(len(a__		) % shard_batch_size == 0		)

						_A					  =			[]
						for idx in range(0    ,   len(a__		)    ,   a__		):
										for l in iterable_dataset_lists:
														observed += l[idx : idx + shard_batch_size]

						if not drop_last:
										while len(a__		) < len(a__		):
														reference += reference
						self.assertListEqual(a__    ,   reference[: len(a__		)]		)







		def  a_ (					self      :       List[str]		)       ->						List[Any]:





						'''simple docstring'''







						_A					  =			42
						_A					  =			RandomIterableDataset()

						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)

						# Edge case with a very small dataset
						_A					  =			RandomIterableDataset(max_length=2		)

						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)
						self.check_iterable_dataset_shards(a__    ,   a__    ,   batch_size=4    ,   drop_last=a__    ,   split_batches=a__		)







		def  a_ (					self      :       List[str]		)       ->						Dict:





						'''simple docstring'''







						_A					  =			BatchSampler(range(16		)    ,   batch_size=4    ,   drop_last=a__		)
						_A					  =			SkipBatchSampler(a__    ,   2		)
						self.assertListEqual(list(a__		)    ,   [[8, 9, 10, 11], [12, 13, 14, 15]]		)







		def  a_ (					self      :       int		)       ->						Union[str, Any]:





						'''simple docstring'''







						_A					  =			SkipDataLoader(list(range(16		)		)    ,   batch_size=4    ,   skip_batches=2		)
						self.assertListEqual([t.tolist() for t in dataloader]    ,   [[8, 9, 10, 11], [12, 13, 14, 15]]		)







		def  a_ (					self      :       int		)       ->						Optional[int]:





						'''simple docstring'''







						_A					  =			DataLoader(list(range(16		)		)    ,   batch_size=4		)
						_A					  =			skip_first_batches(a__    ,   num_batches=2		)
						self.assertListEqual([t.tolist() for t in new_dataloader]    ,   [[8, 9, 10, 11], [12, 13, 14, 15]]		)







		def  a_ (					self      :       Optional[Any]		)       ->						Optional[int]:





						'''simple docstring'''







						_A					  =			DataLoaderShard(list(range(16		)		)    ,   batch_size=4		)
						for idx, _ in enumerate(a__		):
										self.assertEqual(dataloader.end_of_dataloader    ,   idx == 3		)

						# Test it also works on the second iteration
						for idx, _ in enumerate(a__		):
										self.assertEqual(dataloader.end_of_dataloader    ,   idx == 3		)







		def  a_ (					self      :       int		)       ->						int:





						'''simple docstring'''







						Accelerator()
						_A					  =			DataLoaderDispatcher(range(16		)    ,   batch_size=4		)
						for idx, _ in enumerate(a__		):
										self.assertEqual(dataloader.end_of_dataloader    ,   idx == 3		)

						# Test it also works on the second iteration
						for idx, _ in enumerate(a__		):
										self.assertEqual(dataloader.end_of_dataloader    ,   idx == 3		)