You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
query: is_*_namespace: input must be hashable? #421
Modules are hashable, unless under torch.compile IIUC, so I suppose it is related to #411, which you fixed in gh-413.
Here's a quick poking around session with torch.compile below. It looks like Dynamo special-cases @lru_cache so that it compiles at least, but there's some rough edge with resource management (cf the printed backtrace on exit). No idea how severe it is though, so probably some more investigation is in order.
In [1]: from array_api_compat import is_numpy_namespace, is_torch_namespace, is_jax_namespace
In [2]: def foo(x, xp):
...: x = x*x
...: return x, is_torch_namespace(xp), is_numpy_namespace(xp)
...:
In [4]: import torch
In [5]: bar = torch.compile(fullgraph=True)(foo)
In [6]: bar(torch.arange(3), torch)
Out[6]: (tensor([0, 1, 4]), True, False)
In [7]: exit()
Exception ignored in: <function ExactWeakKeyDictionary.__setitem__.<locals>.<lambda> at 0x7fde1cd06340>
Traceback (most recent call last):
File "/home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/torch/_dynamo/utils.py", line 908, in <lambda>
self.refs[idx] = weakref.ref(key, lambda ref: self._remove_id(idx))
^^^^^^^^^^^^^^^^^^^^
File "/home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/torch/_dynamo/utils.py", line 1928, in _remove_id
hook()
File "/home/br/miniforge3/envs/scipy-dev/lib/python3.12/site-packages/torch/_dynamo/utils.py", line 1912, in __call__
del self.scope[self.name]
~~~~~~~~~~^^^^^^^^^^^
KeyError: '__builtins_dict___0'
Activity
ev-br commentedon Apr 19, 2026
Modules are hashable, unless under
torch.compileIIUC, so I suppose it is related to #411, which you fixed in gh-413.Here's a quick poking around session with
torch.compilebelow. It looks like Dynamo special-cases@lru_cacheso that it compiles at least, but there's some rough edge with resource management (cf the printed backtrace on exit). No idea how severe it is though, so probably some more investigation is in order.Two more comments/questions:
torch.compile#413; cf Raymond Hettinger's answer athttps://stackoverflow.com/questions/30730983/make-lru-cache-ignore-some-of-the-function-arguments which suggests an auxilliary function. Will probably want to see if this
is_*_namespacefunctions are decorated with@lru_cache; e.g.is_jax_namespaceis not. Was this deliberate?lucascolley commentedon Apr 19, 2026
ah, okay, this might be a bug in the type-checker I was using, sorry. DetachHead/basedpyright#1779