FluxML/Zygote.jl

fastmath support

Fechada

#90 aberto em 6 de mar. de 2019

 (2 comentários) (0 reação) (0 responsável)Julia (220 forks)batch import
help wanted

Métricas do repositório

Stars
 (1.568 estrelas)
Métricas de merge de PR
 (Mesclagem média 2d 16h) (39 fundiu PRs em 30d)

Description

julia> foo(x) = 2.0x
foo (generic function with 1 method)

julia> bar(x) = @fastmath 2.0x
bar (generic function with 1 method)

julia> Zygote.derivative(foo, 1e6)
2.0

julia> Zygote.derivative(bar, 1e6)
ERROR: Non-differentiable function IntrinsicFunction
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] (::Zygote.Pullback{Tuple{Core.IntrinsicFunction,Float64,Float64},Tuple{Core.IntrinsicFunction}})(::Int8) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface2.jl:0
 [3] mul_fast at ./fastmath.jl:163 [inlined]
 [4] (::Zygote.Pullback{Tuple{typeof(Base.FastMath.mul_fast),Float64,Float64},Tuple{Zygote.Pullback{Tuple{Core.IntrinsicFunction,Float64,Float64},Tuple{Core.IntrinsicFunction}}}})(::Int8) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface2.jl:0
 [5] bar at ./REPL[55]:1 [inlined]
 [6] (::Zygote.Pullback{Tuple{typeof(bar),Float64},Tuple{getfield(Zygote, Symbol("##265#back#163")){getfield(Zygote, Symbol("#back#162")){:mul_fast,Zygote.Context,Module,typeof(Base.FastMath.mul_fast)}},Zygote.Pullback{Tuple{typeof(Base.FastMath.mul_fast),Float64,Float64},Tuple{Zygote.Pullback{Tuple{Core.IntrinsicFunction,Float64,Float64},Tuple{Core.IntrinsicFunction}}}}}})(::Int8) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface2.jl:0
 [7] (::getfield(Zygote, Symbol("##73#74")){Zygote.Pullback{Tuple{typeof(bar),Float64},Tuple{getfield(Zygote, Symbol("##265#back#163")){getfield(Zygote, Symbol("#back#162")){:mul_fast,Zygote.Context,Module,typeof(Base.FastMath.mul_fast)}},Zygote.Pullback{Tuple{typeof(Base.FastMath.mul_fast),Float64,Float64},Tuple{Zygote.Pullback{Tuple{Core.IntrinsicFunction,Float64,Float64},Tuple{Core.IntrinsicFunction}}}}}}})(::Int8) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface.jl:38
 [8] gradient(::Function, ::Float64) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface.jl:44
 [9] derivative(::typeof(bar), ::Float64) at /home/chriselrod/.julia/packages/Zygote/wYgcz/src/compiler/interface.jl:47
 [10] top-level scope at REPL[57]:1

@fastmath is convenient for enabling the autovectorizer and contractions (ie, fma instructions) on unrolled expressions. Would be nice to add mul_fast and friends.

Guia do colaborador