Skip to content

Try to reduce overspecialization of annotations#3037

Open
kshyatt wants to merge 4 commits intomainfrom
ksh/annots
Open

Try to reduce overspecialization of annotations#3037
kshyatt wants to merge 4 commits intomainfrom
ksh/annots

Conversation

@kshyatt
Copy link
Copy Markdown
Collaborator

@kshyatt kshyatt commented Apr 8, 2026

Seems to have helped #3036 a little bit. Even the Fix2 version was not inheriting the @nospecialize...

@kshyatt kshyatt requested a review from vchuravy April 8, 2026 09:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Benchmark Results

main d2193df... main / d2193df...
basics/make_zero/namedtuple 0.055 ± 0.0056 μs 0.0558 ± 0.007 μs 0.986 ± 0.16
basics/make_zero/struct 0.253 ± 0.0082 μs 0.257 ± 0.0077 μs 0.982 ± 0.043
basics/overhead 5.92 ± 0.01 ns 4.54 ± 0.001 ns 1.3 ± 0.0022
basics/remake_zero!/namedtuple 0.232 ± 0.025 μs 0.231 ± 0.024 μs 1.01 ± 0.15
basics/remake_zero!/struct 0.233 ± 0.026 μs 0.23 ± 0.024 μs 1.01 ± 0.16
fold_broadcast/multidim_sum_bcast/1D 10.6 ± 0.49 μs 10.6 ± 2.2 μs 0.994 ± 0.21
fold_broadcast/multidim_sum_bcast/2D 13.1 ± 0.34 μs 13.1 ± 0.37 μs 0.999 ± 0.038
time_to_load 1.09 ± 0.0083 s 1.09 ± 0.012 s 0.998 ± 0.014

Benchmark Plots

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

@kshyatt
Copy link
Copy Markdown
Collaborator Author

kshyatt commented Apr 8, 2026

FWIW this took my compile trace from 22k lines to a mere 4k.

@wsmoses
Copy link
Copy Markdown
Member

wsmoses commented Apr 10, 2026

@vchuravy can you give this a review?

TT = Base.unwrap_unionall(TT0)
ft = TT.parameters[1]
tt = map(_annotate ∘ Base.Fix2(Base.rewrap_unionall, TT0), TT.parameters[2:end])
tt = []
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 this be Type[] ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let's try it!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looks like this won't work with either Type or TypeVar type hint to the vector 😞

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.

really, aren't all the results of _annotate, types though?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Some are TypeVar and some are Type apparently

@wsmoses
Copy link
Copy Markdown
Member

wsmoses commented Apr 14, 2026

@ptiede

Run julia --color=yes --project=test/integration/Comrade --threads=auto --check-bounds=yes -O1 test/integration/Comrade/runtests.jl
Run '/home/runner/k8s/index.js'
using script executor
Precompiling Comrade...
           ✗ VLBISkyModels
Info Given Comrade was explicitly requested, output will be shown live 
WARNING: could not import ComradeBase.m̆ into VLBISkyModels
ERROR: LoadError: UndefVarError: `m̆` not defined in `PolarizedTypes`
Stacktrace:
  [1] getproperty(x::Module, f::Symbol)
    @ Base ./Base.jl:42
  [2] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/models/polarized.jl:426
  [3] include(mod::Module, _path::String)
    @ Base ./Base.jl:562
  [4] include(x::String)
    @ VLBISkyModels ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:1
  [5] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/models/models.jl:30
  [6] include(mod::Module, _path::String)
    @ Base ./Base.jl:562
  [7] include(x::String)
    @ VLBISkyModels ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:1
  [8] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:70
  [9] include
    @ ./Base.jl:562 [inlined]
 [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2924
 [11] top-level scope
    @ stdin:6
in expression starting at /root/.julia/packages/VLBISkyModels/7tbdi/src/models/polarized.jl:426
in expression starting at /root/.julia/packages/VLBISkyModels/7tbdi/src/models/models.jl:30
in expression starting at /root/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:1
in expression starting at stdin:6
ERROR: LoadError: Failed to precompile VLBISkyModels [d6343c73-7174-4e0f-bb64-562643efbeca] to "/root/.julia/compiled/v1.11/VLBISkyModels/jl_wVhx13".
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool; flags::Cmd, cacheflags::Base.CacheFlags, reasons::Dict{String, Int64}, loadable_exts::Nothing)
    @ Base ./loading.jl:3217
  [3] (::Base.var"#1110#1111"{Base.PkgId})()
    @ Base ./loading.jl:2579

Failed to precompile Comrade [99d987ce-9a1e-4df8-bc0b-1ea019aa547b] to "/root/.julia/compiled/v1.11/Comrade/jl_882l4J".
WARNING: could not import ComradeBase.m̆ into VLBISkyModels
ERROR: LoadError: UndefVarError: `m̆` not defined in `PolarizedTypes`
Stacktrace:
  [1] getproperty(x::Module, f::Symbol)
    @ Base ./Base.jl:42
  [2] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/models/polarized.jl:426
  [3] include(mod::Module, _path::String)
    @ Base ./Base.jl:562
  [4] include(x::String)
    @ VLBISkyModels ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:1
  [5] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/models/models.jl:30
  [6] include(mod::Module, _path::String)
    @ Base ./Base.jl:562
  [7] include(x::String)
    @ VLBISkyModels ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:1
  [8] top-level scope
    @ ~/.julia/packages/VLBISkyModels/7tbdi/src/VLBISkyModels.jl:70
  [9] include
    @ ./Base.jl:562 [inlined]
 [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2924
 [11] top-level scope
    @ stdin:6

@ptiede
Copy link
Copy Markdown
Collaborator

ptiede commented Apr 14, 2026

Yes need a quick patch fix

@kshyatt
Copy link
Copy Markdown
Collaborator Author

kshyatt commented Apr 17, 2026

Any updates here?

@ptiede
Copy link
Copy Markdown
Collaborator

ptiede commented Apr 17, 2026

Ok so this actually had been patched already. The problem is that I also had to put that hard upper bound on Enzyme because Comrade is broken on the newer versions (see #2873). So some versions are getting mixed up. I'd ignore the Comrade failure for now because it is already broken.

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.

3 participants