Skip to content

fix(sdk): reacquire HTP sessions on all devices, not just NPU - #1289

Merged
Mengsheng Wu (mengshengwu) merged 1 commit into
mainfrom
fix/llama-cpp-htp-reacquire
Aug 6, 2026
Merged

fix(sdk): reacquire HTP sessions on all devices, not just NPU#1289
Mengsheng Wu (mengshengwu) merged 1 commit into
mainfrom
fix/llama-cpp-htp-reacquire

Conversation

@mengshengwu

@mengshengwu Mengsheng Wu (mengshengwu) commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • test-sdk-qdc has been failing on all three legs since v0.3.18-alpha.2 with Windows fatal exception: access violation in geniex_llm_create / geniex_vlm_create.
  • Root cause: SessionGuard::release_if_last releases the shared HTP sessions on the last llama.cpp destructor unconditionally, but the reacquire hook in LlamaLlm::create / LlamaVlm::create was gated to device == Device::NPU. Any load walks the ggml registry's device list, so the next llama_model_load_from_file — even on cpu / gpu — dereferences the stale HTP session pointer at offset 0x18.
  • Fix: gate the reacquire on htp::htp_backend_present() instead, matching how mark_htp decides whether to participate in the shared refcount.

Test plan

  • Local repeat-load repro on Windows-on-Snapdragon (three back-to-back cpu creates + destroys succeed; prior build crashed on the second create).
  • pytest tests/plugins/llama_cpp/test_llama_cpp_llm.py -k "generate_stream or quality_keywords or multi_turn_recalls or ngram_simple" on the same host — 15 / 16 pass (only the pre-existing Paris-npu early-stop assertion remains, unrelated to the HTP session dance).
  • test-sdk-qdc on this PR — pending CI.

Any llama.cpp load walks the ggml registry's device list, so a stale
HTP session pointer left by the last SessionGuard destruction crashes
the load even when the current target is cpu / gpu. Symmetrize the
gate: reacquire whenever the HTP backend is registered, regardless
of the current device.

Signed-off-by: Mengsheng Wu <mengshengwu@outlook.com>
@mengshengwu
Mengsheng Wu (mengshengwu) merged commit 93aa49d into main Aug 6, 2026
38 of 41 checks passed
@mengshengwu
Mengsheng Wu (mengshengwu) deleted the fix/llama-cpp-htp-reacquire branch August 6, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant