Implement scalar sum over all rows in ggml_compute_forward_sum_f32 #1162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was trying the test-grad0 test from ggml and this way I found a bug in ggml_compute_forward_sum_f32.
Only the sum of the last processed row was written to dst:
https://github.com/ggerganov/llama.cpp/blob/8a0f8673ba1cdc6aa6df27a9fbc698431ca70e8d/ggml.c#L3201-L3210
https://github.com/ggerganov/llama.cpp/blob/8a0f8673ba1cdc6aa6df27a9fbc698431ca70e8d/ggml.c#L6782-L6790
With this PR the sum over all rows is accumulated and then written to dst.
What is not so nice about it, is that the row sum is converted from ggml_float to float, losing precision during accumulation.
Was computing single sum over all rows like I did meant by this TODO?
https://github.com/ggerganov/llama.cpp/blob/8a0f8673ba1cdc6aa6df27a9fbc698431ca70e8d/ggml.h#L486-L489