-
Notifications
You must be signed in to change notification settings - Fork 10
Separate data and instruction #128
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
Conversation
This PR reduces the Integrate Test from 140-160 mins to about 100 mins. |
Tested locally or on the runners? EDIT: Benchmark below: #128 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand most of the code, but I like that the struct fields have clearer types
haskey(tf.bindings, :_1) && (tf.bindings[:_1].val = tf.func) | ||
for i in 1:length(args) | ||
slot = Symbol("_", i + 1) | ||
haskey(tf.bindings, slot) && (tf.bindings[slot].val = args[i]) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be faster if one could avoid looking up every key twice, once in haskey
and once in setindex!
.
One alternative would be to use get
with a default value such as a NoKeyFound()
singleton instead of haskey
(nothing
seems ambiguous for the arguments unfortunately). Another alternative would be to iterate over keys - but this would only work, or be efficient at least, if most keys are :_i
with <= length(args) + 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need an Option
or Maybe
type in Julia 😄
Here most keys in the Dict will not be :_i
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan is to replace to.bindings::Dict
with NamedTuple
in the next PR. So it probably won’t matter.
I simply read the time spent on github action, but it may be not so accurate due to the job concurrency and queue? |
You can see the time the IntegerateTest consumed here: https://github.com/TuringLang/Libtask.jl/actions/workflows/IntegrationTest.yml |
Nice. I can confirm that this PR is good for performance. I ran the following subset of the Turing tests ( [...]
include(pkgdir(Turing)*"/test/test_utils/AllUtils.jl")
using Logging
Logging.disable_logging(Logging.Info)
@testset "Turing" begin
@time include("inference/AdvancedSMC.jl")
@time include("inference/gibbs.jl")
@time include("contrib/inference/sghmc.jl")
@time include("stdlib/RandomMeasures.jl")
end
|
Mostly due to different CPUs. Not all runners use the same CPU and the difference in running time can be as big as 40%. |
I think the main reason behind this is that we now only need to copy the data(variables), and don't need to copy the instructions anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @KDr2 - nice improvements!
|
||
abstract type AbstractInstruction end | ||
abstract type Taped end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep this type for now - it’ll become useful again in future work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this moment, it only has one subtype: TapedFunction, so I removed it. And I think it's not hard to add it back when we need it.
But I'm OK to take it back now if you insist to do so 😄
haskey(tf.bindings, :_1) && (tf.bindings[:_1].val = tf.func) | ||
for i in 1:length(args) | ||
slot = Symbol("_", i + 1) | ||
haskey(tf.bindings, slot) && (tf.bindings[slot].val = args[i]) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan is to replace to.bindings::Dict
with NamedTuple
in the next PR. So it probably won’t matter.
I think it’s ready to merge when the CI passes. |
Implement #127 and #97.
The type info task will be in another PR.