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

gguf-py: Add support for loading merges.txt #3743

Closed
wants to merge 1 commit into from

Conversation

KerfuffleV2
Copy link
Collaborator

@KerfuffleV2 KerfuffleV2 commented Oct 23, 2023

I added support in gguf.py for loading merges.txt when loading merges is enabled and merges aren't found in tokenizer.json. It will also print out a warning when loading merges is turned on but there no merges are found (to hopefully avoid accidentally creating a model that can't be loaded).

I also added a --padvocab option to convert.py which will just create <dummy00001> etc tokens when the model expects more vocab entries than exist in the vocab metadata.

Some other minor cleanups. (I don't know about the line splitting format but some of the lines were getting absurdly long.) Also fixed a small bug where the endianness option wasn't honored when creating vocab only GGUF files.

edit: Confirmed to fix CausalLM models. Tested on https://huggingface.co/CausalLM/EarlyFailures14B/tree/main creating a vocab-only model, which presumably should be the same as the real CausalLM models.

gguf: WARNING: merges.txt: Line 109171: Entry malformed, ignoring
Padding vocab with 213 token(s) - <dummy00001> through <dummy00213>
This gguf file is for Little Endian only
gguf: Adding 109170 merge(s).
gguf: Setting special token type bos to 151643
gguf: Setting special token type eos to 151643
gguf: Setting special token type pad to 151643

Tried loading:

llm_load_vocab: mismatch in special tokens definition ( 421/152064 vs 213/152064 ).
llm_load_print_meta: format           = unknown
llm_load_print_meta: arch             = llama
llm_load_print_meta: vocab type       = BPE
llm_load_print_meta: n_vocab          = 152064
llm_load_print_meta: n_merges         = 109170

I don't know how much of an issue the special tokens mismatch is. I can't see if it's the same in the master version or not since the model can't be loaded.

Closes #3732.

@KerfuffleV2 KerfuffleV2 added the script Script related label Oct 23, 2023
@KerfuffleV2 KerfuffleV2 changed the title Add support for loading merges.txt gguf-py: Add support for loading merges.txt Oct 23, 2023
@CausalLM
Copy link
Contributor

Yes, it works well. Thank you for your work!

@KerfuffleV2
Copy link
Collaborator Author

Yes, it works well.

Thanks for testing! Do you mean you were able to convert the model and get good results actually running it as well?

@CausalLM
Copy link
Contributor

CausalLM commented Oct 23, 2023

Yes,it works well on chatml format, with Q4_0 model of CausalLM/14B.

== Running in interactive mode. ==
 - Press Ctrl+C to interject at any time.
 - Press Return to return control to LLaMa.
 - To return control without starting a new line, end your input with '/'.
 - If you want to submit another line, end your input with '\'.

<|endoftext|>

<|im_start|>system 
You are a helpful assistant. 
<|im_end|> 
<|im_start|>user 
Who are you? 
<|im_end|> 
<|im_start|>assistant
Hello, I am an artificial intelligence and a large language model, also known as a conversatioto provide helpful information and answer questions to the best of my ability.

I can answer a variety of questions on various topics, including but not limited to:

- General knowledge
- Science and technology
- History and culture
- Entertainment and arts
- Health and lifestyle
- Business and finance
- Education and career
- Travel and leisure

I can also generate creative content such as poems, stories, scripts, code, music, and more.

Please feel free to ask me any questions or request my assistance. I will do my best to provide you with accurate and comprehensive information.<|endoftext|>


llama_print_timings:        load time =    1728.12 ms
llama_print_timings:      sample time =     147.91 ms /   152 runs   (    0.97 ms per token,  1027.65 tokens per second)
llama_print_timings: prompt eval time =    1263.65 ms /    50 tokens (   25.27 ms per token,    39.57 tokens per second)
llama_print_timings:        eval time =   38164.05 ms /   152 runs   (  251.08 ms per token,     3.98 tokens per second)
llama_print_timings:       total time =  132450.43 ms

The special tokens <|endoftext|> <|im_start|> and so on, all work as expected, also CJK (Chinese) characters.

@KerfuffleV2
Copy link
Collaborator Author

Thanks! One thing looks a bit weird though:

"also known as a conversatioto provide helpful information" - Did the model actually generate that, or it just not pasted correctly?

@CausalLM
Copy link
Contributor

system_info: n_threads = 6 / 12 | AVX = 1 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | 
main: interactive mode on.
sampling: 
        repeat_last_n = 64, repeat_penalty = 1.100, frequency_penalty = 0.000, presence_penalty = 0.000
        top_k = 40, tfs_z = 1.000, top_p = 0.950, typical_p = 1.000, temp = 0.800
        mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000
generate: n_ctx = 512, n_batch = 512, n_predict = 2560, n_keep = 0


== Running in interactive mode. ==
 - Press Ctrl+C to interject at any time.
 - Press Return to return control to LLaMa.
 - To return control without starting a new line, end your input with '/'.
 - If you want to submit another line, end your input with '\'.

<|endoftext|>

<|im_start|>system 
You are a helpful assistant. 
<|im_end|> 
<|im_start|>user 
Who are you? 
<|im_end|> 
<|im_start|>assistant
Hello, I am an AI language model created to assist users like you with various tasks and provide information. I can help answer questions, offer suggestions, or engage in conversations on a wide range of topics. If you have any specific needs or desires for discussion, please feel free to let me know, and I'll do my best to accommodate you.<|endoftext|>

Cannot reproduce that, maybe it is just an accident. But it is quite a large ver Q4_0, the typo error should not happen.

@TheBloke
Copy link
Contributor

TheBloke commented Oct 23, 2023

Quick question: will I be able to pass --padvocab unconditionally, and rely on it to pad vocab if necessary? Or do I need to check if it's required first?

(I'd love it if I can just set it always, that'd be really helpful and allow me to remove a bunch of complicated code that checks if the vocab size is correct and has been really unreliable for me as models keep coming out with custom vocab sizes)

@KerfuffleV2
Copy link
Collaborator Author

@TheBloke

will I be able to pass --padvocab unconditionally, and rely on it to pad vocab if necessary?

Yes, it'll only activate in the case the "vocab size mismatch" error would have triggered previously. So as long as padding is always what you want to do, you can just unconditionally specify it.

However, there aren't really any checks. Just for example, suppose no vocab could be loaded from the metadata (but it didn't cause an actual error, maybe the JSON keys were just empty or whatever) and the model expects 32,000 vocab entries, well... You'll successfully generate a model with a vocab of <dummy00001> through <dummy32000> which probably won't work so great. :)

@KerfuffleV2
Copy link
Collaborator Author

Cannot reproduce that, maybe it is just an accident.

If you still have the output of the first run in your console, you can scroll back near the top and find the seed that was used to generate it. It will look like:

Log start
main: build = 1420 (13e08d0)
main: built with cc (GCC) 13.2.1 20230801 for x86_64-pc-linux-gnu
main: seed  = 1698064864

So if you want to try to reproduce it, you can try using --seed 1698064864 or whatever.

@cebtenzzre
Copy link
Collaborator

If you still have the output of the first run in your console,

This information is also logged to a file that looks like main.139870073946112.log.

@JeremyBickel

This comment was marked as outdated.

@KerfuffleV2
Copy link
Collaborator Author

KerfuffleV2 commented Oct 23, 2023

Is this relevant for this discussion?

Hmm, hard to say. You didn't provide information about the prompt, generation seed, sampling settings, etc so there isn't really a way to reproduce what you did. Also it seems like you're using llama.cpp through a Python wrapper. It might be built with an older version. I know there were a number of BPE vocab/tokenizer fixes fairly recently.

Please try to reproduce your issue using llama.cpp directly (like the main example) and the latest release.

@goerch
Copy link
Collaborator

goerch commented Oct 23, 2023

I know there were a number of BPE vocab/tokenizer fixes fairly recently.

We are still working actively on it.

@TheBloke
Copy link
Contributor

TheBloke commented Oct 23, 2023

@JeremyBickel

I've not seen that in my testing of the new GGUFs. But it could depend what kind of characters are output I guess. And yes, please show the exact prompt and parameters used.

Here's an example of a command I know works at my end:

./main -m /workspace/process/causallm_14b/gguf/causallm_14b.Q5_1.gguf -p "<|im_start|>system\nA conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.<|im_end|>\n<|im_start|>user\nWhat is The HitchHikers Guide To The Galaxy?<|im_end|>\n<|im_start|>assistant"

Output:

<|im_start|>system\nA conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.<|im_end|>\n<|im_start|>user\nWhat is The HitchHikers Guide To The Galaxy?<|im_end|>\n<|im_start|>assistant:The Hitchhiker's Guide to the Galaxy is a science fiction comedy series written by Douglas Adams, consisting of five novels published between 1978 and 1982. The story follows the adventures of Arthur Dent, a man who has lost most of his life after the Earth was destroyed to make way for a hyperspace bypass. He is saved by Ford Prefect, an alien researcher from the fictional publishing house known as "The Hitchhiker's Guide to the Galaxy," and they embark on a journey through space with other characters such as Zaphod Beeblebrox, the President of the Galaxy, Trillian, a human woman with connections to various alien races, and Marvin the Paranoid Android. Along the way, they encounter various planets, aliens, and challenges, all while providing humorous commentary on humanity, life, and the universe. The books are also accompanied by a radio drama, a television series, and a movie adaptation.<|endoftext|> [end of text]

(There's a few hallucinations in that output. We're noticing quite a lot of hallucination with CausalLM 7B and 14B, unfortunately)

@JeremyBickel

This comment was marked as outdated.

