Cache all_optimizer_states to speed up model sharding #2747
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:
Similar to D68578829, the
get_optimizer_state()
method in theemb_module
is invoked thousands of times when_gen_named_parameters_by_table_fused
is called as it generates EmbeddingFusedOptimizer instances for each iteration.By extracting this operation out of the loop and passing it as a parameter to achieve a caching effect, we can save a lot of time. Specifically, ~6.6s from https://www.internalfb.com/family_of_labs/test_results/694448901
and ~20s from https://www.internalfb.com/family_of_labs/test_results/694448900
Reviewed By: dstaay-fb, lijia19, andywag
Differential Revision: D69443708