





import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


a__      :     Union[str, Any]         =		logging.get_logger(__name__)





class UpperCAmelCase_				:
  __lowerCAmelCase   :						Optional[int]							=   None




@experimental
def      UpperCAmelCase_    (    _UpperCAmelCase							:Dict  ,						_UpperCAmelCase							:Any  ,						_UpperCAmelCase							:Union[str, Any]  ,						_UpperCAmelCase							:Optional[int]  ,						_UpperCAmelCase							:str  ,						_UpperCAmelCase							:List[Any]  ,						_UpperCAmelCase							:int				)	->				Any:
     '''simple docstring'''


     if ParallelBackendConfig.backend_name is None:
          return _map_with_multiprocessing_pool(
              _UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase				)

     return _map_with_joblib(_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase  ,						_UpperCAmelCase				)

def      UpperCAmelCase_    (    _UpperCAmelCase							:Optional[int]  ,						_UpperCAmelCase							:List[Any]  ,						_UpperCAmelCase							:Tuple  ,						_UpperCAmelCase							:Any  ,						_UpperCAmelCase							:List[Any]  ,						_UpperCAmelCase							:List[str]  ,						_UpperCAmelCase							:int				)	->				Union[str, Any]:
     '''simple docstring'''


     A_          =       num_proc if num_proc <= len(_UpperCAmelCase				) else len(_UpperCAmelCase				)
     A_          =       []  # We organize the splits ourselve (contiguous splits)
     for index in range(_UpperCAmelCase				):
          A_          =       len(_UpperCAmelCase				) // num_proc
          A_          =       len(_UpperCAmelCase				) % num_proc
          A_          =       div * index + min(_UpperCAmelCase  ,						_UpperCAmelCase				)
          A_          =       start + div + (1 if index < mod else 0)
          split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)				)

     if len(_UpperCAmelCase				) != sum(len(i[1]				) for i in split_kwds				):
          raise ValueError(
              f'Error dividing inputs iterable among processes. '
              f'Total number of objects {len(_UpperCAmelCase				)}, '
              f'length: {sum(len(i[1]				) for i in split_kwds				)}'				)

     logger.info(
         f'Spawning {num_proc} processes for {len(_UpperCAmelCase				)} objects in slices of {[len(i[1]				) for i in split_kwds]}'				)
     A_   ,    A_          =       None, None
     if not disable_tqdm:
          A_   ,    A_          =       (RLock(),), tqdm.set_lock
     with Pool(_UpperCAmelCase  ,						initargs=_UpperCAmelCase  ,						initializer=_UpperCAmelCase				) as pool:
          A_          =       pool.map(_UpperCAmelCase  ,						_UpperCAmelCase				)
     logger.info(f'Finished {num_proc} processes'				)
     A_          =       [obj for proc_res in mapped for obj in proc_res]
     logger.info(f'Unpacked {len(_UpperCAmelCase				)} objects'				)

     return mapped

def      UpperCAmelCase_    (    _UpperCAmelCase							:int  ,						_UpperCAmelCase							:Dict  ,						_UpperCAmelCase							:Optional[int]  ,						_UpperCAmelCase							:Optional[Any]  ,						_UpperCAmelCase							:Tuple  ,						_UpperCAmelCase							:int  ,						_UpperCAmelCase							:Dict				)	->				int:
     '''simple docstring'''


     import joblib

     with joblib.parallel_backend(ParallelBackendConfig.backend_name  ,						n_jobs=_UpperCAmelCase				):
          return joblib.Parallel()(
              joblib.delayed(_UpperCAmelCase				)((function, obj, types, None, True, None)				) for obj in iterable				)


@experimental
@contextlib.contextmanager
def      UpperCAmelCase_    (    _UpperCAmelCase							:str				)	->				Optional[int]:
     '''simple docstring'''


     A_          =       backend_name

     if backend_name == "spark":
          from joblibspark import register_spark

          register_spark()

          # TODO: call create_cache_and_write_probe if "download" in steps
          # TODO: raise NotImplementedError when Dataset.map etc is called

     try:
          yield
     finally:
          A_          =       None










from typing import TYPE_CHECKING

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


a__      :     str         =		{
    'configuration_roformer': ['ROFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'RoFormerConfig', 'RoFormerOnnxConfig'],
    'tokenization_roformer': ['RoFormerTokenizer'],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      a__      :     List[Any]         =		['RoFormerTokenizerFast']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      a__      :     List[str]         =		[
          'ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
          'RoFormerForCausalLM',
          'RoFormerForMaskedLM',
          'RoFormerForMultipleChoice',
          'RoFormerForQuestionAnswering',
          'RoFormerForSequenceClassification',
          'RoFormerForTokenClassification',
          'RoFormerLayer',
          'RoFormerModel',
          'RoFormerPreTrainedModel',
          'load_tf_weights_in_roformer',
      ]


try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      a__      :     List[Any]         =		[
          'TF_ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
          'TFRoFormerForCausalLM',
          'TFRoFormerForMaskedLM',
          'TFRoFormerForMultipleChoice',
          'TFRoFormerForQuestionAnswering',
          'TFRoFormerForSequenceClassification',
          'TFRoFormerForTokenClassification',
          'TFRoFormerLayer',
          'TFRoFormerModel',
          'TFRoFormerPreTrainedModel',
      ]


try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      a__      :     Dict         =		[
          'FLAX_ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
          'FlaxRoFormerForMaskedLM',
          'FlaxRoFormerForMultipleChoice',
          'FlaxRoFormerForQuestionAnswering',
          'FlaxRoFormerForSequenceClassification',
          'FlaxRoFormerForTokenClassification',
          'FlaxRoFormerModel',
          'FlaxRoFormerPreTrainedModel',
      ]


if TYPE_CHECKING:
      from .configuration_roformer import ROFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, RoFormerConfig, RoFormerOnnxConfig
      from .tokenization_roformer import RoFormerTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_roformer_fast import RoFormerTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_roformer import (
                ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                RoFormerForCausalLM,
                RoFormerForMaskedLM,
                RoFormerForMultipleChoice,
                RoFormerForQuestionAnswering,
                RoFormerForSequenceClassification,
                RoFormerForTokenClassification,
                RoFormerLayer,
                RoFormerModel,
                RoFormerPreTrainedModel,
                load_tf_weights_in_roformer,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_roformer import (
                TF_ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFRoFormerForCausalLM,
                TFRoFormerForMaskedLM,
                TFRoFormerForMultipleChoice,
                TFRoFormerForQuestionAnswering,
                TFRoFormerForSequenceClassification,
                TFRoFormerForTokenClassification,
                TFRoFormerLayer,
                TFRoFormerModel,
                TFRoFormerPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_roformer import (
                FLAX_ROFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                FlaxRoFormerForMaskedLM,
                FlaxRoFormerForMultipleChoice,
                FlaxRoFormerForQuestionAnswering,
                FlaxRoFormerForSequenceClassification,
                FlaxRoFormerForTokenClassification,
                FlaxRoFormerModel,
                FlaxRoFormerPreTrainedModel,
            )


else:
      import sys

      a__      :     Union[str, Any]         =		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



