Repository navigation
fix(turboquant): preserve generation and packed KV cache state - #6612
Merged
Merged
Conversation
Resolve effective generation settings before injecting the cache. Roll back a failed layer readout and preserve batch metadata and vector scale across cache updates. Synchronize the decode benchmark at its timing boundaries.
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.
Summary
Follow-up to #6603. Cache selection now honors the effective generation options. TurboQuant also preserves packed state across batch changes and readout failures, and reconstructs finite outputs from finite KV inputs across the supported dtypes.
What Changed
dynamicselector after building or checking the packed cache. Validate the model's generation defaults and reject incompatible cache layouts and decoding modes before writing cache data.Tests
Ruff passed. The TurboQuant suite passed 94 tests and skipped seven device cases. The documentation suite passed 264 tests. Adjacent suites passed 229 tests and skipped ten LeapQuant device cases. The revised device probe is unverified.
dynamicconflicted with the injected cache. Inherited settings were skipped by the wrapper.test_generate_with_explicit_dynamic_cache_implementation,test_generate_honors_inherited_use_cache,test_generate_rejects_inherited_unsupported_optionstest_cache_can_append_after_reorder_changes_batch_size,test_cache_can_retry_after_materialization_failstest_cache_preserves_scale_for_large_and_small_vectors, FP64 RMS and Hadamard oraclestest_benchmark_times_completed_decodeMeasured Impact
The table gives packed bytes for a head dimension of 128 with QJL enabled.
This validation covers CPU correctness and packed byte counts. Revised throughput and perplexity are unverified.
Logic Flow Documentation
The generation and packed-cache diagrams are also in TurboQuant KV-cache quantization.
BaseQModel._prepare_kv_quant_cacheTurboQuantLayer.updateflowchart TD A["GPTQModel.generate"] --> B{"kv_quant set"} B -->|no| C["model.generate with caller kwargs"] B -->|yes| K{"effective use_cache"} K -->|false| C K -->|enabled| D{"supported generation options"} D -->|no| E["raise ValueError"] D -->|yes| F{"past_key_values supplied"} F -->|no| G["build TurboQuantDynamicCache"] F -->|yes| H{"TurboQuantDynamicCache with matching policy"} H -->|no| E H -->|yes| I["keep caller cache"] G --> L["consume dynamic selector if set"] I --> L L --> J["model.generate"]flowchart LR A["key/value update"] --> B["normalize by vector norm"] B --> C["Hadamard rotation"] C --> D{"keys and use_qjl"} D -->|yes| E["b-bit MSE indices<br/>plus one-bit QJL sketch"] D -->|no| F["b-bit MSE indices"] E --> G["packed chunks<br/>indices, norms, sketch"] F --> G G --> H["materialize on attention call"] H --> I["inverse rotation and norm"]Review Requirements