Fix GPU Hang in MTPTokenIterator: flush Metal graph after verification pass#41
Merged
Conversation
…rification pass On hybrid SSM/attention models (Qwen35), the recurrent GatedDeltaNet layers accumulate un-evaluated MLX graph nodes across each speculateRound(). Without an explicit eval() after callMTP(), the Metal command buffer grows across multiple speculation rounds until it triggers the GPU Watchdog (kIOGPUCommandBufferCallbackErrorHang). Adding eval(mtpResult) immediately after the verification forward pass flushes the accumulated graph, preventing the Metal timeout.
There was a problem hiding this comment.
Pull request overview
This PR addresses a CI-crashing Metal GPU hang during MTP speculative decoding by forcing evaluation immediately after the verification callMTP() forward pass, preventing lazy-graph growth across speculation rounds (notably on hybrid SSM/attention models like Qwen35).
Changes:
- Add an
eval(mtpResult)right after the verification forward pass inMTPTokenIterator.speculateRound(). - Document the rationale for flushing/evaluating at that point to avoid GPU watchdog hangs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // On hybrid SSM/attention models (e.g. Qwen35), the recurrent SSM layers accumulate | ||
| // un-evaluated graph nodes across rounds. Without an explicit sync here the Metal | ||
| // command buffer grows until it triggers the GPU Watchdog. | ||
| eval(mtpResult) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Problem
The
MTPTokenIterator at temperature=0 matches TokenIterator outputtest was consistently crashing CI with:Root Cause
MTPTokenIterator.speculateRound()callsmodel.callMTP()each round but did not immediately evaluate the result. On hybrid SSM/attention models (e.g. Qwen35), the recurrentGatedDeltaNetlayers accumulate un-evaluated MLX lazy graph nodes across speculation rounds. After 3-4 rounds the Metal command buffer overflows and triggers the GPU Watchdog.Fix
Added
eval(mtpResult)immediately after the verificationcallMTP()forward pass, before the acceptance/rejection loop reads.asArray()values. This flushes the full forward-pass graph — including SSM cache state — in one shot each round.Verification
All 16 MTP speculative decoding tests pass locally including the previously failing test.