





from math import ceil





def 	lowerCAmelCase_					(			__a      ,       __a						)	->						Union[str, Any]:







  """simple docstring"""





  lowerCamelCase__: str         =list(range(0      ,       __a						)						)

  lowerCamelCase__: Dict         =[item for sublist in list(device_map.values()						) for item in sublist]

  # Duplicate check
  lowerCamelCase__: List[str]         =[]
  for i in device_map_blocks:
    if device_map_blocks.count(__a						) > 1 and i not in duplicate_blocks:
      duplicate_blocks.append(__a						)
    # Missing blocks
  lowerCamelCase__: Optional[Any]         =[i for i in blocks if i not in device_map_blocks]
  lowerCamelCase__: Union[str, Any]         =[i for i in device_map_blocks if i not in blocks]

  if len(__a						) != 0:
    raise ValueError(
        "Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."
        " These attention blocks were specified more than once: " + str(__a						)						)
  if len(__a						) != 0:
    raise ValueError(
        "There are attention blocks for this model that are not specified in the device_map. Add these attention "
        "blocks to a device on the device_map: " + str(__a						)						)
  if len(__a						) != 0:
    raise ValueError(
        "The device_map contains more attention blocks than this model has. Remove these from the device_map:"
        + str(__a						)						)






def 	lowerCAmelCase_					(			__a      ,       __a						)	->						Dict:







  """simple docstring"""





  lowerCamelCase__: List[Any]         =list(range(__a						)						)
  lowerCamelCase__: Tuple         =int(ceil(n_layers / len(__a						)						)						)
  lowerCamelCase__: Tuple         =[layers[i : i + n_blocks] for i in range(0      ,       __a      ,       __a						)]

  return dict(zip(__a      ,       __a						)						)



"""simple docstring"""



import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


a       :						int       		=		5_0_0_0_0_0

a		,			a       :						Union[str, Any]       		=		os.path.split(__file__)
a       :						Dict       		=		os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))


@get_duration
def 			_UpperCamelCase						(    _A       ,   **_A   )     ->	Any:





    """simple docstring"""

    _UpperCAmelCase        = dataset.map(**_A   )


@get_duration
def 			_UpperCamelCase						(    _A       ,   **_A   )     ->	Dict:





    """simple docstring"""

    _UpperCAmelCase        = dataset.filter(**_A   )


def 			_UpperCamelCase						(    )     ->	Tuple:





    """simple docstring"""

    _UpperCAmelCase        = {"""num examples""": SPEED_TEST_N_EXAMPLES}
    with tempfile.TemporaryDirectory() as tmp_dir:
        _UpperCAmelCase        = datasets.Features({"""text""": datasets.Value("""string"""   ), """numbers""": datasets.Value("""float32"""   )}   )
        _UpperCAmelCase        = generate_example_dataset(
            os.path.join(_A       ,   """dataset.arrow"""   )       ,   _A       ,   num_examples=_A   )

        _UpperCAmelCase        = transformers.AutoTokenizer.from_pretrained("""bert-base-cased"""       ,   use_fast=_A   )

        def tokenize(_A   ):
            return tokenizer(examples["""text"""]   )

        _UpperCAmelCase        = map(_A   )

        _UpperCAmelCase        = map(_A       ,   batched=_A   )

        _UpperCAmelCase        = map(_A       ,   function=lambda _A   : None       ,   batched=_A   )

        with dataset.formatted_as(type="""numpy"""   ):
            _UpperCAmelCase        = map(_A       ,   function=lambda _A   : None       ,   batched=_A   )

        with dataset.formatted_as(type="""pandas"""   ):
            _UpperCAmelCase        = map(_A       ,   function=lambda _A   : None       ,   batched=_A   )

        with dataset.formatted_as(type="""torch"""       ,   columns="""numbers"""   ):
            _UpperCAmelCase        = map(_A       ,   function=lambda _A   : None       ,   batched=_A   )

        with dataset.formatted_as(type="""tensorflow"""       ,   columns="""numbers"""   ):
            _UpperCAmelCase        = map(_A       ,   function=lambda _A   : None       ,   batched=_A   )

        _UpperCAmelCase        = map(_A       ,   function=_A       ,   batched=_A   )

        _UpperCAmelCase        = filter(_A   )

        # Activate later when tokenizer support batched inputs
        # with dataset.formatted_as(type='numpy'):
        #     times[func.__name__ + " fast-tokenizer batched numpy"] = func(dataset, function=tokenize, batched=True)

    with open(_A       ,   """wb"""   ) as f:
        f.write(json.dumps(_A   ).encode("""utf-8"""   )   )


if __name__ == "__main__":  # useful to run the profiler
 benchmark_map_filter()