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
Duplicated computations with mixed array/dataframe delayed output #7545
A computation from a delayed call returning two outputs is done twice when one output is array and one output is a dataframe. Interestingly, if both outputs are arrays, or both outputs are dataframes, the duplication does not occur.
If the two outputs (one array, one dataframe) are fed to another delayed call, a computation on the output of that 2nd delayed call does not cause in the extra computation.
In the code below, compute is printed twice under 'Individually'.
What you expected to happen:
compute should be printed once under 'Individually'.
I've found that turning off optimization causes this problem to go away. The optimizer is somehow deciding to inline the calc computation when the outputs are mixed like this.
Thanks for the nice example @chrisroat, I'm able to reproduce the same behavior. Looking through dask.compute, we optimize each type of dask collection independently here:
That is, we optimize Dask arrays using the the default optimizer for Dask arrays, then optimize Dask DataFrames using the default optimizer for Dask DataFrames, etc. Since each of these optimization passes is done independently, when we are doing the array optimization the optimizer doesn't know that the calc function is being used elsewhere (in the Dask DataFrame computation) so low-level task fusion results in the calc function being inlined. The same thing also happens when the DataFrame optimizer runs too.
I don't necessarily have a good long-term fix for this at the moment, though as a temporary workaround you can try disabling low-level task fusion by setting the optimization.fuse.active configuration value to False. This is slightly better than disabling optimizations altogether.
cc'ing @crusaderky@madsbk who have thought about graph optimizations recently and may be interested in this (though no obligation)
Thanks for the tip on turning off fuse. I also found #7587 which is related, and maybe a duplicate from an implementation point of view - both issues might be solved by some sort of global optimization.
My graphs are pretty large, so I do rely on a lot of the optimization to avoid the scheduler falling over. I'm breaking up my pipelines to keep the graphs under 100k and avoid these issues.
Activity
chrisroat commentedon Apr 10, 2021
I've found that turning off optimization causes this problem to go away. The optimizer is somehow deciding to inline the calc computation when the outputs are mixed like this.
jrbourbeau commentedon Apr 12, 2021
Thanks for the nice example @chrisroat, I'm able to reproduce the same behavior. Looking through
dask.compute, we optimize each type of dask collection independently here:dask/dask/base.py
Lines 331 to 342 in 09862ed
That is, we optimize Dask arrays using the the default optimizer for Dask arrays, then optimize Dask DataFrames using the default optimizer for Dask DataFrames, etc. Since each of these optimization passes is done independently, when we are doing the array optimization the optimizer doesn't know that the
calcfunction is being used elsewhere (in the Dask DataFrame computation) so low-level task fusion results in thecalcfunction being inlined. The same thing also happens when the DataFrame optimizer runs too.I don't necessarily have a good long-term fix for this at the moment, though as a temporary workaround you can try disabling low-level task fusion by setting the
optimization.fuse.activeconfiguration value toFalse. This is slightly better than disabling optimizations altogether.cc'ing @crusaderky @madsbk who have thought about graph optimizations recently and may be interested in this (though no obligation)
chrisroat commentedon Apr 22, 2021
Thanks for the tip on turning off
fuse. I also found #7587 which is related, and maybe a duplicate from an implementation point of view - both issues might be solved by some sort of global optimization.My graphs are pretty large, so I do rely on a lot of the optimization to avoid the scheduler falling over. I'm breaking up my pipelines to keep the graphs under 100k and avoid these issues.