Skip to content
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

Steps forward - Tokenizer #37

Open
cmp-nct opened this issue Jun 30, 2023 · 14 comments
Open

Steps forward - Tokenizer #37

cmp-nct opened this issue Jun 30, 2023 · 14 comments

Comments

@cmp-nct
Copy link
Owner

cmp-nct commented Jun 30, 2023

I'm currently working on the tokenizer, we need a new one.

The llama tokenizer is not suitable, it has problems forming larger tokens and favors smaller ones and it does not adhere to the merge priority of bpe, instead uses sentencepiece scores.

That's why the progress on the roadmap has stopped a bit, without good tokenization Falcon can not provide good quality results.

Couple problems to be solved:

  1. BPE merge logic instead of scores
  2. current tokenization of whitespaces conflicts with BPE whitespace token merging (whitespace and multi-whitespace binding to each other)
    2.1) Same problem with newlines, these are actual tokens and can be combined and interleaved with spaces forming pure whitespace tokens (most likely a lot for code)
  3. vocabulary in ggml V3 is not fit for the purpose

For good quality Falcon flapping we need the tokenizer to be identical or almost identical to the training tokenization

@abc-nix
Copy link

abc-nix commented Jul 1, 2023

Thank you very much for all the work and time you are giving to bring a very good functioning Falcon to the masses.

Thank you.

@cmp-nct
Copy link
Owner Author

cmp-nct commented Jul 3, 2023

Thank you
New tokenizer PR was just merged, also new file version GGCC is now standard.
It provides a significant quality change, the tokenization plays a major role in how the model follows the prompt or fine tune.
Now it follows it precisely as in the transformers repo.

I hope no big bugs, tested it a lot, need some sleep
more release notes here: #38

@maddes8cht
Copy link

Also thanks again for your amazing work !

In fact i have been disappointed by falcons abilities in german. I'm eager to see the improvements later on my pc.

With the new changes, @TheBloke s current falcon models willnot work anymore until he builds new ones?

@cmp-nct
Copy link
Owner Author

cmp-nct commented Jul 3, 2023

Also thanks again for your amazing work !

In fact i have been disappointed by falcons abilities in german. I'm eager to see the improvements later on my pc.

With the new changes, @TheBloke s current falcon models willnot work anymore until he builds new ones?

Yes I'll ask Bloke to make new ones, it was just 8:00 in the morning "yesteday" so I could not fully test everything.
I corrected 10 bugs in the last minute, more might be lingering.
You can use the existing ones, just make sure you add the correct tokenizer.json into the model directory.
Only OpenAssistant requires a custom tokenizer.json to function correct, Wizard and all foundation models use the same.
This will reduce loading times a bit over native ggcc version.
You can also requantize models, if you use the 16+ bit version of them just run them through falcon_quantize with tokenizer.json in the directory. You'll get GGCC files as result.

I ran german tests on Openassistant 7B and 40B in medium quality quantization and I believe it is a lot better than before.
OpenAssistant is not tuned for german though.
I got high quality german from 7B (which I did not expect) and flawless from 40B.

40B dialect:

<|prompter|>Erzähl ma an bayrischen Witz.<|endoftext|><|assistant|>Ein Mann geht zum Bäcker und bestellt ein Semmel. Der Bäcker fragt: "Mit oder ohne Kruste?" Darauf der Kunde: "Ohne, bitte." Daraufhin meint der Bäcker: "Dann nimm halt a Brezn!"<|endoftext|>

<|prompter|>Erzähl mir einen bayrischen Witz im starken Dialekt den du dir selbst ausgedacht hast!<|endoftext|><|assistant|>A Schotten-Hendl is in da Stadt,
des schaut do schee.
I hob mi gschtrahlt und gsagt:
"Hey, i bin a Bayernkind!"
Aber des Hendl hobs gwusst,
und wiasst wieso?
Deswegen hobs glei gmacht,
dass i a Bayernkind soi!<|endoftext|>

40B:

<|prompter|>Erzähle mir eine typisch Bayrische Kurzgeschichte die Gruselig ist.<|endoftext|><|assistant|>Es war ein kalter, regnerischer Abend im Oktober, als meine Freunde und ich uns entschieden, einen Ausflug in den bayerischen Wald zu machen. Wir hatten gehört, dass es dort einige gruselige Legenden und Spukgeschichten gibt, und wir wollten uns die Gelegenheit nicht entgehen lassen, sie selbst zu erleben.

Wir fuhren mit dem Auto durch die Dunkelheit und kamen schließlich an einer verlassenen Kapelle an. Der Regen prasselte auf das Dach des Autos, während wir uns ausstreckten und versuchten, ein wenig Schlaf zu bekommen. Plötzlich hörten wir ein leises Klopfen an der Seitentür des Autos. Wir schauten alle erschrocken auf, aber niemand rührte sich. Das Klopfen wurde lauter und eindringlicher, bis ich endlich den Mut aufbrachte, die Tür zu öffnen.

