Live data from Hacker News

How to wrangle non-deterministic AI outputs into conventional software? (2025)

domainlanguage.com

31–35 of 35 posts

Re: How to wrangle non-deterministic AI outputs into conventional software? (2025)

#31
post #11

Aren’t transformers intrinsically deterministic? I thought the randomness was intentional to make chatbots seem more natural, and OpenAI used to have a seed parameter you could set for deterministic output. I don’t know why that feature isn’t more popular, for the reasons this article outlines

(I'm not an expert. I'd love to be corrected by someone who actually knows.) Floating-point arithmetic is not associative. (A+B)+C does not necessarily equal A+(B+C), but you can get a performance improvement by calculating A, B, and C in parallel, then adding together whichever two finish first. So, in theory, transformers can be deterministic, but in a real system they almost always aren't.

> you can get a performance improvement by calculating A, B, and C in parallel, then adding together whichever two finish first

Technically possible, but I think unlikely to happen in practice.

On the higher level, these large models are sequential and there’s nothing to parallelize. The inference is a continuous chain of data dependencies between temporary tensors which makes it impossible to compute different steps in parallel.

On the lower level, each step is a computationally expensive operation on a large tensor/matrix. These tensors are often millions of numbers, the problem is very parallelizable, and the tactics to do that efficiently are well researched because matrix linear algebra is in wide use for decades. However, it’s both complicated and slow to implement fine grained parallelism like “adding together whichever two finish first” on modern GPUs. Just too much synchronization, when total count of active threads is many thousands, too expensive. Instead, operations like matrix multiplications are often assigning 1 thread per output element or fixed count of output elements, and reduction like softmax or vector dot product are using a series of exponentially decreasing reduction steps, i.e. order is deterministic.

However, that order may change with even minor update of any parts of the software, including opaque pieces at the low level like GPU drivers and firmware. Library developers are updating GPU kernels, drivers, firmware and OS kernels collectively implementing scheduler which assigns work to cores, both may affect order of these arithmetic operations.

Re: How to wrangle non-deterministic AI outputs into conventional software? (2025)

#32

Aren’t transformers intrinsically deterministic? I thought the randomness was intentional to make chatbots seem more natural, and OpenAI used to have a seed parameter you could set for deterministic output. I don’t know why that feature isn’t more popular, for the reasons this article outlines

No, not unless you have a very specific notion of determinism. Some basic operations use arithmetic with finite precision in a way that isn't associative and therefore isn't reproducible. And CUDA introduces its own set of problems[1].

[1] https://docs.nvidia.com/cuda/cublas/index.html#results-repro...

Re: How to wrangle non-deterministic AI outputs into conventional software? (2025)

#33

Aren’t transformers intrinsically deterministic? I thought the randomness was intentional to make chatbots seem more natural, and OpenAI used to have a seed parameter you could set for deterministic output. I don’t know why that feature isn’t more popular, for the reasons this article outlines

Determinism of LLMs has often been discussed on HN, for example here:

https://news.ycombinator.com/item?id=37006224

https://news.ycombinator.com/item?id=45200925

The TL;DR is that LLMs are often not deterministic because GPUs compute submatrices in parallel and sum them up in different orders, depending on which finish first. This is maybe a few percent faster than always using the same order, but it absolutely could be made deterministic if people cared enough. CUDA even provides deterministic primitives if desired. Of course also use the same random seed for samplers, but that is trivial.

Re: How to wrangle non-deterministic AI outputs into conventional software? (2025)

#34

Use one of these structured output libraries: https://github.com/outlines-dev/outlines https://github.com/jxnl/instructor https://github.com/guardrails-ai/guardrails https://www.askmarvin.ai/docs/text/transformation/ Some of them allow a JSON schema, others a Pydantic model (which you can transform to/from JSON).

To add to that, llama.cpp supports GBNF grammars, which allows generation of JSON, or even programming languages:

https://github.com/ggml-org/llama.cpp/blob/master/grammars/R...

Re: How to wrangle non-deterministic AI outputs into conventional software? (2025)

#35
post #28

Earlier quoted context omitted.

I don't think the order of operations is non-deterministic between different runs. That would make programming and researching these systems more difficult than necessary.

It would be if you used atomics.

I said: don't think it's non-deterministic, two negations -> deterministic.
Post reply on HN