[PR #1284] [CLOSED] [Engine] adaptive tier: --adapt-decay outside (0, 1) is refused (inf counts, NaN swap gains) #3358

Closed
opened 2026-11-07 14:40:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1284
Author: @sergqwer
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: pr/adapt-decay-range


📝 Commits (1)

  • 7c2d432 Adaptive tier: --adapt-decay outside (0, 1) is refused

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 src/program/generate.cpp (+8 -1)

📄 Description

Problem and result

--adapt-decay takes any number. The adaptive tier multiplies each expert's usage by the decay after every adaptation, so at 1 or more the counts never shrink. At 2, an expert routed early in the conversation passes FLT_MAX after 128 adaptations (about 128 verify rounds with --adapt-every 1, ~500 with the default 4). Then, in adapt:

  • cand[i].first < vict[i].first + 1.5f is false for inf against inf, so the pair is pushed with gain = inf - inf = NaN;

  • std::sort(swaps, gain > gain) then compares NaNs. That breaks the strict weak ordering std::sort requires: undefined behaviour.

  • Before: strata --adapt-decay 1.5 (or 2, 1, 0, -0.1, nan) starts and runs with it.

  • After: the parse refuses a value outside (0, 1) with --adapt-decay must be between 0 and 1 (exclusive) and exit code 2. Values inside the range behave as before.

The range check offered in #407 and #591; the maintainer took --adapt-decay itself into 0.1.38 without it. On this PR (2026-10-17): "This is a validation fix, not a speed change, so it is outside this pass; it is a small rebase if you want it in the fixes pass." It was #1284 before the 0.2.0-beta tracker reset; this is that rebase.

Approach

A check in the flag parse of src/program/generate.cpp (+8 / -1 lines), beside --adapt-min-gain. !(d > 0 && d < 1) also refuses a NaN. No default changes (the engine's own decay is inside the range).

Validation

Revision: this branch, one commit 7c2d4321 on main e88ee39d (v0.2.0-beta + 12 commits), against a build of main e88ee39d. RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (-DSTRATA_PORTABLE=ON, 75-real;86-real;89-real;120-real, ggml at the pinned 3cf03257).

Passed:

  • strata --adapt-decay V --no-such-flag on this branch: V = 1.5, 1, 2, 0, -0.1, nan -> --adapt-decay must be between 0 and 1 (exclusive), exit 2. V = 0.7, 0.999, 0.01 -> the parse goes on to the next argument (unknown argument: --no-such-flag). On main, --adapt-decay 1.5 goes on to the next argument too.
  • Default output unchanged: on the NVFP4 GPTQ pack (Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's --family nvfp4 --model NVFP4 files), strata --serve with setup's model files plus --expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, env STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>, a 2,100-token and a 32,037-token prompt, 32 greedy tokens each: first-token logits and tokens byte-identical to main's (2K 1e9c612c2e6c7a32..., 4 tokens; 32K f5b2872c7ac30b17..., 20 tokens).

Failed: none observed.

Not run:

  • HIP and Metal builds (both compile this generate.cpp; no ROCm or Mac here).
  • SYCL: sycl/src/program/generate.cpp keeps its own parse without the check.
  • The failure itself was not reproduced as a crash. Measured on v0.1.38 (RTX 5090, IQ2_XS, fixed --expert-cache 14900, a 1,000-token chat, --adapt-every 1, two runs each): at 0.7, 178 rounds and 1,095 experts swapped; at 2, 188 rounds and 3,523 swapped (3.2x), with the same output and no crash. So the case for the check is the undefined sort, not an observed failure.

Limits

strata_control/calibration.py accepts a stored --adapt-decay in 0..1 inclusive. A profile holding exactly 0 or 1 now stops the engine at start with the message above; the calibrator itself only writes 0.97.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1284 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/adapt-decay-range` --- ### 📝 Commits (1) - [`7c2d432`](https://github.com/Niko1221/Strata/commit/7c2d43216b9b852b072ec172faff10d764d11c3c) Adaptive tier: --adapt-decay outside (0, 1) is refused ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/program/generate.cpp` (+8 -1) </details> ### 📄 Description ## Problem and result `--adapt-decay` takes any number. The adaptive tier multiplies each expert's `usage` by the decay after every adaptation, so at 1 or more the counts never shrink. At 2, an expert routed early in the conversation passes `FLT_MAX` after 128 adaptations (about 128 verify rounds with `--adapt-every 1`, ~500 with the default 4). Then, in `adapt`: - `cand[i].first < vict[i].first + 1.5f` is false for inf against inf, so the pair is pushed with `gain = inf - inf = NaN`; - `std::sort(swaps, gain > gain)` then compares NaNs. That breaks the strict weak ordering `std::sort` requires: undefined behaviour. - Before: `strata --adapt-decay 1.5` (or 2, 1, 0, -0.1, nan) starts and runs with it. - After: the parse refuses a value outside (0, 1) with `--adapt-decay must be between 0 and 1 (exclusive)` and exit code 2. Values inside the range behave as before. ## Related discussion The range check offered in #407 and #591; the maintainer took `--adapt-decay` itself into 0.1.38 without it. On this PR (2026-10-17): "This is a validation fix, not a speed change, so it is outside this pass; it is a small rebase if you want it in the fixes pass." It was #1284 before the 0.2.0-beta tracker reset; this is that rebase. ## Approach A check in the flag parse of `src/program/generate.cpp` (+8 / -1 lines), beside `--adapt-min-gain`. `!(d > 0 && d < 1)` also refuses a NaN. No default changes (the engine's own decay is inside the range). ## Validation Revision: this branch, one commit 7c2d4321 on `main` **e88ee39d** (v0.2.0-beta + 12 commits), against a build of `main` e88ee39d. RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (`-DSTRATA_PORTABLE=ON`, `75-real;86-real;89-real;120-real`, ggml at the pinned 3cf03257). **Passed:** - `strata --adapt-decay V --no-such-flag` on this branch: V = 1.5, 1, 2, 0, -0.1, nan -> `--adapt-decay must be between 0 and 1 (exclusive)`, exit 2. V = 0.7, 0.999, 0.01 -> the parse goes on to the next argument (`unknown argument: --no-such-flag`). On `main`, `--adapt-decay 1.5` goes on to the next argument too. - Default output unchanged: on the NVFP4 GPTQ pack (`Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata`, upstream setup's `--family nvfp4 --model NVFP4` files), `strata --serve` with setup's model files plus `--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000`, env `STRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>`, a 2,100-token and a 32,037-token prompt, 32 greedy tokens each: first-token logits and tokens byte-identical to `main`'s (2K `1e9c612c2e6c7a32...`, 4 tokens; 32K `f5b2872c7ac30b17...`, 20 tokens). **Failed:** none observed. **Not run:** - HIP and Metal builds (both compile this `generate.cpp`; no ROCm or Mac here). - SYCL: `sycl/src/program/generate.cpp` keeps its own parse without the check. - The failure itself was not reproduced as a crash. Measured on v0.1.38 (RTX 5090, IQ2_XS, fixed `--expert-cache 14900`, a 1,000-token chat, `--adapt-every 1`, two runs each): at 0.7, 178 rounds and 1,095 experts swapped; at 2, 188 rounds and 3,523 swapped (3.2x), with the same output and no crash. So the case for the check is the undefined sort, not an observed failure. ## Limits `strata_control/calibration.py` accepts a stored `--adapt-decay` in 0..1 inclusive. A profile holding exactly 0 or 1 now stops the engine at start with the message above; the calibrator itself only writes 0.97. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:40:54 +07:00
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#3358
No description provided.