NVIDIA / NVIDIA/TransformerEngine
Performance bottleneck in TransformerLayer and Attention when using attention mask
@cyanguwa is already working on this.
Since Mar 2, 2026.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 831
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 65
Description
Describe the bug
Dear Nvidia experts,
When attention mask is used, these three lines will cause very significant slow down since they are looping over all the items in the batch.
Performance bottleneck in TransformerLayer and Attention.
assertion the type of attention mask
similarly another assertion the type of attention mask
See below for profiling trace:
As you can see from the largest bar from the bottom rows, operations taking most of the time in each transformer is now transformer_engine/pytorch/attention/dot_product_attention/utils.py(1518): get_indices, Similarly the other two assertion is also cause significant slow down.
Steps/Code to reproduce bug
This problem should manifest in any profiling run with data that have attention mask in the input of forward()
Expected behavior
Multiple times of slow down when calling forward of TransformerLayer.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.