fix: restrict policy var save for distributed setup
Description
- Issue
- The current saving logic only saves restrict policy parameters for
rank == 0. - For
rank != 0, therestrict_varis not restored, leading to an unsynchronized state between the embedding variable andrestrict_var. - As a result, the restrict policy does not work correctly in distributed training.
- The current saving logic only saves restrict policy parameters for
- Fixes
- Added
_maybe_save_restrict_policy_paramsfunction:- Checks if
de_varhas a restrict_policy. - Saves the associated restrict policy variable to the file system for each rank.
- Checks if
- Updated
_traverse_emb_layers_and_saveto:- Call
_maybe_save_restrict_policy_paramsfor each distributed embedding variable (de_var). - Ensure restrict policy parameters are saved and restored for all Horovod ranks (
hvd.rank()).
- Call
- Added
Type of change
- [x] Bug fix
- [ ] New Tutorial
- [ ] Updated or additional documentation
- [x] Additional Testing
- [ ] New Feature
Checklist:
- [x] I've properly formatted my code according to the guidelines
- [x] By running yapf
- [x] By running clang-format
- [ ] This PR addresses an already submitted issue for TensorFlow Recommenders-Addons
- [ ] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my feature works
How Has This Been Tested?
- Written test case
tensorflow_recommenders_addons/dynamic_embedding/python/kernel_tests/horovod_embedding_restrict_save_test.pythat trains a dummy model for some steps, then saves the model. - The model's embedding-table is created with restrict policy.
- Test-case checks if the restrict-policy is saved for each rank.
- To simulate distributed environment test-case was tested using
horovodrunfor CPU based distributed setup$ horovodrun -np 2 python tensorflow_recommenders_addons/dynamic_embedding/python/kernel_tests/horovod_distributed_restrict_policy_save.py - Output of saved-model from above test-case:
$ ls /tmp/hvd_distributed_restrict_policy_save_timestamp210/variables/TFRADynamicEmbedding/ all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_m_mht_1of1_rank0_size2-keys all2all_emb-parameter_mht_1of1_rank0_size2-keys all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_m_mht_1of1_rank0_size2-values all2all_emb-parameter_mht_1of1_rank0_size2-values all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_m_mht_1of1_rank1_size2-keys all2all_emb-parameter_mht_1of1_rank1_size2-keys all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_m_mht_1of1_rank1_size2-values all2all_emb-parameter_mht_1of1_rank1_size2-values all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_v_mht_1of1_rank0_size2-keys all2all_emb-parameter_timestamp_mht_1of1_rank0_size2-keys all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_v_mht_1of1_rank0_size2-values all2all_emb-parameter_timestamp_mht_1of1_rank0_size2-values all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_v_mht_1of1_rank1_size2-keys all2all_emb-parameter_timestamp_mht_1of1_rank1_size2-keys all2all_emb-parameter_DynamicEmbedding_all2all_emb-shadow_v_mht_1of1_rank1_size2-values all2all_emb-parameter_timestamp_mht_1of1_rank1_size2-values
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
Hey @rhdong, @jq, @MoFHeka, if I can get some help with review of this would be great! Thanks
Hey @rhdong, @jq, @MoFHeka, if I can get some help with review of this would be great! Thanks
Hi @jatinsharechat , thanks for your contribution! The CLA needed to be signed; please follow the guidance: https://github.com/tensorflow/recommenders-addons/pull/491/checks?check_run_id=39908185786. cc @jq @MoFHeka
Hey @rhdong, @jq, @MoFHeka, if I can get some help with review of this would be great! Thanks
Hi @jatinsharechat , thanks for your contribution! The CLA needed to be signed; please follow the guidance: https://github.com/tensorflow/recommenders-addons/pull/491/checks?check_run_id=39908185786. cc @jq @MoFHeka
I've signed off the CLA and the rescan is green.
the code format is failing, you may run yapf
Gentle ping on this @jq @rhdong