diff --git a/array_api_compat/common/_helpers.py b/array_api_compat/common/_helpers.py index 8a307f9d..10134367 100644 --- a/array_api_compat/common/_helpers.py +++ b/array_api_compat/common/_helpers.py @@ -641,7 +641,7 @@ def your_function(x, y): is_pydata_sparse_array """ - namespaces: set[Namespace] = set() + namespaces: list[Namespace] = [] for x in xs: xp, info = _cls_to_namespace(cast(Hashable, type(x)), api_version, use_compat) if info is _ClsToXPInfo.SCALAR: @@ -663,7 +663,19 @@ def your_function(x, y): ) xp = get_ns(api_version=api_version) - namespaces.add(xp) + namespaces.append(xp) + + # Use a list of modules to avoid a graph break under torch.compile: + # torch._dynamo.exc.Unsupported: Dynamo cannot determine whether the underlying object is hashable + # Explanation: Dynamo does not know whether the underlying python object for + # PythonModuleVariable(