feat: support DSV4 device prefix cache (SWA + C4 + C128).#2008
Open
Kang-Meng wants to merge 1 commit into
Open
feat: support DSV4 device prefix cache (SWA + C4 + C128).#2008Kang-Meng wants to merge 1 commit into
Kang-Meng wants to merge 1 commit into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Kang-Meng
force-pushed
the
feat_dsv4_prefixcache
branch
from
July 23, 2026 05:13
d54b1af to
44a19c9
Compare
Kang-Meng
force-pushed
the
feat_dsv4_prefixcache
branch
from
July 23, 2026 05:52
44a19c9 to
ab71000
Compare
Kang-Meng
marked this pull request as ready for review
July 23, 2026 05:54
Kang-Meng
requested review from
DongheJin,
JimHsiung,
RobbieLeung,
liutongxuan,
walsonyang and
yq33victor
as code owners
July 23, 2026 05:54
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Kang-Meng
requested review from
Clement-Wang26,
DragonFive,
XuZhang99,
liujinguang0125,
xiao-yu-chen,
yingxudeng and
zhang-minchao
as code owners
July 23, 2026 05:54
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.
feat: support DSV4 device prefix cache (SWA + C4 + C128)
Commit:
d54b1af· Branch:feat_dsv4_prefixcache· Repo:xllmDiff: 30 files, +1242 / −576
Background
DeepSeek-V4-Flash (DSV4) previously could not use the device prefix cache.
master.cppcarried a hard guard that, on detecting adeepseek_v4model type,force-set
enable_prefix_cache=falseand logged a warning. This PR removes thatguard and completes
CompositeBlockManager+ prefix-cache support for DSV4'sthree-segment KV layout (SWA + C4 + C128), so DSV4 can actually hit the
device-side prefix cache.
What changed
Removed the DSV4 fallback guard (
master.cpp, −11 lines).DSV4 now takes the normal composite prefix-cache path instead of being
silently disabled.
LeafCombinationclassification inCompositeBlockManager(largest change;
composite_block_manager.cpp+630). The leaf shape isclassified once at construction and cached; the sequence-level orchestrators
dispatch on it to pick the trim/mount strategy:
FLAT_KV— plain KV (normal / Qwen), no trimFLAT_KV_LINEAR— Qwen3.5-Next GDN (KV + LINEAR restore)SWA_COMPRESSED— DSV4 (SWA + C4 + C128): cross-leaf min,C128-stride clamp, SWA tail-continuity, exact-repeat pop
UNSUPPORTED— prefix cache off / xtensorAdds
cache_full_blocks_for_sequenceto incrementally insert each leaf'snewly-forwarded full blocks into its own prefix cache.
Per-stride block-hash chains (
sequence.h/.cpp).DSV4 admission probes SWA/C4/C128 back-to-back each tick with different
strides (base / 4×base / 128×base). Each stride now keeps its own
incrementally-extended hash chain, so switching strides no longer discards
and rebuilds the whole chain. Backed by
std::mapfor pointer stability, soa
Slicefromblock_hashes()survives inserts of other strides.LinearStatePrefixCachemade gap-tolerant(
linear_state_prefix_cache.cpp+229). SWA slides out middle window blocksand LINEAR deeper hits subsume earlier ones, so
match()/insert()toleratemiddle misses (placeholders): the compute path walks the chain from token 0
rather than seeding from the previous block, placeholders advance the cursor
without being stamped/emplaced, and trailing misses are trimmed. The base
PrefixCacheremains solid-prefix.Interface cleanup: dropped the
size_t* matched_tokensout-param frommatch()(reach now expressed asreturned.size() * block_size_); added anLRU-neutral
contains().