Skip to content

Commit

Permalink
[INTERPRETER] Patch globals more carefully (#5485)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
stephen-huan authored Dec 23, 2024
1 parent 513a047 commit a2b398e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python/triton/runtime/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a2b398e

Please sign in to comment.