Same model, same prompt, different answer: where LLM nondeterminism really comes from
Every number below comes from a script I ran on my laptop (PyTorch 2.10, CPU, 8 threads). The script is at the end, so you can run it on yours. Set temperature to 0. Send the same prompt to the same model twice. You'd expect the same answer twice. Often you don't get it, and not because of sampling. Greedy decoding is deterministic by definition: take the highest-scoring token, every time. So…
Floating-point arithmetic doesn't adhere to the associative property, meaning (a + b) + c may not equal a + (b + c). In floating-point numbers, rounding occurs at each step, and the order of addition affects where that rounding takes place. For example, with three numbers, adding them in different orders yields slightly different results due to rounding. A transformer layer performs thousands of such additions per output value, resulting in varying final answers even when using the same model and prompt.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to