Skip to content

[training_utils] feat: use TMA to load Tiles in linear_cross_entropy kernels - #4576

Merged
wuxibin89 merged 3 commits into
verl-project:mainfrom
CtfGo:linear_cross_entropy_with_tma
Dec 22, 2025
Merged

[training_utils] feat: use TMA to load Tiles in linear_cross_entropy kernels#4576
wuxibin89 merged 3 commits into
verl-project:mainfrom
CtfGo:linear_cross_entropy_with_tma

Conversation

@CtfGo

@CtfGo CtfGo commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

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 intest_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

@CLAassistant

CLAassistant commented Dec 17, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread verl/utils/kernel/kernels.py
Comment thread verl/utils/kernel/kernels.py
Comment thread verl/utils/kernel/kernels.py
Comment thread verl/utils/kernel/kernels.py
@CtfGo
CtfGo force-pushed the linear_cross_entropy_with_tma branch from cca9cbd to 28d7c76 Compare December 17, 2025 14:04
@wuxibin89
wuxibin89 merged commit 2d5aafe into verl-project:main Dec 22, 2025
74 of 79 checks passed
@HollowMan6

Copy link
Copy Markdown
Collaborator

#4676 fixes the support for triton >= 3.5.0

jsfanfanfan pushed a commit to meituan-search/verl that referenced this pull request Jan 9, 2026
…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
vyomakesh0728 added a commit to vyomakesh0728/verl that referenced this pull request Jan 22, 2026
…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
sophiayyya pushed a commit to sophiayyya/verl that referenced this pull request Jan 25, 2026
…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
DaizeDong pushed a commit to DaizeDong/verl that referenced this pull request Apr 19, 2026
…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
zwluestc pushed a commit to zwluestc/verl that referenced this pull request May 12, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants