Skip to content
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

[release/2.5] [user triton] Ignore backend-specific args in the TTIR analysis (#141… #1768

Open
wants to merge 1 commit into
base: release/2.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions torch/_higher_order_ops/triton_kernel_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,23 @@ def generate_ttir(kernel, kwargs):

assert isinstance(kernel, JITFunction)

context = triton._C.libtriton.ir.context()
target = triton.runtime.driver.active.get_current_target()
backend = triton.compiler.compiler.make_backend(target)
options = backend.parse_options({})

# ignore backend-specific kwargs same way as in the native Triton code
# https://github.com/triton-lang/triton/blob/a6bb57d6285e723c58e87dd7cba263db6efff789/python/triton/runtime/jit.py#L594-L596
# why this is important for user-defined Triton kernels on AMD: https://github.com/pytorch/pytorch/issues/140800
for name in list(kwargs):
if name not in kernel.arg_names and name in options.__dict__:
kwargs.pop(name)

if len(kwargs) != len(kernel.arg_names):
raise ValueError("Incorrect number of arguments passed to kernel")
raise ValueError(
"Incorrect number of arguments passed to kernel: "
f"passed {list(kwargs.keys())}, expected {kernel.arg_names}."
)

# Replace all SymExprs with a regular value for TTIR generation
# Replace all FakeTensor/TensorBox with real tensors
Expand Down Expand Up @@ -168,10 +183,6 @@ def generate_ttir(kernel, kwargs):
if i not in kernel.constexprs
}

context = triton._C.libtriton.ir.context()
target = triton.runtime.driver.active.get_current_target()
backend = triton.compiler.compiler.make_backend(target)
options = backend.parse_options({})
triton._C.libtriton.ir.load_dialects(context)
backend.load_dialects(context)

Expand Down