Skip to content

Fix set_parameters on device models - #5

Merged
sshin23 merged 1 commit into
mainfrom
fix/device-set-parameters
Aug 19, 2026
Merged

Fix set_parameters on device models#5
sshin23 merged 1 commit into
mainfrom
fix/device-set-parameters

Conversation

@sshin23

@sshin23 sshin23 commented Aug 18, 2026

Copy link
Copy Markdown
Member

Model.set_parameters raised ModelError: Scalar indexing is disallowed on any backend="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). Upstream set_value! does copyto! into a view of the device parameter vector, and view-of-CuArray + PyArray falls to the generic elementwise path GPUArrays forbids.

One-line fix: stage the values through _b.upload first, 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.py fails at exactly the reported error without the fix, passes with it (asserts the new values take numeric effect through objective, not merely that the call survives).
  • CPU selections touching set_parameterstest_parameters.py, test_accessors.py, test_cache.py — 29 passed, unchanged.
  • ruff check clean 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

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>
@sshin23
sshin23 merged commit 3258018 into main Aug 19, 2026
12 checks passed
@sshin23
sshin23 deleted the fix/device-set-parameters branch August 19, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant