Skip to content

Investigate compute_as_if_collection for performance issues #8991

Closed

Description

@ian-r-rose

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.

Activity

  1. self-assigned this
    on Apr 27, 2022
  2. ian-r-rose commented on Apr 28, 2022

    @ian-r-rose
    CollaboratorAuthor

    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).

  3. ian-r-rose commented on May 9, 2022

    @ian-r-rose
    CollaboratorAuthor

    Closing as fixed, though we should revisit the fix and possibly tear it out when #8864 is in

  4. rjzamora commented on Jul 12, 2022

    @rjzamora
    Member

    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.

  5. ian-r-rose commented on Jul 13, 2022

    @ian-r-rose
    CollaboratorAuthor

    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.

  6. rjzamora commented on Jul 13, 2022

    @rjzamora
    Member

    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.

  7. rjzamora commented on Jul 13, 2022

    @rjzamora
    Member

    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.cull should 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions