Repository navigation
fix(metal): drop TSIM_DEVICE, bound the buffer pool, clearer errors - #296
Conversation
- Remove the TSIM_DEVICE environment variable; the `device` argument chooses where a sampler samples. tsim-dev's bench, width and profile modes now pass device="cpu" to the samplers through a small launcher around tsim-bench's worker (dev/tsim_dev/on_device.py). - Keep at most 1 GB of freed Metal output buffers for reuse; larger buffers are released at once, so a big boolean sample no longer pins its memory for the life of the process. - The device="metal" error for a tiny rotation names its angle and the threshold in units of π, and every "cannot run" error says to use device="cpu" or "auto". - Skills: GPU-aware memory advice, Metal rows in the errors table, wrapping fixes and a shorter description in the user skill; a GPU bench row in shipping-tsim-changes; the device side key in benchmarking-tsim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 658640c9e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| done = subprocess.run( | ||
| wrapped, | ||
| env=side_env(side, threads, device), | ||
| env=common.child_env(threads), |
There was a problem hiding this comment.
Clear legacy TSIM_DEVICE for GPU workers
When the invoking shell still exports TSIM_DEVICE=cpu, --device gpu --ref ... now passes that variable through child_env to both workers. The changed checkout ignores it, but a reference such as this commit's parent still honors it, so the benchmark compares the new GPU path against the reference CPU path and can report a misleading performance change. Preserve the previous GPU-side sanitization by removing TSIM_DEVICE from worker environments.
Useful? React with 👍 / 👎.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
☂️ Code Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
# Conflicts: # CHANGELOG.md
TSIM_DEVICE is gone, as on main; the rotation-angle message moves into the shared gpu.tape.unsupported, which CUDA uses too; CUDA's CHANGELOG entry goes under Unreleased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Usability fixes from a review of the Metal backend, plus fixes to the skills.
Changes
Tsim
TSIM_DEVICEremoved. Thedeviceargument is the only way to choose the device. Before, any value other thancpu(such ascpuu,0ormetal) was silently ignored.runtime.POOL_BYTES), and larger buffers are released at once. Before, a 1.28 GB boolean sample ofsurface_d7_r7left 1.6 GB allocated after both the array and the sampler were gone. The bench's calls return at most about 256 MB, so they still reuse buffers.device="metal"errors. A tiny rotation now reports its angle in the units the docs use, and every "cannot run" error names the fix:Cannot sample on Metal: a rotation's angle is 1.0e-05 π from a Clifford angle (a multiple of π/2), closer than the 6.4e-05 π that float32 amplitudes resolve; sample with device='cpu', or with device='auto', which falls back to the CPU.Before, it read:
a rotation has a branch of weight 2.5e-10, below the 1e-08 that float32 amplitudes resolve.metal/__init__.pymodule docstring is rewrapped.Dev harness
tsim-dev bench,bench --widthandprofileusedTSIM_DEVICE=cputo stay on the CPU, because tsim-bench's worker has no device option. They now start the worker throughdev/tsim_dev/on_device.py, which passesdevice="cpu"tocompile_samplerandcompile_detector_samplerwhen Tsim has that argument (older Tsims sample on the CPU only). A--deviceoption in tsim-bench's worker would make the shim unnecessary.Skills and docs
simulating-circuits-with-tsim:batch_sizeon the CPU; on a GPU, leave it unset and ask for fewer shots per call.Cannot sample on Metalrows.shipping-tsim-changes: a row requiringtsim-dev bench --device gpu --ref origin/mainfor changes to the GPU path.benchmarking-tsim:device=cpu|gpuis listed among the--sidekeys. Mentions ofTSIM_DEVICEare replaced here, inprofiling-tsim, indocs/install.mdxand in the CHANGELOG entry.Verification
uv run tsim-dev check: PASS for lint and tests (2783 passed).test_freed_buffers_beyond_the_pool_bytes_are_released: fails without the fix, sincePOOL_BYTESdoesn't exist there.test_device_cpu_keeps_the_samplers_on_the_cpu: checks thatTSIM_DEVICE=cpuis now ignored.R_Z(0.50001)) also stays on the CPU.test_dev_clichecks that the CPU bench runs the worker through the launcher and the GPU bench does not.devicecolumn ascpuby default andmetalwith--device gpu.Benchmarks against
origin/main(quick suite, Apple M4 Pro, 1 thread; the machine was partly busy,busy_cores4.4 to 5.6):tsim-dev bench --ref origin/main(CPU, bit-packed)same(0.98 to 1.03x)tsim-dev bench --device gpu --ref origin/main(bit-packed)same(0.98 to 1.02x)tsim-dev bench --device gpu --bools --ref origin/mainsame(0.98 to 1.00x)GPU, bit-packed:
The two "faster" compile verdicts (4.39x here, 1.95x on
coherent_d3_r3with booleans) are noise. Without--thoroughthe processes compile at the same time, and this change doesn't touch the compile path.Not verified:
--thoroughor--suite fullruns, since this change doesn't aim at speed.tsim-dev profilefails on macOS because py-spy's--nativeisn't supported there. That happens without this change too.🤖 Generated with Claude Code