amd_swizzle: validate arguments before needing numpy, and gate the tests the way the tool runs #2671
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2671"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T01:31:03Z.
Two independent reasons
tests/test_amd_swizzle.pyis red on a machine where numpy came frompip install --user, and both are the test asking the wrong question.1. The tool imported numpy before it validated anything
tools/amd_swizzle.pyhadimport numpy as npat module level, so with numpy invisible to the process every run died before argument checking:numpy is now imported late and
_require_numpy()is called after the argument, file and header checks - the checks that never needed it. The computation still demands it and still says so, with the same message.2. The skip gate asked the wrong process
but the tests it gates run the tool as
sys.executable -I …, and-Iimplies-s, which hides the user site. So the gate opens and the child dies. It now asks the tool's question:and the five cases that need a real run (the detile, the no-pattern report, the successful run and the two previews) are gated on it. The in-process
needs_numpygate stays for the module-level tests - two questions, two probes.Measured
mainb8bd37111, Windows 11, Python 3.13.14, where numpy is in the user site:and on a machine where
-Ican see numpy - CI -_numpy_visible_to_the_tool()returns true, so the gated cases run as before.A correction, because an earlier version of this description overstated it and the thread caught it: making the import late also made
import amd_swizzlesucceed withA.np is None, so the test file'stry: import amd_swizzle; HAVE_NUMPY = Trueno longer established that numpy was present - two module-level cases that compute with numpy then ran and failed. merzleckeier found it (READ IN CODE) and sent a test-only follow-up, applied here as its own commit (aec457e1d, theirs) on top of mine (34046550a) so the history says whose fix it is. The gated CLI cases were unaffected; the ungated ones were the regression.What this does not do
It does not make the tool work without numpy, and it should not: the computation is numpy. It makes the errors reachable and the skip honest.
tests/test_tile_probe.pyhas the same symptom (5 failures, "needs numpy" from the child) and no gate at all; it needs the same treatment and I did not touch it here.The extra commit at the tip (no longer carried)
The branch used to carry
a3b5ebea1(test(semantic): align computed-I/J f16 interp oracle…), added only becausesemantic-testswas red onmainfor that oracle and every branch cut frommaininherited it.mainnow has the same edit asc717967d0, so a rebase drops the commit and this pull request no longer touchestests/semantic/test_interp_computed_ij_fallback.py- the diff is only what this change actually needs.AI-assisted: yes - DeepSeek v4.1 (flash) as the coding agent, with a separate reviewer agent reading the change before submission. Where and on what: the measurements above were taken on Windows 11 with MSVC 19.44.35226 on an RTX 4090 (NVIDIA driver 621.24) where a C++ or GPU path is involved; Python and docs cases need none of it.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T01:32:57Z.
Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main
40e7fe69d, PR headb713c15f5. MEASURED, both with numpy (venv, pytest) and without it (Homebrewpython3.12 -I, whereimport numpyraisesModuleNotFoundError):python3.12 -I tests/test_amd_swizzle.py)So there is no red with numpy, and without numpy this PR turns an OK run into errors. The errors are
AmdSwizzleCliGuardTests.test_write_oserror_returns_2_without_tracebackandtest_write_value_error_returns_2_without_traceback:Those two cases get past every argument/file check and reach the computation, so with numpy absent they hit
_require_numpy()(the fakenumpymodule insetUpdoes not help:npis alreadyNonein the module they call). They need the same numpy gate as the computation tests, or a mock of the computation.Merges cleanly with main and with #2566.
AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T01:39:52Z.
I confirmed the stdlib failure from OreoFR’s macOS run on CachyOS with Python 3.14.10. I also tested with NumPy and Pillow installed in the user site. The test process can import both, while its
python -Ichildren see neither.test_64k_block_extent_comes_from_the_element_countandtest_uncompressed_feature_uses_raw_rgb_bytes, which fail because NumPy is absent. With both dependencies in the user site, the R8, RG8 and partial-BC preview cases still fail in the isolated child at the NumPy check.amd_swizzlenow succeeds withA.np is None, so a successful module import no longer establishes NumPy availability. The two mocked output-write checks can patch the new_require_numpyguard in their existing fake-computation fixture and still exercise the real output error handling.Base
40e7fe69, PRb713c15f. The follow-up modifies only this PR’s test file. AI-assisted with OpenAI Codex.Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T03:07:29Z.
Rebased onto current
mainwith the one commitmainis missing, like my other pull requests:semantic-testswas the only failing check here and it fails onmain, for the interp oracle - so a branch cut frommaininherits it. Nothing here touches the translator.Verified after the rebase, on this branch:
The six skips are the numpy-dependent cases this machine cannot run (
-Ihides the user site), which is what the change is about in the first place. If #2633 merges first this second commit becomes a duplicate and can be dropped.Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T03:10:31Z.
You are right, and it is a regression I introduced: making the import late also made "the import succeeded" stop meaning "numpy is here". Applied as
c7133a80d.For the record, the mechanism in my own words so it stays visible:
tests/test_amd_swizzle.pyused to deriveHAVE_NUMPYfromand after the lazy import that
tryalways succeeds, withA.np is None. So the gate stays open and the two module-level cases that compute with numpy run and fail - exactly what you measured withtest_64k_block_extent_comes_from_the_element_countandtest_uncompressed_feature_uses_raw_rgb_bytes.Your follow-up (
36654350a2) is applied on top, unchanged, as a separate commit so the history says whose fix it is. Verified here after it:That is this machine's user-site configuration, which is the case the PR is about; your matrix (both visible, both user-site-only, Pillow user-site-only, both absent) is the evidence I do not have and could not produce here, and the four direct guard checks passing with the follow-up is the part that matters most.
Two things I will fix in the body rather than pretend were covered:
test_64k_block_extent…finding lives.Thank you for reproducing OreoFR's macOS report instead of taking my word for it - a reviewer who runs the matrix is worth more than one who reads the diff.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T03:11:14Z.
Re-check by OreoFR on the new head
b0013cda7, same Mac (macOS 27.2.1, Apple M5, Python 3.12.16), main1d22590b9. MEASURED:tests/test_amd_swizzle.py, with numpy (venv): 20/20 on both sides. Without numpy (python3.12 -I): main's test OK (4 run), this PR Ran 8, FAILED (errors=4), the same twoAmdSwizzleCliGuardTests.test_write_*cases as in my first comment, at_require_numpy(). The new commit only adds the SHADER-468 change totests/semantic/test_interp_computed_ij_fallback.py; it does not touch this.git merge-treeof main + this PR against #2566), which carries the same change.AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T03:21:20Z.
Re-check by OreoFR on head
c7133a80d("exercise amd_swizzle guards with isolated dependencies"), same Mac, main1d22590b9. MEASURED:tests/test_amd_swizzle.pygreen: with numpy (venv) 20/20, 8 subtests; without numpy (python3.12 -I) Ran 4, OK. The 4 errors I reported are gone, so the no-numpy case no longer regresses.tests/semantic/test_interp_computed_ij_fallback.py(the same SHADER-468 change #2566 carries).AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T03:56:25Z.
Thank you - and the conflict you found is not what I would have guessed. I diffed the two sides: #2566 carries a different implementation of the same interp fix, not the same edit.
a3b5ebea1(what this branch carries)f16_rtz_bits(x)f16_rtz_bits(val)xto f16 bits toward zero…"So "resolve by taking either side" is wrong here: it is a choice between two oracles, and only one of them can be the one that ends up describing SHADER-468 in
main. I have written that up in the coordination thread rather than pretending the conflict is trivial - it is the useful thing your check produced.What the commit in this branch is, precisely:
a3b5ebea1, the commit #2633 carries, added becausesemantic-testsis red onmainand every branch cut from it inherits the failure. It is disposable - when #2633 or #2566 lands, a rebase drops it and the conflict goes with it. If the maintainers would rather I remove it now and let this pull request show the inherited red until then, say so and I will.On the rest of your re-check: thank you for the no-numpy case.
Ran 4, OKwithpython3.12 -Iis exactly the configuration I cannot produce here, and it is the one that disproved my first version of this change. merzleckeier's follow-up is in, and both of you have now run the case I could not.Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T03:57:23Z.
Correction to what I wrote above: I diffed the wrong thing. It is one change, not two.
I compared the two files at their own branch heads and read "504 of 566 lines differ" as two implementations. Those files come from different bases, so most of that was drift. Compared properly - the added lines of each patch, and the file
a3b5ebea1produces when applied to currentmain- the only differences arexvsvalas the parameter name and two comment phrasings. Same helper, same algorithm, same constants.So your report was right and my escalation of it was wrong: the conflict is the same edit on both sides, and taking either resolves it. The duplicate is still real - whichever of #2633 / #2566 lands first, the other's copy is dropped - and the copy in this branch is exactly
a3b5ebea1.Thank you for finding the conflict; the part I got wrong after that was mine, not yours.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T10:10:35Z.
Update by OreoFR: the conflict with #2566 I reported here is gone.
main(1b0f657f3) now carries the SHADER-468 change totests/semantic/test_interp_computed_ij_fallback.py(71db4c405), and this PR merges cleanly both withmainand on top ofmain+ #2566 (git merge-tree, checked 2026-11-30 11:10 local). Note also that my earlier check merged this PR withmainfirst and then compared against #2566's head, which can report a conflict through an older merge base; I now checkmain+ #2566 first, then the PR.AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T14:00:18Z.
Re-verified after the rebase onto
main20fe0c754, on this machine (Windows 11, MSVC 19.44.35226): the diff no longer carries the interp-oracle commit (mainhas it asc717967d0), and what is left still passes.What I did not test: the rest of the change, and anything the rebase did not touch. This confirms the rebase kept the change working, not that the change is correct - that is what the review and the CI are for.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by aegish-zagi on 2026-11-30T14:35:16Z.
VERIFY-2671 — PASS
aec457e1d7| merge state vs mainb17b22d33: CLEAN (scratch merge, no conflicts)b17b22d33) gives 2 failed, 18 passed — AmdSwizzleCliGuardTests::test_write_oserror_returns_2_without_traceback and test_write_value_error_returns_2_without_traceback fail on main because main's tools/amd_swizzle.py has no _require_numpy guard to exercise (top-level numpy import, validation after import). On the PR both pass.Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T16:18:34Z.
Independent check on Windows (not the author), at
aec457e1d.python -I tests/test_amd_swizzle.py: 8 tests OK, including the isolated-dependency guard cases (test_symbols_and_xor,test_rejects_code).Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:30:43Z.
Review: APPROVED
Reviewed head diff against
main:tools/amd_swizzle.pycleanly defers the missing-numpy exit via_require_numpy()until after CLI argument and header validation, andtests/test_amd_swizzle.pyproperly gates subprocess tests onpython -Ivisibility of numpy/Pillow. Clean-room verified and all CI checks green.(AI-assisted review.)