Skip to content

Support mutable operations (set, swap, addupdate) on ReshapeTransform and BitcastTransform views during state discharge. - #40310

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_972069536
Aug 28, 2026
Merged

Support mutable operations (set, swap, addupdate) on ReshapeTransform and BitcastTransform views during state discharge.#40310
copybara-service[bot] merged 1 commit into
mainfrom
test_972069536

Conversation

@copybara-service

Copy link
Copy Markdown

Support mutable operations (set, swap, addupdate) on ReshapeTransform and BitcastTransform views during state discharge.

Previously, ReshapeTransform and BitcastTransform were read-only during state discharge (ref_get). Attempting to mutate them via ref_set, ref_swap, or ref_addupdate failed with NotImplementedError because the write-back loop in transform_swap_array only handled NDIndexer. Additionally, the forward pass in transform_swap_array did not update the transformed value accumulator, which caused swap to return an un-transformed value.

This change:

  • Implements reverse transformations (.reshape(...) and bitcast(...)) during the write-back phase in transform_swap_array.
  • Rebinds new_val during the forward pass in transform_swap_array so swap returns the correctly transformed previous value.
  • Adds support for ReshapeTransform in _addupdate_discharge and explicitly disallows BitcastTransform on addupdate.
  • Adds unit tests in state_test.py covering set, swap, sliced view mutations, and addupdate on reshaped and bitcast views.
  • Adds test coverage in pallas_test.py verifying behavior under Pallas interpret mode and explicit NotImplementedError under Triton.
…ansform` and `BitcastTransform` views during state discharge.

Previously, `ReshapeTransform` and `BitcastTransform` were read-only during state discharge (`ref_get`). Attempting to mutate them via `ref_set`, `ref_swap`, or `ref_addupdate` failed with `NotImplementedError` because the write-back loop in `transform_swap_array` only handled `NDIndexer`. Additionally, the forward pass in `transform_swap_array` did not update the transformed value accumulator, which caused `swap` to return an un-transformed value.

This change:
* Implements reverse transformations (`.reshape(...)` and `bitcast(...)`) during the write-back phase in `transform_swap_array`.
* Rebinds `new_val` during the forward pass in `transform_swap_array` so `swap` returns the correctly transformed previous value.
* Adds support for `ReshapeTransform` in `_addupdate_discharge` and explicitly disallows `BitcastTransform` on `addupdate`.
* Adds unit tests in `state_test.py` covering set, swap, sliced view mutations, and addupdate on reshaped and bitcast views.
* Adds test coverage in `pallas_test.py` verifying behavior under Pallas interpret mode and explicit `NotImplementedError` under Triton.

PiperOrigin-RevId: 972845721
@copybara-service
copybara-service Bot merged commit fd3802e into main Aug 28, 2026
4 of 5 checks passed
@copybara-service
copybara-service Bot deleted the test_972069536 branch August 28, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant