-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Data] support batch_format for Sort and Aggregate #48287
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b353f4f
[Data] support batch_format for Sort
xingyu-long 86af289
Remove batch_format at dataset level to address Scott's comments
xingyu-long 21eb19d
Add inherit_batch_format rule
xingyu-long 9e35188
Update tests to verify inherit_batch_format rule
xingyu-long e4f5009
address the comments
xingyu-long afeb03c
Use AbstractAllToAll instead of limiting to Sort and Aggregate
xingyu-long b92c5f6
add comments for test cases
xingyu-long 76d1dc1
Merge branch 'master' into issue_46748
scottjlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
python/ray/data/_internal/logical/rules/inherit_batch_format.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from collections import deque | ||
from typing import Iterable | ||
|
||
from ray.data._internal.logical.interfaces import LogicalOperator, LogicalPlan, Rule | ||
from ray.data._internal.logical.operators.all_to_all_operator import AbstractAllToAll | ||
from ray.data._internal.logical.operators.map_operator import MapBatches | ||
|
||
|
||
class InheritBatchFormatRule(Rule): | ||
"""For AbstractAllToAll based operator, apply this rule | ||
to inherit batch_format from upstream operator by traversing | ||
the entire DAG.""" | ||
|
||
def apply(self, plan: LogicalPlan) -> LogicalPlan: | ||
optimized_dag: LogicalOperator = self._apply(plan.dag) | ||
new_plan = LogicalPlan(dag=optimized_dag, context=plan.context) | ||
return new_plan | ||
|
||
def _apply(self, op: LogicalOperator): | ||
# Post-order traversal. | ||
nodes: Iterable[LogicalOperator] = deque() | ||
for node in op.post_order_iter(): | ||
nodes.appendleft(node) | ||
|
||
while len(nodes) > 0: | ||
current_op = nodes.pop() | ||
|
||
if isinstance(current_op, AbstractAllToAll): | ||
# traversal up the DAG until we find MapBatches with batch_format | ||
# or we reach to source op and do nothing | ||
upstream_op = current_op.input_dependencies[0] | ||
xingyu-long marked this conversation as resolved.
Show resolved
Hide resolved
|
||
while upstream_op.input_dependencies: | ||
if ( | ||
isinstance(upstream_op, MapBatches) | ||
and upstream_op._batch_format | ||
): | ||
current_op._batch_format = upstream_op._batch_format | ||
break | ||
upstream_op = upstream_op.input_dependencies[0] | ||
|
||
# just return the default op | ||
return op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's combine these 2 loops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking through the codebase, I was trying to use same coding style for this matter. it seems not worth it to combine? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't just blindly follow the patterns, these need to make sense, right?
What's the motivation for first collecting the nodes into a queue, instead of traversing the iterator directly?