|
45 | 45 |
|
46 | 46 |
|
47 | 47 | logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
| 48 | + |
| 49 | + |
| 50 | +def _sanitize_module_name(name: str) -> str: |
| 51 | + """ |
| 52 | + Replace `.` in module names with `_dot_` so that it doesn't |
| 53 | + look like an import path separator. |
| 54 | + """ |
| 55 | + return name.replace(".", "_dot_") |
| 56 | + |
| 57 | + |
48 | 58 | _HF_REMOTE_CODE_LOCK = threading.Lock()
|
49 | 59 |
|
50 | 60 |
|
@@ -358,9 +368,9 @@ def get_cached_module_file(
|
358 | 368 | pretrained_model_name_or_path = str(pretrained_model_name_or_path)
|
359 | 369 | is_local = os.path.isdir(pretrained_model_name_or_path)
|
360 | 370 | if is_local:
|
361 |
| - submodule = os.path.basename(pretrained_model_name_or_path) |
| 371 | + submodule = _sanitize_module_name(os.path.basename(pretrained_model_name_or_path)) |
362 | 372 | else:
|
363 |
| - submodule = pretrained_model_name_or_path.replace("/", os.path.sep) |
| 373 | + submodule = _sanitize_module_name(pretrained_model_name_or_path.replace("/", os.path.sep)) |
364 | 374 | cached_module = try_to_load_from_cache(
|
365 | 375 | pretrained_model_name_or_path, module_file, cache_dir=cache_dir, revision=_commit_hash, repo_type=repo_type
|
366 | 376 | )
|
@@ -395,7 +405,7 @@ def get_cached_module_file(
|
395 | 405 | full_submodule = TRANSFORMERS_DYNAMIC_MODULE_NAME + os.path.sep + submodule
|
396 | 406 | create_dynamic_module(full_submodule)
|
397 | 407 | submodule_path = Path(HF_MODULES_CACHE) / full_submodule
|
398 |
| - if submodule == os.path.basename(pretrained_model_name_or_path): |
| 408 | + if submodule == _sanitize_module_name(os.path.basename(pretrained_model_name_or_path)): |
399 | 409 | # We copy local files to avoid putting too many folders in sys.path. This copy is done when the file is new or
|
400 | 410 | # has changed since last copy.
|
401 | 411 | if not (submodule_path / module_file).exists() or not filecmp.cmp(
|
|
0 commit comments