Overview of torch.func (formerly functorch)
torch.func (previously known as functorch) provides JAX-like composable function transforms for PyTorch. It allows users to apply higher-order functions to numerical functions to compute different quantities.
Key capabilities include:
- Auto-differentiation transforms: e.g.,
grad(f)returns a function that computes the gradient off. - Vectorization/Batching transforms: e.g.,
vmap(f)returns a function that computesfover batches of inputs. - Composition: Transforms can be composed arbitrarily, such as
vmap(grad(f))to compute per-sample gradients, which is otherwise inefficient in standard PyTorch.
Note: This library is currently in beta. APIs may change, and there may not be full coverage over all PyTorch operations.