Skip to content

[PyTorch] Add triton requirement - #2490

Merged
ksivaman merged 6 commits into
NVIDIA:mainfrom
ksivaman:triton_req
Dec 12, 2025
Merged

ksivaman merged 6 commits into
NVIDIA:mainfrom
ksivaman:triton_req

Conversation

@ksivaman

@ksivaman ksivaman commented Dec 9, 2025

Copy link
Copy Markdown
Member

Description

Add requirement for triton.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Add requirement for triton.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
@ksivaman
ksivaman requested a review from tdophung December 9, 2025 14:37
@ksivaman

ksivaman commented Dec 9, 2025

Copy link
Copy Markdown
Member Author

/te-ci pytorch

@greptile-apps

greptile-apps Bot commented Dec 9, 2025 •

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Added triton to PyTorch install requirements, restoring a critical dependency that was accidentally removed during a previous merge.

  • The codebase extensively uses Triton for GPU kernels (permutation, cross entropy, padding operations)
  • JAX already includes triton in test requirements (build_tools/jax.py:23)
  • The change ensures consistent dependency management across the project
  • Uses the correct package name triton (not pytorch-triton)

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The change is a simple, necessary dependency addition that restores functionality. The codebase already imports and uses triton in multiple locations, making this dependency required for proper functionality. No logic changes or breaking modifications were introduced.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
build_tools/pytorch.py 5/5 Added triton to install requirements, restoring dependency that was accidentally removed in a previous merge

Sequence Diagram

sequenceDiagram
    participant User
    participant Setup as setup.py
    participant BuildTools as build_tools/pytorch.py
    participant PyPI
    participant TE as TransformerEngine
    
    User->>Setup: pip install transformer_engine_torch
    Setup->>BuildTools: Call install_requirements()
    BuildTools-->>Setup: Return dependency list including triton
    Setup->>PyPI: Install triton package
    PyPI-->>Setup: triton installed
    Setup->>TE: Build and install TransformerEngine
    TE->>TE: Import triton modules
    Note over TE: Uses triton for:<br/>- Permutation kernels<br/>- Cross entropy<br/>- Padding operations<br/>- Custom GPU kernels
    TE-->>User: Package ready to use
Loading

@greptile-apps greptile-apps 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.

Additional Comments (1)

  1. build_tools/pytorch.py, line 17 (link)

    syntax: incorrect package name - should be triton, not pytorch-triton

    the JAX setup in build_tools/jax.py:23 correctly uses triton as a dependency. the package on PyPI is named triton, not pytorch-triton

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
@ksivaman

Copy link
Copy Markdown
Member Author

/te-ci pytorch

@greptile-apps greptile-apps 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.

Additional Comments (1)

  1. build_tools/pytorch.py, line 17 (link)

    style: consider adding version constraint for triton - the codebase had compatibility issues with triton 3.5 (see commit dd7ab71)

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

tdophung
tdophung previously approved these changes Dec 10, 2025

@tdophung tdophung left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>

@greptile-apps greptile-apps 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.

Additional Comments (1)

  1. build_tools/pytorch.py, line 25 (link)

    style: No version constraint specified for triton. The codebase has compatibility code for triton>=3.5.0 (see transformer_engine/pytorch/triton/permutation.py:21), so consider adding a minimum version constraint.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@ksivaman

Copy link
Copy Markdown
Member Author

/te-ci pytorch

@tdophung

Copy link
Copy Markdown
Collaborator

/te-ci pytorch

@greptile-apps greptile-apps 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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ptrendx ptrendx added the build Build system label Dec 11, 2025
@ksivaman
ksivaman merged commit 8c9f7c2 into NVIDIA:main Dec 12, 2025
@ksivaman
ksivaman deleted the triton_req branch December 12, 2025 13:44
nvegesna-netizen added a commit to nvegesna-netizen/TransformerEngine that referenced this pull request Sep 22, 2026
Review asked whether the -1 to None translation should sit behind a version
gate keyed on the FA4 release that changed the sentinel. It does not need one,
and the reason is worth recording where the next reader will look.

Transcribing flash-attention's _resolve_causal_local_window from before NVIDIA#2490
(interface.py @ 59cf537812) and after it, and running every (causal, window)
pair TE emits through both:

  mask type              b11 as-is       b11 normalized   post-2490 as-is
  causal                 CAUSAL          CAUSAL           LOCAL left=-1 right=0
  causal_bottom_right    CAUSAL          CAUSAL           LOCAL left=-1 right=0
  no_mask                FULL            FULL             FULL
  sliding window         LOCAL 511/0     LOCAL 511/0      LOCAL 511/0

Normalizing changes nothing on the older release, because the old code reaches
the same resolved state from (-1, 0) by widening that the new code reaches from
(None, 0) directly. So the translation is inert before the change and corrective
after it, with no version boundary to get wrong. All four entry points funnel
through that one resolver, on both releases, so the trace covers them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nvegesna-netizen added a commit to nvegesna-netizen/TransformerEngine that referenced this pull request Oct 1, 2026
FA4 returns an all-zero output for causal attention on SM100, silently. No
exception, no warning, finite values, every element zero. Measured against a
float64 reference on B200, with no context parallelism involved:

    flash_attn_func(q, k, v, causal=True, window_size=(-1, 0))
        out.abs().max() = 0.0            relerr = 1.000e+00
    flash_attn_func(q, k, v, causal=True, window_size=(None, None))
        out.abs().max() = 3.453125       relerr = 2.046e-03

TE normalizes an unbounded window side to -1; FA4 spells it None. Until
flash-attention NVIDIA#2490 a shim widened any pair summing below zero to full
attention, so TE's (-1, 0) was always erased and causal= alone set the mask.
NVIDIA#2490 narrowed that to pairs where both bounds are negative, so (-1, 0) now
survives as a literal band of [row + 1, row] -- empty. The kernel returns zeros
and an all -inf LSE.

Normalizing negative bounds to None at the four FA4 entry points, rather than at
the ~20 sites that build these kwargs: those sites are shared with FA2 >= 2.7 and
FA3, where -1 is the correct spelling, so fixing them in place would mean forking
every one on use_flash_attn_4.

All four entry points, not just the two used by context parallelism. The non-CP
path calls flash_attn_func/flash_attn_varlen_func; CP calls
_flash_attn_fwd/_flash_attn_bwd. Covering one pair is worse than covering
neither, because run_attention_with_cp.py grades a CP run against a non-CP run of
the same backend: with both sides zero the comparison agrees, and correcting one
side alone makes the fix present as a regression. That is not hypothetical --
it is what an earlier partial attempt did.

Three reasons CI could not see this, all still worth addressing separately:
NVTE_FLASH_ATTN_V4=0 in the distributed suite, a flash-attn-4 pin predating
NVIDIA#2490, and the self-referential comparison above, which cannot detect any error
affecting CP and non-CP equally.

The new test anchors to a float64 reference rather than to another backend, and
pins FlashAttention -- cuDNN FusedAttention wins selection for the shape under
test and would mask the defect entirely.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com>
nvegesna-netizen added a commit to nvegesna-netizen/TransformerEngine that referenced this pull request Oct 1, 2026
Review asked whether the -1 to None translation should sit behind a version
gate keyed on the FA4 release that changed the sentinel. It does not need one,
and the reason is worth recording where the next reader will look.

Transcribing flash-attention's _resolve_causal_local_window from before NVIDIA#2490
(interface.py @ 59cf537812) and after it, and running every (causal, window)
pair TE emits through both:

  mask type              b11 as-is       b11 normalized   post-2490 as-is
  causal                 CAUSAL          CAUSAL           LOCAL left=-1 right=0
  causal_bottom_right    CAUSAL          CAUSAL           LOCAL left=-1 right=0
  no_mask                FULL            FULL             FULL
  sliding window         LOCAL 511/0     LOCAL 511/0      LOCAL 511/0

Normalizing changes nothing on the older release, because the old code reaches
the same resolved state from (-1, 0) by widening that the new code reaches from
(None, 0) directly. So the translation is inert before the change and corrective
after it, with no version boundary to get wrong. All four entry points funnel
through that one resolver, on both releases, so the trace covers them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Nitin Vegesna <nvegesna@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants