Merged
Conversation
mavenlin
commented
Aug 22, 2025
| @implements(torch.tensor) | ||
| def tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False): | ||
| assert not requires_grad | ||
| return jnp.array( |
Contributor
Author
There was a problem hiding this comment.
We should preserve None as it is so that jax will infer the type from the data itself instead of torch.get_default_dtype(). The latter will make torch.tensor(1) a float tensor instead of integer.
Owner
There was a problem hiding this comment.
ah good catch! do we have a test for this?
mavenlin
commented
Aug 22, 2025
samuela
reviewed
Aug 22, 2025
| @implements(torch.tensor) | ||
| def tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False): | ||
| assert not requires_grad | ||
| return jnp.array( |
Owner
There was a problem hiding this comment.
ah good catch! do we have a test for this?
torch2jax/__init__.py
Outdated
| return jnp.array( | ||
| data.value if isinstance(data, Torchish) else data, dtype=t2j_dtype(dtype or torch.get_default_dtype()) | ||
| ) | ||
| return jnp.array(data.value if isinstance(data, Torchish) else data, dtype=t2j_dtype(dtype)) |
Owner
There was a problem hiding this comment.
data.value if isinstance(data, Torchish) else data
hmm should we use _coerce here? pro: it lines up with the spirit of what's happening here. con: it doesn't currently support lists
Contributor
Author
There was a problem hiding this comment.
I'll keep as it is for now, for coerce, maybe we can consider passing everything that we don't recognize as it is?
be1ca2d to
55f0931
Compare
Owner
|
Thanks @mavenlin ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
key.__getitem__can be inferred.Meaning that
keyhas to beintorindiceto be jittable.slicewithstart&endbeing a traced array would work only when it is not jitted.This behavior is consistent with jax, so we just turn off the jit test for dynamic slice object.