Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def from_pretrained(
_maybe_register_remote_code_model(model_id, revision=revision, token=token, cache_dir=cache_dir)

_export = export
model_dir = model_id
try:
if local_files_only:
object_id = model_id.replace("/", "--")
Expand All @@ -625,8 +626,6 @@ def from_pretrained(
with open(refs_file) as f:
revision = f.read()
model_dir = os.path.join(cached_model_dir, "snapshots", revision)
else:
model_dir = model_id

ov_files = _find_files_matching_pattern(
model_dir,
Expand Down Expand Up @@ -654,7 +653,7 @@ def from_pretrained(
)

return super().from_pretrained(
model_id,
model_dir,
export=_export,
force_download=force_download,
token=token,
Expand Down
11 changes: 5 additions & 6 deletions optimum/intel/openvino/modeling_open_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def from_pretrained(
local_files_only = True

_export = export
model_dir = model_id
try:
if local_files_only:
object_id = model_id.replace("/", "--")
Expand All @@ -160,8 +161,6 @@ def from_pretrained(
with open(refs_file) as f:
revision = f.read()
model_dir = os.path.join(cached_model_dir, "snapshots", revision)
else:
model_dir = model_id

ov_files = _find_files_matching_pattern(
model_dir,
Expand All @@ -188,10 +187,10 @@ def from_pretrained(
f"Could not infer whether the model was already converted or not to the OpenVINO IR, keeping `export={export}`.\n{exception}"
)

if isinstance(model_id, Path):
model_id = model_id.as_posix()
if isinstance(model_dir, Path):
model_dir = model_dir.as_posix()

config_path = config if isinstance(config, (str, os.PathLike)) else model_id
config_path = config if isinstance(config, (str, os.PathLike)) else model_dir
config = cls._load_config(
config_path,
revision=revision,
Expand All @@ -205,7 +204,7 @@ def from_pretrained(

from_pretrained_method = cls._export if _export else cls._from_pretrained
return from_pretrained_method(
model_id=model_id,
model_id=model_dir,
config=config,
revision=revision,
cache_dir=cache_dir,
Expand Down
12 changes: 11 additions & 1 deletion optimum/intel/utils/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import torch
from huggingface_hub import HfApi, get_token, hf_hub_download
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
from huggingface_hub.errors import OfflineModeIsEnabled
from huggingface_hub.hf_api import file_exists
from transformers import CLIPConfig, PretrainedConfig, PreTrainedModel

Expand Down Expand Up @@ -135,7 +136,16 @@ def _find_files_matching_pattern(
files_ = [p for p in files_ if re.search(pattern, str(p))]
files.extend(files_)
else:
repo_files = map(Path, HfApi().list_repo_files(model_name_or_path, revision=revision, token=token))
hf_api = HfApi()
try:
repo_files = map(Path, hf_api.list_repo_files(model_name_or_path, revision=revision, token=token))
except (ConnectionError, OfflineModeIsEnabled):
snapshot_path = hf_api.snapshot_download(repo_id=str(model_name_or_path), revision=revision, token=token)
repo_files = [
Path(os.path.relpath(os.path.join(dirpath, file), snapshot_path))
for dirpath, _, filenames in os.walk(snapshot_path)
for file in filenames
]
files = [Path(p) for p in repo_files if re.match(pattern, str(p)) and str(p.parent) in subfolders]

return files
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"optimum~=2.3.0",
"transformers>=4.51,<5.6",
"setuptools",
"huggingface-hub>=0.23.2,<1.22",
"huggingface-hub>=0.23.2,<2.0",
"nncf>=3.3.0",
"openvino>=2026.0",
"openvino-tokenizers>=2026.0",
Expand Down
Loading