jax
aadcbd58 - Make HiPrim hash and eq include in_aval_flat, in_tree, out_avals_flat, out_tree.

Commit
2 days ago
Make HiPrim hash and eq include in_aval_flat, in_tree, out_avals_flat, out_tree. Unlike `core.Primitive`, every `HiPrim` call creates a new object that saves its input and output types on `self`. `HiPrim.__eq__` and `HiPrim.__hash__` previously checked only the class, `params`, and `effects`, ignoring those saved types. For example, suppose an eager `shard_map` calls `hijax.nonzero(x, size=5, axes=(1,))` on `int32[2, 8]` and then on `int32[2, 0]`: 1. Call 1 builds `prim_1` (expecting `int32[2, 8]`) and caches a `jit` wrapper keyed on `prim_1`. 2. Call 2 builds `prim_2` (expecting `int32[2, 0]`), but `prim_2 == prim_1` is `True` because both have `size=5` and `axes=(1,)`. 3. The cache returns Call 1's `jit` wrapper (still holding `prim_1`), which raises a type mismatch when given `int32[2, 0]`. Include the flattened input and output types and their PyTree structures in `HiPrim.__eq__` and `HiPrim.__hash__`. Use the flattened fields rather than raw `in_avals` and `out_aval` because those attributes can hold unhashable lists or dicts. PiperOrigin-RevId: 1023913167
Author
Parents
Loading