Upload config.py with huggingface_hub
Browse files
config.py
CHANGED
|
@@ -110,6 +110,11 @@ def _hf_revision() -> str | None:
|
|
| 110 |
return rev or None
|
| 111 |
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
@lru_cache(maxsize=8)
|
| 114 |
def _resolve_repo_subdir(local_dir: Path, repo_subdir: str) -> Path:
|
| 115 |
"""Resolve artifact/model subdirs for local dev and HF trust_remote_code.
|
|
@@ -120,6 +125,12 @@ def _resolve_repo_subdir(local_dir: Path, repo_subdir: str) -> Path:
|
|
| 120 |
if local_dir.exists():
|
| 121 |
return local_dir
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
try:
|
| 124 |
from huggingface_hub import snapshot_download
|
| 125 |
except Exception:
|
|
|
|
| 110 |
return rev or None
|
| 111 |
|
| 112 |
|
| 113 |
+
def _is_hf_dynamic_module_runtime() -> bool:
|
| 114 |
+
"""True when executing from HF `trust_remote_code` dynamic module cache."""
|
| 115 |
+
return "transformers_modules" in str(BASE_DIR)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
@lru_cache(maxsize=8)
|
| 119 |
def _resolve_repo_subdir(local_dir: Path, repo_subdir: str) -> Path:
|
| 120 |
"""Resolve artifact/model subdirs for local dev and HF trust_remote_code.
|
|
|
|
| 125 |
if local_dir.exists():
|
| 126 |
return local_dir
|
| 127 |
|
| 128 |
+
# Critical guard: during local/Colab training we should never silently point
|
| 129 |
+
# outputs to a Hub snapshot cache path. Only use Hub fallback when running
|
| 130 |
+
# inside HF dynamic modules (`trust_remote_code` path).
|
| 131 |
+
if not _is_hf_dynamic_module_runtime():
|
| 132 |
+
return local_dir
|
| 133 |
+
|
| 134 |
try:
|
| 135 |
from huggingface_hub import snapshot_download
|
| 136 |
except Exception:
|