feat: resolve HF Hub cache layout in model directory scanning#466
Open
AlexWorland wants to merge 6 commits intojundot:mainfrom
Open
feat: resolve HF Hub cache layout in model directory scanning#466AlexWorland wants to merge 6 commits intojundot:mainfrom
AlexWorland wants to merge 6 commits intojundot:mainfrom
Conversation
Resolve models stored in HuggingFace Hub's cache format (models--Org--Name/snapshots/<hash>/) so they appear in both the model discovery engine and the dashboard model list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
13 new tests covering _resolve_hf_cache_entry() edge cases and discover_models() integration with HF cache directory layouts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove redundant is_file() check before read_text() — the try/except OSError already handles missing refs/main. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Match existing test file conventions — no other test class uses inline section dividers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Deduplicate the bare HF cache directory setup (entry + refs + snapshot) into a shared helper. _make_hf_cache_model now calls through to it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Models downloaded via
huggingface-cliorhuggingface_hubuse an indirect cache layout (models--Org--Name/refs/main→ commit hash →snapshots/<hash>/) instead of a flat directory. When a user adds their HF cache directory (e.g.,~/.cache/huggingface/hub) to model directories in settings, the scanner didn't understand this indirection and found nothing.This change teaches the existing two-level scanner to resolve HF Hub cache entries to their active snapshot. No directories are scanned automatically — users opt in by adding their HF cache path to model directories. The resolved snapshot flows through the same
_is_model_dir()→_register_model()pipeline as all other models.Changes
omlx/model_discovery.py_resolve_hf_cache_entry()— resolvesmodels--Org--Name/tosnapshots/<hash>/viarefs/main; integrate intodiscover_models()between Level 1 and Level 2 checksomlx/admin/routes.pylist_hf_models()dashboard endpoint; extract duplicated dedupe/size/append logic into_add_model()helpertests/test_model_discovery.py_resolve_hf_cache_entry()edge cases, 7 integration tests fordiscover_models()with HF cache layoutsHow it works
Existing flat and org-nested layouts are completely unaffected — the HF cache check only fires for directories matching the
models--*--*naming pattern, and thecontinueensures it doesn't fall through to the org scan.Testing
New test coverage:
_resolve_hf_cache_entry(): valid entry, regular dir, missing org separator, missing refs/main, missing snapshot, whitespace strippingdiscover_models(): single/multiple HF cache models, model_path points to snapshot, missing config.json skipped, mixed flat+HF cache, mixed org+HF cache, no fallthrough to org scan