fix(exla): use per-partition device id when preparing shard_jit input buffers - #1833
Merged
Merged
Conversation
… buffers EXLA.MLIR.Module.compile/5 sets executable.device_id to -1 for sharded (SPMD) executables, since they are not pinned to one device. maybe_outfeed passed that -1 straight into EXLA.Defn.Buffers.from_nx!/2, which compares it against each input buffer's device id and, on a mismatch, calls EXLA.DeviceBuffer.copy_to_device/3 with device_id -1. The NIF rejects -1, raising "No matching device found for device_id -1" any time a shard_jit input tensor already lived on an EXLA device (e.g. default_backend set to EXLA.Backend) instead of Nx.BinaryBackend. from_nx!/4 now takes the real target device id for the buffer it is preparing. maybe_outfeed passes each partition's index as that id when the run is sharded, matching PjRt's default per-partition device assignment, and keeps using executable.device_id otherwise. Added a regression test in sharding_test.exs that reproduces the crash with EXLA.Backend-resident inputs and checks the fix returns correct per-partition results with the right device ids.
Replaces the two optional positional args (transfer?, target_device_id) with a single opts list, so call sites read as flags instead of bare booleans/nils.
polvalente
force-pushed
the
fix/exla-shard-jit-device-id-bug
branch
from
September 10, 2026 20:24
fd2160f to
cc8266c
Compare
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.
EXLA.MLIR.Module.compile/5 sets executable.device_id to -1 for sharded
(SPMD) executables, since they are not pinned to one device. maybe_outfeed
passed that -1 straight into EXLA.Defn.Buffers.from_nx!/2, which compares
it against each input buffer's device id and, on a mismatch, calls
EXLA.DeviceBuffer.copy_to_device/3 with device_id -1. The NIF rejects -1,
raising "No matching device found for device_id -1" any time a shard_jit
input tensor already lived on an EXLA device (e.g. default_backend set to
EXLA.Backend) instead of Nx.BinaryBackend.
from_nx!/4 now takes the real target device id for the buffer it is
preparing. maybe_outfeed passes each partition's index as that id when
the run is sharded, matching PjRt's default per-partition device
assignment, and keeps using executable.device_id otherwise.
Added a regression test in sharding_test.exs that reproduces the crash
with EXLA.Backend-resident inputs and checks the fix returns correct
per-partition results with the right device ids.