| 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 | |
| 559 | def evaluation_module_factory( |