Skip to content

quantize: fix F16/F32 downcast to q6_K #5980

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

Closed

Conversation

JohannesGaessler
Copy link
Collaborator

While converting the official Gemma FP32 GGUF to FP16 with quantize I noticed that token_embd.weight was being converted to q6_k. This seems to be a simple oversight in the code where the only data type checked against is q8_0 but not f16/f32. This PR adds the missing checks.

@ggerganov
Copy link
Member

Wouldn't it make more sense to not quantize at all if the requested type is F16 or F32:

diff --git a/llama.cpp b/llama.cpp
index 24944216..a08d3874 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -12106,8 +12106,10 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
                llama_format_tensor_shape(tensor).c_str(),
                ggml_type_name(tensor->type));
 
+        bool quantize = ggml_is_quantized(quantized_type);
+
         // This used to be a regex, but <regex> has an extreme cost to compile times.
-        bool quantize = name.rfind("weight") == name.size() - 6; // ends with 'weight'?
+        quantize &= name.rfind("weight") == name.size() - 6; // ends with 'weight'?
 
         // quantize only 2D tensors
         quantize &= (ggml_n_dims(tensor) == 2);

note: I haven't tested this

@JohannesGaessler
Copy link
Collaborator Author

With the proposed code change it would not be possible to do f16 <-> f32 conversions because the tensors would simply be copied.

@ggerganov
Copy link
Member

I pushed an alternative fix + some minor code cleanup

@ggerganov ggerganov closed this Mar 11, 2024
NeoZhangJianyu pushed a commit to NeoZhangJianyu/llama.cpp that referenced this pull request Mar 12, 2024
jordankanter pushed a commit to jordankanter/llama.cpp that referenced this pull request Mar 13, 2024
hodlen pushed a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants