Repository navigation
Fix SPEX ignoring random_state, and log the CPU on Windows runners - #645
Merged
Merged
Conversation
sparse_transform draws its random queries from numpy's global random state, which Sparse and SPEX never seeded, so random_state=42 gave a different result after every other use of np.random. This made test_approximate_with_spex fail about once in 400 runs (on main: the FSII case on Python 3.15). With a random_state, the global state is now seeded from the approximator's generator for the transform and restored afterwards. Without one, nothing changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MhQWPdeTbJyESb8uBYqLAU
On some Windows runners the tests crash with an illegal instruction (0xc000001d) at the first TabPFN fit, and the crash cuts off the stack trace. The new step logs the CPU model, the SIMD extensions numpy finds and the CPU capability torch selects, so a crashing runner can be told apart from the ones that pass. It never fails the job. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MhQWPdeTbJyESb8uBYqLAU
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MhQWPdeTbJyESb8uBYqLAU
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mmschlk
pushed a commit
to flyingdoubleG/shapiq
that referenced
this pull request
Oct 26, 2026
Resolves the CHANGELOG conflict with mmschlk#645 and mmschlk#646 by keeping all entries. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NMMG43PofYoX3cELuvzmtt
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.
Motivation and Context
CI went red on
mainafter #641 was merged (run). The merged code had passed every job on the PR, so neither failure was caused by the code that went in. These are two separate problems that a run can hit by chance.1. Ubuntu, Python 3.15:
test_approximate_with_spex[...FSII...]failed (obtained ~0, expected 0.05). This is a real bug, fixed here.SparseandSPEXignoredrandom_state. Thesparse_transformlibrary draws its random queries from numpy's global random state (np.random.randint,np.random.choice), and shapiq never seeded it. As a result,SPEX(random_state=42)gave a different result after any other use ofnp.random. I reproduced the CI failure locally: withrandom_state=42fixed, the failing case fails for global seed 242, about once in 400 seeds.The fix is in
src/shapiq/approximator/sparse/base.py. With arandom_state, the global state is seeded from the approximator's generator for the transform and then restored, so the caller's global state is untouched. Without arandom_state, nothing changes.2. Windows: the test process crashed with
0xc000001d(illegal instruction). Not fixed, only diagnosed here.The crash happens at the first TabPFN fit (
TestProxyTabPFNExplainer::test_proxyshap_tabpfn_reg, which runs PyTorch). The same crash hit a fork PR on 2026-10-23 under the old CI (run). It also passed on all three runs of #641, so it depends on which runner machine a job lands on. Some Windows runners presumably lack a CPU instruction that compiled code in that path uses. The crash cuts off the stack trace, so the library and the instruction are still unknown.This PR adds a step to the Windows test job that logs:
The step has
continue-on-error, so it never fails the job. The next crash can then be compared with a passing runner before choosing a workaround (e.g. capping torch's CPU dispatch).Public API Changes
random_stateonSparse/SPEXnow does what its docstring says. Results with a fixedrandom_statechange, and are now reproducible.How Has This Been Tested?
test_random_state_makes_approximation_reproducible, checks that the samerandom_stategives identical estimates under different global seeds and leaves the global state as it was. It fails without the fix and passes with it.test_approximator_base_sparse.pypasses (15 tests). Everytest_approximate_with_spexcase passes for global seed 242 and seeds 0–19.actionlintand pre-commit pass onci.yml. This PR changesci.yml, so its own run takes the full matrix and runs the new step on Windows.Checklist
CHANGELOG.md(if relevant for users).Generated by Claude Code