Skip to content
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

Method ambiguities causing test failures in Julia 1.10+ #777

Closed
christiangnrd opened this issue Jan 27, 2024 · 1 comment · Fixed by JuliaDiff/ChainRulesCore.jl#657
Closed
Assignees

Comments

@christiangnrd
Copy link
Contributor

I was investigating the BitVector sum test errors on CI and it seems to be related to the method ambiguity test failure.

Upon further inspection, it seems like JuliaLang/julia#49349 is the PR that introduced this error.

test_rrule failure output:
julia> test_rrule(sum, randn(5) .> 0; fkwargs=(;dims=dims))
test_rrule: sum on BitVector: Error During Test at /Users/christian/.julia/packages/ChainRulesTestUtils/by7Dj/src/testers.jl:202
  Got exception outside of a @test
  MethodError: kwcall(::@NamedTuple{dims::Int64}, ::typeof(ChainRulesCore.rrule), ::typeof(sum), ::BitVector) is ambiguous.
  
  Candidates:
    kwcall(::NamedTuple, ::typeof(ChainRulesCore.rrule), ::typeof(sum), x::AbstractArray)
      @ ChainRules ~/.julia/packages/ChainRules/WToPR/src/rulesets/Base/mapreduce.jl:28
    kwcall(kwargs, ::typeof(ChainRulesCore.rrule), ::typeof(sum), var"508"::AbstractArray{Bool})
      @ ChainRules none:0
  
  Possible fix, define
    kwcall(::NamedTuple, ::typeof(ChainRulesCore.rrule), ::typeof(sum), ::AbstractArray{Bool})
  
  Stacktrace:
    [1] kwcall(::@NamedTuple{dims::Int64}, ::typeof(ChainRulesCore.rrule), ::ChainRulesTestUtils.TestConfig, ::Function, ::BitVector)
      @ ChainRulesCore ~/.julia/packages/ChainRulesCore/iaCWL/src/rules.jl:140
    [2] _args_and_call(::ChainRulesTestUtils.TestConfig, ::Vararg{Any}; kwargs::@Kwargs{dims::Int64})
      @ Test ~/julia/usr/share/julia/stdlib/v1.11/Test/src/Test.jl:1800
    [3] _test_inferred(::Any, ::Any, ::Vararg{Any}; kwargs...)
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/by7Dj/src/testers.jl:266
    [4] macro expansion
      @ ~/.julia/packages/ChainRulesTestUtils/by7Dj/src/testers.jl:210 [inlined]
    [5] macro expansion
      @ ~/julia/usr/share/julia/stdlib/v1.11/Test/src/Test.jl:1598 [inlined]
    [6] test_rrule(config::ChainRulesCore.RuleConfig, f::Any, args::Any; output_tangent::Any, check_thunked_output_tangent::Any, fdm::Any, rrule_f::Any, check_inferred::Bool, fkwargs::NamedTuple, rtol::Real, atol::Real, testset_name::Any, kwargs...)
      @ ChainRulesTestUtils ~/.julia/packages/ChainRulesTestUtils/by7Dj/src/testers.jl:205
    [7] #test_rrule#62
      @ ~/.julia/packages/ChainRulesTestUtils/by7Dj/src/testers.jl:178 [inlined]
    [8] top-level scope
      @ REPL[8]:1
    [9] eval
      @ ./boot.jl:428 [inlined]
   [10] eval_user_input(ast::Any, backend::REPL.REPLBackend, mod::Module)
      @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:224
   [11] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
      @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:320
   [12] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
      @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:305
   [13] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
      @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:461
   [14] run_repl(repl::REPL.AbstractREPL, consumer::Any)
      @ REPL ~/julia/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:447
   [15] (::Base.var"#1096#1098"{Bool, Symbol, Bool})(REPL::Module)
      @ Base ./client.jl:440
   [16] #invokelatest#2
      @ ./essentials.jl:1020 [inlined]
   [17] invokelatest
      @ ./essentials.jl:1017 [inlined]
   [18] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
      @ Base ./client.jl:424
   [19] repl_main
      @ ./client.jl:561 [inlined]
   [20] _start()
      @ Base ./client.jl:535
Test Summary:                | Error  Total  Time
test_rrule: sum on BitVector |     1      1  0.9s
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.
@oxinabox
Copy link
Member

Smaller MWE without CRTU

julia> rrule(sum, rand(4) .>0, dims=1)
ERROR: MethodError: kwcall(::@NamedTuple{dims::Int64}, ::typeof(rrule), ::typeof(sum), ::BitVector) is ambiguous.

Candidates:
  kwcall(::NamedTuple, ::typeof(rrule), ::typeof(sum), x::AbstractArray)
    @ ChainRules ~/JuliaEnvs/ChainRules.jl/src/rulesets/Base/mapreduce.jl:28
  kwcall(kwargs, ::typeof(rrule), ::typeof(sum), var"508"::AbstractArray{Bool})
    @ ChainRules none:0

Possible fix, define
  kwcall(::NamedTuple, ::typeof(rrule), ::typeof(sum), ::AbstractArray{Bool})

Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

If we look at the relevant methods via methodswith(typeof(sum))
we can track down the actual methods causing the problem. (rather than the kwarg methods)
The particular ones are

[19] rrule(::typeof(sum), var"508"::AbstractArray{Bool}) @ ChainRules ~/JuliaEnvs/ChainRules.jl/src/rulesets/Base/nondiff.jl:80
[24] rrule(::typeof(sum), x::AbstractArray; dims) @ ChainRules ~/JuliaEnvs/ChainRules.jl/src/rulesets/Base/mapreduce.jl:28`

I am wondering if something in the @non_differentiable macro is lacking

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 a pull request may close this issue.

2 participants