]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/log
pkg/ggml/sources/llama.cpp
22 months agogguf : new file format with flexible meta data (beta) (#2398)
Georgi Gerganov [Mon, 21 Aug 2023 20:07:43 +0000 (23:07 +0300)]
gguf : new file format with flexible meta data (beta) (#2398)

* gguf : first API pass

* gguf : read header + meta data

* gguf : read tensor info

* gguf : initial model loading - not tested

* gguf : add gguf_get_tensor_name()

* gguf : do not support passing existing ggml_context to gguf_init

* gguf : simplify gguf_get_val

* gguf : gguf.c is now part of ggml.c

* gguf : read / write sample models

* gguf : add comments

* refactor : reduce code duplication and better API (#2415)

* gguf : expose the gguf_type enum through the API for now

* gguf : add array support

* gguf.py : some code style changes

* convert.py : start a new simplified implementation by removing old stuff

* convert.py : remove GGML vocab + other obsolete stuff

* GGUF : write tensor (#2426)

* WIP: Write tensor

* GGUF : Support writing tensors in Python

* refactor : rm unused import and upd todos

* fix : fix errors upd writing example

* rm example.gguf

* gitignore *.gguf

* undo formatting

* gguf : add gguf_find_key (#2438)

* gguf.cpp : find key example

* ggml.h : add gguf_find_key

* ggml.c : add gguf_find_key

* gguf : fix writing tensors

* gguf : do not hardcode tensor names to read

* gguf : write sample tensors to read

* gguf : add tokenization constants

* quick and dirty conversion example

* gguf : fix writing gguf arrays

* gguf : write tensors one by one and code reuse

* gguf : fix writing gguf arrays

* gguf : write tensors one by one

* gguf : write tensors one by one

* gguf : write tokenizer data

* gguf : upd gguf conversion script

* Update convert-llama-h5-to-gguf.py

* gguf : handle already encoded string

* ggml.h : get array str and f32

* ggml.c : get arr str and f32

* gguf.py : support any type

* Update convert-llama-h5-to-gguf.py

* gguf : fix set is not subscriptable

* gguf : update convert-llama-h5-to-gguf.py

* constants.py : add layer norm eps

* gguf.py : add layer norm eps and merges

* ggml.h : increase GGML_MAX_NAME to 64

* ggml.c : add gguf_get_arr_n

* Update convert-llama-h5-to-gguf.py

* add gptneox gguf example

* Makefile : add gptneox gguf example

* Update convert-llama-h5-to-gguf.py

* add gptneox gguf example

* Update convert-llama-h5-to-gguf.py

* Update convert-gptneox-h5-to-gguf.py

* Update convert-gptneox-h5-to-gguf.py

* Update convert-llama-h5-to-gguf.py

* gguf : support custom alignment value

* gguf : fix typo in function call

* gguf : mmap tensor data example

* fix : update convert-llama-h5-to-gguf.py

* Update convert-llama-h5-to-gguf.py

* convert-gptneox-h5-to-gguf.py : Special tokens

* gptneox-main.cpp : special tokens

* Update gptneox-main.cpp

* constants.py : special tokens

* gguf.py : accumulate kv and tensor info data + special tokens

* convert-gptneox-h5-to-gguf.py : accumulate kv and ti + special tokens

* gguf : gguf counterpart of llama-util.h

* gguf-util.h : update note

* convert-llama-h5-to-gguf.py : accumulate kv / ti + special tokens

* convert-llama-h5-to-gguf.py : special tokens

* Delete gptneox-common.cpp

* Delete gptneox-common.h

* convert-gptneox-h5-to-gguf.py : gpt2bpe tokenizer

* gptneox-main.cpp : gpt2 bpe tokenizer

* gpt2 bpe tokenizer (handles merges and unicode)

* Makefile : remove gptneox-common

* gguf.py : bytesarray for gpt2bpe tokenizer

* cmpnct_gpt2bpe.hpp : comments

* gguf.py : use custom alignment if present

* gguf : minor stuff

* Update gptneox-main.cpp

* map tensor names

* convert-gptneox-h5-to-gguf.py : map tensor names

* convert-llama-h5-to-gguf.py : map tensor names

* gptneox-main.cpp : map tensor names

* gguf : start implementing libllama in GGUF (WIP)

* gguf : start implementing libllama in GGUF (WIP)

* rm binary commited by mistake

* upd .gitignore

* gguf : calculate n_mult

* gguf :  inference with 7B model working (WIP)

* gguf : rm deprecated function

* gguf : start implementing gguf_file_saver (WIP)

* gguf : start implementing gguf_file_saver (WIP)

* gguf : start implementing gguf_file_saver (WIP)

* gguf : add gguf_get_kv_type

* gguf : add gguf_get_kv_type

* gguf : write metadata in gguf_file_saver (WIP)

* gguf : write metadata in gguf_file_saver (WIP)

* gguf : write metadata in gguf_file_saver

* gguf : rm references to old file formats

* gguf : shorter name for member variable

* gguf : rm redundant method

* gguf : get rid of n_mult, read n_ff from file

* Update gguf_tensor_map.py

* Update gptneox-main.cpp

* gguf : rm references to old file magics

* gguf : start implementing quantization (WIP)

* gguf : start implementing quantization (WIP)

* gguf : start implementing quantization (WIP)

* gguf : start implementing quantization (WIP)

* gguf : start implementing quantization (WIP)

* gguf : start implementing quantization (WIP)

* gguf : quantization is working

* gguf : roper closing of file

* gguf.py : no need to convert tensors twice

* convert-gptneox-h5-to-gguf.py : no need to convert tensors twice

* convert-llama-h5-to-gguf.py : no need to convert tensors twice

* convert-gptneox-h5-to-gguf.py : simplify nbytes

* convert-llama-h5-to-gguf.py : simplify nbytes

* gptneox-main.cpp : n_layer --> n_block

* constants.py : n_layer --> n_block

* gguf.py : n_layer --> n_block

* convert-gptneox-h5-to-gguf.py : n_layer --> n_block

* convert-llama-h5-to-gguf.py : n_layer --> n_block

* gptneox-main.cpp : n_layer --> n_block

* Update gguf_tensor_map.py

* convert-gptneox-h5-to-gguf.py : load model in parts to save memory

* convert-llama-h5-to-gguf.py : load model in parts to save memory

* convert : write more metadata for LLaMA

* convert : rm quantization version

* convert-gptneox-h5-to-gguf.py : add file_type key

* gptneox-main.cpp : add file_type key

* fix conflicts

* gguf : add todos and comments

* convert-gptneox-h5-to-gguf.py : tensor name map changes

* Create gguf_namemap.py : tensor name map changes

* Delete gguf_tensor_map.py

* gptneox-main.cpp : tensor name map changes

* convert-llama-h5-to-gguf.py : fixes

* gguf.py : dont add empty strings

* simple : minor style changes

* gguf : use UNIX line ending

* Create convert-llama-7b-pth-to-gguf.py

* llama : sync gguf-llama.cpp with latest llama.cpp (#2608)

* llama : sync gguf-llama.cpp with latest llama.cpp

* minor : indentation + assert

* llama : refactor gguf_buffer and gguf_ctx_buffer

* llama : minor

* gitignore : add gptneox-main

* llama : tokenizer fixes (#2549)

* Merge tokenizer fixes into the gguf branch.

* Add test vocabularies

* convert : update convert-new.py with tokenizer fixes (#2614)

* Merge tokenizer fixes into the gguf branch.

* Add test vocabularies

* Adapt convert-new.py (and fix a clang-cl compiler error on windows)

* llama : sync gguf-llama with llama (#2613)

* llama : sync gguf-llama with llama

* tests : fix build + warnings (test-tokenizer-1 still fails)

* tests : fix wstring_convert

* convert : fix layer names

* llama : sync gguf-llama.cpp

* convert : update HF converter to new tokenizer voodoo magics

* llama : update tokenizer style

* convert-llama-h5-to-gguf.py : add token types

* constants.py : add token types

* gguf.py : add token types

* convert-llama-7b-pth-to-gguf.py : add token types

* gguf-llama.cpp :  fix n_head_kv

* convert-llama-h5-to-gguf.py : add 70b gqa support

* gguf.py : add tensor data layout

* convert-llama-h5-to-gguf.py : add tensor data layout

* convert-llama-7b-pth-to-gguf.py : add tensor data layout

* gptneox-main.cpp : add tensor data layout

* convert-llama-h5-to-gguf.py : clarify the reverse permute

* llama : refactor model loading code (#2620)

* llama : style formatting + remove helper methods

* llama : fix quantization using gguf tool

* llama : simplify gguf_file_saver

* llama : fix method names

* llama : simplify write_header()

* llama : no need to pass full file loader to the file saver

just gguf_ctx

* llama : gguf_file_saver write I32

* llama : refactor tensor names (#2622)

* gguf: update tensor names searched in quantization

* gguf : define tensor names as constants

* gguf : initial write API (not tested yet)

* gguf : write to file API (not tested)

* gguf : initial write API ready + example

* gguf : fix header write

* gguf : fixes + simplify example + add ggml_nbytes_pad()

* gguf : minor

* llama : replace gguf_file_saver with new gguf write API

* gguf : streaming support when writing files

* gguf : remove oboslete write methods

* gguf : remove obosolete gguf_get_arr_xxx API

* llama : simplify gguf_file_loader

* llama : move hparams and vocab from gguf_file_loader to llama_model_loader

* llama : merge gguf-util.h in llama.cpp

* llama : reorder definitions in .cpp to match .h

* llama : minor simplifications

* llama : refactor llama_model_loader (WIP)

wip : remove ggml_ctx from llama_model_loader

wip : merge gguf_file_loader in llama_model_loader

* llama : fix shape prints

* llama : fix Windows build + fix norm_rms_eps key

* llama : throw error on missing KV paris in model meta data

* llama : improve printing + log meta data

* llama : switch print order of meta data

---------

Co-authored-by: M. Yusuf Sarıgöz <redacted>
* gguf : deduplicate (#2629)

* gguf : better type names

* dedup : CPU + Metal is working

* ggml : fix warnings about unused results

* llama.cpp : fix line feed and compiler warning

* llama : fix strncpy warning + note token_to_str does not write null

* llama : restore the original load/save session implementation

Will migrate this to GGUF in the future

* convert-llama-h5-to-gguf.py : support alt ctx param name

* ggml : assert when using ggml_mul with non-F32 src1

* examples : dedup simple

---------

Co-authored-by: klosax <redacted>
* gguf.py : merge all files in gguf.py

* convert-new.py : pick #2427 for HF 70B support

* examples/gguf : no need to keep q option for quantization any more

* llama.cpp : print actual model size

* llama.cpp : use ggml_elements()

* convert-new.py : output gguf (#2635)

* convert-new.py : output gguf (WIP)

* convert-new.py : add gguf key-value pairs

* llama : add hparams.ctx_train + no longer print ftype

* convert-new.py : minor fixes

* convert-new.py : vocab-only option should work now

* llama : fix tokenizer to use llama_char_to_byte

* tests : add new ggml-vocab-llama.gguf

* convert-new.py : tensor name mapping

* convert-new.py : add map for skipping tensor serialization

* convert-new.py : convert script now works

* gguf.py : pick some of the refactoring from #2644

* convert-new.py : minor fixes

* convert.py : update to support GGUF output

* Revert "ci : disable CI temporary to not waste energy"

This reverts commit 7e82d25f40386540c2c15226300ad998ecd871ea.

* convert.py : n_head_kv optional and .gguf file extension

* convert.py : better always have n_head_kv and default it to n_head

* llama : sync with recent PRs on master

* editorconfig : ignore models folder

ggml-ci

* ci : update ".bin" to ".gguf" extension

ggml-ci

* llama : fix llama_model_loader memory leak

* gptneox : move as a WIP example

* llama : fix lambda capture

ggml-ci

* ggml : fix bug in gguf_set_kv

ggml-ci

* common.h : .bin --> .gguf

* quantize-stats.cpp : .bin --> .gguf

* convert.py : fix HF tensor permuting / unpacking

ggml-ci

* llama.cpp : typo

* llama : throw error if gguf fails to init from file

ggml-ci

* llama : fix tensor name grepping during quantization

ggml-ci

* gguf.py : write tensors in a single pass (#2644)

* gguf : single pass for writing tensors + refactoring writer

* gguf : single pass for writing tensors + refactoring writer

* gguf : single pass for writing tensors + refactoring writer

* gguf : style fixes in simple conversion script

* gguf : refactor gptneox conversion script

* gguf : rename h5 to hf (for HuggingFace)

* gguf : refactor pth to gguf conversion script

* gguf : rm file_type key and method

* gguf.py : fix vertical alignment

* gguf.py : indentation

---------

Co-authored-by: Georgi Gerganov <redacted>
* convert-gptneox-hf-to-gguf.py : fixes

* gguf.py : gptneox mapping

* convert-llama-hf-to-gguf.py : fixes

* convert-llama-7b-pth-to-gguf.py : fixes

* ggml.h : reverse GGUF_MAGIC

* gguf.py : reverse GGUF_MAGIC

* test-tokenizer-0.cpp : fix warning

* llama.cpp : print kv general.name

* llama.cpp : get special token kv and linefeed token id

* llama : print number of tensors per type + print arch + style

* tests : update vocab file with new magic

* editorconfig : fix whitespaces

* llama : re-order functions

* llama : remove C++ API + reorganize common source in /common dir

* llama : minor API updates

* llama : avoid hardcoded special tokens

* llama : fix MPI build

ggml-ci

* llama : introduce enum llama_vocab_type + remove hardcoded string constants

* convert-falcon-hf-to-gguf.py : falcon HF --> gguf conversion, not tested

* falcon-main.cpp : falcon inference example

* convert-falcon-hf-to-gguf.py : remove extra kv

* convert-gptneox-hf-to-gguf.py : remove extra kv

* convert-llama-7b-pth-to-gguf.py : remove extra kv

* convert-llama-hf-to-gguf.py : remove extra kv

* gguf.py : fix for falcon 40b

* falcon-main.cpp : fix for falcon 40b

* convert-falcon-hf-to-gguf.py : update ref

* convert-falcon-hf-to-gguf.py : add tensor data layout

* cmpnct_gpt2bpe.hpp : fixes

* falcon-main.cpp : fixes

* gptneox-main.cpp : fixes

* cmpnct_gpt2bpe.hpp : remove non-general stuff

* Update examples/server/README.md

Co-authored-by: slaren <redacted>
* cmpnct_gpt2bpe.hpp : cleanup

* convert-llama-hf-to-gguf.py : special tokens

* convert-llama-7b-pth-to-gguf.py : special tokens

* convert-permute-debug.py : permute debug print

* convert-permute-debug-master.py : permute debug for master

* convert-permute-debug.py : change permute type of attn_q

* convert.py : 70b model working (change attn_q permute)

* Delete convert-permute-debug-master.py

* Delete convert-permute-debug.py

* convert-llama-hf-to-gguf.py : fix attn_q permute

* gguf.py : fix rope scale kv

* convert-llama-hf-to-gguf.py : rope scale and added tokens

* convert-llama-7b-pth-to-gguf.py : rope scale and added tokens

* llama.cpp : use rope scale kv

* convert-llama-7b-pth-to-gguf.py : rope scale fix

* convert-llama-hf-to-gguf.py : rope scale fix

* py : fix whitespace

* gguf : add Python script to convert GGMLv3 LLaMA models to GGUF (#2682)

* First pass at converting GGMLv3 LLaMA models to GGUF

* Cleanups, better output during conversion

* Fix vocab space conversion logic

* More vocab conversion fixes

* Add description to converted GGUF files

* Improve help text, expand warning

* Allow specifying name and description for output GGUF

* Allow overriding vocab and hyperparams from original model metadata

* Use correct params override var name

* Fix wrong type size for Q8_K

Better handling of original style metadata

* Set default value for gguf add_tensor raw_shape KW arg

* llama : improve token type support (#2668)

* Merge tokenizer fixes into the gguf branch.

* Add test vocabularies

* Adapt convert-new.py (and fix a clang-cl compiler error on windows)

* Improved tokenizer test

But does it work on MacOS?

* Improve token type support

- Added @klosax code to convert.py
- Improved token type support in vocabulary

* Exclude platform dependent tests

* More sentencepiece compatibility by eliminating magic numbers

* Restored accidentally removed comment

* llama : add API for token type

ggml-ci

* tests : use new tokenizer type API (#2692)

* Merge tokenizer fixes into the gguf branch.

* Add test vocabularies

* Adapt convert-new.py (and fix a clang-cl compiler error on windows)

* Improved tokenizer test

But does it work on MacOS?

* Improve token type support

- Added @klosax code to convert.py
- Improved token type support in vocabulary

* Exclude platform dependent tests

* More sentencepiece compatibility by eliminating magic numbers

* Restored accidentally removed comment

* Improve commentary

* Use token type API in test-tokenizer-1.cpp

* py : cosmetics

* readme : add notice about new file format

ggml-ci

---------

Co-authored-by: M. Yusuf Sarıgöz <redacted>
Co-authored-by: klosax <redacted>
Co-authored-by: goerch <redacted>
Co-authored-by: slaren <redacted>
Co-authored-by: Kerfuffle <redacted>
22 months agometal : fix synchronization in new matrix multiplication kernel (#2686)
Shouzheng Liu [Mon, 21 Aug 2023 10:59:29 +0000 (06:59 -0400)]
metal : fix synchronization in new matrix multiplication kernel (#2686)

22 months agoHellaSwag: split token evaluation into batches if needed (#2681)
Kawrakow [Mon, 21 Aug 2023 08:11:31 +0000 (11:11 +0300)]
HellaSwag: split token evaluation into batches if needed (#2681)

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoggml : move all type info to ggml_type_traits (#2663)
slaren [Sun, 20 Aug 2023 20:17:53 +0000 (22:17 +0200)]
ggml : move all type info to ggml_type_traits (#2663)

22 months agoMore efficient Hellaswag implementation (#2677)
Kawrakow [Sun, 20 Aug 2023 13:44:46 +0000 (16:44 +0300)]
More efficient Hellaswag implementation (#2677)

Co-authored-by: Iwan Kawrakow <redacted>
22 months agoserver : better default prompt (#2646)
Georgi Gerganov [Fri, 18 Aug 2023 21:45:36 +0000 (00:45 +0300)]
server : better default prompt (#2646)

22 months agoserver : update xxd usage for older versions compatibility (#2649)
Jhen-Jie Hong [Fri, 18 Aug 2023 21:41:32 +0000 (05:41 +0800)]
server : update xxd usage for older versions compatibility (#2649)

* server : update xxd usage for older versions compatibility

* remove unused $func

22 months agoAdd link to clojure bindings to Readme. (#2659)
Adrian [Fri, 18 Aug 2023 19:39:22 +0000 (12:39 -0700)]
Add link to clojure bindings to Readme. (#2659)

22 months agoreadme : incoming BREAKING CHANGE
Georgi Gerganov [Fri, 18 Aug 2023 14:48:31 +0000 (17:48 +0300)]
readme : incoming BREAKING CHANGE

22 months agollama : add benchmark example (#2626)
slaren [Fri, 18 Aug 2023 10:44:58 +0000 (12:44 +0200)]
llama : add benchmark example (#2626)

* llama : add benchmark example

* add to examples CMakeLists.txt

* fix msvc build

* add missing include

* add Bessel's correction to stdev calculation

Co-authored-by: Johannes Gäßler <redacted>
* improve markdown formatting

* add missing include

* print warning is NDEBUG is not defined

* remove n_prompt and n_gen from the matrix, use each value separately instead

* better checks for non-optimized builds

* llama.cpp : fix MEM_REQ_SCRATCH0 reusing the value of n_ctx of the first call

* fix json formatting

* add sql output

* add basic cpu and gpu info (linx/cuda only)

* markdown: also show values that differ from the default

* markdown: add build id

* cleanup

* improve formatting

* formatting

---------

Co-authored-by: Johannes Gäßler <redacted>
22 months agoreadme : add link to Rust bindings (#2656)
mdrokz [Fri, 18 Aug 2023 10:17:58 +0000 (15:47 +0530)]
readme : add link to Rust bindings (#2656)

22 months agoperplexity : more meaningful ETA number - 2 decimal points
Georgi Gerganov [Fri, 18 Aug 2023 09:48:55 +0000 (12:48 +0300)]
perplexity : more meaningful ETA number - 2 decimal points

22 months agoFix unicode in grammars (fixes #2501) (#2553)
Evan Jones [Thu, 17 Aug 2023 23:54:44 +0000 (19:54 -0400)]
Fix unicode in grammars (fixes #2501) (#2553)

* Fix unicode in grammars (fixes #2501)

* add more comments

* fix test-llama-grammar

22 months agoserver : support for saving templates in browser LocalStorage (#2486)
staviq [Thu, 17 Aug 2023 23:34:01 +0000 (23:34 +0000)]
server : support for saving templates in browser LocalStorage (#2486)

* support for templates in browser LocalStorage

* sync accepted #2409 fix from upstream

* convert autosave invocation to useEffect

* Apply suggestions from code review

Co-authored-by: Jhen-Jie Hong <redacted>
* Regen index.html.cpp, suggested from code review

---------

Co-authored-by: Jhen-Jie Hong <redacted>
22 months agoREADME: fix LLAMA_CUDA_MMV_Y documentation (#2647)
Johannes Gäßler [Thu, 17 Aug 2023 21:57:59 +0000 (23:57 +0200)]
README: fix LLAMA_CUDA_MMV_Y documentation (#2647)

22 months ago[Zig] Fixing Zig build and improvements (#2554)
Henri Vasserman [Thu, 17 Aug 2023 20:11:18 +0000 (23:11 +0300)]
[Zig] Fixing Zig build and improvements (#2554)

* Fix zig after console.o was split

* Better include and flag management

* Change LTO to option

22 months agoAdd --cfg-negative-prompt-file option for examples (#2591)
Kerfuffle [Thu, 17 Aug 2023 13:29:44 +0000 (07:29 -0600)]
Add --cfg-negative-prompt-file option for examples (#2591)

Add --cfg-negative-prompt-file option for examples

22 months agollama : replace (permute + reshape + view_1d) with (view_3d) (#2538)
Georgi Gerganov [Thu, 17 Aug 2023 07:47:09 +0000 (10:47 +0300)]
llama : replace (permute + reshape + view_1d) with (view_3d) (#2538)

ggml-ci

22 months agotests : adds simple llama grammar tests (#2618)
drbh [Thu, 17 Aug 2023 07:41:01 +0000 (03:41 -0400)]
tests : adds simple llama grammar tests (#2618)

* adds simple llama grammar tests

* fix lint and add Makefile

* 0 terminate code_points

* avoid dangling pointers in candidate cleanup

* cleanup grammar at end of test

22 months agoggml-alloc : fix discrepency between measure&eval (#2639)
Shouzheng Liu [Thu, 17 Aug 2023 07:35:53 +0000 (03:35 -0400)]
ggml-alloc : fix discrepency between measure&eval (#2639)

The GGML memory allocator consistently places a tensor within the
optimal-fit memory block, which is the smallest block capable of
accommodating the tensor's size. During the measurement phase, the final
block is generously sized, ensuring it never qualifies as the
optimal-fit block as long as there exists another block capable of
accommodating the tensor. Nevertheless, in the evaluation phase, the
last block is constrained in size and could potentially qualify as the
optimal-fit block. Consequently, there exists the possibility of a
tensor being allocated to a different region during evaluation, leading
to more memory fragmentation in our scratch buffer.

This recent commit guarantees uniform behavior of the allocator across
both the measurement and evaluation phases, eliminating discrepancies
between the two.

22 months agocmake : install ggml-meta.metal if LLAMA_METAL (#2449)
Kolen Cheung [Wed, 16 Aug 2023 20:09:49 +0000 (21:09 +0100)]
cmake : install ggml-meta.metal if LLAMA_METAL (#2449)

22 months agometal : print error of load pipeline state (#2564)
Jhen-Jie Hong [Wed, 16 Aug 2023 20:09:03 +0000 (04:09 +0800)]
metal : print error of load pipeline state (#2564)

* metal : print error of load pipeline state

* metal : return null if load pipeline failed

22 months agometal : enable ggml-alloc (#2627)
Shouzheng Liu [Wed, 16 Aug 2023 20:08:28 +0000 (16:08 -0400)]
metal : enable ggml-alloc (#2627)

* metal: enable ggml-alloc

Make ggml-alloc work with concurrently dispatch.

* style-fix

Co-authored-by: slaren <redacted>
---------

Co-authored-by: slaren <redacted>
Co-authored-by: Georgi Gerganov <redacted>
22 months agometal : matrix-matrix multiplication kernel (#2615)
Shouzheng Liu [Wed, 16 Aug 2023 20:07:04 +0000 (16:07 -0400)]
metal : matrix-matrix multiplication kernel (#2615)

* metal: matrix-matrix multiplication kernel

This commit removes MPS and uses custom matrix-matrix multiplication
kernels for all quantization types. This commit also adds grouped-query
attention to support llama2 70B.

* metal: fix performance degradation from gqa

Integers are slow on the GPU, and 64-bit divides are extremely slow.
In the context of GQA, we introduce a 64-bit divide that cannot be
optimized out by the compiler, which results in a decrease of ~8% in
inference performance. This commit fixes that issue by calculating a
part of the offset with a 32-bit divide. Naturally, this limits the
size of a single matrix to ~4GB. However, this limitation should
suffice for the near future.

* metal: fix bugs for GQA and perplexity test.

I mixed up ne02 and nb02 in previous commit.

22 months agoscripts : add helper script to get wikitext
Georgi Gerganov [Tue, 15 Aug 2023 07:04:58 +0000 (10:04 +0300)]
scripts : add helper script to get wikitext

22 months agoserver : add missing /json-schema-to-grammar.mjs (#2616)
Jhen-Jie Hong [Mon, 14 Aug 2023 22:14:14 +0000 (06:14 +0800)]
server : add missing /json-schema-to-grammar.mjs (#2616)

fixes #2611

22 months agometal : return null instead of exit(1) (#2573)
Jhen-Jie Hong [Mon, 14 Aug 2023 13:37:39 +0000 (21:37 +0800)]
metal : return null instead of exit(1) (#2573)

22 months agoserver : add --numa support (#2524)
Cheng Shao [Mon, 14 Aug 2023 13:36:42 +0000 (15:36 +0200)]
server : add --numa support (#2524)

22 months agollama : add missing enum keyword in function signatures (#2610)
Kamil Tomšík [Mon, 14 Aug 2023 13:35:16 +0000 (15:35 +0200)]
llama : add missing enum keyword in function signatures (#2610)

22 months agoCUDA: launch_bounds, small q4_K, q5_K mmq refactor (#2596)
Johannes Gäßler [Mon, 14 Aug 2023 08:41:22 +0000 (10:41 +0200)]
CUDA: launch_bounds, small q4_K, q5_K mmq refactor (#2596)

22 months agoserver : fix default grammar by use empty string in the UI (#2604)
Jhen-Jie Hong [Mon, 14 Aug 2023 08:20:17 +0000 (16:20 +0800)]
server : fix default grammar by use empty string in the UI (#2604)

22 months agoserver : implement json-schema-to-grammar.mjs & add grammar param in the UI (#2588)
Jhen-Jie Hong [Mon, 14 Aug 2023 07:16:54 +0000 (15:16 +0800)]
server : implement json-schema-to-grammar.mjs & add grammar param in the UI (#2588)

* server : implement json-schema-to-grammar.mjs by follow python impl

* server : add grammar support in chat.mjs

* server : implement grammer param in the UI

* server : generate .hpp

* server : remove trailing whitespaces

* server : generate .hpp

* server : fix sort of prop pairs

* server : optimize regex & iteration

22 months agoEnhance Windows 7 and below compatibility. (#2592)
vxiiduu [Mon, 14 Aug 2023 03:59:16 +0000 (13:59 +1000)]
Enhance Windows 7 and below compatibility. (#2592)

* Enhance Windows 7 compatibility.
* Clean away unnecessary preprocessor conditional

22 months agotest : add simple grammar parsing tests (#2594)
drbh [Sun, 13 Aug 2023 14:00:48 +0000 (10:00 -0400)]
test : add simple grammar parsing tests (#2594)

* adds simple grammar parsing tests

* adds cassert header

22 months agoCUDA: Fixed OpenLLaMA 3b mmq, reduced compile time (#2590)
Johannes Gäßler [Sat, 12 Aug 2023 22:24:45 +0000 (00:24 +0200)]
CUDA: Fixed OpenLLaMA 3b mmq, reduced compile time (#2590)

22 months agoAdding support for llama2.c models (#2559)
byte-6174 [Fri, 11 Aug 2023 23:17:25 +0000 (19:17 -0400)]
Adding support for llama2.c models (#2559)

22 months agoserver: fixed wrong variable name in timing json (#2579)
Equim [Fri, 11 Aug 2023 22:35:14 +0000 (06:35 +0800)]
server: fixed wrong variable name in timing json (#2579)

* server: fixed wrong variable name in timing json

* remove redunct entry

22 months agoHandle `ENABLE_VIRTUAL_TERMINAL_PROCESSING` more gracefully on earlier versions of...
DannyDaemonic [Thu, 10 Aug 2023 20:11:36 +0000 (13:11 -0700)]
Handle `ENABLE_VIRTUAL_TERMINAL_PROCESSING` more gracefully on earlier versions of Windows.

22 months agoAdd --n-predict -2 for stopping generation on full context (#2565)
Christian Demsar [Thu, 10 Aug 2023 14:28:27 +0000 (10:28 -0400)]
Add --n-predict -2 for stopping generation on full context (#2565)

22 months agoFix grammar-based sampling issue in server (#2566)
Martin Krasser [Thu, 10 Aug 2023 10:16:38 +0000 (12:16 +0200)]
Fix grammar-based sampling issue in server (#2566)

22 months agoggml-alloc: Don't try to re-use buffers of external tensors (#2562)
Sam Spilsbury [Wed, 9 Aug 2023 20:47:42 +0000 (23:47 +0300)]
ggml-alloc: Don't try to re-use buffers of external tensors (#2562)

* ggml-alloc: Don't try to re-use buffers of external tensors

They might be weights that came from another context, so we
have no control over them (and they might be re-used elsewhere
so writing to them would be a bad idea).

* ggml-alloc: >= when checking for out-of-bounds

Co-authored-by: slaren <redacted>
---------

Co-authored-by: slaren <redacted>
22 months agoadd log_callback to llama_context_params for custom logging. (#2234)
grahameth [Wed, 9 Aug 2023 20:46:40 +0000 (22:46 +0200)]
add log_callback to llama_context_params for custom logging. (#2234)

* add log_callback to llama_context_params for custom logging.

* Fix macro expansion on gcc

* Add struct llama_state for global variables and move log_callback there

* Turn log level into enum and some minor changes.

* Remove model_for_logging parameter (not needed anymore)

* Convert remaining fprintf(stderr, ...) calls to use new macros.

* Fix enum and initialize g_state

* Fix log calls after merge

* Fix missing static

* Add back all the new lines in the logging strings

* Add comment for llama_log_callback and replace remaining printf calls

---------

Co-authored-by: grahameth <->
Co-authored-by: Helmut <redacted>
22 months agoCUDA: tuned mul_mat_q kernels (#2546)
Johannes Gäßler [Wed, 9 Aug 2023 07:42:34 +0000 (09:42 +0200)]
CUDA: tuned mul_mat_q kernels (#2546)

22 months agoAllow passing grammar to completion endpoint (#2532)
Martin Krasser [Tue, 8 Aug 2023 13:29:19 +0000 (15:29 +0200)]
Allow passing grammar to completion endpoint (#2532)

* Allow passing grammar to completion endpoint

22 months agoCUDA: tighter VRAM scratch size for 65b/70b (#2551)
Johannes Gäßler [Tue, 8 Aug 2023 12:38:16 +0000 (14:38 +0200)]
CUDA: tighter VRAM scratch size for 65b/70b (#2551)

22 months agollm.vim : multiline autocompletion, get rid of "^@" (#2543)
chaihahaha [Tue, 8 Aug 2023 12:07:02 +0000 (20:07 +0800)]
llm.vim : multiline autocompletion, get rid of "^@" (#2543)

22 months agovim : bring back simple llm.vim example
Georgi Gerganov [Tue, 8 Aug 2023 12:05:30 +0000 (15:05 +0300)]
vim : bring back simple llm.vim example

22 months agovim : streaming and more (#2495)
AustinMroz [Tue, 8 Aug 2023 11:44:48 +0000 (06:44 -0500)]
vim : streaming and more (#2495)

* Update Vim plugin

* Remove getbufoneline usage, Add input bind example.

getbufoneline() appears to be a recently added function and has been
replaced with getbufline for compatibility.

An additional example that explains how to add a keybind that works in
insert mode was added.

22 months agoAdd --rope-scale parameter (#2544)
klosax [Mon, 7 Aug 2023 17:07:19 +0000 (19:07 +0200)]
Add --rope-scale parameter (#2544)

* common.cpp : Add --rope-scale parameter
* README.md : Add info about using linear rope scaling

22 months agoggml : mul mat tweaks (#2372)
Georgi Gerganov [Mon, 7 Aug 2023 11:25:58 +0000 (14:25 +0300)]
ggml : mul mat tweaks (#2372)

* ggml : mul mat wip

ggml-ci

* ggml : alternative thread distribution for mul_mat

ggml-ci

* ggml : mul_mat block tiling attempt

* ggml : mul_mat threads yield

ggml-ci

22 months agoggml : pad result of ggml_nbytes()
Georgi Gerganov [Mon, 7 Aug 2023 11:24:42 +0000 (14:24 +0300)]
ggml : pad result of ggml_nbytes()

22 months agoggml : change params pointer (style change) (#2539)
Georgi Gerganov [Mon, 7 Aug 2023 10:55:18 +0000 (13:55 +0300)]
ggml : change params pointer (style change) (#2539)

ggml-ci

22 months agoggml : sync (custom ops) (#2537)
Georgi Gerganov [Mon, 7 Aug 2023 10:20:09 +0000 (13:20 +0300)]
ggml : sync (custom ops) (#2537)

ggml-ci

22 months agoFixed mmap prefetch for GPU offloading (#2529)
Johannes Gäßler [Mon, 7 Aug 2023 08:09:40 +0000 (10:09 +0200)]
Fixed mmap prefetch for GPU offloading (#2529)

22 months agometal : fix out-of-bounds access + inc concurrency nodes (#2416)
Georgi Gerganov [Mon, 7 Aug 2023 07:52:57 +0000 (10:52 +0300)]
metal : fix out-of-bounds access + inc concurrency nodes (#2416)

* metal : fix out-of-bounds access + style changes

* metal : increase concurrency nodes to 2*GGML_MAX_NODES

22 months ago[Makefile] Move ARM CFLAGS before compilation (#2536)
GiviMAD [Mon, 7 Aug 2023 06:21:46 +0000 (23:21 -0700)]
[Makefile] Move ARM CFLAGS before compilation (#2536)

22 months ago[Zig] Rewrite build for Zig 0.11 (#2514)
Henri Vasserman [Mon, 7 Aug 2023 05:35:53 +0000 (08:35 +0300)]
[Zig] Rewrite build for Zig 0.11 (#2514)

* zig build fixes

* Disable LTO on Windows.

22 months agoconsole : fix issue related to Windows 11 PowerShell console mode persistence (#2521)
DannyDaemonic [Sun, 6 Aug 2023 06:49:34 +0000 (23:49 -0700)]
console : fix issue related to Windows 11 PowerShell console mode persistence (#2521)

22 months agoconvert.py : add missing abstract methods for quantized data (#2491)
Keiichi Tabata [Sun, 6 Aug 2023 06:34:05 +0000 (15:34 +0900)]
convert.py : add missing abstract methods for quantized data (#2491)

22 months agoCUDA: faster k-quant mul_mat_q kernels (#2525)
Johannes Gäßler [Sat, 5 Aug 2023 16:20:44 +0000 (18:20 +0200)]
CUDA: faster k-quant mul_mat_q kernels (#2525)

22 months agofix firefox autoscroll (#2519)
Jonas Wunderlich [Fri, 4 Aug 2023 20:16:11 +0000 (20:16 +0000)]
fix firefox autoscroll (#2519)

22 months agoserver: regenerate completion.js.hpp (#2515)
Cebtenzzre [Fri, 4 Aug 2023 19:00:57 +0000 (15:00 -0400)]
server: regenerate completion.js.hpp (#2515)

22 months agoCUDA: use min compute capability of GPUs actually used (#2506)
Cebtenzzre [Fri, 4 Aug 2023 15:35:22 +0000 (11:35 -0400)]
CUDA: use min compute capability of GPUs actually used (#2506)

22 months agoCUDA: check if event is NULL before cudaStreamWaitEvent (#2505)
Cebtenzzre [Fri, 4 Aug 2023 15:34:32 +0000 (11:34 -0400)]
CUDA: check if event is NULL before cudaStreamWaitEvent (#2505)

Fixes #2503

22 months agoAdd --simple-io option for subprocesses and break out console.h and cpp (#1558)
DannyDaemonic [Fri, 4 Aug 2023 15:20:12 +0000 (08:20 -0700)]
Add --simple-io option for subprocesses and break out console.h and cpp (#1558)

22 months agoFixing race condition in server and partial stream handling in frontend. (#2391)
Stephen Nichols [Fri, 4 Aug 2023 11:37:24 +0000 (06:37 -0500)]
Fixing race condition in server and partial stream handling in frontend. (#2391)

* Fixing race condition in server.cpp and partial stream handling in completion.js

* Reverting assert edits.

* Adding newline to eof

22 months agoStream save llama context data to file instead of allocating entire buffer upfront...
l3utterfly [Fri, 4 Aug 2023 11:29:52 +0000 (19:29 +0800)]
Stream save llama context data to file instead of allocating entire buffer upfront (#2488)

* added stream saving context data to file to avoid allocating unnecessary amounts of memory

* generalised copying state data to file or buffer

* added comments explaining how copy_state_data works

* fixed trailing whitespaces

* fixed save load state example

* updated save load state to use public function in llama.cpp

* - restored breakage of the llama_copy_state_data API
- moved new logic for copying llama state data to internal function

* fixed function declaration order

* restored save load state example

* fixed whitepace

* removed unused llama-util.h include

* Apply suggestions from code review

Co-authored-by: slaren <redacted>
* Apply code review suggestions

Co-authored-by: slaren <redacted>
---------

Co-authored-by: slaren <redacted>
22 months agobuild : fix several cast and printf warnings (#2499)
Borislav Stanimirov [Fri, 4 Aug 2023 10:07:21 +0000 (13:07 +0300)]
build : fix several cast and printf warnings (#2499)

22 months agoexamples : generate JSON according to schema (#1887)
Evan Jones [Thu, 3 Aug 2023 02:05:44 +0000 (22:05 -0400)]
examples : generate JSON according to schema (#1887)

* examples : add JSON schema grammars

* complete JSON grammar

* ensure primitive types can be used as root of schema

* support integer type and adjust usage text

22 months agoCUDA: faster non k-quant mul_mat_q kernels (#2483)
Johannes Gäßler [Wed, 2 Aug 2023 16:04:04 +0000 (18:04 +0200)]
CUDA: faster non k-quant mul_mat_q kernels (#2483)

22 months agoCUDA: Fix models with output size != 32000 (#2480)
Johannes Gäßler [Wed, 2 Aug 2023 14:48:10 +0000 (16:48 +0200)]
CUDA: Fix models with output size != 32000 (#2480)

22 months agoreadme : add Aquila-7B model series to supported models (#2487)
ldwang [Wed, 2 Aug 2023 08:21:11 +0000 (16:21 +0800)]
readme : add Aquila-7B model series to supported models (#2487)

* support bpe tokenizer in convert

Signed-off-by: ldwang <redacted>
* support bpe tokenizer in convert

Signed-off-by: ldwang <redacted>
* support bpe tokenizer in convert, fix

Signed-off-by: ldwang <redacted>
* Add Aquila-7B models in README.md

Signed-off-by: ldwang <redacted>
* Up Aquila-7B models in README.md

Signed-off-by: ldwang <redacted>
---------

Signed-off-by: ldwang <redacted>
Co-authored-by: ldwang <redacted>
22 months agotests : Fix compilation warnings (Linux/GCC) (#2451)
Eve [Wed, 2 Aug 2023 08:06:19 +0000 (04:06 -0400)]
tests : Fix compilation warnings (Linux/GCC) (#2451)

* fix hellaswag print format, cast away warning in test-double-float

* c++11 cannot use designated initializers

* add static to test-grad0.c internal functions

* use memcpy in test-double-float.c

* port c tests to c++

* use initializer list for ggml_init_params

22 months agoreadme : Add Chinese LLaMA-2 / Alpaca-2 to supported models (#2475)
Yiming Cui [Wed, 2 Aug 2023 06:18:31 +0000 (14:18 +0800)]
readme : Add Chinese LLaMA-2 / Alpaca-2 to supported models (#2475)

* add support for chinese llama-2 / alpaca-2

* remove white spaces

22 months agofix a typo in examples/server/README.md (#2478)
Bono Lv [Tue, 1 Aug 2023 12:54:28 +0000 (20:54 +0800)]
fix a typo in examples/server/README.md (#2478)

22 months agoserver : Support dark mode (#2414)
ebraminio [Tue, 1 Aug 2023 08:56:23 +0000 (01:56 -0700)]
server : Support dark mode (#2414)

* server : Support dark mode

So it respects user system light / dark settings.

* Update index.html.hpp by running ./deps.sh

22 months agometal : add gqa8 kernel to allow llama-2-70B on metal (#2459)
Matteo Boschini [Tue, 1 Aug 2023 07:43:12 +0000 (09:43 +0200)]
metal : add gqa8 kernel to allow llama-2-70B on metal (#2459)

* Added gqa8 kernel to allow llama-2-70B on metal

* Update ggml-metal.m

Co-authored-by: Cebtenzzre <redacted>
* Extend kernel_mul_mat_f16_f32 to handle gqa broadcast

* Added ne03==ne13 assertion

---------

Co-authored-by: Cebtenzzre <redacted>
22 months agoCUDA: fixed LLAMA_FAST compilation option (#2473)
Johannes Gäßler [Mon, 31 Jul 2023 19:02:19 +0000 (21:02 +0200)]
CUDA: fixed LLAMA_FAST compilation option (#2473)

22 months agoCUDA: fixed cmake F16 option (#2471)
Johannes Gäßler [Mon, 31 Jul 2023 17:52:22 +0000 (19:52 +0200)]
CUDA: fixed cmake F16 option (#2471)

22 months agoCUDA: mmq CLI option, fixed mmq build issues (#2453)
Johannes Gäßler [Mon, 31 Jul 2023 13:44:35 +0000 (15:44 +0200)]
CUDA: mmq CLI option, fixed mmq build issues (#2453)

22 months agoCUDA: Implemented row flattening for non-glm RoPE (#2468)
Johannes Gäßler [Mon, 31 Jul 2023 12:32:30 +0000 (14:32 +0200)]
CUDA: Implemented row flattening for non-glm RoPE (#2468)

22 months agoCUDA: fewer memory bank conflicts for mul_mat_q (#2458)
Johannes Gäßler [Mon, 31 Jul 2023 11:18:51 +0000 (13:18 +0200)]
CUDA: fewer memory bank conflicts for mul_mat_q (#2458)

22 months agoFix Metal backend broken from the allocator changes (#2455)
slaren [Mon, 31 Jul 2023 09:02:53 +0000 (11:02 +0200)]
Fix Metal backend broken from the allocator changes (#2455)

* fix Metal backend broken from the allocator changes

23 months agoggml : add graph tensor allocator (#2411)
slaren [Sun, 30 Jul 2023 13:58:01 +0000 (15:58 +0200)]
ggml : add graph tensor allocator (#2411)

* ggml : add graph tensor allocator

* ggml : don't calculate data pointer of unallocated tensors when creating a view with an offset

* ggml : refactor ggml_view_Nd into ggml_view_tensor_offset

23 months agoCUDA: Quantized matrix matrix multiplication (#2160)
Johannes Gäßler [Sat, 29 Jul 2023 21:04:44 +0000 (23:04 +0200)]
CUDA: Quantized matrix matrix multiplication (#2160)

* mmq implementation for non k-quants

* q6_K

* q2_K

* q3_k

* q4_K

* vdr

* q5_K

* faster q8_1 loading

* loop unrolling

* add __restrict__

* q2_K sc_high

* GGML_CUDA_MMQ_Y

* Updated Makefile

* Update Makefile

* DMMV_F16 -> F16

* Updated README, CMakeLists

* Fix CMakeLists.txt

* Fix CMakeLists.txt

* Fix multi GPU out-of-bounds

23 months agoCUDA: faster multi GPU synchronization (#2448)
Johannes Gäßler [Sat, 29 Jul 2023 21:04:10 +0000 (23:04 +0200)]
CUDA: faster multi GPU synchronization (#2448)

23 months agoperplexity : add Hellaswag calculation (#2389)
klosax [Fri, 28 Jul 2023 18:25:36 +0000 (20:25 +0200)]
perplexity : add Hellaswag calculation (#2389)

* common.h : add hellaswag / remove perplexity-lines

* common.cpp : add hellaswag / remove perplexity-lines

* perplexity.cpp : add hellswag scores / remove perplexity-lines

* perplexity.cpp : clean up

* common.h : change default param value

* common.cpp : Change default param

* perplexity.cpp : alter wording

* common.h : alter wording

* common.cpp : alter wording

23 months agoggml : workaround for missing _mm256_setr_m128i in GCC < 8 in k_quants.c (#2405)
Lee [Fri, 28 Jul 2023 18:17:45 +0000 (02:17 +0800)]
ggml : workaround for missing _mm256_setr_m128i in GCC < 8 in k_quants.c (#2405)

23 months agollama : support more diverse tokenizers? (#2420)
eric8607242 [Fri, 28 Jul 2023 18:10:05 +0000 (02:10 +0800)]
llama : support more diverse tokenizers? (#2420)

* supporting more diverse tokenizers

* Update llama.cpp

---------

Co-authored-by: Georgi Gerganov <redacted>
23 months agoexamples : fix whitespace
Georgi Gerganov [Fri, 28 Jul 2023 18:05:08 +0000 (21:05 +0300)]
examples : fix whitespace

23 months agoexamples : server chat mode with llama2 (#2400)
nhamanasu [Fri, 28 Jul 2023 18:02:10 +0000 (03:02 +0900)]
examples : server chat mode with llama2 (#2400)

* add: server chat mode with llama2

* fix: remove the unnecessary last \n

23 months agoreadme : fix the description of the Tail free sampling (TFS) method (#2431)
Weird Constructor [Fri, 28 Jul 2023 08:44:43 +0000 (10:44 +0200)]
readme : fix the description of the Tail free sampling (TFS) method (#2431)

23 months agollama : use n_embd_gqa instead of n_embd to handle llama-2 70B (#2433)
Rand Xie [Fri, 28 Jul 2023 08:42:53 +0000 (01:42 -0700)]
llama : use n_embd_gqa instead of n_embd to handle llama-2 70B (#2433)

23 months agoObtaining LLaMA 2 instructions (#2308)
niansa/tuxifan [Fri, 28 Jul 2023 01:14:11 +0000 (03:14 +0200)]
Obtaining LLaMA 2 instructions (#2308)

* Obtaining LLaMA 2 instructions

* Removed sharing warning for LLaMA 2

* Linked TheBloke's GGML repos

* Add LLaMA 2 to list of supported models

* Added LLaMA 2 usage instructions

* Added links to LLaMA 2 70B models

23 months agoconvert.py : Update to support 70B HF format model files (#2427)
mj-shifu [Thu, 27 Jul 2023 20:39:17 +0000 (22:39 +0200)]
convert.py : Update to support 70B HF format model files (#2427)

* convert.py : fix llama 2 70b conversion from Huggingface

23 months agometal : disable graph concurrency optimization due to bug (#2413)
Georgi Gerganov [Thu, 27 Jul 2023 08:00:54 +0000 (11:00 +0300)]
metal : disable graph concurrency optimization due to bug (#2413)

23 months agoggml : fix assert in ggml_set_unary_op (#2410)
slaren [Wed, 26 Jul 2023 21:57:23 +0000 (23:57 +0200)]
ggml : fix assert in ggml_set_unary_op (#2410)

23 months agomake : build with -Wmissing-prototypes (#2394)
Cebtenzzre [Wed, 26 Jul 2023 18:00:04 +0000 (14:00 -0400)]
make : build with -Wmissing-prototypes (#2394)

23 months agoggml : allocate graphs in a context (#2392)
slaren [Wed, 26 Jul 2023 13:56:53 +0000 (15:56 +0200)]
ggml : allocate graphs in a context (#2392)

* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <redacted>
23 months agoAdd LLAMA_DEFAULT_RMS_EPS so we can change the default (#2384)
Kawrakow [Tue, 25 Jul 2023 15:35:53 +0000 (18:35 +0300)]
Add LLAMA_DEFAULT_RMS_EPS so we can change the default (#2384)

Co-authored-by: Iwan Kawrakow <redacted>