Skip to content

Commit 861614b

Browse files
committed
[bugfix] saving model without model.name_or_path
Summary: the way models were saved assumed that model.name_or_path was populated but this is not always the case. This PR relaxes this assumption so that the model can be saved. Signed-off-by: HDCharles <charlesdavidhernandez@gmail.com>
1 parent 99e231e commit 861614b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/llmcompressor/pytorch/model_load/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def load_safetensors_state_dict(file_path: str) -> Dict[str, torch.Tensor]:
144144
def copy_python_files_from_model_cache(model, save_path: str):
145145
config = model.config
146146
cache_path = None
147-
if hasattr(config, "_name_or_path"):
147+
print("GGG", config._name_or_path)
148+
if hasattr(config, "_name_or_path") and len(config._name_or_path)>0:
148149
import os
149150
import shutil
150151

src/llmcompressor/transformers/utils/helpers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
hf_hub_download,
1515
try_to_load_from_cache,
1616
)
17+
from huggingface_hub.errors import HFValidationError
1718
from loguru import logger
1819
from transformers import AutoConfig
1920
from transformers.trainer_utils import get_last_checkpoint
@@ -96,7 +97,7 @@ def infer_recipe_from_model_path(model_path: Union[str, Path]) -> Optional[str]:
9697
:return: The path to the recipe file if found, None otherwise.
9798
"""
9899
model_path = model_path.as_posix() if isinstance(model_path, Path) else model_path
99-
100+
print("DD", model_path, os.path.isdir(model_path) , os.path.isfile(model_path))
100101
if os.path.isdir(model_path) or os.path.isfile(model_path):
101102
# Model path is a local path to the model directory or file
102103
model_path = (
@@ -111,10 +112,14 @@ def infer_recipe_from_model_path(model_path: Union[str, Path]) -> Optional[str]:
111112
return None
112113

113114
# Try to resolve HF model ID to cached location first
114-
cached_recipe = try_to_load_from_cache(
115-
repo_id=model_path,
116-
filename=RECIPE_FILE_NAME,
117-
)
115+
cached_recipe = None
116+
try:
117+
cached_recipe = try_to_load_from_cache(
118+
repo_id=model_path,
119+
filename=RECIPE_FILE_NAME,
120+
)
121+
except HFValidationError as e:
122+
logger.info(f"unable to get recipe from hf_hub, raised:\n{e}")
118123

119124
if cached_recipe and cached_recipe is not _CACHED_NO_EXIST:
120125
# Recipe found in cached model

0 commit comments

Comments
 (0)