Skip to content

flashnext hip: the chunk fallback measures room after the window plan slots - #3419

Merged
ashhart merged 6 commits into
ashhart:mainfrom
gilby:strix/hip-fn-scratch-room-slots
Nov 19, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
gilby:strix/hip-fn-scratch-room-slots

Conversation

@gilby

@gilby gilby commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What this changes

Follow-up to #2728. On Flash Next HIP, the chunk fallback decides whether a smaller prompt chunk would admit more streams by comparing the room left on the device with the two scratch sizes. It measured that room before the window plan's slots were allocated, so the slots' bytes were counted as free. With little room left, the fallback could keep the larger chunk although fewer streams then fit than it had worked out.

The fallback now takes the slots' bytes off the room first. narrows gets the slots' bytes as an argument, and fittedScratch passes gdn.Slots.bytes for the wanted stream count when the model has a window plan, and 0 otherwise. One file, zig/src/families/flashnext/hip/engine.zig.

Checks on this head

  • Head commit: 3554434
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 341 and 341, 0 new findings.
  • Tests run, with the command and pass, fail and skip counts: zig build test -Dhip=true: 482 of 504 passed, 20 skipped, 2 failed. The 2 failures are the Flash Next hip.tables gather-pool tests, which fail the same way on the base. python3 tools/pr_check.py --base origin/main: 0 errors.
  • New test: "the chunk fallback leaves the window plan slots' bytes off the room". It fails when the slots' bytes are no longer passed at the call site and passes with the change.
  • CI: I will post the result here when it finishes.
  • Not run, and why: CUDA and Metal, since the file is HIP only. A served start in which the fallback actually changes its answer: on a 128 GB Strix Halo the default configurations leave enough room that both chunk sizes admit every wanted stream, so I could not reach that case on a real server; the host test covers it.

Receipt

One Strix Halo (gfx1151, 128 GB, 115 GiB GTT), HIP 7.1 toolchain, Flash Next oQ4e, main 2ba55ec7d against this head, a fresh server for each start. The point of the receipt is that the default configurations are unchanged.

configuration main this head
--context 131072 --parallel 4 79.76 GiB on the device, 4 streams of 131136 positions, 4.31 GiB each, 4096-row chunks the same line
--context 262144 --parallel 3 --policy prefill_step=2048 78.56 GiB on the device, 3 streams of 262208 positions, 8.07 GiB each, 2048-row chunks the same line

No fallback line was printed in any of the four starts. One greedy 64-token request per start gave the same reply hash in all four (17 rounds, 46 of 46 drafts accepted). No speed cells: the change runs once at start and touches no kernel or round.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@gilby

gilby commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

CI on 3554434a8: every job passes (zig, zig-windows, zig-macos-dev-tools, pytest, fmt, benchmark-clients on both systems, release-paths); the two nightly host jobs are skipped as usual.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The slot subtraction matches the later allocation, the host fallback tests pass, and CI is reported green at 3554434a8.

The remaining device cell is a start that actually takes the changed fallback; both recorded launches leave enough room to avoid it. Please use a valid reduced HIP memory budget to cross that decision and post the old/new fallback and allocation lines, peak memory, and equal full token hashes with the same checkpoint and requests. We have no HIP device to reproduce that cell here.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Here is the reduced-memory-budget device cell crossing the fallback decision on one Strix Halo iGPU (gfx1151, Qwen3.8-Flash-Next oQ4e group-32 checkpoint, --context 131072).

1. Fallback and allocation lines (TENSORFOLD_HIP_MEMORY_LIMIT_GB=96.99, default --parallel auto)

At 96.99 GiB (~17.18 GiB free after the 4096-row scratch and 8 gdn.Slots), 4 streams at 4.31 GiB each need 17.23 GiB. On main (2ba55ec7d), narrows omits the 8 gdn.Slots (0.1060 GiB) so it keeps 4096-row chunks and falls down to 3 streams; on 3554434a8, subtracting those slots crosses the threshold so it takes 1024-row chunks and keeps 4 streams:

  • Old (2ba55ec7d): policy [tensorfold] HIP rank 0 of 1: policy matrix=auto,attention=auto,kernels=auto,graphs=auto,prefill_step=4096,fill_rows=512; mtp drafts 3 under 0.8, 8 snapshots prefill_step 4096 is this GPU's default, 1024 when it admits fewer streams;, budget info: HIP memory budget from the host's /proc/meminfo (integrated, shared memory): 120.8 of 122.7 GiB free, 12.3 GiB reserve, allocation [tensorfold] HIP gfx1151 device 0, rank 0 of 1: Flash Next, 79.81 GiB on the device, 3 streams of 131136 positions, 4.31 GiB each; prompts in 4096-row chunks.
  • New (3554434a8): policy [tensorfold] HIP rank 0 of 1: policy matrix=auto,attention=auto,kernels=auto,graphs=auto,prefill_step=4096,fill_rows=512; mtp drafts 3 under 0.8, 8 snapshots prefill_step 4096 is this GPU's default, 1024 when it admits fewer streams;, budget info: HIP memory budget from the host's /proc/meminfo (integrated, shared memory): 120.9 of 122.7 GiB free, 12.3 GiB reserve, allocation [tensorfold] HIP gfx1151 device 0, rank 0 of 1: Flash Next, 78.04 GiB on the device, 4 streams of 131136 positions, 4.31 GiB each; prompts in 1024-row chunks (4096-row chunks would admit fewer of the streams asked for).

