Skip to content

Commit 6400391

Browse files
committed
py: let users add full base model and dataset to model_card
1 parent d32c74d commit 6400391

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

gguf-py/gguf/metadata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ def use_array_model_card_metadata(metadata_key: str, model_card_key: str):
400400
if org_component is not None and model_full_name_component is not None:
401401
base_model["repo_url"] = f"https://huggingface.co/{org_component}/{model_full_name_component}"
402402

403+
elif isinstance(model_id, dict):
404+
base_model = model_id
403405
else:
404406
logger.error(f"base model entry '{str(model_id)}' not in a known format")
405407
metadata.base_models.append(base_model)
@@ -454,6 +456,8 @@ def use_array_model_card_metadata(metadata_key: str, model_card_key: str):
454456
if org_component is not None and dataset_name_component is not None:
455457
dataset["repo_url"] = f"https://huggingface.co/{org_component}/{dataset_name_component}"
456458

459+
elif isinstance(dataset_id, dict):
460+
dataset = dataset_id
457461
else:
458462
logger.error(f"dataset entry '{str(dataset_id)}' not in a known format")
459463
metadata.datasets.append(dataset)

gguf-py/tests/test_metadata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ def test_apply_metadata_heuristic_from_model_card(self):
197197
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
198198
self.assertEqual(got, expect)
199199

200+
# Base Model spec is given directly
201+
model_card = {'base_models': [{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}]}
202+
expect = gguf.Metadata(base_models=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
203+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
204+
self.assertEqual(got, expect)
205+
200206
# Dataset spec is inferred from model id
201207
model_card = {'datasets': 'teknium/OpenHermes-2.5'}
202208
expect = gguf.Metadata(datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
@@ -209,6 +215,12 @@ def test_apply_metadata_heuristic_from_model_card(self):
209215
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
210216
self.assertEqual(got, expect)
211217

218+
# Dataset spec is given directly
219+
model_card = {'datasets': [{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}]}
220+
expect = gguf.Metadata(datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
221+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
222+
self.assertEqual(got, expect)
223+
212224
def test_apply_metadata_heuristic_from_hf_parameters(self):
213225
hf_params = {"_name_or_path": "./hermes-2-pro-llama-3-8b-DPO"}
214226
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card=None, hf_params=hf_params, model_path=None)

0 commit comments

Comments
 (0)