[XPU] Fix patch for old llvm package error for triton xpu (#134204)

Fixes #134199

The PR #133694 does a workaround to replace the str `"https://tritonlang.blob.core.windows.net/llvm-builds/"` with  `"https://oaitriton.blob.core.windows.net/public/llvm-builds/"` in `triton/python/setup.py`. However, in [newer version of Triton](06e6799f4e), it has already been changed to `"https://oaitriton.blob.core....` and don't need to be replaced.  But formerly, this will throw a runtime error.

This PR makes the `check_and_replace` logic won't fail in such a scenario. Both the old link and the newer link could work.

Also note that the `.ci/docker/common/install_triton.sh` does not need the fix, because its `sed` command won't be in effect if there is no such pattern.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/134204
Approved by: https://github.com/chuanqi129, https://github.com/EikanWang, https://github.com/atalman
This commit is contained in:
Stonepia
2024-08-22 23:18:44 +00:00
committed by PyTorch MergeBot
parent 629bd6f718
commit 30d7e7a1cd

View File

@ -54,6 +54,7 @@ def patch_init_py(
def patch_setup_py(path: Path) -> None:
with open(path) as f:
orig = f.read()
try:
orig = check_and_replace(
orig,
"https://tritonlang.blob.core.windows.net/llvm-builds/",
@ -61,6 +62,11 @@ def patch_setup_py(path: Path) -> None:
)
with open(path, "w") as f:
f.write(orig)
except RuntimeError as e:
print(
f"Applying patch_setup_py() for llvm-build package failed: {e}.",
"If you are trying to build a newer version of Triton, you can ignore this.",
)
def build_triton(