Skip to content

Different outputs for differents numbers of threads (same seed) #95

Closed

Description

@BadisG

Hello,

I simply wanted to bring up the point that the output can vary based on the number of threads selected, even if the seed stays constant.

I have an intel core i7 10700K that has 16 threads.

For this example I'm using the 13B model (./models/13B/ggml-model-q4_0.bin)

When I put -t 14 (make -j && ./main -m ./models/13B/ggml-model-q4_0.bin -p "Building a website can be done in 10 simple steps:" -t 14 -n 50 --seed 1678486056), I got this result:
duU196l

When I put -t 15 (make -j && ./main -m ./models/13B/ggml-model-q4_0.bin -p "Building a website can be done in 10 simple steps:" -t 15 -n 50 --seed 1678486056), I got this result:
5WIrvd1

I have zero knowledge in machine learning, perhaps this is a normal behavior.

Looking forward for your reactions!

Activity

  1. gjmulder commented on Mar 13, 2023

    @gjmulder
    Contributor

    That isn't surprising, as each thread may be getting its own random seed. Changing the number of threads would then change the random seed initialisation, thus generating different output.

  2. ggerganov commented on Mar 13, 2023

    @ggerganov
    Member

    It's not the random seed. The random seed is only one in the main thread.

    The problem is more complex - the tensor operations are multi-threaded and based on the number of threads, they process different sizes of the input data. Since these are floating point numbers and they are often accumulated, the finite precision of floating-point operations causes the final results to be slightly different for different number of threads. This effect is amplified by the auto-regressive nature of the transformer.

    There are ways to fix this, but a major refactor in ggml is required.

  3. ggerganov commented on Mar 23, 2023

    @ggerganov
    Member

    @BadisG
    I think I have fixed this behaviour on latest master. If you can give it a try and let me know if the results for different number of threads is now the same

  4. BadisG commented on Mar 23, 2023

    @BadisG
    Author

    @ggerganov I just tried with t = 14, 12 and 5 and I have the same result each time.
    Looks like it's fixed! Great work I appreciate 😄

  5. added a commit that references this issue on Feb 20, 2026
  6. added a commit that references this issue on Apr 8, 2026
  7. added a commit that references this issue on Sep 19, 2026
  8. 26 remaining items

  9. added a commit that references this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions