Repository navigation
Use DataFrameIOLayer in DataFrame.from_delayed - #8852
Conversation
… to expand Blockwise to enable per-block dependencies
|
cc @ian-r-rose |
|
Excellent. Do you think this would drastically improve the scheduler time and memory requirement as well? |
|
Thanks for this @rjzamora, and sorry for being slow to take a look. This is cool! I'm struggling a bit with the design here -- in particular, I'm worried about adding yet more complexity to I took a crack at what this could look like without modifying But perhaps there is still a way to get the dependency information needed off of |
|
@ian-r-rose - Thanks for taking a look at this! (sorry for the delay - I was off last week)
Yep - That is pretty much the same process I went through :)
I'll probably try to give this another go today or tomorrow, but I'm still very open to suggestions (note that I left this as "Draft", because I was still hoping I had missed something obvious). I do think it is also worth sharing that I see this kind of improvement as a way to reduce the number of cases we need to explicitly optimize/support in
Moving This leads me to your question @rajeee - I do expect this change to improve memory requirements, but not necessarily for the original form of your stack-overflow question. As a result of point (2) above, you would need to also supply the |
Specifying division in the from_delayed isn't a big deal. I was kind of already doing that in the next line in my SO question. Let me know when this is sort of ready to test; I am very curious to test this on my dataset that was failing previously and see if it succeeds this time. |
Yeah, figured as much :). I played with another experiment here which more-or-less works by embedding the delayed All of this is in the service of trying to avoid giving |
Nice - Does this work when a list of |
I don't think so -- to be clear, I'm not really proposing the above, just playing around to try to understand the constraints better. Another variant (that I was hoping to avoid) would be to make core ddf = dask.dataframe.io.map_partitions(read_files, files_groups) |
|
@ian-r-rose - Got it. I share your motivation to move in the direction of simplicity :) For the case of building a collection from delayed/future objects, it really feels like we need to tweak
You make a good point that we could also consider implementing/pushing simpler alternatives to |
ian-r-rose
left a comment
There was a problem hiding this comment.
Thanks @rjzamora, I do like how this is getting simpler.
I think I'm coming around to your implementation, even if I don't understand everything yet.
| def valid(self) -> bool: | ||
| """Whether this object will return "valid" dependency keys. |
There was a problem hiding this comment.
Another way of writing this might be something along the lines of produces_keys, akin to produces_tasks. I know we are getting rid of produces_tasks, but to me it's a clearer way of communicating what this means.
There was a problem hiding this comment.
Okay - produces_tasks seems reasonable to me.
| valid_keys = product( | ||
| *( | ||
| list(range(nbi)) | ||
| for nbi in layers[layer].io_deps[k].numblocks | ||
| ) | ||
| ) | ||
| new_deps |= { | ||
| layers[layer].io_deps[k][valid_key] for valid_key in valid_keys | ||
| } |
There was a problem hiding this comment.
Am I wrong to be thinking that a simpler way to get the set of valid deps would be to read them off of full_graph.dependencies?
There was a problem hiding this comment.
Grr - I'm still trying to work this one out. We certainly can pull out the valid dependencies from the intial version of full_graph, but this can become tricky by the time we get to the final version of full_graph (since this function is called somewhat recursively).
There was a problem hiding this comment.
Okay - I think (hope) d7ca3f1 does what you had in mind. (Although, I may need to clean up the exact code I used)
There was a problem hiding this comment.
Thanks @rjzamora, that is what I had in mind.
I'm not 100% sure it's better, but to me it feels more idiomatic to not explicitly iterate over the keys for a non-materialized graph at this stage. What do you think?
There was a problem hiding this comment.
I do get the sense that it is better. It also seems like it is the "correct" thing to do even without the new produces_keys feature. For example, I am now realizing that we may be able to remove the block below it:
elif k not in io_names:
new_deps.add(k)because these dependencies should already be in new_deps as well.
There was a problem hiding this comment.
Yup. I was able to just replace the original Scratch that - Seems that we still need to handle some edge cases for now (rolling that second change back).new_deps logic by pulling the dependencies straight from full_graph.dependencies. This seems like a nice improvement over the original _optimize_blockwise code anyway (hope CI passes).
There was a problem hiding this comment.
Ah, bummer. Thanks for checking
ian-r-rose
left a comment
There was a problem hiding this comment.
Thanks @rjzamora, I'm happy with where this stands, and it wouldn't be too difficult to modify it down the line.
I don't fully see all the consequences of using fuse_roots like this. It's interesting: this is similar to where we were before from_array became blockwise.
| ) | ||
| + 1 | ||
| ) | ||
| # NOTE: Fusion requires `optimize_blockwise`` and `fuse_roots` |
There was a problem hiding this comment.
I hadn't really appreciated this. At the end of this, we are fully materialized. Are there cases where it would be a mistake to do that?
There was a problem hiding this comment.
This is a great point. I had honestly forgotten that fuse_roots will return a materialized Layer, but that makes sense. Although we may be able to rewrite fuse roots to avoid materialization, we may not get much out of that. What we really want is the graph to remain HLG when dsk.cull is called. So, perhaps we just want to move the cull operation to occur in between optimize_blockwise and fuse_roots? I'll throw up a small separate PR to check if this idea breaks anything :)
|
Thanks for the review @ian-r-rose - I'll plan to merge this later today if there aren't any other concerns. |
This PR rewrites the logic in
dask.dataframe.io.from_delayedto enable blockwise fusion withDelayedIO functions. Take the followingDelayed-based custom IO code for example:This code uses
pd.read_parquetdirectly to aggregate specific files in an input parquet dataset into a smaller number of files in an output dataset. With the current implementation offrom_delayed, this code results in the following "optimized" graph:Note that neither the delayed
read_filestasks nor the followingto-parquettasks are fused into the same task asfrom-delayed. This means different workers may end up running the read_files and to-parquet tasks for the same partition. After this PR, this problem is resolved:Note that the move to DataFrameIOLayer works for both
Delayedanddistributed.Futureobjects.TODO:
delayed/delayed_depsattribute design inBlockwiseDep