Skip to content

ENH: fix is_jax_array under torch.compile - #464

Open
lucascolley wants to merge 1 commit into
data-apis:mainfrom
lucascolley:is-jax-torch-compile
Open

ENH: fix is_jax_array under torch.compile#464
lucascolley wants to merge 1 commit into
data-apis:mainfrom
lucascolley:is-jax-torch-compile

Conversation

@lucascolley

Copy link
Copy Markdown
Member

This fixes errors like the following:

E               torch._dynamo.exc.UserError:
GetAttrVariable(TupleVariable(length=0), dtype) has no type
E               For more information about this error, see:
https://pytorch.org/docs/main/generated/exportdb/index.html#unknown-python-type
E
E               from user code:
E                  File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_lib/_helpers.py",
line 612, in inner
E                   res = func(*args, **kwargs)  # pyright:
ignore[reportCallIssue]
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/tests/main/test_at.py",
line 47, in at_op
E                   return meth(y, copy=copy, xp=xp)
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_at.py",
line 374, in add
E                   return self._op(_AtOp.ADD, operator.iadd,
operator.add, y, copy=copy, xp=xp)  # pyright:
ignore[reportUnknownArgumentType]
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_at.py",
line 289, in _op
E                   (_compat.is_dask_array(idx) or
_compat.is_jax_array(idx))
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/.pixi/envs/tests-backends/lib/python3.14/site-packages/array_api_compat/common/_helpers.py",
line 253, in is_jax_array
E                   or _is_jax_zero_gradient_array(x)
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/.pixi/envs/tests-backends/lib/python3.14/site-packages/array_api_compat/common/_helpers.py",
line 84, in _is_jax_zero_gradient_array
E                   cls = cast(Hashable, type(dtype))

cc @crusaderky for vis

This fixes errors like the following:
```
E               torch._dynamo.exc.UserError:
GetAttrVariable(TupleVariable(length=0), dtype) has no type
E               For more information about this error, see:
https://pytorch.org/docs/main/generated/exportdb/index.html#unknown-python-type
E
E               from user code:
E                  File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_lib/_helpers.py",
line 612, in inner
E                   res = func(*args, **kwargs)  # pyright:
ignore[reportCallIssue]
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/tests/main/test_at.py",
line 47, in at_op
E                   return meth(y, copy=copy, xp=xp)
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_at.py",
line 374, in add
E                   return self._op(_AtOp.ADD, operator.iadd,
operator.add, y, copy=copy, xp=xp)  # pyright:
ignore[reportUnknownArgumentType]
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/src/array_api_extra/_at.py",
line 289, in _op
E                   (_compat.is_dask_array(idx) or
_compat.is_jax_array(idx))
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/.pixi/envs/tests-backends/lib/python3.14/site-packages/array_api_compat/common/_helpers.py",
line 253, in is_jax_array
E                   or _is_jax_zero_gradient_array(x)
E                 File
"/Users/lucascolley/ghq/github.com/data-apis/array-api-extra/.pixi/envs/tests-backends/lib/python3.14/site-packages/array_api_compat/common/_helpers.py",
line 84, in _is_jax_zero_gradient_array
E                   cls = cast(Hashable, type(dtype))
```
@lucascolley
lucascolley requested a review from ev-br August 16, 2026 14:03
@ev-br

ev-br commented Aug 16, 2026

Copy link
Copy Markdown
Member

Is there an MWE, ideally as a test or as an example for the added comment?

attrs on empty tuples is a tad cryptic, and I'm not sure how to trigger it---or check if the whole _is_zero_grad_array can be removed, as the comment above indicates will be possible "at some point".

@lucascolley

Copy link
Copy Markdown
Member Author

calling is_jax_array on a torch array while running under torch.compile(fullgraph=True) should reproduce.

@ev-br

ev-br commented Aug 16, 2026

Copy link
Copy Markdown
Member

Great. Add an otherwise failing code snippet to the comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants