Skip to content

@benchmark on ReverseDiff.gradient! gives a shorter time than the original function #102

@xukai92

Description

@xukai92
type LP
    lp::Union{Float64,ReverseDiff.TrackedReal}
end

lp = LP(0.0)

f2(x) = begin
    lp.lp = 0.0
    lp.lp = logpdf(Normal(0, 1), x[1])
    for i = 2:length(x)
        lp.lp += logpdf(Normal(x[i-1], 1), x[i])
    end
    lp.lp
end

f_tape2 = GradientTape(f2, (x))
compiled_f_tape2 = compile(f_tape2)
inputs = (x)
results = (similar(x))
;

@benchmark f2(x) # => mean=1.336ms
@benchmark ReverseDiff.gradient!(results, compiled_f_tape2, x) # => mean=208.294 μs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions