]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/log
pkg/ggml/sources/llama.cpp
13 months agometal : use `vm_allocate` instead of `posix_memalign` on macOS (#7078)
Gilad S [Wed, 8 May 2024 19:08:10 +0000 (22:08 +0300)]
metal : use `vm_allocate` instead of `posix_memalign` on macOS (#7078)

* fix: use `malloc` instead of `posix_memalign` in `ggml-metal.m` to make it not crash Electron proccesses

* fix: typo

* fix: use `vm_allocate` instead of `posix_memalign`

* fix: don't call `newBufferWithBytesNoCopy` with `NULL` when `ggml_metal_host_malloc` returns `NULL`

* fix: use `vm_allocate` only on macOS

13 months agomain : add --conversation / -cnv flag (#7108)
Dawid Potocki [Wed, 8 May 2024 14:32:32 +0000 (02:32 +1200)]
main : add --conversation / -cnv flag (#7108)

13 months agosgemm : AVX Q4_0 and Q8_0 (#6891)
Eve [Wed, 8 May 2024 14:29:23 +0000 (14:29 +0000)]
sgemm : AVX Q4_0 and Q8_0 (#6891)

* basic avx implementation

* style

* combine denibble with load

* reduce 256 to 128 (and back!) conversions

* sse load

* Update sgemm.cpp

* oops

oops

13 months agoserver : add_special option for tokenize endpoint (#7059)
Johan [Wed, 8 May 2024 12:27:58 +0000 (14:27 +0200)]
server : add_special option for tokenize endpoint (#7059)

13 months agoconvert.py : --vocab-only generates false but valid params (#7027)
20kdc [Wed, 8 May 2024 12:22:32 +0000 (13:22 +0100)]
convert.py : --vocab-only generates false but valid params (#7027)

An example of how this might be used in the style of baby-llama will be attached with this PR.

13 months agollama : add BPE pre-tokenization for Qwen2 (#7114)
Ren Xuancheng [Wed, 8 May 2024 12:06:43 +0000 (20:06 +0800)]
llama : add BPE pre-tokenization for Qwen2 (#7114)

* Add BPE pre-tokenization for Qwen2.

* minor : fixes

---------

Co-authored-by: Ren Xuancheng <redacted>
Co-authored-by: Georgi Gerganov <redacted>
13 months agoclean up json_value & server_log (#7142)
Xuan Son Nguyen [Wed, 8 May 2024 11:24:14 +0000 (13:24 +0200)]
clean up json_value & server_log (#7142)

13 months agoconvert : add BPE pre-tokenization for DBRX (#7132)
DAN™ [Wed, 8 May 2024 10:43:23 +0000 (06:43 -0400)]
convert : add BPE pre-tokenization for DBRX (#7132)

* Add BPE pre-tokenization for DBRX.

* Add vocab GGUFs.

* Remove test.

* Remove GGUFs.

13 months agopy : also print the normalizers
Georgi Gerganov [Wed, 8 May 2024 09:47:07 +0000 (12:47 +0300)]
py : also print the normalizers

13 months agocompare-llama-bench.py: add missing basicConfig (#7138)
Brian [Wed, 8 May 2024 08:54:39 +0000 (18:54 +1000)]
compare-llama-bench.py: add missing basicConfig (#7138)

* compare-llama-bench.py: add missing basicConfig

* compare-llama-bench.py: Add line break between error message and print_help()

* Add regular print() markdown table

13 months agoggml : introduce bfloat16 support (#6412)
Justine Tunney [Wed, 8 May 2024 06:30:09 +0000 (02:30 -0400)]
ggml : introduce bfloat16 support (#6412)

* Introduce bfloat16 support

Many models on Hugging Face (e.g. Mistral, TinyLLaMA) use bfloat16 as
their canonical floating point format.

      ┌sign
      │
      │   ┌exponent
      │   │
      │   │      ┌mantissa
      │   │      │
      │┌──┴───┐┌─┴───┐
    0b0000000000000000 brain16

This encoding has the same number of exponent bits as float32. That
makes conversion relatively straightforward, even in the absence of
hardware support. For example, converting brain16 to binary32 means
simply shifting 16 bits to the left.

      ┌sign
      │
      │   ┌exponent
      │   │
      │   │      ┌mantissa
      │   │      │
      │┌──┴───┐┌─┴───────────────────┐
    0b00000000000000000000000000000000 IEEE binary32

The issue is that converting bf16 to fp16 can result in information
loss. Only 13% of bf16 numbers can be precisely represented in fp16
which in practice ends up being 99.71% of Mistral 7b v0.2's weights
however there is currently no way other than fp32 to get the others

      ┌sign
      │
      │  ┌exponent
      │  │
      │  │    ┌mantissa
      │  │    │
      │┌─┴─┐┌─┴──────┐
    0b0000000000000000 IEEE binary16

This change fixes that, by adding a bf16 data type to GGML. Support
for CPU inference has been implemented along with optimizations for
the AVX2, AVX512, and AVX512BF16 ISAs. Perplexity on Mistral 7b 0.2
improves somewhere around -0.0024 to -0.0046 compared to using fp16

* Remove GGML code that's not needed

* Minimize the GGML API surface area for BF16

* Remove bf16 luts

* Make the GGML header look nicer

* Fix documentation

* Apply ggerganov's fixes for test-backend-ops

* Add BF16 code for new ggml_validate_row_data() function

13 months agometal : fix unused warning
Georgi Gerganov [Wed, 8 May 2024 06:14:50 +0000 (09:14 +0300)]
metal : fix unused warning

13 months agoFurther tidy on Android instructions README.md (#7077)
Jeximo [Wed, 8 May 2024 00:26:43 +0000 (21:26 -0300)]
Further tidy on Android instructions README.md (#7077)

* Further tidy on Android instructions README.md

Fixed some logic when following readme direction

* Clean up redundent information

A new user arriving will see simple directions on llama.cpp homepage

* corrected puncuation

Period after cmake, colon after termux

* re-word for clarity

method seems to be more correct, instead of alternative in this context

* Organized required packages per build type

building llama.cpp with NDK on a pc doesn't require installing clang, cmake, git, or wget in termux.

* README.md

corrected title

* fix trailing whitespace

13 months agoFixed save_imatrix to match old behaviour for MoE (#7099)
jukofyork [Wed, 8 May 2024 00:24:16 +0000 (01:24 +0100)]
Fixed save_imatrix to match old behaviour for MoE (#7099)

* Fixed save_imatrix to match old behaviour for MoE

This fix is simple and clear, but unnecessarily doubles the memory overhead..

* Fixed missing idx variable

* Unconditionally increment ncall

Co-authored-by: slaren <redacted>
* Fixed 2 bugs in save_imatrix()

- Fixed segfault bug because the counts vector needed to be created.
- Fixed pre-existing bug didn't actually add to the counts for "--combine" option.

* ncall needs summing too

* Trailing whitespace

---------

Co-authored-by: slaren <redacted>
13 months agoserver: fix incorrectly reported token probabilities (#7125)
Johannes Gäßler [Tue, 7 May 2024 21:07:58 +0000 (23:07 +0200)]
server: fix incorrectly reported token probabilities (#7125)

* server: normalize token probabilities

* fix temperature == 0.0f

13 months agoFix OLMo HF to GGUF conversion (#6910)
nopperl [Tue, 7 May 2024 19:39:43 +0000 (19:39 +0000)]
Fix OLMo HF to GGUF conversion (#6910)

13 months agoserver : update readme with undocumented options (#7013)
Kyle Mistele [Tue, 7 May 2024 18:44:29 +0000 (13:44 -0500)]
server : update readme with undocumented options (#7013)

13 months agoreadme : update hot topics
Georgi Gerganov [Tue, 7 May 2024 18:43:13 +0000 (21:43 +0300)]
readme : update hot topics

13 months agomain : update log text (EOS to EOG) (#7104)
RhinoDevel [Tue, 7 May 2024 17:51:31 +0000 (19:51 +0200)]
main : update log text (EOS to EOG) (#7104)

* Update log text (EOS to EOG)

The log text "found EOS" is no longer always correct, here, because there is now an is-EOG check that also returns true for EOT.

* Improve log msg. further by using "an" instead of "some".

As suggested, to avoid misunderstanding (no multiple EOG tokens found, just one).

13 months agodocs: fix typos (#7124)
omahs [Tue, 7 May 2024 15:20:33 +0000 (17:20 +0200)]
docs: fix typos (#7124)

* fix typo

* fix typos

* fix typo

* fix typos

* fix typo

* fix typos

13 months agoci : add GG_BUILD_EXTRA_TESTS_0 env (#7098)
Georgi Gerganov [Tue, 7 May 2024 08:08:49 +0000 (11:08 +0300)]
ci : add GG_BUILD_EXTRA_TESTS_0 env (#7098)

* ci : add GG_BUILD_EXTRA_TESTS_0 env

ggml-ci

* Update run.sh

ggml-ci

13 months agoAdd an option to build without CUDA VMM (#7067)
William Tambellini [Mon, 6 May 2024 18:12:14 +0000 (11:12 -0700)]
Add an option to build without CUDA VMM (#7067)

Add an option to build ggml cuda without CUDA VMM
resolves
https://github.com/ggerganov/llama.cpp/issues/6889
https://forums.developer.nvidia.com/t/potential-nvshmem-allocated-memory-performance-issue/275416/4

13 months agoflake.lock: Update (#7079)
Georgi Gerganov [Mon, 6 May 2024 15:36:06 +0000 (18:36 +0300)]
flake.lock: Update (#7079)

Flake lock file updates:

• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/9126214d0a59633752a136528f5f3b9aa8565b7d?narHash=sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm%2BGpZNw%3D' (2024-04-01)
  → 'github:hercules-ci/flake-parts/e5d10a24b66c3ea8f150e47dfdb0416ab7c3390e?narHash=sha256-yzcRNDoyVP7%2BSCNX0wmuDju1NUCt8Dz9%2BlyUXEI0dbI%3D' (2024-05-02)
• Updated input 'flake-parts/nixpkgs-lib':
    'github:NixOS/nixpkgs/d8fe5e6c92d0d190646fb9f1056741a229980089?dir=lib&narHash=sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk%3D' (2024-03-29)
  → 'https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz?narHash=sha256-QBx10%2Bk6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94%3D' (2024-05-02)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856?narHash=sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY%3D' (2024-04-25)
  → 'github:NixOS/nixpkgs/63c3a29ca82437c87573e4c6919b09a24ea61b0f?narHash=sha256-4cPymbty65RvF1DWQfc%2BBc8B233A1BWxJnNULJKQ1EY%3D' (2024-05-02)

Co-authored-by: github-actions[bot] <redacted>
13 months agominor : fix trailing whitespace
Georgi Gerganov [Mon, 6 May 2024 06:31:30 +0000 (09:31 +0300)]
minor : fix trailing whitespace

13 months agoAdding support for the --numa argument for llama-bench. (#7080)
kunnis [Sun, 5 May 2024 12:17:47 +0000 (07:17 -0500)]
Adding support for the --numa argument for llama-bench. (#7080)

13 months agoDisable benchmark on forked repo (#7034)
Sigbjørn Skjæret [Sun, 5 May 2024 11:38:55 +0000 (13:38 +0200)]
Disable benchmark on forked repo (#7034)

* Disable benchmark on forked repo

* only check owner on schedule event

* check owner on push also

* more readable as multi-line

* ternary won't work

* style++

* test++

* enable actions debug

* test--

* remove debug

* test++

* do debug where we can get logs

* test--

* this is driving me crazy

* correct github.event usage

* remove test condition

* correct github.event usage

* test++

* test--

* event_name is pull_request_target

* test++

* test--

* update ref checks

13 months agoreadme : add note that LLaMA 3 is not supported with convert.py (#7065)
Lyle Dean [Sun, 5 May 2024 05:21:46 +0000 (06:21 +0100)]
readme : add note that LLaMA 3 is not supported with convert.py (#7065)

13 months agocommand-r : add BPE pre-tokenization (#7063)
DAN™ [Sun, 5 May 2024 05:19:30 +0000 (01:19 -0400)]
command-r : add BPE pre-tokenization (#7063)

* Add BPE pre-tokenization for Command-R/R+.

* Bump transformers convert requirement.

* command-r : add individual digits regex

---------

Co-authored-by: Georgi Gerganov <redacted>
13 months agopy : logging and flake8 suppression refactoring (#7081)
Brian [Sun, 5 May 2024 05:07:48 +0000 (15:07 +1000)]
py : logging and flake8 suppression refactoring (#7081)

Set one as executable and add basicConfig()
to another. Also added noqa tag to test scripts.

13 months agogguf-split: add --no-tensor-first-split (#7072)
Xuan Son Nguyen [Sat, 4 May 2024 16:56:22 +0000 (18:56 +0200)]
gguf-split: add --no-tensor-first-split (#7072)

13 months agoTidy Android Instructions README.md (#7016)
Jeximo [Sat, 4 May 2024 16:10:15 +0000 (13:10 -0300)]
Tidy Android Instructions README.md (#7016)

* Tidy Android Instructions README.md

Remove CLBlast instructions(outdated), added OpenBlas.

* don't assume git is installed

Added apt install git, so that git clone works

* removed OpenBlas

Linked to Linux build instructions

* fix typo

Remove word "run"

* correct style

Co-authored-by: slaren <redacted>
* correct grammar

Co-authored-by: slaren <redacted>
* delete reference to Android API

* remove Fdroid reference, link directly to Termux

Fdroid is not required

Co-authored-by: slaren <redacted>
* Update README.md

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

Co-authored-by: slaren <redacted>
13 months agoFix Linux /sys cpu path to guess number of cores (#7064)
viric [Sat, 4 May 2024 13:26:53 +0000 (15:26 +0200)]
Fix Linux /sys cpu path to guess number of cores (#7064)

13 months agoIf first token generated from the server is the stop word the server will crash ...
maor-ps [Sat, 4 May 2024 09:06:40 +0000 (12:06 +0300)]
If first token generated from the server is the stop word the server will crash (#7038)

This will reproduce the issue in llama13b
{
'prompt': 'Q: hello world \nA: ',
 'stop': ['\n'],
 'temperature': 0.0,
 'n_predict': 10,
 'cache_prompt': True,
 'n_probs': 10
}

13 months agotests : add test-tokenizer-0.sh + fix some tokenizers (#7036)
Georgi Gerganov [Sat, 4 May 2024 05:32:32 +0000 (08:32 +0300)]
tests : add test-tokenizer-0.sh + fix some tokenizers (#7036)

* tests : add test-tokenizer-0.sh

* unicode : add all unicode number ranges

* starcoder : fix pre-tokenizer

* tests : add test that fails with DeepSeek tokenizers

* falcon : fix regex

* unicode : regenerate unicode tables

* refact : add tokenizer model

* lint : fix

* tests : disable failing tests

ggml-ci

* refact : add tests files

ggml-ci

* convert : print -> logging

ggml-ci

* lint : fix

* unicode : digit -> number

* phi-3 : update

14 months agoconvert.py : add python logging instead of print() (#6511)
Brian [Fri, 3 May 2024 19:36:41 +0000 (05:36 +1000)]
convert.py : add python logging instead of print() (#6511)

* convert.py: add python logging instead of print()

* convert.py: verbose flag takes priority over dump flag log suppression

* convert.py: named instance logging

* convert.py: use explicit logger id string

* convert.py: convert extra print() to named logger

* convert.py: sys.stderr.write --> logger.error

* *.py: Convert all python scripts to use logging module

* requirements.txt: remove extra line

* flake8: update flake8 ignore and exclude to match ci settings

* gh-actions: add flake8-no-print to flake8 lint step

* pre-commit: add flake8-no-print to flake8 and also update pre-commit version

* convert-hf-to-gguf.py: print() to logger conversion

* *.py: logging basiconfig refactor to use conditional expression

* *.py: removed commented out logging

* fixup! *.py: logging basiconfig refactor to use conditional expression

* constant.py: logger.error then exit should be a raise exception instead

* *.py: Convert logger error and sys.exit() into a raise exception (for atypical error)

* gguf-convert-endian.py: refactor convert_byteorder() to use tqdm progressbar

* verify-checksum-model.py: This is the result of the program, it should be printed to stdout.

* compare-llama-bench.py: add blank line for readability during missing repo response

* reader.py: read_gguf_file() use print() over logging

* convert.py: warning goes to stderr and won't hurt the dump output

* gguf-dump.py: dump_metadata() should print to stdout

* convert-hf-to-gguf.py: print --> logger.debug or ValueError()

* verify-checksum-models.py: use print() for printing table

* *.py: refactor logging.basicConfig()

* gguf-py/gguf/*.py: use __name__ as logger name

Since they will be imported and not run directly.

* python-lint.yml: use .flake8 file instead

* constants.py: logger no longer required

* convert-hf-to-gguf.py: add additional logging

* convert-hf-to-gguf.py: print() --> logger

* *.py: fix flake8 warnings

* revert changes to convert-hf-to-gguf.py for get_name()

* convert-hf-to-gguf-update.py: use triple quoted f-string instead

* *.py: accidentally corrected the wrong line

* *.py: add compilade warning suggestions and style fixes

14 months agollama : rename ctx to user_data in progress_callback (#7045)
Daniel Bevenius [Fri, 3 May 2024 13:24:30 +0000 (15:24 +0200)]
llama : rename ctx to user_data in progress_callback (#7045)

* llama : rename ctx to user_data in progress_callback

This commit renames the `ctx` parameter to `user_data` in the
`llama_progress_callback` typedef.

The motivation for this is that other callbacks use `user_data` or
`data`, and using `ctx` in this case might be confusing as it could be
confused with `llama_context`.

---------

Signed-off-by: Daniel Bevenius <redacted>
14 months agoRemove .attention from skipped tensors to match more accurately (#7051)
Bartowski [Thu, 2 May 2024 23:49:09 +0000 (19:49 -0400)]
Remove .attention from skipped tensors to match more accurately (#7051)

14 months agochore: fix typo in llama.cpp (#7032)
alwqx [Thu, 2 May 2024 15:56:41 +0000 (23:56 +0800)]
chore: fix typo in llama.cpp (#7032)

Co-authored-by: Jared Van Bortel <redacted>
14 months agoUpdate LOG_IMPL and LOG_TEE_IMPL (#7029)
Andrew Downing [Wed, 1 May 2024 21:31:30 +0000 (17:31 -0400)]
Update LOG_IMPL and LOG_TEE_IMPL (#7029)

ROCm clang defines _MSC_VER which results in the wrong implementation of LOG_IMPL and LOG_TEE_IMPL being compiled.

This fixes https://github.com/ggerganov/llama.cpp/issues/6972

14 months agomain : fix off by one error for context shift (#6921)
l3utterfly [Wed, 1 May 2024 19:27:41 +0000 (04:27 +0900)]
main : fix off by one error for context shift (#6921)

14 months agoServer: add tests for batch size, different seeds (#6950)
Johannes Gäßler [Wed, 1 May 2024 15:52:55 +0000 (17:52 +0200)]
Server: add tests for batch size, different seeds (#6950)

14 months agoCUDA: CUDART < 11.7 workaround for __hmax, __hmax2 (#7019)
Johannes Gäßler [Wed, 1 May 2024 12:46:37 +0000 (14:46 +0200)]
CUDA: CUDART < 11.7 workaround for __hmax, __hmax2 (#7019)

14 months agoci : exempt confirmed bugs from being tagged as stale (#7014)
slaren [Wed, 1 May 2024 05:13:59 +0000 (07:13 +0200)]
ci : exempt confirmed bugs from being tagged as stale (#7014)

14 months agoperplexity: more statistics, added documentation (#6936)
Johannes Gäßler [Tue, 30 Apr 2024 21:36:27 +0000 (23:36 +0200)]
perplexity: more statistics, added documentation (#6936)

* perplexity: more statistics, added documentation

* add LLaMA 3 8b scoreboard

14 months agoswitch to using localizedDescription (#7010)
Kevin Gibbons [Tue, 30 Apr 2024 15:14:02 +0000 (08:14 -0700)]
switch to using localizedDescription (#7010)

14 months agometal : remove deprecated error code (#7008)
Georgi Gerganov [Tue, 30 Apr 2024 12:52:21 +0000 (15:52 +0300)]
metal : remove deprecated error code (#7008)

14 months agometal : log more info on error (#6987)
Kevin Gibbons [Tue, 30 Apr 2024 09:34:50 +0000 (02:34 -0700)]
metal : log more info on error (#6987)

14 months agoggml : add Flash Attention (#5021)
Georgi Gerganov [Tue, 30 Apr 2024 09:16:08 +0000 (12:16 +0300)]
ggml : add Flash Attention (#5021)

* ggml : add ggml_flash_attn_ext API

* ggml : fix GQA support in ggml_flash_attn_ext

* ggml : online attention (CPU)

* metal : initial implementation

* metal : f16 precision

* metal : reduce branches

* metal : specialize for head size

* wip : 8 rows per simd group

* wip : 4 rows per simd group

* wip : template for rows per warp

* metal : parallelize across KV size

* metal : parallel reduce across heads

* metal : efficient flash_attn_f16 implementation

* metal : avoid redundant loads of the attention

* metal : scale and mask in matrix form

* metal : fix comment

* llama : avoid ggml_cast, use F32 query

* metal : add parallel reduce version (disabled)

* metal : move output into local memory + optimize

- the result from each simdgroup now stays in the registers
- significantly reduced SRAM usage
- more efficient skipping of -INF blocks
- avoid simdgroup barrier in hot loop
- add comments

* metal : add tests, fix scaling, support C > 32

* metal : improve precision

* ggml : fix f16 mad

* metal : minor

* metal : support Q > 8

* tests : add ATTN tests

* metal : disable buffer allocation logs

* tests : more

* metal : faster inner loop for C == 32

* metal : fix array initialization

* tests : ifdef

* ggml : switch to padded F16 mask for ggml_soft_max, ggml_flash_attn_ext

* ggml : fix ggml_soft_max mask requirement

* cuda : fix soft_max to use correct mask size

* cuda : add flash_attn kernel (wip)

* metal : optimize softmax for C > 32

* metal : optimize softmax

* tests : minor fix

* cuda : avoid zeroing fragments

* tests : update dims

* cuda : fix __hisinf() result check

* cuda : avoid warp_reduce for smax

* cuda : use int instead of int64_t

Noticeably improves performance (thanks to Johannes)

* cuda : make loops use the same loop values

Thanks Johannes again for the tip

* cuda : unroll some of the loops

* cuda : avoid __hisinf branches

* cuda : use half2 in softmax

* cuda : switch to 1 warp for bs > 16

* cuda : speed-up reduce part of the kernel

* cuda : unroll Q*K^T loop

* cuda : fix -INF block check

* cuda : simplify softmax

* cuda : fix matrix names

* cuda : minor

* llama : adapt to F16 KQ_pos

* llama : adapt new models to F16 KQ_mask

* ggml : fix F16 store (ARM NEON)

* llama : fix type of KQ_mask and KQ_pos

* ggml : fix CPU soft_max

* tests : add hs=256

* cuda : fix build

* metal : improve perf via smaller int registers

* cuda : adapt soft_max to F16 mask and pos

* CUDA: faster FlashAttention, kernel for bs == 1

* 16 cols for Phi-2

* no vec for hs, no hs==256 ncols==32 for Volta

* adjust kernel selection logic

* 4 warps, 256 stride for all D

* no ncols == 64

* Multiple parallel blocks for batch size 1

* fix compile warnings

* fix excessive KQ_b loads

* fix cmake build

* fix KV cache padding, NaN from INFINITY (#6438)

* llama : flash_attn cparam + fix defrag

* server: support flash_attn param

* server: bench: enable flash_attn param

* CUDA: refactor host code, dyn. par. blocks

* fix flash_attn_vec_f16 race condition

* flush softmax exp below threshold to 0

* store temp KQ in registers

* Calculate KQ as FP32 if KQV has GGML_PREC_F32

* Add __hgt2_mask implementation for CUDA 11

* fix KQ FP32 precision fpr parallel_blocks > 1

* llama-bench : add -fa,--flash-attn arg

* metal : add BS=1 kernel for flash attention (#6508)

* metal : add BS=1 kernel for flash attention (wip)

* metal : support more than 1 warps

* metal : opts

* metal : opt

* metal : switch to parallel reduce

* metal : reduce registers

* metal : simplify

* metal : initial FA vec kernel

* metal : use F32 attention accumulators

* batched-bench : add fattn arg

* llama : simplify llama_build_kv_store

ggml-ci

* llama : adapt build_olmo to changes

* ggml : fix arm fp16 store on windows

* metal : clean-up

* metal : clean-up kernel code

* metal : minor

* tests : remove benchmarks

ggml-ci

* ggml : fix avx512 const correctness

ggml-ci

* ggml : fix soft_max with bias on CPU

ggml-ci

* common : print --flash-attn in help

* ggml : fix num dimensions in ggml_flash_attn_ext

* llama : force disable flash attention for incompatible models

* ggml : ggml_soft_max support F16/F32 mask/pos

ggml-ci

* cuda : uint -> uint32_t

* cuda : "constexpr dim3" -> "const dim3"

ggml-ci

* cuda : try to fix __hgt2_mask

ggml-ci

* ggml : add TODO's for F16/F32 mask/pos support in other backends

* llama : replace bool need_kq_pos with use_alibi

* llama : prep ALiBi support for BERT models

ggml-ci

* llama : fix n_batch requirements

ggml-ci

* cont

* server : add help for --flash-attn arg

* llama : disable FA for AMD

* tests : remove TMP_ATTN_BENCH

ggml-ci

* llama : support save/load state with FA enabled

ggml-ci

* ci : add CUDA save-load-state tests

ggml-ci

* llama : llama_kv_cache_clear zeroes data + fix save-load seq

ggml-ci

* llama : fix copy-paste errors, add TODO

* llama : disallow incompatible states

* llama : update llama_state_get_size after v_trans field

* metal : remove tmp log

* llama : add static reminder for llama_state_get_size

* metal : fix max nsg

ggml-ci

* ci : fix arg order

ggml-ci

---------

Co-authored-by: Johannes Gäßler <redacted>
Co-authored-by: Pierrick HYMBERT <redacted>
14 months agoconvert : use utf8 encoding (#7000)
Georgi Gerganov [Tue, 30 Apr 2024 08:05:25 +0000 (11:05 +0300)]
convert : use utf8 encoding (#7000)

* convert : use utf8 encoding

* convert : update instructions and warning message

14 months agoImprove usability of --model-url & related flags (#6930)
Olivier Chafik [Mon, 29 Apr 2024 23:52:50 +0000 (00:52 +0100)]
Improve usability of --model-url & related flags (#6930)

* args: default --model to models/ + filename from --model-url or --hf-file (or else legacy models/7B/ggml-model-f16.gguf)

* args: main & server now call gpt_params_handle_model_default

* args: define DEFAULT_MODEL_PATH + update cli docs

* curl: check url of previous download (.json metadata w/ url, etag & lastModified)

* args: fix update to quantize-stats.cpp

* curl: support legacy .etag / .lastModified companion files

* curl: rm legacy .etag file support

* curl: reuse regex across headers callback calls

* curl: unique_ptr to manage lifecycle of curl & outfile

* curl: nit: no need for multiline regex flag

* curl: update failed test (model file collision) + gitignore *.gguf.json

14 months agoExtending grammar integration tests (#6644)
Clint Herron [Mon, 29 Apr 2024 18:40:14 +0000 (14:40 -0400)]
Extending grammar integration tests (#6644)

* Cleaning up integration tests to share code between tests and make it simpler to add new tests.

* Add tests around quantifiers to ensure both matching and non-matching compliance.

* Add slightly more complex grammar with quantifiers to test references with quantifiers.

* Fixing build when C++17 is not present.

* Separating test calls to give more helpful stack traces on failure. Adding verbose messages to give visibility for what is being tested.

* Adding quotes around strings to explicitly show whitespace

* Removing trailing whitespace.

* Implementing suggestions from @ochafik -- grammars and test strings now print and flush before tests to aid in debugging segfaults and whatnot.

* Cleaning up forgotten symbols. Modifying simple test to use test harness. Added comments for more verbose descriptions of what each test is accomplishing.

* Unicode symbol modifications to hopefully make log easier to parse visually.

14 months agomain : fix typo in comment in main.cpp (#6985)
Daniel Bevenius [Mon, 29 Apr 2024 17:56:59 +0000 (19:56 +0200)]
main : fix typo in comment in main.cpp (#6985)

Signed-off-by: Daniel Bevenius <redacted>
14 months agobuild(cmake): simplify instructions (`cmake -B build && cmake --build build ...`...
Olivier Chafik [Mon, 29 Apr 2024 16:02:45 +0000 (17:02 +0100)]
build(cmake): simplify instructions (`cmake -B build && cmake --build build ...`) (#6964)

* readme: cmake . -B build && cmake --build build

* build: fix typo

Co-authored-by: Jared Van Bortel <redacted>
* build: drop implicit . from cmake config command

* build: remove another superfluous .

* build: update MinGW cmake commands

* Update README-sycl.md

Co-authored-by: Neo Zhang Jianyu <redacted>
* build: reinstate --config Release as not the default w/ some generators + document how to build Debug

* build: revert more --config Release

* build: nit / remove -H from cmake example

* build: reword debug instructions around single/multi config split

---------

Co-authored-by: Jared Van Bortel <redacted>
Co-authored-by: Neo Zhang Jianyu <redacted>
14 months agoci : tmp disable gguf-split (#6983)
Georgi Gerganov [Mon, 29 Apr 2024 15:36:39 +0000 (18:36 +0300)]
ci : tmp disable gguf-split (#6983)

ggml-ci

14 months agoggml : fix __MSC_VER -> _MSC_VER (#6977)
Georgi Gerganov [Mon, 29 Apr 2024 14:55:02 +0000 (17:55 +0300)]
ggml : fix __MSC_VER -> _MSC_VER (#6977)

ggml-ci

14 months agollava-cli : multiple images (#6969)
cpumaxx [Mon, 29 Apr 2024 14:34:24 +0000 (07:34 -0700)]
llava-cli : multiple images (#6969)

Co-authored-by: root <redacted>
14 months agoreadme : update hot topics
Georgi Gerganov [Mon, 29 Apr 2024 14:06:19 +0000 (17:06 +0300)]
readme : update hot topics

14 months agollama : fix BPE pre-tokenization (#6920)
Georgi Gerganov [Mon, 29 Apr 2024 13:58:41 +0000 (16:58 +0300)]
llama : fix BPE pre-tokenization (#6920)

* merged the changes from deepseeker models to main branch

* Moved regex patterns to unicode.cpp and updated unicode.h

* Moved header files

* Resolved issues

* added and refactored unicode_regex_split and related functions

* Updated/merged the deepseek coder pr

* Refactored code

* Adding unicode regex mappings

* Adding unicode regex function

* Added needed functionality, testing remains

* Fixed issues

* Fixed issue with gpt2 regex custom preprocessor

* unicode : fix? unicode_wstring_to_utf8

* lint : fix whitespaces

* tests : add tokenizer tests for numbers

* unicode : remove redundant headers

* tests : remove and rename tokenizer test scripts

* tests : add sample usage

* gguf-py : reader prints warnings on duplicate keys

* llama : towards llama3 tokenization support (wip)

* unicode : shot in the dark to fix tests on Windows

* unicode : first try custom implementations

* convert : add "tokenizer.ggml.pre" GGUF KV (wip)

* llama : use new pre-tokenizer type

* convert : fix pre-tokenizer type writing

* lint : fix

* make : add test-tokenizer-0-llama-v3

* wip

* models : add llama v3 vocab file

* llama : adapt punctuation regex + add llama 3 regex

* minor

* unicode : set bomb

* unicode : set bomb

* unicode : always use std::wregex

* unicode : support \p{N}, \p{L} and \p{P} natively

* unicode : try fix windows

* unicode : category support via std::regex

* unicode : clean-up

* unicode : simplify

* convert : add convert-hf-to-gguf-update.py

ggml-ci

* lint : update

* convert : add falcon

ggml-ci

* unicode : normalize signatures

* lint : fix

* lint : fix

* convert : remove unused functions

* convert : add comments

* convert : exercise contractions

ggml-ci

* lint : fix

* cmake : refactor test targets

* tests : refactor vocab tests

ggml-ci

* tests : add more vocabs and tests

ggml-ci

* unicode : cleanup

* scripts : ignore new update script in check-requirements.sh

* models : add phi-3, mpt, gpt-2, starcoder

* tests : disable obsolete

ggml-ci

* tests : use faster bpe test

ggml-ci

* llama : more prominent warning for old BPE models

* tests : disable test-tokenizer-1-bpe due to slowness

ggml-ci

---------

Co-authored-by: Jaggzh <redacted>
Co-authored-by: Kazim Abrar Mahi <redacted>
14 months agosampling : use std::random_device{}() for default random seed (#6962)
David Renshaw [Mon, 29 Apr 2024 13:35:45 +0000 (09:35 -0400)]
sampling : use std::random_device{}() for default random seed (#6962)

14 months agoconvert : fix conversion of some BERT embedding models (#6937)
Christian Zhou-Zheng [Mon, 29 Apr 2024 13:34:41 +0000 (09:34 -0400)]
convert : fix conversion of some BERT embedding models (#6937)

14 months agomake : change GNU make default CXX from g++ to c++ (#6966)
Przemysław Pawełczyk [Mon, 29 Apr 2024 13:08:20 +0000 (15:08 +0200)]
make : change GNU make default CXX from g++ to c++ (#6966)

14 months agoci : add building in MSYS2 environments (Windows) (#6967)
Przemysław Pawełczyk [Mon, 29 Apr 2024 12:59:47 +0000 (14:59 +0200)]
ci : add building in MSYS2 environments (Windows) (#6967)

14 months agollama : fix typo LAMMAFILE -> LLAMAFILE (#6974)
Johannes Gäßler [Mon, 29 Apr 2024 12:36:22 +0000 (14:36 +0200)]
llama : fix typo LAMMAFILE -> LLAMAFILE (#6974)

14 months agoFix more int overflow during quant (PPL/CUDA). (#6563)
DAN™ [Sun, 28 Apr 2024 22:38:44 +0000 (18:38 -0400)]
Fix more int overflow during quant (PPL/CUDA). (#6563)

* Fix more int overflow during quant.

* Fix some more int overflow in softmax.

* Revert back to int64_t.

14 months agogguf : enforce that tensor names are unique (#6905)
Xuan Son Nguyen [Sun, 28 Apr 2024 15:36:18 +0000 (17:36 +0200)]
gguf : enforce that tensor names are unique (#6905)

* not allow adding duplicated tensor name

* no duplicated tensor while reading gguf

* typo

* throw exception inside llama_model_loader

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

Co-authored-by: slaren <redacted>
14 months agoadd device version in device list (#6959)
Neo Zhang [Sun, 28 Apr 2024 14:40:31 +0000 (22:40 +0800)]
add device version in device list (#6959)

Co-authored-by: arthw <>
14 months agoflake.lock: Update
github-actions[bot] [Sun, 28 Apr 2024 00:18:27 +0000 (00:18 +0000)]
flake.lock: Update

Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/5c24cf2f0a12ad855f444c30b2421d044120c66f?narHash=sha256-XtTSSIB2DA6tOv%2Bl0FhvfDMiyCmhoRbNB%2B0SeInZkbk%3D' (2024-04-19)
  → 'github:NixOS/nixpkgs/7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856?narHash=sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY%3D' (2024-04-25)

14 months agoReplace "alternative" boolean operator in conditional compilation directive (#6949)
mgroeber9110 [Sat, 27 Apr 2024 19:02:06 +0000 (21:02 +0200)]
Replace "alternative" boolean operator in conditional compilation directive (#6949)

14 months agoci: server: tests python env on github container ubuntu latest / fix n_predict (...
Pierrick Hymbert [Sat, 27 Apr 2024 15:50:48 +0000 (17:50 +0200)]
ci: server: tests python env on github container ubuntu latest / fix n_predict (#6935)

* ci: server: fix python env

* ci: server: fix server tests after #6638

* ci: server: fix windows is not building PR branch

14 months agoReset schedule earlier to allow overlap with ggml graph computation on device (#6933)
agray3 [Fri, 26 Apr 2024 18:08:30 +0000 (19:08 +0100)]
Reset schedule earlier to allow overlap with ggml graph computation on device (#6933)

* Reset schedule earlier to allow overlap with graph computation on device

14 months agoquantize: add imatrix and dataset metadata in GGUF (#6658)
Pierrick Hymbert [Fri, 26 Apr 2024 18:06:33 +0000 (20:06 +0200)]
quantize: add imatrix and dataset metadata in GGUF (#6658)

* imatrix: save the dataset file used in the output file

* llama: support kv overrides type string string

* common: factorize KV Overrides parsing between common and server

* quantize: add imatrix n entries and dataset KV metadata
quantize: factorize KV Overrides parsing between common
#6656

* llama: remove kv override str_value initialization as it does not compile on some toolchain

* quantize: add imatrix m_last_call as `quantize.imatrix.chunks_count`

* quantize: add imatrix filename in KV

* llama: add llama_model_kv_override_free

* common: add llama_model_kv_override_free
common: free kv override if used after model loading

* llama: finally move the string KV override value to the stack

* llama : minor

* no need to add a NUL to the std::vector, std::string can be initialized from a pair of iterators.

Co-authored-by: slaren <redacted>
* kv override: ensure string termination

---------

Co-authored-by: Georgi Gerganov <redacted>
Co-authored-by: slaren <redacted>
14 months agoadd basic tensor data validation function (#6884)
slaren [Fri, 26 Apr 2024 16:39:58 +0000 (18:39 +0200)]
add basic tensor data validation function (#6884)

* add basic tensor data validation function

* add --check-tensors command line argument

tensor validation is disabled by default and can be enabled by adding
`--check-tensors` to the command line arguments.

quantize always validates tensors.

14 months agogguf : fix mismatch between alloc and free functions (#6929)
slaren [Fri, 26 Apr 2024 15:07:42 +0000 (17:07 +0200)]
gguf : fix mismatch between alloc and free functions (#6929)

14 months agollamafile : use 64-bit integers in sgemm (#6928)
Justine Tunney [Fri, 26 Apr 2024 14:05:33 +0000 (10:05 -0400)]
llamafile : use 64-bit integers in sgemm (#6928)

14 months agoci: server: fix python installation (#6925)
Pierrick Hymbert [Fri, 26 Apr 2024 10:27:25 +0000 (12:27 +0200)]
ci: server: fix python installation (#6925)

14 months agoserver: stop generation at `n_ctx_train` if `n_predict` is not set (#6638)
Pierrick Hymbert [Fri, 26 Apr 2024 10:15:30 +0000 (12:15 +0200)]
server: stop generation at `n_ctx_train` if `n_predict` is not set (#6638)

* server: cap n_predict if not set to n_ctx_train

* server: fix infinite loop

* server: infinite loop, move in process_token
server: infinite loop: set stop limit to true

* minor: spaces

* minor: spaces

* server: include prompt tokens in the EOS limit

14 months agoci: server: fix python installation (#6922)
Pierrick Hymbert [Fri, 26 Apr 2024 09:11:51 +0000 (11:11 +0200)]
ci: server: fix python installation (#6922)

14 months agoMerge pull request from GHSA-p5mv-gjc5-mwqv
Georgi Gerganov [Fri, 26 Apr 2024 07:41:53 +0000 (10:41 +0300)]
Merge pull request from GHSA-p5mv-gjc5-mwqv

* always use calloc

clamp n_kv on failure to read a kv

* ggml : alternative ctx->header.n_kv update

---------

Co-authored-by: slaren <redacted>
14 months agoci: server: fix python installation (#6918)
Pierrick Hymbert [Fri, 26 Apr 2024 07:27:49 +0000 (09:27 +0200)]
ci: server: fix python installation (#6918)

14 months agoci: fix concurrency for pull_request_target (#6917)
Pierrick Hymbert [Fri, 26 Apr 2024 07:26:59 +0000 (09:26 +0200)]
ci: fix concurrency for pull_request_target (#6917)

14 months agobench: server add stop word for PHI-2 (#6916)
Pierrick Hymbert [Fri, 26 Apr 2024 07:26:16 +0000 (09:26 +0200)]
bench: server add stop word for PHI-2 (#6916)

14 months agollava : add support for moondream vision language model (#6899)
vik [Thu, 25 Apr 2024 19:38:31 +0000 (12:38 -0700)]
llava : add support for moondream vision language model (#6899)

* add support for moondream vision language model

This required making the following changes to the CLIP model:

1. Support for patch embedding bias.
2. Make class embedding and pre-layernorm optional.
3. Add support for post-layernorm.

* Update examples/llava/clip.cpp

---------

Co-authored-by: Georgi Gerganov <redacted>
14 months agocmake : restore LLAMA_LLAMAFILE_DEFAULT
Georgi Gerganov [Thu, 25 Apr 2024 18:31:17 +0000 (21:31 +0300)]
cmake : restore LLAMA_LLAMAFILE_DEFAULT

14 months agocmake : remove obsolete ANDROID check
Georgi Gerganov [Thu, 25 Apr 2024 15:59:51 +0000 (18:59 +0300)]
cmake : remove obsolete ANDROID check

14 months agollama : synchronize before get/set session data (#6911)
slaren [Thu, 25 Apr 2024 15:59:03 +0000 (17:59 +0200)]
llama : synchronize before get/set session data (#6911)

14 months agoci : tmp disable slow tests
Georgi Gerganov [Thu, 25 Apr 2024 14:06:27 +0000 (17:06 +0300)]
ci : tmp disable slow tests

14 months agoreadme : update model list (#6908)
BarfingLemurs [Thu, 25 Apr 2024 13:52:28 +0000 (09:52 -0400)]
readme : update model list (#6908)

* Update README.md

* missing space

* llama3 !

14 months agollama : check that all the tensor data is in the model file (#6885)
slaren [Thu, 25 Apr 2024 13:23:47 +0000 (15:23 +0200)]
llama : check that all the tensor data is in the model file (#6885)

* llama : check that all the tensor data is in the model file

* also check for unsigned overflow

14 months agoggml : fix redefinition of vaddvq_f32 for 32-bit ARM (#6906)
Georgi Gerganov [Thu, 25 Apr 2024 12:48:25 +0000 (15:48 +0300)]
ggml : fix redefinition of vaddvq_f32 for 32-bit ARM (#6906)

14 months agoclip : rename lerp function to avoid conflict (#6894)
Daniel Bevenius [Thu, 25 Apr 2024 12:38:14 +0000 (14:38 +0200)]
clip : rename lerp function to avoid conflict (#6894)

This commit renamesthe lerp (linear interpolation) function in clip.cpp
to avoid a conflict with the lerp function in the <cmath> standard C++
library when using c++20.

The motivation for this change is to enable projects that use c++20 to
be able to compile clip.cpp without having to resort to patching it. The
lerp function was added to cmath in version C++20 (202002L) and is why
this is not causing any issue at the moment as C++11/C++17 is currently
used by llama.cpp.

I realize that llama.cpp uses either C++11 (or C++17 in the case for
SYCL) but wanted to ask if this would be an acceptable change just the
same.

Refs: https://en.cppreference.com/w/cpp/numeric/lerp

Signed-off-by: Daniel Bevenius <redacted>
14 months agoggml : fix MIN / MAX macros (#6904)
Georgi Gerganov [Thu, 25 Apr 2024 12:12:28 +0000 (15:12 +0300)]
ggml : fix MIN / MAX macros (#6904)

ggml-ci

14 months agotests : minor bash stuff (#6902)
Georgi Gerganov [Thu, 25 Apr 2024 11:27:20 +0000 (14:27 +0300)]
tests : minor bash stuff (#6902)

* tests : minor bash stuff

ggml-ci

* llama : fix build

ggml-ci

* tests : fix CUR_DIR -> ROOT_DIR

ggml-ci

* tests : fix fname

ggml-ci

14 months agoquantize : add '--keep-split' to quantize model into shards (#6688)
jiez [Thu, 25 Apr 2024 10:29:35 +0000 (18:29 +0800)]
quantize : add '--keep-split' to quantize model into shards (#6688)

* Implement '--keep-split' to quantize model into several shards

* Add test script

* Update examples/quantize/quantize.cpp

Co-authored-by: Georgi Gerganov <redacted>
* Split model correctly even if tensor id is out-of-order

* Update llama_model_quantize_params

* Fix preci failures

---------

Co-authored-by: z5269887 <redacted>
Co-authored-by: Georgi Gerganov <redacted>
14 months agoREADME: add graphic for matrix multiplication (#6881)
Johannes Gäßler [Wed, 24 Apr 2024 19:29:13 +0000 (21:29 +0200)]
README: add graphic for matrix multiplication (#6881)

14 months agollama : add llama_get_pooling_type function (#6862)
Douglas Hanley [Wed, 24 Apr 2024 13:10:07 +0000 (08:10 -0500)]
llama : add llama_get_pooling_type function (#6862)

* add llama_get_pooling_type function

* fix argument name, move with ctx funcs

14 months agoserver : do not apply Markdown formatting in code sections (#6850)
mgroeber9110 [Wed, 24 Apr 2024 10:54:24 +0000 (12:54 +0200)]
server : do not apply Markdown formatting in code sections (#6850)

14 months agocommon : revert showing control tokens by default for server (#6860)
Kyle Mistele [Wed, 24 Apr 2024 10:15:29 +0000 (05:15 -0500)]
common : revert showing control tokens by default for server (#6860)

* fix: revert showing control tokens by default

* feat: revert changes to default behavior of llama_token_to_piece; provide overridden declaration to receive "bool special" param to toggle showing control tokens

* feat: use the overridden declaration of llama_token_to_piece from common/common.cpp to specify "false" so that control tokens are not shown in chat completion responses"

* common : simplify

---------

Co-authored-by: Georgi Gerganov <redacted>
14 months agoServer: fix seed for multiple slots (#6835)
Johannes Gäßler [Wed, 24 Apr 2024 09:08:36 +0000 (11:08 +0200)]
Server: fix seed for multiple slots (#6835)

* Server: add tests for consistent results

* sampling: separate rng per sampling context

14 months agoggml : move 32-bit arm compat in ggml-impl.h (#6865)
Georgi Gerganov [Wed, 24 Apr 2024 09:00:07 +0000 (12:00 +0300)]
ggml : move 32-bit arm compat in ggml-impl.h (#6865)

ggml-ci

14 months agollama : add phi 3 chat template (#6857)
Tristan Druyen [Wed, 24 Apr 2024 08:52:37 +0000 (10:52 +0200)]
llama : add phi 3 chat template (#6857)

* Add phi 3 chat template & tests

* test : fix chat template result

---------

Co-authored-by: Georgi Gerganov <redacted>