Add SpeechLM and VLM fsdp2 sharding support in nemo automodel
State: closed | Pull request: yes
Labels: name: core

name: NLP

name: CI

# What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

**Collection**: [Note which collection this PR will affect]

# Changelog 
- Add specific line by line info of high level changes in this PR.

# Usage
* You can potentially add a usage example below

```python
# Add a code snippet demonstrating how to use this 
```

# 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**:
- [ ] 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)


<!-- pylint-output-strict-mode-false -->

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.

---

Your code was analyzed with PyLint. The following annotations have been identified:

```
************* Module nemo.collections.llm.gpt.model.gemma
nemo/collections/llm/gpt/model/gemma.py:40:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:59:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:68:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:76:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:80:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:84:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:104:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:124:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/gemma.py:137:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/gemma.py:143:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/gemma.py:175:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/gemma.py:194:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/gemma.py:207:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/gemma.py:211:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.collections.nlp.models.language_modeling.megatron_base_model
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:103:0: C0301: Line too long (149/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:111:0: C0301: Line too long (134/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:254:0: C0301: Line too long (125/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:272:0: C0301: Line too long (120/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:347:0: C0301: Line too long (133/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:607:0: C0301: Line too long (123/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:662:0: C0301: Line too long (153/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:834:0: C0301: Line too long (122/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:972:0: C0301: Line too long (121/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:991:0: C0301: Line too long (136/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1108:0: C0301: Line too long (195/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1165:0: C0301: Line too long (135/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1214:0: C0301: Line too long (120/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1297:0: C0301: Line too long (128/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:331:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:462:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:467:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:700:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:752:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:933:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1037:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1272:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1303:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1307:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_base_model.py:1311:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.collections.nlp.models.language_modeling.megatron_retro_model
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:36:0: C0301: Line too long (199/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:142:0: C0301: Line too long (191/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:304:0: C0301: Line too long (126/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:335:0: C0301: Line too long (140/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:386:0: C0301: Line too long (123/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:441:0: C0301: Line too long (206/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:451:0: C0301: Line too long (124/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:458:0: C0301: Line too long (210/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:462:0: C0301: Line too long (161/119) (line-too-long)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:112:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:15:0: W0611: Unused import itertools (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:18:0: W0611: Unused import queue (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:20:0: W0611: Unused import warnings (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:21:0: W0611: Unused fields imported from dataclasses (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:23:0: W0611: Unused Dict imported from typing (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:23:0: W0611: Unused Iterator imported from typing (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:23:0: W0611: Unused List imported from typing (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:23:0: W0611: Unused Union imported from typing (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:26:0: W0611: Unused CPUAccelerator imported from lightning.pytorch.accelerators (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:38:0: W0611: Unused MegatronBaseModel imported from nemo.collections.nlp.models.language_modeling.megatron_base_model (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:40:0: W0611: Unused build_model imported from nemo.collections.nlp.modules.common.megatron.build_model (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:41:0: W0611: Unused Float16Module imported from nemo.collections.nlp.modules.common.megatron.module (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:42:0: W0611: Unused get_all_params_for_weight_decay_optimization imported from nemo.collections.nlp.modules.common.megatron.utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:42:0: W0611: Unused get_ltor_masks_and_position_ids imported from nemo.collections.nlp.modules.common.megatron.utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:42:0: W0611: Unused get_params_for_weight_decay_optimization imported from nemo.collections.nlp.modules.common.megatron.utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:49:0: W0611: Unused TextGenerationStrategy imported from nemo.collections.nlp.modules.common.text_generation_strategy (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:50:0: W0611: Unused get_default_length_params imported from nemo.collections.nlp.modules.common.text_generation_utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:50:0: W0611: Unused get_default_sampling_params imported from nemo.collections.nlp.modules.common.text_generation_utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:50:0: W0611: Unused megatron_gpt_generate imported from nemo.collections.nlp.modules.common.text_generation_utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:57:0: W0611: Unused LengthParam imported from nemo.collections.nlp.modules.common.transformer.text_generation (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:57:0: W0611: Unused OutputType imported from nemo.collections.nlp.modules.common.transformer.text_generation (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:57:0: W0611: Unused SamplingParam imported from nemo.collections.nlp.modules.common.transformer.text_generation (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:57:0: W0611: Unused TextGeneration imported from nemo.collections.nlp.modules.common.transformer.text_generation (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:63:0: W0611: Unused utils_funcs imported from nemo.collections.nlp.parts (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:64:0: W0611: Unused activation_to_func imported from nemo.collections.nlp.parts.utils_funcs (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:64:0: W0611: Unused get_last_rank imported from nemo.collections.nlp.parts.utils_funcs (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:65:0: W0611: Unused Exportable imported from nemo.core.classes (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:66:0: W0611: Unused PretrainedModelInfo imported from nemo.core.classes.common (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:67:0: W0611: Unused ChannelType imported from nemo.core.neural_types (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:67:0: W0611: Unused NeuralType imported from nemo.core.neural_types (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:72:4: W0611: Unused InferenceParams imported from megatron.core (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:80:4: W0611: Unused TransformerConfig imported from megatron.core.transformer.transformer_config (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:81:4: W0611: Unused init_method_normal imported from megatron.core.utils (unused-import)
nemo/collections/nlp/models/language_modeling/megatron_retro_model.py:81:4: W0611: Unused scaled_init_method_normal imported from megatron.core.utils (unused-import)
************* Module nemo.lightning.pytorch.strategies.utils
nemo/lightning/pytorch/strategies/utils.py:40:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/pytorch/strategies/utils.py:49:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:57:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:69:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:85:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:120:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:142:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/utils.py:197:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module scripts.checkpoint_converters.convert_bert_hf_to_nemo
scripts/checkpoint_converters/convert_bert_hf_to_nemo.py:65:0: C0301: Line too long (218/119) (line-too-long)
scripts/checkpoint_converters/convert_bert_hf_to_nemo.py:38:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/checkpoint_converters/convert_bert_hf_to_nemo.py:56:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/checkpoint_converters/convert_bert_hf_to_nemo.py:79:0: C0116: Missing function or method docstring (missing-function-docstring)

-----------------------------------
Your code has been rated at 9.45/10
```

---

Mitigation guide:

* Add sensible and useful docstrings to functions and methods
* For trivial methods like getter/setters, consider adding `# pylint: disable=C0116` inside the function itself
* To disable multiple functions/methods at once, put a `# pylint: disable=C0116` before the first and a `# pylint: enable=C0116` after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

<!-- pylint-output-strict-mode-true -->

beep boop 🤖: 🚨 The following files must be fixed before merge!

---

Your code was analyzed with PyLint. The following annotations have been identified:

```
************* Module hf
examples/speechlm/sft/hf.py:29:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.collections.speechlm.models.hf_auto_model_for_speech_seq2seq
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:27:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:35:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:60:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:73:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:79:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:82:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:105:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:112:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:124:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/speechlm/models/hf_auto_model_for_speech_seq2seq.py:129:4: C0116: Missing function or method docstring (missing-function-docstring)

-----------------------------------
Your code has been rated at 9.76/10
```

---

Mitigation guide:

* Add sensible and useful docstrings to functions and methods
* For trivial methods like getter/setters, consider adding `# pylint: disable=C0116` inside the function itself
* To disable multiple functions/methods at once, put a `# pylint: disable=C0116` before the first and a `# pylint: enable=C0116` after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

Closing this in favor of https://github.com/NVIDIA/NeMo/pull/11876