-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Investigate gemma 2 generation quality #8240
Comments
Just to confirm, gemma2 's window size is hard coded right? |
Ref comment: #8227 (comment) Issue with math questions may indicate problem with tokenizer, we should firstly try if llama.cpp tokenizer matches gemma2's tokenizer result or not. |
The default value if hard-coded (in order not to break existing gguf), but the value will be override with the one in gguf (in case you re-convert to get new gguf) Metadata key is |
For what it's worth, I have found that Gemma-2-27B quantized to Q6_K often makes mistakes/typos with proper names compared to Gemma-2-8B in Q8_0. I don't think the difference in quantization quality would be so large, but this could be something to watch for. |
I tested all working implementations of the gemma-2-27b inference code. Reference models:Compared implementations:
Not tested: hf transformers launch commandsgemma.cpp:
chatllm:
llama.cpp:
Outputs:gemma.cpp:`tanto va la gatta al lardo che ci lascia lo zampino. chatllm.cpp at Q8_0:`tanto va la gatta al lardo che ci lascia lo zampino. ai studio with temperature 1.0:`tanto va la gatta al lardo che ci lascia lo zampino. llama.cpp at temperature 0.01:
Analysis of resultsThe model in llama.cpp spits out random italian words and then starts speaking spanish. I tried many other questions from my benchmarks. The other three models all agree to the same correct response. llama.cpp gives a different and incorrect response. EDIT: |
9B-IT is working great and now I can increase the ctx size. :) |
Don't know if I'm heading the right direction or not: from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b")
chktxt = 'Repeat the question and then answer it: Matteo has 20 apples, he buys 20 oranges. Then he discards half of his fruits equally. Then he discards a quarter of his fruits equally between apples and oranges. How many apples remain?'
tokenizer(chktxt)['input_ids'][1:]
# [41422, 573, 2872, 578, 1492, 3448, 665, 235292, 100006, 919, 235248, 235284, 235276, 34188, 235269, 693, 58015, 235248, 235284, 235276, 72638, 235265, 5040, 693, 9027, 2050, 3933, 576, 926, 16803, 16404, 235265, 5040, 693, 9027, 2050, 476, 9453, 576, 926, 16803, 16404, 1865, 34188, 578, 72638, 235265, 2250, 1767, 34188, 5822, 235336] Compared to the llama.cpp output (using
The word
|
I noticed something possibly interesting:
The old but closer to correct GGUF [Q6_K_L] is from this commit (I matched the sha256 hashes to make sure) AFAIK these initial versions, were not created from scratch by llama.cpp, but based on the f32 GGUF provided directly by google on kaggle, although AFAIK these initial GGUFs had various other issues... I see 2 possible causes:
Logs:
launch command (latest llama.cpp 49122a8):
|
@tristandruyen I think the result you provided is still wrong even for the outdated gguf. The response from outdated gguf is "ci si lascia lo zampino". |
My bad, as I do not speak italian my brain parsed it as correct... It's still kinda interesting that it's much closer to the correct response though.... |
We still don't know what the conversion code Google used was, so it's possible that yes there's still something missing... But the Google one definitely has a bad tokenizer, so if that was somehow fixed we may be able to see the proper performance, if only someone was able to contact them 🥲 |
@ngxson This indicates a problem with the tokenizer conversion. I don't fully understand the details to fix it, but a simple observation that I found is using: diff --git a/convert-hf-to-gguf.py b/convert-hf-to-gguf.py
index 4a7f500f..d7eaf9cd 100755
--- a/convert-hf-to-gguf.py
+++ b/convert-hf-to-gguf.py
@@ -2345,7 +2345,7 @@ class Gemma2Model(Model):
model_arch = gguf.MODEL_ARCH.GEMMA2
def set_vocab(self):
- self._set_vocab_llama_hf()
+ self._set_vocab_sentencepiece()
self.gguf_writer.add_add_space_prefix(False)
def set_gguf_parameters(self): This would tokenize correctly the word "discards", but there are other problems with added/special tokens not being added at all. So some fix for the vocabulary conversion is necessary |
For me, Gemma2 27b is going off the rails as soon as 'slot context shift' occurs. I get high quality output until that point. **3. Security config java
**Exploring the Nature of Light Introduction: Light is an essential aspect of our universe, influencing everything from the smallest atom to the largest galaxy. Understanding the nature of light, how it interacts, and its properties are fundamental to many scientific fields, including physics, astronomy, and biology. **Wave-Particle Duality: The Double Nature of Light The nature of light has been a subject of much debate and experimentation. |
That's because, as I am trying to explain since 2 weeks, the quantizing is "wrong". |
Bartowski and others already provide GGUF's with output and embed tensors quantized as f16 as _L variants... Also I wouldn't call people wrong for providing standard GGUF variants with standard settings. |
From the hf blog. "Running in float16 may be faster on your hardware, and results should be similar on the 9B model. Do note, however, that the 27B instruction-tuned model produces erratic outputs when using float16: you must use bfloat16 for that model weight." Could this be relevant? I'm not familiar enough with the llama.cpp codebase to check this myself. The guuf by google is in float32 while the hf model is in bf16. |
Honestly @matteoserva you may have a point, but I would hope that it's not relevant if we go bf16 to FP32 to fp16.. could try _XL versions where I leave embed and output at f32 LOL but that better not make any difference, would be pretty weird.. But yeah if even converting to f32 doesn't work properly, it's a deeper issue. My guess is Google was referring to take the bf16 and on-the-fly running it as fp16 which could definitely degrade performance at edge cases (I think we saw this in Qwen2?) |
"[!WARNING] https://huggingface.co/google/gemma-2-27b-it/discussions/17/files |
Bfloat16->float32->float16 is generally an invalid conversion since float16 doesn't have the same range as the other two. Is there a reason to think that the model weights are in the float16 range even if they are in the bfloat16 format? |
Just to mention here, when I was converting the HF gemma2 to bft16 gguf, I noticed that the norm tensors were converted to fp16 instead of directly copying them from HF safetensors which were in bf16. I found that behaviour quite odd. I even supplied |
@ggerganov Simply apply this change, I get perplexity from My laptop is potato, I only tested with just 3 chunks of With
With
|
@matteoserva it's been shown that upcasting to FP32 before going to fp16 maintains a bit more accuracy than doing the conversion directly, but yes you lose out on some of the range and if Gemma 2 has a ton of values that fall outside the fp16 range that are extremely important they're different then I guess that could do it. Does that really seem likely to be the issue? Especially when quantizing, almost zero and really almost zero are always going to basically be zero.. I'd think it more important to maintain the relationships in the middle of the range rather than the whole range (which probably matters more in training) I suppose in an ideal world we could keep the embeddings and outputs at bf16, but then we lose GPU support (I think?) Embeddings at f32 seems like it should be overly excessive for a quantized model, and I'd hope we never need to do that since that would be a huge increase in final size... Maybe we need to prioritize GPU support of bf16 more, but I'm so far from the expertise required that I'm in no position to push for it lol Take what I say with a grain of salt please 😅 |
@ngxson the problem with sentencepiece is it's not tokenizing the start and end tokens correctly, so it may have better PPL but it produces worse results There's clearly some middle ground we're missing |
Sorry for asking so many questions but I'm really missing the reason why you assume that converting to float16 is possible at all. The maximum value for a float16 is 65535. I also expect most of the original weights to be greater than 65k since putting a constraint on their value would waste 20% of the bits of a bfloat16 value. Is there some sort of quantization applied when converting gemma from bfloat to float32 to float16? In other words, how are you compressing a number from the range ±10^38 to another format whose range is ±65535? A naive division is not possible. I suppose that models released directly in float32 format have the additional constraint that their weights are in a small range around 0, that's why the conversion to float16 is possible. |
I ran some bench suites on my own Q6_K non-imatrix quant and the 9b model is doing well on benchmarks. It This quant was generated prior to the sliding attention patch but that shouldnt make difference since I limit CoT to 2500 tokens. |
Temp 1.0 seems to be a bit too high for Gemma 2 27b. What is the 'natural' temp for this model, does anyone know? |
1.0 is the default temperature set in aistudio. Did you notice any detrimental effect regarding a temp of 1.0? |
I've noticed both temperature 0 and 1.0 used in Google code (in gemma.cpp repo): |
It seemed to have some trouble with numbers/math at temp 1.0. gemma-2-27b-it-Q8_0.gguf --top-k 0 --min-p 0.0 --top-p 1.0 --color -t 5 --temp 1 --repeat_penalty 1 -c 4096 -n -1 -ngl 14 --conversation -i at temp 1.0 I get this:
Aliens (the sequel to Alien) came out 7 years before Alien 3. Here's the breakdown:
at temp 0 I get:
"Aliens" was released in 1986. "Alien 3" was released in 1992. Therefore, "Aliens" came out 6 years before "Alien 3". Let me know if you have any other movie trivia questions! |
Btw, for this kind of queries that require known facts you should always use |
huggingface/transformers#31775 is this relevant to llama.cpp implementation? |
I think it's already correct in llama.cpp (feel free to correct me if I'm wrong): Line 11572 in be20e7f
|
Use proper nouns, it helps the model know what you are talking about.
Or just multiturn, should work fine, model will create proper nouns in context.
|
Hah! I first got the problem in the context of it writing an essay about Alien 3, but I couldn't reproduce it. I think another part of it might be that Alien was released 7 years before Aliens, so maybe that's where the network is getting that urge from? |
Here are two prompts that were run at 0 temp with Gemma 27B Q8_0 a difference is the second prompt has one more paragraph of lorem ipsum, but in fact, just adding a linebreak to the last paragraph causes a degradation of formatting and coherence identically ("Bard" instead of "Gemma", double space instead of single space in two places) |
There have been reports that using a higher |
@BugReporterZ i set final_logit_softcapping to 50 in config.json, and just in case replaced default 30.0f with 50.0f in llama.cpp file, requantized the model - the output for above prompts was unaffected |
For anyone running tests relying on context shift, make sure to try #8348 since there was a bug that affected the quality of context shifts for Gemma2 models |
@cuelebra The mentioned token probably isn't used by gemma (maybe google reuse the same tokenizer for other models). HF transformers outputs the same thing: from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b")
tokenizer("[toxicity=0]")
# [2, 235309, 1373, 235293, 235276, 235307] This token need to be marked as special token to make it work, but that's not the case, see: https://huggingface.co/google/gemma-2-9b/blob/main/tokenizer_config.json |
Important A note for everyone: if you think there's a bug in llama.cpp tokenizer, please make sure to test with HF |
This is a difference between how the corporate hosted implementation and llamacpp work. If it's different for this particular token, maybe there are other cases for which tokenization is different from how google trained the model. It's entirely possible that the transformers implementation of the tokenizer for gemma is not correct, especially considering they had other bugs with implementation already. |
What is the 'f' for? |
for letting everyone know that it's a single precision floating point number |
HTML tags are not yet tokenized correctly by Gemma-2's tokenizer in |
Are you guys planning to merge that branch or am I waiting around like an idiot for nothing? I see related changes happening elsewhere. Just wondering when I can re-convert. Again, let me know if there's anything I can do to help speed it up |
That's my experience, too. My instructions had clear directions to use * (asterisks) for actions and I had dialog examples. Gemma stubbornly kept using quotes around speech and did not use asterisks around actions, and kept using double newlines between paragraphs. After a dozen of messages (which I corrected manually), Gemma finally stopped using quotes and started using asterisks correctly. However, nothing helped against double newlines. I haven't yet seen such a stubborn LLM, when it comes to formatting. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
Initial reports can be seen from #8227
Important
A note for everyone: if you think there's a bug in llama.cpp tokenizer, please make sure to test with HF
transformers
library first (see this comment for example)The text was updated successfully, but these errors were encountered: