Repository navigation
mps: index_put_ (x[int_index] = v) on Metal with a device-side bounds check - #104
Merged
Merged
Conversation
…de bounds check index_put_ was on MPS_HOST_READBACK_OPS: its kernel read back, and candle's Metal scatter/index_add do not bounds-check. index_put_inplace now routes a cpu self to the old kernel (index_put_on_host) and any other device to index_put_on_device: int64 indices with negative wrap, broadcasting, None slots and index.Tensor's axis placement (the flat offsets are shared through a new index_flat_offsets); values broadcast to upstream's shape; a 0-dim cpu value is uploaded. - accumulate=True: one index_add on the (block, span) view. - accumulate=False: each source row's position is scattered (f32) into a -1 column, and the last row aimed at each destination is index_selected and where'd over self (no i64/u8 Metal scatter value kernel); exact below 2^24 positions, refused by name above. - #89's index_bounds_on_device runs before any write: out of range raises upstream cpu's IndexError text and leaves self unchanged. - Still refused by name: masks not shaped like self, int32 indices (this branch predates #100), an all-None index list. - MPS_HOST_READBACK_OPS 88 -> 87 (README, README_ko, STATUS.md). tests/devices/mps/test_mpsindexput.py (6): agreement with upstream mps (cpu recorded) incl. accumulate and a write through a view, exact downloads per call (1; 0 empty; 2 on raise), out-of-range parity, duplicates graded as "one of the values aimed at it" (upstream cpu and mps disagree on the winner). test_mpssetitem's int-index refusal became an agreement test. Red before: 5 of 6 failed. Nullified: dropping the bounds check let x[3] = ... write into a 3-row tensor where upstream raises (4 tests red). Gate (worktree): suites=138/138 ok=2139 FAIL=2, worktree environment only.
…7.21 - int32 index tensors now cast on the device (PR #100's i32 kernels): the Metal guard calling the deleted refuse_mps_int32_index is removed, and test_mpsindexput's int32 refusal row became an agreement row. - Conflicts: gate_suites.py keeps both new suites; matrix.md keeps develop's section 7.20 (int32) and renumbers this branch's index_put_ section to 7.21, with STATUS.md pointing there. - Writing into an int32 *self* (x_int32[idx] = v) still refuses by name: index_put_ is not in the int32 widened-op table. Rebuilt: test_mpsindexput 6/6, test_mpssetitem, test_mpsindex, test_mpsint32, test_metalplace, test_mpsclone, test_intmps, test_dtypedev, test_shim, test_remeasure2 ok. Gate (worktree): suites=139/139 ok=2146 FAIL=2, worktree environment only.
Contributor
Gate on CI (issue #24)Full gate: 139 suites = 131 run on at least one CI runner + 8 local-only. The local gate (
Local-only: verified by no CI runner (8)
Suites that verified nothing, or failed, on a runner
Every suite, every runner
A SKIP is unverified on that runner, never passed. UNVERIFIED means the suite ran and every one of its tests skipped by name. |
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.
Refs #32 (the write side of #89's index.Tensor). Gap left by #99 / PR #102:
w[int_index] = valueon mps refused by name.Feature added:
index_put_computes on Metal: int64 and int32 indices (int32 cast on device via #100's kernels), negative wrap, broadcasting,Noneslots and index.Tensor's axis placement (sharedindex_flat_offsets), values broadcast to upstream's shape, 0-dim cpu value uploaded.accumulate=Trueviaindex_add;accumulate=Falsevia a last-writer row map (exact below 2^24 positions, named refusal above). #89's device bounds check runs before any write: out of range raises upstream's IndexError and leavesselfunchanged. Downloads per call: 1 (0 empty, 2 on raise).MPS_HOST_READBACK_OPS88 -> 87.Still refused by name: masks not shaped like
self; an all-None index list; writing into an int32 self (index_put_is not in the int32 widened-op table).Test added:
tests/devices/mps/test_mpsindexput.py(6): agreement vs upstream mps (cpu recorded) incl. accumulate, int32 indices, a write through a view; exact download counts; out-of-range parity; duplicates graded as one-of-the-candidates (upstream cpu and mps disagree on the winner).test_mpssetitem's int-index refusal became an agreement test.Evidence (local, this Mac): red before: 5 of 6 failed. Nullified: dropping the bounds check let
x[3] = ...write into a 3-row tensor where upstream raises (4 tests red). After merging develop: 10 affected suites pass; gate 139/139 suites, ok=2146, FAIL=2 (worktree environment only). Docs: matrix.md §7.21.