-
Notifications
You must be signed in to change notification settings - Fork 9
Remove more invalid / uneven shardings #23
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
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 |
|---|---|---|
|
|
@@ -76,6 +76,32 @@ def _build_meta_tensor(tensor_meta): | |
| ) | ||
|
|
||
|
|
||
| def remove_invalid_configs(out_strat, mesh): | ||
| kept = [] | ||
| for strategy in out_strat.strategies: | ||
| is_valid = True | ||
| output_specs = strategy.output_specs | ||
| if isinstance(output_specs, DTensorSpec): | ||
| output_specs = [output_specs] | ||
| specs = list(strategy.input_specs) + list(output_specs) | ||
|
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. nit: list(output_specs) seems redundant to the line above?
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.
|
||
| for spec in specs: | ||
| if spec is None: | ||
| continue | ||
| shape = list(spec.tensor_meta.shape) | ||
| for mesh_shape, plc in zip(mesh.shape, spec.placements): | ||
| if plc.is_shard(): | ||
| dim = plc.dim | ||
| if shape[dim] % mesh_shape == 0: | ||
| shape[dim] //= mesh_shape | ||
| else: | ||
| is_valid = False | ||
| break | ||
| if is_valid: | ||
| kept.append(strategy) | ||
|
|
||
| return OpStrategy(kept) | ||
|
|
||
|
|
||
| def _create_all_options_no_nested_sharding(mesh, shape, tensor_meta=None): | ||
| if tensor_meta is None: | ||
| tensor_meta = _gen_tensor_meta(shape) | ||
|
|
@@ -94,7 +120,9 @@ def _create_all_options_no_nested_sharding(mesh, shape, tensor_meta=None): | |
| continue | ||
| spec = DTensorSpec.from_dim_map(mesh, op, [], tensor_meta) | ||
| strats.append(OpSpec(spec, input_specs=[spec], redistribute_cost=[[0.0]])) | ||
| return OpStrategy(strats) | ||
| out_strats = OpStrategy(strats) | ||
| out_strats = remove_invalid_configs(out_strats, mesh) | ||
| return out_strats | ||
|
|
||
|
|
||
| def _create_all_options(mesh, shape, tensor_meta=None, tensor=None): | ||
|
|
@@ -112,7 +140,9 @@ def _create_all_options(mesh, shape, tensor_meta=None, tensor=None): | |
| for placement in all_options: | ||
| spec = DTensorSpec(mesh, placement, tensor_meta=tensor_meta) | ||
| strats.append(OpSpec(spec, input_specs=[spec], redistribute_cost=[[0.0]])) | ||
| return OpStrategy(strats) | ||
| out_strats = OpStrategy(strats) | ||
| out_strats = remove_invalid_configs(out_strats, mesh) | ||
| return out_strats | ||
|
|
||
|
|
||
| @register_rule(operator.getitem) | ||
|
|
||
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.
lol