fix(strategy): reject non-finite spectral_alpha in storage.generate#273
Merged
zeokin merged 1 commit intoJul 17, 2026
Merged
Conversation
Contributor
|
This PR currently has merge conflicts with the base branch. Please resolve them within 12 hours or the bot will close the PR automatically. |
philluiz2323
force-pushed
the
fix/strategy-spectral-alpha-finite
branch
from
July 16, 2026 05:16
47b3e32 to
03ba760
Compare
storage.generate passes spectral_alpha straight to _fill_decaying_spectrum, whose k**-alpha weights go all-NaN for a NaN alpha (the whole generated matrix becomes NaN) or collapse to [1, 0, 0, ...] for Inf (a silent rank-1 'decaying-spectrum' couple). The sibling data_rank argument is already validated at this public boundary; spectral_alpha was not. Guard it (finite and >= 0) right next to the data_rank check. (The --spectral-alpha CLI flag that used to feed this was reverted in 84b6604, but storage.generate is a public API that still takes the parameter, so the boundary itself still needs the guard.) Add CPU tests: generate() rejects non-finite/negative alpha for decaying-spectrum, accepts finite values (output stays finite), and ignores the knob for other fills.
philluiz2323
force-pushed
the
fix/strategy-spectral-alpha-finite
branch
from
July 16, 2026 05:32
03ba760 to
edf40d5
Compare
zeokin
approved these changes
Jul 17, 2026
zeokin
left a comment
Owner
There was a problem hiding this comment.
Non-finite spectral_alpha silently produced an all-NaN matrix or a rank-1 collapse -- corrupt benchmark input. Closes the library boundary the CLI already guards.
5 tasks
statxc
added a commit
to statxc/Cuda-Compute-OSS
that referenced
this pull request
Jul 17, 2026
…merge storage.py accumulated two duplicates when zeokin#273 (reject non-finite spectral_alpha) landed: 1. import math appeared twice (lines 8 and 10) -- the only F811 in the shipped source tree; matmul/storage.py imports cleanly. 2. spectral_alpha is validated twice in generate(): a top-of-function guard and again inside the decaying-spectrum branch. The top guard is strictly stronger (it also rejects bool / non-Real) and runs first, so the in-branch re-check is dead code -- every bad alpha (nan/inf/-inf/<0/non-Real/bool/None) is caught up top, verified by direct call. Drop the re-check; move its rationale comment and its value-in-message (got {alpha!r}) onto the surviving guard, so the error is if anything more informative (it now names non-Real offenders the inner check never reached). Behaviour is unchanged: same inputs rejected, same fills produced. Pure redundancy removal, one file, no protected paths.
zeokin
added a commit
that referenced
this pull request
Jul 17, 2026
fix(strategy): drop two storage.py redundancies left by the #273 merge
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
storage.generatepassesspectral_alphastraight to_fill_decaying_spectrum, whose weights arenp.arange(1, rank+1) ** -alpha, with no finiteness check:alpha = nan→ weights allNaN→ the entire generated matrix isNaN.alpha = inf→ weights collapse to[1, 0, 0, …]→ a "rank-R decaying-spectrum" matrix silently becomes rank 1.The sibling
data_rankargument is already validated at this same public boundary;spectral_alphawas the gap.Reproduced (CPU, current
main):Fix
Guard
spectral_alpha(finite and>= 0) insidestorage.generate'sdecaying-spectrumbranch, right next to the existingdata_rankguard, so every caller of the publicrunner/storageAPI is protected.Verification (CPU — no GPU needed)
python -m pytest tests/test_decaying_spectrum_alpha.py—generate()rejects non-finite/negative alpha for decaying-spectrum, accepts finite values (output stays finite), and ignores the knob for unrelated fillspython -m pytest tests/test_cli_errors.py— unaffected, green (this PR no longer touches the CLI)Scorecard
Not applicable: pure input-validation/robustness fix at the storage boundary, touching no scored path (
ready-non-gpuclass).