Refactor deepcopy logic to improve planning speed #665
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.
Summary:
Summary
When there are many possible proposals to plan with, e.g. >1000 proposals from GreedyProposer for ads models in [fused, fused_uvm_caching] modes, the planner can run >20 min to come up with a best plan. The speed bottleneck comes from
deepcopy(List[ShardingOption])
in proposers and partitioner. With the diff to reorganize the deepcopy operations, the planning time can be decreased to ~2.5 min.Idea
(1) Reduce times of deepcopy
When
List[ShardingOption]
is passed as plan/proposal between proposer, partitioner and planner, two times ofdeepcopy(List[ShardingOption])
(one in proposer, the other in partitioner) are done to isolate the state of List[ShardingOption] between planning stesp. As deepcopy is expensive, we just need to keep one deepcopy in partitioner. Doing so reduces the planning time from ~20 min to ~10 min.(2) Custom deepcopy
During partitioning, the only field updated in ShardingOption is
shard.ranks
. To avoid copying big objects (e.g. tensor, module) to save time, a custom__deepcopy__
function is created in ShardingOption that only deepcopiesshards
, and that everything else is passed with the original object. Doing so reduces the planning time from ~10 min to 2.5 min.(3) Freeze _tensor and _module
With idea (2), the
tensor
andmodule
fields in ShardingOption are changed to be read-only to avoid modification during planning.Differential Revision: D39822605