tinygrad-notes

Dot products: values, reduction, and fusion

All tutorials · Updated September 21, 2026 · tinygrad 8ad8f73

For two vectors, a dot product multiplies corresponding elements and sums the products. tinygrad expresses this through its ordinary Tensor operations, making it a compact example of fusion and reduction.

from tinygrad import Tensor

a = Tensor([1.0, 2.0, 3.0]).realize()
b = Tensor([4.0, 5.0, 6.0]).realize()
assert a.dot(b).item() == 32.0
assert (a * b).sum().item() == 32.0
print("1*4 + 2*5 + 3*6 = 32")

OpMixin.dot handles more than vectors: higher ranks require shape normalization and a transpose of the appropriate right-hand axis. The matrix-multiplication chapter works through that case.

For the vector case, the product need not become a separately allocated array. Its values can flow directly into accumulation. Calling realize() on the product first requests an intermediate and changes the scheduling opportunities.

The old article described LazyBuffers and ScheduleItems. To trace today’s implementation, inspect out.uop before realization, follow rangeification, inspect the scheduled calls, then examine the generated program.

Floating-point summation order matters. A parallel reduction can group additions differently from a scalar Python loop. Use a justified numerical tolerance for non-exact examples, and state the input and accumulation dtypes. The small integer-valued float example above has an exactly representable result.

Original chapter by Di Zhu: historical version.