fix(strategy): validate dtype in the public subspace_matmul() API (Fixes #222)#223
Merged
zeokin merged 1 commit intoJul 14, 2026
Conversation
strategy.subspace_matmul() had the same dtype gap matmul.matmul() had before zeokin#209 (the strategy package is deliberately standalone and shares no code with matmul): _dtype_name silently returned "fp32" for any unrecognized dtype, so subspace_matmul on integer arrays built a fp32 Config while the operands went to the GPU at their native dtype and died deep inside torch.matmul. It also never checked that A and B share a dtype, so subspace_matmul(fp16, fp32) crashed the same opaque way. Resolve/validate the dtype at the top of subspace_matmul(), before the backend exists (so the error is clear and GPU-independent): raise ValueError on A.dtype != B.dtype, and make _dtype_name raise a ValueError listing DTYPES instead of mislabelling an unsupported dtype as fp32. Completes the dtype-validation pattern across both public multiply APIs, as zeokin#201 did for the three CLIs. fp16/fp32/fp64 are unchanged. Add CPU-only tests (validation runs before the GPU backend): unsupported dtypes (int32/int64/uint8/complex128) and A/B mismatch raise ValueError with a clear message, the three supported dtypes map correctly, and the pre-existing square-shape guard still fires first. Three fail on the pre-fix code. Fixes zeokin#222
zeokin
approved these changes
Jul 14, 2026
zeokin
left a comment
Owner
There was a problem hiding this comment.
Validates A/B dtype match and rejects unsupported dtypes before the GPU; narrow, tested.
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.
Fixes #222.
PR kind
PR kind: fix
Summary
strategy.subspace_matmul()had the same dtype gapmatmul.matmul()had before#209 — and since the strategy package is deliberately standalone (it shares no
code with
matmul/), the fix had to be made separately here:_dtype_namesilently returned"fp32"for any unrecognized dtype, sosubspace_matmulon integer arrays built afp32Configwhile the operandswent to the GPU at their native dtype and died deep inside
torch.matmul. It alsonever checked that
AandBshare a dtype, sosubspace_matmul(fp16, fp32)crashed the same opaque way.
The fix
Resolve/validate the dtype at the top of
subspace_matmul(), before the backendexists (so the error is clear and GPU-independent): raise
ValueErroronA.dtype != B.dtype, and make_dtype_nameraise aValueErrorlistingDTYPESinstead of mislabelling an unsupported dtype as
fp32. This completes thedtype-validation pattern across both public multiply APIs, exactly as #201
completed the clean-CLI-error pattern across all three CLIs.
fp16/fp32/fp64are unchanged.
Validation
uv run --extra test python -m pytest tests/ strategy/tests/ eval/tests/ -v→ 263 passed, 24 skipped.
uv run python -m strategy.smoke→1/1 transforms passed.Backend(...), so it raises on a no-GPU machine (the newtests are pure CPU). The three reject tests fail on the pre-fix code.
New
strategy/tests/test_subspace_matmul_dtype.py: unsupported dtypes(
int32/int64/uint8/complex128) and A/B mismatch raiseValueErrorwith aclear message; the three supported dtypes map correctly; and the pre-existing
square-shape guard still fires first.
No protected paths touched (
strategy/,strategy/tests/are Open perCONTRIBUTING.md). This changes
strategy/__init__.py, a file thematmul#209fix never touched — the two packages are intentionally separate.
GPU Result (required for feat PRs only)
N/A —
fixPR (input validation in the public API). No scorecard required; theresult of a valid multiply is unchanged.
Checklist
strategy.smoke, pluspytest tests/ strategy/tests/ eval/tests/).Co-authored-byfooters for coding agents such as Cursor, Codex, Claude, Copilot, or similar tools.