





from typing import List

import numpy as np






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							dict    ):
		SCREAMING_SNAKE_CASE__			=      {key: len(UpperCamelCase__    ) for key, value in gen_kwargs.items() if isinstance(UpperCamelCase__					,   UpperCamelCase__    )}
		if len(set(lists_lengths.values()    )    ) > 1:
				raise RuntimeError(
				    (
				        """Sharding is ambiguous for this dataset: """
				        + """we found several data sources lists of different lengths, and we don't know over which list we should parallelize:\n"""
				        + """\n""".join(f'''\t- key {key} has length {length}''' for key, length in lists_lengths.items()    )
				        + """\nTo fix this, check the 'gen_kwargs' and make sure to use lists only for data sources, """
				        + """and use tuples otherwise. In the end there should only be one single list, or several lists with the same length."""
				    )    )
		SCREAMING_SNAKE_CASE__			=      max(lists_lengths.values()					,   default=0    )
		return max(1					,   UpperCamelCase__    )






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							int					,   UpperCamelCase__:							int    ):
		SCREAMING_SNAKE_CASE__			=      []
		for group_idx in range(UpperCamelCase__    ):
				SCREAMING_SNAKE_CASE__			=      num_shards // max_num_jobs + (group_idx < (num_shards % max_num_jobs))
				if num_shards_to_add == 0:
						break
				SCREAMING_SNAKE_CASE__			=      shards_indices_per_group[-1].stop if shards_indices_per_group else 0
				SCREAMING_SNAKE_CASE__			=      range(UpperCamelCase__					,   start + num_shards_to_add    )
				shards_indices_per_group.append(UpperCamelCase__    )
		return shards_indices_per_group






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							dict					,   UpperCamelCase__:							int    ):
		SCREAMING_SNAKE_CASE__			=      _number_of_shards_in_gen_kwargs(UpperCamelCase__    )
		if num_shards == 1:
				return [dict(UpperCamelCase__    )]
		else:
				SCREAMING_SNAKE_CASE__			=      _distribute_shards(num_shards=UpperCamelCase__					,   max_num_jobs=UpperCamelCase__    )
				return [
				    {
				        key: [value[shard_idx] for shard_idx in shard_indices_per_group[group_idx]]
				        if isinstance(UpperCamelCase__					,   UpperCamelCase__    )
				        else value
				        for key, value in gen_kwargs.items()
				    }
				    for group_idx in range(len(UpperCamelCase__    )    )
				]






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							List[dict]    ):
		return {
		    key: [value for gen_kwargs in gen_kwargs_list for value in gen_kwargs[key]]
		    if isinstance(gen_kwargs_list[0][key]					,   UpperCamelCase__    )
		    else gen_kwargs_list[0][key]
		    for key in gen_kwargs_list[0]
		}






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							np.random.Generator					,   UpperCamelCase__:							dict    ):
		SCREAMING_SNAKE_CASE__			=      {len(UpperCamelCase__    ) for value in gen_kwargs.values() if isinstance(UpperCamelCase__					,   UpperCamelCase__    )}
		SCREAMING_SNAKE_CASE__			=      {}
		for size in list_sizes:
				SCREAMING_SNAKE_CASE__			=      list(range(UpperCamelCase__    )    )
				rng.shuffle(indices_per_size[size]    )
		# Now let's copy the gen_kwargs and shuffle the lists based on their sizes
		SCREAMING_SNAKE_CASE__			=      dict(UpperCamelCase__    )
		for key, value in shuffled_kwargs.items():
				if isinstance(UpperCamelCase__					,   UpperCamelCase__    ):
						SCREAMING_SNAKE_CASE__			=      [value[i] for i in indices_per_size[len(UpperCamelCase__    )]]
		return shuffled_kwargs






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_lowerCamelCase   				=			{
    'configuration_layoutlmv3': [
        'LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'LayoutLMv3Config',
        'LayoutLMv3OnnxConfig',
    ],
    'processing_layoutlmv3': ['LayoutLMv3Processor'],
    'tokenization_layoutlmv3': ['LayoutLMv3Tokenizer'],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase   				=			['LayoutLMv3TokenizerFast']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase   				=			[
	    'LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'LayoutLMv3ForQuestionAnswering',
	    'LayoutLMv3ForSequenceClassification',
	    'LayoutLMv3ForTokenClassification',
	    'LayoutLMv3Model',
	    'LayoutLMv3PreTrainedModel',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase   				=			[
	    'TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'TFLayoutLMv3ForQuestionAnswering',
	    'TFLayoutLMv3ForSequenceClassification',
	    'TFLayoutLMv3ForTokenClassification',
	    'TFLayoutLMv3Model',
	    'TFLayoutLMv3PreTrainedModel',
	]

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase   				=			['LayoutLMv3FeatureExtractor']
	_lowerCamelCase   				=			['LayoutLMv3ImageProcessor']


if TYPE_CHECKING:
	from .configuration_layoutlmva import (
	    LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    LayoutLMvaConfig,
	    LayoutLMvaOnnxConfig,
	)
	from .processing_layoutlmva import LayoutLMvaProcessor
	from .tokenization_layoutlmva import LayoutLMvaTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_layoutlmva import (
		    LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
		    LayoutLMvaForQuestionAnswering,
		    LayoutLMvaForSequenceClassification,
		    LayoutLMvaForTokenClassification,
		    LayoutLMvaModel,
		    LayoutLMvaPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_layoutlmva import (
		    TF_LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFLayoutLMvaForQuestionAnswering,
		    TFLayoutLMvaForSequenceClassification,
		    TFLayoutLMvaForTokenClassification,
		    TFLayoutLMvaModel,
		    TFLayoutLMvaPreTrainedModel,
		)

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor
		from .image_processing_layoutlmva import LayoutLMvaImageProcessor

else:
	import sys

	_lowerCamelCase   				=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)