-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[Graph Partition][Cache] Use inductor partition ops config #27702
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
Changes from all commits
36315f1
49f93fb
9f1944d
cd9b0b6
ffd0226
0e5a38b
2f7ae24
a85682a
3e374a0
e069c2e
f6314eb
cc9098b
c942ce2
891df2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,12 @@ | |
|
|
||
| import contextlib | ||
| import logging | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import torch | ||
| from torch._library.utils import lookup_op | ||
|
|
||
| from vllm.logger import init_logger | ||
|
|
||
| if TYPE_CHECKING: | ||
| import torch | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
|
|
@@ -56,47 +53,35 @@ def resolve_defined_ops(op_names: list[str]) -> list["torch._ops.OpOverload"]: | |
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def inductor_partition_rule_context(overloads: list["torch._ops.OpOverload"]): | ||
| def inductor_partition_rule_context(splitting_ops: list[str]): | ||
| """Context manager to temporarily register Inductor partition rules. | ||
|
|
||
| Registers custom partition rules for specified operators, forcing the | ||
| Inductor scheduler to partition the graph at these operators. The rules | ||
| are automatically restored to their previous state on exit. | ||
|
|
||
| Note: Callers should use resolve_defined_ops() to convert operator names | ||
| to OpOverload objects before calling this function. | ||
|
|
||
| Args: | ||
| overloads: List of resolved operator overload objects. | ||
| splitting_ops: List of operator names to partition on. | ||
| """ | ||
| if not overloads: | ||
| if not splitting_ops: | ||
| logger.debug("No partition ops provided; skipping rule registration.") | ||
| yield | ||
| return | ||
|
|
||
| from torch._inductor.scheduler import ( # type: ignore | ||
| _custom_should_partition_fns, | ||
| register_should_partition_rule, | ||
| ) | ||
|
|
||
| def _always_partition(*_args, **_kwargs): | ||
| return True | ||
|
|
||
| # Save current state before registering | ||
| saved_rules = _custom_should_partition_fns.copy() | ||
|
|
||
| for overload in overloads: | ||
| register_should_partition_rule( | ||
| overload, | ||
| _always_partition, | ||
| ) | ||
| saved_splitting_ops: list[str] = list( | ||
| torch._inductor.config.custom_should_partition_ops | ||
| ) | ||
| torch._inductor.config.custom_should_partition_ops = splitting_ops | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this safe? I believe this config knob is only recently added (last week). Users who use older version of pytorch would hit an error here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only accessed by pytorch 2.9.0 and pytorch 2.9.1. Pytorch 2.9.1 will include the config. Test passed for both pytorch versions. |
||
|
|
||
| logger.debug("Registered inductor partition rules for %d operators", len(overloads)) | ||
| logger.debug( | ||
| "Registered inductor partition rules for %d operators", len(splitting_ops) | ||
| ) | ||
|
|
||
| try: | ||
| yield | ||
| finally: | ||
| # Clear and restore previous state | ||
| _custom_should_partition_fns.clear() | ||
| _custom_should_partition_fns.update(saved_rules) | ||
| torch._inductor.config.custom_should_partition_ops = saved_splitting_ops | ||
| logger.debug("Restored previous partition rules state.") | ||
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.
While we're at it could we remove
resolve_op_overloadsfrom the Dynamo partition path as well and use string names for ops there too?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.
yes I will update dynamo partition path in a follow up pr.