-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Megatron encoder-decoder refactor #3542
Megatron encoder-decoder refactor #3542
Conversation
2. Added megatron base encoder decoder class. Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 6 alerts and fixes 1 when merging 059c4d3 into 101977e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 6 alerts and fixes 1 when merging a7127a9 into 1b83bec - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 9 alerts and fixes 1 when merging d4cbc7c into 1b83bec - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 9 alerts and fixes 1 when merging 802eae7 into 1b83bec - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 12 alerts and fixes 1 when merging e4008e0 into 9a1cc36 - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 9 alerts and fixes 1 when merging 5cee721 into ddcc2a6 - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
…ivne/NeMo into megatron-encoder-decoder-refactor
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 2 alerts and fixes 4 when merging 7e66395 into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
…ivne/NeMo into megatron-encoder-decoder-refactor
This pull request introduces 2 alerts and fixes 4 when merging eda6288 into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
nemo/collections/nlp/modules/common/megatron/megatron_encoder_decoder.py
Outdated
Show resolved
Hide resolved
nemo/collections/nlp/modules/common/megatron/megatron_encoder_decoder.py
Outdated
Show resolved
Hide resolved
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.
LGTM. Thanks!
Had some minor comments, but will approve. Please change your copyrights to 2022.
2. Updated copyright year. Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 2 alerts and fixes 4 when merging a2c145b into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
…ivne/NeMo into megatron-encoder-decoder-refactor
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 2 alerts and fixes 4 when merging d6bc1ec into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 2 alerts and fixes 4 when merging be1c9ec into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 1 alert and fixes 4 when merging 67e56da into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
Signed-off-by: Micha Livne <mlivne@nvidia.com>
This pull request introduces 1 alert and fixes 4 when merging 17f00d3 into 00df30e - view on LGTM.com new alerts:
fixed alerts:
|
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.
LGTM. Thanks!
* 1. Added megatron encoder and decoder. 2. Added megatron base encoder decoder class. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added base encoder-decoder megatron model. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Workingon T5Model refactor. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. FInished T5Model. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added skeleton for ModelPT encoder decoder. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Consolidated functions. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Class structure is done. Not tested yete. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Rearranging code, and fixing bugs. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Updated name of classes from Model to Module. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Merged conflicts. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Removed unsused imports. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed typo. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixing unused imports. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Relpaced self.cfg to self._cfg. Signed-off-by: Micha Livne <mlivne@nvidia.com> * Fix typi Signed-off-by: MaximumEntropy <sandeep.subramanian.1@umontreal.ca> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed typos in function arguments. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added support in custom tokenizer. Signed-off-by: Micha Livne <mlivne@nvidia.com> * Fix for T5 with SPM Signed-off-by: MaximumEntropy <sandeep.subramanian.1@umontreal.ca> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * whole word masking fix for spm Signed-off-by: MaximumEntropy <sandeep.subramanian.1@umontreal.ca> * Fix whole word masking for spm Signed-off-by: MaximumEntropy <sandeep.subramanian.1@umontreal.ca> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Moved tokens_encoder_decoder.py to modules. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Removed comment. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed class namkes. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Updated Jenkinsfile with new T5 model. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added a missing module. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Updated CI to use a smaller model. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added apex import guards. 2. Updated copyright year. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed style. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Added hint types. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed decoding to use token_logits instead of dec_output. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Debugging. Signed-off-by: Micha Livne <mlivne@nvidia.com> * 1. Fixed indentation bug. Signed-off-by: Micha Livne <mlivne@nvidia.com> Co-authored-by: Micha Livne <mlivne@nvidia.com> Co-authored-by: MaximumEntropy <sandeep.subramanian.1@umontreal.ca>
This PR refactor Megatron T5 to a modular base encoder-decoder class hierarchy, and a T5 class which customizes the base class. The goal of the refactor is to support multiple encoder-decoder models with minimal code redundancy.
Refactor High Level Description
Hierarchy tree is expressed below via list alignment (i.e., right alignment for child class).
MegatronModule
sub-classes:MegatronTransformerEncoderModule
/MegatronTransformerDecoderModule
- various architectures for manipulation of hidden --> hiddenMegatronTransformerEncoderDecoderModule
- contains above classes and generates required joint encoder/decoder mask given independent masks, and reparametrization (e.g., vae)TokensEncoderDecoderModule
- modality-specific (e.g., tokens-tokens) model which map between pre-processed data (e.g., token ids) and encoder/decoder continuous input (i.e., hidden); handles embedders (i.e., embedding + positional embedding); handles projection from hidden to data distribution (e.g., project from hidden dimensions to the number of tokens)NLPModel
sub-classes:MegatronBaseModel
- common initialization of MegatronMegatronLMEncoderDecoderModel
- modality-specific (e.g., text-text) model which pre-process raw data (e.g., tokenizer pre-process text to token ids); generic modality-specific training/testing/inference/loss methodsMegatronT5Model
- a specific model (i.e., T5) which prepares datasets (i.e., with corresponding data augmentation), and model-specific features (e.g., sentinels in tokenizer)Notable Changes
1
for active element, and0
for masked element (i.e., as opposed to 3D Megatron mask withFalse
for active andTrue
for masked). This allows easy manipulation of masks. Conversion to 3D Megatron masks is done on-the-fly.