Skip to content

Commit fb41f25

Browse files
authored
[bugfix] saving model without model.name_or_path (#2061)
Summary: the way models were saved assumed that model.name_or_path was populated but this is not always the case. I think that if you generate a model and then immediately quantize it, you'll run into this problem. This PR relaxes this assumption so that the model can be saved. TEST PLAN: ran https://gist.github.com/HDCharles/78c55da388076aa046ee893edfbd9df5 previously you'd get: huggingface_hub.errors.HFValidationError: Repo id must use alphanumeric chars, '-', '_' or '.'. The name cannot start or end with '-' or '.' and the maximum length is 96: ''. now: no error --------- Signed-off-by: HDCharles <charlesdavidhernandez@gmail.com>
1 parent db0b68d commit fb41f25

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/llmcompressor/pytorch/model_load/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ 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+
if hasattr(config, "_name_or_path") and len(config._name_or_path.strip()) > 0:
148148
import os
149149
import shutil
150150

src/llmcompressor/transformers/utils/helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def infer_recipe_from_model_path(model_path: Union[str, Path]) -> Optional[str]:
5757
- Hugging face model ID
5858
:return: The path to the recipe file if found, None otherwise.
5959
"""
60-
model_path = model_path.as_posix() if isinstance(model_path, Path) else model_path
60+
model_path = (
61+
model_path.as_posix() if isinstance(model_path, Path) else model_path.strip()
62+
)
63+
if model_path == "":
64+
logger.debug("got path_or_name=<empty string>" "unable to find recipe")
65+
return None
6166

6267
if os.path.isdir(model_path) or os.path.isfile(model_path):
6368
# Model path is a local path to the model directory or file

0 commit comments

Comments
 (0)