[training_utils] feat: use TMA to load Tiles in linear_cross_entropy kernels - #4576
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the use of Tensor Memory Access (TMA) in Triton kernels to improve performance on Hopper GPUs, which is a great enhancement. The implementation correctly checks for TMA support and adds separate code paths for it. However, this has led to significant code duplication within several Triton kernels (efficient_entropy_kernel_general_mainloop, efficient_entropy_backward_kernel_general_mainloop_MN, efficient_entropy_backward_kernel_general_d_logits, and efficient_entropy_backward_kernel_general_d_logits_split_N). I've provided suggestions to refactor these kernels to remove duplication. Since the conditional logic is based on a compile-time constant (USE_TMA), these changes should improve maintainability and readability without impacting performance.
cca9cbd to
28d7c76
Compare
|
#4676 fixes the support for triton >= 3.5.0 |
…kernels (verl-project#4576) ### What does this PR do? The triton kernels of linear_cross_entropy iteratively load `hidden` and `weight` block tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation. ### Test ``` python3 tests/utils/test_linear_cross_entropy.py ``` Latency(ms) improvement of test cases in`test_linear_cross_entropy.py` on H20 |case |linear_cross_entropy Forward| linear_cross_entropy Forward with TMA|linear_cross_entropy Backward| linear_cross_entropy Backward with TMA| |---|---|----|---|----| |0|129.64|18.83|157.85|56.14| |1|35.35|6.02|49.91|22.10| |2|12.28|2.05|16.41|6.63| |3|71.36|10.29|89.49|31.32| |4|405.92|56.49|477.97|173.43| ### Design & Code Changes add `USE_TMA` parameter and use `tl.make_tensor_descriptor` to create desc of TMA in triton kernels if it is enabled
…kernels (verl-project#4576) ### What does this PR do? The triton kernels of linear_cross_entropy iteratively load `hidden` and `weight` block tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation. ### Test ``` python3 tests/utils/test_linear_cross_entropy.py ``` Latency(ms) improvement of test cases in`test_linear_cross_entropy.py` on H20 |case |linear_cross_entropy Forward| linear_cross_entropy Forward with TMA|linear_cross_entropy Backward| linear_cross_entropy Backward with TMA| |---|---|----|---|----| |0|129.64|18.83|157.85|56.14| |1|35.35|6.02|49.91|22.10| |2|12.28|2.05|16.41|6.63| |3|71.36|10.29|89.49|31.32| |4|405.92|56.49|477.97|173.43| ### Design & Code Changes add `USE_TMA` parameter and use `tl.make_tensor_descriptor` to create desc of TMA in triton kernels if it is enabled
…kernels (verl-project#4576) ### What does this PR do? The triton kernels of linear_cross_entropy iteratively load `hidden` and `weight` block tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation. ### Test ``` python3 tests/utils/test_linear_cross_entropy.py ``` Latency(ms) improvement of test cases in`test_linear_cross_entropy.py` on H20 |case |linear_cross_entropy Forward| linear_cross_entropy Forward with TMA|linear_cross_entropy Backward| linear_cross_entropy Backward with TMA| |---|---|----|---|----| |0|129.64|18.83|157.85|56.14| |1|35.35|6.02|49.91|22.10| |2|12.28|2.05|16.41|6.63| |3|71.36|10.29|89.49|31.32| |4|405.92|56.49|477.97|173.43| ### Design & Code Changes add `USE_TMA` parameter and use `tl.make_tensor_descriptor` to create desc of TMA in triton kernels if it is enabled
…kernels (verl-project#4576) ### What does this PR do? The triton kernels of linear_cross_entropy iteratively load `hidden` and `weight` block tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation. ### Test ``` python3 tests/utils/test_linear_cross_entropy.py ``` Latency(ms) improvement of test cases in`test_linear_cross_entropy.py` on H20 |case |linear_cross_entropy Forward| linear_cross_entropy Forward with TMA|linear_cross_entropy Backward| linear_cross_entropy Backward with TMA| |---|---|----|---|----| |0|129.64|18.83|157.85|56.14| |1|35.35|6.02|49.91|22.10| |2|12.28|2.05|16.41|6.63| |3|71.36|10.29|89.49|31.32| |4|405.92|56.49|477.97|173.43| ### Design & Code Changes add `USE_TMA` parameter and use `tl.make_tensor_descriptor` to create desc of TMA in triton kernels if it is enabled
…kernels (verl-project#4576) ### What does this PR do? The triton kernels of linear_cross_entropy iteratively load `hidden` and `weight` block tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation. ### Test ``` python3 tests/utils/test_linear_cross_entropy.py ``` Latency(ms) improvement of test cases in`test_linear_cross_entropy.py` on H20 |case |linear_cross_entropy Forward| linear_cross_entropy Forward with TMA|linear_cross_entropy Backward| linear_cross_entropy Backward with TMA| |---|---|----|---|----| |0|129.64|18.83|157.85|56.14| |1|35.35|6.02|49.91|22.10| |2|12.28|2.05|16.41|6.63| |3|71.36|10.29|89.49|31.32| |4|405.92|56.49|477.97|173.43| ### Design & Code Changes add `USE_TMA` parameter and use `tl.make_tensor_descriptor` to create desc of TMA in triton kernels if it is enabled
What does this PR do?
The triton kernels of linear_cross_entropy iteratively load
hiddenandweightblock tile by calculating data address explicitly at present, which shows poor performance on Hopper GPU. This PR improve that with the TMA of Hopper to avoid heavy address calculation.Test
Latency(ms) improvement of test cases in
test_linear_cross_entropy.pyon H20Design & Code Changes
add
USE_TMAparameter and usetl.make_tensor_descriptorto create desc of TMA in triton kernels if it is enabled