feat(modelcard): give local model files the modelCard of the Hugging Face repo they came from - #114
lab700xdev wants to merge 1 commit into
Conversation
…Face repo they came from A local copy of a Hugging Face model used to get no modelCard, while an hf:// scan of the same repo did. Local scans now look for evidence of the repo (the HF cache layout, or a config.json whose _name_or_path is an org/name repo id), prove it by finding the file's SHA-256 or git blob id in that repo's file listing, and only then attach the repo's card. - No proof, a lookup failure, or more than one repo proving out: no card. - A matched card records aisbom:hf:match (hf-cache or config-name-or-path). - Only the repo id and commit are sent; paths, names and hashes stay local. Path-like or single-name _name_or_path values are never requested. - On by default for CycloneDX 1.7, SPDX 3.0 and score on a directory; --no-hf-lookup, AISBOM_NO_HF_LOOKUP=1 or --offline turn it off. - SPDX 3.0 now links each model only to its own card's datasets. - README privacy section, Action README and air-gapped guide updated.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c519ec516d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for dep in results.get("dependencies", []) | ||
| ], | ||
| "datasets": _card_datasets(results.get("hf_model_card")), | ||
| "datasets": _all_card_datasets(results), |
There was a problem hiding this comment.
Include per-model dataset assignments in the namespace
When the same artifacts and dependencies have different per-model dataset assignments but the same first-seen dataset union—for example, model A changes from [x, y] to [x] while model B changes from [z] to [y, z]—this fingerprint remains identical even though the generated trainedOn relationships differ. Both SPDX documents consequently reuse the same document, package, and relationship IRIs, so importing them into one SPDX/RDF store can conflate distinct relationship versions. Fingerprint each artifact's own _card_datasets(_card_for(...)) list rather than only the union.
Useful? React with 👍 / 👎.
What
A local copy of a Hugging Face model now gets the same
modelCardanhf://scan of its repo produces, when the link can be proven.models--<org>--<name>/snapshots/<commit>/…, which gives the repo and revision), or aconfig.jsonnext to the weights whose_name_or_pathis anorg/namerepo id. File names are never used.lfs.oidin the repo's file listing, or, for small files stored in git, its git blob id must equal anoid. A renamed file still matches. A fine-tune whose config still names its base model does not.hf://card fetch.A matched card carries
aisbom:hf:match(hf-cacheorconfig-name-or-path), so an inferred link can be told apart from anhf://scan.Privacy and opt-out
huggingface.co. The hash comparison happens locally, so paths, file names and hashes are never sent._name_or_paththat is a single name, looks like a path, or names a directory that exists is never requested.scoreon a directory.--no-hf-lookup,AISBOM_NO_HF_LOOKUP=1or--offlineturn it off.Other changes
hf://scans, where every model shares one card).score's model-card and dataset fix hints mention that a local copy in the HF cache also works.Verification
poetry run pytest --cov=aisbom --cov-fail-under=85: 1452 passed, 93.73% coverage.aisbom bypass-scorecard --checkpasses.hf-internal-testing/tiny-random-bert, comparingmainagainst this branch:model.safetensorsvia git blob id,pytorch_model.binvia LFS SHA-256). No field regressions; the only added component key ismodelCard, and it equals thehf://scan's card apart fromaisbom:hf:match.mainapart from serial number and timestamp.config.jsonnaming the repo: matched. Fine-tune with a config naming the base model: no card.aisbom scoreon the cache copy: 50.0 (D) with--no-hf-lookup, 65.0 (C) without.Release note
Local scans of HF-cached models now contact
huggingface.coby default, including in the GitHub Action when the scanned directory has that evidence.