fix tensor dimensions are not compatible for FP8 issue in sft
State: closed | Pull request: yes
Labels: name: bug

name: NLP

name: Run CICD

# What does this PR do ?
when we use nemo for sft FP8 training, it will reports 
`  File "/usr/local/lib/python3.10/dist-packages/torch/autograd/function.py", line 289, in apply
    return user_fn(self, *args)
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/module/linear.py", line 447, in backward
    wgrad, _ = fp8_gemm(
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/cpp_extensions/gemm.py", line 45, in fp8_gemm
    assert_dim_for_fp8_exec(A)
  File "/usr/local/lib/python3.10/dist-packages/transformer_engine/pytorch/utils.py", line 221, in assert_dim_for_fp8_exec
    assert check_dim_for_fp8_exec(tensor), (
AssertionError: Tensor dimensions are not compatible for FP8 execution: (3584 % 8 != 0, 1912 % 16 != 0)` 

 fp8 GEMM requires tensor dimension be multiple of 16. This means the sequence dimension of input data should be padded to multiple of 16, which is not implemented in NeMo chat style data loader yet.​
so need to change 
`max_length = min(self.max_seq_length, self._ceil_to_nearest(max_length, 8)`
to
`max_length = min(self.max_seq_length, self._ceil_to_nearest(max_length, 16)`
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 
```

# Jenkins CI
To run Jenkins, a NeMo User with write access must comment `jenkins` on the PR.

# 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)


This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

This PR was closed because it has been inactive for 7 days since being marked as stale.

Please rebase to latest main, CI is broken -> stopped your pipeline. Thanks.

<!-- 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.nlp.data.language_modeling.megatron.gpt_sft_chat_dataset
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:113:0: C0301: Line too long (165/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:116:0: C0301: Line too long (144/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:147:0: C0301: Line too long (132/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:156:0: C0301: Line too long (165/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:177:0: C0301: Line too long (169/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:240:0: C0301: Line too long (124/119) (line-too-long)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:59:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:182:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/nlp/data/language_modeling/megatron/gpt_sft_chat_dataset.py:311:0: C0115: Missing class docstring (missing-class-docstring)

-----------------------------------
Your code has been rated at 9.52/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!