MCPcopy Create free account
hub / github.com/huggingface/evaluate / _create_cache_file

Method _create_cache_file

src/evaluate/module.py:277–308  ·  view source on GitHub ↗

Create a new cache file. If the default cache file is used, we generated a new hash.

(self, timeout=1)

Source from the content-addressed store, hash-verified

275 return builder_data_dir
276
277 def _create_cache_file(self, timeout=1) -> Tuple[str, FileLock]:
278 """Create a new cache file. If the default cache file is used, we generated a new hash."""
279 file_path = os.path.join(self.data_dir, f"{self.experiment_id}-{self.num_process}-{self.process_id}.arrow")
280 filelock = None
281 for i in range(self.max_concurrent_cache_files):
282 filelock = FileLock(file_path + ".lock")
283 try:
284 filelock.acquire(timeout=timeout)
285 except Timeout:
286 # If we have reached the max number of attempts or we are not allow to find a free name (distributed setup)
287 # We raise an error
288 if self.num_process != 1:
289 raise ValueError(
290 f"Error in _create_cache_file: another evaluation module instance is already using the local cache file at {file_path}. "
291 f"Please specify an experiment_id (currently: {self.experiment_id}) to avoid collision "
292 f"between distributed evaluation module instances."
293 ) from None
294 if i == self.max_concurrent_cache_files - 1:
295 raise ValueError(
296 f"Cannot acquire lock, too many evaluation module instance are operating concurrently on this file system."
297 f"You should set a larger value of max_concurrent_cache_files when creating the evaluation module "
298 f"(current value is {self.max_concurrent_cache_files})."
299 ) from None
300 # In other cases (allow to find new file name + not yet at max num of attempts) we can try to sample a new hashing name.
301 file_uuid = str(uuid.uuid4())
302 file_path = os.path.join(
303 self.data_dir, f"{self.experiment_id}-{file_uuid}-{self.num_process}-{self.process_id}.arrow"
304 )
305 else:
306 break
307
308 return file_path, filelock
309
310 def _get_all_cache_files(self) -> Tuple[List[str], List[FileLock]]:
311 """Get a lock on all the cache files in a distributed setup.

Callers 1

_init_writerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected