Skip to content

fix allocation counts for primals (plus _new_ frule)#843

Merged
yebai merged 8 commits intocopilot/fix-521d0edf-b6f3-4f8f-810a-9b67505ecccafrom
py
Nov 10, 2025
Merged

fix allocation counts for primals (plus _new_ frule)#843
yebai merged 8 commits intocopilot/fix-521d0edf-b6f3-4f8f-810a-9b67505ecccafrom
py

Conversation

@penelopeysm
Copy link
Collaborator

@penelopeysm penelopeysm commented Nov 9, 2025

This PR fixes failing allocation tests in #714 for a number of primal functions, such as sum(abs2, ::Vector) on 1.12, and rand(::AbstractRNG, Float64) on 1.10 / 1.11. It also fixes the allocs for forward-mode _new_.

YES, it's ugly.

Specifically, this avoids the reporting of spurious allocations by:

  1. using @allocations on 1.11, which Just Works;

  2. creating a closure on 1.12, which effectively does the same as interpolating the arguments with a package like BenchmarkTools, which is needed for sum(abs2, xs).

  3. manually splatting the varargs on all versions, which removes allocations which I believe are caused by something like incomplete specialisation. See for example https://discourse.julialang.org/t/specialization-on-vararg-of-types/108251 and also the following example:

using Random

vararg(f::F, x::Vararg{Any,N}) where {F,N} = nothing
vararg(randn, Xoshiro(468), Float64) # generate the specialisation
Base.specializations(@which vararg(randn, Xoshiro(468), Float64))
# -> Base.MethodSpecializations(MethodInstance for vararg(::typeof(randn), ::Xoshiro, ::Type))

explicit(f::F, x1::X1, x2::X2) where {F,X1,X2} = nothing
explicit(randn, Xoshiro(468), Float32) # generate the specialisation
Base.specializations(@which explicit(randn, Xoshiro(468), Float32))
# -> Base.MethodSpecializations(MethodInstance for explicit(::typeof(randn), ::Xoshiro, ::Type{Float32}))

Because Base.allocations is also a varargs function (https://github.com/JuliaLang/julia/blob/ba1e628ee49351af0b704afd2b2903d253bd3564/base/timing.jl#L485-L491), going via Base.allocations sometimes causes extra allocations (grr). So this PR also just inlines its definition into count_allocs.

Effectively, count_allocs is now a version of Base.allocations that uses a closure + explicit numbered arguments.


Note that I tested various combinations of BenchmarkTools and Chairmarks and I couldn't find a way to correctly get interpolations all the way down to 0, so I think this PR is legitimately the only way to correctly detect zero-allocation function calls. For example:

using BenchmarkTools
using Mooncake
function allocs()
    local f = Mooncake._new_
    local x = (Mooncake.TestResources.TypeStableMutableStruct{Float64}, 5.0, 4.0)
    display(@btime $f($x...))
    local closure = () -> f(x...)
    display(@btime $closure())
end
allocs() # 3, 3

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2025

Mooncake.jl documentation for PR #843 is available at:
https://chalk-lab.github.io/Mooncake.jl/previews/PR843/

@penelopeysm penelopeysm marked this pull request as draft November 9, 2025 21:05
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2025

Performance Ratio:
Ratio of time to compute gradient and time to compute function.
Warning: results are very approximate! See here for more context.

┌────────────────────────────┬──────────┬──────────┬─────────────┬─────────┬─────────────┬────────┐
│                      Label │   Primal │ Mooncake │ MooncakeFwd │  Zygote │ ReverseDiff │ Enzyme │
│                     String │   String │   String │      String │  String │      String │ String │
├────────────────────────────┼──────────┼──────────┼─────────────┼─────────┼─────────────┼────────┤
│                   sum_1000 │ 100.0 ns │      1.8 │         1.9 │     1.1 │        5.61 │   8.21 │
│                  _sum_1000 │ 941.0 ns │     6.64 │        1.01 │  1500.0 │        33.7 │   1.09 │
│               sum_sin_1000 │  6.55 μs │      2.5 │         1.4 │    1.69 │        10.3 │   2.21 │
│              _sum_sin_1000 │  5.22 μs │     3.09 │        2.19 │   274.0 │        13.2 │    2.5 │
│                   kron_sum │ 317.0 μs │     41.5 │        2.73 │    5.22 │       225.0 │   8.35 │
│              kron_view_sum │ 331.0 μs │     42.0 │        3.37 │    10.7 │       210.0 │   8.63 │
│      naive_map_sin_cos_exp │  2.13 μs │      2.4 │        1.41 │ missing │        7.17 │   2.37 │
│            map_sin_cos_exp │  2.17 μs │     2.66 │        1.42 │    1.55 │         6.0 │   2.32 │
│      broadcast_sin_cos_exp │  2.26 μs │     2.38 │        1.39 │    2.33 │        1.46 │   2.22 │
│                 simple_mlp │ 160.0 μs │     7.16 │        3.04 │    1.82 │        14.3 │    3.4 │
│                     gp_lml │ 189.0 μs │     10.7 │        2.43 │    4.68 │     missing │   7.63 │
│ turing_broadcast_benchmark │  1.87 ms │     4.53 │        3.25 │ missing │        27.8 │   2.49 │
│         large_single_block │ 380.0 ns │     4.53 │        2.03 │  4420.0 │        32.9 │   2.24 │
└────────────────────────────┴──────────┴──────────┴─────────────┴─────────┴─────────────┴────────┘

This fixes:
- `sum(abs2, randn(11))` on 1.12
- `rand(rng, Float64)` on 1.10 and 1.11
@penelopeysm penelopeysm mentioned this pull request Nov 10, 2025
6 tasks
@penelopeysm
Copy link
Collaborator Author

penelopeysm commented Nov 10, 2025

The TLDR of where I'm stuck is 1.12. Benchmarking with a closure, i.e.

clos = () -> f(x1, x2, x3)
clos()
Base.allocations(clos)

gives 0 allocations for sum(abs2, randn(10)), BUT gives 1 allocation for Mooncake._new_(Mooncake.TestResources.TypeStableMutableStruct{Float64}, 5.0, 4.0).

So, OK, remove the closure:

f(x1, x2, x3)
Base.allocations(f, x1, x2, x3)

and that gives 0 allocations for _new_ but 1 allocation for sum.

Obviously, we could fix this quickly by special casing _new_ but that feels wrong and I'd like to know when the closure is needed and when it isn't needed.

On top of that, a lot of this is surprisingly impossible to reproduce locally in a simple script. I can at least get it to fail reliably with act.

@Technici4n
Copy link
Collaborator

Did you look at the generated IR? That might provide some insights

@yebai
Copy link
Member

yebai commented Nov 10, 2025

Just a quick question — is there any particular reason we can’t continue using Base.@allocations, given that it hasn’t been removed?

@penelopeysm
Copy link
Collaborator Author

Did you look at the generated IR?

Yup, but it wasn't very helpful and also it's the same on 1.11 and 1.12 for _new_, so I think it's certainly just down to changes in the way allocations works.

is there any particular reason we can’t continue using Base.@allocations

I mostly took my cue from #714 (comment). Just tried it anyway, and no luck on 1.12:

@test (@allocations f(x...)) == 0
# Fails for both `_new_` and `sum`

pclos = () -> f(x...)
@test (@allocations pclos()) == 0
# Fails for `_new_` and `randn(Xoshiro(3), Float64)`

@penelopeysm
Copy link
Collaborator Author

Base.allocations itself is stuck behind a Vararg argument, so now I've inlined its definition, and it is looking good when I run this locally with act. Will see what CI says.

https://github.com/JuliaLang/julia/blob/ba1e628ee49351af0b704afd2b2903d253bd3564/base/timing.jl#L485-L491

@penelopeysm penelopeysm marked this pull request as ready for review November 10, 2025 15:26
@penelopeysm
Copy link
Collaborator Author

penelopeysm commented Nov 10, 2025

This should fix all the allocations now. Remaining issues are lacpy, dtrsv, and JET test.

I'll try to find an MWE for the Base.allocations issue with Varargs and file it upstream, although goodness knows I've struggled to reproduce this locally, so I'm not optimistic about the chances.

@penelopeysm penelopeysm requested a review from yebai November 10, 2025 15:38
@penelopeysm penelopeysm changed the title fix allocation counts for primals fix allocation counts for primals (plus _new_ frule) Nov 10, 2025
Copy link
Member

@yebai yebai left a comment

Choose a reason for hiding this comment

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

Thanks, @penelopeysm!

@yebai yebai merged commit c7f1073 into copilot/fix-521d0edf-b6f3-4f8f-810a-9b67505eccca Nov 10, 2025
122 of 130 checks passed
@yebai yebai deleted the py branch November 10, 2025 15:58
@penelopeysm
Copy link
Collaborator Author

penelopeysm commented Nov 10, 2025

I kind of think that this count_allocs should be in a standalone package 😄

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 58.06452% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/test_utils.jl 58.06% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

sunxd3 pushed a commit that referenced this pull request Nov 11, 2025
* Initial plan

* Add Julia v1.12 compatibility for BBCode and IR infrastructure

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add 'pre' version to CI workflow

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Fix inlining_policy function name for Julia v1.12+ compatibility and format code

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* CompatHelper: bump compat for JET in [weakdeps] to 0.10, (keep existing compat) (#691)

* CompatHelper: bump compat for JET in [weakdeps] to 0.10, (keep existing compat)

* Set tangent_type for AbstractLogger to NoTangent (#710)

* Initial plan

* Set tangent_type for Logging.ConsoleLogger to NoTangent

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Add ConsoleLogger test to verify AbstractLogger tangent type coverage

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add Base.CoreLogging.SimpleLogger to type union

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update test/tangents.jl

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add better error messages for tangent accessors when types are passed (#707)

* Initial plan

* Add better error messages for tangent accessors when types are passed

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Tidy up  (#715)

* Tidy up error-generating methods

* Remove redundant tests

* Remove more redundant test cases

* Bump patch version

* add rule for complex logdet (#664)

* working complex logdet

* bump version

* proper getrf! tests

* improve tests

* move tests

* generalize tests

* formatting and version

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Mateus Araújo <maltusan@gmail.com>
Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Delete .github/copilot-instructions.md (#722)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Uncomment b_binv_test_case for PlanarLayer (#727)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Add DiffEq integration test for Mooncake (#726)

* Initial plan

* Add DiffEq integration test with original example from issue

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Finalize DiffEq integration test with comprehensive structure

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Remove @info and @test_broken statements to reduce clutter

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* fix formatting (#728)

* Fix DiffEq integration test by restricting to reverse mode only (#731)

* Initial plan

* Fix DiffEq integration test by testing reverse mode only

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* formatting

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>

* Fix IR docs duplication and improve documentation structure (#718)

* Initial plan

* Update IR docs title and remove duplication, add comparison section

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Address PR feedback: update title and simplify Optics reference

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Restore IRCode field details that were incorrectly removed

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add robust Julia version-dependent JET version handling to CI workflow (#733)

* Fix changelog version (#693)

* remove `const M` (#696)

* remove const M

* fix formatting

* Update Project.toml

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update README.md (#697)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* minimal print io output (#699)

* minimal print

* vers bump

* remove prev tests

* include show in derived

* Update algorithmic_differentiation.md (#703)

I noticed a typo. I likely won't look at this again for a week or so, so please feel free to merge for me.

Signed-off-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>

* Fix 660 (#705)

* Fix + tests

* Bump patch version

* Use _stable_typeof directly

* Comment on the use of _stable_typeof

* Extend arrayify for complex numbers (#706)

* Fix + tests

* Bump patch version

* Use _stable_typeof directly

* Add arrayify tests

* Widen permitted types

* Bump patch version again

* Formatting

* Uncomment blas tests

* Create contribution guidelines in copilot-instructions.md (#713)

Added contribution guidelines for the automatic differentiation package.

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Set tangent_type for AbstractLogger to NoTangent (#710)

* Initial plan

* Set tangent_type for Logging.ConsoleLogger to NoTangent

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Add ConsoleLogger test to verify AbstractLogger tangent type coverage

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add Base.CoreLogging.SimpleLogger to type union

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update test/tangents.jl

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add better error messages for tangent accessors when types are passed (#707)

* Initial plan

* Add better error messages for tangent accessors when types are passed

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Tidy up  (#715)

* Tidy up error-generating methods

* Remove redundant tests

* Remove more redundant test cases

* Bump patch version

* add rule for complex logdet (#664)

* working complex logdet

* bump version

* proper getrf! tests

* improve tests

* move tests

* generalize tests

* formatting and version

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Mateus Araújo <maltusan@gmail.com>
Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Delete .github/copilot-instructions.md (#722)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Uncomment b_binv_test_case for PlanarLayer (#727)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Add DiffEq integration test for Mooncake (#726)

* Initial plan

* Add DiffEq integration test with original example from issue

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Finalize DiffEq integration test with comprehensive structure

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Remove @info and @test_broken statements to reduce clutter

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* fix formatting (#728)

* Fix DiffEq integration test by restricting to reverse mode only (#731)

* Initial plan

* Fix DiffEq integration test by testing reverse mode only

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* formatting

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>

* Fix IR docs duplication and improve documentation structure (#718)

* Initial plan

* Update IR docs title and remove duplication, add comparison section

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Address PR feedback: update title and simplify Optics reference

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Restore IRCode field details that were incorrectly removed

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Initial plan

* Add Julia version-dependent JET version selection to CI workflow

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Improve JET version handling to support complex constraints and remove need for explicit version on Julia 1.12+

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update CI.yml

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Signed-off-by: Mateus Araújo <maltusan@gmail.com>
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Co-authored-by: Astitva Aggarwal <84859349+AstitvaAggarwal@users.noreply.github.com>
Co-authored-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>
Co-authored-by: Mateus Araújo <maltusan@gmail.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Mateus Araújo <maltusan@gmail.com>
Signed-off-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>
Co-authored-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Co-authored-by: Mateus Araújo <maltusan@gmail.com>
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Co-authored-by: Astitva Aggarwal <84859349+AstitvaAggarwal@users.noreply.github.com>

* Prevent exporting names already declared as public

This is disallowed by the language and results in an error.

* Extend required interface CC.add_edges_impl!

* Adapt to stackless inference change (using CC.Future etc)

* Always return a boolean from `src_inlining_policy`

* Fix relocation of a few Experimental functions to CC

* Fix `_ir_abstract_constant_propagation` rename

* Adjust to `ir_abstract_constant_propagation` changes

* Support `invoke` CodeInstance arguments

* Adjust to opaque macro behavior change

* Define better slotnames for debugging

* Fix opaque closure construction

* Adjust to 1.12 opaque closure creation change

* More fixes

* Fix IRCode construction bug

* Adjust to binding changes for primal type extraction

* Rules for new intrinsics

* Set appropriate world bounds on the `CodeInfo`

* Optimize opaque closures

* Avoid failures on <1.12

* Don't attempt to set bounds if no inferred code is available

* More <1.12 fixes

* Don't optimize if IR interp can't be performed

* More fixes/tests

* Revert use of `Base.allocations`

It is not defined on <1.12, and the macro form seems fine.

* Fix bad line info information

* Make line info logic more robust, fix a few more things

* [WIP] add rules for `svec` and `_svec_len`

* Don't add _svec_len rule for < 1.12

* Try to avoid error in IRInterp

* Allow type unstability for `compute_oc_signature`

* Attempt to fix allocations

* Still use the same Tuple type for < 1.12

* Unconditionally set ir.argtypes[1] to an accurate Tuple

* Fix `primal_type` bug

* Fix construction error for IRCode

* Fix more issues

* Discard unwanted change

* Make version check static

* Add some @zero_derivatives for logging (#815)

* Mark Base.fixup_stdlib_path as having @zero_derivative

This comes up because in Julia 1.12 logmsg_code gets the folder of
Core.Compiler if needed to resolve paths, which results in a ccall
with no known rule. See
JuliaLang/julia#57274.

* Make Base.CoreLogging.handle_message_nothrow as having @zero_derivative

This comes up in logmsg_code, because in Julia v1.12
handle_message_nothrow got a try-catch structure, which creates an
UpsilonNode that Mooncake can't handle.

* Update avoiding_non_differentiable_code.jl

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* fix format

* Fix handle_message_nothrow @zero_derivative rule

* Improve a comment

* Fix duplicate svec rule after merge

* Remove JET version adjustment from CI workflow

Removed JET version adjustment step based on Julia version from CI workflow.

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Fix typo in 1.12-

* Also test buildkit and ext on 1.12?

* Use an eval to avoid duplicating BBCode

* Remove useless line (thanks Copilot)

* Update get_primal_type for GlobalRef

* Update isva comment

* Require Julia 1.12.1 or newer

* Fix stdin reference not working in 1.11

* Update patch_for_319 following Julia 1.12 changes

* Binding partitions are lazily populated!

* Set the IR's valid worlds to only the interpreter world (#832)

* Try to set the IR valid worlds to only the interpreter world

* Add explanation to set_valid_worlds!

* Tweak comment

* Update dispatch_doctor.jl

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Import _Utils from DispatchDoctor in tests

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* reformat

* Use a single world for inference

* Disable JET tests for Julia 1.12 temporarily.

Julia 1.12 has a few Base functions that are not type-stable, causing false-positive JET test failures in Mooncake.

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* re-enable JET test for Julia 1.12 and format.

* Mark compute_oc_signature as unstable

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Add documentation for resolve_unbound_globalrefs function

Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>

* Add unstable block for version-specific functions

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update allocation tests for Julia version compatibility

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update frule allocation tests for Julia version compatibility

* refactor count_allocs

* Update JET version to include 0.11 (#841)

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* fix allocation counts for primals (plus `_new_` frule) (#843)

* Fix allocation counters for `sum` and `rand` primals

This fixes:
- `sum(abs2, randn(11))` on 1.12
- `rand(rng, Float64)` on 1.10 and 1.11

* Use `eval` instead

* Fix for `_new_` (I think)

* Just get rid of the varargs in count_allocs

* Add a warning

* Fix all the horrible edge cases

* Final fixes (please don't let me down)

* Format

* Skip certain stability and performance tests for 1.12 (#844)

* Refactor stability rules for Float types in Julia

Updated stability and allocation rules for Float types based on Julia version.

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Remove Float16 cases from test cases

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update avoiding_non_differentiable_code.jl

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* reformat

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Clarify GlobalRef resolution docs

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Fix for TwicePrecision allocs (#845)

* Add rules for LAPACK.lacpy! and BLAS.trsv! (#839)

* Add rules for LAPACK.lacpy!

* LAPACK.lacpy! is exclusive to Julia 1.11+

* Add rule for BLAS.trsv!

* Isolate sensitive trsm! rule

---------

Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* re-enable F16, only F32 and F64 are type unstable on 1.12

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Update Project.toml

Co-authored-by: Markus Hauru <mhauru@turing.ac.uk>
Signed-off-by: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com>

---------

Signed-off-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Signed-off-by: Mateus Araújo <maltusan@gmail.com>
Signed-off-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Signed-off-by: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: yebai <3279477+yebai@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org>
Co-authored-by: Hong Ge <hg344@cam.ac.uk>
Co-authored-by: Will Tebbutt <3628294+willtebbutt@users.noreply.github.com>
Co-authored-by: Mateus Araújo <maltusan@gmail.com>
Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Co-authored-by: Astitva Aggarwal <84859349+AstitvaAggarwal@users.noreply.github.com>
Co-authored-by: serenity4 <cedric.bel@hotmail.fr>
Co-authored-by: Markus Hauru <mhauru@turing.ac.uk>
Co-authored-by: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com>
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