@JeremyBickel

This comment was marked as outdated.

@JeremyBickel

This comment was marked as outdated.

@JeremyBickel

This comment was marked as outdated.

@goerch
Copy link
Collaborator

goerch commented Oct 23, 2023

ERROR: byte not found in vocab:

Time for a tokenizer test?

@TheBloke
Copy link
Contributor

@JeremyBickel is that ctransformers? It's not been updated since September 10th so I wouldn't be sure it's still guaranteed to work with latest GGUFs. I'd say you should try llama-cpp-python, but I've seen someone reporting that same bug with that as well.

Maybe only llama.cpp supports this properly right now.

Running your prompt on the latest llama.cpp gave:

<|im_start|>system
You are a helpful assistant.
<|im_end|>
<|im_start|>user
Tag each word of the following SENTENCE using these semantic tags: agent, main-action, purpose, direct-object, theme, relative pronon, status-action, location, recipient, comparison marker, referential-agent, transitive-action, means marker, time-indicator, description, status, conjunction, theme. SENTENCE: And after these things I saw four angels standing on the four corners of the earth, holding the four winds of the earth, that the wind should not blow on the earth, nor on the sea, nor on any tree.
<|im_end|>
<|im_start|>assistant:And (conj) after (time-indicator) these (theme) things (theme) I (referential-agent) saw (status-action) four (numeral) angels (theme) standing (status-action) on (location) the (theme) four (numeral) corners (theme) of (preposition) the (theme) earth (theme), holding (transitive-action) the (theme) four (numeral) winds (theme) of (preposition) the (theme) earth (theme), that (relative pronon) the (theme) wind (theme) should (status-action) not (modal) blow (direct-object) on (preposition) the (theme) earth (theme), nor (conjunction) on (preposition) the (theme) sea (theme), nor (conjunction) on (preposition) any (numeral) tree (theme).<|endoftext|> [end of text]

@JeremyBickel
Copy link

JeremyBickel commented Oct 23, 2023

@TheBloke
I confirm that. I got the binary llama.cpp and ran main. It worked. So, maybe it it ctransformers. Sorry for the gigantic time sink. ..and thanks.

@goerch
Copy link
Collaborator

goerch commented Oct 24, 2023

From CausalML 's special_tokens_map :

  "additional_special_tokens": [
    "<|im_start|>",
    "<|im_end|>"
  ],

But I see them in output of main : is this expected behavior?

@KerfuffleV2
Copy link
Collaborator Author

But I see them in output of main : is this expected behavior?

Unfortunately, I can't really answer questions like that since all I did was add support for loading merges from a different source.

I guess the thing to do would be to run it with the official Python stuff and compare how tokenizing occurs with what llama.cpp does.

@goerch
Copy link
Collaborator

goerch commented Oct 24, 2023

I guess the thing to do would be to run it with the official Python stuff and compare how tokenizing occurs with what llama.cpp does.

I'm on it :)

@KerfuffleV2
Copy link
Collaborator Author

Although adding stuff like tests for specific models is good and certainly important, any further changes needed with this pull specifically that just adds support for loading merges from merges.txt?

@TheBloke
Copy link
Contributor

TheBloke commented Nov 2, 2023

Although adding stuff like tests for specific models is good and certainly important, any further changes needed with this pull specifically that just adds support for loading merges from merges.txt?

I for one would love to see this merged, for --padvocab and any future merges.txt based models.

@KerfuffleV2
Copy link
Collaborator Author

@TheBloke

I for one would love to see this merged,

I too yearn for closure! Have you been using this? In other words, can I assume that everything still works fine with other changes that have occurred during this time. I know it merges cleanly but that's not always a guarantee.

@sorgfresser
Copy link

I can verify this fixes #3935 for me and while using @KerfuffleV2 's fork is an option for now, I would really like to see this merged as I am certainly not the only one trying to convert models with a non-matching vocab size and converting, then switching back to the original repo is no real solution.

@TheBloke
Copy link
Contributor

TheBloke commented Nov 5, 2023

Sorry @KerfuffleV2 I haven't actually tried it yet :) I was kind of waiting for it to be merged, as I still have my own workaround code in place

I have however used the implementation of --padvocab that strutive07 provided as part of their HF Vocab module, and can confirm that that worked great. I know it's not the same code of course..

I will do a manual test of this PR shortly and let you know.

@KerfuffleV2
Copy link
Collaborator Author

KerfuffleV2 commented Nov 5, 2023

No problem. I don't really know which pull request is going to actually get merged (first) or whatever. We won't want two implementations of the vocab padding stuff, so if the other one gets merged first then I'll want to remove it from this pull and likely the same for the other one as well.


edit:

I know it's not the same code of course..

The padding stuff is same code, so we can say that part was tested sufficiently.

The merges.txt part is just a fallback and only applies if the other source of merges doesn't provide any. So there's not too much chance of that causing issues.

More testing is, of course, always welcome!

@TheBloke
Copy link
Contributor

TheBloke commented Nov 6, 2023

OK I've done some testing and --padvocab is working well on all the models I've thrown at it. And the BPE merges seems fine as well. Great!

Only issue I noticed is a tangential one - the problem of added_tokens with an ID that's less than vocab_size. This was meant to be resolved by another PR, but I don't know what happened to that; I've lost track of which PR it was in, and I don't think it's been merged

So currently models like Open-Orca/Mistral-7B-OpenOrca will fail with:

 [pytorch2] tomj@MC:/workspace/git/kerfuffle-llamacpp (feat-use-mergestxt ✔) ᐅ ./convert.py /workspace/models/Open-Orca_Mistral-7B-OpenOrca --outtype f16 --outfile /workspace/models/oo-mistral.fp16.gguf --padvocab
Loading model file /workspace/models/Open-Orca_Mistral-7B-OpenOrca/pytorch_model-00001-of-00002.bin
Loading model file /workspace/models/Open-Orca_Mistral-7B-OpenOrca/pytorch_model-00001-of-00002.bin
Loading model file /workspace/models/Open-Orca_Mistral-7B-OpenOrca/pytorch_model-00002-of-00002.bin
params = Params(n_vocab=32002, n_embd=4096, n_layer=32, n_ctx=32768, n_ff=14336, n_head=32, n_head_kv=8, f_norm_eps=1e-05, f_rope_freq_base=10000.0, f_rope_scale=None, ftype=<GGMLFileType.MostlyF16: 1>, path_model=PosixPath('/workspace/models/Open-Orca_Mistral-7B-OpenOrca'))
Loading vocab file '/workspace/models/Open-Orca_Mistral-7B-OpenOrca/tokenizer.model', type 'spm'
Traceback (most recent call last):
  File "/workspace/git/kerfuffle-llamacpp/./convert.py", line 1224, in <module>
    main()
  File "/workspace/git/kerfuffle-llamacpp/./convert.py", line 1203, in main
    vocab = load_vocab(vocab_dir, args.vocabtype)
  File "/workspace/git/kerfuffle-llamacpp/./convert.py", line 1105, in load_vocab
    return SentencePieceVocab(path, added_tokens_path if added_tokens_path.exists() else None)
  File "/workspace/git/kerfuffle-llamacpp/./convert.py", line 372, in __init__
    raise Exception(f"Expected added token IDs to be sequential and start at {vocab_size}; got {actual_ids}")
Exception: Expected added token IDs to be sequential and start at 32000; got [0, 1, 2, 32000, 32001]

I do have code to handle that but it would be great to have that sorted at the same time as all the other convert.py changes.

Although I'm a little confused about what the longer term plan is for convert.py and vocab. Is it expected that all three of SPM, BPE and HF will be supported separately? Or that HF AutoTokenizer will supersede the other two? Because strutive's PR seems to always use AutoTokenizer, and SentencePiece isn't used at all any more (if I'm understanding correctly). And it therefore doesn't have this issue.

So if the plan is to use HF then issues like the SPM loader not handling tokens < vocab_size won't be an issue. But if it's planned to support all three as separate options, it is.

I guess I'll raise that on the HF Vocab PR as well.

Add --padvocab option to convert.py

Other minor cleanups
@KerfuffleV2
Copy link
Collaborator Author

KerfuffleV2 commented Nov 6, 2023

@TheBloke It actually did get merged: #3831

The person that made it kind of disappeared so I made a version that could apply to master and GG closed the original pull and merged those changes.

Your problem with this pull at least is that while it merged cleanly into master it hadn't been rebased on the current version in a while. I just did that. Sorry, didn't really think about it until now.

I don't have control over #3633 but you can ask to have it rebased also (or maybe it'll get merged soon?)

edit: I can't really say anything about that. My interaction with it has just been to add some features, fix some things. Unfortunately there's no long-term plan from me. (Obviously it would be good if one existed though.)

edit: Adding another random thing since I'm already hitting you with a notification. About the Yi model, apparently it gets pretty confused when it sees a BOS token and our conversion doesn't support the add_bos_token/add_eos_token options. If you want to mess with it manually, what would probably work is just setting the BOS token to 2 (same as EOS). They said they didn't use BOS at all in their training.

@KerfuffleV2
Copy link
Collaborator Author

The merges.txt stuff is in #3981, theoretically the --padvocab option will get added when #3633 is merged. This pull is now redundant.

@MiyazonoKaori
Copy link

MiyazonoKaori commented Nov 24, 2023

hi, @KerfuffleV2 @CausalLM @TheBloke
I recently converted the Qwen model into a llama structure.
However, I encountered an issue with additional bias parameters in the attention KQVO within the model, which are not directly compatible with llama.cpp.
I have made the following modifications to the llama.cpp file

