Skip to content

[WIP] feat(deepseek): land V4 L1 KV cache on heterogeneous flat kv pools - #750

Open
SimonCqk wants to merge 1 commit into
lightseekorg:mainfrom
SimonCqk:feat/deepseek-v4-flat-kv-cache-migration
Open

[WIP] feat(deepseek): land V4 L1 KV cache on heterogeneous flat kv pools#750
SimonCqk wants to merge 1 commit into
lightseekorg:mainfrom
SimonCqk:feat/deepseek-v4-flat-kv-cache-migration

Conversation

@SimonCqk

Copy link
Copy Markdown
Contributor

Summary

Migrate DeepSeek V4 L1/device KV cache management to heterogeneous flat block pools while preserving the radix path as a compatibility and differential oracle.

The new design makes the cache plan the single authority for group geometry, physical pools, target/draft ownership, table layout, and device metadata. Model-agnostic runtime components consume only generic cache capabilities and table/lifecycle interfaces.

Key Changes

  • Added canonical V4 Flat KV memory planning for heterogeneous groups and target/draft union.
  • Added atomic multi-pool allocation, prefix reuse, reclaim, retract, and release through BlockPoolSet and KvCacheCoordinator.
  • Replaced the general structured-completion mechanism with a request-owned fixed FIFO that publishes accepted cache only after the GPU fence retires.
  • Bound Flat/Radix table sources at initialization and refreshed grouped tables correctly for eager and CUDA Graph execution.
  • Preserved MTP rewind, terminal deferred release, stale-generation rejection, and sleep/wake repair.
  • Removed duplicate validation, dead abstractions, hot-path snapshot allocation, and redundant tests.
  • Documented the final architecture and B200 validation procedure in the migration design.

Scope

This PR covers device-side/L1 KV cache management only. It does not add L2/CPU offload, kvstore integration, group-aware PD transfer, or global radix removal.

@SimonCqk
SimonCqk requested a review from a team as a code owner July 21, 2026 14:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a11e4ada3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread python/tokenspeed/runtime/engine/event_loop.py Outdated
@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch from 98e28a5 to 5a35355 Compare July 22, 2026 03:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a35355ff0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread python/tokenspeed/runtime/layers/attention/registry.py Outdated
@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch 2 times, most recently from 442495c to b777c65 Compare July 24, 2026 07:44
@SimonCqk
SimonCqk requested a review from a team as a code owner July 24, 2026 07:44
@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch from b777c65 to b85fed1 Compare July 27, 2026 09:33

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b85fed17e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread python/tokenspeed/runtime/execution/drafter/eagle.py Outdated
@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch from b85fed1 to f603a07 Compare July 30, 2026 11:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f603a07a69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1443 to +1445
lcm_spec=(
lcm_setup.draft if use_lcm_v4 and lcm_setup is not None else None
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Sanitize the draft LCM arena on page reuse

When DeepSeek V4 speculative/MTP decoding enables this separate draft LCM pool and the scheduler recycles a parent page, ModelExecutor.zero_flat_cache_pages() sanitizes only self.token_to_kv_pool; it never calls the sanitizer on self.draft_token_to_kv_pool, even though the new draft pool also sets flat_kv_requires_page_zeroing=True and uses the same scheduler page IDs in an independent backing arena. Reused draft SWA/compressor pages can therefore retain bytes from the previous owner and contaminate draft computation where a step does not overwrite the entire aliased page. Sanitize the corresponding draft-group pages as well and record the completion event after both pools are cleared.

Useful? React with 👍 / 👎.

@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch 2 times, most recently from e1bc75e to 4be215b Compare July 31, 2026 17:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4be215b7c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)


def _prepare_deepseek_v4(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the promised DeepSeek V4 migration documentation

This introduces a new heterogeneous FlatKV/LCM architecture with important operational constraints, but no documentation was added or updated; a repo-wide search also confirms that the migration guide cited by the commit, docs/serving/deepseek-v4-flat-kv-cache-migration.md, does not exist. Add that guide or update an existing serving document so operators can discover the required Flat scheduler build and unsupported L2/PD combinations.

AGENTS.md reference: AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

Signed-off-by: SimonCqk <cqk0100@gmail.com>
@SimonCqk
SimonCqk force-pushed the feat/deepseek-v4-flat-kv-cache-migration branch from 4be215b to 2eddc81 Compare August 1, 2026 02:09
@lightseek-bot

Copy link
Copy Markdown
Contributor

@SimonCqk let's wait for #864 @wangbo981016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants