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

Fixes #111

Merged
merged 2 commits into from
Apr 22, 2022
Merged

Fixes #111

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Yota"
uuid = "cd998857-8626-517d-b929-70ad188a48f0"
authors = ["Andrei Zhabinski <andrei.zhabinski@gmail.com>"]
version = "0.7.2"
version = "0.7.3"

[deps]
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
Expand Down
7 changes: 2 additions & 5 deletions src/cr_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import Umlaut: make_name, Input, to_expr, BcastCtx

struct ChainRulesCtx end

@inline instance_type(f::F) where {F} = F
@inline instance_type(T::UnionAll) = Type{<:T}
@inline instance_type(T::DataType) = Type{T}

function isprimitive(::ChainRulesCtx, f, args...)
F = instance_type(f)
Args = instance_type.(args)
F = Core.Typeof(f)
Args = Core.Typeof.(args)
Core.Compiler.return_type(rrule, Tuple{YotaRuleConfig, F, Args...}) !== Nothing && return true
if is_kwfunc(F)
Args_kwrrule = Tuple{Any, typeof(Core.kwfunc(f)), YotaRuleConfig, Args...,}
Expand Down
7 changes: 6 additions & 1 deletion src/grad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function record_primitive!(tape::Tape{GradCtx}, v_fargs...)
rr_op = (is_kwfunc(f) ?
mkcall(Core.kwfunc(rrule), v_args[1], rrule, YOTA_RULE_CONFIG, v_args[2:end]...) :
mkcall(rrule, YOTA_RULE_CONFIG, v_f, v_args...))
@assert rr_op.val !== nothing "rrule($(op.fn), ...) returned nothing"
@assert rr_op.val !== nothing "rrule($f, ...) returned nothing"
v_rr = push!(tape, rr_op)
v_val = push!(tape, mkcall(_getfield, v_rr, 1))
v_pb = push!(tape, mkcall(_getfield, v_rr, 2))
Expand All @@ -70,6 +70,11 @@ struct BcastGradCtx
end


# get_static_params is broken for BcastGradCtx, so turning off
# this feature for now
Umlaut.get_static_params(::Tracer{BcastGradCtx}, v_fargs) = Core.svec([])


function record_or_recurse!(t::Tracer{BcastGradCtx}, v_fargs...)
fargs = [v isa V ? t.tape[v].val : v for v in v_fargs]
# global STATE = (t, v_fargs)
Expand Down
2 changes: 2 additions & 0 deletions test/test_cr_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ rrule(::YotaRuleConfig, ::typeof(primitive_test2), x; y=1) = primitive_test2(x;
@test val == 7
@test pb(1.0) == (ZeroTangent(), 2.0)

trace(broadcasted, double_dec, [1.0, 2.0])

rr = make_rrule(broadcasted, double_dec, [1.0, 2.0])
val, pb = rr(config, broadcasted, double_dec, [3.0, 4.0])
@test val == [5.0, 7.0]
Expand Down