Unverified Commit ed81d5ed authored by Ajay Anubolu's avatar Ajay Anubolu Committed by GitHub
Browse files

[Bugfix] Fix RunAI streamer crash with S3-hosted model paths (#35976)


Signed-off-by: default avatarAjAnubolu <anuboluajay@gmail.com>
Co-authored-by: default avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 3c23ac84
...@@ -220,6 +220,37 @@ def get_model_path(model: str | Path, revision: str | None = None): ...@@ -220,6 +220,37 @@ def get_model_path(model: str | Path, revision: str | None = None):
return snapshot_download(repo_id=model, **common_kwargs) return snapshot_download(repo_id=model, **common_kwargs)
def _try_download_from_hf_hub(
model: str | Path, file_name: str, revision: str | None
) -> Path | None:
"""Try to download a file from HuggingFace Hub.
Returns the local path on success, None on failure.
Skips download if model is a local directory.
"""
if Path(model).is_dir():
return None
try:
return Path(hf_hub_download(model, file_name, revision=revision))
except huggingface_hub.errors.OfflineModeIsEnabled:
return None
except (
RepositoryNotFoundError,
RevisionNotFoundError,
EntryNotFoundError,
LocalEntryNotFoundError,
) as e:
logger.debug("File or repository not found in hf_hub_download:", exc_info=e)
return None
except HfHubHTTPError as e:
logger.warning(
"Cannot connect to Hugging Face Hub. Skipping file download for '%s':",
file_name,
exc_info=e,
)
return None
def get_hf_file_bytes( def get_hf_file_bytes(
file_name: str, model: str | Path, revision: str | None = "main" file_name: str, model: str | Path, revision: str | None = "main"
) -> bytes | None: ) -> bytes | None:
...@@ -227,8 +258,7 @@ def get_hf_file_bytes( ...@@ -227,8 +258,7 @@ def get_hf_file_bytes(
file_path = try_get_local_file(model=model, file_name=file_name, revision=revision) file_path = try_get_local_file(model=model, file_name=file_name, revision=revision)
if file_path is None: if file_path is None:
hf_hub_file = hf_hub_download(model, file_name, revision=revision) file_path = _try_download_from_hf_hub(model, file_name, revision)
file_path = Path(hf_hub_file)
if file_path is not None and file_path.is_file(): if file_path is not None and file_path.is_file():
with open(file_path, "rb") as file: with open(file_path, "rb") as file:
...@@ -275,26 +305,7 @@ def get_hf_file_to_dict( ...@@ -275,26 +305,7 @@ def get_hf_file_to_dict(
file_path = try_get_local_file(model=model, file_name=file_name, revision=revision) file_path = try_get_local_file(model=model, file_name=file_name, revision=revision)
if file_path is None: if file_path is None:
try: file_path = _try_download_from_hf_hub(model, file_name, revision)
hf_hub_file = hf_hub_download(model, file_name, revision=revision)
except huggingface_hub.errors.OfflineModeIsEnabled:
return None
except (
RepositoryNotFoundError,
RevisionNotFoundError,
EntryNotFoundError,
LocalEntryNotFoundError,
) as e:
logger.debug("File or repository not found in hf_hub_download:", exc_info=e)
return None
except HfHubHTTPError as e:
logger.warning(
"Cannot connect to Hugging Face Hub. Skipping file download for '%s':",
file_name,
exc_info=e,
)
return None
file_path = Path(hf_hub_file)
if file_path is not None and file_path.is_file(): if file_path is not None and file_path.is_file():
with open(file_path) as file: with open(file_path) as file:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment