Repository navigation
Conversation
…ta check resolveModel() delegated hf: URIs straight to node-llama-cpp's resolveModelFile(), which checks huggingface.co metadata before the local model cache. On networks where huggingface.co is unreachable, the connect hangs indefinitely and qmd embed/query appear to deadlock at 0% CPU even when the model file is already cached. Short-circuit: for hf: URIs, return the cached file directly when a matching filename exists in the model cache directory; fall back to the existing resolution flow otherwise. Also make loadCpuCompatibleLlama() try a locally built CPU backend (build: auto, gpu off) before falling back to the packaged Metal prebuilt, so machines with a local CPU build get a true CPU path. Validation: Apple M4 Pro / macOS 15.6 / qmd 2.8.3 - before, qmd embed hung forever; after, 70 docs / 252 chunks embedded in ~31s on CPU.
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.
PR draft → tobi/qmd
Title: llm: resolve cached hf: models from local model cache before network metadata check (fixes indefinite hang when huggingface.co is unreachable)
Body
Problem
LlamaCpp.resolveModel()delegateshf:URIs straight to node-llama-cpp'sresolveModelFile(), which performs a network metadata check against huggingface.co before looking at the local model cache. On networks where huggingface.co is unreachable (blocked, with silently dropped packets), the TCP connect has no effective timeout and the call hangs forever at 0% CPU —qmd embed/qmd query/ model loading never proceed even though the model file is already present in the model cache directory (manually downloaded or previously cached).This surfaces as the "embed deadlocks at 0% CPU" family (see #735). On our machine (Apple M4 Pro, macOS 15.6) the deadlock was not Metal-related: with the fix below, a locally built CPU-only backend embeds the full corpus in ~35s, and Metal was never implicated. The same 0%-CPU-idle signature can have different root causes per environment; this patch removes one of them for everyone behind unreachable-HF networks.
Fix
resolveModel(): forhf:URIs, check the model cache directory for a file whose name matches the URI's filename first; if present, return it directly and skip the network resolution entirely. Fall back to the existingresolveModelFile()flow otherwise. (qmd's ownpullModels()already does filename-based cache matching — this applies the same idea to load-time resolution.)Also included: in
loadCpuCompatibleLlama(), when the CPU-only prebuilt is missing, try a locally built CPU backend (build: "auto", gpu off) before falling back to the packaged Metal prebuilt — machines with a local CPU build get a true CPU path instead of an unintended Metal load.Validation
qmd embedhung indefinitely (0% CPU, all threads in cond-wait); after — 70 docs / 252 chunks embedded in ~31-35s on CPU, queries 4-13ms, across 10 real-world Chinese colloquial queries recall@3 improved from 0/10 (BM25) to 7/10 (vector).Notes
Issue #735 comment draft(数据点回帖)
Suggested comment:
Data point from a different environment that may help triage: Apple M4 Pro, macOS 15.6 (not 26.x), qmd 2.8.3 — identical symptom (
qmd embedhangs at 0% CPU after printing the model line, all threads idle in cond-wait). In our case the root cause turned out not to be Metal: it wasresolveModel("hf:…")performing a network metadata check against huggingface.co, which is unreachable from our network and hangs indefinitely without a timeout — even when the model file is already in the local cache. Workarounds that did NOT help here:QMD_FORCE_CPU(no such env in 2.8.3; the correct one isQMD_LLAMA_GPU=false), full Xcode, different node versions, CPU-only local builds — because the hang happened before/independent of backend selection. After short-circuiting hf: resolution to use the local cache file directly (2-line change inLlamaCpp.resolveModel), embed completes fine on a locally built CPU backend (70 docs / 252 chunks in ~35s). Suggestion: consider a fail-fast timeout or cache-first resolution forhf:URIs — it would make the "deadlock" reports easier to triage, since unreachable-HF environments currently mimic the Metal JIT hang exactly.