Skip to content

Turn RunAttributor into a compile-time preference#3047

Open
vchuravy wants to merge 5 commits into
mainfrom
vc/prefs
Open

Turn RunAttributor into a compile-time preference#3047
vchuravy wants to merge 5 commits into
mainfrom
vc/prefs

Conversation

@vchuravy
Copy link
Copy Markdown
Member

Attributor yet again seems to be the cause of some illegal code transformation,
and I would like my last few days of investigating #3041 (comment) back.

This PR turns running it into an preference flag (so that folks who want it don't need to remember passing an environment flag),
but turns it off by default.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Benchmark Results

main d14a42b... main / d14a42b...
basics/make_zero/namedtuple 0.0535 ± 0.0018 μs 0.0527 ± 0.002 μs 1.02 ± 0.051
basics/make_zero/struct 0.273 ± 0.0056 μs 0.275 ± 0.0062 μs 0.992 ± 0.03
basics/overhead 5.87 ± 0.01 ns 4.03 ± 0.01 ns 1.46 ± 0.0044
basics/remake_zero!/namedtuple 0.225 ± 0.0075 μs 0.227 ± 0.0087 μs 0.991 ± 0.05
basics/remake_zero!/struct 0.229 ± 0.0094 μs 0.229 ± 0.012 μs 0.997 ± 0.067
fold_broadcast/multidim_sum_bcast/1D 10.2 ± 0.43 μs 10.3 ± 1.8 μs 0.994 ± 0.18
fold_broadcast/multidim_sum_bcast/2D 12.2 ± 0.29 μs 12.2 ± 0.3 μs 0.998 ± 0.034
time_to_load 1.07 ± 0.004 s 1.09 ± 0.028 s 0.982 ± 0.026

Benchmark Plots

A plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/25494080677/artifacts/6854668816.

@vchuravy
Copy link
Copy Markdown
Member Author

Sigh it seems necessary for 1.10 test to pass.

Comment thread src/preferences.jl Outdated
Comment thread src/preferences.jl Outdated
@vchuravy vchuravy requested a review from wsmoses April 28, 2026 14:42
Comment thread lib/EnzymeTestUtils/test/test_forward.jl Outdated
@wsmoses
Copy link
Copy Markdown
Member

wsmoses commented Apr 29, 2026

is there a reason for doing this since we already have the ref option?

I agree this is nicer, but technically breaking

@vchuravy
Copy link
Copy Markdown
Member Author

is there a reason for doing this since we already have the ref option?

Attributor is turned off already by default for 1.12 and as #3041 shows causes compilation issues that are really frustrating to debug in 1.11 (I spent ~4days trying to root cause that bug this week).

So yes as CI shows it sometimes does positive things, but it also continuously seems to create deeply frustrating bugs and I for one had enough of it.

@wsmoses
Copy link
Copy Markdown
Member

wsmoses commented Apr 30, 2026

oh I meant more in reference to it being a preference vs the current ref [not wrt the default or not].

we should look at the remaining failure with 1.11 when disabled. part of why its okay to turn off is ive been slowly making an "attributor lite" pass for our specific needs, though not as aggressive

@vchuravy
Copy link
Copy Markdown
Member Author

vchuravy commented May 6, 2026

oh I meant more in reference to it being a preference vs the current ref [not wrt the default or not].

I think that's fine. We are promoting it from an internal interface, to something more official and documented.

vchuravy and others added 5 commits May 7, 2026 13:51
Add src/preferences.jl with documented run_attributor() getter and
set_run_attributor!() setter, defaulting to false. Export both from
the top-level Enzyme module.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Document the attributor pass in faq.md with a description of what it
does, why it defaults to false, and how to use run_attributor() and
set_run_attributor!(). Add a basic test for the preference round-trip.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
Comment thread src/compiler/optimize.jl

const RunAttributor = Ref(VERSION < v"1.12")
import ..Enzyme: run_attributor
const RunAttributor = run_attributor()
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.

I really worry about making this change as there is a lot of code which modifies the ref atm downstream

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.

I also don't like the idea about this being a once-per-session setting

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also don't like the idea about this being a once-per-session setting

But it already is, due to caching if you set it inside the session you will get inconclusive results.

With this at least you can setup two projects and change the setting there.

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