Repository navigation
spark-model(hy4): add chunk-aligned prefix caching (P2 #7) and process guards (P3 #10, #11) - #165
Merged
Merged
Conversation
… in-order cuBLASLt
…h-4096 # Conflicts: # crates/spark-model/src/layers/hy4/batch.rs
…-4096 # Conflicts: # crates/spark-model/src/layers/hy4/batch.rs
…hunk early-exit, and raise prefill_rows default to 4096
Prevents the scheduler's idle initial_chunk_budget (max_prefill_tokens + 1) from splitting chunk 0 into 4096 + 1 rows and shifting subsequent chunk boundaries off the prefill.capacity grid. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Prevents default thinking from consuming the 32/64-token probe budget in Gate 1 and Gate 3. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Ensures every invocation of verify_hy4_gate.py measures a true cold miss on request 1 followed by a warm prefix-cache hit on request 2. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Owner
Author
Phase 2 & Phase 3 Live Validation on
|
| Workload | Prompt Tokens | Cached Prefix Tokens (cached_tokens) |
Cold TTFT (eff tok/s) |
Warm TTFT (eff tok/s) |
Warm TTFT Speedup | Cold == Warm Output Parity |
|---|---|---|---|---|---|---|
19.4K Long DSA Recall (probe_dsa_long.py 1024 48) |
19,379 |
16,384 (4 chunks) |
18.229 s (1,063.1 tok/s) |
3.412 s (5,679.7 tok/s) |
5.34x (-14.82 s) |
100% Bit-Exact (48/48 tokens, 'ANSWER: 342 Perth...') |
23.2K OpenClaw Captured Turn (1795901442-000437.c2s) |
23,174 |
20,480 (5 chunks) |
22.214 s (1,043.2 tok/s) |
3.230 s (7,175.1 tok/s) |
6.88x (-18.98 s) |
100% Exact (web_search({"query":"Qwen 4 release available Alibaba 2026","count":5.0})) |
| 23.2K OpenClaw Follow-Up Turn (new user message) | 23,205 |
20,480 (5 chunks) |
— | 3.258 s (7,121.7 tok/s) |
6.82x |
Emits valid web_search call (finish=tool_calls) |
Gate 3 (verify_hy4_gate.py, 11.7K prompt) |
11,671 |
8,192 (2 chunks) |
11.083 s |
4.296 s |
2.58x |
100% Exact ([PASS] Gate 3) |
2. P2 #8: SWA Causal Tile Width Sweep (ATLAS_HY4_SWA_TILE_ROWS, bench_prompt_4096.txt 4,182 tok)
ATLAS_HY4_SWA_TILE_ROWS |
Median TTFT | Median Prefill tok/s |
3-Trial Rates (tok/s) |
probe_ids Token Parity |
|---|---|---|---|---|
8 (legacy) |
4.208 s |
993.9 tok/s |
[996.6, 993.9, 993.3] |
[29206] (exact) |
32 |
3.799 s |
1,100.7 tok/s |
[1099.9, 1100.7, 1101.4] |
[29206] (exact) |
64 (default) |
3.749 s |
1,115.6 tok/s |
[1115.8, 1113.9, 1115.6] |
[29206] (exact, optimal) |
128 |
3.809 s |
1,098.1 tok/s |
[1098.6, 1095.5, 1098.1] |
[29206] (exact) |
256 |
3.845 s |
1,087.8 tok/s |
[1092.7, 1087.4, 1087.8] |
[29206] (exact) |
3. P3 #11: Standard HY4 Gate Script (scripts/dev/verify_hy4_gate.py)
[PASS] Gate 1 (wide prefill >= 1024 tok): prompt_tokens=2287, elapsed=2369.6 ms
[PASS] Gate 2 (HY4 tool-call grammar): query_cluster_node({"node_id": "spark-rank-0", "metric": "hbm_free"})
[PASS] Gate 3 (prefix cache parity): prompt_tokens=11671, cached_tokens=8192, cold=11082.7 ms -> warm=4296.2 ms
ALL HY4 GATES PASSED.
…AS_HY4_DSA_TILE_ROWS knob - Extend HY4 prefix caching with 512-token tail-chunk granularity (PREFIX_TAIL_GRANULE = 512, MAX_PREFIX_SNAPSHOTS = 4) on multi-chunk prompts so warm turns cache up to 99%+ of the prompt instead of stopping at the previous 4096-token boundary, while preserving identical cold/warm chunk boundaries. - Add ATLAS_HY4_DSA_TILE_ROWS (default 64, up to MAX_ROWS = 256) so DSA indexed causal tile width can be swept at runtime without rebuilds. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Owner
Author
Phase 4 Update (
|
| Workload | Prompt Tokens | cached_tokens (%) |
Cold TTFT (eff tok/s) |
Warm TTFT (eff tok/s) |
Warm TTFT Speedup | Cold == Warm Parity |
|---|---|---|---|---|---|---|
23.2K OpenClaw Captured Turn (1795901442-000437.c2s) |
23,174 |
23,040 (99.4%) |
22.457 s (1,031.9 tok/s) |
0.588 s (39,389 tok/s) |
38.2x (-21.87 s) |
100% Exact (True: web_search args + reasoning identical) |
| 23.2K OpenClaw Follow-Up Turn (new user turn) | 23,205 |
23,040 (99.3%) |
— | 0.645 s (35,980 tok/s) (wall 4.12 s) |
34.8x |
Emits valid web_search call (finish=tool_calls) |
19.4K Long DSA Recall (probe_dsa_long.py 1024 48) |
19,379 |
18,944 (97.8%) |
18.428 s (1,051.6 tok/s) |
0.904 s (21,437 tok/s) (wall 2.37 s) |
20.4x (-17.52 s) |
100% Bit-Exact (48/48 tokens, 'ANSWER: 342 Perth...') |
Gate 3 (verify_hy4_gate.py, 11.7K prompt) |
11,671 |
11,264 (96.5%) |
11.640 s |
1.584 s |
7.35x |
100% Exact ([PASS] Gate 3) |
bench_prompt_4096.txt (4,182 tok, Trials 1–3 warm) |
4,182 |
4,096 (97.9%) |
3.753 s (1,114.4 tok/s) |
0.490 s (8,535 tok/s) |
7.66x |
100% Bit-Exact (probe_ids = [29206]) |
2. DSA Causal Tile Width Sweep (ATLAS_HY4_DSA_TILE_ROWS = {64, 128, 256})
ATLAS_HY4_DSA_TILE_ROWS |
Warm 4.2K Median TTFT | Warm 4.2K Effective tok/s |
probe_ids Token Parity |
|---|---|---|---|
64 (default) |
0.490 s |
8,535.0 tok/s |
[29206] (exact) |
128 |
0.491 s |
8,510.6 tok/s |
[29206] (exact) |
256 |
0.492 s |
8,498.4 tok/s |
[29206] (exact) |
3. DFly Speculative Draft Depth Sweep (--num-drafts = {5, 6, 7}, decode_real.py 4 Prompts x 2 Repeats)
--num-drafts |
Overall Mean tok/s |
Overall Median tok/s |
code-limiter |
code-topk |
edit-json |
edit-sql |
Token Parity vs d=5 |
|---|---|---|---|---|---|---|---|
5 (default) |
31.48 tok/s |
31.92 tok/s |
31.88 tok/s |
24.44 tok/s |
37.54 tok/s |
32.07 tok/s |
Baseline (4/4 exact) |
6 |
30.73 tok/s |
30.48 tok/s |
31.82 tok/s |
22.07 tok/s |
39.17 tok/s |
29.84 tok/s |
4/4 bit-exact |
7 |
32.50 tok/s |
33.83 tok/s |
30.80 tok/s |
21.08 tok/s |
41.53 tok/s |
36.58 tok/s |
4/4 bit-exact |
- Decision: Keep
--num-drafts=5as the general-purpose default because it maximizes lower-acceptance code synthesis (code-topk:24.44vs21.08 tok/s), while--num-drafts=7is validated bit-exact and reaches41.5 tok/son structured JSON/SQL edits.
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
Hy4Model):Hy4Model::enable_prefix_caching()wired frombuild_modelwhenprefix_cache.is_active()(--enable-prefix-caching) orATLAS_HY4_PREFIX_CACHE=1(=0kill-switch disables).source.scratch.indices(2048 * 4bytes) inAttentionCache::copy_committed_state_fromalongsidelatent,pool,tail,len, andfirst_group_position.PrefixCellsnapshots strictly at non-final prefill chunk boundaries (sub_end < tokens.len(), exact multiples of the chunk width) so cold and warm executions traverse identical chunk boundaries and preserve circular SWA (576-slot) and DSAIndexPoolstates bit-for-bit.PREFIX_SAVE(10) andPREFIX_RESTORE(11) wire commands and recordsseq.cached_prefix_tokens.ATLAS_HY4_*Environment Variable Registry):ATLAS_HY4_*environment variables incrates/spark-model/src/layers/hy4/README.mdwith their default, validation PR, and graduation/expiry decision.scripts/dev/verify_hy4_gate.pyexercising width>= 512prompt prefill, forced tool-call grammar (tool_choice="required"), and cross-request prefix-cache cold-vs-warm output parity.