]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/log
pkg/ggml/sources/llama.cpp
2 years agotrain : fix compile warning
Georgi Gerganov [Sat, 1 Jul 2023 15:45:44 +0000 (18:45 +0300)]
train : fix compile warning

2 years agoggml : disable GGML_TASK_INIT and GGML_TASK_FINALIZE by default (#1995)
Qingyou Meng [Sat, 1 Jul 2023 15:42:43 +0000 (23:42 +0800)]
ggml : disable GGML_TASK_INIT and GGML_TASK_FINALIZE by default (#1995)

Will not be scheduled unless explicitly enabled.

2 years agoUse unsigned for random seed (#2006)
Howard Su [Thu, 29 Jun 2023 13:15:15 +0000 (21:15 +0800)]
Use unsigned for random seed (#2006)

* Use unsigned for random seed. Keep -1 as the value to use a time based seed.

Co-authored-by: Georgi Gerganov <redacted>
2 years agoPorting the improved K-Quant CUDA kernels to OpenCL (#1966)
LostRuins [Thu, 29 Jun 2023 03:56:43 +0000 (11:56 +0800)]
Porting the improved K-Quant CUDA kernels to OpenCL (#1966)

* Added broken new q4k quant

* xx + ib0

* Fix q2_k fast kernel

* Use preprocessor for QK_K

* Add q6_k fast matmul kernel

* ported q3k speedup successfully

* ported q2k and q5k speedups

* remove old dot kernels and template

* fixed global const struct types

* fixing address spaces

* fixed string too long CI issue

---------

Co-authored-by: 0cc4m <redacted>
2 years agollama : replacing auto &kv with const auto &kv (#2041)
m3ndax [Wed, 28 Jun 2023 18:39:08 +0000 (20:39 +0200)]
llama : replacing auto &kv with const auto &kv (#2041)

* Replacing auto &kv with const auto &kv

* Create codacy.yml

* Delete codacy.yml

2 years agocuda : remove nchannels_x argument from mul_mat_vec_nc_f16_f32 (#2028)
Salvador E. Tropea [Wed, 28 Jun 2023 17:27:31 +0000 (14:27 -0300)]
cuda : remove nchannels_x argument from mul_mat_vec_nc_f16_f32 (#2028)

- Not used

2 years agocuda : fix missing const qualifier in casts (#2027)
Salvador E. Tropea [Wed, 28 Jun 2023 17:26:26 +0000 (14:26 -0300)]
cuda : fix missing const qualifier in casts (#2027)

2 years agollama : remove shards weight file support (#2000)
Howard Su [Wed, 28 Jun 2023 17:13:02 +0000 (10:13 -0700)]
llama : remove shards weight file support (#2000)

* Remove multiple shards

* Remove multiple file loaders

* Remove llama_load_tensor_shard class

* Simplify load logic

* Remove dead code guess_n_parts function

* Remove vocab_only from constructor of llama_model_loader

* Remove alignment_prevents_mmap which is not more needed.

* Remove useless check

2 years agoCUDA GPU acceleration for LoRAs + f16 models (#1970)
Johannes Gäßler [Wed, 28 Jun 2023 16:35:54 +0000 (18:35 +0200)]
CUDA GPU acceleration for LoRAs + f16 models (#1970)

2 years agollama : support input embeddings directly (#1910)
ningshanwutuobang [Wed, 28 Jun 2023 15:53:37 +0000 (23:53 +0800)]
llama : support input embeddings directly  (#1910)

* add interface for float input

* fixed inpL shape and type

* add examples of input floats

* add test example for embd input

* fixed sampling

* add free for context

* fixed add end condition for generating

* add examples for llava.py

* add READMD for llava.py

* add READMD for llava.py

* add example of PandaGPT

* refactor the interface and fixed the styles

* add cmake build for embd-input

* add cmake build for embd-input

* Add MiniGPT-4 example

* change the order of the args of llama_eval_internal

* fix ci error

2 years agofix pthreads setaffinity usage on android (#2020)
Erik Scholz [Tue, 27 Jun 2023 17:06:33 +0000 (19:06 +0200)]
fix pthreads setaffinity usage on android (#2020)

2 years agobaby-llama : fix build after ggml_rope change (#2016)
Howard Su [Tue, 27 Jun 2023 05:07:13 +0000 (13:07 +0800)]
baby-llama : fix build after ggml_rope change (#2016)

2 years agollama : fix rope usage after ChatGLM change
Georgi Gerganov [Mon, 26 Jun 2023 21:37:13 +0000 (00:37 +0300)]
llama : fix rope usage after ChatGLM change

2 years agoggml : add support for ChatGLM RoPE
Georgi Gerganov [Mon, 26 Jun 2023 21:06:51 +0000 (00:06 +0300)]
ggml : add support for ChatGLM RoPE

2 years agoreadme : add Scala 3 bindings repo (#2010)
Roman Parykin [Mon, 26 Jun 2023 19:47:59 +0000 (22:47 +0300)]
readme : add Scala 3 bindings repo (#2010)

2 years agoggml : increase max tensor name + clean up compiler warnings in train-text (#1988)
David Yang [Mon, 26 Jun 2023 19:45:32 +0000 (03:45 +0800)]
ggml : increase max tensor name + clean up compiler warnings in train-text (#1988)

* Clean up compiler warnings in train-text

Some brackets to disambiguate order of operations

* Increase GGML_MAX_NAME

Avoiding strncpy danger in train-text-from-scratch and reducing potential future name length issues

2 years agoreadme : LD_LIBRARY_PATH complement for some Android devices when building with CLBla...
Gustavo Rocha Dias [Mon, 26 Jun 2023 19:34:45 +0000 (16:34 -0300)]
readme : LD_LIBRARY_PATH complement for some Android devices when building with CLBlast inside Termux (#2007)

* docs - Alternative way to build at Android, with CLBlast.

* doc - LD_LIBRARY_PATH complement for some Android devices when building with CLBlast inside Termux.

* doc- fix typo

2 years agoggml : avoid conv 2d kernel round up
Georgi Gerganov [Mon, 26 Jun 2023 18:03:59 +0000 (21:03 +0300)]
ggml : avoid conv 2d kernel round up

2 years agoggml : add NUMA support (#1556)
zrm [Mon, 26 Jun 2023 17:57:59 +0000 (13:57 -0400)]
ggml : add NUMA support (#1556)

* detect NUMA systems and pin work threads to nodes (linux)

* disable mmap prefetch/readahead for NUMA systems

* avoid sending finalize op to thread pool if it does nothing

* silence robot

* fix args

* make --numa a param

* recommendation that n_nodes evenly divide n_threads did not warrant such aggressive enforcement

* lower synchronization overhead

* statically allocate

* move numa state to g_state

* add description for --numa

* ggml : minor style changes

* ggml : minor style + try fix sanitizer build

* llama : allow to initialize backend with NUMA support

* llama : avoid ggml include in llama-util.h

* ggml : style / formatting

* ggml : fix handling of ops with n_threads > n_tasks > 1

* server : utilize numa parameter

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agok-quants : fix indentation
Georgi Gerganov [Mon, 26 Jun 2023 17:10:52 +0000 (20:10 +0300)]
k-quants : fix indentation

2 years agotests : fix quantize perf (#1990)
katsu560 [Mon, 26 Jun 2023 16:47:02 +0000 (01:47 +0900)]
tests : fix quantize perf (#1990)

* fix test quantize perf

* avoid the global state

2 years agok-quants : add AVX support to dot functions (#1916)
katsu560 [Mon, 26 Jun 2023 16:46:07 +0000 (01:46 +0900)]
k-quants : add AVX support to dot functions (#1916)

* k_quants : add AVX support

* k_quants : apply review comments

2 years agoreadme : add link to new k-quants for visibility
Georgi Gerganov [Mon, 26 Jun 2023 16:45:09 +0000 (19:45 +0300)]
readme : add link to new k-quants for visibility

2 years agok-quants : support for super-block size of 64 (#2001)
Kawrakow [Mon, 26 Jun 2023 16:43:07 +0000 (19:43 +0300)]
k-quants : support for super-block size of 64 (#2001)

* k_quants: WIP super-blocks with 64 weights

* k_quants: WIP super-blocks with 64 weights

Q6_K scalar and AVX2 works

* k_quants: WIP super-blocks with 64 weights

Q4_K scalar and AVX2 works

* k_quants: WIP super-blocks with 64 weights

Q2_K scalar and AVX2 works. Q2_K is way too slow (it is actually slower
than the scalar implementation)

* k_quants: WIP super-blocks with 64 weights

Q3_K scalar and AVX2 works.

* k_quants: WIP super-blocks with 64 weights

Q5_K scalar and AVX2 works, and with that all
k_quants are done on AVX2 and scalar

* k_quants: WIP super-blocks with 64 weights

Q6_K working on CUDA. Cannot make it run quite as gast as
with super-blocks with 256 weigths: 8% slower on 4080,
20% slower on the 1660 (but there we fit 1 less layer on the
GPU because pf the larger model size), so some fraction of
these 20% is due to that,

* k_quants: WIP super-blocks with 64 weights

Q4_K working on CUDA. ~10% slower on GTX-1660,
16% slower on 4080.

* k_quants: WIP super-blocks with 64 weights

Q2_K working on CUDA. ~3% slower on GTX-1660,
10% slower on 4080.

* k_quants: WIP super-blocks with 64 weights

Q3_K working on CUDA.

* k_quants: WIP super-blocks with 64 weights

Q5_K working on CUDA, and with this CUDA is done.

* k_quants: WIP super-blocks with 64 weights

Q6_K working on ARM_NEON

* k_quants: WIP super-blocks with 64 weights

Q4_K working on ARM_NEON, but quite a bit slower than 256 weights

* k_quants: WIP super-blocks with 64 weights

Q2_K working on ARM_NEON, but quite a bit slower than 256 weights

* k_quants: WIP super-blocks with 64 weights

Q3_K working on ARM_NEON, but quite a bit slower than 256 weights.

* k_quants: WIP super-blocks with 64 weights

Q5_K working on ARM_NEON, but quite a bit slower than 256 weights.

With that, we have full support for ARM_NEON, although
performance is not quite there.

* k_quants: WIP super-blocks with 64 weights

Slightly more efficient Q3_K and Q5_K

* k_quants: WIP super-blocks with 64 weights

Another small improvement for Q3_K and Q5_K on ARM_NEON

* k_quants: WIP super-blocks with 64 weights

Yet another speedup for Q5_K on ARM_NEON.
We are now within 10% of the QK_K = 256 version.

* k_quants: WIP super-blocks with 64 weights

* We are able to pass preprocessor macros to the Metal
  compiler
* Q6_K works and is actually slightly more efficient than
  the QK_K = 256 version (25.2 ms vs 25.8 ms)

* k_quants: WIP super-blocks with 64 weights

Q4_K works on Metal and is actually slightly faster
than QK_K = 256 (21.95 ms vs 24.0 ms).

* k_quants: WIP super-blocks with 64 weights

Q2_K works on Metal and is very slightly faster
than QK_K = 256 (23.8 ms vs 24.2 ms).

* k_quants: WIP super-blocks with 64 weights

Q3_K works on Metal and is slightly faster
than QK_K = 256 (26.6 ms vs 28.3 ms).

* k_quants: WIP super-blocks with 64 weights

Q5_K works on Metal and is slightly faster
than QK_K = 256 (23.7 ms vs 26.3 ms).

* k_quants: call them _K, not _k, also on Metal

* k_quants: correctly define QK_K in llama.cpp

* Fixed bug in q4_K quantization added with the 64-block addition

* Simplify via lambda

* k_quants: swicth Q3_K to 4-bit scales when QK_K = 64

Otherwise there isn't much benefit from this
quantization type. There is some very slight loss
in accuracy, but we reduce size by ~7%.
E.g., for OpenLLaMA-3B, Q3_K_S perplexity is
8.6131 with 8-bit scales and 8.6352 with 4-bit,
while file size decreases from 1.53G to 1.44G.

* k_quants: switch Q4_K to 4-bit scales when QK_K = 64

 Here the loss in accuracy is greater than for Q3_K,
 but the Q4_K points still move further to the left on
 the perplexity vs size curve.

* k_quants: forgot to add the Metal changes in last commit

* k_quants: change Q5_K to be type 0 when QK_K = 64

Still needs AVX2 implementation

* k_quants: AVX2 implementation for new 64-weight Q5_K

* k_quants: 10% faster ARM_NEON Q5_K dot product

* k_quants: fixed issue caused by merging with master

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agoFix assert when free invalid cuda pointer (#2005)
Howard Su [Mon, 26 Jun 2023 15:15:47 +0000 (23:15 +0800)]
Fix assert when free invalid cuda pointer (#2005)

Fix assert via initializing extra structure always.
CUDA error 1 at C:\GPT\llama.cpp\ggml-cuda.cu:2536: invalid argument

2 years agoreadme : add new roadmap + manifesto
Georgi Gerganov [Sun, 25 Jun 2023 13:08:12 +0000 (16:08 +0300)]
readme : add new roadmap + manifesto

2 years agoggml : sync latest ggml (custom operators)
Georgi Gerganov [Sun, 25 Jun 2023 11:25:08 +0000 (14:25 +0300)]
ggml : sync latest ggml (custom operators)

2 years agofix server sampling: top k sampler first (#1977)
anon998 [Sun, 25 Jun 2023 08:48:36 +0000 (08:48 +0000)]
fix server sampling: top k sampler first (#1977)

Co-authored-by: anon <redacted>
2 years agoreadme : add Azure CI discussion link
Georgi Gerganov [Sun, 25 Jun 2023 06:07:03 +0000 (09:07 +0300)]
readme : add Azure CI discussion link

2 years agozig : upgrade build system support (#1981)
sjinzh [Sun, 25 Jun 2023 05:45:44 +0000 (13:45 +0800)]
zig : upgrade build system support (#1981)

* upgrade zig build system support

* zig : add new line at the end of the file

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years ago#1869 Fix null reference errors when training from scratch with CUDA (#1907)
Robyn [Sat, 24 Jun 2023 18:10:29 +0000 (04:10 +1000)]
#1869 Fix null reference errors when training from scratch with CUDA (#1907)

* #1869 Fix null reference errors when training from scratch with CUDA build

Calling ggml_compute_forward when node->src0 was null was causing train-text-from-scratch.exe to terminate unexpectedly.

* ggml : do not dereference src0 if NULL

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agotests : sync test-grad0 from ggml
Georgi Gerganov [Sat, 24 Jun 2023 16:40:18 +0000 (19:40 +0300)]
tests : sync test-grad0 from ggml

2 years agoflake : fix ggml-metal.metal path and run nixfmt (#1974)
Rowan Hart [Sat, 24 Jun 2023 11:07:08 +0000 (04:07 -0700)]
flake : fix ggml-metal.metal path and run nixfmt (#1974)

2 years agoconvert : fix invalid params in write_vocab_only (#1975)
AN Long [Sat, 24 Jun 2023 11:02:06 +0000 (19:02 +0800)]
convert : fix invalid params in write_vocab_only (#1975)

2 years agoggml : improve ggml_graph_dump_dot, add ggml_format_name (#1978)
slaren [Sat, 24 Jun 2023 10:57:18 +0000 (12:57 +0200)]
ggml : improve ggml_graph_dump_dot, add ggml_format_name (#1978)

* Improve ggml_graph_dump_dot, add ggml_format_name

* add more automatic names to view ops

* fix name of copies

2 years agoreadme : fix whitespaces
Georgi Gerganov [Sat, 24 Jun 2023 10:38:18 +0000 (13:38 +0300)]
readme : fix whitespaces

2 years agoreadme : fixed termux instructions (#1973)
Alberto [Sat, 24 Jun 2023 10:32:13 +0000 (12:32 +0200)]
readme : fixed termux instructions (#1973)

2 years agollama : fix top-p sampling to match the canonical definition (#1953)
Alex Renda [Sat, 24 Jun 2023 10:15:01 +0000 (03:15 -0700)]
llama : fix top-p sampling to match the canonical definition (#1953)

* Fix top-p sampling to match the standard definition (smallest set that has probability mass at least p, not largest set with probability mass less than p)

* top-p: correct gt to gte

* add test for correct top-p behavior

2 years agollama : make model stateless and context stateful (llama_state) (#1797)
Didzis Gosko [Sat, 24 Jun 2023 08:47:58 +0000 (11:47 +0300)]
llama : make model stateless and context stateful (llama_state) (#1797)

* llama : make model stateless and context stateful

* llama : minor cleanup

* llama : update internal API declaration

* Apply suggestions from code review

fix style

Co-authored-by: Georgi Gerganov <redacted>
* Missing model memory release

* Fix style

* Add deprecated warning for public API function llama_init_from_file

* Update public API use cases: move away from deprecated llama_init_from_file

* Deprecate public API function llama_apply_lora_from_file

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agoAdd OpenLLaMA instructions to the README (#1954)
eiery [Fri, 23 Jun 2023 08:38:01 +0000 (04:38 -0400)]
Add OpenLLaMA instructions to the README (#1954)

* add openllama to readme

2 years agorework convert.py to read hyper-parameters from config.json (#1958)
Erik Scholz [Thu, 22 Jun 2023 12:20:47 +0000 (14:20 +0200)]
rework convert.py to read hyper-parameters from config.json (#1958)

* Read hyper-parameters from HuggingFace-transformer config.json, if they exist, and fall back to guessing, like before otherwise.
  This allows converting open_llama 3B and other non-standard model designs.

2 years agocmake: revert CUDA arch default to 52, 61 if f16 (#1959)
Johannes Gäßler [Wed, 21 Jun 2023 21:49:25 +0000 (23:49 +0200)]
cmake: revert CUDA arch default to 52, 61 if f16 (#1959)

2 years agoFix typo in README.md (#1961)
Rahul Vivek Nair [Wed, 21 Jun 2023 21:48:43 +0000 (03:18 +0530)]
Fix typo in README.md (#1961)

2 years agoreadme : add link to p1
Georgi Gerganov [Tue, 20 Jun 2023 16:05:54 +0000 (19:05 +0300)]
readme : add link to p1

2 years agoFix typo (#1949)
Xiake Sun [Tue, 20 Jun 2023 12:42:40 +0000 (05:42 -0700)]
Fix typo (#1949)

2 years agollama : fix params struct slignment (#1936)
Ettore Di Giacinto [Tue, 20 Jun 2023 01:24:39 +0000 (03:24 +0200)]
llama : fix params struct slignment (#1936)

* Workaround struct misalignment during value-copy

Signed-off-by: mudler <redacted>
* Move booleans at the bottom of the structure

Signed-off-by: mudler <redacted>
* Add comment

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

Signed-off-by: mudler <redacted>
2 years ago[Fix] Reenable server embedding endpoint (#1937)
Henri Vasserman [Mon, 19 Jun 2023 22:12:39 +0000 (01:12 +0300)]
[Fix] Reenable server embedding endpoint (#1937)

* Add back embedding feature

* Update README

2 years agoggml : fix bug in LBFGS optimizer (found by ggml tests)
Georgi Gerganov [Mon, 19 Jun 2023 17:43:30 +0000 (20:43 +0300)]
ggml : fix bug in LBFGS optimizer (found by ggml tests)

2 years agollama : use aligned memory during ggml_init call from loading saved sessions (#1934)
l3utterfly [Mon, 19 Jun 2023 15:20:06 +0000 (23:20 +0800)]
llama : use aligned memory during ggml_init call from loading saved sessions (#1934)

* fixed issue: memory is not guaranteed to be aligned properly during ggml_init call from loading saved sessions

* - removed commented out old code from fix
- updated another instance of same issue below original

2 years agocmake : fix trailing whitespaces
Georgi Gerganov [Mon, 19 Jun 2023 15:18:34 +0000 (18:18 +0300)]
cmake : fix trailing whitespaces

2 years agollama : only use Q6_K for output weights if tensor size is multiple of 256 (#1932)
Kawrakow [Mon, 19 Jun 2023 15:17:03 +0000 (18:17 +0300)]
llama : only use Q6_K for output weights if tensor size is multiple of 256 (#1932)

* Only use Q6_K for output weights if tensor size is multiple of 256

* Fixed copy/paste mistake

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agocuda : faster k-quants on older GPUs (#1930)
Kawrakow [Mon, 19 Jun 2023 15:14:09 +0000 (18:14 +0300)]
cuda : faster k-quants on older GPUs (#1930)

* k_quants: hopefully much faster Q4_K on older GPUs

On the GTX-1660 that I have available to represent
"old GPUs", token prediction drops from 65.5 ms/tok
to 41.5 ms/tok!

* k_quants: hopefully much faster Q3_K on older GPUs

On the GTX-1660 that I have available to represent
"old GPUs", token prediction drops from 60.3 ms/tok
to 41.0 ms/tok!

* k_quants: faster Q2_K on older GPUs

It looks like I didn't need to change anything
compared to what we already had, so this is just
adding clarifying comments. But I now measure
36.3 ms/tok on the GTX-1660, instead fo the
47.2 ms/tok that I have written in the faster
k-quants PR.

* k_quants: faster Q5_K on older GPUs

68.5 ms/tok -> 62.0 ms/tok on GTX-1660.
For some reason the same access pattern that leads
to such resounding success for Q2_K to Q4_K did not
work at all for Q5_K.

It is also more difficult to measure because for Q5_K_S
we only have 32 layers on the GTX-1660, so output, tok embeddings
and kv cache are done on the CPU.

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agoggml : sync latest ggml repo (#1924)
Georgi Gerganov [Mon, 19 Jun 2023 15:12:33 +0000 (18:12 +0300)]
ggml : sync latest ggml repo (#1924)

* ggml : sync latest ggml repo

* ggml : remove unused comments

* ggml : asserts

2 years agocmake : fix build shared ggml when CUDA is enabled (#1929)
Howard Su [Mon, 19 Jun 2023 15:10:37 +0000 (23:10 +0800)]
cmake : fix build shared ggml when CUDA is enabled (#1929)

Co-authored-by: Georgi Gerganov <redacted>
2 years agoConvert vector to f16 for dequantize mul mat vec (#1913)
Johannes Gäßler [Mon, 19 Jun 2023 08:23:56 +0000 (10:23 +0200)]
Convert vector to f16 for dequantize mul mat vec (#1913)

* Convert vector to f16 for dmmv

* compile option

* Added compilation option description to README

* Changed cmake CUDA_ARCHITECTURES from "OFF" to "native"

2 years agoAdded tokens per second to info prints (#1928)
Johannes Gäßler [Sun, 18 Jun 2023 15:41:26 +0000 (17:41 +0200)]
Added tokens per second to info prints (#1928)

2 years agoFixed incorrectly applying RMS norm twice (#1925)
Johannes Gäßler [Sun, 18 Jun 2023 14:07:09 +0000 (16:07 +0200)]
Fixed incorrectly applying RMS norm twice (#1925)

2 years agoggml : fix bug in ggml_compute_forward_add_q_f32 (#1918)
l3utterfly [Sun, 18 Jun 2023 11:19:16 +0000 (19:19 +0800)]
ggml : fix bug in ggml_compute_forward_add_q_f32 (#1918)

2 years agoreadme : update Android build instructions (#1922)
Mike [Sun, 18 Jun 2023 08:28:26 +0000 (16:28 +0800)]
readme : update Android build instructions (#1922)

Add steps for using termux on android devices to prevent common errors.

2 years agollama : prevent usage of k-quants when tensor size is not a multiple of 256 (#1921)
Kawrakow [Sun, 18 Jun 2023 08:13:43 +0000 (11:13 +0300)]
llama : prevent usage of k-quants when tensor size is not a multiple of 256 (#1921)

* Fix examples/metal

* k-quants: prevent usage when tensor size is not divisible by 256

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agoexamples : fix examples/metal (#1920)
Kawrakow [Sun, 18 Jun 2023 07:52:10 +0000 (10:52 +0300)]
examples : fix examples/metal (#1920)

Co-authored-by: Iwan Kawrakow <redacted>
2 years agometal : handle buffers larger than device's maxBufferLength (#1826)
Georgi Gerganov [Sun, 18 Jun 2023 06:09:47 +0000 (09:09 +0300)]
metal : handle buffers larger than device's maxBufferLength (#1826)

* metal : handle buffers larger than device's maxBufferLength

* metal : print more verbose device info + handle errors

* metal : fix prints for overlapping views

* metal : minimize view overlap to try to utilize device memory better

2 years agocmake : add CUDA_ARCHITECTURES to new target ggml_static (#1917)
Howard Su [Sun, 18 Jun 2023 04:29:47 +0000 (12:29 +0800)]
cmake : add CUDA_ARCHITECTURES to new target ggml_static (#1917)

2 years agomake : do not print help for simple example
Georgi Gerganov [Sat, 17 Jun 2023 17:55:03 +0000 (20:55 +0300)]
make : do not print help for simple example

2 years agominor : warning fixes
Georgi Gerganov [Sat, 17 Jun 2023 17:24:11 +0000 (20:24 +0300)]
minor : warning fixes

2 years agoOnly one CUDA stream per device for async compute (#1898)
Johannes Gäßler [Sat, 17 Jun 2023 17:15:02 +0000 (19:15 +0200)]
Only one CUDA stream per device for async compute (#1898)

2 years agollama : fix kv_cache `n` init (close #1903)
Georgi Gerganov [Sat, 17 Jun 2023 16:30:22 +0000 (19:30 +0300)]
llama : fix kv_cache `n` init (close #1903)

2 years agomake : update for latest Arch (#1701)
DaniAndTheWeb [Sat, 17 Jun 2023 16:17:22 +0000 (18:17 +0200)]
make : update for latest Arch (#1701)

With the upcoming change to the openblas package in arch the Makefile workaround is no longer needed.

2 years agoggml : fix warnings under MSVC (#1908)
Howard Su [Sat, 17 Jun 2023 15:46:15 +0000 (23:46 +0800)]
ggml : fix warnings under MSVC (#1908)

2 years agometal : add norm, cpy f16->f16, alibi kernels (#1823)
Aaron Miller [Sat, 17 Jun 2023 14:37:49 +0000 (07:37 -0700)]
metal : add norm, cpy f16->f16, alibi kernels (#1823)

2 years agoexposed modules so that they can be invoked by nix run github:ggerganov/llama.cpp...
Faez Shakil [Sat, 17 Jun 2023 12:13:05 +0000 (17:13 +0500)]
exposed modules so that they can be invoked by nix run github:ggerganov/llama.cpp#server etc (#1863)

2 years agoServer Example Refactor and Improvements (#1570)
Randall Fitzgerald [Sat, 17 Jun 2023 11:53:04 +0000 (07:53 -0400)]
Server Example Refactor and Improvements (#1570)

A major rewrite for the server example.

Note that if you have built something on the previous server API, it will probably be incompatible.
Check out the examples for how a typical chat app could work.

This took a lot of effort, there are 24 PR's closed in the submitter's repo alone, over 160 commits and a lot of comments and testing.

Summary of the changes:

- adds missing generation parameters: tfs_z, typical_p, repeat_last_n, repeat_penalty, presence_penalty, frequency_penalty, mirostat, penalize_nl, seed, ignore_eos
- applies missing top k sampler
- removes interactive mode/terminal-like behavior, removes exclude parameter
- moves threads and batch size to server command-line parameters
- adds LoRA loading and matches command line parameters with main example
- fixes stopping on EOS token and with the specified token amount with n_predict
- adds server timeouts, host, and port settings
- adds expanded generation complete response; adds generation settings, stop reason, prompt truncated, model used, and final text
- sets defaults for unspecified parameters between requests
- removes /next-token endpoint and as_loop parameter, adds stream parameter and server-sent events for streaming
- adds CORS headers to responses
- adds request logging, exception printing and optional verbose logging
- adds better stopping words handling when matching multiple tokens and while streaming, or when it finishes on a partial stop string
- adds printing an error when it can't bind to the host/port specified
- fixes multi-byte character handling and replaces invalid UTF-8 characters on responses
- prints timing and build info on startup
- adds logit bias to request parameters
- removes embedding mode
- updates documentation; adds streaming Node.js and Bash examples
- fixes code formatting
- sets server threads to 1 since the current global state doesn't work well with simultaneous requests
- adds truncation of the input prompt and better context reset
- removes token limit from the input prompt
- significantly simplified the logic and removed a lot of variables

---------

Co-authored-by: anon998 <redacted>
Co-authored-by: Henri Vasserman <redacted>
Co-authored-by: Felix Hellmann <redacted>
Co-authored-by: Johannes Gäßler <redacted>
Co-authored-by: Lesaun Harvey <redacted>
2 years agohooks : setting up flake8 and pre-commit hooks (#1681)
Jiří Podivín [Sat, 17 Jun 2023 10:32:48 +0000 (12:32 +0200)]
hooks : setting up flake8 and pre-commit hooks (#1681)

Small, non-functional changes were made to non-compliant files.
These include breaking up long lines, whitespace sanitation and
unused import removal.

Maximum line length in python files was set to a generous 125 chars,
in order to minimize number of changes needed in scripts and general
annoyance. The "txt" prompts directory is excluded from the checks
as it may contain oddly formatted files and strings for a good reason.

Signed-off-by: Jiri Podivin <redacted>
2 years agoreadme : alternative way to build for Android with CLBlast. (#1828)
Gustavo Rocha Dias [Sat, 17 Jun 2023 09:01:06 +0000 (06:01 -0300)]
readme :  alternative way to build for Android with CLBlast. (#1828)

2 years agoAllow cmake to build ggml as a library (#1896)
Kerfuffle [Sat, 17 Jun 2023 07:49:42 +0000 (01:49 -0600)]
Allow cmake to build ggml as a library (#1896)

* Allow cmake to build ggml as a library

* A ggml_static library will be created

* When BUILD_SHARED_LIBS is enabled, ggml_shared will also be built

2 years agotrain : get raw text instead of page with html (#1905)
David Yang [Sat, 17 Jun 2023 06:51:54 +0000 (14:51 +0800)]
train : get raw text instead of page with html (#1905)

We probably want to train using just the text of Shakespeare instead of the html of the page displaying his work.

2 years agoopencl : support k-quants (#1836)
0cc4m [Fri, 16 Jun 2023 18:59:49 +0000 (20:59 +0200)]
opencl : support k-quants (#1836)

* Porting q2_k kernel to OpenCL

* Set global and local sizes for kernel calls for dequantizing k-quants

* Added q6_k kernel

* Fix q4_k opencl struct order

* Replace uchar with uint8_t

* Finish dequant kernels

* Added OpenCL DMMV kernels

* Fix q2_k, improve code

* Fix q3_k

* Shorten switch statements

* Improve code formatting

---------

Co-authored-by: Concedo <redacted>
2 years agoexamples : add "simple" (#1840)
SuperUserNameMan [Fri, 16 Jun 2023 18:58:09 +0000 (20:58 +0200)]
examples : add "simple" (#1840)

* Create `simple.cpp`

* minimalist example `CMakeLists.txt`

* Update Makefile for minimalist example

* remove 273: Trailing whitespace

* removed trailing white spaces simple.cpp

* typo and comments simple.cpp

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agocmake : add auto detection of BLAS_INCLUDE_DIRS (#1886)
Zenix [Fri, 16 Jun 2023 18:53:04 +0000 (03:53 +0900)]
cmake : add auto detection of BLAS_INCLUDE_DIRS (#1886)

2 years agollama : fix embd when offloading non-repeating layers (#1891)
Johannes Gäßler [Fri, 16 Jun 2023 18:25:51 +0000 (20:25 +0200)]
llama : fix embd when offloading non-repeating layers (#1891)

2 years agoFixed possible macro redefinition (#1892)
FrankHB [Fri, 16 Jun 2023 18:25:01 +0000 (02:25 +0800)]
Fixed possible macro redefinition (#1892)

MinGW libstdc++ may define `NOMINMAX` unconditionally. This fixes the case when it is already defined.

2 years agobuild : fix and ignore MSVC warnings (#1889)
Borislav Stanimirov [Fri, 16 Jun 2023 18:23:53 +0000 (21:23 +0300)]
build : fix and ignore MSVC warnings (#1889)

2 years agoCUDA : faster k-quant dot kernels (#1862)
Kawrakow [Fri, 16 Jun 2023 17:08:44 +0000 (20:08 +0300)]
CUDA : faster k-quant dot kernels (#1862)

* cuda : faster k-quant dot kernels

* Imrove Q2_K dot kernel on older GPUs

We now have a K_QUANTS_PER_ITERATION macro, which should be
set to 1 on older and to 2 on newer GPUs.
With this, we preserve the performance of the original
PR on RTX-4080, and are faster compared to master on
GTX-1660.

* Imrove Q6_K dot kernel on older GPUs

Using the same K_QUANTS_PER_ITERATION macro as last commit,
we preserve performance on RTX-4080 and speed up
Q6_K on a GTX-1660.

* Add LLAMA_CUDA_KQUANTS_ITER to CMakeLists.txt and Makefile

Allowed values are 1 or 2. 2 gives the best performance on
modern GPUs and is set as default. On older GPUs 1 may work
better.

* PR comments

---------

Co-authored-by: Iwan Kawrakow <redacted>
2 years agogitignore : add several entries specific to Visual Studio (#1888)
Borislav Stanimirov [Fri, 16 Jun 2023 06:58:11 +0000 (09:58 +0300)]
gitignore : add several entries specific to Visual Studio (#1888)

2 years agoFixed CUDA runtime version check (#1879)
Johannes Gäßler [Thu, 15 Jun 2023 19:49:08 +0000 (21:49 +0200)]
Fixed CUDA runtime version check (#1879)

2 years agocmake : remove whitespaces
Georgi Gerganov [Thu, 15 Jun 2023 18:56:50 +0000 (21:56 +0300)]
cmake : remove whitespaces

2 years agoexamples : add chat-vicuna.sh (#1854)
yangli2 [Thu, 15 Jun 2023 18:05:53 +0000 (11:05 -0700)]
examples : add chat-vicuna.sh (#1854)

Co-authored-by: Yang Li <redacted>
2 years agocmake : set include path for OpenBlas (#1830)
Igor Okulist [Thu, 15 Jun 2023 17:51:26 +0000 (12:51 -0500)]
cmake : set include path for OpenBlas (#1830)

2 years agoswift : Package compile breaks due to ggml-metal.metal (#1831)
Frederik Vogel [Thu, 15 Jun 2023 17:47:04 +0000 (02:47 +0900)]
swift : Package compile breaks due to ggml-metal.metal (#1831)

* Ignore metal file in spm

* Add ggml.h to spm public Headers

---------

Co-authored-by: Vogel Frederik <redacted>
2 years agomake : add train-text-from-scratch (#1850)
daboe01 [Thu, 15 Jun 2023 17:42:48 +0000 (19:42 +0200)]
make : add train-text-from-scratch (#1850)

* make finetuning example accessible

* fixed: targed was in wrong line

* fixed: name of executable was wrong

* fixed: naming of binary

* fixed: model path was wrong

* fixed clean target

* Update examples/train-text-from-scratch/README.md

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agoreadme : server compile flag (#1874)
Srinivas Billa [Thu, 15 Jun 2023 17:36:38 +0000 (18:36 +0100)]
readme : server compile flag (#1874)

Explicitly include the server make instructions for C++ noobsl like me ;)

2 years agomake : clean *.so files (#1857)
sandyiscool [Thu, 15 Jun 2023 17:36:06 +0000 (23:06 +0530)]
make : clean *.so files (#1857)

2 years agoFix the validation of main device (#1872)
Howard Su [Thu, 15 Jun 2023 17:29:59 +0000 (01:29 +0800)]
Fix the validation of main device (#1872)

2 years agometal : parallel command buffer encoding (#1860)
Georgi Gerganov [Thu, 15 Jun 2023 17:29:48 +0000 (20:29 +0300)]
metal : parallel command buffer encoding (#1860)

* metal : parallel command buffer encoding

* metal : determine number of command buffers based on gf->n_threads

2 years agoBetter error when using both LoRA + GPU layers (#1861)
Johannes Gäßler [Thu, 15 Jun 2023 17:06:46 +0000 (19:06 +0200)]
Better error when using both LoRA + GPU layers (#1861)

2 years agoCUDA full GPU acceleration, KV cache in VRAM (#1827)
Johannes Gäßler [Wed, 14 Jun 2023 17:47:19 +0000 (19:47 +0200)]
CUDA full GPU acceleration, KV cache in VRAM (#1827)

* Fixed CUDA RoPE

* ggml_cuda_mul_mat_vec_p021

* ggml_cuda_scale

* ggml_cuda_diag_mask_inf

* ggml_is_permuted

* ggml_cuda_cpy

* flatten rows for ggml_cuda_op

* Added a --low-vram option

* Fixed Windows performance

* Fixed LLAMA_CUDA_DMMV_Y > 1 for WizardLM

2 years agobaby-llama : fix operator!= (#1821)
0xspringtime [Tue, 13 Jun 2023 19:37:54 +0000 (15:37 -0400)]
baby-llama : fix operator!= (#1821)

* Update baby-llama.cpp

Seems to be an error in the implementation of the operator!= function. It attempts to compare the this pointer (a llama_hparams_lora object) with the other pointer (a llama_hparams object) using memcmp. This can lead to incorrect results because the sizes of the objects being compared (sizeof(llama_hparams) and sizeof(llama_hparams_lora)) are different, should now be able to compare two llama_hparams_lora objects for inequality.

* Update baby-llama.cpp

* Update baby-llama.cpp

2 years agotrain : improved training-from-scratch example (#1652)
xaedes [Tue, 13 Jun 2023 19:04:40 +0000 (21:04 +0200)]
train : improved training-from-scratch example (#1652)

* add python wrapper

https://gist.github.com/abetlen/2b90e5f153f6efd00931d098de5c73ce

* fix decoding error. adds errors=ignore parameter

* add python bindings for functions to get and set the whole llama state
(rng, logits, embedding and kv_cache)

* update python bindings

* add text generating baby-llama from scratch example

* fix race condition bug in ggml_compute_forward_diag_mask_f32

* implement ggml_soft_max_back for more performant backward pass of soft_max

avoids creating big intermediate matrices of size n_embd x n_embd for llama layers and n_vocab x n_vocab for cross entropy loss

* improve softmax backward pass

go from quadratic runtime to linear runtime by simplifying the formulas

* fix race condition bug in non-inplace ggml_compute_forward_diag_mask_f32

memcpy needs to be synchronized across threads to avoid race conditions.
=> do it in INIT phase

* fix bug in ggml_compute_forward_soft_max_back_f32 on DEBUG build

* improve performance of mul_mat backward pass

avoid transpose by using mul_mat with swapped arguments

* avoid printing too much newlines in baby-llama-text

* activate threading in baby-llama-text

* add ggml_out_prod and use it for mul_mat backward pass for improved performance

performance stats report improvement from 37 seconds to 16 seconds runtime during my training tests

* better weight initialization improves training convergence at start

* better weight initialization improves training convergence at start

* improve ggml_out_prod performance

- change iteration order (>15s -> 10s runtime)
- parallelize over one more dimension: over dst matrix rows (10s -> <5s runtime)

* add llama sampler, shuffle samples and constrain sampling to tokens occurring in train data

* fix get_samples call, add model tensor names, increase model size, start training samples after newline

* save train trained model to checkpoint and load model to be trained from checkpoint

* use inplace functions where possible

* initialize rng with srand

* use different arguments for input and output checkpoint

* ggml fixes to support backward pass on inplace operations

* remove duplicate include

* fix cross entropy loss

- add target probabilities for each sample which is then used in cross entropy loss

* print used memory before and after optimization

* sample with non-greedy sampling parameters at the end of training

* add cmake target for baby-llama-text

* add ggml_add1_inplace to header

* enable gradient propagation for inplace add1 and scale operations

those functions backward passes don't need the original src0, so they also work when forward is inplace

* implement AdamW in ggml_opt_adam by adding weight decay parameter (default 0.001f)

also add a schedule parameter (default 1.0f) that can be used to scale alpha and decay according to learning schedule.
setting the decay parameter to zero disables AdamW resulting in normal Adam optimizer.

since the difference between Adam and AdamW is minimal it is not implemented as another optimizer, but integrated into the existing Adam optimizer.

* use inplace operations in cross_entropy_loss

* fix random weight initialization scale

* add missing default parameters for adam optimizer

* add ggml_opt_context, so that we can properly resume training

otherwise the optimizer states, tracking statistics about the error function and its derivates,
will reset to zero each time ggml_opt is called, hindering convergence on resumed training.

now the optimizer context and all its memory is stored in a separate struct.

* fix bug in llama_sample_token_mirostat_v2

when all candidates are filtered out through mu threshold, the following soft_max operation will fail.
so keep at least one.

* add forward function without using cache, for more performant training

during training on whole samples no cache is required.
removing the cache and simplifying the remaining code results in performance and memory usage improvement.

* print suppressed newline tokens as string "\n"

printing too much actual newlines is suppressed to avoid flooding the console.

* store optimizer state in training checkpoint and add learning schedule

persistent optimizer state allows to resume training without resetting the optimizer
learning schedule consists of linear warmup ramp followed by cosine decay with restarts

* remove unused functions

* fix bug in get_samples which corrupted training targets

* save checkpoint only when it was trained

* simplify code

* remove trailing whitespace

* simplify backward pass for SQRT

* replace inefficient repeat backward pass with dedicated repeat_back operation

* add ggml_cross_entropy_loss with backward pass for faster training

cross entropy loss can also be implemented using softmax and log, but as dedicated operation it is faster and especially avoids unnecessary memory overhead.

* add tests for cross_entropy_loss backward pass

finite differences regularly results in estimated gradient of zero, despite the backward pass giving non zero gradient.
_probably_ the finite differences fails due to numerical issues

* use ggml_cross_entropy_loss in text training example

* remove trailing whitespace

* slightly improve how cross entropy loss is compute

btw: directly implemented cross entropy loss seems to have way lower magnitudes than when implemented with softmax and log.
probably the input to log gets closer to zero due to float numerics.
maybe the multiplication by (1.0-eps)/sum is more accurate..

* add llama_get_vocab to get the vocabulary as output parameters

* set default model.type for unknown models with few layers

* add export of training checkpoint to llama compatible model file

* get vocabulary for exporting training checkpoint to llama compatible model file

* implement backward pass of flash attention

* bugfixes for backward pass of flash attention

* test flash attention backward pass

need to set loose error bounds to pass.
the finitie differences are close to numeric limits and often return quite different values than the backward pass.
reducing eps further lets the gradients vanish completely.
likewise setting eps to big results in wronger values.
the softmax in the middle of the function is probably the most responsible for the numeric issues using finite differences.

* add option to train with flash attention and move options to the top of the main function

training from scratch also works with flash attention
training convergence and generation results after fix number of iterations are worse than when not using flash attention.
maybe there still lingers a bug in the flash attention backward pass?
but training works, just with slower convergence.

flash attention is still worth to use, because it requires way less memory and is faster with high n_ctx

* add train_params and command line option parser

* remove unnecessary comments

* add train params to specify memory size

* remove python bindings

* rename baby-llama-text to train-text-from-scratch

* replace auto parameters in lambda function

* add #include <climits>

* add explicit cast to fix compile error

"error: non-constant-expression cannot be narrowed from type 'int64_t' (aka 'long long') to 'uint32_t' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]"

* remove trailing whitespace

* add ggml_opt_resume_g which accepts forward and backward cgraphs

* fix formulas in comments

* bug fix for ggml_compute_forward_get_rows_back_f32

the result should be set to zero, not to whatever data is in opt0

* improve training memory usage with scratch buffers

instead of relying on the automatic backward pass, we manually create the graph for the backward pass.
it turns out that all backward pass operations need only temporary memory which can be reused after each layer.

will compute backward pass for ALL model parameters

* add option to use scratch buffers in training or not

make it configurable because currently training with scratch buffers implies flash attention and optimization over all parameters.

* ci : disable temporary

* store view offset and permute axes in opt[0] instead of storing it in padding

use memcpy to store offset, because offset is of type size_t.
when storing it as int32_t offset would have to be smaller than 2^31 which is not necessarily true.

* minor : fix compile warnings + minor style changes

* fix bug in threaded indices calculation of ggml_compute_forward_flash_attn_back_f32

* store view offset like in master branch

* bug fix in forward_batch_wo_cache_flash_attn_train

* scratch buffer bug fixes in forward_batch_wo_cache_flash_attn_train

data of permute and reshape is the same as their input.
if we want to preserve the output of permute/reshape, we also need to preserve their inputs.

replace reshape(src0, src1) with reshape_nd calls so that we don't need src1.

replace (temporary) t03 with ggml_repeat(ctx0, layer.attention_norm, t02).
in the future we could also use the new broadcasting ggml_mul to avoid these repeat calls.
for this we need backward pass of broadcasting ggml_mul.

* remove unnecessary scratch buffer 0

buf 0 is persistent memory, so we can just disable scratch for this by using buf -1

* avoid creating unnecessary grad tensors

previously we need to create grads for model parameters, so that expand(..) correctly populates cgraph->leafs & cgraph->grads
this wasted memory, because unnecessary grad for each op were automatically created:
the automatically generated grad was unnecessary because we later manually set the grad (e.g. t35->grad = expand(gb, ...) ).
this discarded the automatically generated grad resulting in wasted memory.

improved this by changing expand(..) to not use ggml_build_forward_expand.
expand set cgraph->nodes but not the leafs.
cgraph->leafs & cgraph->grads are set in another pass after the last expand call.

* print used training seed

* zero initialize gfbuf and gbbuf

* ci : re-enable workflows + add README for training

---------

Co-authored-by: Georgi Gerganov <redacted>
2 years agollama : do a warm-up eval at start for better timings (#1824)
Georgi Gerganov [Tue, 13 Jun 2023 17:20:07 +0000 (20:20 +0300)]
llama : do a warm-up eval at start for better timings (#1824)

2 years agoAllow "quantizing" to f16 and f32 (#1787)
Kerfuffle [Tue, 13 Jun 2023 10:23:23 +0000 (04:23 -0600)]
Allow "quantizing" to f16 and f32 (#1787)

* Allow "quantizing" to f16 and f32

Fix an issue where quantizing didn't respect LLAMA_NO_K_QUANTS

Add brief help to the list of quantization types in the quantize tool

Ignore case for quantization type arguments in the quantize tool