Repository navigation
Reduce repeated Gemma 4 12B prompt prefill - #535
Merged
Merged
Conversation
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.
Repeated long system/tool prompts make each Gemma 4 12B request pay the full prefill cost. The runtime now skips discarded vocabulary projections and keeps one bounded, immutable system/tool prefix. Each request extends independent KV cache objects, including sliding-window position metadata; user turns and tool results are excluded from retention.
On one M5 Pro synthetic prompt (8,499 input tokens, 15 generated tokens), the original path took 10.180 and 10.292 seconds around the optimized pair; optimized cold took 9.352 seconds and warm took 0.778 seconds. All four generations had identical token IDs, raw output, and tool arguments. This is a local timing probe, not an accuracy result or a general latency guarantee.
The 12B prefix budget defaults to 1,024 MiB and uses the existing
SPEECH_SWIFT_GEMMA4_PREFIX_CACHE_MBoverride (0disables retention). E4B keeps its existing default. Native responses reportcachedPrefixTokens, capabilities report cache support, and provenance records the effective budget. Local model documentation and a reproducible benchmark summary are included.Validation: 10 focused config/prefix tests pass. Real-weight release tests pass for cold/warm token parity, a long second user followed by the original user (cache isolation), native tool/result history and cancellation, and capture of malformed output. The release server build passes. Complete-service HTTP integration remains unrun: two model-service startups hit the 2 GiB free-disk guard before readiness, including after removal of this task’s rebuildable artifacts. This limit occurs before requests or retained prefix state; no HTTP or speech-latency claim is made.
Regression risk: medium because retained KV state adds memory and depends on correct independent cache copying. The snapshot is bounded, token-matched, limited to system/tool input, explicitly releasable, and covered by reference-generation comparisons.