-
Notifications
You must be signed in to change notification settings - Fork 453
[Feature] Allow targeting multiples of sequential targets #2493
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
Open
aayush7511
wants to merge
2
commits into
vllm-project:main
Choose a base branch
from
aayush7511:feat/targets-per-subgraph
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−7
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,7 @@ def trace_subgraphs( | |||||
| sample_input: dict[str, Any], | ||||||
| sequential_targets: list[str], | ||||||
| ignore: list[str], | ||||||
| targets_per_subgraph: int = 1 | ||||||
| ) -> list[Subgraph]: | ||||||
| """ | ||||||
| Trace a model to produce subgraphs, where each sequential target belongs to exactly | ||||||
|
|
@@ -98,6 +99,7 @@ def trace_subgraphs( | |||||
| __len__, __bool__, and __contains__ values are assumed constant across batches | ||||||
| :param sequential_targets: list of patterns matching sequential targets | ||||||
| :param ignore: function and method names to skip during tracing | ||||||
| :param targets_per_subgraph: number of targets to include per subgraph | ||||||
| :return: a list of Subgraphs in order of execution | ||||||
| """ | ||||||
| # find modules | ||||||
|
|
@@ -152,7 +154,7 @@ def trace_subgraphs( | |||||
| graph.device = model.device | ||||||
|
|
||||||
| # perform subgraph partition | ||||||
| partitions = topological_partition(graph, targets) | ||||||
| partitions = topological_partition(graph, targets, targets_per_subgraph) | ||||||
| subgraphs = partition_graph(model, partitions) | ||||||
| trace_consumed_names(subgraphs) | ||||||
|
|
||||||
|
|
@@ -260,27 +262,32 @@ def find_target_nodes(graph: GraphModule, targets: set[Module]) -> set[Node]: | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def topological_partition(graph: GraphModule, targets: set[Module]) -> list[list[Node]]: | ||||||
| def topological_partition(graph: GraphModule, targets: set[Module], targets_per_subgraph: int = 1) -> list[list[Node]]: | ||||||
| """ | ||||||
| Partition the graph into partitions such that each `target` belongs to exactly one | ||||||
| partition and executing each partition depends only on intermediate values produced | ||||||
| by executing the partitions before it. | ||||||
|
|
||||||
| :param graph: graph being partitioned | ||||||
| :param targets: target modules which will be assigned to disjoint partitions | ||||||
| :param targets_per_subgraph: number of targets to include per subgraph | ||||||
| :return: list of partitions, where each partition is a list of nodes belonging to | ||||||
| that partition | ||||||
| """ | ||||||
| assert graph_is_well_formed(graph.graph) | ||||||
| target_nodes = find_target_nodes(graph, targets) | ||||||
|
|
||||||
| if(targets_per_subgraph <= 0): | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| raise ValueError("targets_per_subgraph is required to be greater than or equal to one") | ||||||
|
|
||||||
| partitions: list[list[Node]] = [[]] | ||||||
| remaining_indegrees = { | ||||||
| node: len([node for node in node.all_input_nodes if node.op != "get_attr"]) | ||||||
| for node in graph.graph.nodes | ||||||
| } | ||||||
| partition_index = 0 # global counter | ||||||
|
|
||||||
| targets_seen = 0 # number of targets encountered so far | ||||||
|
Collaborator
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.
Suggested change
|
||||||
|
|
||||||
| # start with graph input nodes, | ||||||
| # but delay the `get_attr` nodes as long as possible | ||||||
| queue = deque( | ||||||
|
|
@@ -296,8 +303,11 @@ def topological_partition(graph: GraphModule, targets: set[Module]) -> list[list | |||||
|
|
||||||
| # guarantee targets are assigned to disjoint partitions | ||||||
| if node in target_nodes: | ||||||
| partition_index += 1 | ||||||
| partitions.append([]) | ||||||
| targets_seen += 1 | ||||||
|
|
||||||
| if targets_seen % targets_per_subgraph == 0: | ||||||
| partition_index += 1 | ||||||
| partitions.append([]) | ||||||
|
|
||||||
| # recurse on last indegree only in order to guarantee that | ||||||
| # the node is assigned to maximal partition | ||||||
|
|
||||||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.