Skip to content

CMakeLists.txt: AOTRITON_INHERIT_SYSTEM_SITE_TRITON flag#116

Merged
xinyazhang merged 1 commit intoROCm:mainfrom
LunNova:lunnova/external-triton-option
Aug 19, 2025
Merged

CMakeLists.txt: AOTRITON_INHERIT_SYSTEM_SITE_TRITON flag#116
xinyazhang merged 1 commit intoROCm:mainfrom
LunNova:lunnova/external-triton-option

Conversation

@LunNova
Copy link
Copy Markdown
Contributor

@LunNova LunNova commented Aug 17, 2025

Closes #114

Motivation

Reusing an existing triton install allows building it separately from aotriton.

This is useful for nixpkgs' packaging of aotriton as we would prefer to build triton in a separate derivation and import it in aotriton.

Technical Details

Added a new CMake flag that's off by default that enables the --system-site-packages flag when creating the venv and checks an existing triton can be imported instead of building it from the submodule.

Test Plan

Build with and without the flag enabled.

Test Result

Works for both cases.

Submission Checklist

Copy link
Copy Markdown
Collaborator

@xinyazhang xinyazhang left a comment

Choose a reason for hiding this comment

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

I don't think this PR will work as intended.

A dedicated venv is created under the build directory regardless the value of AOTRITON_USE_EXTERNAL_TRITON, and the import triton under this venv will not work unless you have already installed one.

If a dedicated Triton is preferred, I suggest let this variable point to a .whl file and install the wheel file into the venv, which is easier to deal with and more flexible.

@xinyazhang
Copy link
Copy Markdown
Collaborator

Another problem is: aotriton has extended the Triton language a little bit for NPOT head dimension optimization, and consequently its kernel cannot be compiled by stock Triton.

@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 18, 2025

A dedicated venv is created under the build directory regardless the value of AOTRITON_USE_EXTERNAL_TRITON, and the import triton under this venv will not work unless you have already installed one.

It works in the nixpkgs context but maybe nixpkgs is customizing something to default venvs to ineriting from site-wide packages.
Should I enable --system-site-packages when creating the venv if the triton inherit flag is set?

Another problem is: aotriton has extended the Triton language a little bit for NPOT head dimension optimization, and consequently its kernel cannot be compiled by stock Triton.

Does this apply for 0.10 or only current HEAD? Not getting any compile errors on 0.10b with upstream triton 3.3.

@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 18, 2025

If a dedicated Triton is preferred, I suggest let this variable point to a .whl file and install the wheel file into the venv, which is easier to deal with and more flexible.

I don't think this would help at all with how nixpkgs' python packaging works.

Even if we have to pin a specific ROCm/triton sha it's a lot easier on our end if our aotriton build can inherit a site-packages triton that was built from that sha, otherwise we have to duplicate code needed to get triton to work for our aotriton package.

@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 18, 2025

@LunNova LunNova requested a review from xinyazhang August 18, 2025 03:31
@LunNova LunNova force-pushed the lunnova/external-triton-option branch from 0e84e7f to ddab9e2 Compare August 18, 2025 03:51
@xinyazhang
Copy link
Copy Markdown
Collaborator

Does this apply for 0.10 or only current HEAD? Not getting any compile errors on 0.10b with upstream triton 3.3.

Please double check the actual Triton version you are using to compile. In current code framework the only way to use upstream Triton is to call test_*.py under tritonsrc/. The .bit_length extension is not upstreamed yet.

It works in the nixpkgs context but maybe nixpkgs is customizing something to default venvs to ineriting from site-wide packages.

If that's true the problem is the AOTRITON_USE_EXTERNAL_TRITON does not do what is was named for. I don't have any nixos environment to validate, but the code path basically does the following thing

python -m venv build/venv
build/venv/bin/pip install -r requirements.txt
build/venv/bin/python -c "import triton; import triton.language; print('Triton found: ', triton.__version__)"

Unless nixos hacked venv pacakge, the last setup should always fail because it is intentionally avoided to add heavy weight packages (e.g., torch/triton) to requirements.txt.

In addition, to make the code above work, the standard practice is to use --system-site-packages, which means your PR only needs the current AOTRITON_VENV_INHERIT_SITE_PACKAGES (or rename it to AOTRITION_INHERIT_SYSTEM_SITE_TRITON for better self-describing)

The supposed logic of AOTRITON_USE_EXTERNAL_TRITON, from its name, should be:

python -m venv build/venv
build/venv/bin/pip install -r requirements.txt
build/venv/bin/pip install ${AOTRITON_USE_EXTERNAL_TRITON}
# Skip triton build later

@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 18, 2025

Unless nixos hacked venv pacakge, the last setup should always fail because it is intentionally avoided to add heavy weight packages (e.g., torch/triton) to requirements.txt.

Yeah - it looks like nixos hacked venv creation to implicitly inherit global site-packages, hence it working earlier.

I've pushed an additional commit which adds a flag to enable inheriting site packages when creating the venv so the external triton option is usable on other distros.

@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 18, 2025

To confirm, you'd be ok with a single flag AOTRITION_INHERIT_SYSTEM_SITE_TRITON which enables --system-site-packages and verifies triton is available in the venv without trying to pip install it?

@xinyazhang
Copy link
Copy Markdown
Collaborator

xinyazhang commented Aug 18, 2025

To confirm, you'd be ok with a single flag AOTRITION_INHERIT_SYSTEM_SITE_TRITON which enables --system-site-packages and verifies triton is available in the venv without trying to pip install it?

Yes.
This is a more natural solution IMO.

The only concern is unlike its name it inherits everything. But the other naming scheme is also problematic: users are not informed this option expects Triton from system site and they may prefer a "clean" system site and avoid installing triton there.

Compared with the second option I think the first one's risk is lower: venv users should easily guess the "inheritance" is achieved through --system-site-packages

AOTRITION_INHERIT_SYSTEM_SITE_TRITON creates the venv with --system-site-packages set
and verifies triton is pre-installed instead of building it from source.

This is useful for hermetic build environments where the triton setup process will fail
due to its online components, such as nixpkgs.
@LunNova LunNova changed the title CMakeLists.txt: use existing triton if AOTRITON_USE_EXTERNAL_TRITON is set CMakeLists.txt: AOTRITON_INHERIT_SYSTEM_SITE_TRITON flag Aug 19, 2025
@LunNova LunNova force-pushed the lunnova/external-triton-option branch from ddab9e2 to e20af1d Compare August 19, 2025 02:39
@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 19, 2025

Updated to use AOTRITION_INHERIT_SYSTEM_SITE_TRITON

Copy link
Copy Markdown
Collaborator

@xinyazhang xinyazhang left a comment

Choose a reason for hiding this comment

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

LGTM

@xinyazhang xinyazhang merged commit 9734c3e into ROCm:main Aug 19, 2025
@LunNova
Copy link
Copy Markdown
Contributor Author

LunNova commented Aug 19, 2025

Thanks!

@LunNova LunNova deleted the lunnova/external-triton-option branch August 19, 2025 14:48
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.

[Feature]: It should be possible to reuse an existing triton

2 participants