Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are some common errors caused by shape polymorphism in JAX


What are some common errors caused by shape polymorphism in JAX


Shape polymorphism in JAX can lead to several common errors due to its handling of symbolic dimensions in array shapes. Here are some of these errors:

1. Incompatible Shapes for Broadcasting: When using shape polymorphism, operations like addition or matrix multiplication may fail if the symbolic dimensions do not match the expected shapes. For example, trying to add arrays with shapes `(v,)` and `(4,)` will result in an error because `v` is a symbolic dimension that may not always equal 4[1][2].

2. Shape Checking Errors: Operations like matrix multiplication require specific shape constraints, such as having square matrices. If the symbolic dimensions do not satisfy these constraints (e.g., using `(v, 4)` instead of `(v, v)`), JAX will raise errors[1][2].

3. Inconclusive Dimension Operations: Comparisons involving symbolic dimensions can be inconclusive if they cannot be resolved to a boolean value for all possible values of the symbolic dimensions. This leads to errors like `InconclusiveDimensionOperation` when trying to compare symbolic shapes[1].

4. Shape Assertion Errors: JAX assumes that dimension variables are strictly positive integers. If the actual input shapes do not satisfy these assumptions (e.g., a shape like `(b, b, 2*d)` when `d` is not an integer), JAX will raise errors during execution[1][2].

These errors highlight the need to carefully manage symbolic dimensions when using shape polymorphism in JAX.

Citations:
[1] https://docs.jax.dev/en/latest/export/shape_poly.html
[2] https://github.com/google/jax/blob/main/jax/experimental/jax2tf/README.md
[3] https://docs.jax.dev/en/latest/notebooks/thinking_in_jax.html
[4] https://stackoverflow.com/questions/65934509/errors-in-polymorphism
[5] https://github.com/google/jax/discussions/15995
[6] https://docs.jax.dev/en/latest/debugging/index.html
[7] https://jax.readthedocs.io/en/latest/errors.html
[8] https://laracasts.com/discuss/channels/eloquent/polymorphism-why-should-i-violate-database-design?reply=103880