]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/log
pkg/ggml/sources/llama.cpp
2 years agoggml : fix Q4_3 quantization
Georgi Gerganov [Thu, 20 Apr 2023 17:44:05 +0000 (20:44 +0300)]
ggml : fix Q4_3 quantization

Broke it during conflict resolution in last PR

2 years agollama : multi-threaded quantization (#1075)
Kawrakow [Thu, 20 Apr 2023 17:42:27 +0000 (19:42 +0200)]
llama : multi-threaded quantization (#1075)

* Multi-threading quantization.

Not much gain for simple quantizations, bit it will be important
for quantizations that require more CPU cycles.

* Multi-threading for quantize-stats

It now does the job in ~14 seconds on my Mac for
Q4_0, Q4_1 and Q4_2. Single-threaded it was taking
more than 2 minutes after adding the more elaborate
version of Q4_2.

* Reviewer comments

* Avoiding compiler confusion

After changing chunk_size to const int as suggested by
@ggerganov, clang and GCC starting to warn me that I don't
need to capture it in the lambda. So, I removed it from the
capture list. But that makes the MSVC build fail. So,
making it a constexpr to make every compiler happy.

* Still fighting with lambda captures in MSVC

---------

Co-authored-by: Iwan Kawrakow <redacted>
Co-authored-by: Georgi Gerganov <redacted>
2 years agoggml : add Q4_3 quantization (#1082)
Georgi Gerganov [Thu, 20 Apr 2023 17:35:53 +0000 (20:35 +0300)]
ggml : add Q4_3 quantization (#1082)

2 years agoci : remove the LLAMA_ACCELERATE matrix dimension from Ubuntu builds in the CI (...
Ivan Komarov [Thu, 20 Apr 2023 15:15:18 +0000 (17:15 +0200)]
ci : remove the LLAMA_ACCELERATE matrix dimension from Ubuntu builds in the CI (#1074)

[Accelerate](https://developer.apple.com/documentation/accelerate) is an Apple framework which can only be used on macOS, and the CMake build [ignores](https://github.com/ggerganov/llama.cpp/blob/master/CMakeLists.txt#L102) the `LLAMA_ACCELERATE` variable when run on non-Apple platforms. This implies setting `LLAMA_ACCELERATE` is a no-op on Ubuntu and can be removed.

This will reduce visual noise in CI check results (in addition to reducing the number of checks we have to run for every PR). Right now every sanitized build is duplicated twice for no good reason (e.g., we have `CI / ubuntu-latest-cmake-sanitizer (ADDRESS, Debug, ON)` and `CI / ubuntu-latest-cmake-sanitizer (ADDRESS, Debug, OFF)`).

2 years agofix: LLAMA_CUBLAS=1 undefined reference 'shm_open' (#1080)
源文雨 [Thu, 20 Apr 2023 13:28:43 +0000 (21:28 +0800)]
fix: LLAMA_CUBLAS=1 undefined reference 'shm_open' (#1080)

2 years agoAVX2 optimization for vec_dot_q4_2_q8_0 (#1068)
Stephan Walter [Thu, 20 Apr 2023 06:45:41 +0000 (06:45 +0000)]
AVX2 optimization for vec_dot_q4_2_q8_0 (#1068)

2 years agoImprove cuBLAS performance by dequantizing on the GPU (#1065)
slaren [Thu, 20 Apr 2023 01:14:14 +0000 (03:14 +0200)]
Improve cuBLAS performance by dequantizing on the GPU (#1065)

2 years agoMinor: Readme fixed grammar, spelling, and misc updates (#1071)
CRD716 [Wed, 19 Apr 2023 19:52:14 +0000 (14:52 -0500)]
Minor: Readme fixed grammar, spelling, and misc updates (#1071)

2 years agoQ4_2 quantization with rmse-optimized scale and quants (#1062)
Kawrakow [Wed, 19 Apr 2023 18:20:14 +0000 (20:20 +0200)]
Q4_2 quantization with rmse-optimized scale and quants (#1062)

* Q4_2 quantization with rmse-optimized scale and quants

For quantize-stats we get
q4_2: rmse 0.00159301, maxerr 0.17480469, 95pct<0.0030, median<0.0012

For 7B perplexity with BLAS enabled we get 6.2038 after 655 chunks.

Quantization is slow (~90 seconds on my Mac for 7B) as not
multi-threaded as in PR #896.

* ggml : satisfy the sanitizer builds

Not sure why this makes them fail

* Better follow ggml conventions for function names

* Fixed type as per reviewer comment

---------

Co-authored-by: Iwan Kawrakow <redacted>
Co-authored-by: Georgi Gerganov <redacted>
2 years agoggml : use 8-bit precision for Q4_1 intermediate results (#1047)
Georgi Gerganov [Wed, 19 Apr 2023 17:10:08 +0000 (20:10 +0300)]
ggml : use 8-bit precision for Q4_1 intermediate results (#1047)

* ggml : use 8-bit precision for Q4_1 intermediate results (ARM)

* ggml : optimize ggml_vec_dot_q4_1_q8_0() via vmalq_n_f32

56 ms/token with Q4_1 !

* ggml : AVX2 implementation of ggml_vec_dot_q4_1_q8_0 (#1051)

* gitignore : ignore ppl-*.txt files

---------

Co-authored-by: slaren <redacted>
2 years agoreadme : add warning about Q4_2 and Q4_3
Georgi Gerganov [Wed, 19 Apr 2023 16:07:54 +0000 (19:07 +0300)]
readme : add warning about Q4_2 and Q4_3

2 years agoggml : Q4 cleanup - remove 4-bit dot product code (#1061)
Stephan Walter [Wed, 19 Apr 2023 16:06:37 +0000 (16:06 +0000)]
ggml : Q4 cleanup - remove 4-bit dot product code (#1061)

* Q4 cleanup

* Remove unused AVX512 Q4_0 code

2 years agoAdd NVIDIA cuBLAS support (#1044)
slaren [Wed, 19 Apr 2023 09:22:45 +0000 (11:22 +0200)]
Add NVIDIA cuBLAS support (#1044)

2 years agoMulti-threaded ggml_cpy (#1035)
slaren [Tue, 18 Apr 2023 22:53:24 +0000 (00:53 +0200)]
Multi-threaded ggml_cpy (#1035)

* Multi-threaded ggml_cpy

* Update ggml.c

Co-authored-by: Georgi Gerganov <redacted>
* Also fix wdata offset in ggml_compute_forward_add_q_f32

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agoggml : add new Q4_2 quantization (ARM only) (#1046)
Georgi Gerganov [Tue, 18 Apr 2023 20:54:57 +0000 (23:54 +0300)]
ggml : add new Q4_2 quantization (ARM only) (#1046)

* ggml : Q4_2 ARM

* ggml : add ggml_is_quantized()

* llama : update llama_type_name() with Q4_2 entry

* ggml : speed-up q4_2

- 4 threads: ~100ms -> ~90ms
- 8 threads:  ~55ms -> ~50ms

* ggml : optimize q4_2 using vmlaq_n_f32 + vmulq_n_f32

2 years agoggml : scratch that - vmlaq_n_f32 is always better
Georgi Gerganov [Tue, 18 Apr 2023 20:11:23 +0000 (23:11 +0300)]
ggml : scratch that - vmlaq_n_f32 is always better

Had a background process that was messing with the timings

2 years agogitignore : vdot
Georgi Gerganov [Tue, 18 Apr 2023 20:00:08 +0000 (23:00 +0300)]
gitignore : vdot

2 years agoggml : optimize ggml_vec_dot_q4_0_q8_0() using vectorized accumulators
Georgi Gerganov [Tue, 18 Apr 2023 19:59:17 +0000 (22:59 +0300)]
ggml : optimize ggml_vec_dot_q4_0_q8_0() using vectorized accumulators

2 years agoAdding a simple program to measure speed of dot products (#1041)
Kawrakow [Tue, 18 Apr 2023 19:00:14 +0000 (21:00 +0200)]
Adding a simple program to measure speed of dot products (#1041)

On my Mac, the direct Q4_1 product is marginally slower
(~69 vs ~55 us for Q4_0). The SIMD-ified ggml version
is now almost 2X slower (~121 us).

On a Ryzen 7950X CPU, the direct product for Q4_1 quantization
is faster than the AVX2 implementation (~60 vs ~62 us).

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agoreadme : update hot topics about new LoRA functionality
Georgi Gerganov [Tue, 18 Apr 2023 17:10:26 +0000 (20:10 +0300)]
readme : update hot topics about new LoRA functionality

2 years agoci : do not run on drafts
Georgi Gerganov [Mon, 17 Apr 2023 15:00:10 +0000 (18:00 +0300)]
ci : do not run on drafts

2 years agoDo not close file after mmap (Windows version) (#1034)
Ivan Komarov [Tue, 18 Apr 2023 01:15:50 +0000 (03:15 +0200)]
Do not close file after mmap (Windows version) (#1034)

2 years agoreadme : add Ruby bindings (#1029)
Atsushi Tatsuma [Mon, 17 Apr 2023 19:34:35 +0000 (04:34 +0900)]
readme : add Ruby bindings (#1029)

2 years agoadd 4_0 to default outfile namestr dict (#1031)
Cameron [Mon, 17 Apr 2023 18:26:23 +0000 (11:26 -0700)]
add 4_0 to default outfile namestr dict (#1031)

this came up when trying to convert the gpt4all-lora-unfiltered-quantized.bin file

2 years agoAdd LoRA support (#820)
slaren [Mon, 17 Apr 2023 15:28:55 +0000 (17:28 +0200)]
Add LoRA support (#820)

2 years agollama : well-defined static initialization of complex objects (#927)
Arik Poznanski [Mon, 17 Apr 2023 14:41:53 +0000 (17:41 +0300)]
llama : well-defined static initialization of complex objects (#927)

* Replaced static initialization of complex objects with a initialization on first use. This prevents an undefined behavior on program run, for example, crash in Release build, works in Debug build

* replaced use of auto with exact type to avoid using -std=c++14

* Made the assessors functions for static maps be static const

2 years agoquantize-stats : fix bug in --type argument
Georgi Gerganov [Mon, 17 Apr 2023 14:31:06 +0000 (17:31 +0300)]
quantize-stats : fix bug in --type argument

2 years agoggml : avoid using ggml_fp16_to_fp32() and ggml_fp32_to_fp16() in ggml.c
Georgi Gerganov [Mon, 17 Apr 2023 13:16:23 +0000 (16:16 +0300)]
ggml : avoid using ggml_fp16_to_fp32() and ggml_fp32_to_fp16() in ggml.c

2 years agoSpeedup the AVX-512 implementation of ggml_vec_dot_q4_0() (#933)
Ivan Komarov [Mon, 17 Apr 2023 13:10:57 +0000 (15:10 +0200)]
Speedup the AVX-512 implementation of ggml_vec_dot_q4_0() (#933)

2 years agoFix: do not close file on mmap (#1017)
slaren [Sun, 16 Apr 2023 19:27:38 +0000 (21:27 +0200)]
Fix: do not close file on mmap (#1017)

2 years agostdout : vertical align outputs for better readibility
Georgi Gerganov [Sun, 16 Apr 2023 10:58:48 +0000 (13:58 +0300)]
stdout : vertical align outputs for better readibility

2 years agoexamples: add missing <ctime> include for time() (#1011)
Pavol Rusnak [Sun, 16 Apr 2023 10:13:00 +0000 (12:13 +0200)]
examples: add missing <ctime> include for time() (#1011)

2 years agoFix msys2 build error and warnings (#1009)
nanahi [Sun, 16 Apr 2023 09:13:42 +0000 (17:13 +0800)]
Fix msys2 build error and warnings (#1009)

2 years agoconvert.py: Fix loading safetensors and ggml format on Windows (#991)
comex [Sat, 15 Apr 2023 21:53:21 +0000 (14:53 -0700)]
convert.py: Fix loading safetensors and ggml format on Windows (#991)

Calling `mmap.mmap` on Windows apparently resets the file offset of the
raw file object (and makes the BufferedReader return a *negative* file
offset).  For safetensors, avoid using the file offset after calling
mmap.  For GGML format, explicitly save and restore the offset.

Fixes #966.

2 years agoFix potential int8 overflow in non-SIMD vec_dot (#986)
Stephan Walter [Sat, 15 Apr 2023 18:28:56 +0000 (18:28 +0000)]
Fix potential int8 overflow in non-SIMD vec_dot (#986)

2 years agoRefactor ggml.c for future tensor types (#1001)
Stephan Walter [Sat, 15 Apr 2023 16:25:38 +0000 (16:25 +0000)]
Refactor ggml.c for future tensor types (#1001)

2 years agoggml : add Q8_0 quantization for intermediate results (#951)
Georgi Gerganov [Sat, 15 Apr 2023 14:53:22 +0000 (17:53 +0300)]
ggml : add Q8_0 quantization for intermediate results (#951)

* ggml : add Q8_0 quantization for intermediate results

* quantize-stats : fix test + add it to Makefile default

* Q8: use int8_t, AVX/AVX2 optimizations

* ggml : fix quantize_row_q8_0() ARM_NEON rounding

* minor : updates after rebase to latest master

* quantize-stats : delete obsolete strings

* ggml : fix q4_1 dot func

---------

Co-authored-by: Stephan Walter <redacted>
2 years agoggml : use posix_memalign on non-Windows env
Georgi Gerganov [Sat, 15 Apr 2023 11:25:45 +0000 (14:25 +0300)]
ggml : use posix_memalign on non-Windows env

2 years agobenchmark : fix result validation in benchmark-q4_0-matmult (#987)
Ivan Komarov [Sat, 15 Apr 2023 05:51:54 +0000 (07:51 +0200)]
benchmark : fix result validation in benchmark-q4_0-matmult (#987)

2 years agocmake : add finding the OpenBLAS header file (#992)
katsu560 [Sat, 15 Apr 2023 05:51:11 +0000 (14:51 +0900)]
cmake : add finding the OpenBLAS header file (#992)

2 years agoRevert "main : alternative instruct mode (Vicuna support, etc.) (#863)" (#982)
Pavol Rusnak [Fri, 14 Apr 2023 19:58:43 +0000 (21:58 +0200)]
Revert "main : alternative instruct mode (Vicuna support, etc.) (#863)" (#982)

This reverts commit f4d277ae17247ee51129ef1a9ff74d377cc90b1b.

2 years agopy : bump sentencepiece to 0.1.98 to support Python 3.11 (#976)
Pavol Rusnak [Fri, 14 Apr 2023 19:46:49 +0000 (21:46 +0200)]
py : bump sentencepiece to 0.1.98 to support Python 3.11 (#976)

2 years agomake : fix dependencies, use auto variables (#983)
Stephan Walter [Fri, 14 Apr 2023 19:39:48 +0000 (19:39 +0000)]
make : fix dependencies, use auto variables (#983)

2 years agoExpose type name from ggml (#970)
Pavol Rusnak [Fri, 14 Apr 2023 18:05:37 +0000 (20:05 +0200)]
Expose type name from ggml (#970)

Avoid duplication of type names in utils

Co-authored-by: Håkon H. Hitland <redacted>
2 years agomain : alternative instruct mode (Vicuna support, etc.) (#863)
Tomáš Pazdiora [Fri, 14 Apr 2023 15:19:17 +0000 (17:19 +0200)]
main : alternative instruct mode (Vicuna support, etc.) (#863)

* Add support for configs, add configurable prefixes / suffixes, deprecate instruct mode, add stop prompt

* Add multiline mode, update text input.

* bugfix

* update implementation

* typos

* Change --multiline implementation to be toggled by EOF.

* bugfix

* default multiline mode

* add more configs

* update formating

* update formatting

* apply suggestions

2 years agoggml : add unary and binary map operations (#874)
Kerfuffle [Fri, 14 Apr 2023 14:43:55 +0000 (08:43 -0600)]
ggml : add unary and binary map operations (#874)

* GGML map ops proof of concept.

* Various cleanups.

Add handling for task setting.

Add handling for ggml_compute_backward.

Rename functions to ggml_map_unary_f32 and ggml_map_binary_f32

Fix compiler warnings related to casting function pointers and `void *`

Reorder functions and definitions based on the GGML op number.

Use typedefs for map op function pointer types.

* Fix position of map ops cases in ggml_compute_forward

2 years agopy : cleanup dependencies (#962)
Pavol Rusnak [Fri, 14 Apr 2023 13:37:11 +0000 (15:37 +0200)]
py : cleanup dependencies (#962)

after #545 we do not need torch, tqdm and requests in the dependencies

2 years agopy : fix flake8 and isort nitpicks (#960)
Pavol Rusnak [Fri, 14 Apr 2023 12:23:21 +0000 (14:23 +0200)]
py : fix flake8 and isort nitpicks (#960)

2 years agoggml : minor
Georgi Gerganov [Fri, 14 Apr 2023 10:31:29 +0000 (13:31 +0300)]
ggml : minor

2 years agoggml : always allocate buffers with size multiple of GGML_MEM_ALIGN
Georgi Gerganov [Fri, 14 Apr 2023 10:31:15 +0000 (13:31 +0300)]
ggml : always allocate buffers with size multiple of GGML_MEM_ALIGN

2 years agopy : new conversion script (#545)
comex [Fri, 14 Apr 2023 07:03:03 +0000 (00:03 -0700)]
py : new conversion script (#545)

Current status: Working, except for the latest GPTQ-for-LLaMa format
  that includes `g_idx`.  This turns out to require changes to GGML, so
  for now it only works if you use the `--outtype` option to dequantize it
  back to f16 (which is pointless except for debugging).

  I also included some cleanup for the C++ code.

  This script is meant to replace all the existing conversion scripts
  (including the ones that convert from older GGML formats), while also
  adding support for some new formats.  Specifically, I've tested with:

  - [x] `LLaMA` (original)
  - [x] `llama-65b-4bit`
  - [x] `alpaca-native`
  - [x] `alpaca-native-4bit`
  - [x] LLaMA converted to 'transformers' format using
        `convert_llama_weights_to_hf.py`
  - [x] `alpaca-native` quantized with `--true-sequential --act-order
        --groupsize 128` (dequantized only)
  - [x] same as above plus `--save_safetensors`
  - [x] GPT4All
  - [x] stock unversioned ggml
  - [x] ggmh

  There's enough overlap in the logic needed to handle these different
  cases that it seemed best to move to a single script.

  I haven't tried this with Alpaca-LoRA because I don't know where to find
  it.

  Useful features:

  - Uses multiple threads for a speedup in some cases (though the Python
    GIL limits the gain, and sometimes it's disk-bound anyway).

  - Combines split models into a single file (both the intra-tensor split
    of the original and the inter-tensor split of 'transformers' format
    files).  Single files are more convenient to work with and more
    friendly to future changes to use memory mapping on the C++ side.  To
    accomplish this without increasing memory requirements, it has some
    custom loading code which avoids loading whole input files into memory
    at once.

  - Because of the custom loading code, it no longer depends in PyTorch,
    which might make installing dependencies slightly easier or faster...
    although it still depends on NumPy and sentencepiece, so I don't know
    if there's any meaningful difference.  In any case, I also added a
    requirements.txt file to lock the dependency versions in case of any
    future breaking changes.

  - Type annotations checked with mypy.

  - Some attempts to be extra user-friendly:

      - The script tries to be forgiving with arguments, e.g. you can
        specify either the model file itself or the directory containing
        it.

      - The script doesn't depend on config.json / params.json, just in
        case the user downloaded files individually and doesn't have those
        handy.  But you still need tokenizer.model and, for Alpaca,
        added_tokens.json.

      - The script tries to give a helpful error message if
        added_tokens.json is missing.

2 years agoggml : fix q4_1 dot product types
Georgi Gerganov [Fri, 14 Apr 2023 06:45:42 +0000 (09:45 +0300)]
ggml : fix q4_1 dot product types

2 years agoggml : optimize rope function to avoid call powf in the tight loop (#807)
Howard Su [Fri, 14 Apr 2023 06:24:52 +0000 (14:24 +0800)]
ggml : optimize rope function to avoid call powf in the tight loop (#807)

2 years agoperplexity : add support for batch size to `--perplexity` (#407)
Gary Linscott [Thu, 13 Apr 2023 21:50:42 +0000 (14:50 -0700)]
perplexity : add support for batch size to `--perplexity` (#407)

* Add support to batch size for perplexity

* Revert "Fix memory allocation issues and seg faults"

This reverts commit 4870e455b3653f7d7769fa5772b2c90ffad088df.

* update from merge

* Remove perplexity from main

* updates

* Update batch size for efficiency

2 years agocommon : remove unnecessary includes (#947)
CRD716 [Thu, 13 Apr 2023 15:39:25 +0000 (10:39 -0500)]
common : remove unnecessary includes (#947)

2 years agoggml : add GGML_DEFAULT_N_THREADS
Georgi Gerganov [Thu, 13 Apr 2023 15:36:40 +0000 (18:36 +0300)]
ggml : add GGML_DEFAULT_N_THREADS

2 years agoggml : speed-up ggml_vec_dot_q4_1() ARM_NEON + 32-bit ARM support (#900)
Georgi Gerganov [Thu, 13 Apr 2023 15:32:36 +0000 (18:32 +0300)]
ggml : speed-up ggml_vec_dot_q4_1() ARM_NEON + 32-bit ARM support (#900)

* ggml : speed-up q4_1 ARM_NEON by ~5%

* ggml : implement vaddvq when missing

* ggml : implement vminvq and vmaxvq when missing

* ggml : implement vzip when missing

* ggml : fix comment

* ggml : try to use correct ifdef

2 years agollama : merge llama_internal.h into llama.h
Georgi Gerganov [Thu, 13 Apr 2023 15:04:45 +0000 (18:04 +0300)]
llama : merge llama_internal.h into llama.h

Hide it behind an #ifdef

2 years agogitignore : benchmark
Georgi Gerganov [Thu, 13 Apr 2023 15:01:22 +0000 (18:01 +0300)]
gitignore : benchmark

2 years agoggml : optimize non-SIMD Q4_0 vector dot product (#703)
Stephan Walter [Thu, 13 Apr 2023 14:59:50 +0000 (14:59 +0000)]
ggml : optimize non-SIMD Q4_0 vector dot product (#703)

2 years agoggml : introduce GGML_ALIGNED_MALLOC/GGML_ALIGNED_FREE macros (#884)
Pavol Rusnak [Thu, 13 Apr 2023 14:08:32 +0000 (16:08 +0200)]
ggml : introduce GGML_ALIGNED_MALLOC/GGML_ALIGNED_FREE macros (#884)

which allows us to use aligned_alloc or _aligned_malloc functions

2 years agofix whitespace (#944)
CRD716 [Thu, 13 Apr 2023 14:03:57 +0000 (09:03 -0500)]
fix whitespace (#944)

2 years agoreadme : remove python 3.10 warning (#929)
CRD716 [Thu, 13 Apr 2023 13:59:53 +0000 (08:59 -0500)]
readme : remove python 3.10 warning (#929)

2 years agoreadme : llama node binding (#911)
Genkagaku.GPT [Thu, 13 Apr 2023 13:54:27 +0000 (21:54 +0800)]
readme : llama node binding (#911)

* chore: add nodejs binding

* chore: add nodejs binding

2 years agoflake.nix: add all binaries from bin (#848)
Pavol Rusnak [Thu, 13 Apr 2023 13:49:05 +0000 (15:49 +0200)]
flake.nix: add all binaries from bin (#848)

2 years agozig : update build.zig (#872)
Judd [Thu, 13 Apr 2023 13:43:22 +0000 (21:43 +0800)]
zig : update build.zig (#872)

* update

* update readme

* minimize the changes.

---------

Co-authored-by: zjli2019 <redacted>
2 years agoggml : update cblas_sgemm columns var to be more reasonable (#838)
Vladimir [Thu, 13 Apr 2023 13:24:30 +0000 (15:24 +0200)]
ggml : update cblas_sgemm columns var to be more reasonable (#838)

2 years agoexamples : add -n to alpaca and gpt4all scripts (#706)
niansa/tuxifan [Thu, 13 Apr 2023 13:03:39 +0000 (15:03 +0200)]
examples : add -n to alpaca and gpt4all scripts (#706)

2 years agocmake : add explicit F16C option (x86) (#576)
anzz1 [Thu, 13 Apr 2023 12:48:21 +0000 (15:48 +0300)]
cmake : add explicit F16C option (x86) (#576)

Fixes building for x86 processors missing F16C featureset
MSVC not included, as in MSVC F16C is implied with AVX2/AVX512

2 years agobenchmark : add tool for timing q4_0 matrix multiplication (#653)
SebastianApel [Thu, 13 Apr 2023 12:46:23 +0000 (14:46 +0200)]
benchmark : add tool for timing q4_0 matrix multiplication (#653)

* Initial version of q4_0 matrix multiplication benchmark

* Bugfix: Added dependency to ggml.o to benchmark

* Reviewer requests: added parameter for threads, switched to ggml_time_us()

* Reviewer input: removed rtsc, use epsilon for check

* Review comment: Removed set_locale

* Feature: Param for numer of iterations, Bugfix for use of parameter threads

* Reviewer suggestion: Moved to examples

* Reviewer feedback: Updated clean: and benchmark: sections

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agodo not force the prompt file to end with a new line (#908)
Pavol Rusnak [Thu, 13 Apr 2023 09:33:16 +0000 (11:33 +0200)]
do not force the prompt file to end with a new line (#908)

2 years agoDon't crash on ftype (formerly f16) == 4 (#917)
Stephan Walter [Wed, 12 Apr 2023 15:06:16 +0000 (15:06 +0000)]
Don't crash on ftype (formerly f16) == 4 (#917)

2 years agoreadme : change "GPU support" link to discussion
Georgi Gerganov [Wed, 12 Apr 2023 11:48:57 +0000 (14:48 +0300)]
readme : change "GPU support" link to discussion

2 years agoreadme : update hot topics with link to "GPU support" issue
Georgi Gerganov [Wed, 12 Apr 2023 11:31:12 +0000 (14:31 +0300)]
readme : update hot topics with link to "GPU support" issue

2 years agoreadme: link to sha256sums file (#902)
Nicolai Weitkemper [Wed, 12 Apr 2023 06:46:20 +0000 (08:46 +0200)]
readme: link to sha256sums file (#902)

This is to emphasize that these do not need to be obtained from elsewhere.

2 years agoFix whitespace, add .editorconfig, add GitHub workflow (#883)
Pavol Rusnak [Tue, 11 Apr 2023 19:45:44 +0000 (21:45 +0200)]
Fix whitespace, add .editorconfig, add GitHub workflow (#883)

2 years agoAdd enum llama_ftype, sync ggml_type to model files (#709)
Stephan Walter [Tue, 11 Apr 2023 15:03:51 +0000 (15:03 +0000)]
Add enum llama_ftype, sync ggml_type to model files (#709)

2 years agoWindows fixes (#890)
comex [Tue, 11 Apr 2023 13:19:54 +0000 (06:19 -0700)]
Windows fixes (#890)

Mostly for msys2 and mingw64 builds, which are different from each other
and different from standard Visual Studio builds.  Isn't Windows fun?

- Define _GNU_SOURCE in more files (it's already used in ggml.c for
  Linux's sake).

- Don't use PrefetchVirtualMemory if not building for Windows 8 or later
  (mingw64 doesn't by default).  But warn the user about this situation
  since it's probably not intended.

- Check for NOMINMAX already being defined, which it is on mingw64.

- Actually use the `increment` variable (bug in my `pizza` PR).

- Suppress unused variable warnings in the fake pthread_create and
  pthread_join implementations for Windows.

- (not Windows-related) Remove mention of `asprintf` from comment;
  `asprintf` is no longer used.

Fixes #871.

2 years agoAdd BAIR's Koala to supported models (#877)
qouoq [Mon, 10 Apr 2023 20:41:53 +0000 (04:41 +0800)]
Add BAIR's Koala to supported models (#877)

2 years agoggml : fix WASM build
Georgi Gerganov [Mon, 10 Apr 2023 20:20:01 +0000 (23:20 +0300)]
ggml : fix WASM build

2 years agoggml : add ggml_cont() + optimize ggml_cpy() for contiguous dst
Georgi Gerganov [Mon, 10 Apr 2023 19:40:28 +0000 (22:40 +0300)]
ggml : add ggml_cont() + optimize ggml_cpy() for contiguous dst

2 years agoggml : remove trailing whitespaces
Georgi Gerganov [Mon, 10 Apr 2023 16:32:45 +0000 (19:32 +0300)]
ggml : remove trailing whitespaces

2 years agoSimplify to include lower-case windows.h always, fix compile on mingw32 (#747)
Marco Matthies [Mon, 10 Apr 2023 17:57:59 +0000 (19:57 +0200)]
Simplify to include lower-case windows.h always, fix compile on mingw32 (#747)

2 years agoggml : fix quantize_row_q4_1() ARM_NEON (close #876)
Georgi Gerganov [Mon, 10 Apr 2023 16:29:48 +0000 (19:29 +0300)]
ggml : fix quantize_row_q4_1() ARM_NEON (close #876)

2 years agoPrint model version.
comex [Sat, 8 Apr 2023 20:08:21 +0000 (13:08 -0700)]
Print model version.

Also improve model type printing, and fix indentation of an unrelated
switch statement.

2 years agoRewrite loading code to try to satisfy everyone:
comex [Sat, 8 Apr 2023 19:24:37 +0000 (12:24 -0700)]
Rewrite loading code to try to satisfy everyone:

- Support all three formats (ggml, ggmf, ggjt).  (However, I didn't
  include the hack needed to support GPT4All files without conversion.
  Those can still be used after converting them with convert.py from my
  other PR.)

- Support both mmap and read (mmap is used by default, but can be
  disabled with `--no-mmap`, and is automatically disabled for pre-ggjt
  files or on platforms where mmap is not supported).

- Support multi-file models like before, but automatically determine the
  number of parts rather than requiring `--n_parts`.

- Improve validation and error checking.

- Stop using the per-file type field (f16) entirely in favor of just
  relying on the per-tensor type/size fields.  This has no immediate
  benefit, but makes it easier to experiment with different formats, and
  should make it easier to support the new GPTQ-for-LLaMa models in the
  future (I have some work in progress on that front).

- Support VirtualLock on Windows (using the same `--mlock` option as on
  Unix).

    - Indicate loading progress when using mmap + mlock.  (Which led me
      to the interesting observation that on my Linux machine, with a
      warm file cache, mlock actually takes some time, whereas mmap
      without mlock starts almost instantly...)

      - To help implement this, move mlock support from ggml to the
        loading code.

- madvise/PrefetchVirtualMemory support (based on #740)

- Switch from ifstream to the `fopen` family of functions to avoid
  unnecessary copying and, when mmap is enabled, allow reusing the same
  file descriptor for both metadata reads and mmap (whereas the existing
  implementation opens the file a second time to mmap).

- Quantization now produces a single-file output even with multi-file
  inputs (not really a feature as much as 'it was easier this way').

Implementation notes:

I tried to factor the code into more discrete pieces than before.

Regarding code style: I tried to follow the code style, but I'm naughty
and used a few advanced C++ features repeatedly:

- Destructors to make it easier to ensure everything gets cleaned up.

- Exceptions.  I don't even usually use exceptions when writing C++, and
  I can remove them if desired... but here they make the loading code
  much more succinct while still properly handling a variety of errors,
  ranging from API calls failing to integer overflow and allocation
  failure.  The exceptions are converted to error codes at the
  API boundary.)

Co-authored-by: Pavol Rusnak <redacted> (for the bit I copied from #740)
2 years agofix for windows utf-8 input (#840)
Tomáš Pazdiora [Sat, 8 Apr 2023 15:49:39 +0000 (17:49 +0200)]
fix for windows utf-8 input (#840)

Use UTF-16 as input on Windows, since UTF-8 does not work and reads multibyte characters as zeros

2 years agocmake should link openblas properly with -lopenblas like how it's done in the makefil...
eiery [Sat, 8 Apr 2023 11:15:17 +0000 (07:15 -0400)]
cmake should link openblas properly with -lopenblas like how it's done in the makefile (#839)

2 years agoAdd new binaries to flake.nix (#847)
lon [Sat, 8 Apr 2023 10:04:23 +0000 (07:04 -0300)]
Add new binaries to flake.nix (#847)

2 years agoAdd quantize-stats command for testing quantization (#728)
unbounded [Fri, 7 Apr 2023 22:09:18 +0000 (00:09 +0200)]
Add quantize-stats command for testing quantization (#728)

Command that calculates some statistics over the errors introduced by
quantization, like mean square error, max error and some percentile errors for layer
weights. Should be useful for testing quantization improvements.

Exposes some internal state from ggml and llama for testing

2 years agomake : add libllama.so target for llama-cpp-python (#797)
bhubbb [Fri, 7 Apr 2023 16:11:58 +0000 (02:11 +1000)]
make : add libllama.so target for llama-cpp-python (#797)

I was able to get llama-cpp-python working but only when I build libllama.so with make.

2 years agozig : don't link examples/common.cpp for non-example (#814)
iacore [Fri, 7 Apr 2023 16:05:29 +0000 (16:05 +0000)]
zig : don't link examples/common.cpp for non-example (#814)

2 years agollama : always sort logits before nucleus sampling (#812)
Ivan Stepanov [Fri, 7 Apr 2023 16:02:12 +0000 (19:02 +0300)]
llama : always sort logits before nucleus sampling (#812)

* Always sort logits before nucleus sampling

* remove second normalization

- fix windows build
- remove normalization since std::discrete_distribution does not require it

2 years agoDo not crash when it has nothing to say. (#796)
Sergey Alirzaev [Thu, 6 Apr 2023 15:59:11 +0000 (17:59 +0200)]
Do not crash when it has nothing to say. (#796)

Otherwise observing this in the interactive mode:
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/bits/stl_vector.h:1230: reference std::vector<int>::back() [_Tp = int, _Alloc = std::allocator<int>]: Assertion '!this->empty()' failed.

2 years agoMake docker instructions more explicit (#785)
Pavol Rusnak [Thu, 6 Apr 2023 06:56:58 +0000 (08:56 +0200)]
Make docker instructions more explicit (#785)

2 years agoggml : multi-thread ggml_rope() (~3-4 times faster on M1) (#781)
Georgi Gerganov [Wed, 5 Apr 2023 19:11:03 +0000 (22:11 +0300)]
ggml : multi-thread ggml_rope() (~3-4 times faster on M1) (#781)

2 years agoggml, llama : avoid heavy V transpose + improvements (#775)
Georgi Gerganov [Wed, 5 Apr 2023 19:07:33 +0000 (22:07 +0300)]
ggml, llama : avoid heavy V transpose + improvements (#775)

ggml :

- added ggml_view_3d()
- ggml_view_tensor() now inherits the stride too
- reimplement ggml_cpy() to account for dst stride
- no longer require tensor->data to be memory aligned

llama :

- compute RoPE on 32-bit tensors (should be more accurate)
- store RoPE-ed K in the KV cache
- store transposed V in the KV cache (significant speed-up)
- avoid unnecessary Q copy

2 years agoUpdate README.md
Georgi Gerganov [Wed, 5 Apr 2023 16:54:30 +0000 (19:54 +0300)]
Update README.md

2 years agollama : define non-positive top_k; top_k range check (#779)
Ivan Stepanov [Wed, 5 Apr 2023 16:20:05 +0000 (19:20 +0300)]
llama : define non-positive top_k; top_k range check (#779)

* Define non-positive top_k; top_k range check

* minor : brackets

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agomiku.sh : add executable bit (#780)
at8u [Wed, 5 Apr 2023 15:59:13 +0000 (15:59 +0000)]
miku.sh : add executable bit (#780)