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

@non_differentiable _denom #687

Merged
merged 5 commits into from
Jan 11, 2023
Merged

@non_differentiable _denom #687

merged 5 commits into from
Jan 11, 2023

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Dec 21, 2022

Fixes this:

julia> Zygote.hessian_reverse(x -> sum(sin, mean(x.^2; dims=1)), [1 2; 3 4.0])  # Int
4×4 Matrix{Float64}:
 1.24259  2.87677  0.0      0.0
 2.87677  8.91398  0.0      0.0
 0.0      0.0      1.33701  4.35217
 0.0      0.0      4.35217  7.86527

julia> Zygote.hessian_reverse(x -> sum(sin, mean(x.^2; dims=[1])), [1 2; 3 4.0])  # Vector
4×4 Matrix{Float64}:
 1.24259  2.87677  0.0      0.0
 2.87677  8.91398  0.0      0.0
 0.0      0.0      1.33701  4.35217
 0.0      0.0      4.35217  7.86527

julia> Zygote.hessian_reverse(x -> sum(sin, mean(x.^2; dims=(1,))), [1 2; 3 4.0])  # Tuple
ERROR: Mutating arrays is not supported -- called push!(Vector{Int64}, ...)
...
Stacktrace:
...
  [5] unique
    @ ./set.jl:176 [inlined]
  [6] (::typeof((unique)))(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/SmJK6/src/compiler/interface2.jl:0
  [7] _denom
    @ ~/.julia/packages/ChainRules/hVHC4/src/rulesets/Statistics/statistics.jl:7 [inlined]
  [8] (::typeof((_denom)))(Δ::Float64)
    @ Zygote ~/.julia/packages/Zygote/SmJK6/src/compiler/interface2.jl:0
  [9] #rrule#1801
    @ ~/.julia/packages/ChainRules/hVHC4/src/rulesets/Statistics/statistics.jl:13 [inlined]
 [10] (::typeof((#rrule#1801)))(Δ::Tuple{Matrix{Float64}, NamedTuple{(:n, :sum_pullback), Tuple{Float64, Nothing}}})

Edit: Also adds some Zero paths which seem necc. for FluxML/Zygote.jl#1328.

And a trivial foreach case, for FluxML/Zygote.jl#1297

@mcabbott mcabbott merged commit 4ee4ef5 into main Jan 11, 2023
@mcabbott mcabbott deleted the mcabbott-patch-3 branch January 11, 2023 00:46
@oxinabox
Copy link
Member

@mcabbott per colprac

PRs must have 1 approval before they are merged.

You can always ping me on Julia slack if you ware waiting for approval on something.
(I get too many github notifications right now to always keep up with them)

@oxinabox
Copy link
Member

This seems fine though
Ideally we wouldn't need those zero paths, since Zygote should be dropping them anyway, but its no big deal to have them

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