-
Notifications
You must be signed in to change notification settings - Fork 89
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
FastMath operations #174
Comments
if we wanted to do the simplest swap for DiffRules, then probably requires JuliaDiff/ChainRulesCore.jl#127 |
I would not do it that way, and we don't really need to. We can just metaprogram them out directly inside ChainRules. |
For reference the following almost works. Create a new file called .e.g using ChainRulesCore
src_code = String(read(joinpath(@__DIR__, "base.jl")))
src_code = "begin $src_code end"
src_ast = Meta.parse(src_code)
block_asts = [x for x in src_ast.args if x isa Expr] # don't want anything that don't have subexpressions
transformed_asts_once = Base.FastMath.make_fastmath.(block_asts)
new_asts = transformed_asts_once[block_asts .!= transformed_asts_once]
expanded_asts = macroexpand.(Ref(@__MODULE__), new_asts)
transformed_asts = Base.FastMath.make_fastmath.(expanded_asts)
eval.(transformed_asts) because I don't think this is entirely an unreasonable way to do this. |
Perhaps as less horrifying way is to make a fastable_ast = quote
@scalar_rule ....
...
...
rule(::typeof...)
...
end
eval(Base.FastMath.makefast(fastable_ast)) # declare fastmath versions
eval(fastable_ast) # also the original nonfast versions (do this second incase mistakenly tranformed an orignal) That seems less scary, |
It would be good to have support for
@fastmath
, especially the functions thatccall
libm.Not sure if it's the right approach here, but in Zygote we did this by looping over the usual
DiffRules
.This is a bit of a blocker for FluxML/Zygote.jl#366, because we want to remove DiffRules as part of that, but currently doing so would cause a regression on this.
The text was updated successfully, but these errors were encountered: