autoray.experimental.complexity_tracing¶
Functionality for tracing through an autoray.lazy computation and estimating the cost and scaling.
In the following there are cost_* functions that estimate the total cost
of a given operation, including sub-leading factors. There are also
cost_scaling_* functions that only consider the leading factor of the cost,
so that we can prime number decompose it and extract the scaling.
Attributes¶
Functions¶
Get the batch size and ordered matrix dimensions of |
|
|
|
|
|
|
|
Here we only care about the leading factor of the cost, which we need to |
|
|
|
|
|
|
|
|
|
|
|
|
Estimate the total cost of one or more lazy output nodes. |
|
|
|
|
|
|
|
|
|
|
|
Estimate cost scalings for one or more lazy output nodes. |
|
Plot the cost scaling of every operation in one or more lazy output |
Module Contents¶
- autoray.experimental.complexity_tracing._get_batch_matrix_sizes(x)¶
Get the batch size and ordered matrix dimensions of
x.
- autoray.experimental.complexity_tracing.cost_tensordot(x)¶
- autoray.experimental.complexity_tracing.cost_scaling_tensordot¶
- autoray.experimental.complexity_tracing.cost_qr(x)¶
- autoray.experimental.complexity_tracing.cost_svd(x)¶
- autoray.experimental.complexity_tracing.cost_eigh(x)¶
- autoray.experimental.complexity_tracing.cost_scaling_linalg(x)¶
Here we only care about the leading factor of the cost, which we need to preserve so that we can prime number decompose it.
- autoray.experimental.complexity_tracing.cost_matmul(x)¶
- autoray.experimental.complexity_tracing.cost_scaling_matmul¶
- autoray.experimental.complexity_tracing.cost_einsum(x)¶
- autoray.experimental.complexity_tracing.cost_scaling_einsum¶
- autoray.experimental.complexity_tracing.cost_linear(x)¶
- autoray.experimental.complexity_tracing.cost_nothing(x)¶
- autoray.experimental.complexity_tracing._LINEAR_COSTS¶
- autoray.experimental.complexity_tracing._NOTHING_COSTS¶
- autoray.experimental.complexity_tracing.COSTS¶
- autoray.experimental.complexity_tracing.cost_node(x, allow_missed=True)¶
- autoray.experimental.complexity_tracing.compute_cost(z, print_missed=True, allow_missed=True)¶
Estimate the total cost of one or more lazy output nodes.
Shared dependencies of multiple output nodes are counted once.
- Parameters:
- autoray.experimental.complexity_tracing.COST_SCALINGS¶
- autoray.experimental.complexity_tracing.frequencies(it)¶
- autoray.experimental.complexity_tracing._check_factor_map(factor_map)¶
- autoray.experimental.complexity_tracing.compute_cost_scalings(z, factor_map, print_missed=True, allow_missed=True)¶
Estimate cost scalings for one or more lazy output nodes.
- Parameters:
z (pytree of LazyArray) – The output node or nodes to trace. Shared dependencies are counted once.
factor_map (dict[str, int]) – Mapping from dimension labels to distinct prime numbers. Every dimension in the traced computation should be a product of these.
print_missed (bool, optional) – Whether to warn about unregistered operations, dimensions that are not products of the
factor_mapprimes, and other prime factors.allow_missed (bool, optional) – Whether to omit operations without a registered scaling and allow dimensions that are not products of the
factor_mapprimes. IfFalse, raise aValueErrorlisting them instead.
- autoray.experimental.complexity_tracing.plot_scalings(z, factor_map, x=None, y=None, marker='s', size=400, cmap=None, norm='log', colorbar=True, print_missed=True, allow_missed=True, ax=None, figsize=None, show_and_close=True)¶
Plot the cost scaling of every operation in one or more lazy output nodes, as the exponents of two dimension labels, colored by how often each occurs.
Operations with zero cost are left out. Operations with the same
xandyexponents are merged into one point, whose count is their total number of repeats.- Parameters:
z (pytree of LazyArray) – The output node or nodes to trace.
factor_map (dict[str, int]) – Mapping from dimension labels to distinct prime numbers, see
compute_cost_scalings.x (str, optional) – The label whose exponent is plotted on the x-axis. By default the label with the second largest dimension in
factor_map.y (str, optional) – The label whose exponent is plotted on the y-axis. By default the label with the largest dimension in
factor_map.marker (str, optional) – Marker for each point.
size (float, optional) – Size of each marker.
cmap (str or Colormap, optional) – Colormap for the number of repeats.
norm (str or Normalize, optional) – Color normalization for the number of repeats, by default
"log".colorbar (bool, optional) – Whether to add a colorbar showing the number of repeats.
print_missed (bool, optional) – Whether to warn about unregistered operations and prime factors.
allow_missed (bool, optional) – Whether to omit operations without a registered scaling.
ax (matplotlib.axes.Axes, optional) – Axes to plot on, will be created if not provided.
figsize (tuple, optional) – Size of the figure, if one is created.
show_and_close (bool, optional) – Whether to show and close a created figure.
style (str or dict, optional) – Matplotlib style to use, by default a neutral style that works on light and dark backgrounds.
- Returns:
fig (matplotlib.figure.Figure or None) – The created figure, or
Noneifaxwas given.ax (matplotlib.axes.Axes) – The axes plotted on.