Vor uns stand eine kleine Gestalt in einem weißen Nachthemd. Sie trug einen Hut mit breiter Krempe und hielt ein Licht in der Hand. "Kommt mit mir", flüsterte sie leise. "Ich zeige euch etwas."

Wir zögerten, aber schließlich ließen wir uns von ihr durch den Wald führen. Wir folgten ihr über Stock und Stein, bis wir zu einer Lichtung kamen. Dort stand eine Gruppe Kinder in weißen Nachthemden und hielten Kerzen in der Hand. Sie sangen ein trauriges Lied und tanzten im Kreis um einen großen Baum.

Plötzlich hörten wir ein Rauschen hinter uns, als ob jemand durch das Unterholz lief. Wir drehten uns um und sahen eine zweite Gruppe Kinder in roten Nachthemden, die sich schnell näherte. Die weiß gekleideten Kinder schrien vor Angst auf und rannten davon.

Wir wollten ihnen folgen, aber plötzlich standen wir mitten im Wald und hatten keine Ahnung, wo wir waren. Wir versuchten uns zu orientieren, aber es war dunkel und nebelig, und wir konnten nichts erkennen. Plötzlich hörten wir ein leises Flüstern in unserem Ohr: "Geht zurück zum

7B test:

<|prompter|>Erzähle mir eine typisch Bayrische Kurzgeschichte die Gruselig ist.<|endoftext|><|assistant|>Hier eine Bayrische Kurzgeschichte, die Gruselig ist:

Es war eine heiße Sommernacht in Bayern und der junge Mann stand auf dem Dach seiner Mühle. Er hatte dort oben gewohnt, seit er klein war und wusste, dass dies seine Heimat war. Das Dach war weich unter seinen Füßen und der Wind wehte durch seine Haare. Es war ein seltsames Gefühl, die Stille zu genießen und sich zu freuen, dass er hier oben war und nicht im schwüligen Inneren seiner Mühle saß.

Jetzt hörte er etwas Schreckliches. Ein Geräusch, das wie das Knirschen von Rippen klang. Er drehte sich um und sah sie da: Eine Gestalt, die aus dem Dunkel der Nacht hervorbrach und ihn anstarrte. Es war eine alte Frau mit weißen Haaren und glänzenden Augen, die so klar waren wie das Wasser eines Seebecktes. Sie hatte ein langes rotes Kleid, das sich im Wind bewegte, und ihre Hände waren krumm und zitterten.

Der junge Mann sprang von dem Dach und lief davon, aber er konnte nicht schnell genug sein. Die Frau kam ihm nach und ihr Körper glitt über den Dachboden wie eine Schlange. Sie schnappte nach seiner Hand und zerrte an ihr, aber es war so fest verankert wie das Dach selbst.

Der junge Mann wehrte sich mit aller Kraft und schrie auf, aber seine Stimme wurde nur von der Windgewinnung verschluckt. Die Frau lachte herzhaft und drückte noch fester zu. Dann begann sie, langsam zu drehen, sodass die Sonne ihren Rücken erreichte und ihre Haut zum Glanz erhob.

Der junge Mann konnte den Blick nicht von ihr abwenden. Sie war wunderschön und doch etwas Furchtbares in ihren Augen lag. Dann drehte sie sich um und verschwand im Dunkeln der Nacht. Der junge Mann rannte zu seiner Mühle zurück, aber er wusste, dass er nie wieder in Frieden dort oben schlafen konnte.

@maddes8cht
Copy link

Wow
I ran german tests on Openassistant 7B and 40B in medium quality quantization and I believe it is a lot better than before.
Yes it is !
I think it may be even better than it's english results so far has been.

That's a real big leap.

@TheBloke
Copy link

TheBloke commented Jul 3, 2023

Awesome! I am standing by to hit my big red quantisation button, just say the word

@cmp-nct
Copy link
Owner Author

cmp-nct commented Jul 3, 2023

Yes, it's a good time to requantize.

The tokenizer still has minor flaws, I ran it on a 200kb file and there were 30 tokens mismatching. But in all "normal" tests I ran it was identical to the transformers implementation. The difference might also come from some invalid UTF quirk that is being encoded on python and raw on cpp side

@maddes8cht
Copy link

maddes8cht commented Jul 4, 2023

Awesome! I am standing by to hit my big red quantisation button, just say the word
@TheBloke
the word
scnr ;)

@linuxmagic-mp
Copy link

Interrupting this thread to point out latest warnings from that pull..

Operating System: Ubuntu 20.04.6 LTS
Kernel: Linux 5.4.0-147-generic
Architecture: x86-64
lscpu -> 'Model name: Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz'
-> 'CPU(s):

