Shape #
Additional analytic (HasFDerivAt) tape nodes for shape permutations.
These nodes are linear/isometric and are useful for models that do explicit reshaping and dimension permutations (e.g. Multi-Head Attention head splitting/combining).
reshape is linear: on vectors it is just a type cast along Spec.Shape.size equality.
We implement it as a Node to keep the DAG theorem applicable.
reshape node: reinterpret the same underlying coordinates as a different shape.
This is only definable when Spec.Shape.size s₁ = Spec.Shape.size s₂; at the vector level it is
a cast.
PyTorch analogue: view/reshape operations that do not change the total number of elements.
https://pytorch.org/docs/stable/tensor_view.html
Instances For
NodeFDerivCorrect for reshape (it is linear/isometric).
Instances For
flatten is a specialization of reshape to the canonical vector shape
(.dim (Spec.Shape.size s) .scalar).
flatten node: specialization of reshape to the canonical vector shape (.dim (Spec.Shape.size s) .scalar).
PyTorch analogue: flatten when applied to a contiguous tensor.
https://pytorch.org/docs/stable/generated/torch.flatten.html
Instances For
NodeFDerivCorrect for flatten.
Instances For
Move reindexVec across the left argument of an inner product.
Reindex a tensor node by any coordinate equivalence. This is the proof-level primitive behind arbitrary axis permutations; its JVP uses the same permutation and its VJP uses the inverse.
Instances For
NodeFDerivCorrect for an arbitrary coordinate reindexing.