Skip to content

Fix hook order inside while loop #1615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exla/lib/exla/defn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ defmodule EXLA.Defn do
) do
[initial_arg, _arg, pred, body] = args

{initial, cache} = recur_composite(initial_arg, state, cache)

initial =
if token = get_token(cache) do
Comment on lines +315 to 318
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to recur on initial_arg first and use the cached token. Currently we get the token first, so it doesn't account for all the prior computation.

{token, initial_arg}
[token | initial]
else
initial_arg
initial
end

{initial, cache} = recur_composite(initial, state, cache)

{pred_computation, cache} = mlir_while_computation(pred, initial, {:pred, 8}, state, cache)
{body_computation, cache} = mlir_while_computation(body, initial, :with_token, state, cache)

Expand Down
Loading