Open
Conversation
Mostly adapted from the IQ2_TN kernels from ikawrakow/ik_llama.cpp#13 which were themselves adapted from the Q2_K kernels.
Member
|
Few updates by just pattern matching with the diff --git a/ggml/src/ggml-metal/ggml-metal.metal b/ggml/src/ggml-metal/ggml-metal.metal
index 8ac60744..a068e84c 100644
--- a/ggml/src/ggml-metal/ggml-metal.metal
+++ b/ggml/src/ggml-metal/ggml-metal.metal
@@ -5075,15 +5075,15 @@ void kernel_mul_mv_tq2_0_f32_impl(
const int im = tgpig.z;
const int first_row = (r0 * N_SIMDGROUP + sgitg) * N_DST;
- const int ib_row = first_row * nb;
const uint i12 = im%args.ne12;
const uint i13 = im/args.ne12;
- const uint offset0 = (i12/args.r2)*(nb*args.ne01) + (i13/args.r3)*(nb*args.ne01*args.ne02);
+ const uint64_t offset0 = first_row*args.nb01 + (i12/args.r2)*args.nb02 + (i13/args.r3)*args.nb03;
+ const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
- device const block_tq2_0 * x = (device const block_tq2_0 *) src0 + ib_row + offset0;
- device const float * y = (device const float *) src1 + r1*args.ne10 + im*args.ne00*args.ne1;
+ device const block_tq2_0 * x = (device const block_tq2_0 *) (src0 + offset0);
+ device const float * y = (device const float *) (src1 + offset1);
float yl[32];
float sumf[N_DST]={0.f}, all_sum;
@@ -5139,7 +5139,7 @@ void kernel_mul_mv_tq2_0_f32_impl(
device float * dst_f32 = (device float *) dst + (uint64_t)im*args.ne0*args.ne1 + (uint64_t)r1*args.ne0;
- for (int row = 0; row < N_DST; ++row) {
+ for (int row = 0; row < N_DST && first_row + row < args.ne0; ++row) {
all_sum = simd_sum(sumf[row]);
if (tiisg == 0) {
dst_f32[first_row + row] = all_sum;Haven't performed any tests so double-check if this makes sense. |
Contributor
The Metal implementation actually came from here. See this comment by @compilade. |
Contributor
Author
|
Hi @ggerganov I updated the branch with your changes. While I understand replacing ib_row with first_row * nb, and the the bounds check, |
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.
Support for TQ2_0 on Metal.
This a commit by @compilade from last year, re-applied to current.
Run with:
llama-cli -m "$(huggingface-cli download basavyr/TriLM_3.9B_Unpacked_quantized TriLM_3.9B_Unpacked_quant_TQ2_0.gguf)" -p The
llama-cli -m "$(huggingface-cli download brunopio/Llama3-8B-1.58-100B-tokens-GGUF Llama3-8B-1.58-100B-tokens-TQ2_0.gguf)"
The result runs and the result seems similar to that of the original commit by @compilade.
Though the result is not great compared to 4bit Llama 8B. Perhaps someone can compare with non-metal result.