Type checking for pytrees
See original GitHub issueGlad to hear JAX will eventually have annotations! I was following this issue for updates. I actually started trying to add annotations myself before I realized how much work it was going to be.
One thing it would be nice to expose as soon as possible though are base types for tensors and pytrees:
Tensor = Union[np.ndarray, jnp.ndarray] # probably needs more things in the union like tracers and DeviceArray?
PyTree = Union[Tensor,
'PyTreeLike',
Tuple['PyTree', ...],
List['PyTree'],
Dict[Hashable, 'PyTree'],
None]
_Originally posted by @NeilGirdhar in https://github.com/google/jax/issues/1555#issuecomment-639554300_
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Pytrees - JAX documentation - Read the Docs
Classes are considered container-like if they are in the pytree registry, which by default includes lists, tuples, and dicts. That is: any object...
Read more >py_trees Documentation - Read the Docs
A parallel checking for a valid policy configuration after ... The py-trees-demo-action-behaviour program demonstrates a more complicated ...
Read more >Patrick Kidger (fosstodon.org/@PatrickKidger) on Twitter ...
Type annotations and runtime checking for shape and dtype of JAX arrays, and PyTrees. - GitHub - google/jaxtyping: Type annotations and ...
Read more >TF_JAX_tutorials - Part 10 (Pytrees in JAX) - Kaggle
JAX also lets you register custom types as pytrees (we will take a few ... Check if we can make a pytree from...
Read more >Python Type Checking (Guide) - Real Python
Type annotations and type hints; Adding static types to code, both your code and the code of others; Running a static type checker;...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
mypy
now supports recursive types since v0.981, and will be enabled by default since v0.990. E.g.:I can imagine two ways in which it might make sense to type check pytrees:
In theory, the first type could be checked with
Generic
and the second type could be checked (at least partially) withTypeVar
.