'''simple docstring'''

from math import ceil







def      UpperCamelCase_						(					snake_case_       :       str						,		snake_case_       :       Dict      )					->     int:






 '''simple docstring'''

 __lowerCAmelCase											=						list(range(0						,		snake_case_      )      )

 __lowerCAmelCase											=						[item for sublist in list(device_map.values()      ) for item in sublist]

 # Duplicate check
 __lowerCAmelCase											=						[]
 for i in device_map_blocks:
  if device_map_blocks.count(snake_case_      ) > 1 and i not in duplicate_blocks:
   duplicate_blocks.append(snake_case_      )
    # Missing blocks
 __lowerCAmelCase											=						[i for i in blocks if i not in device_map_blocks]
 __lowerCAmelCase											=						[i for i in device_map_blocks if i not in blocks]

 if len(snake_case_      ) != 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(snake_case_      )      )
 if len(snake_case_      ) != 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(snake_case_      )      )
 if len(snake_case_      ) != 0:
  raise ValueError(
      """The device_map contains more attention blocks than this model has. Remove these from the device_map:"""
      + str(snake_case_      )      )







def      UpperCamelCase_						(					snake_case_       :       Tuple						,		snake_case_       :       List[str]      )					->     Dict:






 '''simple docstring'''

 __lowerCAmelCase											=						list(range(snake_case_      )      )
 __lowerCAmelCase											=						int(ceil(n_layers / len(snake_case_      )      )      )
 __lowerCAmelCase											=						[layers[i : i + n_blocks] for i in range(0						,		snake_case_						,		snake_case_      )]

 return dict(zip(snake_case_						,		snake_case_      )      )







'''simple docstring'''

import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast







@dataclass
class 				_lowercase     (				datasets.BuilderConfig			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       Optional[datasets.Features]      	=					None







class 				_lowercase     (				datasets.ArrowBasedBuilder			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       Union[str, Any]      	=					PandasConfig
 def a					(      self   :	Union[str, Any]							)  ->    int:
  return datasets.DatasetInfo(features=self.config.features							)
 def a					(      self   :	Any      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]							)  ->    str:
  if not self.config.data_files:
   raise ValueError(f"""At least one data file must be specified, but got data_files={self.config.data_files}"""							)
  __lowerCAmelCase											=						dl_manager.download_and_extract(self.config.data_files							)
  if isinstance(SCREAMING_SNAKE_CASE__      ,       (str, list, tuple)							):
   __lowerCAmelCase											=						data_files
   if isinstance(SCREAMING_SNAKE_CASE__      ,       SCREAMING_SNAKE_CASE__							):
    __lowerCAmelCase											=						[files]
   # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
   __lowerCAmelCase											=						[dl_manager.iter_files(SCREAMING_SNAKE_CASE__							) for file in files]
   return [datasets.SplitGenerator(name=datasets.Split.TRAIN      ,       gen_kwargs={"""files""": files}							)]
  __lowerCAmelCase											=						[]
  for split_name, files in data_files.items():
   if isinstance(SCREAMING_SNAKE_CASE__      ,       SCREAMING_SNAKE_CASE__							):
    __lowerCAmelCase											=						[files]
   # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
   __lowerCAmelCase											=						[dl_manager.iter_files(SCREAMING_SNAKE_CASE__							) for file in files]
   splits.append(datasets.SplitGenerator(name=SCREAMING_SNAKE_CASE__      ,       gen_kwargs={"""files""": files}							)							)
  return splits
 def a					(      self   :	Any      ,       SCREAMING_SNAKE_CASE__   :	pa.Table							)  ->    pa.Table:
  if self.config.features is not None:
   # more expensive cast to support nested features with keys in a different order
   # allows str <-> int/float or str to Audio for example
   __lowerCAmelCase											=						table_cast(SCREAMING_SNAKE_CASE__      ,       self.config.features.arrow_schema							)
  return pa_table





 def a					(      self   :	Any      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]							)  ->    List[Any]:
  for i, file in enumerate(itertools.chain.from_iterable(SCREAMING_SNAKE_CASE__							)							):
   with open(SCREAMING_SNAKE_CASE__      ,       """rb"""							) as f:
    __lowerCAmelCase											=						pa.Table.from_pandas(pd.read_pickle(SCREAMING_SNAKE_CASE__							)							)
    yield i, self._cast_table(SCREAMING_SNAKE_CASE__							)






