Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/huggingface_hub/repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ def model_index_to_eval_results(model_index: list[dict[str, Any]]) -> tuple[str,
```
"""

if not model_index:
raise ValueError("`model_index` must be a non-empty list.")

eval_results = []
for elem in model_index:
name = elem["name"]
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/serialization/_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def load_torch_model(
[`ImportError`](https://docs.python.org/3/library/exceptions.html#ImportError)
If safetensors or torch is not installed when trying to load a .safetensors file or a PyTorch checkpoint respectively.
[`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
If the checkpoint path is invalid or if the checkpoint format cannot be determined.
If the checkpoint format cannot be determined.

Example:
```python
Expand All @@ -437,7 +437,7 @@ def load_torch_model(
checkpoint_path = Path(checkpoint_path)

if not checkpoint_path.exists():
raise ValueError(f"Checkpoint path {checkpoint_path} does not exist")
raise FileNotFoundError(f"Checkpoint path {checkpoint_path} does not exist")
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
# 1. Check if checkpoint is a single file
if checkpoint_path.is_file():
state_dict = load_state_dict_from_file(
Expand Down
4 changes: 4 additions & 0 deletions tests/test_repocard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ def test_model_index_to_eval_results_source_null(self):
assert eval_results[0].source_name is None
assert eval_results[0].source_url is None

def test_model_index_to_eval_results_empty(self):
with pytest.raises(ValueError, match="`model_index` must be a non-empty list."):
model_index_to_eval_results([])

def test_card_data_requires_model_name_for_eval_results(self):

with pytest.raises(ValueError, match="`eval_results` requires `model_name` to be set."):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def test_load_state_dict_missing_file(safe_serialization):

def test_load_torch_model_directory_does_not_exist():
"""Test proper error handling when directory does not contain a valid checkpoint."""
with pytest.raises(ValueError, match="Checkpoint path does_not_exist does not exist"):
with pytest.raises(FileNotFoundError, match="Checkpoint path does_not_exist does not exist"):
load_torch_model(Mock(), "does_not_exist")


Expand Down
Loading