From 551db26bb75eb203cccdc25603a6a001eed1c795 Mon Sep 17 00:00:00 2001 From: iuyua9 Date: Sat, 16 May 2026 11:49:15 +0800 Subject: [PATCH] fix: recognize root Hugging Face repo IDs (#325) * fix: recognize root Hugging Face repo IDs * fix: propagate invalid HF repo ids * fix: match transformers local path precedence --- src/heretic/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/heretic/utils.py b/src/heretic/utils.py index 27dd697..32f78b7 100644 --- a/src/heretic/utils.py +++ b/src/heretic/utils.py @@ -22,6 +22,7 @@ from datasets import DatasetDict, ReadInstruction, load_dataset, load_from_disk from datasets.config import DATASET_STATE_JSON_FILENAME from datasets.download.download_manager import DownloadMode from datasets.utils.info_utils import VerificationMode +from huggingface_hub.utils import validate_repo_id from optuna import Trial from psutil import Process from questionary import Choice, Style @@ -172,13 +173,13 @@ def format_duration(seconds: float) -> str: def is_hf_path(path: str) -> bool: """Checks whether a path likely refers to a Hugging Face repository.""" - return ( - not path.startswith("/") - and not path.endswith("/") - and path.count("/") == 1 - and "\\" not in path - and not Path(path).exists() - ) + # Match Transformers: existing local paths take precedence over Hub lookup, + # even if the path string is also a valid repository ID. + if Path(path).exists(): + return False + + validate_repo_id(path) + return True @dataclass