Skip to content

Studio: show HF-cache-layout models from registered scan folders in the chat picker - #12258

Open
VTplus wants to merge 17 commits into
unslothai:mainfrom
VTplus:studio-scan-folder-chat-picker
Open

VTplus wants to merge 17 commits into
unslothai:mainfrom
VTplus:studio-scan-folder-chat-picker

Conversation

@VTplus

@VTplus VTplus commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Addresses the scan-folder variant of #7676 and complements #7680: genuine cache rows stay hf_cache (the visibility this PR adds), while a physically separate scan-folder copy keeps its actual custom-folder ownership. Same use case (custom scan folders) as #12253/#12254 — that change loads a selected model from the folder without re-downloading it; this one makes the folder's models selectable in the chat picker in the first place.

What

Registered custom-folder scans now distinguish a real Hugging Face cache from a physically separate repository copy that merely uses the same directory layout.

_collect_models_from_default_sources passes the known active, legacy, default, and previous cache roots to _promote_to_custom_source. A scanned hf_cache row keeps that source only when its resolved path is the same as or below one of those roots. Otherwise it becomes custom, its cache-only model_id and active_cache fields are cleared, and its inventory id is rebuilt from the physical custom path.

The picker itself is unchanged: it already accepts custom rows from /api/hub/local.

Why

A complete repository copied into a registered scan folder can retain the Hugging Face models--org--name/snapshots/<revision> layout. The scanner correctly recognizes that layout, but the previous promotion step treated the layout alone as proof that the row belonged to a configured cache. The chat picker intentionally excludes hf_cache rows, so the model disappeared even though Model Hub and the local inventory could see it.

Scope / guards

  • Only rows returned from a registered custom-folder scan are reclassified.
  • A model physically inside an active, legacy, default, or known previous Hugging Face cache remains hf_cache, including when that cache is also registered as a scan folder.
  • A real cache entry and a physically separate scan-folder copy remain distinct inventory rows.
  • Ollama and Hermes rows retain their existing source labels.
  • The physical model path, format, variant, partial state, load id, and existing capability classification are preserved.
  • Path containment uses the existing real-path, case-normalized path_is_same_or_child helper, which returns False on path-resolution errors.
  • No frontend source filter, legacy /api/models/local or /v1/models route, download path, resolver, or inference behavior is changed.

Tests

  • studio/backend/hub/tests/test_model_services.py: 9 focused cases covering HF-cache-layout promotion, a configured cache registered as a scan folder, separate physical copies, preserved Ollama/Hermes ownership, and preserved chat-capability classification.
  • tests/studio/test_model_picker_contracts.py: 3 focused contracts confirming that the visible picker reads /api/hub/local, accepts custom, excludes hf_cache, and still requires chat capability.
  • Focused result: 12 passed.
  • Broader Hub service run on Windows: 302 passed, 2 skipped. Ten additional tests failed during host-specific setup: one requires an undecodable filename unsupported by this Windows filesystem, and nine require symbolic-link privileges unavailable to the test process. None exposed an assertion failure in the changed behavior.

The rebuilt Studio backend reports healthy, and its live inventory returns the reproduced gpt-oss-20b-GGUF row as custom, chat-capable, and text-generation.

Known limitations (deliberate)

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that _promote_to_custom_source treated the HF directory layout alone as cache ownership, which hid scan-folder copies from the chat picker. Will get this reviewed.

VTplus added 2 commits October 2, 2026 21:06
# Conflicts:
#	studio/backend/hub/services/models/local_inventory.py
#	studio/backend/hub/tests/test_custom_gguf_discovery.py

@chrikrah chrikrah left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VTplus I would merge this. On a CPU-only Linux box, reverting only the production guard takes the suite from 5 red to 9: the three registered parametrisations of test_local_inventory_lists_a_registered_hf_home_as_custom, whose expectation you flipped, and test_local_inventory_keeps_both_rows_when_the_repo_is_cached_and_parked. Your two cache-preserving tests hold on both sides, so the suite discriminates in both directions.

$ cd studio/backend && python -m pytest hub/tests/test_model_services.py hub/tests/test_custom_gguf_discovery.py -q --timeout=330
5 failed, 365 passed, 1 skipped in 27.57s
# baseline 77b02960, same command: 5 failed, 362 passed, 1 skipped
# the same 5 fail on both sides and predate this branch: the SimpleNamespace stub at
# hub/tests/test_model_services.py:183 has no .source, which utils/hf_cache_settings.py:445 reads
# head with only the _promote_to_custom_source guard reverted, tests kept:
9 failed, 361 passed, 1 skipped
$ cd "$(git rev-parse --show-toplevel)" && python -m pytest tests/studio/test_model_picker_contracts.py -q   ->  202 passed
$ python -m pytest studio/backend/tests/test_legacy_ollama_source.py studio/backend/tests/test_ollama_manifest_load_resolution.py -q   ->  32 passed
$ ruff 0.15.18 (the .pre-commit-config.yaml pin) check, 6 changed files  ->  All checks passed!
# not run: the GPU and live-model paths, and the Windows casing case, no hardware for either

path_is_same_or_child compares os.path.realpath and os.path.normcase, which is the same helper the allowed-roots guard at local_inventory.py:622 uses, so a symlinked or differently-cased cache root still reads as the cache.

