An LLM is deterministic; given the same inputs you’ll get the extract same outputs. The post-processing of the LLM randomly selects a token from the weighted distribution. This is what makes an LLM-based chat AI non-deterministic.
At any given point, the sampler could select the completely wrong token independent of whether the LLM knew the right answer. The reverse is true, of course, and much more likely.
For a more complex AI solution, there can be a later step that double-checks the response, but subtle errors will still sneak through.
Um, everything I’ve read on them in practice and all of my personal experience with them points to them being non-deterministic, but its deterministic effects can be controlled. Even under temperature settings of 0, they can produce different output (though maybe still equivalent) from the same input.
The LLM transformer is completely deterministic. The math operations are all pretty basic: matrix multiply, addition, and some non-linear activations. The application built around the LLM will introduce non-determinism.
There are a few places that can add non-determinism in decreasing impact:
Random sampling of the outputs is the biggest one since it is an intentional decision.
Ensuring you have identical inputs for each run may not be possible with a web AI like Claude or GPT. Even if you clear the context each time, they could be tweaking the context with memories from your account or adding the current time to the system prompt.
Web AIs have load-balancing and you’re not guaranteed to get an identical HW and SW stack each time. You may not get the extract same model either. I’ve observed this we Gemini when running my automated test suite. Most of the time I’d get identical output, but occasional I’d get a version with a couple of words changed (and always changed the same way).
The SW stack (e.g. CUDA) isn’t necessarily deterministic although there’s been a lot of effort to make it more so.
Well, if you’re saying the operation is deterministic in theory, I’d agree. But it seems where the rubber meets the road, it isn’t really. If I open a ollama prompt and set the temperature to 0.0, and ask it a specific question, I get the same answer back in a new session after stopping the model. Even if both answers are complete bullshit, the answer is identical.
Hey, it’s gemma2:2b. It might sprout bullshit, but it will run on my pathetic desktop, and the questions I asked were basically asking it to hallucinate. Give it a break. It’s at least deterministic on the first question.
But repeated prompts are a different story. If I provide a really open-ended prompt, such as “sally”. The first response is identical in each run, sometimes the response to the second “sally” is the same, but eventually repeated prompts (usually the third) give answers that diverge (meaninglessly diverge, but they aren’t the same). Yes, I feel for my poor GPU and CPU having to run that inane “sally” query repeatedly. I won’t do it again.
In this case, I’m using ROCm instead of CUDA, but I can’t imagine anyone using these systems without one of them being used to facilitate GPU hardware, but this is pretty close to the metal for an LLM. So I’d say it’s theoretically possible for it to be deterministic, but I doubt anyone is doing that in practice.
I wanted to highlight that the LLM is deterministic in practice (not just in theory) as you’ve seen by running your own ollama instance, but then we intentionally make it indeterministic by randomly choosing each output token.
Actually I think it might be worse for the more intellectual folks. I suck at chess, so being beaten by a chess program was no problem for me. If I had considered myself great at it might be worse. Someone who knows deep inside that they are not as smart as most might have an easier time getting outsmarted by AI than someone who considers themselves as elite.