microsoft / triton-shared

Shared Middle-Layer for Triton Compilation
MIT License
165 stars 34 forks source link

triton-shared doesn't work with latest triton commit #76

Closed Duconnor closed 8 months ago

Duconnor commented 9 months ago

I have successfully built triton along with the triton-shared project. I can use the triton-shared-opt command line tool to lower triton ir but I was unable to use triton-shared as a backend component. I've tried to run python python/examples/test_reduce.py but failed with the following error:

Traceback (most recent call last):
  File "/xxx/third_party/triton_shared/python/examples/test_reduce.py", line 55, in <module>
    test()
  File "/xxx/third_party/triton_shared/python/examples/test_reduce.py", line 39, in test
    reduce_kernel_2d[grid](x, output, x.stride(0), n_rows, BLOCK_SIZE=BLOCK_SIZE)
  File "/xxx/python/triton/runtime/jit.py", line 164, in <lambda>
    return lambda *args, **kwargs: self.run(grid=grid, warmup=False, *args, **kwargs)
  File "/xxx/python/triton/runtime/jit.py", line 346, in run
    device = driver.get_current_device()
  File "/xxx/python/triton/runtime/driver.py", line 231, in __getattr__
    return getattr(self._obj, name)
AttributeError: 'UnsupportedDriver' object has no attribute 'get_current_device'

The error seems to be caused by the fact that there is no available driver for the CPU backend in triton. By inspecting the relevant code, I found that there is only HIPDriver and CudaDriver available in triton for now. So do I need to make any extra adjustment in order to run this example? Any suggestion would be greatly appreciated.

By the way, this is a really interesting project that tries to lower triton IR to linalg. Nice job guys. :)

nhat-nguyen commented 9 months ago

Thank you for trying the project out. triton latest has some breaking changes that make the 3rd party backends no longer work. You can check out triton at commit 56c284cf7e39f249cdf1d8d5dba7892deb0286d6 which is right before the breaking change.

The 3rd party refactor is still ongoing, once triton main finalizes all the changes, we will update triton-shared to work with the new 3rd party backend integration.

srcarroll commented 9 months ago

Can you elaborate on how to get this working? First of all the triton-shared submodule in this triton sha doesn't contain the python/examples/ directory. Second, even if i update the submodule to latest, i still get an error ValueError: Cannot find backend for cpu. Thanks in advance

nhat-nguyen commented 9 months ago

So the setup should be something like (which I think you already have)

This is what our GitHub actions have as well, as you can see here: https://github.com/microsoft/triton-shared/blob/main/.github/workflows/integration-tests.yml

Perhaps a clean build would help, the steps in https://github.com/microsoft/triton-shared/blob/main/.github/workflows/test-plugin.yml are what we use to build locally. Note that the CPU backend requires having 2 environment variables TRITON_SHARED_OPT_PATH and LLVM_BINARY_DIR:

cd triton/python
export TRITON_SHARED_OPT_PATH=$(pwd)/build/$(ls $(pwd)/build | grep -i cmake)/third_party/triton_shared/tools/triton-shared-opt/triton-shared-opt
export LLVM_BINARY_DIR=${HOME}/.triton/llvm/$(ls ${HOME}/.triton/llvm/ | grep -i llvm)/bin
srcarroll commented 9 months ago

Thanks for all the info. I'll try this out and let you know if i run into any more issues

srcarroll commented 8 months ago

I'm curious what the timeline is for fixing this upstream. Is there a current PR out there I can track?

P.S. @nhat-nguyen, I was able to get it to work with your directions. Thanks again!

nhat-nguyen commented 8 months ago

P.S. @nhat-nguyen, I was able to get it to work with your directions. Thanks again!

Glad that worked for you.

I'm curious what the timeline is for fixing this upstream. Is there a current PR out there I can track?

@srcarroll triton upstream still doesn't fully support 3rd party plugin after the recent refactor. I'm trying to get a fix out as soon as I can, but there are still some details to work out. You can follow this channel where we discuss the progress: https://app.slack.com/client/T01379XQ9FG/C05461NMQUU

nhat-nguyen commented 8 months ago

@srcarroll We made some progress on this. Going forward, triton will require plugins to include triton as a submodule. There's an ongoing PR to support building 3rd party plugin using this new structure: https://github.com/openai/triton/pull/3007

While waiting for that PR to complete, we have updated our reference CPU backend to work with triton latest and include a submodule that points to the branch in the above PR (#87).

I have also updated the instructions on how to build with the new structure. Let me know if you have any issues. The instructions might change depending on the feedback in the ongoing PR.

srcarroll commented 8 months ago

@srcarroll We made some progress on this. Going forward, triton will require plugins to include triton as a submodule. There's an ongoing PR to support building 3rd party plugin using this new structure: https://github.com/openai/triton/pull/3007

While waiting for that PR to complete, we have updated our reference CPU backend to work with triton latest and include a submodule that points to the branch in the above PR (#87).

I have also updated the instructions on how to build with the new structure. Let me know if you have any issues. The instructions might change depending on the feedback in the ongoing PR.

Sweet! Thanks for the update. I'll give it a go in the next couple days and let you know.

nhat-nguyen commented 8 months ago

I'm marking this as fixed by #87. Feel free to reopen the issue again if you have any other issues. 😄