Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BadisG opened this issue Mar 13, 2023 · 4 comments
Closed

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

BadisG opened this issue Mar 13, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@BadisG
Copy link

BadisG commented Mar 13, 2023

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!

@gjmulder
Copy link
Collaborator

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.

@ggerganov ggerganov added the enhancement New feature or request label Mar 13, 2023
@ggerganov
Copy link
Owner

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.

@ggerganov
Copy link
Owner

@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

@BadisG
Copy link
Author

BadisG commented Mar 23, 2023

@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 😄

@BadisG BadisG closed this as completed Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants