Fix set_parameters on device models - #5
Merged
Merged
Conversation
Every other setter routes host values through the placement helper (_bridge.upload); set_parameters passed the numpy array straight through, so on a device model upstream set_value!'s copyto! into a view of the device vector fell into the scalar path GPUArrays forbids: ModelError: Scalar indexing is disallowed. The new test needs hardware (the scalar-indexing guard only exists on a real device array), so it skips where nvidia-smi is absent, like test_cupy.py. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Model.set_parametersraisedModelError: Scalar indexing is disallowedon anybackend="cuda"model: it was the one setter passing its numpy array straight through, while every other setter routes host values through the placement helper (_bridge.upload, whose own comment names this exact trap). Upstreamset_value!doescopyto!into a view of the device parameter vector, and view-of-CuArray +PyArrayfalls to the generic elementwise path GPUArrays forbids.One-line fix: stage the values through
_b.uploadfirst, making the upstream copy device-to-device. On CPU this is the identity placement (one extra host copy of a parameter vector).Evidence (GV100 box; CI has no GPU, so the new test skips there):
tests/test_device_parameters.pyfails at exactly the reported error without the fix, passes with it (asserts the new values take numeric effect throughobjective, not merely that the call survives).set_parameters—test_parameters.py,test_accessors.py,test_cache.py— 29 passed, unchanged.ruff checkclean on both changed files.Found while measuring for #4 (the daemon design): live-instance parameter refresh is exactly this call, but it is a user-facing bug today independent of that work.
🤖 Generated with Claude Code