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

error with BitVector #1086

Closed
CarloLucibello opened this issue Sep 29, 2021 · 1 comment · Fixed by #1089
Closed

error with BitVector #1086

CarloLucibello opened this issue Sep 29, 2021 · 1 comment · Fixed by #1089

Comments

@CarloLucibello
Copy link
Member

CarloLucibello commented Sep 29, 2021

julia> function f1(x)   
         mask = x .< 0.5
         sum(x .* (1 .- mask))
       end
f1 (generic function with 1 method)

julia> gradient(f1, rand(3))
ERROR: MethodError: no method matching -(::Nothing)
Closest candidates are:
  -(::Any, ::ChainRulesCore.ZeroTangent) at /home/carlo/.julia/packages/ChainRulesCore/8vlYQ/src/tangent_arithmetic.jl:118
  -(::Any, ::ChainRulesCore.NoTangent) at /home/carlo/.julia/packages/ChainRulesCore/8vlYQ/src/tangent_arithmetic.jl:78
  -(::Any, ::ChainRulesCore.NotImplemented) at /home/carlo/.julia/packages/ChainRulesCore/8vlYQ/src/tangent_arithmetic.jl:63
  ...
Stacktrace:
 [1] (::Zygote.var"#1022#1023"{Int64, BitVector})(Δ::Vector{Float64})
   @ Zygote ~/.julia/packages/Zygote/EPhp6/src/lib/broadcast.jl:75
 [2] (::Zygote.var"#3755#back#1024"{Zygote.var"#1022#1023"{Int64, BitVector}})(Δ::Vector{Float64})
   @ Zygote ~/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:59
 [3] Pullback
   @ ./REPL[31]:3 [inlined]
 [4] (::typeof((f1)))(Δ::Float64)
   @ Zygote ~/.julia/packages/Zygote/EPhp6/src/compiler/interface2.jl:0
 [5] (::Zygote.var"#50#51"{typeof((f1))})(Δ::Float64)
   @ Zygote ~/.julia/packages/Zygote/EPhp6/src/compiler/interface.jl:41
 [6] gradient(f::Function, args::Vector{Float64})
   @ Zygote ~/.julia/packages/Zygote/EPhp6/src/compiler/interface.jl:76
 [7] top-level scope
   @ REPL[32]:1

Without the - it works:

julia> function f2(x)   
         mask = x .< 0.5
         sum(x .* mask)
       end
f2 (generic function with 1 method)

julia> gradient(f2, rand(3))
([0.0, 0.0, 1.0],)
@DhairyaLGandhi
Copy link
Member

Try with an older version of zygote.

bors bot added a commit that referenced this issue Oct 2, 2021
1089: Fix broadcasting `-` with booleans  r=CarloLucibello a=mcabbott

Closes #1086

The issue is that `unbroadcast` collapses the gradient of a non-differentiable argument to `nothing`, Zygote's marker for such things, which the rule then tried to negate. (This is why CRC defines its own zero types for this purpose, instead of using nothing). I presume the original reason for `-unbroadcast(y, Δ)` not `unbroadcast(y, -Δ)` is to save an allocation when `y` is a scalar etc.

I did not see any other cases where further operations are done after `unbroadcast`. 

Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
bors bot added a commit that referenced this issue Oct 2, 2021
1089: Fix broadcasting `-` with booleans  r=mcabbott a=mcabbott

Closes #1086

The issue is that `unbroadcast` collapses the gradient of a non-differentiable argument to `nothing`, Zygote's marker for such things, which the rule then tried to negate. (This is why CRC defines its own zero types for this purpose, instead of using nothing). I presume the original reason for `-unbroadcast(y, Δ)` not `unbroadcast(y, -Δ)` is to save an allocation when `y` is a scalar etc.

I did not see any other cases where further operations are done after `unbroadcast`. 

Co-authored-by: Michael Abbott <32575566+mcabbott@users.noreply.github.com>
@bors bors bot closed this as completed in e9fa213 Oct 3, 2021
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