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

TrackedStyle is broken for non-numeric tracked types #65

Open
mohamed82008 opened this issue Feb 17, 2020 · 0 comments
Open

TrackedStyle is broken for non-numeric tracked types #65

mohamed82008 opened this issue Feb 17, 2020 · 0 comments

Comments

@mohamed82008
Copy link
Collaborator

It seems that the implementation of ∇broadcast assumes that the arguments are not non-numeric tracked types. For example this fails:

julia> using Tracker

julia> f(x, y) = x.s * y; Tracker.gradient(x -> sum(f.([(s = x[1],)], x)), [1.0])
ERROR: MethodError: *(::Tracker.TrackedReal{Float64}, ::ForwardDiff.Dual{Nothing,Float64,1}) is ambiguous. Candidates:
  *(x::Real, y::ForwardDiff.Dual{Ty,V,N} where N where V) where Ty in ForwardDiff at C:\Users\user\.julia\packages\ForwardDiff\vt5F1\src\dual.jl:140
  *(a::Tracker.TrackedReal, b::Real) in Tracker at C:\Users\user\.julia\dev\Tracker\src\lib\real.jl:94
Possible fix, define
  *(::Tracker.TrackedReal, ::ForwardDiff.Dual{Ty,V,N} where N where V)
Stacktrace:
 [1] f(::NamedTuple{(:s,),Tuple{Tracker.TrackedReal{Float64}}}, ::ForwardDiff.Dual{Nothing,Float64,1}) at .\REPL[4]:1
 [2] partial(::typeof(f), ::Tracker.TrackedReal{Float64}, ::Int64, ::NamedTuple{(:s,),Tuple{Tracker.TrackedReal{Float64}}}, ::Float64) at C:\Users\user\.julia\dev\Tracker\src\lib\array.jl:505
 [3] _broadcast_getindex_evalf at .\broadcast.jl:630 [inlined]
 [4] _broadcast_getindex at .\broadcast.jl:603 [inlined]
 [5] getindex at .\broadcast.jl:563 [inlined]
 [6] copy at .\broadcast.jl:853 [inlined]
 [7] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(Tracker.partial),Tuple{Base.RefValue{typeof(f)},Array{Tracker.TrackedReal{Float64},1},Int64,Array{NamedTuple{(:s,),Tuple{Tracker.TrackedReal{Float64}}},1},Array{Float64,1}}}) at .\broadcast.jl:819
 [8] broadcast(::typeof(Tracker.partial), ::Base.RefValue{typeof(f)}, ::Array{Tracker.TrackedReal{Float64},1}, ::Int64, ::Vararg{Any,N} where N) at .\broadcast.jl:757
 [9] ∇broadcast at C:\Users\user\.julia\dev\Tracker\src\lib\array.jl:509 [inlined]
 [10] copy at C:\Users\user\.julia\dev\Tracker\src\lib\array.jl:540 [inlined]
 [11] materialize at .\broadcast.jl:819 [inlined]
 [12] #549 at C:\Users\user\.julia\dev\Tracker\src\lib\array.jl:513 [inlined]
 [13] ntuple at .\ntuple.jl:42 [inlined]
 [14] back at C:\Users\user\.julia\dev\Tracker\src\lib\array.jl:513 [inlined]
 [15] back_(::Tracker.Call{Tracker.var"#back#550"{2,typeof(f),Tuple{Array{NamedTuple{(:s,),Tuple{Tracker.TrackedReal{Float64}}},1},TrackedArray{,Array{Float64,1}}}},Tuple{Nothing,Tracker.Tracked{Array{Float64,1}}}}, ::Array{Tracker.TrackedReal{Float64},1}, ::Bool) at C:\Users\user\.julia\dev\Tracker\src\back.jl:35
 [16] back(::Tracker.Tracked{Array{Tracker.TrackedReal{Float64},1}}, ::Array{Tracker.TrackedReal{Float64},1}, ::Bool) at C:\Users\user\.julia\dev\Tracker\src\back.jl:58
 [17] foreach at C:\Users\user\.julia\dev\Tracker\src\back.jl:38 [inlined]
 [18] back_(::Tracker.Call{Tracker.var"#484#485"{TrackedArray{,Array{Tracker.TrackedReal{Float64},1}}},Tuple{Tracker.Tracked{Array{Tracker.TrackedReal{Float64},1}}}}, ::Tracker.TrackedReal{Float64}, ::Bool) at C:\Users\user\.julia\dev\Tracker\src\back.jl:38
 [19] back(::Tracker.Tracked{Tracker.TrackedReal{Float64}}, ::Int64, ::Bool) at C:\Users\user\.julia\dev\Tracker\src\back.jl:58
 [20] #back!#15 at C:\Users\user\.julia\dev\Tracker\src\back.jl:77 [inlined]
 [21] #back! at .\none:0 [inlined]
 [22] #back!#32 at C:\Users\user\.julia\dev\Tracker\src\lib\real.jl:16 [inlined]
 [23] back!(::Tracker.TrackedReal{Tracker.TrackedReal{Float64}}) at C:\Users\user\.julia\dev\Tracker\src\lib\real.jl:14
 [24] gradient_(::Function, ::Array{Float64,1}) at C:\Users\user\.julia\dev\Tracker\src\back.jl:4
 [25] #gradient#24 at C:\Users\user\.julia\dev\Tracker\src\back.jl:164 [inlined]
 [26] gradient(::Function, ::Array{Float64,1}) at C:\Users\user\.julia\dev\Tracker\src\back.jl:164
 [27] top-level scope at REPL[4]:1

Any tips on how to fix this?

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

No branches or pull requests

1 participant