d16_format_probe: compute the rule models once per input (TEST-D16-MODELS-CACHE) #2376
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2376
Loading…
Reference in a new issue
No description provided.
Delete branch "test-d16-models-cache"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: TEST-D16-MODELS-CACHE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197567323), picking up the item @amine23012004 claimed and then released as free for anyone (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191191563).
What and why
models16()andmodels32()intools/d16_format_probe.pyare pure functions of (kind, bits, value), but a sweep,classify()and the tests call them about 955,000 times for about 131,000 distinct inputs, each time redoing the exactFractionarithmetic. The rule bits are now computed once per input (functools.lru_cacheon a tuple), and each call still returns a fresh dict, so a caller that edits it cannot change what the next call gets. Every caller looks the rules up by name (classify()iterates its ownrulestuple), so the dict's key order does not reach any output. No result changes.The commit is amine23012004's, kept as written and with them as its author (their branch
test-d16-models-cache, 9a7128947), rebased on currentmain. It adds a test that the cache hands each call its own dict.tests/semantic/test_buffer_load_format.pyandtools/rdna2spirv.pyonly name the probe in comments; nothing else imports it excepttools/d16_image_probe.pyand the two d16 test files.This PR touches the same two files as #1664; the two merge without conflict (
git merge-treeof both heads).Tested
On
main2e2c51c09 + this commit, Windows 11 (26300), Python 3.12.10, i9-13900K, timed while a fullmake_game.pybuild was using the CPU, so the absolute times are noisy:python -I tests/test_d16_format_probe.py: 26.6 s before, 12.0 s after (12.4 s after the rebase); 24 tests OK (2 skipped, GPU).python -I tests/test_d16_image_probe.py: 22.6 s before, 17.0 s after; OK (2 skipped).python -I tools/d16_format_probe.py --self-test: self-test ok.python -I tests/test_image_d16_probe.py: 22 tests OK (2 skipped).python -m unittest discover -s tests/semantic -p test_buffer_load_format.py: 34 tests OK.python -m compileall -q make_game.py tools tests,python -I make_game.py --help,python -I tests/test_text_write_line_endings.py(3 OK),python -I scripts/check_no_game_data.pyon both changed files,git diff --check: clean.amine23012004 measured 26.7 s -> 7.7 s and 21.8 s -> 13.1 s on an idle machine.
GPUs tested: n/a (CPU-only change; the probe's GPU kernels are untouched)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator rule here.)🤖 Generated with Claude Code
I compared the cached model at
e6b97d1e43with its parent2e2c51c092on every encoding of UNORM8, SNORM8, UNORM10, UNORM16 and SNORM16. For each input I compared the dictionaries by rule name: all ten half-precision results (including denormal-flush variants) and all three single-precision results.All 1,723,904 named outputs matched across the 132,608 inputs. Clearing a returned dictionary from each model also left the next lookup intact for the SNORM16 minimum and UNORM16 maximum. This was a CPU comparison on Windows 11, Python 3.13.18. The float16 passthrough control does not use these rounding models.
AI-assisted verification with OpenAI Codex (GPT-6).
@wavehs Fixed in afee1e34b:
test_models_are_cached_but_each_call_gets_its_own_dictnow also asserts that the secondmodels16/models32call adds one hit to_models16.cache_info()/_models32.cache_info(), next to the fresh-dict check.Checked on Windows 11, CPython 3.12.10:
python -I tests/test_d16_format_probe.py: 24 tests OK (skipped=2).@functools.lru_cachedecorators removed, the test now fails ('function' object has no attribute 'cache_info'); before this commit it stayed green.python -I scripts/check_no_game_data.pyon both files andgit diff --check: clean.AI-assisted (Claude Code).