






'''simple docstring'''







import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase   )   -> List[str]:






							def wrapper(*UpperCamelCase       ,    **UpperCamelCase   ):
														lowerCamelCase__      :			int 						= timeit.default_timer()
														lowerCamelCase__      :			Any 						= func(*a_       ,    **a_   )
														lowerCamelCase__      :			str 						= timeit.default_timer() - starttime
														return delta

							lowerCamelCase__      :			int 						= func.__name__

							return wrapper





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase=100       ,    UpperCamelCase=None   )   -> Tuple:
							lowerCamelCase__      :			Union[str, Any] 						= []
							lowerCamelCase__      :			Optional[int] 						= seq_shapes or {}
							for i in range(a_   ):
														lowerCamelCase__      :			List[Any] 						= {}
														for col_id, (k, v) in enumerate(features.items()   ):
																					if isinstance(a_       ,    _ArrayXD   ):
																												lowerCamelCase__      :			Optional[Any] 						= np.random.rand(*v.shape   ).astype(v.dtype   )
																					elif isinstance(a_       ,    datasets.Value   ):
																												if v.dtype == "string":
																																			lowerCamelCase__      :			str 						= '''The small grey turtle was surprisingly fast when challenged.'''
																												else:
																																			lowerCamelCase__      :			Union[str, Any] 						= np.random.randint(10       ,    size=1   ).astype(v.dtype   ).item()
																					elif isinstance(a_       ,    datasets.Sequence   ):
																												while isinstance(a_       ,    datasets.Sequence   ):
																																			lowerCamelCase__      :			Optional[int] 						= v.feature
																												lowerCamelCase__      :			List[Any] 						= seq_shapes[k]
																												lowerCamelCase__      :			Any 						= np.random.rand(*a_   ).astype(v.dtype   )
																					lowerCamelCase__      :			Tuple 						= data

														dummy_data.append((i, example)   )

							return dummy_data





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase=100       ,    UpperCamelCase=None   )   -> str:
							lowerCamelCase__      :			Optional[Any] 						= generate_examples(a_       ,    num_examples=a_       ,    seq_shapes=a_   )

							with ArrowWriter(features=a_       ,    path=a_   ) as writer:
														for key, record in dummy_data:
																					lowerCamelCase__      :			int 						= features.encode_example(a_   )
																					writer.write(a_   )

														lowerCamelCase__      :			Any 						= writer.finalize()

							if not num_final_examples == num_examples:
														raise ValueError(
														    f'''Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}.'''   )

							lowerCamelCase__      :			Union[str, Any] 						= datasets.Dataset.from_file(filename=a_       ,    info=datasets.DatasetInfo(features=a_   )   )

							return dataset









'''simple docstring'''







_A			:    List[str]					  ='''0.21.0'''

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
			from .utils import rich

