Repository navigation
Support io_call and runtime_call inside a block body in EXLA - #1910
Merged
polvalente merged 3 commits intoNov 27, 2026
Merged
Conversation
An io_call or runtime_call inside the body of a block failed to compile. The body of a block is lowered as its own function, and the callback pid those calls need is an argument of the main function, so the call was built from a value of another function. The pid is now an argument of every block function. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Contributor
Author
|
ran into this while writing tests for a per-use recomputation version of checkpointing |
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
blasphemetheus
marked this pull request as ready for review
November 26, 2026 18:39
polvalente
approved these changes
Nov 27, 2026
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.
An
io_callorruntime_callinside the body of anNx.blockfails to compile on EXLA. This passes the callback pid into block functions so they compile and run.The problem
Nx.block/4wraps a group of operations under a struct, so a compiler can either replace the whole group with its own implementation or run the body as written.io_callruns an Elixir function on a value while a compiled function is executing, for example to print or log it.Each works on its own with EXLA. Together they do not:
With this change the last call prints the tensor 6 and returns it.
runtime_callinside a block body fails with the same error.Where it fails and where it does not
On main, with the host client:
io_callorruntime_callisdefnwhilebody or acondbranchwhileorcondOnly blocks that EXLA runs from their body are affected. The blocks built into Nx have no side effects in their bodies, so today this is reached by calling
Nx.block/4directly.Cause
EXLA compiles the body of a block as a separate function and calls it.
io_callandruntime_callneed the pid of the callback server as their first operand, and that pid is an argument of the main function only. The lowering inside the block function used the main function's pid, andEXLA.MLIR.Value.op/5rejects an operand that belongs to another function.whilebodies andcondbranches are regions of the function that contains them, so they can use its pid directly.The change
The pid becomes the first argument of every block function.
default_block_implementation/5passes it at the call:block_computation/5declares it in the signature and makes it the pid for the body:Block functions whose body has no side effect receive the argument and do not use it. Passing it only where it is needed would mean walking the body before building the function.
Not covered
Nx.Defn.Evaluatortreats anio_callthat names a hook differently when it is inside a block body:The evaluator runs a block body on concrete tensors, outside the traced expression, so the hooks given to
jitare not looked up there. That is a separate problem innxand is not changed here.Tests
Six tests in the
io_callsdescribe block ofexla/test/exla/defn/api_test.exs. Each fails on main:io_callinside a blockio_calls before, inside and after a block, received in program orderio_callin each of two blocksio_callinside a block insidewhileio_callinside a block inside the taken branch ofcondruntime_callinside a block🤖 Generated with Claude Code