[GH-ISSUE #2021] [Bug]: gfx1151: a 4K prompt stays under STRATA_PF_SWITCH_MIN_T=4096 (its chunk is 4,095 tokens) and is ~16% slower #804

Closed
opened 2026-11-04 01:46:02 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @libratechw on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2021

What happened

docs/STRIX_HALO.md section 5 sets STRATA_PF_SWITCH_MIN_T=4096, so that prompts shorter than 4,096 tokens keep the default numerics. A prompt of 4,096 tokens (what the benchmarks call "4K") is read as a chunk of 4,095 tokens, so it is below the threshold. The hyper-connection and padding switches, and the dense GEMM that goes with them, then stay off for it, and the dense projections run hipBLASLt solutions that are not in tools/hip/gfx1151-hipblaslt-100401.txt (Cijk_..._HSS_..._MT96x96x32; 26% of the GPU time of a 4K prompt in a rocprofv3 trace, against pfg::kernel_bk64 when the switches are on).

Measured on one server, 4 requests of the same 4K prompt in a row (UD-Q4_K_XL, STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1, the section 5 switches, only STRATA_PF_SWITCH_MIN_T changed), prompt tok/s:

STRATA_PF_SWITCH_MIN_T range over 4 requests per request
4096 1,052-1,106
2048 1,262-1,298 about 0.58 s shorter
1024 1,246-1,295 about 0.58 s shorter

I know 4096 was chosen to keep the 1.0-1.9K prompts of the test set on the default output (b6b7a87d); the code default is 0 (every chunk). So this is not a request to change the number. The question is which of these you would want:

  1. a lower default in section 5 (for example 2048; chunks of 2,048-4,095 tokens then differ from the default by rounding, which I can measure with first-token KL the way I did for #2020);
  2. a note in section 5 that a "4K" prompt is below 4096, with the number to use if you want it above;
  3. the threshold compared with the prompt length instead of the chunk length (a 4K prompt as a whole is long enough to benefit, even when the chunk is 4,095 tokens).

I have no preference between them, and I can make the change in whichever form you pick.

Strata version, GPU, OS

v0.1.43 · Radeon 8060S (Ryzen AI Max+ 395, gfx1151) · Linux 7.0, ROCm 7.14.1

Engine log

Not attached: it is the same on every start. The rocprofv3 traces (4096 against 2048) are available on request.

🤖 Generated with Claude Code

Originally created by @libratechw on GitHub (Oct 12, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2021 ## What happened `docs/STRIX_HALO.md` section 5 sets `STRATA_PF_SWITCH_MIN_T=4096`, so that prompts shorter than 4,096 tokens keep the default numerics. A prompt of 4,096 tokens (what the benchmarks call "4K") is read as a chunk of 4,095 tokens, so it is below the threshold. The hyper-connection and padding switches, and the dense GEMM that goes with them, then stay off for it, and the dense projections run hipBLASLt solutions that are not in `tools/hip/gfx1151-hipblaslt-100401.txt` (`Cijk_..._HSS_..._MT96x96x32`; 26% of the GPU time of a 4K prompt in a rocprofv3 trace, against `pfg::kernel_bk64` when the switches are on). Measured on one server, 4 requests of the same 4K prompt in a row (UD-Q4_K_XL, `STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1`, the section 5 switches, only `STRATA_PF_SWITCH_MIN_T` changed), prompt tok/s: | `STRATA_PF_SWITCH_MIN_T` | range over 4 requests | per request | |---|---:|---:| | 4096 | 1,052-1,106 | | | 2048 | 1,262-1,298 | about 0.58 s shorter | | 1024 | 1,246-1,295 | about 0.58 s shorter | I know `4096` was chosen to keep the 1.0-1.9K prompts of the test set on the default output (b6b7a87d); the code default is 0 (every chunk). So this is not a request to change the number. The question is which of these you would want: 1. a lower default in section 5 (for example 2048; chunks of 2,048-4,095 tokens then differ from the default by rounding, which I can measure with first-token KL the way I did for #2020); 2. a note in section 5 that a "4K" prompt is below 4096, with the number to use if you want it above; 3. the threshold compared with the prompt length instead of the chunk length (a 4K prompt as a whole is long enough to benefit, even when the chunk is 4,095 tokens). I have no preference between them, and I can make the change in whichever form you pick. ## Strata version, GPU, OS v0.1.43 · Radeon 8060S (Ryzen AI Max+ 395, gfx1151) · Linux 7.0, ROCm 7.14.1 ## Engine log Not attached: it is the same on every start. The rocprofv3 traces (4096 against 2048) are available on request. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@Niko1221 commented on GitHub (Oct 12, 2026):

Thank you for the rocprofv3 trace and the three-way table; it is a clear case. Your reading is right: STRATA_PF_SWITCH_MIN_T compares the length of the prompt chunk, and a 4,096-token prompt is read as a chunk of 4,095 tokens, so with 4096 the switches stay off for it. It is not a bug in the comparison (the threshold is documented as a chunk length, and the code default is 0 = every chunk), so we are not changing the code or any default for it in 0.1.43.1; nothing on CUDA or the gfx12 defaults depends on it.

Of your three options, we would take the note in section 5 of docs/STRIX_HALO.md (a 4K prompt is a 4,095-token chunk, so use STRATA_PF_SWITCH_MIN_T=4095 or 2048 if you want it above the threshold, with the rounding-level difference stated). A PR with that note would be welcome. A lower number in the section-5 recipe, or comparing the whole prompt's length, changes which prompts take the rounding-level path, so that needs your first-token KL for 2048 and 4095 against the default, as for #2020, before we decide it; please post it here when you have it.

<!-- gh-comment-id:6129325879 --> @Niko1221 commented on GitHub (Oct 12, 2026): Thank you for the rocprofv3 trace and the three-way table; it is a clear case. Your reading is right: `STRATA_PF_SWITCH_MIN_T` compares the length of the prompt chunk, and a 4,096-token prompt is read as a chunk of 4,095 tokens, so with 4096 the switches stay off for it. It is not a bug in the comparison (the threshold is documented as a chunk length, and the code default is 0 = every chunk), so we are not changing the code or any default for it in 0.1.43.1; nothing on CUDA or the gfx12 defaults depends on it. Of your three options, we would take the note in section 5 of docs/STRIX_HALO.md (a 4K prompt is a 4,095-token chunk, so use `STRATA_PF_SWITCH_MIN_T=4095` or 2048 if you want it above the threshold, with the rounding-level difference stated). A PR with that note would be welcome. A lower number in the section-5 recipe, or comparing the whole prompt's length, changes which prompts take the rounding-level path, so that needs your first-token KL for 2048 and 4095 against the default, as for #2020, before we decide it; please post it here when you have it.
Author
Owner

@libratechw commented on GitHub (Oct 13, 2026):

Thank you. The first-token KL you asked for, against the default engine (no section-5 switches), 8 natural-text prompts of 1.5K, 2,048, 3K, 4,095, 4,096, 4.5K, 6K and 8K tokens, gfx1151, the section-5 switches with only STRATA_PF_SWITCH_MIN_T changed (STRATA_PF_FUSED=1, plus STRATA_PF_FUSED_KQ=1 for the K-quant model):

STRATA_PF_SWITCH_MIN_T UD-IQ4_XS mean / max UD-Q4_K_XL mean / max top-1 against the default
4096 0.0168 / 0.0468 0.0026 / 0.0074 7 of 8
4095 0.0168 / 0.0468 0.0026 / 0.0074 7 of 8
2048 0.0154 / 0.0468 0.0023 / 0.0074 7 of 8

Per prompt, the 2048 row differs from the other two only where a chunk is between 2,048 and 4,095 tokens (the 3K, 4,095 and 4,096 prompts: IQ4_XS 0.0025 / 0.0082 / 0.0075 at 4096 and 0.0013 / 0.0051 / 0.0003 at 2048). The top token is the same in all 8 prompts for all three rows; the one prompt that differs from the default (6K) differs under all of them, so it comes from the other switches. Putting those chunks on the switches does not move them farther from the default than they already are.

One correction to the premise: 4095 does not turn the switches on for a 4,096-token prompt in the default configuration. The 4096 and 4095 rows are identical. I moved the threshold across a 4,096-token prompt (UD-IQ4_XS, --spec 4, --prefill 16384): the switches are on at 4089 and off at 4090, so its chunk is 4,089 tokens. The reason is in generate.cpp: with the prompt cache (default 6) the prompt is read in two parts, cut at the last <|im_start|> (turn_at), and the last token is read alone (cuts = {..., turn_at, n - 1}). The new turn's header is 7 tokens with reasoning off (<|im_start|>, assistant, newline, <think>, blank line, </think>, blank line; I counted them with the tokenizer), so the big chunk is n - 7. With --prompt-cache 0 there is no turn_at and the chunk is n - 1: on at 4095, off at 4096, as in your reading and the trace of this issue. The header depends on the template and the reasoning mode, so the offset can differ for other requests.

So a value below the chunk of the shortest prompt you want is the safe advice, such as 2048.

I will open a PR with the note for section 5 next (the chunk-not-prompt reading, 2048 as the suggested value, these KL numbers). Whether to change the recipe's 4096 is yours to decide from the table.

<!-- gh-comment-id:6136841844 --> @libratechw commented on GitHub (Oct 13, 2026): Thank you. The first-token KL you asked for, against the default engine (no section-5 switches), 8 natural-text prompts of 1.5K, 2,048, 3K, 4,095, 4,096, 4.5K, 6K and 8K tokens, gfx1151, the section-5 switches with only `STRATA_PF_SWITCH_MIN_T` changed (`STRATA_PF_FUSED=1`, plus `STRATA_PF_FUSED_KQ=1` for the K-quant model): | `STRATA_PF_SWITCH_MIN_T` | UD-IQ4_XS mean / max | UD-Q4_K_XL mean / max | top-1 against the default | |---:|---:|---:|---:| | 4096 | 0.0168 / 0.0468 | 0.0026 / 0.0074 | 7 of 8 | | 4095 | 0.0168 / 0.0468 | 0.0026 / 0.0074 | 7 of 8 | | 2048 | 0.0154 / 0.0468 | 0.0023 / 0.0074 | 7 of 8 | Per prompt, the 2048 row differs from the other two only where a chunk is between 2,048 and 4,095 tokens (the 3K, 4,095 and 4,096 prompts: IQ4_XS 0.0025 / 0.0082 / 0.0075 at 4096 and 0.0013 / 0.0051 / 0.0003 at 2048). The top token is the same in all 8 prompts for all three rows; the one prompt that differs from the default (6K) differs under all of them, so it comes from the other switches. Putting those chunks on the switches does not move them farther from the default than they already are. One correction to the premise: `4095` does not turn the switches on for a 4,096-token prompt in the default configuration. The 4096 and 4095 rows are identical. I moved the threshold across a 4,096-token prompt (UD-IQ4_XS, `--spec 4`, `--prefill 16384`): the switches are on at 4089 and off at 4090, so its chunk is 4,089 tokens. The reason is in `generate.cpp`: with the prompt cache (default 6) the prompt is read in two parts, cut at the last `<|im_start|>` (`turn_at`), and the last token is read alone (`cuts = {..., turn_at, n - 1}`). The new turn's header is 7 tokens with reasoning off (`<|im_start|>`, `assistant`, newline, `<think>`, blank line, `</think>`, blank line; I counted them with the tokenizer), so the big chunk is n - 7. With `--prompt-cache 0` there is no `turn_at` and the chunk is n - 1: on at 4095, off at 4096, as in your reading and the trace of this issue. The header depends on the template and the reasoning mode, so the offset can differ for other requests. So a value below the chunk of the shortest prompt you want is the safe advice, such as 2048. I will open a PR with the note for section 5 next (the chunk-not-prompt reading, 2048 as the suggested value, these KL numbers). Whether to change the recipe's 4096 is yours to decide from the table.
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6659235299 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#804
No description provided.