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.
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:
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")
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
matmulan output for
covers()of another dtypean output
dtypeof another kind (floating point, complex, integer, or bool) than the inputsa named algorithm's format that is not a real floating-point format, such as
int32block_size,split_kv, or anMMAStepparameter that is not an int, orbackward_blocksthat is not a tuple or list of intsone array for
covers()on a result with named outputs: attention'soutputandlogsumexp;var's orstd's result andmean;batch_norm'soutput,running_mean, andrunning_varwhen it updates running statistics; or a backward's gradients, namedgrad_plus the input's namea result with named outputs passed in place of an array, or to
any_of; pass one output asr[name]a float8 input to a Fourier transform, or a complex one to
rfftorihfftan output
dtypethat is not complex forfft,ifft,rfft, orihfft, or not a real floating-point format forirfftorhfftan integer or bool input to a Fourier transform's backward
a Fourier transform's
axisthat is not an int or a tuple of ints, or annof the other form: an intnfor an intaxis, a tuple of the same length for a tuplea pass in an FFT algorithm's plan that is neither an int nor a
Bluesteinpassan integer or bool input to
mean,var,std,softmax,log_softmax, a normalization, orconvolution, or a complex one tosoftmax,log_softmax, a normalization, orconvolutionconvert_float_formatbetween a real and a complex format, or from or to an integer or bool formatan output
dtypethat is not floating point (or complex, for a complex input) for an operation whose result is never an integer, such asdivide,sqrt,exp,mean,softmax, orlayer_normscatter_add'sindexthat is not an integer array, or abaseandsrcof different kindsa
correctionforvarorstdthat is not a real numbera normalization's
weightorbiasin another dtype than the inputconvolution'sstride,padding,dilation, oroutput_paddingthat is not an int or one int per spatial dimension
ValueError:
an output for
covers()with the wrong shapeblock_size,split_kv, either number ofbackward_blocks, orMMAStep'sproductsorsplitbelow 1backward_blocksof other than two numbersdropout_pother than 0an unknown
overflowmodea non-finite
alphaorbetatogemm, orscaleto attentionan
accumulator_roundingthat is not to nearesterror_model(k)where the formula has no finite boundflush_to_zero=Truefor a tensor-core algorithm or for an attention algorithm withmmaan earlier float32 result, passed in place of an array, as a tensor-core algorithm's
AorBa Fourier transform's
normother than"backward","ortho","forward", or None, annbelow 1, oraxis=()forrfft,irfft,hfft, orihfftan 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 lengthan FFT algorithm's backward methods without
backward_planwhenfft,ifft,rfft, orihffttakes a path other than"complex"a
Bluesteinpass whose padded length is less than twice its length minus 1, or whose radices do not multiply to its padded lengthan
axisout of range forcumulative_sumorscatter_add, or ascatter_addwhoseindexhas another shape thansrc, or whosesrchas another number of dimensions thanbasea
convolutioninput without a batch dimension, a channel dimension, and the weight's spatial dimensions; a weight that does not fit the input's channels ingroups;groupsbelow 1;output_paddingwithouttransposed=True, or not smaller than the stride or the dilation; a bias of another shape than(out_channels,); or an output with no elementsa normalization's
epsthat is negative or not finite, anormalized_shapethat is not the input's last dimensions, or aweightorbiasof the wrong shapebatch_normwith an input of fewer than 2 dimensions,running_meanwithoutrunning_varor the reverse,training=Falsewithout them,training=Truewith one value per channel, or amomentumthat is not finite when it updates the running statisticsa
correctionforvarorstdthat is not a fraction with a denominator of at most2**20logsumexpof 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'sindexthat is out of range forbasealongaxis
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, andmatrix_exp's backward, and the Fourier transforms and their backwards