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.
GGML_OP_RESHAPE, GGML_OP_VIEW, GGML_OP_PERMUTE, GGML_OP_TRANSPOSE
, along withGGML_OP_NONE
, are all noops inggml
. I.e., nothing happens. Butggml
still has a thread barrier after them, which wastes time. The waste is not too bad for large models where computations are long compared to the time taken for thread synchronization. But for small models skipping those unnecessary waits makes a noticeable difference.Let's look at a really tiny model - the 99M parameter TriLM ternary model quantized with
IQ2_TN
. The following table compares performance for PP-512 and TG-128 with and without the change in this PRSo, basically, for such a small model
ggml
spends 10% of its time waiting for threads to pass through a barrier after a noop when generating tokens.There are other barriers that can be eliminated. E.g., the typical attention block involves matrix multiplications of the
Q, K
andV
tensors with the same activations, so there is no need to synchronize threads after each such matrix multiplications. In a similar way, in the feed-forward portion of the network theffn_up
andffn_gate
tensors multiply the same activations, so one can save another barrier there. This is left for a future PR.