2. Device and host memory (/v1/memory and /metrics)

  • 2ba55ec7d (4096-row chunks, 3 streams): at open device.active_bytes = 85,695,664,096 (79.81 GiB) and device.peak_bytes = 86,962,926,688 (80.99 GiB weight-load transient peak); after serving all concurrent and long-prompt cells below: device.active_bytes = 98,641,155,040 (91.87 GiB), device.peak_bytes = 98,665,121,256 (91.89 GiB), process_resident_peak_bytes = 62,830,362,624.
  • 3554434a8 (1024-row fallback chunks, 4 streams): at open device.active_bytes = 83,794,426,336 (78.04 GiB) and device.peak_bytes = 86,962,926,688 (80.99 GiB); after serving the same requests: device.active_bytes = 96,739,917,280 (90.10 GiB), device.peak_bytes = 96,763,883,496 (90.12 GiB, -1,901,237,760 bytes / -1.77 GiB from narrowing 4096 to 1024 scratch), process_resident_peak_bytes = 64,162,103,296.

3. Equal full token_sha256 across the same checkpoint and requests

  • tools/bench_prompts.json (--levels 1,2,3 --tokens 128 --reps 2 --alone --serial --temperatures 1.0,0): 24 of 24 concurrent replies on 3554434a8 match 2ba55ec7d (0 unequal), and across both arms 48 of 48 concurrent = alone and 36 of 36 alone = "draft": false (0 unequal, 0 failed): T=1.0 seed=1234 16 prompt tokens 6445af0e916d62f2ac7bd1c5b34de7893c9664dd0dd1a68509a3fb6fe367bc50, T=1.0 seed=1235 30 prompt tokens 3db54ce6c06b7d9c226b963c3313081403d56135c1c2a89c961ffd726e0148f9, T=1.0 seed=1236 26 prompt tokens 6a9007df6b6268cb8846bf0599301b9acc42a62225c221bd4178dc3bfd70010c, T=0 16 prompt tokens 33fa1daeb6b41fe93065dd6f2057f238c3ee0968e7342b4d1c73901080ec44ae, T=0 30 prompt tokens 5190133172921798119b305e55883cad921c75528a35c77df5d420d54585bc52, and T=0 26 prompt tokens 92011add14d4f28318c125d3a37e52acc2638d15ea0753be21cbd6cbea5eadae.
  • Multi-chunk prefill (--levels 1,2 --tokens 128 --reps 1 --alone --serial --temperatures 1.0,0 on a 3,543-token chat prompt and a 5,862-token completion prompt, so 2ba55ec7d runs 1 and 2 chunks of up to 4,096 rows while 3554434a8 runs 4 and 6 chunks of at most 1,024 rows): 6 of 6 concurrent replies on 3554434a8 match 2ba55ec7d (0 unequal), and across both arms 12 of 12 concurrent = alone and 16 of 16 alone = "draft": false (0 unequal, 0 failed): T=1.0 seed=1234 5,862 prompt tokens aeda3d8cd95bd825cfd192006cfbd2d95544f78c39fbcdaf8ff34b18f038cfb0, T=1.0 seed=1235 3,543 prompt tokens 8e312083c3341b2b0179920106f523317345040fcda988ad0347e6deae3109fd, T=0 5,862 prompt tokens f444d34c36158d236b1f3f8379bbaff46e90737aa7d48f89b3ca918cf133720f, and T=0 3,543 prompt tokens 0948161269c1c437b8168b45967be9a9fafd22fd915de3f1fc27cc53a935cbe5.

4. Fixed --parallel 4 boundary (TENSORFOLD_HIP_MEMORY_LIMIT_GB=96.9639, --context 131072 --parallel 4)

  • 2ba55ec7d: keeps 4096-row chunks and refuses with tensorfold: --parallel 4 needs 17.23 GiB at a 131072-token window and 17.21 GiB is left: serve --parallel 3, or lower --context.
  • 3554434a8: takes the 1024-row fallback ([tensorfold] HIP gfx1151 device 0, rank 0 of 1: Flash Next, 77.99 GiB on the device, 4 streams of 131136 positions, 4.31 GiB each; prompts in 1024-row chunks (4096-row chunks would admit fewer of the streams asked for)), device.active_bytes = 83,737,498,784 (77.99 GiB) at open and 100,998,153,376 active / 101,001,155,248 peak (94.06 GiB) after serving tools/bench_prompts.json (--levels 4 --tokens 64 --reps 1 --temperatures 0 --alone), with 4 of 4 concurrent token_sha256 matching their solo runs (d290637399e0ffd9b5f72086ed47509c450fd9b1b14e186197ad4da4fb4e3fb9, 6fe29728c3b089fe492c840fa1f02601e6df6b0ce2afcee1d3e54e4aebaf188f, 307cce03d5566e018b3255cd11fb82e5c7d2426a6d5c90c4ec0b518bfdcb28e2, 9c875ebb23658024a0617d8bae90fdbe8ab417aa56a03a9a6c9aefa10077bde4).

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. This answers the missing device check: the reduced budget makes the new code choose 1,024-row chunks and admit four streams where the old code kept 4,096-row chunks and admitted three. The memory measurements and complete token hashes cover the changed path, including prompts across several chunks.

HIP is hardware we do not run, so your posted runs are the device evidence for both boundaries; on our side we check that the CUDA and Metal paths stay unchanged. No further code change is requested from this follow-up.

  • Synthena

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The reduced-memory-budget run crosses the changed fallback and shows the new code choosing the smaller chunks and admitting the extra stream, with the memory measurements and full token hashes covering that path. The host test fails when the slots are left out and passes with the change. CI is green at this head, and the change stays inside HIP startup.

No further code change is requested. We will check the CUDA and Metal paths on our side.

  • Synthena

@ashhart
ashhart force-pushed the strix/hip-fn-scratch-room-slots branch from 3554434 to 4c25139 Compare November 19, 2026 20:29
@ashhart
ashhart merged commit 61fe903 into ashhart:main Nov 19, 2026
ashhart added a commit that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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