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

Method get_module

src/evaluate/loading.py:528–556  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

526 assert self.name.count("/") == 0
527
528 def get_module(self) -> ImportableModule:
529 dynamic_modules_path = self.dynamic_modules_path if self.dynamic_modules_path else init_dynamic_modules()
530 importable_directory_path = os.path.join(dynamic_modules_path, self.module_type, self.name)
531 hashes = (
532 [h for h in os.listdir(importable_directory_path) if len(h) == 64]
533 if os.path.isdir(importable_directory_path)
534 else None
535 )
536 if not hashes:
537 raise FileNotFoundError(f"Metric {self.name} is not cached in {dynamic_modules_path}")
538 # get most recent
539
540 def _get_modification_time(module_hash):
541 return (
542 (Path(importable_directory_path) / module_hash / (self.name.split("--")[-1] + ".py")).stat().st_mtime
543 )
544
545 hash = sorted(hashes, key=_get_modification_time)[-1]
546 logger.warning(
547 f"Using the latest cached version of the module from {os.path.join(importable_directory_path, hash)} "
548 f"(last modified on {time.ctime(_get_modification_time(hash))}) since it "
549 f"couldn't be found locally at {self.name}, or remotely on the Hugging Face Hub."
550 )
551 # make the new module to be noticed by the import system
552 module_path = ".".join(
553 [os.path.basename(dynamic_modules_path), self.module_type, self.name, hash, self.name.split("--")[-1]]
554 )
555 importlib.invalidate_caches()
556 return ImportableModule(module_path, hash)
557
558
559def evaluation_module_factory(

Callers 1

Calls 2

init_dynamic_modulesFunction · 0.85
ImportableModuleClass · 0.85

Tested by 1