Repository navigation
Close the generator after the server ends the response - #1
Open
cassieliang6709 wants to merge 1 commit into
Open
cassieliang6709 wants to merge 1 commit into
cassieliang6709 wants to merge 1 commit into
Conversation
Closing a speculative generator feeds the tokens it yielded but did not process into the caches. The server closed it before telling the client the response was done, so every request waited for that extra forward pass. Close it after the response ends; the cache is still complete before it is saved.
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.
This goes on top of ml-explore#2083.
The
finallyblock inspeculative_generate_stepfeeds the tokens that were yielded but not processed into both caches. In the server that block runs when thestream_generateloop breaks, which is beforerqueue.put(None), so the client waits for a target and a draft forward pass before the response ends.This keeps a reference to the generator, ends the response first, then closes the generator. The caches are still filled before
insert_cache.Time from the last content chunk to the end of the stream, M1 Pro, Qwen3-4B-Instruct-2507-4bit with Qwen3-0.6B-4bit as the draft, 22 streamed requests per run:
tests/test_server.py,tests/test_generate.pyandtests/test_prompt_cache.pypass (110 tests).