Skip to content

qwen3_5 CUDA: page-aligned prefix saves and opt-in device snapshots - #4473

Merged
ashhart merged 9 commits into
mainfrom
lead/q35-prefix-snapshot-gpu
Nov 24, 2026
Merged

ashhart merged 9 commits into
mainfrom
lead/q35-prefix-snapshot-gpu

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

Two commits on the Qwen3.5 CUDA prefix cache:

  1. Shared prefixes are saved at page boundaries. Save marks are rounded to the page grid (Pages.layout.page_tokens) and intersected with the cold-prompt cuts, so a resumed prompt restores whole pages and TF_QWEN_KV_PAGES no longer has to divide the compute grid.
  2. Opt-in device snapshots. With TF_QWEN_KV_SNAPSHOT_GPU=1, prefix snapshots stay in device memory and restore by device-to-device copy instead of round-tripping through pinned host memory. Unset keeps today's host snapshots. A failed device allocation falls back to the host path. The switch is documented in docs/environment.md.

Checks

  • Host tests: fresh and resumed stepped-cut sequences at 256-token page marks inside the 4096-row grid, with 512-row caps and solo cuts; a byte-real fault fixture comparing every state byte after each resume, covering D2D save and restore, device allocation fallback, failed copies and waits, retry, eviction and page leases.
  • zig fmt --check, zig ast-check, the 600-line cap and the lean count (unchanged) pass, as do check-native-cuda-host and compile-cuda-tests for Linux.

Still to run

The GPU gate: fresh servers per arm, cache-agent traces (agent_loops, agent_cohorts) at 512, 4K and 129K prefix tokens with the switch off and on, plus a one-stream decode control. Kill on any token or state difference, any decode regression, or under 3% repeated-turn TTFT gain.

Round shared-prefix save marks to the page grid and make those marks real cold-pass cuts, including solo passes. Fresh and resumed prompts now stop at the same page edges without requiring the page size to divide the compute grid.
TF_QWEN_KV_SNAPSHOT_GPU=1 keeps the radix store's bounded recurrent snapshots in device memory and restores them D2D. Device allocation failure selects the existing pinned-host path before copying; failed copies drain or quarantine before release. The fake device now transfers real bytes so host tests compare fresh, resumed and rebuilt state and inject allocation, copy and wait failures.
@ashhart
ashhart force-pushed the lead/q35-prefix-snapshot-gpu branch from 44237d9 to da4a05a Compare November 24, 2026 12:49
@ashhart
ashhart merged commit 1a14bb1 into main Nov 24, 2026
2 of 12 checks passed
@ashhart
ashhart deleted the lead/q35-prefix-snapshot-gpu branch November 24, 2026 12:50
ashhart added a commit that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
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.

1 participant