You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate compute_as_if_collection for performance issues #8991
Over here we identified a case where writing a dataframe to_parquet with compute=True resulted in much slower (~10x) write times compared to compute=False, then calling compute() on the resulting scalar.
Those two different code paths were more different than they needed to be, with one using dask.base.compute_as_if_collection, and the other using a dd.Scalar directly. In #8982 we consolidated those two code paths to just use Scalar, and this seemingly fixed the issue. However, it's still concerning that compute_as_if_collection had such poor performance: this is used in a number of places throughout the codebase. It could be that there are some optimizations that are not surviving the process.
Opening this issue to track follow-up investigations to #8982.
I'm turning in for the evening, so I'm not doing a full writeup, but I'm reasonably sure that this is a bug in HighLevelGraph.cull, specifically having to do with known_key_dependencies. The computed dependencies there seem to be overly coupled and result in bad scheduling/more stuff in memory. The regular compute=False code path was (accidentally) deleting known_key_dependencies, which means that any errors in them weren't affecting scheduling. But the compute=True code path lets the bad dependencies through, and things start to go poorly.
Funnily enough, #8965 also (inadvertently?) deletes known_key_dependencies, so this issue doesn't appear there either.
HighLevelGraphs are currently undergoing some examination/redesign (cf. #8980), so I suppose we can add this to the list of things to look into (maybe removing the concept of known_key_dependencies all together).
Just leaving a note here that I am exploring changes to fuse_roots, and test_gh_8991 passes when culling is performed before fuse_roots.
Interesting! I wonder if it is for a similar reason as the above. Does fuse_roots drop existing known_key_dependencies? If those dependencies are bad, then it would be accidentally avoiding the issue as above.
Interesting! I wonder if it is for a similar reason as the above. Does fuse_roots drop existing known_key_dependencies? If those dependencies are bad, then it would be accidentally avoiding the issue as above.
Yes - Didn't dig in here much yet, but the basic reason seems to be that fuse_roots always returns HighLevelGraph(layers, dependencies) (even when the actual optimization is skipped). This essentially means that fuse_roots will always drop the known_key_dependencies calculated by cull.
It seems to me like the real problem here is indeed in HighLevelGraph.cull, where the culled_deps output of layer.cull is being used to update a dictionary that is then used to initialize key_dependencies in the new HighLevelGraph object.
The problem is that the culled_deps output of layer.cullshould not be used to populate HighLevelGraph.key_dependencies in the general case, because culled_deps simply encodes which input keys are required for the Layer to produce each output key (which is not (necessarily) the same as direct key dependencies). For example, SimpleShuffleLayer.cull will simply return a dictionary encoding the fact that each output key of the shuffle depends on every output key of the previous Layer. This is different from the low-level dependency graph needed for scheduling, and is only the same if the Layer materializes into a simple dictionary containing a single task for every output key (not the case for a shuffle).
Activity
ian-r-rose commentedon Apr 28, 2022
I'm turning in for the evening, so I'm not doing a full writeup, but I'm reasonably sure that this is a bug in
HighLevelGraph.cull, specifically having to do withknown_key_dependencies. The computed dependencies there seem to be overly coupled and result in bad scheduling/more stuff in memory. The regularcompute=Falsecode path was (accidentally) deletingknown_key_dependencies, which means that any errors in them weren't affecting scheduling. But thecompute=Truecode path lets the bad dependencies through, and things start to go poorly.Funnily enough, #8965 also (inadvertently?) deletes
known_key_dependencies, so this issue doesn't appear there either.HighLevelGraphs are currently undergoing some examination/redesign (cf. #8980), so I suppose we can add this to the list of things to look into (maybe removing the concept of
known_key_dependenciesall together).ian-r-rose commentedon May 9, 2022
Closing as fixed, though we should revisit the fix and possibly tear it out when #8864 is in
rjzamora commentedon Jul 12, 2022
Just leaving a note here that I am exploring changes to
fuse_roots, andtest_gh_8991passes when culling is performed beforefuse_roots.ian-r-rose commentedon Jul 13, 2022
Interesting! I wonder if it is for a similar reason as the above. Does
fuse_rootsdrop existingknown_key_dependencies? If those dependencies are bad, then it would be accidentally avoiding the issue as above.rjzamora commentedon Jul 13, 2022
Yes - Didn't dig in here much yet, but the basic reason seems to be that
fuse_rootsalways returnsHighLevelGraph(layers, dependencies)(even when the actual optimization is skipped). This essentially means thatfuse_rootswill always drop theknown_key_dependenciescalculated bycull.rjzamora commentedon Jul 13, 2022
It seems to me like the real problem here is indeed in
HighLevelGraph.cull, where theculled_depsoutput oflayer.cullis being used to update a dictionary that is then used to initializekey_dependenciesin the newHighLevelGraphobject.The problem is that the
culled_depsoutput oflayer.cullshould not be used to populateHighLevelGraph.key_dependenciesin the general case, becauseculled_depssimply encodes which input keys are required for the Layer to produce each output key (which is not (necessarily) the same as direct key dependencies). For example,SimpleShuffleLayer.cullwill simply return a dictionary encoding the fact that each output key of the shuffle depends on every output key of the previous Layer. This is different from the low-level dependency graph needed for scheduling, and is only the same if the Layer materializes into a simple dictionary containing a single task for every output key (not the case for a shuffle).