(for testing using this smaller machine)

Feel free to drop this from the thread, if it gets in the way. Might need a 'special' discussion, just for warnings reports.

    inlined from ‘ggml_graph_print_impl’ at ggml.c:18287:13:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: warning: ‘__builtin___snprintf_chk’ specified bound 512 exceeds destination size 128 [-Wstringop-overflow=]
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   68 |        __bos (__s), __fmt, __va_arg_pack ());
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Other unused variables.. (less noise)

int vram_reserved=128MB;
size_t vram_overhead = 32
MB;
const int i_gpu_last =
offload_func_t offload_func_nr =
offload_func_t offload_func_kqv =
offload_func_t offload_func =

In file included from libfalcon.cpp:14:
libfalcon.h: At global scope:
libfalcon.h:252:24: warning: ‘FINETUNE_NAME’ defined but not used [-Wunused-variable]
  252 |     static const char *FINETUNE_NAME[6] = { "UNSPECIFIED", "NONE", "ALPACA", "OPENASSISTANT", "WIZARD", "FALCONINSTRUCT" };
      |                        ^~~~~~~~~~~~~
./libfalcon.h:252:24: warning: ‘FINETUNE_NAME’ defined but not used [-Wunused-variable]
  252 |     static const char *FINETUNE_NAME[6] = { "UNSPECIFIED", "NONE", "ALPACA", "OPENASSISTANT", "WIZARD", "FALCONINSTRUCT" };
examples/falcon/falcon_main.cpp:462:77: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 9 has type ‘std::vector<std::vector<int> >::size_type’ {aka ‘long unsigned int’} [-Wformat=]
  462 | fprintf(stderr, "|            | %5d | %5d | %5d | %5zu | %13d | %20s | #%3lld |\n",
      |                                                                         ~~~~^
      |                                                                             |
      |                                                                             long long int

Same issue in a couple of other examples..

@linuxmagic-mp
Copy link

Might also want to update the README, mention that you have to move (or symbolic link) the original tokenizer.json to the new location of the ggml formats, before quantizing.. (or get the convert script to copy it to the destination)

We still doing q4_0 instead of q4_k, or are they both good now?

falcon_model_quantize_internal: model size = 27531.39 MB
falcon_model_quantize_internal: quant size = 3872.59 MB
falcon_model_quantize_internal: hist: 0.036 0.015 0.024 0.038 0.055 0.076 0.097 0.114 0.121 0.114 0.097 0.076 0.055 0.038 0.024 0.020

main: quantize time = 299602.55 ms
main: total time = 299602.55 ms

@cmp-nct
Copy link
Owner Author

cmp-nct commented Jul 7, 2023

Might also want to update the README, mention that you have to move (or symbolic link) the original tokenizer.json to the new location of the ggml formats, before quantizing.. (or get the convert script to copy it to the destination)

We still doing q4_0 instead of q4_k, or are they both good now?

falcon_model_quantize_internal: model size = 27531.39 MB falcon_model_quantize_internal: quant size = 3872.59 MB falcon_model_quantize_internal: hist: 0.036 0.015 0.024 0.038 0.055 0.076 0.097 0.114 0.121 0.114 0.097 0.076 0.055 0.038 0.024 0.020

main: quantize time = 299602.55 ms main: total time = 299602.55 ms

We currently do not have K quantizers that can handle 7B (superblock of 64), we'd need k quantizers that can do both 256 and 64 based on the quantization.
There are 64 variants available (ggerganov#2001) but adding those would require a lot of work on falcon side (updating all 16 bit kernels as well) while not really delivering the flexibility we require.
I don't think that a compilation flag splitting 7B off from 40B is the correct way forward.
Though if someone invests the work to fully integrate the 64 patch including the 16 bit dequantizer cuda kernels (or a unified dequantizer) I'll be glad to test and merge it.

For now I prefer to keep 7B with traditional quantization now and 40B with K quants.
7B is conveniently small, you can use 5_1 or 8_0 for high quality and 4_0 for highest speed.

@linuxmagic-mp
Copy link

Fine by me, just want to make sure I am keeping up ;) @cmp-nct did we break something in the latest batch of commits? make clean && make failed to make the falconize binaries this time..

make: *** No rule to make target 'falcon.cpp', needed by 'falcon.o'.  Stop.

@cmp-nct
Copy link
Owner Author

cmp-nct commented Jul 7, 2023

Fine by me, just want to make sure I am keeping up ;) @cmp-nct did we break something in the latest batch of commits? make clean && make failed to make the falconize binaries this time..

make: *** No rule to make target 'falcon.cpp', needed by 'falcon.o'.  Stop.

Please git pull again.
the normal Makefile was bugged from a PR that changed the names of .so and .a files.
Should be good again

@linuxmagic-mp
Copy link

All good..

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

No branches or pull requests

5 participants