From a2b398e0bb1b120f31cf386d6ae3261c3ab84207 Mon Sep 17 00:00:00 2001 From: Stephen Huan Date: Mon, 23 Dec 2024 10:07:04 -0800 Subject: [PATCH] [INTERPRETER] Patch globals more carefully (#5485) Fixes #5484. Since python objects can arbitrarily override `__contains__`, using `inspect.ismodule` seems to be the most general solution, beyond numpy arrays. Overriding a module's `__contains__` would be very strange. ```python >>> import triton.language as tl >>> import inspect >>> inspect.ismodule(tl) True >>> inspect.ismodule(tl.core) True ``` --- python/triton/runtime/interpreter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/triton/runtime/interpreter.py b/python/triton/runtime/interpreter.py index e6942d470f8a..d4a09ffaf8ba 100644 --- a/python/triton/runtime/interpreter.py +++ b/python/triton/runtime/interpreter.py @@ -1001,7 +1001,7 @@ def _set_attr(input, values, name): def _patch_lang(fn): - langs = [value for _, value in fn.__globals__.items() if value in [tl, tl.core]] + langs = [value for _, value in fn.__globals__.items() if inspect.ismodule(value) and value in [tl, tl.core]] assert len(langs) >= 1, "triton.language must be visible from within jit'd function" for lang in langs: _patch_builtin(lang, interpreter_builder)