Skip to content

Introduce aggressive merge to CapabilityPartitioner#100195

Closed
seanlatias wants to merge 3 commits intopytorch:mainfrom
seanlatias:partitioner
Closed

Introduce aggressive merge to CapabilityPartitioner#100195
seanlatias wants to merge 3 commits intopytorch:mainfrom
seanlatias:partitioner

Conversation

@seanlatias
Copy link
Copy Markdown
Contributor

With the old partitioner, suppose add is supported, the following code

def fn(a, b, c, d):
    x = a + b # add
    y = c + d # add_1
    return (x, y)

traced = symbolic_trace(fn)
partitioner = CapabilityBasedPartitioner(traced, supported_ops, allows_single_node_partition=True)
partitions = partitioner.propose_partitions()

results in the partitions [[add], [add_1]]. However, since these two partitions do not depend on each other, they can be aggressively merged into a single partition [[add, add_1]] without causing any issues. This PR introduces a new feature that allows such aggressive merging by introducing an option aggressive_merge to the Partitioner class.

@pytorch-bot pytorch-bot Bot added the release notes: fx release notes category label Apr 27, 2023
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 27, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/100195

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 222e1d2:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 27, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: seanlatias / name: Yi-Hsiang (Sean) Lai (6cf854defbeb3f7ee709f66ba70a6770b1d1aa09)

@seanlatias
Copy link
Copy Markdown
Contributor Author

@SherlockNoMad please take a look. I tagged you because you are the creater of this pass. Thank you.

Comment thread torch/fx/passes/infra/partitioner.py Outdated
size = len(merge_candidates_list)
self_id = merge_candidates_list[0]
for other_id in merge_candidates_list[1:]:
maybe_merge_partition(self_id, other_id)
Copy link
Copy Markdown
Contributor

@SherlockNoMad SherlockNoMad May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bug in the original impl. This case should have been handled in line 168. Could you please try fixing the original bug, instead of implementing it as a patch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I can do that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SherlockNoMad I fixed the merging logic. Please take a look and enable the CI. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix!

Comment thread torch/fx/passes/infra/partitioner.py Outdated
@seanlatias seanlatias requested a review from SherlockNoMad May 4, 2023 23:32
@SherlockNoMad
Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 5, 2023
@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
With the old partitioner, suppose `add` is supported, the following code
```python
def fn(a, b, c, d):
    x = a + b # add
    y = c + d # add_1
    return (x, y)

traced = symbolic_trace(fn)
partitioner = CapabilityBasedPartitioner(traced, supported_ops, allows_single_node_partition=True)
partitions = partitioner.propose_partitions()
```
results in the partitions `[[add], [add_1]]`. However, since these two partitions do not depend on each other, they can be aggressively merged into a single partition `[[add, add_1]]` without causing any issues. This PR introduces a new feature that allows such aggressive merging by introducing an option `aggressive_merge` to the Partitioner class.

Pull Request resolved: pytorch#100195
Approved by: https://github.com/SherlockNoMad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: fx release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants