Cherry pick commits in #6528 to main
# What does this PR do ?

Manually cherry-pick changes from https://github.com/NVIDIA/NeMo/pull/6528. Automatic merging probably failed due to merge conflicts with https://github.com/NVIDIA/NeMo/pull/6510.

**Collection**: NLP

# Changelog 
- Cherry-pick changes from https://github.com/NVIDIA/NeMo/pull/6528
- Move duplicated logic for distributed optimizer into recently-added [`MegatronGPTModel.fwd_bwd_step` function](https://github.com/NVIDIA/NeMo/blob/24c7b4bdcb794536a52a38bbd1737422f095681f/nemo/collections/nlp/models/language_modeling/megatron_gpt_model.py#L333).


# Usage

Set `virtual_pipeline_model_parallel_size > 1`:
https://github.com/NVIDIA/NeMo/blob/5468077f5127be1a4c88065de2544f4268b9a6e4/examples/nlp/language_modeling/conf/megatron_gpt_config.yaml#L51

This requires `pipeline_model_parallel_size > 2`  and `virtual_pipeline_model_parallel_size*pipeline_model_parallel_size` divides `num_layers`.

# 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?
- [x] Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
  - [x] Reviewer: Does the PR have correct import guards for all optional libraries?
  
**PR Type**:
- [ ] New Feature
- [x] 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
* Cherry-pick from https://github.com/NVIDIA/NeMo/pull/6528
* Fixes merge conflicts with https://github.com/NVIDIA/NeMo/pull/6510