Libtask.jl
Libtask.jl copied to clipboard
Questions About Semantics
There are several tests that surprised me, and I would like to know why the semantics chosen are the correct ones.
Firstly, https://github.com/TuringLang/Libtask.jl/blob/6264afd33f9441697d2f5ed4a75bbcc37f15feba/test/tape_copy.jl#L47 . This test stipulates that Dicts ought not to be deepcopyed when tasks are copied. Why is this?
Same thing here. Why are Refs not deepcopyed? https://github.com/TuringLang/Libtask.jl/blob/6264afd33f9441697d2f5ed4a75bbcc37f15feba/test/tape_copy.jl#L116
. This test stipulates that Dicts ought not to be deepcopyed when tasks are copied. Why is this?
Same thing here. Why are Refs not deepcopyed?
IIRC, There isn't a reason for that other than we couldn't find a robust way to deepcopy them earlier.
cc @KDr2
Oh, interesting. I had wondered if there's some semantic reason -- the "ref atomic" test made me wonder if the point is that you want Refs to behave differently from other mutable types. Interested to see what @KDr2 's thoughts are.
The current(default) behavior:
Refis deep copiedArrayis deep copiedDictis NOT deep copied- All other types are NOT deep copied
This default behavior is set following the behavior of the old version of Libtask when we have our own Ref and Array type implemented in it.
However, this setting can be customized(except Ref and Array are always deep copied):
ttask = TapedTask(f, 0; deepcopy_types=Dict) will make the Dict values deep copied.
Ahhh interesting, okay.
@yebai do you know if we rely on not deepcopying anywhere in AdvancedPS.jl / Turing.jl?
I’d suggest we have the option to maintain the current behaviour to avoid surprises, but I am unaware of specific reasons for not deep copying everything by default
edit: VarInfo passed to models should not be deepcopied I think.
edit: VarInfo passed to models should not be deepcopied I think.
Why is this? Given that it defines the state of each model, I would have thought you would definitely want a completely independent copy on each task. I must be missing something...