Repository navigation
Conversation
Add three optimizations to _find_lowest_cost_sharding and two reachability tests that prove the PQ transition graph covers all valid strategies. The fast path checks whether the initial input placements already match a strategy rule on every mesh dim, returning immediately without constructing MeshTopoInfo or the PQ. The per-input cost cache avoids redundant _compute_redistribute_cost calls by keying on destination placement tuples (at most 64 unique keys per input on a 3D mesh). _build_output_spec is extracted as a shared helper between the fast path and PQ match block. _collect_all_matches is a testing-only parameter that forces the PQ to exhaustively explore the full transition graph, collecting every shardable match into a set while still returning the optimal result. Authored with Claude. [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/175313
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 3 Unrelated FailuresAs of commit d2fd078 with merge base 003e05b ( NEW FAILURE - The following job has failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Add three optimizations to _find_lowest_cost_sharding and two reachability tests that prove the PQ transition graph covers all valid strategies. The fast path checks whether the initial input placements already match a strategy rule on every mesh dim, returning immediately without constructing MeshTopoInfo or the PQ. The per-input cost cache avoids redundant _compute_redistribute_cost calls by keying on destination placement tuples (at most 64 unique keys per input on a 3D mesh). _build_output_spec is extracted as a shared helper between the fast path and PQ match block. _collect_all_matches is a testing-only parameter that forces the PQ to exhaustively explore the full transition graph, collecting every shardable match into a set while still returning the optimal result. Authored with Claude. ghstack-source-id: 966a427 Pull Request resolved: #175313
| mesh, selected_output_placements, num_outputs, output_metas | ||
| ) | ||
| redistribute_costs = [ | ||
| generate_redistribute_costs(OpStrategy([OpSpec(input_spec)]), arg_spec) |
There was a problem hiding this comment.
shouldn't redistribute_costs be zeros? maybe calling this is OK though, it should be short-circuiting inside?
| ] | ||
| op_spec = OpSpec( | ||
| output_specs=output_spec, | ||
| input_specs=arg_specs, |
There was a problem hiding this comment.
we should probably refactor a helper fn that tries to do shard prop without redistribute.
for now, we can make one that is specific to single-dim strategies, since that's all we need from here. later we might want to have a similar API that works for any op, and falls back to some other path for non-single-dim strategies
| ) -> DTensorSpec | tuple[DTensorSpec | None, ...]: | ||
| """Build multi-dim output spec from per-mesh-dim output placements.""" | ||
| if num_outputs == 1: | ||
| output_placements_tuple = tuple(out[0] for out in selected_output_placements) |
There was a problem hiding this comment.
confusing why we have multiple outputs in num_outputs==1 case?
| ) | ||
| return tuple(multi_output_specs) | ||
| else: | ||
| return DTensorSpec(mesh, (Replicate(),) * mesh.ndim) |
There was a problem hiding this comment.
what is the else case for?
| [OpOverload, ArgsType, KwargsType], list[list[Placement | _ShardingPlaceholder]] | ||
| ], | ||
| output_tensor_meta: TensorMeta | Sequence[TensorMeta | None] | None = None, | ||
| _collect_all_matches: set[tuple[tuple[Placement, ...], ...]] | None = None, |
very WIP ghstack-source-id: bbd81da Pull Request resolved: pytorch/pytorch#169438 [DTensor] PQ search: fast path, cost cache, and reachability tests Add three optimizations to _find_lowest_cost_sharding and two reachability tests that prove the PQ transition graph covers all valid strategies. The fast path checks whether the initial input placements already match a strategy rule on every mesh dim, returning immediately without constructing MeshTopoInfo or the PQ. The per-input cost cache avoids redundant _compute_redistribute_cost calls by keying on destination placement tuples (at most 64 unique keys per input on a 3D mesh). _build_output_spec is extracted as a shared helper between the fast path and PQ match block. _collect_all_matches is a testing-only parameter that forces the PQ to exhaustively explore the full transition graph, collecting every shardable match into a set while still returning the optimal result. Authored with Claude. ghstack-source-id: bbd81da Pull Request resolved: pytorch/pytorch#175313
Stack from ghstack (oldest at bottom):
Add three optimizations to _find_lowest_cost_sharding and two
reachability tests that prove the PQ transition graph covers all valid
strategies.
The fast path checks whether the initial input placements already match
a strategy rule on every mesh dim, returning immediately without
constructing MeshTopoInfo or the PQ. The per-input cost cache avoids
redundant _compute_redistribute_cost calls by keying on destination
placement tuples (at most 64 unique keys per input on a 3D mesh).
_build_output_spec is extracted as a shared helper between the fast path
and PQ match block.
_collect_all_matches is a testing-only parameter that forces the PQ to
exhaustively explore the full transition graph, collecting every
shardable match into a set while still returning the optimal result.
Authored with Claude.