The "active_cache": None line looks redundant beside common.py:847, which nulls that field for every source but hf_cache, and it is not, because model_copy(update = ...) bypasses that builder and would leave the promoted row as the one custom row carrying a non-null value. No test currently separates the two, since both preference sites compare active_cache is True.

@danielhanchen the one path I could not exercise is the Windows casing branch. Say the word and I will run it against a real cache on hardware you name.

@VTplus

VTplus commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review @chrikrah

This PR was developed and tested on a Windows machine.

Re-tested at the pushed head (d5d146b) after merging current main:

the discovery suite passes there (35 passed, including the _winapi.CreateJunction two-aliases test, which also exercises the _scan_root physical-identity dedupe), and every Windows run exercises path_is_same_or_child's normcase branch natively.
The only local skips are the symlink-creation tests (no SeCreateSymbolicLinkPrivilege outside dev mode on this box), which Linux CI covers.

(The same change also applies and passes on top of current main (124e89a), run as a patch: discovery 35 passed, contracts 202 passed.)

One behavior note for the record: parked copies used to show a delete button, but that delete never resolved scan-folder copies (the cache delete only walks configured HF cache roots), so the relabeling removes a dead affordance rather than a working one. Making delete actually work for scan-folder copies could be a follow-up if there's interest.

VTplus added 4 commits October 6, 2026 23:01
…at-picker

# Conflicts:
#	studio/backend/hub/services/models/local_inventory.py
…icker - sync branch with upstream before re-cutting the patch

Upstream had evolved hub/services/models/local_inventory.py and tests/studio/test_model_picker_contracts.py since the last sync; the three-way merge takes both sides without conflicts.
…icker - sync branch with upstream before re-cutting the patch

182 upstream commit(s) since the branch base; see git log for the range.
…icker - sync branch with upstream before re-cutting the patch

125 upstream commit(s) since the branch base; see git log for the range.
…icker - sync branch with upstream before re-cutting the patch

165 upstream commit(s) since the branch base; see git log for the range.
…icker - sync branch with upstream

778 upstream commit(s) since the branch base; see git log for the range.
…icker - sync branch with upstream

554 upstream commit(s) since the branch base; see git log for the range.
Pin the cache-only fields on promoted scan-folder rows, cover an oMLX cache root as a real cache root, and keep the legacy-path comment true for this branch's code.
…icker - sync branch with upstream

49 upstream commit(s) since the branch base; see git log for the range.
@VTplus

VTplus commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated the branch.
The fix addresses models stored in registered scan folders outside the configured Hugging Face caches but using the same directory layout: they appear in Model Hub but are missing from the chat model picker.

Together, #12258, #12803, and #13343 improve support for complete model copies stored in registered Custom Folders.

…icker - sync branch with upstream

664 upstream commit(s) since the branch base; see git log for the range.
…icker - sync branch with upstream

1046 upstream commit(s) since the branch base; see git log for the range.
danielhanchen added a commit that referenced this pull request Nov 18, 2026
)

## Skip interpreter teardown in the DDP trainable-embeddings worker


`tests/test_ddp_find_unused_default.py::test_trainable_embeddings_train_under_ddp_reentrant_checkpointing`
has hung on `Repo tests (CPU, rest-2)` twice: on #12258, and on #18220,
whose base is current `main`.

```
E   Failed: ['.../tests/_ddp_trainable_embeddings_worker.py', '.../ddp'] hung past 150s:
E   [Gloo] Rank 0 is connected to 1 peer ranks. ...
E   RANK_OK find_unused=FalseRANK_OK find_unused=False
```

Both ranks had finished. They printed `RANK_OK` after writing their
results, and then the processes never exited. Locally the whole test
takes about 12 s.

### Cause

After `RANK_OK`, `tests/_ddp_trainable_embeddings_worker.py` calls
`dist.destroy_process_group()` and returns to normal interpreter
teardown. The repo's other gloo workers do not do that.
`tests/test_tp_native_gloo.py`, `test_tp_host_input_embedding_gloo.py`,
`test_sharded_load_bnb4_gloo.py`, the `pp_*_gloo` workers and others
all:

- barrier before tearing the group down, because rank 0 hosts the
TCPStore;
- call `os._exit(0)` once results are saved, because interpreter
teardown can wedge or abort on a gloo C++ thread after the work is done.

This worker predates that pattern. That is the failure seen here: the
run is finished, but the process never exits.

I could not trigger the CI hang itself: 48 local torchrun launches, 8 in
parallel, all exited 0. So the hang is shown with an injected teardown
wedge (see Verification).

### Fix

On the distributed path, after `RANK_OK`, the worker now does what the
other gloo workers do:

- `dist.barrier()`, then `dist.destroy_process_group()`;
- flush stdout and stderr, then `os._exit(0)`.

Nothing before `RANK_OK` changes. That includes the training steps, the
result files and the single-process reference run. The test's assertions
are unchanged, and a rank that fails before `RANK_OK` still exits
non-zero.

### Verification

- `tests/test_ddp_find_unused_default.py`: 63 passed.
- Sabotage check: after `RANK_OK` on the distributed path, I injected a
thread that never ends, standing in for a teardown thread that wedges.
- `main`: `hung past 150s` with both `RANK_OK` lines printed, which is
the CI signature.
  - This change: the test passes in 10.8 s.
- ruff is clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants