Numerical accuracy
In modern computers, floating point numbers are represented using IEEE 754 standard. For more details on floating point arithmetic and IEEE 754 standard, please see Floating point arithmetic. In particular, note that floating point provides limited accuracy (about 7 decimal digits for single precision floating point numbers, about 16 decimal digits for double precision floating point numbers) and that floating point addition and multiplication are not associative, so the order of the operations affects the results. Because of this, PyTorch is not guaranteed to produce bitwise identical results for floating point computations that are mathematically identical. Similarly, bitwise identical results are not guaranteed across PyTorch releases, individual commits, or different platforms. In particular, CPU and GPU results can be different even for bitwise-identical inputs and even after controlling for the sources of randomness.
Batched computations or slice computations
Many operations in PyTorch support batched computation, where the same operation is performed
for the elements of the batches of inputs. An example of this is torch.mm() and
. It is possible to implement batched computation as a loop over batch
elements, and apply the necessary math operations to the individual batch elements, for
efficiency reasons we are not doing that, and typically perform computation for the whole
batch. The mathematical libraries that we are calling, and PyTorch internal implementations
of operations can produce slightly different results in this case, compared to non-batched
computations. In particular, let and be 3D tensors with the dimensions suitable for
batched matrix multiplication. Then (the first element of the batched result) is
not guaranteed to be bitwise identical to (the matrix product of the first
elements of the input batches) even though mathematically it’s an identical computation.