Errors#

ExactRef raises an error rather than return an answer it cannot guarantee, and when it is given arguments it cannot use. Its reference, rounded, is guaranteed to be the exact answer rounded once to the output format; when ExactRef cannot establish that, for example because it cannot settle which way an exact value rounds, it raises ReferenceUnavailableError instead.

exception ReferenceUnavailableError#

A result could not be established with the promised guarantee.

This is raised instead of returning an unverified answer: for example when an exact value may lie exactly where the rounding to the output format changes (halfway between two of its values, for rounding to nearest) and the refinement's precision cap is reached before that is decided.

exception UnsupportedFormatError#

Raised for an unknown format name or a format this library cannot hold.

ReferenceUnavailableError is a subclass of ArithmeticError. Guarantees and limits lists when it is raised.

UnsupportedFormatError is a subclass of ValueError. A test harness that runs PyTorch's dtypes through ExactRef meets it on a dtype ExactRef has no format for, such as float8_e8m0fnu, the scale format of MX quantization. The harness can catch it and skip that dtype:

Code
import torch
import exactref as er

for dtype in (torch.bfloat16, torch.float8_e4m3fn, torch.float8_e8m0fnu):
    try:
        # Importing a tensor reads its dtype, which must have an ExactRef format
        er.asarray(torch.zeros(128, 4096, dtype=dtype))
        print(f"{dtype}: supported")
    except er.UnsupportedFormatError:
        print(f"{dtype}: skipped")
Output
torch.bfloat16: supported
torch.float8_e4m3fn: supported
torch.float8_e8m0fnu: skipped

Errors of Python's own classes#

Other errors you may meet come from Python's own classes.

TypeError:

  • inputs of different dtypes to matmul

  • an output for covers() of another dtype

  • an output dtype of another kind (floating point, complex, integer, or bool) than the inputs

  • a named algorithm's format that is not a real floating-point format, such as int32

  • block_size, split_kv, or an MMAStep parameter that is not an int, or backward_blocks that is not a tuple or list of ints

  • one array for covers() on a result with named outputs: attention's output and logsumexp; var's or std's result and mean; batch_norm's output, running_mean, and running_var when it updates running statistics; or a backward's gradients, named grad_ plus the input's name

  • a result with named outputs passed in place of an array, or to any_of; pass one output as r[name]

  • a float8 input to a Fourier transform, or a complex one to rfft or ihfft

  • an output dtype that is not complex for fft, ifft, rfft, or ihfft, or not a real floating-point format for irfft or hfft

  • an integer or bool input to a Fourier transform's backward

  • a Fourier transform's axis that is not an int or a tuple of ints, or an n of the other form: an int n for an int axis, a tuple of the same length for a tuple

  • a pass in an FFT algorithm's plan that is neither an int nor a Bluestein pass

  • an integer or bool input to mean, var, std, softmax, log_softmax, a normalization, or convolution, or a complex one to softmax, log_softmax, a normalization, or convolution

  • convert_float_format between a real and a complex format, or from or to an integer or bool format

  • an output dtype that is not floating point (or complex, for a complex input) for an operation whose result is never an integer, such as divide, sqrt, exp, mean, softmax, or layer_norm

  • scatter_add's index that is not an integer array, or a base and src of different kinds

  • a correction for var or std that is not a real number

  • a normalization's weight or bias in another dtype than the input

  • convolution's stride, padding, dilation, or output_padding that is not an int or one int per spatial dimension

ValueError:

  • an output for covers() with the wrong shape

  • block_size, split_kv, either number of backward_blocks, or MMAStep's products or split below 1

  • backward_blocks of other than two numbers

  • dropout_p other than 0

  • an unknown overflow mode

  • a non-finite alpha or beta to gemm, or scale to attention

  • an accumulator_rounding that is not to nearest

  • error_model(k) where the formula has no finite bound

  • flush_to_zero=True for a tensor-core algorithm or for an attention algorithm with mma

  • an earlier float32 result, passed in place of an array, as a tensor-core algorithm's A or B

  • a Fourier transform's norm other than "backward", "ortho", "forward", or None, an n below 1, or axis=() for rfft, irfft, hfft, or ihfft

  • an FFT algorithm with an unknown path, a radix its path does not take, or a plan that does not fit the call: passes that do not multiply to the axis's length, plans for another number of axes, a real or packed path for a complex input, or the packed form at an odd length

  • an FFT algorithm's backward methods without backward_plan when fft, ifft, rfft, or ihfft takes a path other than "complex"

  • a Bluestein pass whose padded length is less than twice its length minus 1, or whose radices do not multiply to its padded length

  • an axis out of range for cumulative_sum or scatter_add, or a scatter_add whose index has another shape than src, or whose src has another number of dimensions than base

  • a convolution input without a batch dimension, a channel dimension, and the weight's spatial dimensions; a weight that does not fit the input's channels in groups; groups below 1; output_padding without transposed=True, or not smaller than the stride or the dilation; a bias of another shape than (out_channels,); or an output with no elements

  • a normalization's eps that is negative or not finite, a normalized_shape that is not the input's last dimensions, or a weight or bias of the wrong shape

  • batch_norm with an input of fewer than 2 dimensions, running_mean without running_var or the reverse, training=False without them, training=True with one value per channel, or a momentum that is not finite when it updates the running statistics

  • a correction for var or std that is not a fraction with a denominator of at most 2**20

  • logsumexp of a complex input with an infinite or NaN element, except a real part of -inf beside a finite imaginary part

IndexError:

  • an index in scatter_add's index that is out of range for base along axis

OverflowError:

  • a Python integer that does not fit the format it is converted to

  • with overflow="error", an integer that does not fit its format, in a conversion of array data or in an operation's result

NotImplementedError:

  • normal() where there is no normal answer (what an ordinary implementation that adds in index order computes, emulated exactly): matrix_exp, matrix_exp_frechet, and matrix_exp's backward, and the Fourier transforms and their backwards