Repository navigation
Serialize MTP runs per session (fix cancel race), release v0.8.70 - #127
Merged
Merged
Conversation
Cancelling an MTP stream is unacknowledged: the consumer returns while the cancelled loop can still be inside a target or draft decode. The next generate/stream on the same session then decoded into the same two contexts, aborting the VM (GGML_ASSERT(logits != nullptr) in 4 of 7 runs at 9daa0aa22). generate_mtp_tokens now holds a per-session mutex for its whole run, so a second call waits, at most one draft-and-verify iteration after a cancel. The known-broken :mtp_cancel test moves into :mtp and also compares the greedy output after three cancelled streams. Without the lock it aborts 5/5; with it, 10/10 of the old test and 5/5 of the :mtp module pass.
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.
Fixes the
:mtp_cancelrace and bumps the version to v0.8.70. llama.cpp stays at9daa0aa22.Problem
Cancelling an MTP stream only sets a flag; nothing confirms the loop has stopped.
Generator.stop/1returns while the cancelledgenerate_mtp_tokensloop can still be inside a target or draft decode. Agenerate/3/stream/3started right then on the same%MTP{}session decoded into the same two contexts at the same time. At9daa0aa22that aborted the VM in 4 of 7 runs withGGML_ASSERT(logits != nullptr)(common/sampling.cpp, from the MTP drafter).Fix
LlamaSpeculativegains arun_mutex, whichgenerate_mtp_tokensholds for its whole run. A second call on the session waits for the first to finish. After a cancel the wait is at most one draft-and-verify step: the loop checks the flag every step, and a cancelled prompt decode stops early through the abort callback. The cancel protocol for normal (non-MTP) streaming is unchanged.Behaviour change: a call made while another stream on the same session is still running now waits for it, instead of corrupting it.
Tests and docs
LlamaCppEx.MTPCancelTest(:mtp_cancel) becomes a regular:mtptest inMTPModelTest. It cancels three streams in a row and asserts the greedy output afterwards is unchanged, so it also catches a corrupted cache that doesn't crash.:mtp_canceltag is removed fromtest_helper.exsand from the release guide.MTPmoduledoc warning against reusing a session is replaced by a description of the waiting behaviour.Verification (M1 Max, Metal, Qwen3.6-27B)
mtp_canceltest, before the fixGGML_ASSERT(logits != nullptr):mtpmodule with the fixvm_exit_test.exs,:mtp_sidecar(Qwen3.8-27B), format