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

Method _get_all_cache_files

src/evaluate/module.py:310–343  ·  view source on GitHub ↗

Get a lock on all the cache files in a distributed setup. We wait for timeout second to let all the distributed node finish their tasks (default is 100 seconds).

(self)

Source from the content-addressed store, hash-verified

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.
312 We wait for timeout second to let all the distributed node finish their tasks (default is 100 seconds).
313 """
314 if self.num_process == 1:
315 if self.cache_file_name is None:
316 raise ValueError(
317 "Evaluation module cache file doesn't exist. Please make sure that you call `add` or `add_batch` "
318 "at least once before calling `compute`."
319 )
320 file_paths = [self.cache_file_name]
321 else:
322 file_paths = [
323 os.path.join(self.data_dir, f"{self.experiment_id}-{self.num_process}-{process_id}.arrow")
324 for process_id in range(self.num_process)
325 ]
326
327 # Let's acquire a lock on each process files to be sure they are finished writing
328 filelocks = []
329 for process_id, file_path in enumerate(file_paths):
330 if process_id == 0: # process 0 already has its lock file
331 filelocks.append(self.filelock)
332 else:
333 filelock = FileLock(file_path + ".lock")
334 try:
335 filelock.acquire(timeout=self.timeout)
336 except Timeout:
337 raise ValueError(
338 f"Cannot acquire lock on cached file {file_path} for process {process_id}."
339 ) from None
340 else:
341 filelocks.append(filelock)
342
343 return file_paths, filelocks
344
345 def _check_all_processes_locks(self):
346 expected_lock_file_names = [

Callers 1

_finalizeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected