Consolidate gpt continue training script into pretraining script
State: closed | Pull request: yes
Labels: name: NLP

name: Run CICD

# What does this PR do ?

## Continual Learning with Pretrained Checkpoints

Continual learning enables large language models (LLMs) to acquire new skills and remain current with the swiftly advancing landscape of human knowledge. This guide details how to engage in continual learning using existing pretrained checkpoints with the `examples/nlp/language_modeling/megatron_gpt_pretraining.py` script. This process is applicable to various models including Llama 1/2/3, Gemma, Mistral, Mixtral, and others.

### Configuration for Continual Learning
To enable continual learning, modify the `model` configuration in your script as follows:

```yaml
model:
  # Use the following settings to specify the source for continual learning:
  restore_from_path: null  # Set this to a .nemo file path to restore only the model weights.
  restore_from_ckpt: null  # Set this to a checkpoint path to restore both model weights and optimizer states.
```

- **restore_from_path**: Use this when you want to restore only the model weights from a `.nemo` file.
- **restore_from_ckpt**: Use this to restore both model weights and optimizer states from a PyTorch checkpoint.

### Adjusting Training Configurations
Upon engaging in continual learning, it is possible and often beneficial to modify various training configurations:
- **Model Parallelism**: Depending on the computational resources available, you may adjust the model's parallelism settings.
- **Data Blend**: You can change the dataset or modify how data is blended during training to better suit the new training objectives.
- **Learning Rate Scheduler**: Adjusting the learning rate schedule can help optimize training for the new conditions.

Refer to the *pretrain* section of the documentation for details on configuring these parameters.

### Important Notes on Continual Learning
- **State Reset**: When engaging in continual learning, all states including model parallelism configuration, dataset, learning rate scheduler, and randomness are reset, except for the states loaded from the checkpoint.
- **Resuming Training**: If training is interrupted (e.g., due to a system failure) and you wish to resume the continual learning process, ensure that the restore flags (`restore_from_path` or `restore_from_ckpt`) are set back to `null`. This prevents the system from resetting the states again, which could lead to incorrect results.

**Collection**: [nlp]

# GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

# Before your PR is "Ready for review"
**Pre checks**:
- [ ] 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)


Can we add github CI test for this and then also test the regular GPT pretraining, with resuming, is the same before and after this PR?

We should also add docs for this, the readme here is a good start.

sure i will add some tests. the gpt resume behavior is not changed in my local tests

@ericharper  as I work on CI. I did some local tests 
![image](https://github.com/NVIDIA/NeMo/assets/54727607/87434f33-aaa7-4f6a-aac4-086948815a4a)