]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/log
pkg/ggml/sources/llama.cpp
22 months agomake : fix clang tests build, add missing examples (#2859)
Cebtenzzre [Tue, 29 Aug 2023 08:42:41 +0000 (04:42 -0400)]
make : fix clang tests build, add missing examples (#2859)

* make : do not pass headers to the compiler

This fixes building tests with clang.

* make : add missing examples

* make : fix build-info.h dependencies

22 months agometal : add option to disable debug logs (close #2764)
Georgi Gerganov [Tue, 29 Aug 2023 08:33:46 +0000 (11:33 +0300)]
metal : add option to disable debug logs (close #2764)

22 months agoscripts : add pipefail
Georgi Gerganov [Tue, 29 Aug 2023 07:50:30 +0000 (10:50 +0300)]
scripts : add pipefail

22 months agoadded `struct` to llama_dump_timing_info_yaml's `llama_context` (#2857)
Marcus Dunn [Tue, 29 Aug 2023 06:33:27 +0000 (23:33 -0700)]
added `struct` to llama_dump_timing_info_yaml's `llama_context` (#2857)

fixes C compat.

22 months agotrain : mem usage and other improvements (#2439)
xaedes [Mon, 28 Aug 2023 19:51:47 +0000 (21:51 +0200)]
train : mem usage and other improvements  (#2439)

* fix track_max_mem in forward_batch_wo_cache_flash_attn_train

* remove unnecessary Adam(W) optimizer tensors.

reduces optimizer memory overhead from 7*modelsize to 2*modelsize.

additionally allows to optimize models with more than 2^31 parameters by replacing int with int64_t.

bumps training checkpoint file version, but old checkpoints can still be read.
new version with less tensors is saved.

* add gradient clipping to AdamW

* Fix reset of unused g->nodes and g->grads to NULL

* implement gradient checkpointing for training

reduces memory overhead from O(n_layer) to O(sqrt(n_layer))

as explained in readme of https://github.com/cybertronai/gradient-checkpointing

* remove unused compute buffer 3

* add and use function ggml_build_backward_expand to avoid stack overflows with large maximum number of nodes

GGML_API void ggml_build_backward_expand(struct ggml_context * ctx, struct ggml_cgraph * gf, struct ggml_cgraph * gb, bool keep);

* change AdamW decay parameter to work like the torch AdamW decay parameter

It is now relative to Adam learning rate `alpha*sched`.
Before that it was relative to `sched` only.

`alpha` being the maximum learning rate and `sched` being a scaling parameter in [0..1]

* change default AdamW weight decay parameter used in training to 0.1 as used in nanoGPT

* change default AdamW weight decay parameter defined in ggml to 0.0, making Adam default instead of AdamW

btw: the default weight decay parameter for torch.optim.AdamW is 0.01

* bug fixes for cross entropy loss

ggml_cross_entropy_loss: sums where not correctly added in workload of each thread
ggml_cross_entropy_loss_back: simplify backward process, reducing numerical issues

guard usage of exp f16 lookup in cross entropy by #define GGML_CROSS_ENTROPY_EXP_FP16

cross entropy loss is only used once during training, but it is quite sensitive to numerical errors introduced by exp-f16-lookup.
so exp-f16-lookup for cross entropy loss is disabled by default, trading better gradients for very slightly worse runtime performance.

* fix test-grad0 for cross_entropy_loss

the second argument to cross_entropy_loss must sum up to 1 for each row

* fix test-grad0 for soft_max

dont use only sum as aggregation, because sum of softmax is always 1 -> finite differences should not work
instead use sum(log(soft_max()*(1-eps)+eps)); use eps to avoid log(0)

* improve finite differences of test-grad0 by using double instead of float

* change cross_entropy_loss to output average over all rows

this helps keeping the loss and gradients in a sane range

* improve gradient checkpointing

sqrt(n_layers) is only the best checkpoint step when mem size of checkpoints and mem size of layers are equal.
since layers require more memory than the single-tensor-checkpoint we use, the optimal values are compute different:

```
  given: n, u, v
  objective: minimize(a*u+b*v) where a*b=n, a>0, b>0
  b=n/a
  minimize(a*u+v*n/a)
  diff(a*u+v*n/a, a) = u - (v*n/a)/a
  diff(a*u+v*n/a, a) == 0
  u - (v*n/a)/a == 0
  u == v*n/(a*a)
  u*a*a = v*n
  a*a = v*n/u
  a = sqrt(n*v/u)
```

this change results in more checkpoints, requiring less layers to store between checkpoints, overall improving memory usage.

* disable gradient checkpointing debug output

* llama : fix rope usage in train-text-from-scratch after ChatGLM change

* add more training parameters:

--enable-restart N         Only for Adam optimizer. Enable restarts of cos-decay
--disable-restart N        Only for Adam optimizer. Disable restarts of cos-decay
--opt-past N               Number of optimization iterations to track for delta convergence test. Disabled when zero.
--opt-delta N              Maximum delta for delta convergence test. Disabled when <= zero.
--opt-max-no-improvement N Maximum number of optimization iterations with no improvement. Disabled when <= zero.
--adam-epsf N              AdamW epsilon for convergence test. Disabled when <= zero.
--adam-min-alpha N         Adam minimum learning rate alpha, usually 0.1 * alpha

* replace memcpy with reshape operation so that the graph is not cut at the input

this makes it possible to store other values into the input tensor and then simply recompute the graph without rebuilding it

* remove unused function argument from get_example_targets_batch

* measure and print total training time

* add optimization callback to ggml_opt_resume_g

this callback is called before each iteration with custom data and pointer to learning schedule parameter (only used in Adam(W)).

can be used for dynamic learning schedule and setting input data for batches before each iteration

* use optimization callback in training

allows dynamic learning schedule and different batch data for each iteration without relying on low n_iter and high n_examples parameters

reduces runtime by avoiding restart of optimization function and improves training convergence by providing a different batch for each iteration

* add minimum number of tensor dimensions to apply weight decay (default 2)

this allows to not apply weight decay to bias parameters

* rename training parameter cos-decay-alpha to cos-decay-min and clarify that adam-min-alpha also applies to warmup

* fix increase of model.train_samples and model.train_tokens

now that each optimizer iteration gets its own batch we need to multiply by number of opt iterations

* change sampling parameters for prediction after training to defaults of common.h

and clarify what is context for prediction and what are generated tokens

* tighten abs error bounds for cross_entropy_loss in test-grad0

* add conditional compilation of using F16 exp in flash attention

uncomment `// #define GGML_FLASH_ATTN_EXP_FP16` to enable usage of f16 exp in flash attention

* tighten abs error bounds for flash_attn in test-grad0

* tighten abs error bounds for sqrt in test-grad0

* remove out-commented vectorized code of opt_adam

the vectorized code might be bit faster for low number of parameters, but it had a big memory usage overhead

* ggml : update ggml_rms_norm_back with configurable eps

* llama training : fix ggml_rms_norm_back calls to pass configurable eps

* remove trailing whitespace

* add train function using automatic gradient checkpointing backward pass and allocator

* in train function replace add_inplace by regular add

because using add_inplace seems to result in different gradients

* don't use allocate hash_map on context

because the context has no_alloc=True when using memory allocator resulting in NULL data pointers

* correctly clone reshape and permute operations by also cloning tensor->nb values

* fix variable name and add missing type cast

* terminate recursive tensor cloning when reaching tensor without src tensors

* correctly clone view tensors by setting data pointers

without this the checkpointing would only work when being used together with memory allocator

* fix variable names

* swap arguments to commutative ops to be the same as in `forward_batch_wo_cache_flash_attn`

* add input tensors as checkpoints

so that recursive tensor cloning of gradient checkpointing terminates on input tensors

* fix variable name and add missing boolean negation

* make sure some tensors are not reallocated by inserting new temporary nodes depending on them:

output and parameter gradient tensors need to be available at the end of the graph execution

parameter gradient tensors also need to be available before the graph execution because they are set to zero before each optimizer iteration

checkpoint tensors are allocated all together to reduce memory allocator fragmentation

afterwards, in addition to the temporary nodes, we also need to reset the temporary leafs

* fix ASSERT to work with zero layers

* add training options whether to use allocator and/or unified training function

* integrate unified training function which may use memory allocator

the unified training function also supports arguments whether to use flash attention and/or gradient checkpointing

* format name of cloned tensors with " (clone)" suffix

* set names for tensors in unified train function for easier debugging

* allocate graph on context using ggml_new_graph

* remove handwritten training functions

* remove unused training parameters "use_scratch" and "use_unified"

* remove trailing whitespace

* remove unused train params: mem_compute1_gb & mem_compute2_gb

mem_compute_gb is used for compute when automatic memory allocator is not enabled, otherwise it can be very small to only hold the tensor definitions
mem_compute0_gb is used for automatic memory allocator (as long as measurement of max required size is not implemented)

* remove unused forward_batch function

* add debug asserts in ggml_allocr_alloc to some common pitfalls when using this function directly

* only use ggml_allocr_alloc when tensor has NULL data and is no view

* fix test when to create temporary backward graph

temporary backward graph is only necessary when using checkpointing

* fix memory "leak" in optimizers

each iteration a new cplan with new memory for work data was allocated.
now cplan creation only happens at the start of optimization, with each iteration reusing the cplan and its work data.

* reverse order of for loop in ggml_build_backward_expand to save memory when using gradient checkpointing and allocator

with this loop order gradient checkpointing with allocator on 16 layer model saves 13% memory; 2 layer memory it saves 2% memory.

the computation results are the same

* add missing lctx argument to get_example_targets_batch

* implement llama model file saving using gguf

checkpoint loading and saving disabled, to be replaced by loading and saving via gguf

* implement loading/saving of checkpointing files using GGUF

* bug fixes

* add checkpoint file version for future compatibility

* update readme with gguf filenames

* save & load opt->just_initialized value

* add first draft for checkpoint conversion script

* add gguf arch and ftype

* save opt parameter counter as uint64

* add gguf key and tensor names for optimizer and training

* add layer_norm_rms_eps to checkpoint convert script

* use same GGUF_GET_KEY macro as in llama.cpp

* use norm_rms_eps, and rope parameters and command line options to set them

* fix memory corruption bug in gguf

ctx->kv and ctx->infos was reallocated using not-aligned realloc, but freed with aligned free.
to fix this a GGML_ALIGNED_REALLOC was added, but there is no posix_memalign_realloc function.
so on non-windows and non-mingw32 platforms we fall back to aligned malloc, followed by copying
and freeing the old data.

* add gguf example cmake file

* bug fixes in tokenize_file

* bug fixes in load_llama_model_gguf

* bug fix: init model when no checkpoint was loaded

* bug fix in read_tensor_by_name

* bug fix in load_opt_context_gguf

* avoid printing lots of spaced on the unusual case that loss gets nan

* set name of tensors with empty name from what was read from gguf

* remove trailing whitespace

* print data checksums before saving and after loading to verify correctness

* bug fixes for convert-train-checkpoint-to-gguf

* temporarily add code to write old checkpoint files

used to verify that old checkpoint files are correctly converted to gguf

* bug fixes for convert-train-checkpoint-to-gguf.py loading checkpoints with opt_version=0

* remove code used to verify correctness of checkpoint file conversion

* remove trailing whitespace

* remove prediction related code

use main for prediction, it is better optimized

* update train-text-from-scratch README.md

* fix non-windows GGML_ALIGNED_REALLOC

* add missing blank line at end of file

* remove GGML_ALIGNED_REALLOC and use normal malloc/realloc/free for gguf ctx->kv & ctx->infos

* train : fix compile warnings

---------

Co-authored-by: Georgi Gerganov <redacted>
22 months agollama-bench : set locale to utf8 (#2832)
slaren [Mon, 28 Aug 2023 17:19:18 +0000 (19:19 +0200)]
llama-bench : set locale to utf8 (#2832)

22 months agoYAML result logging + preset script (#2657)
Johannes Gäßler [Mon, 28 Aug 2023 15:59:39 +0000 (17:59 +0200)]
YAML result logging + preset script (#2657)

22 months agomake : fix tests build (#2855)
alonfaraj [Mon, 28 Aug 2023 15:38:35 +0000 (18:38 +0300)]
make : fix tests build (#2855)

* makefile:
- fix test name
- add missing tests build

* editorconfig : fixes

---------

Co-authored-by: Georgi Gerganov <redacted>
22 months agollama.cpp : fix wrong vsnprintf call in MS compiler (#2856)
grahameth [Mon, 28 Aug 2023 15:38:12 +0000 (17:38 +0200)]
llama.cpp : fix wrong vsnprintf call in MS compiler (#2856)

Co-authored-by: grahameth <->
22 months agoggml : tiny ggml_vec_dot_q4_K_q8_K AVX2 improvement (#2819)
Ronny Brendel [Mon, 28 Aug 2023 12:51:08 +0000 (14:51 +0200)]
ggml : tiny ggml_vec_dot_q4_K_q8_K AVX2 improvement (#2819)

22 months agoggml : sync (mem align to header + conv_transpose_2d fixes + ggml_alloc) (#2852)
Georgi Gerganov [Mon, 28 Aug 2023 11:24:53 +0000 (14:24 +0300)]
ggml : sync (mem align to header + conv_transpose_2d fixes + ggml_alloc) (#2852)

* ggml : sync (mem align to header + conv_transpose_2d fixes)

ggml-ci

* ggml-alloc : minor fix

* ggml-alloc : sync more fixes

22 months agoCUDA: fix RoPE asserts, block sizes (#2833)
Johannes Gäßler [Mon, 28 Aug 2023 11:23:55 +0000 (13:23 +0200)]
CUDA: fix RoPE asserts, block sizes (#2833)

22 months agollama.h : add missing struct keyword for C compat in callback type (#2847)
igarnier [Mon, 28 Aug 2023 08:19:59 +0000 (10:19 +0200)]
llama.h : add missing struct keyword for C compat in callback type (#2847)

22 months agometal : fix memory leak (#2762)
Georgi Gerganov [Mon, 28 Aug 2023 07:59:08 +0000 (10:59 +0300)]
metal : fix memory leak (#2762)

* metal : fix memory leak

* metal : fix encoders memory leak

* metal : clean up more memory resources

* metal : fix more leaks

* metal : reuse dispatch queue + autoreleasepool

* metal : reuse array for command buffers and encoders

* ggml : assert for odd number of blocks on ARM

15M tinyllama is an example

22 months agoquantize : make output filename optional again (#2823)
Cebtenzzre [Mon, 28 Aug 2023 06:32:25 +0000 (02:32 -0400)]
quantize : make output filename optional again (#2823)

* quantize : make output filename optional again

* quantize : fix path parsing on Windows

suggested by @slaren

22 months agodevops : added systemd units and set versioning to use date. (#2835)
JohnnyB [Mon, 28 Aug 2023 06:31:24 +0000 (07:31 +0100)]
devops : added systemd units and set versioning to use date. (#2835)

* Corrections and systemd units

* Missing dependency clblast

22 months agogguf : fix strings to not be null-terminated (#2839)
Georgi Gerganov [Sun, 27 Aug 2023 18:50:22 +0000 (21:50 +0300)]
gguf : fix strings to not be null-terminated (#2839)

* gguf : fix strings to not be null-terminated

ggml-ci

* gguf : fix gguf_add_tensor name

22 months agollama : fix MPI threads (close #2827)
Georgi Gerganov [Sun, 27 Aug 2023 15:55:41 +0000 (18:55 +0300)]
llama : fix MPI threads (close #2827)

22 months agoexamples : update llama2.c converter to read vocab and write models in GGUF format...
Olivier Chafik [Sun, 27 Aug 2023 14:13:31 +0000 (15:13 +0100)]
examples : update llama2.c converter to read vocab and write models in GGUF format (#2751)

* llama2.c: direct gguf output (WIP)

* Simplify vector building logic

* llama2.c gguf conversion: fix token types in converter

* llama2.c: support copying vocab from a llama gguf model file

* llama2.c: update default path for vocab model + readme

* llama2.c: use defines for gguf keys

* llama2.c: escape whitespaces w/ U+2581 in vocab converter the llama.cpp way

* llama2.c converter: cleanups + take n_ff from config

22 months agollama : speedup tokenization (#2831)
Kawrakow [Sun, 27 Aug 2023 13:50:33 +0000 (16:50 +0300)]
llama : speedup tokenization (#2831)

* Speedup tokenization

On current master it takes ~3.2 seconds to tokenize
Wikitext. With this change it becomes ~525 ms.

* Fixit: it was missing the piece after the last found occurence

---------

Co-authored-by: Iwan Kawrakow <redacted>
22 months agofalcon : fix CUDA inference by making K and Q contiguous (#2830)
Georgi Gerganov [Sun, 27 Aug 2023 13:40:48 +0000 (16:40 +0300)]
falcon : fix CUDA inference by making K and Q contiguous (#2830)

* falcon : fix CUDA inference by making K and Q contiguous

ggml-ci

* cuda : add assert to guard from non-cont ropes

22 months agoreadme : fix headings
Georgi Gerganov [Sun, 27 Aug 2023 12:52:34 +0000 (15:52 +0300)]
readme : fix headings

22 months agoscripts : helper convert script
Georgi Gerganov [Sun, 27 Aug 2023 12:24:40 +0000 (15:24 +0300)]
scripts : helper convert script

22 months agok_quants tuning for Falcon-7b (#2816)
Kawrakow [Sun, 27 Aug 2023 12:19:59 +0000 (15:19 +0300)]
k_quants tuning for Falcon-7b (#2816)

* Make ggml-cuda.cu build with QK_K = 64

Using LLAMA_CUDA_FORCE_DMMV = ON and -nommq it runs and produces
a meaningful result.

* k_quants tuning for Falcon-7b

---------

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoreadme : update hot topics
Georgi Gerganov [Sun, 27 Aug 2023 11:44:35 +0000 (14:44 +0300)]
readme : update hot topics

22 months agogguf : add 64-bit support (GGUF v2) (#2821)
Georgi Gerganov [Sun, 27 Aug 2023 11:19:54 +0000 (14:19 +0300)]
gguf : add 64-bit support (GGUF v2) (#2821)

* gguf : bump version to 2

* gguf : add support for 64-bit (no backwards comp yet)

* gguf : v1 backwards comp

* gguf.py : bump GGUF version

* gguf.py : uint64_t on all lengths, sizes and counts, enums still uint32_t

* gguf.py : string lengths uint32_t

* gguf : update all counts to 64-bit

* gguf.py : string len uint64_t and n_dims uint32_t

* gguf : fix typo

* llama.cpp : print gguf version

---------

Co-authored-by: klosax <redacted>
22 months agollama : more tokenizer fixes (#2810)
Georgi Gerganov [Sun, 27 Aug 2023 11:19:19 +0000 (14:19 +0300)]
llama : more tokenizer fixes (#2810)

* tests : write a Python tokenizer test (wip)

* llama : prefix input text for tokenization with whitespace

* llama : distinguish pieces from decoded text + fix detokenization

* common : add comments

* examples : no longer manually add leading space when tokenizing

* tests : use Python to generate tokenizer tests for C++

* tests : add option to tokenize text files

ggml-ci

* tests : add test-tokenizer-1.py

* llama.cpp : fix LF token

* hellaswag : move the concat space for clarity

* tests : add falcon tests (py + cpp, currently do not pass Unicode)

ggml-ci

* common : temporary separate llama_detokenize calls for SPM and BPE

---------

Co-authored-by: klosax <redacted>
22 months agoggml : detect SSSE3 (#2825)
Przemysław Pawełczyk [Sun, 27 Aug 2023 08:10:25 +0000 (10:10 +0200)]
ggml : detect SSSE3 (#2825)

* ggml : add ggml_cpu_has_ssse3

* llama : show SSSE3 in system info

22 months agoci : add LoRA test to CI (#2650)
slaren [Sun, 27 Aug 2023 07:03:27 +0000 (09:03 +0200)]
ci : add LoRA test to CI (#2650)

* ci : add lora test

ggml-ci

* move lora summary to the top, add lora logs

ggml-ci

* ci : decrease CPU ppl runs to 2 to avoide 20 min timeout

ggml-ci

* add 7b lora test

use 1 thread for CUDA generation tests

ggml-ci

* add test with q8_0 (cpu only)

ggml-ci

---------

Co-authored-by: Georgi Gerganov <redacted>
22 months agoserver : add `/detokenize` endpoint (#2802)
Bruce MacDonald [Sat, 26 Aug 2023 23:11:45 +0000 (16:11 -0700)]
server : add `/detokenize` endpoint (#2802)

* Add a /detokenize endpoint to the example server

* remove trailing white-space

22 months agoconvert.py : advanced option (#2753)
Kerfuffle [Sat, 26 Aug 2023 20:13:36 +0000 (14:13 -0600)]
convert.py : advanced option (#2753)

* Allow convert.py to convert to q8_0

Fix issue with bounded_parallel_map and greedy consuming iterator

Display elapsed time during conversion

* Add --concurrency option

Minor improvements to help text

Clean up bounded_parallel_map function a bit

* Massive speed improvement thanks to Cebtenzzre

* Refactor types

22 months agollama : use Unicode Escape Sequence to replace encoded characters (#2814)
Tim Miller [Sat, 26 Aug 2023 18:27:07 +0000 (03:27 +0900)]
llama : use Unicode Escape Sequence to replace encoded characters (#2814)

The use of special characters within source files can break compiling on some computers with different region and language settings. Using Unicode escape sequences should allow for the code to be compiled on all setups without needing to change your computers settings or switch regions.

22 months agoflake.nix : add rocm support and cleanup (#2808)
Tungsten842 [Sat, 26 Aug 2023 18:19:44 +0000 (20:19 +0200)]
flake.nix : add rocm support and cleanup (#2808)

22 months agollama : move #includes out of _GNU_SOURCE conditional (#2817)
Cebtenzzre [Sat, 26 Aug 2023 18:17:51 +0000 (14:17 -0400)]
llama : move #includes out of _GNU_SOURCE conditional (#2817)

22 months agomain : fix bug (penalize_nl=false doesn't work) + suppress warning on mingw (#1528)
Dr. Tom Murphy VII Ph.D [Sat, 26 Aug 2023 18:12:56 +0000 (14:12 -0400)]
main : fix bug (penalize_nl=false doesn't work) + suppress warning on mingw (#1528)

* Fix bug in main.cpp where penalize_nl=false has no effect. It modifies the underlying logits array, but at this point we are already working on the candidates copy.

* Suppress redefinition warning for NOMINMAX on mingw. In my installation, this macro is already defined by /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/os_defines.h:45.

* main : fix indentation

* main : pass ctx to llama_token_nl()

---------

Co-authored-by: Georgi Gerganov <redacted>
22 months agollama : use std::abs in llama_sample_tail_free (#2800)
Cebtenzzre [Sat, 26 Aug 2023 16:53:52 +0000 (12:53 -0400)]
llama : use std::abs in llama_sample_tail_free (#2800)

Plain 'abs' casts the input to int.

22 months agok-quants : remove unnecessary tensor shape restrictions (#2811)
Georgi Gerganov [Sat, 26 Aug 2023 14:37:35 +0000 (17:37 +0300)]
k-quants : remove unnecessary tensor shape restrictions (#2811)

22 months agoBetter perplexity for 2- and 3-bit quantization for LLaMA-v2-70B (#2807)
Kawrakow [Sat, 26 Aug 2023 14:27:49 +0000 (17:27 +0300)]
Better perplexity for 2- and 3-bit quantization for LLaMA-v2-70B (#2807)

* Better perplexity for 2- and 3-bit quantization for the 70B model

* PR comment

---------

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoFix HellaSwag (#2805)
Kawrakow [Sat, 26 Aug 2023 13:48:53 +0000 (16:48 +0300)]
Fix HellaSwag (#2805)

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoflake : build llama.cpp on Intel with nix (#2795)
Volodymyr Vitvitskyi [Sat, 26 Aug 2023 13:25:39 +0000 (14:25 +0100)]
flake : build llama.cpp on Intel with nix (#2795)

Problem
-------
`nix build` fails with missing `Accelerate.h`.

Changes
-------
- Fix build of the llama.cpp with nix for Intel: add the same SDK frameworks as
for ARM
- Add `quantize` app to the output of nix flake
- Extend nix devShell with llama-python so we can use convertScript

Testing
-------
Testing the steps with nix:
1. `nix build`
Get the model and then
2. `nix develop` and then `python convert.py models/llama-2-7b.ggmlv3.q4_0.bin`
3. `nix run llama.cpp#quantize -- open_llama_7b/ggml-model-f16.gguf ./models/ggml-model-q4_0.bin 2`
4. `nix run llama.cpp#llama -- -m models/ggml-model-q4_0.bin -p "What is nix?" -n 400 --temp 0.8 -e -t 8`

Co-authored-by: Volodymyr Vitvitskyi <redacted>
22 months agoHandle null rope scaling value (#2793)
Nigel Bosch [Sat, 26 Aug 2023 12:11:17 +0000 (07:11 -0500)]
Handle null rope scaling value (#2793)

22 months agoFix spm whitespaces (#2806)
klosax [Sat, 26 Aug 2023 11:45:53 +0000 (13:45 +0200)]
Fix spm whitespaces (#2806)

* llama.cpp : fix spm whitespace escaping + clean up

* main.cpp : spm - add whitespace in front of prompt

* test-tokenizer-0.cpp : spm - add whitespace in front of prompt

22 months agoexamples : skip unnecessary external lib in server README.md how-to (#2804)
lon [Sat, 26 Aug 2023 08:07:43 +0000 (10:07 +0200)]
examples : skip unnecessary external lib in server README.md how-to (#2804)

22 months agollama : fix struct decl (#2790)
Marcus Dunn [Fri, 25 Aug 2023 16:17:15 +0000 (09:17 -0700)]
llama : fix struct decl (#2790)

22 months agoFaster perplexity computation (#2786)
Kawrakow [Fri, 25 Aug 2023 16:05:02 +0000 (19:05 +0300)]
Faster perplexity computation (#2786)

Co-authored-by: Iwan Kawrakow <redacted>
22 months agollama : add llama_beam_search() (#2267)
Matt Pulver [Fri, 25 Aug 2023 15:18:48 +0000 (11:18 -0400)]
llama : add llama_beam_search() (#2267)

* Add llama_beam_search().

* Add '// Beam search' heading to llama.{h,cpp} after llama_grammar_accept_token().

* Add space around * pointers and & references.

* Add spaces around comparison and assignment operators.

* Prefer west const.

* Use llama_ prefix for structs in global namespace.

* Delete obsolete comment from an earlier revision.

* Change eos to eob in llama_beam and llama_beam_view structs.

22 months agoconvert.py : Get rope scale from HuggingFace models (#2772)
Nigel Bosch [Fri, 25 Aug 2023 14:41:52 +0000 (09:41 -0500)]
convert.py : Get rope scale from HuggingFace models (#2772)

* Get rope scale from HF models

* Save rope scale only for linear scaling

* Rewrite for clarity

22 months agollama-bench : add model sizes (#2771)
slaren [Fri, 25 Aug 2023 13:16:19 +0000 (15:16 +0200)]
llama-bench : add model sizes (#2771)

* llama-bench : add model sizes

* more compact markdown output

* back to GiB

* adjust column sizes

22 months agoconvert.py : export rope freq_base when converting CodeLlama from an HF model (#2773)
slaren [Fri, 25 Aug 2023 12:08:53 +0000 (14:08 +0200)]
convert.py : export rope freq_base when converting CodeLlama from an HF model (#2773)

22 months agoserver : display token probabilities in the UI (#2489)
Jhen-Jie Hong [Fri, 25 Aug 2023 10:32:45 +0000 (18:32 +0800)]
server : display token probabilities in the UI (#2489)

* server : add n_probs param in chat UI

* server : keep message data array & show in probabilites component

* server : add simple popover component

* server : fix completion_probabilities undefined if not set n_probs

* server : implement Probabilites

* server : handle bytes

* server : make n_probs max to 10 for easy scroll

* server : adjust for dark/light mode

* server : Fix regenerated prompt

* server : update index.html.hpp

* server : convert prob to percentage + show original value as div title

* server : fix Probabilites not used if included empty str

* server : skip byte pair in display probabilites

* server : remove array check of completion_probabilities in messages

* skip empty array or byte pair (> 1) in Probabilites

* generate index.html.hpp

* fix incorrect prob convert if the str is already a known token

* use final response to show probabilities on stop

* revert unnecessary change

* correct probabilites usage

* remove unused function

* always send partial response for get correct probs of last to_send

* fix typo

* fix content of format_final_response

* refactor probs render & make pColor transparent if not found

* send empty string when got stop_pos in partial

* avoid unnecessary empty data event & send rest of partial tokens on stop

* use <br /> for new line

* skip -1 tok in loop to avoid send '' on end

* trim last new lines on stop

* revert unnecessary change

22 months agoci : pip install gguf in editable mode (#2782)
Georgi Gerganov [Fri, 25 Aug 2023 10:03:25 +0000 (13:03 +0300)]
ci : pip install gguf in editable mode (#2782)

ggml-ci

22 months agogguf : export objects to user code (#2780)
M. Yusuf Sarıgöz [Fri, 25 Aug 2023 09:43:41 +0000 (12:43 +0300)]
gguf : export objects to user code (#2780)

* gguf export more objects to user code

* gguf export all objects to user code for now

* gguf : bump version

22 months agoROCm Port (#1087)
Henri Vasserman [Fri, 25 Aug 2023 09:09:42 +0000 (12:09 +0300)]
ROCm Port (#1087)

* use hipblas based on cublas
* Update Makefile for the Cuda kernels
* Expand arch list and make it overrideable
* Fix multi GPU on multiple amd architectures with rocblas_initialize() (#5)
* add hipBLAS to README
* new build arg LLAMA_CUDA_MMQ_Y
* fix half2 decomposition
* Add intrinsics polyfills for AMD
* AMD assembly optimized __dp4a
* Allow overriding CC_TURING
* use "ROCm" instead of "CUDA"
* ignore all build dirs
* Add Dockerfiles
* fix llama-bench
* fix -nommq help for non CUDA/HIP

---------

Co-authored-by: YellowRoseCx <redacted>
Co-authored-by: ardfork <redacted>
Co-authored-by: funnbot <redacted>
Co-authored-by: Engininja2 <redacted>
Co-authored-by: Kerfuffle <redacted>
Co-authored-by: jammm <redacted>
Co-authored-by: jdecourval <redacted>
22 months agocuda : add RoPE kernel for mode == 2 (NeoX) (#2760)
Georgi Gerganov [Fri, 25 Aug 2023 08:55:59 +0000 (11:55 +0300)]
cuda : add RoPE kernel for mode == 2 (NeoX) (#2760)

* cuda : add RoPE kernel for mode == 2 (NeoX)

* falcon : do not offload the embeddings layer

22 months agogguf : make gguf pip-installable
M. Yusuf Sarıgöz [Fri, 25 Aug 2023 06:26:05 +0000 (09:26 +0300)]
gguf : make gguf pip-installable

* gitignore : add dist and rm pyproject.toml

* gguf: prepare as Pip package

* gguf: prepare as Pip package

* gguf : fix line endings

* requirements : add gguf

* gguf : update readme with build notes

* gguf : update readme with build notes

* gguf : add notes for tests

22 months agoggml-alloc : enlarge size of parse_seq (#2776)
Shouzheng Liu [Fri, 25 Aug 2023 05:58:00 +0000 (01:58 -0400)]
ggml-alloc : enlarge size of parse_seq (#2776)

Since we also store barriers in this array, we need to double its size.

22 months agoAdded `enum` to `llama_token_get_type` return type (#2774)
Marcus Dunn [Thu, 24 Aug 2023 21:49:30 +0000 (14:49 -0700)]
Added `enum` to `llama_token_get_type` return type (#2774)

22 months agoconvert.py : try to determine n_ctx automatically for CodeLlama (#2770)
slaren [Thu, 24 Aug 2023 19:10:39 +0000 (21:10 +0200)]
convert.py : try to determine n_ctx automatically for CodeLlama (#2770)

22 months agogguf : add rope_freq_base parameter for CodeLlama (#2769)
slaren [Thu, 24 Aug 2023 18:04:05 +0000 (20:04 +0200)]
gguf : add rope_freq_base parameter for CodeLlama (#2769)

22 months agofalcon : write file type
Georgi Gerganov [Thu, 24 Aug 2023 16:58:30 +0000 (19:58 +0300)]
falcon : write file type

22 months agometal : bug-fix when enable ggml-alloc (#2757)
Shouzheng Liu [Thu, 24 Aug 2023 16:27:25 +0000 (12:27 -0400)]
metal : bug-fix when enable ggml-alloc (#2757)

* metal: better memory alloc w/ concurrency dispatch

The ggml-alloc should only free tensors at memory barriers.

* ggml-alloc: avoid return silently

In certain cases, the allocate_node() function may silently return
without performing any memory allocation.

22 months agoconvert : auto-determine model name based on dir + scripts update
Georgi Gerganov [Thu, 24 Aug 2023 16:26:19 +0000 (19:26 +0300)]
convert : auto-determine model name based on dir + scripts update

22 months agoFix for main example getting stuck when -n -2 and --interactive (#2767)
Kerfuffle [Thu, 24 Aug 2023 16:11:13 +0000 (10:11 -0600)]
Fix for main example getting stuck when -n -2 and --interactive (#2767)

* Fix for main example getting stuck when -n -2 and --interactive

* Add a comment so future generations may suffer less.

22 months agofix convert.py for codellama, add llama 34B to the list of recognized models (#2768)
slaren [Thu, 24 Aug 2023 15:44:11 +0000 (17:44 +0200)]
fix convert.py for codellama, add llama 34B to the list of recognized models (#2768)

22 months agoTag release with build number (#2732)
DannyDaemonic [Thu, 24 Aug 2023 13:58:02 +0000 (06:58 -0700)]
Tag release with build number (#2732)

* Modified build.yml to use build number for release

* Add the short hash back into the tag

* Prefix the build number with b

22 months agometal : add Q8_0 support (#2763)
Georgi Gerganov [Thu, 24 Aug 2023 13:19:57 +0000 (16:19 +0300)]
metal : add Q8_0 support (#2763)

* metal : add dequantize_q8_0 kernel

* metal : add mul_mat_q8_0_f32 kernel

* metal : add Q8_0 mul_mm kernel

22 months agollama : escape all U+2581 in a string (#2750)
Georgi Gerganov [Thu, 24 Aug 2023 09:26:01 +0000 (12:26 +0300)]
llama : escape all U+2581 in a string (#2750)

22 months agollama : fix grammar sometimes generating null char (#2756)
Evan Jones [Thu, 24 Aug 2023 04:07:13 +0000 (00:07 -0400)]
llama : fix grammar sometimes generating null char (#2756)

22 months agoreadme : fix link
Georgi Gerganov [Wed, 23 Aug 2023 20:44:19 +0000 (23:44 +0300)]
readme : fix link

22 months agominor : fix trailing whitespace
Georgi Gerganov [Wed, 23 Aug 2023 20:43:00 +0000 (23:43 +0300)]
minor : fix trailing whitespace

22 months agoreadme : update hot topics
Georgi Gerganov [Wed, 23 Aug 2023 20:41:16 +0000 (23:41 +0300)]
readme : update hot topics

22 months agollm : add Falcon support (#2717)
Georgi Gerganov [Wed, 23 Aug 2023 20:08:04 +0000 (23:08 +0300)]
llm : add Falcon support (#2717)

* llama : refactor GGUF constants into static maps

* llama : check if model architecture is known

* llama : refactor llama_model_load_internal()

* gguf : add KV constant maps

* llm : read arch-specific KVs

* convert : add dummy scores + types

* falcon : load tensor data (CPU only)

* llama : fix loading progress bar

* llama : add arch member to llama_model

* falcon : CPU inference working

* falcon : support non-40B models

* falcon : minor

* llama : minor updates

ggml-ci

* convert-falcon-hf-to-gguf.py : fix special token mapping

* llama.cpp : llama default UNK token = id 0

* llama.cpp : fix bpe tokenizer

* llama.cpp : fix the fix of bpe tokenizer

* ggml : pass eps to ggml_norm

* metal : implement RoPE (mode = 2) + avoid ggml_repeat

* ggml : ggml_repeat always creates new tensor

* falcon : copy-paste self-attention from LLaMA

* metal : print extra compute pipeline info

* falcon : minor changes (still chasing the Metal problem)

* llama.cpp : fix linefeed token

* metal : fix GELU kernel numerical stability by using precise::tanh

* metal : temporary workaround for the concurrency optimization bug

* falcon : add CUDA offloading (#2739)

* llama : better model naming and size reporting

* llama : prep new tokenizer support

* llama : advanced BPE tokenizer based on ggllm.cpp imlpementation

* llama : remove oboslete comment

ggml-ci

* common : remove obsolete BPE API + disable test-tokenizer-1

* llama : revert BPE special-case in llama_byte_to_token()

* cuda : add TODOs for RoPE NeoX implementation

* llama : default special tokens based on vocab type

* perplexity : add log for start of tokenization

---------

Co-authored-by: klosax <redacted>
Co-authored-by: slaren <redacted>
22 months agominor : fix trailing whitespace
Georgi Gerganov [Wed, 23 Aug 2023 19:37:39 +0000 (22:37 +0300)]
minor : fix trailing whitespace

22 months agoexamples : restore the functionality to import llama2.c models (#2685)
Olivier Chafik [Wed, 23 Aug 2023 19:33:05 +0000 (20:33 +0100)]
examples : restore the functionality to import llama2.c models (#2685)

* Fix import of llama2.c models that don't share weights between embedding layers

* llama2c: reinstate ggmlv3 conversion output + update readme w/ gguf conv

* llama2.c: comment out legacy "load from ggml model" logic

* llama2.c: convert special-cased "<0xXX>" single byte tokens from tokenizer.bin

22 months agofix convert-lora-to-ggml.py (#2738)
slaren [Wed, 23 Aug 2023 14:46:54 +0000 (16:46 +0200)]
fix convert-lora-to-ggml.py (#2738)

22 months agomain : insert bos if no tokens (#2727)
klosax [Wed, 23 Aug 2023 14:46:03 +0000 (16:46 +0200)]
main : insert bos if no tokens (#2727)

* main.cpp : insert bos if no tokens

* Update examples/main/main.cpp

* Update examples/main/main.cpp

---------

Co-authored-by: Georgi Gerganov <redacted>
22 months agogitignore : fix for windows (#2729)
akawrykow [Wed, 23 Aug 2023 14:31:34 +0000 (07:31 -0700)]
gitignore : fix for windows (#2729)

22 months agochmod : make scripts executable (#2675)
Cebtenzzre [Wed, 23 Aug 2023 14:29:09 +0000 (10:29 -0400)]
chmod : make scripts executable (#2675)

22 months agodevops : RPM Specs (#2723)
JohnnyB [Wed, 23 Aug 2023 14:28:22 +0000 (15:28 +0100)]
devops : RPM Specs (#2723)

* Create llama-cpp.srpm

* Rename llama-cpp.srpm to llama-cpp.srpm.spec

Correcting extension.

* Tested spec success.

* Update llama-cpp.srpm.spec

* Create lamma-cpp-cublas.srpm.spec

* Create lamma-cpp-clblast.srpm.spec

* Update lamma-cpp-cublas.srpm.spec

Added BuildRequires

* Moved to devops dir

22 months agoFix values shown in the quantize tool help (#2735)
Kawrakow [Wed, 23 Aug 2023 09:57:12 +0000 (12:57 +0300)]
Fix values shown in the quantize tool help (#2735)

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoStrided perplexity (#2714)
Kawrakow [Wed, 23 Aug 2023 09:56:42 +0000 (12:56 +0300)]
Strided perplexity (#2714)

* Implementing strided computation of perplexity

* Alternative way to output PPL results

---------

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoFix ggml to gguf conversion on Windows (#2733)
IgnacioFDM [Wed, 23 Aug 2023 09:31:09 +0000 (06:31 -0300)]
Fix ggml to gguf conversion on Windows (#2733)

This fixes `RuntimeWarning: overflow encountered in long_scalars`

Credit: anon (not mine)

22 months agoserver : allow json array in prompt or content for direct token input (#2306)
Xiao-Yong Jin [Wed, 23 Aug 2023 07:12:12 +0000 (02:12 -0500)]
server : allow json array in prompt or content for direct token input (#2306)

* server: allow json array in prompt or content

We accept an array of strings and numbers representing tokens,
in addition to the current string valued prompt or content.

This allows direct token input, so that any special tokens
can be processed and used at the frontend during the construction
of the json data, before sending to the server. And the server
does not need to know or parse special tokens from textual input.

With this, we can use EOS and BOS used in llama-2-chat models.

* server: use tokenizePrompt(json) and default "" if empty prompt

* server: fix prompt check

* server: tokenize endpoint no longer adds BOS

22 months agodocs : add grammar docs (#2701)
Evan Jones [Wed, 23 Aug 2023 01:01:57 +0000 (21:01 -0400)]
docs : add grammar docs (#2701)

* docs : add grammar docs

* tweaks to grammar guide

* rework GBNF example to be a commented grammar

22 months agoImprove handling of special tokens in GGML to GGUF converter (#2725)
Kerfuffle [Tue, 22 Aug 2023 23:39:39 +0000 (17:39 -0600)]
Improve handling of special tokens in GGML to GGUF converter (#2725)

* Improve UNK, BOS, EOS token handling when converting without metadata.

* Allow importing as a module.

* Remove some obsolete code and minor cleanups.

* Set default UNK token mapping from -1 to 0 in llama.cpp

* Try to handle overflow due to buggy Windows Python with a better error message

22 months agollama : fix whitespace escaping in tokenizer (#2724)
goerch [Tue, 22 Aug 2023 21:10:42 +0000 (23:10 +0200)]
llama : fix whitespace escaping in tokenizer (#2724)

22 months agoCUDA: use mul_mat_q kernels by default (#2683)
Johannes Gäßler [Tue, 22 Aug 2023 20:47:05 +0000 (22:47 +0200)]
CUDA: use mul_mat_q kernels by default (#2683)

22 months agoconvert.py : clarifying error message (#2718)
Alex Petenchea [Tue, 22 Aug 2023 18:58:16 +0000 (21:58 +0300)]
convert.py : clarifying error message (#2718)

22 months agoFix CUDA softmax by subtracting max value before exp (#2665)
Jiahao Li [Tue, 22 Aug 2023 18:27:06 +0000 (02:27 +0800)]
Fix CUDA softmax by subtracting max value before exp (#2665)

22 months agogguf : add ftype meta info to the model (#2710)
Georgi Gerganov [Tue, 22 Aug 2023 17:05:59 +0000 (20:05 +0300)]
gguf : add ftype meta info to the model (#2710)

* llama : add ftype meta info to the model

ggml-ci

* convert.py : add ftype when converting (does not work)

* convert.py : fix Enum to IntEnum

ggml-ci

22 months agoQuantization imrovements for k_quants (#2707)
Kawrakow [Tue, 22 Aug 2023 16:14:09 +0000 (19:14 +0300)]
Quantization imrovements for k_quants (#2707)

* Improve LLaMA-2 2-, 3- and 4-bit quantization

* Q3_K_S: use Q5_K for 1st 2 layers of attention.wv and feed_forward.w2
* Q4_K_S: use Q6_K for 1st 2 layers of attention.wv and feed_forward.w2
* Q2_K and Q3_K_M: use Q5_K instead of Q4_K for 1st 2 layers of
  attention.wv and feed_forward.w2

This leads to a slight model sized increase as follows:
Q2_K  : 2.684G vs 2.670G
Q3_K_S: 2.775G vs 2.745G
Q3_K_M: 3.071G vs 3.057G
Q4_K_S: 3.592G vs 3.563G

LLaMA-2 PPL for context 512 changes as follows:
Q2_K  : 6.6691 vs 6.8201
Q3_K_S: 6.2129 vs 6.2584
Q3_K_M: 6.0387 vs 6.1371
Q4_K_S: 5.9138 vs 6.0041

There are improvements for LLaMA-1 as well, but they are
way smaller than the above.

* Minor 4-bit quantization improvement

For the same model size as previus commit, we get
PPL = 5.9069 vs 5.9138.

* Some more fine tuning

* Adding make_qkx2_quants

With it, we get PPL = 5.8828 for L2-7B Q4_K_S.

* Another minor improvement

* Q2_K improvement

Smaller model, lower perplexity.
 7B: file size = 2.632G, PPL = 6.3772 vs original 2.670G PPL = 6.8201
12B: file size = 5.056G, PPL = 5.4577 vs original 5.130G PPL = 5.7178

It is mostly Q3_K except for tok_embeddings, attention.wq, attention.wk,
which are Q2_K

* Iterating

* Revert Q5_K back to make_qkx1_quants

* Better Q6_K

* make_qkx2_quants is better for Q5_K after all

* Fix after rebasing on master

* Fix for changed tensor names

---------

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoembedding : evaluate prompt in batches (#2713)
slaren [Tue, 22 Aug 2023 14:03:12 +0000 (16:03 +0200)]
embedding : evaluate prompt in batches (#2713)

22 months agoggml-cuda : use graph allocator (#2684)
slaren [Tue, 22 Aug 2023 13:25:19 +0000 (15:25 +0200)]
ggml-cuda : use graph allocator (#2684)

use a different function for no_alloc to avoid breaking backwards compat, fixes lora

remove 512 n_batch limit

fixed 2048 batch size

cleanup

Co-authored-by: Johannes Gäßler <redacted>
22 months agoggml : sync latest (SAM + SD operators, CUDA alibi) (#2709)
Georgi Gerganov [Tue, 22 Aug 2023 11:22:08 +0000 (14:22 +0300)]
ggml : sync latest (SAM + SD operators, CUDA alibi) (#2709)

* ggml : sync latest (SAM + SD operators, CUDA alibi)

ggml-ci

* ggml : fix tabs

22 months agollama-bench : minor fixes (#2695)
slaren [Tue, 22 Aug 2023 07:56:03 +0000 (09:56 +0200)]
llama-bench : minor fixes (#2695)

22 months agoggml : support CUDA's half type for aarch64(#1455) (#2670)
Kylin [Tue, 22 Aug 2023 07:14:23 +0000 (15:14 +0800)]
ggml : support CUDA's half type for aarch64(#1455) (#2670)

* ggml: support CUDA's half type for aarch64(#1455)
support CUDA's half type for aarch64 in ggml_fp16_t definition

* ggml: use __CUDACC__ to recognise nvcc compiler

22 months agometal : add missing barriers for mul-mat (#2699)
Shouzheng Liu [Tue, 22 Aug 2023 06:18:40 +0000 (02:18 -0400)]
metal : add missing barriers for mul-mat (#2699)

22 months agoserver : fallback to default if client param is null (#2688)
Jhen-Jie Hong [Tue, 22 Aug 2023 00:32:00 +0000 (08:32 +0800)]
server : fallback to default if client param is null (#2688)

* server : fallback to default if client param is null

* server : do not overwrite 404 if status is 500 from exception_handler

22 months agoFix convert-llama-ggmlv3-to-gguf.py vocab conversion (#2698)
Kerfuffle [Tue, 22 Aug 2023 00:01:34 +0000 (18:01 -0600)]
Fix convert-llama-ggmlv3-to-gguf.py vocab conversion (#2698)

When converting without metadata, the hex value for bytes entries weren't 0 padded to 2 digits.

22 months agopy : remove obsolete script
Georgi Gerganov [Mon, 21 Aug 2023 20:40:22 +0000 (23:40 +0300)]
py : remove obsolete script