struct llama_layer {
    ...
    // attention bias
    struct ggml_tensor * bo;
    struct ggml_tensor * bqkv;

    //add
    struct ggml_tensor * wq_bias;
    struct ggml_tensor * wk_bias;
    struct ggml_tensor * wv_bias;
    struct ggml_tensor * wo_bias;
...
...
case LLM_ARCH_LLAMA:
case LLM_ARCH_REFACT:
    ...
    layer.wq = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_Q,   "weight", i), {n_embd, n_embd},     backend_split);
    layer.wk = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_K,   "weight", i), {n_embd, n_embd_gqa}, backend_split);
    layer.wv = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_V,   "weight", i), {n_embd, n_embd_gqa}, backend_split);
    layer.wo = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_OUT, "weight", i), {n_embd, n_embd},     backend_split);

    // add
    layer.wq_bias = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_Q,   "bias", i), {n_embd}, backend);
    layer.wk_bias = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_K,   "bias", i), {n_embd_gqa}, backend);
    layer.wv_bias = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_V,   "bias", i), {n_embd_gqa}, backend);
    layer.wo_bias = ml.create_tensor(ctx, tn(LLM_TENSOR_ATTN_OUT, "bias", i), {n_embd}, backend);
...
struct ggml_cgraph * build_llama()
...
// self-attention
{
     //add
     struct ggml_tensor * Bq = model.layers[il].wq_bias;
     struct ggml_tensor * Bk = model.layers[il].wk_bias;
     struct ggml_tensor * Bv = model.layers[il].wv_bias;

     // compute Q and K and RoPE them
     struct ggml_tensor * Qcur = ggml_mul_mat(ctx0, model.layers[il].wq, cur);
     Qcur = ggml_add(ctx0, Qcur, Bq);  // add
     cb(Qcur, "Qcur", il);

     struct ggml_tensor * Kcur = ggml_mul_mat(ctx0, model.layers[il].wk, cur);
     Kcur = ggml_add(ctx0, Kcur, Bk);  //add
     cb(Kcur, "Kcur", il);

     struct ggml_tensor * Vcur = ggml_mul_mat(ctx0, model.layers[il].wv, cur);
     Vcur = ggml_add(ctx0, Vcur, Bv);  //add
     cb(Vcur, "Vcur", il);

     Qcur = ggml_rope_custom(
          ctx0, ggml_reshape_3d(ctx0, Qcur, n_embd_head, n_head,    n_tokens), inp_pos,
          n_embd_head, 0, 0, n_orig_ctx, freq_base, freq_scale,
          ext_factor, attn_factor, beta_fast, beta_slow
     );
     cb(Qcur, "Qcur", il);

     Kcur = ggml_rope_custom(
           ctx0, ggml_reshape_3d(ctx0, Kcur, n_embd_head, n_head_kv, n_tokens), inp_pos,
           n_embd_head, 0, 0, n_orig_ctx, freq_base, freq_scale,
           ext_factor, attn_factor, beta_fast, beta_slow
     );
     cb(Kcur, "Kcur", il);
     llm_build_kv_store(ctx0, hparams, kv_self, gf, Kcur, Vcur, n_ctx, n_tokens, kv_head, cb, il);
     cur = llm_build_kqv(ctx0, hparams, kv_self,
                                     model.layers[il].wo, 
                                     model.layers[il].wo_bias,  //add
     Qcur, KQ_scale, KQ_mask, n_ctx, n_tokens, n_kv, -1.0f, cb, il);
     cb(cur, "kqv_out", il);

After these changes, I was able to successfully generate with the llama.cpp.
Unfortunately, the output from the model is highly unsatisfactory and appears completely disordered.

sampling: 
	repeat_last_n = 64, repeat_penalty = 1.100, frequency_penalty = 0.000, presence_penalty = 0.000
	top_k = 40, tfs_z = 1.000, top_p = 0.700, min_p = 0.050, typical_p = 1.000, temp = 0.800
	mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000
generate: n_ctx = 512, n_batch = 512, n_predict = 2000, n_keep = 0


<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\nWho are you?\n<|im_end|>\n<|im_start|>assistant
I
Who am<|im_end|> [end of text]

Could anyone kindly advise where I might have gone wrong? What modifications should I consider to enable the model to function correctly?

Thank you very much for your time and assistance.

CausalLM added a commit to CausalLM/llama.cpp that referenced this pull request Dec 1, 2023
QKVO bias, should fix InternLM (ggerganov#3133) and works for LLaMAfied Qwen models (ggerganov#3743 (comment)).
ggerganov pushed a commit that referenced this pull request Dec 1, 2023
* Support attention_bias on LLaMA architecture

QKVO bias, should fix InternLM (#3133) and works for LLaMAfied Qwen models (#3743 (comment)).

* check existence of qkvo bias while loading llama models

Tested on LLaMA2, CUDA and CPU.

* Update llama.cpp
github-actions bot pushed a commit to KerfuffleV2/ggml-sys-bleedingedge that referenced this pull request Dec 2, 2023
== Relevant log messages from source repo:

commit 5a7d3125e7c24f223659b7f0b7aa7736986e92c0
Author: Georgi Gerganov <[email protected]>
Date:   Fri Dec 1 20:39:12 2023 +0200

    llama : avoid using "optional" keyword (#4283)

commit d5a1cbde60531d02ac74da27ea355182e3a4d516
Author: Georgi Gerganov <[email protected]>
Date:   Fri Dec 1 20:35:03 2023 +0200

    llama : support optional tensors (#4283)

commit 511f52c334e37033f9c9de07b98fca4abc9470bd
Author: Jared Van Bortel <[email protected]>
Date:   Fri Dec 1 13:18:35 2023 -0500

    build : enable libstdc++ assertions for debug builds (#4275)

commit 03562f3a86d6706eea9f4fc09b532946c191b34e
Author: CausalLM <[email protected]>
Date:   Sat Dec 2 02:17:06 2023 +0800

    llama : support attention bias on LLaMA architecture (#4283)

    * Support attention_bias on LLaMA architecture

    QKVO bias, should fix InternLM (ggerganov/llama.cpp#3133) and works for LLaMAfied Qwen models (ggerganov/llama.cpp#3743 (comment)).

    * check existence of qkvo bias while loading llama models

    Tested on LLaMA2, CUDA and CPU.

    * Update llama.cpp

commit 37c746d687d877bc11803e96b4dc5f378b83c0a0
Author: Shijie <[email protected]>
Date:   Sat Dec 2 02:16:31 2023 +0800

    llama : add Qwen support (#4281)

    * enable qwen to llama.cpp

    * llama : do not GPU split bias tensors

    ---------

    Co-authored-by: Georgi Gerganov <[email protected]>
YellowRoseCx added a commit to YellowRoseCx/koboldcpp-rocm that referenced this pull request Dec 12, 2023
commit 53b5ae02cb1b533b78302422951bcfdeca6e2738
Author: YellowRoseCx <[email protected]>
Date:   Tue Dec 12 12:08:29 2023 -0600

    mixtral fan service

commit 168b1d74e26d0321e2e89358303b6c33e8d7d33e
Merge: f13295b de15d4a6
Author: YellowRoseCx <[email protected]>
Date:   Tue Dec 12 12:00:52 2023 -0600

    Merge branch 'kcpp-rocm-mixtral2' into main2

commit de15d4a632939a685ec12fa17355298542facf15
Merge: 74acc54 ea4402b
Author: YellowRoseCx <[email protected]>
Date:   Tue Dec 12 11:45:19 2023 -0600

    Merge branch 'mixtral' into kcpp-rocm-mixtral

commit ea4402b
Author: Georgi Gerganov <[email protected]>
Date:   Tue Dec 12 17:03:38 2023 +0200

    test-backend-ops : add one more sum_rows test

commit a51bc0c
Author: Georgi Gerganov <[email protected]>
Date:   Tue Dec 12 15:55:42 2023 +0200

    metal : fix binary ops for ne10 % 4 != 0

commit 08eb991
Author: Georgi Gerganov <[email protected]>
Date:   Tue Dec 12 14:14:15 2023 +0200

    metal : add cpy f16 -> f32 kernel

commit a742d9f
Author: slaren <[email protected]>
Date:   Tue Dec 12 12:46:33 2023 +0100

    gguf-py : bump version

commit 6a419f4
Author: Georgi Gerganov <[email protected]>
Date:   Tue Dec 12 13:04:33 2023 +0200

    convert : support safetensors format

commit 74acc54
Author: Concedo <[email protected]>
Date:   Tue Dec 12 10:53:34 2023 +0800

    Revert "Hide hipBLAS (ROCm) if CuBLAS exists - vice versa"

    This reverts commit 4b854d4.

commit f1cbfab
Author: slaren <[email protected]>
Date:   Mon Dec 11 20:02:55 2023 +0100

    convert : fix style

commit 7dc75e3
Author: slaren <[email protected]>
Date:   Mon Dec 11 20:00:28 2023 +0100

    convert : use 1e6 rope_freq_base for mixtral

commit 296c945
Author: slaren <[email protected]>
Date:   Mon Dec 11 16:53:25 2023 +0100

    cuda : fix mul_mat_id with multi gpu

commit 33e50f1
Author: slaren <[email protected]>
Date:   Mon Dec 11 12:27:48 2023 +0100

    test-backend-ops : disable MOE test with thread sanitizer

commit ffda94c
Author: slaren <[email protected]>
Date:   Mon Dec 11 12:15:31 2023 +0100

    test-backend-ops : simplify and disable slow tests to avoid CI timeout

commit 06581f2
Author: Concedo <[email protected]>
Date:   Mon Dec 11 16:54:42 2023 +0800

    perf endpoint lets you monitor if the embedded horde worker has issues

commit fce971d
Author: Concedo <[email protected]>
Date:   Mon Dec 11 16:17:10 2023 +0800

    do not build the clblast noavx2 binary if not on windows

commit 8cbaed1
Author: Georgi Gerganov <[email protected]>
Date:   Mon Dec 11 08:55:16 2023 +0200

    llama : fix hard-coded number of experts

commit 4b854d4
Author: YellowRoseCx <[email protected]>
Date:   Sun Dec 10 22:49:35 2023 -0600

    Hide hipBLAS (ROCm) if CuBLAS exists - vice versa

commit b002981
Author: slaren <[email protected]>
Date:   Mon Dec 11 02:43:52 2023 +0100

    test-backend-ops : fix dequantize block offset

commit f1380d7
Author: slaren <[email protected]>
Date:   Sun Dec 10 22:58:31 2023 +0100

    test-backend-ops : add cpy from f32 -> all types test

commit 54d254b
Author: slaren <[email protected]>
Date:   Sun Dec 10 21:52:11 2023 +0100

    test-backend-ops : cleanup, add moe test for batches

commit e2cf3b7
Author: henk717 <[email protected]>
Date:   Sun Dec 10 14:30:17 2023 +0100

    koboldcpp.sh - The Mamba Multitool (LostRuins#554)

    * .sh script V1

    * koboldcpp.sh polish

    * koboldcpp.sh dist generator

    * Include html's in dist

    * RWKV in Linux Dist

    * Lower dependency requirements

    * Eliminate wget dependency

    * More distinct binary name

    I know its technically amd64, but I don't want to cause confusion among nvidia users.

    * Use System OpenCL

    Unsure how this will behave in the pyinstaller build, but pocl ended up CPU only. With a bit of luck the pyinstaller uses the one from the actual system if compiled in a system without opencl, while conda now includes it for that specific system.

    * Add cblas dependency

    Missing this causes compile failures on some system's

    * ICD workaround

    Ideally we find a better solution, but conda forces ICD and needs this for the successful compile. However, pyinstaller then embeds the ICD causing it to be limited to the system it was compiled for. By temporarily removing the ICD pyinstaller can't find it and everything remains functional. Ideally we do this on a pyinstaller level, but I could not find any good options to do so yet.

    ---------

    Co-authored-by: root <root@DESKTOP-DQ1QRAG>

commit 54ba263
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 15:27:41 2023 +0200

    test-backend-ops : make experts more evenly probable (test_moe)

commit b0b83dd
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 14:30:38 2023 +0200

    metal : fix ggml_mul_mat_id for F32

commit 65923a8
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 14:17:46 2023 +0200

    convert : determine n_ctx correctly

commit 8614aa7
Author: slaren <[email protected]>
Date:   Sun Dec 10 13:12:11 2023 +0100

    cuda : fix get_rows when ncols is odd

commit cefebb3
Author: slaren <[email protected]>
Date:   Sun Dec 10 13:11:39 2023 +0100

    test-backend-ops : add moe test

commit e640cbe
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 13:57:54 2023 +0200

    llama : add n_expert and n_expert_used to hparams + change quants

commit d1259b7
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 13:00:13 2023 +0200

    llama : do not quantize expert gating tensors

commit 6cfb31f
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 10:59:13 2023 +0200

    metal : add indirect mat-vec kernels for all quantization types

commit 016f9bb
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 10 09:38:21 2023 +0200

    metal : fix ggml_get_rows to work with non-cont src1

commit 0710b0f
Author: slaren <[email protected]>
Date:   Sat Dec 9 23:29:47 2023 +0100

    llama : offload missing ffn_moe_silu

commit 62b95f9
Author: slaren <[email protected]>
Date:   Sat Dec 9 22:39:34 2023 +0100

    cuda : support non-contiguous src1 in get_rows

commit 2e4db48
Author: slaren <[email protected]>
Date:   Sat Dec 9 22:38:22 2023 +0100

    ggml : update get_rows f16 and q

commit ac3f7d8
Author: slaren <[email protected]>
Date:   Sat Dec 9 19:19:03 2023 +0100

    ggml : get_rows : support non-contiguos tensors with gaps, generalize up to 3D

commit 8c5b66e
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 15:30:34 2023 +0200

    metal : reduce the kernel launches for ggml_mul_mat_id

commit 7e2006b
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 14:24:58 2023 +0200

    metal : add/mul/div use general kernel when src1 not cont

commit 06dfde3
Author: slaren <[email protected]>
Date:   Sat Dec 9 13:21:09 2023 +0100

    llama : add basic support for offloading moe with CUDA

commit 2cbcba8
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 14:18:42 2023 +0200

    metal : add more general support for ggml_get_rows + tests

commit 9064b1c
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 14:04:54 2023 +0200

    ggml : fix ggml_get_rows to take into account ne02 / ne11

commit ee8fb39
Author: slaren <[email protected]>
Date:   Sat Dec 9 12:42:25 2023 +0100

    ggml : add n_as argument to ggml_mul_mat_id

commit 7372b62
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 13:18:58 2023 +0200

    ggml : ggml_get_rows support 2D indexing [n_tokens, n_experts] (cpu only)

commit 8b185b7
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 13:01:42 2023 +0200

    llama : fix expert weighting in the FFN

commit 7ea3695
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 12:45:15 2023 +0200

    llama : first working version

commit af1a096
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 12:07:39 2023 +0200

    llama : fix cur -> cur_expert

commit aedfad1
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 11:47:40 2023 +0200

    llama : update graph to support MoE

commit 861cd67
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 11:19:46 2023 +0200

    ggml : sync latest ggml_mul_mat_id

commit a3eefe9
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 11:14:03 2023 +0200

    llama : model loading

commit d38e41e
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 10:59:37 2023 +0200

    convert : fix n_ff typo

commit dff8cbe
Author: Georgi Gerganov <[email protected]>
Date:   Sat Dec 9 10:51:58 2023 +0200

    convert : support Mixtral as LLAMA arch

commit 7a69152
Author: Concedo <[email protected]>
Date:   Fri Dec 8 21:06:32 2023 +0800

    lowvram var defaults

commit 7418bca
Author: Concedo <[email protected]>
Date:   Fri Dec 8 19:20:30 2023 +0800

    up ver

commit c47bc28
Author: Concedo <[email protected]>
Date:   Fri Dec 8 18:35:45 2023 +0800

    slight refactor for noscript ui

commit 7469f20
Author: Concedo <[email protected]>
Date:   Fri Dec 8 18:16:14 2023 +0800

    use lowvram flag for offload qkv

commit ec21fa7
Merge: 930cdfb fe680e3
Author: Concedo <[email protected]>
Date:   Fri Dec 8 17:42:26 2023 +0800

    Merge branch 'master' into concedo_experimental

    # Conflicts:
    #	.github/workflows/build.yml
    #	.gitignore
    #	CMakeLists.txt
    #	Makefile
    #	Package.swift
    #	README.md
    #	ggml-cuda.cu
    #	llama.cpp
    #	llama.h
    #	scripts/sync-ggml.sh
    #	tests/CMakeLists.txt

commit 930cdfb
Author: Concedo <[email protected]>
Date:   Fri Dec 8 16:53:30 2023 +0800

    updated lite, added patch that links to noscript mode

commit fe680e3
Author: Georgi Gerganov <[email protected]>
Date:   Thu Dec 7 22:26:54 2023 +0200

    sync : ggml (new ops, tests, backend, etc.) (ggerganov#4359)

    * sync : ggml (part 1)

    * sync : ggml (part 2, CUDA)

    * sync : ggml (part 3, Metal)

    * ggml : build fixes

    ggml-ci

    * cuda : restore lost changes

    * cuda : restore lost changes (StableLM rope)

    * cmake : enable separable compilation for CUDA

    ggml-ci

    * ggml-cuda : remove device side dequantize

    * Revert "cmake : enable separable compilation for CUDA"

    This reverts commit 09e35d0.

    * cuda : remove assert for rope

    * tests : add test-backend-ops

    * ggml : fix bug in ggml_concat

    * ggml : restore `ggml_get_n_tasks()` logic in `ggml_graph_plan()`

    * ci : try to fix macOS

    * ggml-backend : remove backend self-registration

    * ci : disable Metal for macOS cmake build

    ggml-ci

    * metal : fix "supports family" call

    * metal : fix assert

    * metal : print resource path

    ggml-ci

    ---------

    Co-authored-by: slaren <[email protected]>

commit bcc0eb4
Author: Georgi Gerganov <[email protected]>
Date:   Thu Dec 7 13:03:17 2023 +0200

    llama : per-layer KV cache + quantum K cache (ggerganov#4309)

    * per-layer KV

    * remove unnecessary copies

    * less code duplication, offload k and v separately

    * llama : offload KV cache per-layer

    * llama : offload K shift tensors

    * llama : offload for rest of the model arches

    * llama : enable offload debug temporarily

    * llama : keep the KV related layers on the device

    * llama : remove mirrors, perform Device -> Host when partial offload

    * common : add command-line arg to disable KV cache offloading

    * llama : update session save/load

    * llama : support quantum K cache (ggerganov#4312)

    * llama : support quantum K cache (wip)

    * metal : add F32 -> Q8_0 copy kernel

    * cuda : add F32 -> Q8_0 copy kernel

    ggml-ci

    * cuda : use mmv kernel for quantum cache ops

    * llama : pass KV cache type through API

    * llama : fix build

    ggml-ci

    * metal : add F32 -> Q4_0 copy kernel

    * metal : add F32 -> Q4_1 copy kernel

    * cuda : wip

    * cuda : add F32 -> Q4_0 and F32 -> Q4_1 copy kernels

    * llama-bench : support type_k/type_v

    * metal : use mm kernel only for quantum KV cache

    * cuda : add comment

    * llama : remove memory_f16 and kv_f16 flags

    ---------

    Co-authored-by: slaren <[email protected]>

    * readme : add API change notice

    ---------

    Co-authored-by: slaren <[email protected]>

commit 81bc921
Author: Hongyu Ouyang <[email protected]>
Date:   Thu Dec 7 02:25:22 2023 -0800

    train : fix ggerganov#4227 (double free in examples/train-text-from-scratch/train-text-from-scratch.cpp) (ggerganov#4351)

    On commit b1108 (44c117f) xaedes added

        ggml_allocr * alloc = NULL;

        ... (many lines in between)

        if (alloc) {
            ggml_allocr_free(alloc);
        }

    Which is correct, but it's easy to lose context after many lines in between.

    On commit b1287 (0e76a899) xaedes made a big change. From here on, alloc is freed eagerly.

        alloc = ggml_allocr_new(...)
        ... (short lines of code)
        ggml_allocr_free(alloc)

    This happens a few times, but alloc is never set to NULL, and many lines below,
    we still have

        if (alloc) {
            ggml_allocr_free(alloc);
        }

    which causes a double-free.

commit 05cd6e5
Author: Georgi Gerganov <[email protected]>
Date:   Wed Dec 6 20:21:59 2023 +0200

    server : recognize cache_prompt parameter in OAI API (ggerganov#4347)

commit c751152
Author: Concedo <[email protected]>
Date:   Thu Dec 7 00:52:25 2023 +0800

    noscript mode is done

commit 12002d8
Author: Concedo <[email protected]>
Date:   Wed Dec 6 17:51:08 2023 +0800

    very basic noscript mode

commit caa9249
Author: Georgi Gerganov <[email protected]>
Date:   Wed Dec 6 10:41:03 2023 +0200

    common : fix compile warning

commit da5eaef
Author: stduhpf <[email protected]>
Date:   Wed Dec 6 09:08:17 2023 +0100

    speculative : support `--color` (ggerganov#4343)

    * speculative: add some colors

    * minor : add braces

    ---------

    Co-authored-by: Georgi Gerganov <[email protected]>

commit 5f6e0c0
Author: Marcus Dunn <[email protected]>
Date:   Tue Dec 5 10:55:12 2023 -1000

    grammar : pre-computed pieces + reserve mem + less string copies (ggerganov#4330)

    * reserve space for codepoints

    * improvement for the appended 0

    * used precomputed token text for grammar sample

    * reserve canidates_decoded

    * reserve canidates_grammar

    * remove candidates_decoded

    * Revert "remove candidates_decoded"

    This reverts commit 3773328.

    * changed decode_utf8 to take src by ref

commit 5aa365d
Author: Kerfuffle <[email protected]>
Date:   Tue Dec 5 10:19:18 2023 -0700

    llama : allow overriding GGUF metadata when loading model (ggerganov#4092)

    * feat: Allow overriding GGUF metadata when loading model

    * Fix the one time GCC is stricter than clang about something

    * Step1

    * Refactor... basically everything!

    * Nuke obsolete GetArrayLen struct

    * simplify std::string specialization

    * Various cleanups

    Add informational output when overrides are applied

    Warn user when an override with the wrong type is specified

    * Fix broken logic for parsing bool KV overrides
    Fix issue where overrides didn't apply when key missing in GGUF metadata
    Resolve merge changes

    * llama : rearrange model params

    * Update new GET_KEY call

    Add note that metadata KV overrides aren't reflected in initial metadata KV info dump

    ---------

    Co-authored-by: cebtenzzre <[email protected]>
    Co-authored-by: Georgi Gerganov <[email protected]>

commit b6f952f
Author: Concedo <[email protected]>
Date:   Tue Dec 5 21:08:10 2023 +0800

    improved exit logic

commit 52c8bc3
Author: MaggotHATE <[email protected]>
Date:   Tue Dec 5 15:05:51 2023 +0500

    sampling : custom samplers order (ggerganov#4285)

    * Samplers sequence order w parameter

    * Cleaned commented code

    * Fixed formatting

    * Rewrote with unordered_map

    * Revert and rewrite, too many problems and safeguards would be needed

    * Fixed code style

    * Code style fixes according to review

    * More readable samplers input string, fixed help

    * Style fix in sampler_queue

    * Formatting fixes

    * Fixing whitespaces

commit e4b76bb
Author: kchro3 <[email protected]>
Date:   Mon Dec 4 23:29:46 2023 -0800

    swift : revert compiler checks for swift package (ggerganov#4332)

commit 23b5e12
Author: Daniel Bevenius <[email protected]>
Date:   Mon Dec 4 17:04:21 2023 +0100

    simple : update error message for KV cache check (ggerganov#4324)

    This commit updates the error message that is printed when the
    KV cache is not big enough to hold all the prompt and generated
    tokens. Specifically it removes the reference to n_parallel and
    replaces it with n_len.

    Signed-off-by: Daniel Bevenius <[email protected]>

commit d208995
Author: Miwa / Ensan <[email protected]>
Date:   Tue Dec 5 01:03:49 2023 +0900

    swift : fix concatenation method to avoid invalid UTF8 stringfication (ggerganov#4325)

commit 5c9f90c
Author: Miwa / Ensan <[email protected]>
Date:   Mon Dec 4 22:43:45 2023 +0900

    swift : fix prompt tokenization logic (ggerganov#4321)

commit a5a5839
Author: Concedo <[email protected]>
Date:   Mon Dec 4 21:10:42 2023 +0800

    handle accidentally selecting a kcpps file as model instead

commit 4fa44e8
Author: Ikko Eltociear Ashimine <[email protected]>
Date:   Mon Dec 4 16:57:35 2023 +0900

    grammar-parser : fix typo (ggerganov#4318)

    preceeding -> preceding

commit 8602f5a
Merge: ac36aee fbbc428
Author: Concedo <[email protected]>
Date:   Sun Dec 3 22:00:14 2023 +0800

    Merge branch 'master' into concedo_experimental

commit fbbc428
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 3 15:56:35 2023 +0200

    ggml : reuse ggml_get_n_tasks() in ggml_graph_plan() (ggerganov#4308)

    * ggml : fix soft max out-of-bounds access

    ggml-ci

    * ggml : reuse ggml_get_n_tasks() in ggml_graph_plan()

    ggml-ci

commit ac36aee
Merge: 48544cd 33e171d
Author: Concedo <[email protected]>
Date:   Sun Dec 3 21:56:29 2023 +0800

    Merge branch 'master' into concedo_experimental

    # Conflicts:
    #	CMakeLists.txt
    #	Makefile

commit adf3de4
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 3 15:56:22 2023 +0200

    ggml : fix soft max out-of-bounds access (ggerganov#4307)

    ggml-ci

commit 48544cd
Author: Concedo <[email protected]>
Date:   Sun Dec 3 21:46:50 2023 +0800

    Revert "Revert "ggml : add ggml_soft_max_ext (ggerganov#4256)""

    This reverts commit a8e66ef.

commit 33e171d
Author: Ed Lee <[email protected]>
Date:   Sun Dec 3 01:10:43 2023 -0800

    server : fix OpenAI API `stop` field to be optional (ggerganov#4299)

    (cherry picked from commit Mozilla-Ocho/llamafile@e8c92bc)

commit 6949b50
Author: Rickard Edén <[email protected]>
Date:   Sun Dec 3 10:03:25 2023 +0100

    py : add grammar to oai like api (ggerganov#4294)

commit d7b800b
Author: Georgi Gerganov <[email protected]>
Date:   Sun Dec 3 10:58:16 2023 +0200

    llama : pad KV cache size (ggerganov#4280)

    * llama : pad KV cache size to 32

    * metal : try to improve batched decoding

commit 6570a20
Author: Concedo <[email protected]>
Date:   Sun Dec 3 15:44:53 2023 +0800

    token count includes ids

commit 5a7d312
Author: Georgi Gerganov <[email protected]>
Date:   Fri Dec 1 20:39:12 2023 +0200

    llama : avoid using "optional" keyword (ggerganov#4283)

commit d5a1cbd
Author: Georgi Gerganov <[email protected]>
Date:   Fri Dec 1 20:35:03 2023 +0200

    llama : support optional tensors (ggerganov#4283)

commit b220222
Author: Miwa / Ensan <[email protected]>
Date:   Sat Dec 2 03:19:45 2023 +0900

    swift : fix token_to_piece implementation (ggerganov#4278)

    * Fix token_to_piece implementation in Swift

    * Fix errors

commit 511f52c
Author: Jared Van Bortel <[email protected]>
Date:   Fri Dec 1 13:18:35 2023 -0500

    build : enable libstdc++ assertions for debug builds (ggerganov#4275)

commit 03562f3
Author: CausalLM <[email protected]>
Date:   Sat Dec 2 02:17:06 2023 +0800

    llama : support attention bias on LLaMA architecture (ggerganov#4283)

    * Support attention_bias on LLaMA architecture

    QKVO bias, should fix InternLM (ggerganov#3133) and works for LLaMAfied Qwen models (ggerganov#3743 (comment)).

    * check existence of qkvo bias while loading llama models

    Tested on LLaMA2, CUDA and CPU.

    * Update llama.cpp

commit 37c746d
Author: Shijie <[email protected]>
Date:   Sat Dec 2 02:16:31 2023 +0800

    llama : add Qwen support (ggerganov#4281)

    * enable qwen to llama.cpp

    * llama : do not GPU split bias tensors

    ---------

    Co-authored-by: Georgi Gerganov <[email protected]>

commit 880f579
Author: Georgi Gerganov <[email protected]>
Date:   Fri Dec 1 18:42:11 2023 +0200

    llama : fix integer overflow during quantization (ggerganov#4284)

    happens with multi-threaded quantization of Qwen-72B

    ggml-ci
mounta11n pushed a commit to mounta11n/plusplus-camall that referenced this pull request Dec 19, 2023
* Support attention_bias on LLaMA architecture

QKVO bias, should fix InternLM (ggerganov#3133) and works for LLaMAfied Qwen models (ggerganov#3743 (comment)).

* check existence of qkvo bias while loading llama models

Tested on LLaMA2, CUDA and CPU.

* Update llama.cpp
hodlen added a commit to hodlen/llama.cpp that referenced this pull request Apr 1, 2024
llama : restore prefix space in llama tokenizer (ggerganov#4081)

gguf : fix potential infinite loops while parsing (ggerganov#4100)

Co-authored-by: Bernhard Gstrein <[email protected]>

Respect tokenizer.ggml.add_bos_token value when tokenizing (ggerganov#4040)

* gguf-py: gguf-dump: Respect --no-tensor flag in JSON mode.

* Respect add_bos_token GGUF metadata value

* gguf-py: Try to fix SpecialVocab giving up too easily for the Nth time

llama : fix data units (ggerganov#4101)

* llama : fix data units

ggml-ci

* Revert "llama : fix data units"

This reverts commit f5feac8.

* llama : disambiguate data units

ggml-ci

cuda : get_row_rounding F32 (ggerganov#4095)

* Fix ggerganov#4017

* Update ggml-cuda.cu

Co-authored-by: Jared Van Bortel <[email protected]>

* Update ggml-cuda.cu

Co-authored-by: Jared Van Bortel <[email protected]>

---------

Co-authored-by: Jared Van Bortel <[email protected]>

finetune : zero the loraB initial vectors (ggerganov#4082)

* finetune : zero the loraB initial vectors

Without this, the first iteration is starting out far from the base model, instead of exactly on it.
Zeroing loraB is what the paper recommends. loralib also zeroes at least one of the init vector pairs
(though it departs from the paper in using a different distribution for the other vector, in some cases).

* tabs to spaces

* Use ggml_set_zero instead of adding a new function

finetune : speed-up ggml_compute_forward_out_prod_f32 via BLAS (ggerganov#4079)

* Remove logically superfluous assertions and order by dimension

* Use cblas_sgemm() to implement ggml_compute_forward_out_prod()

* Remove ggml_compute_forward_out_prod_use_blas(), fix compiling errors on cmake/zig, remove trailing whitespace

* Add openBLAS support for sgemm() in compute_forward_out_prod()

llama : add functions to get the model's metadata (ggerganov#4013)

* llama : add functions to get the model's metadata

* format -> std::to_string

* better documentation

train : move number of gpu layers argument parsing to common/train.cpp (ggerganov#4074)

- introduces help entry for the argument
 - cuts '--gpu-layers' form in order to simplify usage and documentation.

Signed-off-by: Jiri Podivin <[email protected]>
Co-authored-by: Jiri Podivin <[email protected]>

py : remove superfluous import statements (ggerganov#4076)

Signed-off-by: Jiri Podivin <[email protected]>
Co-authored-by: Jiri Podivin <[email protected]>

llava : fix compilation warning that fread return value is not used (ggerganov#4069)

common : improve yaml log escaping (ggerganov#4080)

* logging: improve escaping in yaml output

* logging: include review feedback

py : Falcon HF compatibility (ggerganov#4104)

Falcon HF compatibility

convert : use 'model' value if it exists. This allows karpathy/tinyllamas to load (ggerganov#4089)

Co-authored-by: Don Mahurin <@>

examples : add tokenize (ggerganov#4039)

tokenize : fix trailing whitespace

build : support ppc64le build for make and CMake (ggerganov#3963)

* build: support ppc64le build for make and CMake

* build: keep __POWER9_VECTOR__ ifdef and extend with __powerpc64__

Co-authored-by: Georgi Gerganov <[email protected]>

---------

Co-authored-by: Georgi Gerganov <[email protected]>

llama : increase max nodes (ggerganov#4115)

Clean up ggml-cuda.cu warnings when compiling with clang (for ROCM) (ggerganov#4124)

* ggml-cuda.cu: Clean up warnings when compiling with clang

* ggml-cuda.cu: Move static items into anonymous namespace

* ggml-cuda.cu: Fix use of namespace start macro

* Revert "ggml-cuda.cu: Fix use of namespace start macro"

This reverts commit 26c1149.

* Revert "ggml-cuda.cu: Move static items into anonymous namespace"

This reverts commit e29757e.

scripts : Remove missed baichuan convert script (ggerganov#4127)

tokenize example: Respect normal add BOS token behavior (ggerganov#4126)

Allow building with Makefile

gguf-py : export chat templates (ggerganov#4125)

* gguf-py : export chat templates

* llama.cpp : escape new lines in gguf kv info prints

* gguf-py : bump version

* gguf-py : check chat_template type

* gguf-py : initialize chat_template

gitignore : tokenize

common : comma should be semicolon (ggerganov#4137)

server : relay error messages (ggerganov#4131)

finetune : add --n-gpu-layers flag info to --help (ggerganov#4128)

Revert "finetune : add --n-gpu-layers flag info to --help (ggerganov#4128)"

This reverts commit 05e8301.

speculative : fix prompt tokenization in speculative example (ggerganov#4025)

* Support special tokens and not adding BOS to prompt in speculative

* Adapt to new should_add_bos function

* Ensure tgt and dft have same add_bos setting

ci : add flake8 to github actions (python linting) (ggerganov#4129)

Disabled rules:

* E203 Whitespace before ':' - disabled because we often use 'C' Style where values are aligned

* E211 Whitespace before '(' (E211) - disabled because we often use 'C' Style where values are aligned

* E221 Multiple spaces before operator - disabled because we often use 'C' Style where values are aligned

* E225 Missing whitespace around operator - disabled because it's broken so often it seems like a standard

* E231 Missing whitespace after ',', ';', or ':' - disabled because we often use 'C' Style where values are aligned

* E241 Multiple spaces after ',' - disabled because we often use 'C' Style where values are aligned

* E251 Unexpected spaces around keyword / parameter equals - disabled because it's broken so often it seems like a standard

* E261 At least two spaces before inline comment - disabled because it's broken so often it seems like a standard

* E266 Too many leading '#' for block comment - sometimes used as "section" separator

* E501 Line too long - disabled because it's broken so often it seems like a standard

* E701 Multiple statements on one line (colon) - broken only in convert.py when defining abstract methods (we can use# noqa instead)

* E704 Multiple statements on one line - broken only in convert.py when defining abstract methods (we can use# noqa instead)

main : Add ChatML functionality to main example (ggerganov#4046)

Co-authored-by: Sebastian Cramond <[email protected]>

readme : update ROCm Windows instructions (ggerganov#4122)

* Update README.md

* Update README.md

Co-authored-by: Jared Van Bortel <[email protected]>

---------

Co-authored-by: Jared Van Bortel <[email protected]>

finetune - update readme to mention llama support only (ggerganov#4148)

stablelm : simplify + speedup generation (ggerganov#4153)

docs : add llama-star arch idea

examples : fix typo in parallel example doc comment (ggerganov#4181)

Signed-off-by: Daniel Bevenius <[email protected]>

readme : update hot topics

llama : KV cache view API + better KV cache management (ggerganov#4170)

* llama : keep track of used KV cells + better KV cache management

* llama : zero KV cache used upon clear

ggml-ci

* llama : allow exporting a view of the KV cache (ggerganov#4180)

* Allow exporting a view of the KV cache

* Allow dumping the sequences per cell in common

* Track max contiguous cells value and position as well

* Fix max contiguous empty cells index calculation

Make dump functions deal with lengths or sequences counts > 10 better

* Fix off by one error in dump_kv_cache_view

* Add doc comments for KV cache view functions

Eliminate cell sequence struct; use llama_seq_id directly

Minor cleanups

* common : add -dkvc arg for enabling kv cache dumps

---------

Co-authored-by: Kerfuffle <[email protected]>

Fix incorrect format strings and uninitialized variables. (ggerganov#4133)

* Fix incorrect format strings and uninitialized variables.

* Address comments

* Add the missing include statement

readme : use PATH for Windows ROCm (ggerganov#4195)

* Update README.md to use PATH for Windows ROCm

* Update README.md

* Update README.md

main.swift : fix eos checking (ggerganov#4197)

llama_token_eos(const struct llama_model *) is currently getting struct llama_context type variable context as a parameter.

convert : fix tensors using grad in some models (ggerganov#4173)

ggml-cuda : support stablelm rope (ggerganov#4156)

* ggml-cuda : support stablelm rope

* remove unused freq_base kernel parameter

* add n_dims parameter to llm_build_k_shift, default to n_rot via overload

* llama : fix llm_build_k_shift args

---------

Co-authored-by: Georgi Gerganov <[email protected]>

llama : set metal log callback correctly (ggerganov#4204)

server : OAI API compatibility (ggerganov#4198)

* Add openai-compatible POST /v1/chat/completions API endpoint to server example

* fix code style

* Update server README.md

* Improve server README.md

* Fix server.cpp code style according to review

* server : some style changes

* server : indentation

* server : enable special tokens during tokenization by default

* server : minor code style

* server : change random string generator

* straightforward /v1/models endpoint

---------

Co-authored-by: kir-gadjello <[email protected]>
Co-authored-by: Tobi Lütke <[email protected]>

readme : update hot topics

Update docs for yarn_ext_factor <0.0 as unspecified instead of NaN (ggerganov#4189)

llama : grammar `reserve` space in `decode_utf8` (ggerganov#4210)

* reserve space for codepoints

* improvement for the appended 0

scripts : Use mmap in torch load (ggerganov#4202)

* Use mmap in torch load, prefer .bin files when loading

* Revert .bin > .safetensors preference

metal : fix yarn (ggerganov#4220)

get the correct n_orig_ctx in metal

lookahead : add example for lookahead decoding (ggerganov#4207)

* lookahead : init

* lookahead : generate and store n-grams

* lookahead : use loop instead recursion to generate n-grams

* lookahead : initial working implementation

* lookahead : filter repeating n-grams

* lookahead : use deterministic init

* lookahead : add to Makefile

* lookahead : fix a bug in the seq_id of the lookahead tokens

* lookahead : add comments

---------

Co-authored-by: slaren <[email protected]>

readme : update hot topics

lookahead : support `-n -1` infinite generation

ggml : fix -Warray-bounds warning with gcc (ggerganov#4231)

examples : iOS example with swift ui (ggerganov#4159)

* copy to llama.cpp as subdir

* attempt enabling metal, fails

* ggml metal compiles!

* Update README.md

* initial conversion to new format, utf8 errors?

* bug fixes, but now has an invalid memory access :(

* added O3, now has insufficient memory access

* begin sync with master

* update to match latest code, new errors

* fixed it!

* fix for loop conditionals, increase result size

* fix current workflow errors

* attempt a llama.swiftui workflow

* Update .github/workflows/build.yml

Co-authored-by: Georgi Gerganov <[email protected]>

---------

Co-authored-by: Georgi Gerganov <[email protected]>

readme : add Amica to UI list (ggerganov#4230)

cmake : fix issue with version info not getting baked into LlamaConfig.cmake (ggerganov#3970)

* Split CPP generation from build-info query

* Remove blank lines

* Add BUILD_SHARED_LIBS option

ggml : re-enable BLAS for CPU when src0 != F32 + remove redundant full offload checks in llama.cpp (ggerganov#4240)

* ggml : use blas even if src0 is not F32

* llama : use n_threads_batch only when n_tokens >= 32

ggml-ci

* llama : revert n_threads_batch logic

ggml-ci

ggml : restore abort() in GGML_ASSERT (ggerganov#4242)

readme : add FreeChat (ggerganov#4248)

examples : add readme files

py : fix oai proxy (ggerganov#3972)

* fix oai proxy

fix generation not stoped while bot stop talking in chat mode

fix possible `slot_id` not exist

response for cors (and pre flight)

* oai proxy: workaround for some client (such as Chatbox)

* use stop as separator to replace hardcoded `\n`

llama : fix typical sampling (ggerganov#4261)

Typical sampling was broken because after copying new_candidates into canditates, the "sorted" bool is left at "true", but the new data is no longer sorted according to probability. Patch to set "sorted" to false.

Test: Generating with temp=0.0001 (approx. argmax)  should generate the same sequence at typical>=1.0 and typical=0.9999 (approx. disabled, but enters the typical sampling codepath).

convert.py : fix llama/llama2 conversion due to vocab_size=-1 (ggerganov#4258)

llama : fix alignment of general.name in print meta (ggerganov#4254)

* llama: fix alignment of general.name in print meta

This commit fixes the alignment of the general.name field in the
llm_load_print_meta function.

Currently the output looks like this:
```console
llm_load_print_meta: model ftype      = mostly Q4_0
llm_load_print_meta: model params     = 13.02 B
llm_load_print_meta: model size       = 6.86 GiB (4.53 BPW)
llm_load_print_meta: general.name   = LLaMA v2
```
And with this commit it looks like this:
```console
llm_load_print_meta: model ftype      = mostly Q4_0
llm_load_print_meta: model params     = 13.02 B
llm_load_print_meta: model size       = 6.86 GiB (4.53 BPW)
llm_load_print_meta: general.name     = LLaMA v2
```

Signed-off-by: Daniel Bevenius <[email protected]>

* llama: fix alignment of special tokens

Signed-off-by: Daniel Bevenius <[email protected]>

---------

Signed-off-by: Daniel Bevenius <[email protected]>

readme : fix typo (ggerganov#4253)

llama.cpp uses GitHub Actions, not Gitlab Actions.

cmake : fix the metal file foder path (ggerganov#4217)

batched.swift : update README.md (ggerganov#4214)

docs: update how to run

docker : add finetune option (ggerganov#4211)

readme : fix (ggerganov#4135)

* fix: readme

* chore: resolve comments

* chore: resolve comments

main : pass LOG_TEE callback to llama.cpp log (ggerganov#4033)

* main : Call llama_log_set to use LOG_TEE

* tabs to spaces

llava : ShareGPT4V compatibility (vision encoder only loading) (ggerganov#4172)

* ShareGPT4 compatibility (vision encoder only loading)

Load only a CLIP vision encoder (as supplied by ShareGPT finetunes)
Corrects the argument parsing for --img_mean and --img_std (which were previously not parsed but attempted to access)
Defines defaults for img_mean and img_std which are equal to the llava 1.5 CLIP encoder, so you do not have to provide them

* Update convert-image-encoder-to-gguf.py

build : fix build info generation and cleanup Makefile (ggerganov#3920)

* cmake : fix joining of REAL_GIT_DIR

* fix includes with help from include-what-you-use

* make : remove unneeded deps and add test-rope target

* fix C includes in C++ source files

* Revert "fix includes with help from include-what-you-use"

This reverts commit 635e9fa.

make : fix Apple clang determination bug (ggerganov#4272)

Co-authored-by: Will Findley <[email protected]>

server : add single-client multi-prompt support (ggerganov#4232)

* * add multiprompt support

* * cleanup

* * more cleanup

* * remove atomicity of id_gen, and change lock_guard to unique_lock on completion requests

* * remove all references to mutex_multitasks

* Update examples/server/server.cpp

Co-authored-by: Jared Van Bortel <[email protected]>

* Update examples/server/server.cpp

Co-authored-by: Jared Van Bortel <[email protected]>

* Update examples/server/server.cpp

Co-authored-by: Jared Van Bortel <[email protected]>

* Update examples/server/server.cpp

Co-authored-by: Jared Van Bortel <[email protected]>

* * change to set

---------

Co-authored-by: Jared Van Bortel <[email protected]>

server : add --log-disable to disable logging to file (ggerganov#4260)

* * add --log-disable to disable logging to file in the server example

* * typo fix

ggml : add ggml_soft_max_ext (ggerganov#4256)

* metal : implement soft_max_ext

* cuda : implement soft_max_ext

* ggml : implement soft_max_ext (CPU)

* batched-bench : print threads

ggml-ci

* metal : simplify soft_max encoding

ggml-ci

* cuda : use 512 threads for soft_max instead of 32

* ggml : update soft max cpu

* cuda : do warp-based block reduce

* cuda : increase max block size to 1024

* cuda : fix warp reduction initialization of shared mem

* metal : warp-based reduction for soft max kernel

* metal : warp-based reduce for rms_norm

* metal : simplify soft max kernel

ggml-ci

* alloc : fix build with debug

py : add requirements file for convert-hf-to-gguf.py (ggerganov#4277)

This commit adds a requirements file for the convert-hf-to-gguf.py
script, and also add the torch and transformers packages to it.

The motivation for this is that currently running convert-hf-to-gguf.py
will produce the following error:
```console
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install -r requirements.txt
Collecting numpy==1.24.4
Collecting sentencepiece==0.1.98
Collecting gguf>=0.1.0
Installing collected packages: sentencepiece, numpy, gguf
Successfully installed gguf-0.5.1 numpy-1.24.4 sentencepiece-0.1.98

(venv) $ python convert-hf-to-gguf.py --help
Traceback (most recent call last):
  File "llama.cpp/convert-hf-to-gguf.py", line 16, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'
```
With this commit, and using requirements-hf-to-gguf.txt instead of
requirements.txt, the script can be run and shows the help output.

Signed-off-by: Daniel Bevenius <[email protected]>

llama : fix integer overflow during quantization (ggerganov#4284)

happens with multi-threaded quantization of Qwen-72B

ggml-ci

llama : add Qwen support (ggerganov#4281)

* enable qwen to llama.cpp

* llama : do not GPU split bias tensors

---------

Co-authored-by: Georgi Gerganov <[email protected]>

llama : support attention bias on LLaMA architecture (ggerganov#4283)

* Support attention_bias on LLaMA architecture

QKVO bias, should fix InternLM (ggerganov#3133) and works for LLaMAfied Qwen models (ggerganov#3743 (comment)).

* check existence of qkvo bias while loading llama models

Tested on LLaMA2, CUDA and CPU.

* Update llama.cpp

build : enable libstdc++ assertions for debug builds (ggerganov#4275)

swift : fix token_to_piece implementation (ggerganov#4278)

* Fix token_to_piece implementation in Swift

* Fix errors

llama : support optional tensors (ggerganov#4283)

llama : avoid using "optional" keyword (ggerganov#4283)

llama : pad KV cache size (ggerganov#4280)

* llama : pad KV cache size to 32

* metal : try to improve batched decoding

py : add grammar to oai like api (ggerganov#4294)

server : fix OpenAI API `stop` field to be optional (ggerganov#4299)

(cherry picked from commit Mozilla-Ocho/llamafile@e8c92bc)

ggml : fix soft max out-of-bounds access (ggerganov#4307)

ggml-ci

ggml : reuse ggml_get_n_tasks() in ggml_graph_plan() (ggerganov#4308)

* ggml : fix soft max out-of-bounds access

ggml-ci

* ggml : reuse ggml_get_n_tasks() in ggml_graph_plan()

ggml-ci

grammar-parser : fix typo (ggerganov#4318)

preceeding -> preceding

swift : fix prompt tokenization logic (ggerganov#4321)

swift : fix concatenation method to avoid invalid UTF8 stringfication (ggerganov#4325)

simple : update error message for KV cache check (ggerganov#4324)

This commit updates the error message that is printed when the
KV cache is not big enough to hold all the prompt and generated
tokens. Specifically it removes the reference to n_parallel and
replaces it with n_len.

Signed-off-by: Daniel Bevenius <[email protected]>

swift : revert compiler checks for swift package (ggerganov#4332)

sampling : custom samplers order (ggerganov#4285)

* Samplers sequence order w parameter

* Cleaned commented code

* Fixed formatting

* Rewrote with unordered_map

* Revert and rewrite, too many problems and safeguards would be needed

* Fixed code style

* Code style fixes according to review

* More readable samplers input string, fixed help

* Style fix in sampler_queue

* Formatting fixes

* Fixing whitespaces

llama : allow overriding GGUF metadata when loading model (ggerganov#4092)

* feat: Allow overriding GGUF metadata when loading model

* Fix the one time GCC is stricter than clang about something

* Step1

* Refactor... basically everything!

* Nuke obsolete GetArrayLen struct

* simplify std::string specialization

* Various cleanups

Add informational output when overrides are applied

Warn user when an override with the wrong type is specified

* Fix broken logic for parsing bool KV overrides
Fix issue where overrides didn't apply when key missing in GGUF metadata
Resolve merge changes

* llama : rearrange model params

* Update new GET_KEY call

Add note that metadata KV overrides aren't reflected in initial metadata KV info dump

---------

Co-authored-by: cebtenzzre <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>

grammar : pre-computed pieces + reserve mem + less string copies (ggerganov#4330)

* reserve space for codepoints

* improvement for the appended 0

* used precomputed token text for grammar sample

* reserve canidates_decoded

* reserve canidates_grammar

* remove candidates_decoded

* Revert "remove candidates_decoded"

This reverts commit 3773328.

* changed decode_utf8 to take src by ref

speculative : support `--color` (ggerganov#4343)

* speculative: add some colors

* minor : add braces

---------

Co-authored-by: Georgi Gerganov <[email protected]>

common : fix compile warning

server : recognize cache_prompt parameter in OAI API (ggerganov#4347)

train : fix ggerganov#4227 (double free in examples/train-text-from-scratch/train-text-from-scratch.cpp) (ggerganov#4351)

On commit b1108 (44c117f) xaedes added

    ggml_allocr * alloc = NULL;

    ... (many lines in between)

    if (alloc) {
        ggml_allocr_free(alloc);
    }

Which is correct, but it's easy to lose context after many lines in between.

On commit b1287 (0e76a899) xaedes made a big change. From here on, alloc is freed eagerly.

    alloc = ggml_allocr_new(...)
    ... (short lines of code)
    ggml_allocr_free(alloc)

This happens a few times, but alloc is never set to NULL, and many lines below,
we still have

    if (alloc) {
        ggml_allocr_free(alloc);
    }

which causes a double-free.

llama : per-layer KV cache + quantum K cache (ggerganov#4309)

* per-layer KV

* remove unnecessary copies

* less code duplication, offload k and v separately

* llama : offload KV cache per-layer

* llama : offload K shift tensors

* llama : offload for rest of the model arches

* llama : enable offload debug temporarily

* llama : keep the KV related layers on the device

* llama : remove mirrors, perform Device -> Host when partial offload

* common : add command-line arg to disable KV cache offloading

* llama : update session save/load

* llama : support quantum K cache (ggerganov#4312)

* llama : support quantum K cache (wip)

* metal : add F32 -> Q8_0 copy kernel

* cuda : add F32 -> Q8_0 copy kernel

ggml-ci

* cuda : use mmv kernel for quantum cache ops

* llama : pass KV cache type through API

* llama : fix build

ggml-ci

* metal : add F32 -> Q4_0 copy kernel

* metal : add F32 -> Q4_1 copy kernel

* cuda : wip

* cuda : add F32 -> Q4_0 and F32 -> Q4_1 copy kernels

* llama-bench : support type_k/type_v

* metal : use mm kernel only for quantum KV cache

* cuda : add comment

* llama : remove memory_f16 and kv_f16 flags

---------

Co-authored-by: slaren <[email protected]>

* readme : add API change notice

---------

Co-authored-by: slaren <[email protected]>

sync : ggml (new ops, tests, backend, etc.) (ggerganov#4359)

* sync : ggml (part 1)

* sync : ggml (part 2, CUDA)

* sync : ggml (part 3, Metal)

* ggml : build fixes

ggml-ci

* cuda : restore lost changes

* cuda : restore lost changes (StableLM rope)

* cmake : enable separable compilation for CUDA

ggml-ci

* ggml-cuda : remove device side dequantize

* Revert "cmake : enable separable compilation for CUDA"

This reverts commit 09e35d0.

* cuda : remove assert for rope

* tests : add test-backend-ops

* ggml : fix bug in ggml_concat

* ggml : restore `ggml_get_n_tasks()` logic in `ggml_graph_plan()`

* ci : try to fix macOS

* ggml-backend : remove backend self-registration

* ci : disable Metal for macOS cmake build

ggml-ci

* metal : fix "supports family" call

* metal : fix assert

* metal : print resource path

ggml-ci

---------

Co-authored-by: slaren <[email protected]>

grammar : revert the replacement of llama_token_to_piece with id_to_token (ggerganov#4396)

Update README.md (ggerganov#4388)

Fix small typo.

ggml : increased GGML_MAX_PARAMS to allow finetuning of 70b models (ggerganov#4424)

server : fix local model name in server (ggerganov#4420)

llama : document logits_all deprecation (ggerganov#4418)

llama_context_params.logits_all is a parameter for controlling
llama_eval. This documents that logits_all should not be used with
llama_decode and llama_batch.

build : target Windows 8 for standard mingw-w64 (ggerganov#4405)

* build : target Windows 8 for standard mingw-w64

* make : fix missing console.o deps

This was causing a link error with `make all` on Windows.

english : use `typos` to fix comments and logs (ggerganov#4354)

server : tweak default sampling parameters (ggerganov#4367)

* Set a more typical Top P setting as the default

* Update temp max

llama : add Mixtral support (ggerganov#4406)

* convert : support Mixtral as LLAMA arch

* convert : fix n_ff typo

* llama : model loading

* ggml : sync latest ggml_mul_mat_id

* llama : update graph to support MoE

* llama : fix cur -> cur_expert

* llama : first working version

* llama : fix expert weighting in the FFN

* ggml : ggml_get_rows support 2D indexing [n_tokens, n_experts] (cpu only)

* ggml : add n_as argument to ggml_mul_mat_id

* ggml : fix ggml_get_rows to take into account ne02 / ne11

* metal : add more general support for ggml_get_rows + tests

* llama : add basic support for offloading moe with CUDA

* metal : add/mul/div use general kernel when src1 not cont

* metal : reduce the kernel launches for ggml_mul_mat_id

* ggml : get_rows : support non-contiguos tensors with gaps, generalize up to 3D

* ggml : update get_rows f16 and q

* cuda : support non-contiguous src1 in get_rows

* llama : offload missing ffn_moe_silu

* metal : fix ggml_get_rows to work with non-cont src1

* metal : add indirect mat-vec kernels for all quantization types

* llama : do not quantize expert gating tensors

* llama : add n_expert and n_expert_used to hparams + change quants

* test-backend-ops : add moe test

* cuda : fix get_rows when ncols is odd

* convert : determine n_ctx correctly

* metal : fix ggml_mul_mat_id for F32

* test-backend-ops : make experts more evenly probable (test_moe)

* test-backend-ops : cleanup, add moe test for batches

* test-backend-ops : add cpy from f32 -> all types test

* test-backend-ops : fix dequantize block offset

* llama : fix hard-coded number of experts

* test-backend-ops : simplify and disable slow tests to avoid CI timeout

* test-backend-ops : disable MOE test with thread sanitizer

* cuda : fix mul_mat_id with multi gpu

* convert : use 1e6 rope_freq_base for mixtral

* convert : fix style

* convert : support safetensors format

* gguf-py : bump version

* metal : add cpy f16 -> f32 kernel

* metal : fix binary ops for ne10 % 4 != 0

* test-backend-ops : add one more sum_rows test

* ggml : do not use BLAS with ggml_mul_mat_id

* convert-hf : support for mixtral-instruct (ggerganov#4428)

* convert : typo fix, add additional hyperparameters, use LLaMA arch for Mixtral-instruct

* convert : use sentencepiece tokenizer for Mixtral-instruct

* convert : make flake8 happy

* metal : fix soft_max kernels

ref: ggerganov/ggml@1914017

* metal : limit kernels to not use more than the allowed threads

---------

Co-authored-by: Georgi Gerganov <[email protected]>
Co-authored-by: Radek Pilar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
script Script related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CausalLM: Llama + vocab.json BPE tokenizer = error loading model: cannot find tokenizer merges in model file
8 participants