LLM Prompt Learning Improvements
State: closed | Pull request: yes
Labels: name: stale

# What does this PR do ?

- Makes GPT Prompt Learning Model class inherit from the base prompt learning model class, as a result:

      1.   Memory optimizations made for GPT prompt learning with large LMs are now also applied to T5
      2.   T5 pipeline parallel prompt learning is enabled
      3.   Future improvements made on the base prompt learning model class will effect both T5 and GPT without duplication of effort

- Adds ability to optionally save an inference ready .nemo file after each validation run if the val loss is lower than all previous val losses

- Reorganizes GPT and T5 prompt learning model classes so methods are listed in the same order, for easier class navigation and understandability.  

**Collection**: NLP

# Changelog 
- Updates GPT Prompt Learning Model class
- Updates T5 Prompt Learning Model class
- Updates Base Prompt Learning Model class
- Adds `save_intermediate_nemo_file` option to GPT and T5 prompt learning configs

# Usage
```python

python examples/nlp/language_modeling/megatron_gpt_prompt_learning.py \
        --config-name=story_generation.yaml \
        trainer.devices=2 \
        trainer.num_nodes=1 \
        trainer.max_epochs=${EPOCHS} \
        trainer.max_steps=-1 \
        exp_manager.exp_dir=/results \
        exp_manager.create_wandb_logger=True \
        exp_manager.wandb_logger_kwargs.project=${PROJECT} \
        exp_manager.wandb_logger_kwargs.name=${EXPNAME} \
        exp_manager.resume_ignore_no_checkpoint=True \
        model.language_model_path=/5b_fp16_tp2-O2.nemo.unpacked \
        model.nemo_path=/prompt-learning/rocstories_mlp_encoder_${SIZE}_tokens${TOKENS}_epochs${EPOCHS}_${LR}.nemo \
        model.save_intermediate_nemo_file=True \
        model.existing_tasks=[] \
        model.new_tasks=['rocstories'] \
        model.tensor_model_parallel_size=2 \
        model.pipeline_model_parallel_size=1 \
        model.global_batch_size=128 \
        model.micro_batch_size=2 \
        model.optim.lr=${LR} \
        model.data.train_ds=[${DATA}/${TRAIN_FILE}] \
        model.data.validation_ds=[${DATA}/${VAL_FILE}] \
        model.virtual_prompt_style=p-tuning 
```

# Before your PR is "Ready for review"
**Pre checks**:
- [x] Make sure you read and followed [Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md)
- [ ] Did you write any new necessary tests?
- [ ] Did you add or update any necessary documentation?
- [ ] Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
- [ ] Reviewer: Does the PR have correct import guards for all optional libraries?
  
**PR Type**:
- [x] New Feature
- [ ] Bugfix
- [ ] Documentation

If you haven't finished some of the above items you can still open "Draft" PR.


## Who can review?

Anyone in the community is free to review the PR once the checks have passed. 
[Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md) contains specific people who can review PRs to various areas.

# Additional Information
* Related to # (issue)