Skip to content

Disable argument preservation optimization#3017

Open
Pangoraw wants to merge 3 commits into
mainfrom
pb/disable-preserve-opt
Open

Disable argument preservation optimization#3017
Pangoraw wants to merge 3 commits into
mainfrom
pb/disable-preserve-opt

Conversation

@Pangoraw

@Pangoraw Pangoraw commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

we can see if there are potential unwanted side effects of disabling, and remove the optimization altogether if there are none.

But this optimization has caused a few issues in the past

Pangoraw and others added 3 commits June 30, 2026 02:12
The blunt `XLA_BYPASS_OPTIMIZATION` flag broke the clamp! test because
`maximum(x_ra)` started donating x_ra's buffer: with all block-arg results
forced into nresults, preserved_args_idx was always empty, making every arg
donated. XLA then rejected the already-donated clamp output with
"Donation requested for invalid buffer".

Replace the global bypass with two targeted checks:

1. Preserve a block-arg result only when `linear_results[i] === linear_args[arg_num+1]`
   (the result is the identical traced object as the arg at that MLIR position).
   Cross-arg aliasing — e.g. state.u⁰ capturing state.u's block arg — fails
   this identity check and is returned through XLA explicitly instead.

2. Collect `block_arg_outputs` (arg indices whose block arg appears directly in
   nresults) and skip donation for those args, preventing XLA from modifying
   the buffer in-place and corrupting the value being returned as the
   cross-arg output.

Also removes the now-unnecessary XLA_BYPASS_OPTIMIZATION Ref and reverts the
kernelabstractions filecheck pattern, which was loosened only because unchanged
args were no longer preserved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@wsmoses wsmoses left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we have this as an optional optimization, rather than full disable rn?

@Pangoraw

Pangoraw commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

hitting test failures with an unconditional deactivation of the optimization due to #3023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants