fix tensor dimensions are not compatible for FP8 issue in sft #8787
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Usage
# 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:
PR Type:
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 contains specific people who can review PRs to various areas.
Additional Information