Transforms¶
vmap = svmap
module-attribute
¶
dvmap(fn, in_axes=0, out_axis=0)
¶
Dynamically vectorize a function by lazily determining the batch size from inputs.
Unlike svmap/vmap, the UOp graph is rebuilt on each call, which allows the batch
size to vary. Useful inside traced contexts (e.g. AD operators) where the batch size
is not known at graph-construction time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[P, Tensor]
|
Callable accepting Tensors and returning a single Tensor. |
required |
in_axes
|
int | tuple[int | None, ...]
|
Which axis is the batch dimension for each input. An int applies to all
inputs; |
0
|
out_axis
|
int
|
Where to place the batch dimension in the output. |
0
|
Source code in src/anvil/transform/_vmap.py
svmap(fn, batch_size, in_axes=0, out_axis=0)
¶
Statically vectorize a NumericalFunction with a fixed batch size.
The UOp graph is rewritten once at construction time and reused on each call
via UOp.substitute(), making it more efficient than dvmap for repeated
evaluation with the same batch size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
NumericalFunction
|
The NumericalFunction to vectorize (must have a single output). |
required |
batch_size
|
int
|
Fixed batch dimension size. |
required |
in_axes
|
int | tuple[int | None, ...]
|
Which axis is the batch dimension for each input. An int applies to all
inputs; |
0
|
out_axis
|
int
|
Where to place the batch dimension in the output. |
0
|