New op: ggml_sum_rows_ext#2132
Merged
Merged
Conversation
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In the models that use HC and sparse attention there is often the need to sum over the rows of a tensor.
ggmldoes not provide this functionality, so on needs to permute the zeroth and 1st dimension, make the resulting tensor contiguous usingggml_cont(because theggml_sum_rowsimplementations do not support non-contiguous tensors), and only then useggml_sum_rowsto sum over the elements of the row. This is inefficient and may result in extra RAM/VRAM usage.This PR adds
ggml_sum_rows_ext, which takes as an additional argument the dimension over which the summation should be done. With that, the above simplifies toggml_sum_rows_ext(ctx, tensor, 1).As a test of the impact, in this PR I have used the new
ggml_sum_rows_extfunctionality in the openPangu model. The result is quite striking: ~60% better PP and ~15% better TG for short context. For long context the inference time is dominated by the indexer/attention computations, so the impact there is lower. Nevertheless, the average performance improvement for contexts between 0 and 64k tokens is 32% (PP) and 6.5% (TG). This is on a 2x3090+Ryzen-3995WX system with 20 out of 48 MoE layers left in RAM.Running CPU-only the performance gain is less striking, but I still see ~10% better PP and ~6% better TG.
I guess, the main reason the effect is so large on CUDA is that the rows of the permuted tensor only have 4 elements, so in the CUDA implementation only 4 out of 32 threads in a WARP do actual work.