Skip to content

Use symlinks for external plugins to fix TRITON_PLUGIN_DIRS #6627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Apr 28, 2025

Disable the new backend installing logic for external plugins, since package_dir does not accept absolute paths. Instead, use a hybrid approach where in-tree backends are installed using the new logic and external backends are symlinked. This implies that source distributions cannot be created when using external plugins.

Fixes #6612


New contributor declaration

  • I am not making a trivial change, such as fixing a typo in a comment.

  • I have written a PR description following these
    rules.

  • I have run pre-commit run --from-ref origin/main --to-ref HEAD.

  • Select one of the following.

    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because it touches build system only.
  • Select one of the following.

    • I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

Disable the new backend installing logic for external plugins, since
`package_dir` does not accept absolute paths.  Instead, use a hybrid
approach where in-tree backends are installed using the new logic
and external backends are symlinked.  This implies that source
distributions cannot be created when using external plugins.

Fixes triton-lang#6612
@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

One note: I've noticed a potential bug in the logic (that was there before my first change):

creating symlink: /home/mgorny/git/triton/python/triton/backends/triton_shared -> /tmp/triton_shared/backend
creating symlink: /home/mgorny/git/triton/python/triton/tools/extra/triton-shared-opt -> /tmp/triton_shared/tools/triton-shared-opt
creating symlink: /home/mgorny/git/triton/python/triton/tools/extra/RegisterTritonSharedDialects.h -> /tmp/triton_shared/tools/RegisterTritonSharedDialects.h
creating symlink: /home/mgorny/git/triton/python/triton/tools/extra/CMakeLists.txt -> /tmp/triton_shared/tools/CMakeLists.txt

Note that files like RegisterTritonSharedDialects.h and CMakeLists.txt ended up being symlinked into tools/extra/. Perhaps we should consider only directories there?

@BabakkGraphcore
Copy link
Contributor

Seeing the same error as before with this change. I think because even though the symlinks are setup for the external plugins their package_dir path is still TRITON_PLUGIN_DIRS and so absolute.

@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

They shouldn't, unless I really messed something up:

triton/setup.py

Lines 599 to 601 in f5c252c

# we use symlinks for external plugins
if backend.is_external:
continue

Did you do a full clean of the build tree? Ideally git clean -dfx, as setuptools metadata tends to persist a lot.

@BabakkGraphcore
Copy link
Contributor

Ah, sorry - you're right. Successful build after that 🎉 However non .py files from the backend didn't get installed. Does the manifest need to be tweaked ?

@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

Sorry — just made a dummy backend and reproduced the problem. I think the problem is that find_packages() is run prior to creating the symlinks. I'll investigate — perhaps the simplest solution will be to create external plugin symlinks in global scope.

@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

@BabakkGraphcore, could you try now?

@BabakkGraphcore
Copy link
Contributor

@BabakkGraphcore, could you try now?

No change. Tested with...

 git clean -dfx
 pip -v install  --force-reinstall  . 

The specific file that isn't being copied is a .cpp if that helps with your testing setup at all.

@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

In backend directory? Let me sigh a bit, then try to fix it. Data files with setuptools are a nightmare.

@mgorny
Copy link
Contributor Author

mgorny commented Apr 28, 2025

Ah, sorry, now I understand what you meant by the manifest. I forgot that it affects installing data files.

@BabakkGraphcore
Copy link
Contributor

thanks @mgorny that looks to be working now, build + tests passing 🎉

going to try one more test and get it a passing CI workflow with it

@BabakkGraphcore
Copy link
Contributor

going to try one more test and get it a passing CI workflow with it

Took a while 😅 but all good, thanks for the fix

@Jokeren Jokeren merged commit 784b550 into triton-lang:main Apr 29, 2025
8 checks passed
FindHao pushed a commit to FindHao/triton that referenced this pull request Apr 30, 2025
…ang#6627)

Disable the new backend installing logic for external plugins, since
`package_dir` does not accept absolute paths. Instead, use a hybrid
approach where in-tree backends are installed using the new logic and
external backends are symlinked. This implies that source distributions
cannot be created when using external plugins.

Fixes triton-lang#6612

------


<!---
The core Triton is a small number of people, and we receive many PRs
(thank
you!).  To help us review your code more quickly, **if you are a new
contributor (less than 3 PRs merged) we ask that you complete the
following
tasks and include the filled-out checklist in your PR description.**

Complete the following tasks before sending your PR, and replace `[ ]`
with
`[x]` to indicate you have done them.
-->

# New contributor declaration
- [x] I am not making a trivial change, such as fixing a typo in a
comment.

- [x] I have written a PR description following these
  [rules](https://cbea.ms/git-commit/#why-not-how).

- [x] I have run `pre-commit run --from-ref origin/main --to-ref HEAD`.

- Select one of the following.
  - [ ] I have added tests.
    - `/test` for `lit` tests
    - `/unittest` for C++ tests
    - `/python/test` for end-to-end tests
- [x] This PR does not need a test because it touches build system only.

- Select one of the following.
  - [x] I have not added any `lit` tests.
- [ ] The `lit` tests I have added follow these [best
practices](https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices),
including the "tests should be minimal" section. (Usually running Python
code
    and using the instructions it generates is not minimal.)
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.

Adding third party TRITON_PLUGIN_DIRS is broken
4 participants