-
Notifications
You must be signed in to change notification settings - Fork 12
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
Repeated calls to replace! have quadratic complexity #142
Comments
Yes, it's a known issue and a notable historical artifact. Initially, Yota was designed to work with its custom rules that required only adding new operations onto the tape and not replacing anything. However, with ChainRules we have to replace a single operation: %2 = foo(%1) with 3 operations: %2 = rrule(foo, %1)
%3 = getfield(%2, 1)
%4 = getfield(%2, 2) Since variable IDs change, we need to To avoid this effect, we should either drop ChainRules, or at least redesign tape to support multiple output variables. Unfortunately, both of these options are unrealistic at this point of development. |
Thanks, for now I have my
in the |
True! I experimented with a single-pass AD for some time, but eventually decided to keep them separate because of corner cases. For example, Julia has a pretty special way to represent vararg functions: julia> foo(xs) = print(xs...)
foo (generic function with 2 methods)
julia> Umlaut.getcode(foo, (Vector{Float64},))
1 1 ─ %1 = Core._apply_iterate(Base.iterate, Main.print, _2)::Core.Const(nothing)
│
└── return %1 Usually, you don't want to handle things like julia> trace(foo, [1, 2, 3.0])
1.02.03.0(nothing, Tape{Umlaut.BaseCtx}
inp %1::typeof(foo)
inp %2::Vector{Float64}
%3 = check_variable_length(%2, 3, 2)::Nothing
%4 = __to_tuple__(%2)::Tuple{Float64, Float64, Float64}
%5 = getfield(%4, 1)::Float64
%6 = getfield(%4, 2)::Float64
%7 = getfield(%4, 3)::Float64
%8 = print(%5, %6, %7)::Nothing
) But if you override too many of the "internal" functions like On the other hand, you don't to cover all corner cases, so you have good chances to get it done! |
Yota.jl/src/grad.jl
Line 152 in 54dc712
This is because the remainder of the band is rewritten every time if I understand correctly. Maybe there is a potential efficiency gain here. Ignore if already considered
The text was updated successfully, but these errors were encountered: