2023-03-10 19:47:46 +00:00
# llama.cpp
2023-04-05 15:56:20 +00:00
![llama ](https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png )
2023-03-26 07:20:49 +00:00
2023-03-12 20:09:26 +00:00
[![License: MIT ](https://img.shields.io/badge/license-MIT-blue.svg )](https://opensource.org/licenses/MIT)
2023-10-04 13:50:44 +00:00
[Roadmap ](https://github.com/users/ggerganov/projects/7 ) / [Project status ](https://github.com/ggerganov/llama.cpp/discussions/3471 ) / [Manifesto ](https://github.com/ggerganov/llama.cpp/discussions/205 ) / [ggml ](https://github.com/ggerganov/ggml )
2023-06-25 13:08:12 +00:00
2023-03-15 19:39:06 +00:00
Inference of [LLaMA ](https://arxiv.org/abs/2302.13971 ) model in pure C/C++
2023-03-10 19:47:46 +00:00
2023-08-21 20:07:43 +00:00
### Hot topics
2023-08-27 11:44:35 +00:00
2024-01-31 15:30:17 +00:00
- Remove LLAMA_MAX_DEVICES and LLAMA_SUPPORTS_GPU_OFFLOAD: https://github.com/ggerganov/llama.cpp/pull/5240
- Incoming backends: https://github.com/ggerganov/llama.cpp/discussions/5138
2024-01-31 02:38:07 +00:00
- [SYCL backend ](README-sycl.md ) is ready (1/28/2024), support Linux/Windows in Intel GPUs (iGPU, Arc/Flex/Max series)
2024-01-08 18:25:17 +00:00
- New SOTA quantized models, including pure 2-bits: https://huggingface.co/ikawrakow
2023-12-17 18:16:23 +00:00
- Collecting Apple Silicon performance stats:
- M-series: https://github.com/ggerganov/llama.cpp/discussions/4167
- A-series: https://github.com/ggerganov/llama.cpp/discussions/4508
2023-11-25 10:02:13 +00:00
- Looking for contributions to improve and maintain the `server` example: https://github.com/ggerganov/llama.cpp/issues/4216
2023-08-18 14:48:31 +00:00
----
2023-03-14 07:43:52 +00:00
2023-05-08 16:33:30 +00:00
< details >
< summary > Table of Contents< / summary >
< ol >
< li >
< a href = "#description" > Description< / a >
< / li >
< li >
< a href = "#usage" > Usage< / a >
< ul >
< li > < a href = "#get-the-code" > Get the Code< / a > < / li >
< li > < a href = "#build" > Build< / a > < / li >
< li > < a href = "#blas-build" > BLAS Build< / a > < / li >
< li > < a href = "#prepare-data--run" > Prepare Data & Run< / a > < / li >
< li > < a href = "#memorydisk-requirements" > Memory/Disk Requirements< / a > < / li >
< li > < a href = "#quantization" > Quantization< / a > < / li >
< li > < a href = "#interactive-mode" > Interactive mode< / a > < / li >
2023-08-23 01:01:57 +00:00
< li > < a href = "#constrained-output-with-grammars" > Constrained output with grammars< / a > < / li >
2023-05-08 16:33:30 +00:00
< li > < a href = "#instruction-mode-with-alpaca" > Instruction mode with Alpaca< / a > < / li >
2023-06-23 08:38:01 +00:00
< li > < a href = "#using-openllama" > Using OpenLLaMA< / a > < / li >
2023-05-08 16:33:30 +00:00
< li > < a href = "#using-gpt4all" > Using GPT4All< / a > < / li >
< li > < a href = "#using-pygmalion-7b--metharme-7b" > Using Pygmalion 7B & Metharme 7B< / a > < / li >
< li > < a href = "#obtaining-the-facebook-llama-original-model-and-stanford-alpaca-model-data" > Obtaining the Facebook LLaMA original model and Stanford Alpaca model data< / a > < / li >
< li > < a href = "#verifying-the-model-files" > Verifying the model files< / a > < / li >
< li > < a href = "#seminal-papers-and-background-on-the-models" > Seminal papers and background on the models< / a > < / li >
< li > < a href = "#perplexity-measuring-model-quality" > Perplexity (measuring model quality)< / a > < / li >
< li > < a href = "#android" > Android< / a > < / li >
< li > < a href = "#docker" > Docker< / a > < / li >
< / ul >
< / li >
< li > < a href = "#contributing" > Contributing< / a > < / li >
< li > < a href = "#coding-guidelines" > Coding guidelines< / a > < / li >
< li > < a href = "#docs" > Docs< / a > < / li >
< / ol >
< / details >
2023-03-10 19:47:46 +00:00
## Description
2023-04-26 20:24:42 +00:00
The main goal of `llama.cpp` is to run the LLaMA model using 4-bit integer quantization on a MacBook
2023-03-10 19:47:46 +00:00
- Plain C/C++ implementation without dependencies
2023-06-04 20:34:30 +00:00
- Apple silicon first-class citizen - optimized via ARM NEON, Accelerate and Metal frameworks
2023-05-05 14:43:36 +00:00
- AVX, AVX2 and AVX512 support for x86 architectures
2023-03-10 19:47:46 +00:00
- Mixed F16 / F32 precision
2023-08-23 20:41:16 +00:00
- 2-bit, 3-bit, 4-bit, 5-bit, 6-bit and 8-bit integer quantization support
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
- CUDA, Metal, OpenCL, SYCL GPU backend support
2023-03-10 19:47:46 +00:00
2023-04-26 20:24:42 +00:00
The original implementation of `llama.cpp` was [hacked in an evening ](https://github.com/ggerganov/llama.cpp/issues/33#issuecomment-1465108022 ).
2023-08-23 20:41:16 +00:00
Since then, the project has improved significantly thanks to many contributions. This project is mainly for educational purposes and serves
2023-04-26 20:24:42 +00:00
as the main playground for developing new features for the [ggml ](https://github.com/ggerganov/ggml ) library.
2023-03-11 10:31:21 +00:00
2023-04-05 15:56:20 +00:00
**Supported platforms:**
2023-03-12 06:41:54 +00:00
- [X] Mac OS
- [X] Linux
2023-03-13 17:21:51 +00:00
- [X] Windows (via CMake)
2023-03-17 09:47:06 +00:00
- [X] Docker
2023-03-12 06:41:54 +00:00
2023-04-05 15:56:20 +00:00
**Supported models:**
2023-03-29 16:37:20 +00:00
2023-03-30 19:31:54 +00:00
- [X] LLaMA 🦙
2023-07-28 01:14:11 +00:00
- [x] LLaMA 2 🦙🦙
2023-08-23 20:41:16 +00:00
- [X] Falcon
2023-03-29 16:37:20 +00:00
- [X] [Alpaca ](https://github.com/ggerganov/llama.cpp#instruction-mode-with-alpaca )
- [X] [GPT4All ](https://github.com/ggerganov/llama.cpp#using-gpt4all )
2023-08-02 06:18:31 +00:00
- [X] [Chinese LLaMA / Alpaca ](https://github.com/ymcui/Chinese-LLaMA-Alpaca ) and [Chinese LLaMA-2 / Alpaca-2 ](https://github.com/ymcui/Chinese-LLaMA-Alpaca-2 )
2023-03-30 19:31:54 +00:00
- [X] [Vigogne (French) ](https://github.com/bofenghuang/vigogne )
2023-04-05 15:56:20 +00:00
- [X] [Vicuna ](https://github.com/ggerganov/llama.cpp/discussions/643#discussioncomment-5533894 )
2023-04-10 20:41:53 +00:00
- [X] [Koala ](https://bair.berkeley.edu/blog/2023/04/03/koala/ )
2023-05-04 16:33:31 +00:00
- [X] [OpenBuddy 🐶 (Multilingual) ](https://github.com/OpenBuddy/OpenBuddy )
2023-10-17 18:13:21 +00:00
- [X] [Pygmalion/Metharme ](#using-pygmalion-7b--metharme-7b )
2023-05-19 17:16:30 +00:00
- [X] [WizardLM ](https://github.com/nlpxucan/WizardLM )
2023-10-17 18:13:21 +00:00
- [X] [Baichuan 1 & 2 ](https://huggingface.co/models?search=baichuan-inc/Baichuan ) + [derivations ](https://huggingface.co/hiyouga/baichuan-7b-sft )
- [X] [Aquila 1 & 2 ](https://huggingface.co/models?search=BAAI/Aquila )
2023-09-29 12:50:35 +00:00
- [X] [Starcoder models ](https://github.com/ggerganov/llama.cpp/pull/3187 )
- [X] [Mistral AI v0.1 ](https://huggingface.co/mistralai/Mistral-7B-v0.1 )
2023-10-06 19:13:36 +00:00
- [X] [Refact ](https://huggingface.co/smallcloudai/Refact-1_6B-fim )
2023-10-17 18:13:21 +00:00
- [X] [Persimmon 8B ](https://github.com/ggerganov/llama.cpp/pull/3410 )
2023-10-10 23:02:49 +00:00
- [X] [MPT ](https://github.com/ggerganov/llama.cpp/pull/3417 )
2023-10-17 18:13:21 +00:00
- [X] [Bloom ](https://github.com/ggerganov/llama.cpp/pull/3553 )
2023-12-14 07:38:49 +00:00
- [x] [Yi models ](https://huggingface.co/models?search=01-ai/Yi )
2023-11-14 10:17:12 +00:00
- [X] [StableLM-3b-4e1t ](https://github.com/ggerganov/llama.cpp/pull/3586 )
2023-12-14 07:38:49 +00:00
- [x] [Deepseek models ](https://huggingface.co/models?search=deepseek-ai/deepseek )
- [x] [Qwen models ](https://huggingface.co/models?search=Qwen/Qwen )
- [x] [Mixtral MoE ](https://huggingface.co/models?search=mistral-ai/Mixtral )
2023-12-24 13:35:49 +00:00
- [x] [PLaMo-13B ](https://github.com/ggerganov/llama.cpp/pull/3557 )
2023-12-28 14:03:57 +00:00
- [x] [GPT-2 ](https://huggingface.co/gpt2 )
2024-02-05 07:41:38 +00:00
- [x] [CodeShell ](https://github.com/WisdomShell/codeshell )
2023-12-14 07:38:49 +00:00
**Multimodal models:**
- [x] [Llava 1.5 models ](https://huggingface.co/collections/liuhaotian/llava-15-653aac15d994e992e2677a7e )
- [x] [Bakllava ](https://huggingface.co/models?search=SkunkworksAI/Bakllava )
- [x] [Obsidian ](https://huggingface.co/NousResearch/Obsidian-3B-V0.5 )
- [x] [ShareGPT4V ](https://huggingface.co/models?search=Lin-Chen/ShareGPT4V )
2024-01-25 20:14:32 +00:00
- [x] [MobileVLM 1.7B/3B models ](https://huggingface.co/models?search=mobileVLM )
2023-10-17 18:13:21 +00:00
2023-04-05 15:56:20 +00:00
**Bindings:**
- Python: [abetlen/llama-cpp-python ](https://github.com/abetlen/llama-cpp-python )
- Go: [go-skynet/go-llama.cpp ](https://github.com/go-skynet/go-llama.cpp )
2023-10-22 18:16:43 +00:00
- Node.js: [withcatai/node-llama-cpp ](https://github.com/withcatai/node-llama-cpp )
2024-01-07 20:24:11 +00:00
- JS/TS (llama.cpp server client): [lgrammel/modelfusion ](https://modelfusion.dev/integration/model-provider/llamacpp )
2023-04-17 19:34:35 +00:00
- Ruby: [yoshoku/llama_cpp.rb ](https://github.com/yoshoku/llama_cpp.rb )
2024-01-28 08:30:44 +00:00
- Rust (nicer API): [mdrokz/rust-llama.cpp ](https://github.com/mdrokz/rust-llama.cpp )
- Rust (more direct bindings): [utilityai/llama-cpp-rs ](https://github.com/utilityai/llama-cpp-rs )
2023-05-12 05:39:40 +00:00
- C#/.NET: [SciSharp/LLamaSharp ](https://github.com/SciSharp/LLamaSharp )
2023-06-26 19:47:59 +00:00
- Scala 3: [donderom/llm4s ](https://github.com/donderom/llm4s )
2023-08-18 19:39:22 +00:00
- Clojure: [phronmophobic/llama.clj ](https://github.com/phronmophobic/llama.clj )
2023-08-29 09:30:10 +00:00
- React Native: [mybigday/llama.rn ](https://github.com/mybigday/llama.rn )
2023-09-01 13:36:14 +00:00
- Java: [kherud/java-llama.cpp ](https://github.com/kherud/java-llama.cpp )
2023-12-22 06:49:54 +00:00
- Zig: [deins/llama.cpp.zig ](https://github.com/Deins/llama.cpp.zig )
2024-01-20 08:05:43 +00:00
- Flutter/Dart: [netdur/llama_cpp_dart ](https://github.com/netdur/llama_cpp_dart )
2023-04-05 15:56:20 +00:00
**UI:**
- [nat/openplayground ](https://github.com/nat/openplayground )
- [oobabooga/text-generation-webui ](https://github.com/oobabooga/text-generation-webui )
2023-09-03 05:50:51 +00:00
- [withcatai/catai ](https://github.com/withcatai/catai )
2023-11-27 17:39:42 +00:00
- [semperai/amica ](https://github.com/semperai/amica )
2023-11-29 07:16:34 +00:00
- [psugihara/FreeChat ](https://github.com/psugihara/FreeChat )
2023-12-25 16:09:53 +00:00
- [ptsochantaris/emeltal ](https://github.com/ptsochantaris/emeltal )
2024-01-09 16:45:54 +00:00
- [iohub/collama ](https://github.com/iohub/coLLaMA )
2024-02-03 11:20:26 +00:00
- [pythops/tenere ](https://github.com/pythops/tenere )
2023-03-29 16:37:20 +00:00
2023-03-11 10:31:21 +00:00
---
2023-03-10 19:47:46 +00:00
2023-08-23 20:41:16 +00:00
Here is a typical run using LLaMA v2 13B on M2 Ultra:
2023-03-10 19:47:46 +00:00
```java
2023-08-23 20:41:16 +00:00
$ make -j && ./main -m models/llama-13b-v2/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e
2023-08-23 20:43:00 +00:00
I llama.cpp build info:
2023-03-10 19:47:46 +00:00
I UNAME_S: Darwin
I UNAME_P: arm
I UNAME_M: arm64
2023-08-23 20:41:16 +00:00
I CFLAGS: -I. -O3 -std=c11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -pthread -DGGML_USE_K_QUANTS -DGGML_USE_ACCELERATE
I CXXFLAGS: -I. -I./common -O3 -std=c++11 -fPIC -DNDEBUG -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar -pthread -DGGML_USE_K_QUANTS
2023-03-10 19:47:46 +00:00
I LDFLAGS: -framework Accelerate
2023-08-23 20:41:16 +00:00
I CC: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
I CXX: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
2023-03-10 19:47:46 +00:00
2023-03-10 22:09:19 +00:00
make: Nothing to be done for `default'.
2023-08-23 20:41:16 +00:00
main: build = 1041 (cf658ad)
main: seed = 1692823051
llama_model_loader: loaded meta data with 16 key-value pairs and 363 tensors from models/llama-13b-v2/ggml-model-q4_0.gguf (version GGUF V1 (latest))
llama_model_loader: - type f32: 81 tensors
llama_model_loader: - type q4_0: 281 tensors
llama_model_loader: - type q6_K: 1 tensors
llm_load_print_meta: format = GGUF V1 (latest)
llm_load_print_meta: arch = llama
llm_load_print_meta: vocab type = SPM
llm_load_print_meta: n_vocab = 32000
llm_load_print_meta: n_merges = 0
llm_load_print_meta: n_ctx_train = 4096
llm_load_print_meta: n_ctx = 512
llm_load_print_meta: n_embd = 5120
llm_load_print_meta: n_head = 40
llm_load_print_meta: n_head_kv = 40
llm_load_print_meta: n_layer = 40
llm_load_print_meta: n_rot = 128
llm_load_print_meta: n_gqa = 1
llm_load_print_meta: f_norm_eps = 1.0e-05
llm_load_print_meta: f_norm_rms_eps = 1.0e-05
llm_load_print_meta: n_ff = 13824
llm_load_print_meta: freq_base = 10000.0
llm_load_print_meta: freq_scale = 1
llm_load_print_meta: model type = 13B
llm_load_print_meta: model ftype = mostly Q4_0
llm_load_print_meta: model size = 13.02 B
llm_load_print_meta: general.name = LLaMA v2
llm_load_print_meta: BOS token = 1 '< s > '
llm_load_print_meta: EOS token = 2 '< / s > '
llm_load_print_meta: UNK token = 0 '< unk > '
llm_load_print_meta: LF token = 13 '< 0x0A > '
llm_load_tensors: ggml ctx size = 0.11 MB
llm_load_tensors: mem required = 7024.01 MB (+ 400.00 MB per state)
...................................................................................................
llama_new_context_with_model: kv self size = 400.00 MB
llama_new_context_with_model: compute buffer total size = 75.41 MB
2023-08-23 20:43:00 +00:00
system_info: n_threads = 16 / 24 | AVX = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | FMA = 0 | NEON = 1 | ARM_FMA = 1 | F16C = 0 | FP16_VA = 1 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 0 | VSX = 0 |
2023-08-23 20:41:16 +00:00
sampling: repeat_last_n = 64, repeat_penalty = 1.100000, presence_penalty = 0.000000, frequency_penalty = 0.000000, top_k = 40, tfs_z = 1.000000, top_p = 0.950000, typical_p = 1.000000, temp = 0.800000, mirostat = 0, mirostat_lr = 0.100000, mirostat_ent = 5.000000
generate: n_ctx = 512, n_batch = 512, n_predict = 400, n_keep = 0
Building a website can be done in 10 simple steps:
Step 1: Find the right website platform.
Step 2: Choose your domain name and hosting plan.
Step 3: Design your website layout.
Step 4: Write your website content and add images.
Step 5: Install security features to protect your site from hackers or spammers
Step 6: Test your website on multiple browsers, mobile devices, operating systems etc…
Step 7: Test it again with people who are not related to you personally – friends or family members will work just fine!
Step 8: Start marketing and promoting the website via social media channels or paid ads
Step 9: Analyze how many visitors have come to your site so far, what type of people visit more often than others (e.g., men vs women) etc…
Step 10: Continue to improve upon all aspects mentioned above by following trends in web design and staying up-to-date on new technologies that can enhance user experience even further!
How does a Website Work?
A website works by having pages, which are made of HTML code. This code tells your computer how to display the content on each page you visit – whether it’ s an image or text file (like PDFs). In order for someone else’ s browser not only be able but also want those same results when accessing any given URL; some additional steps need taken by way of programming scripts that will add functionality such as making links clickable!
The most common type is called static HTML pages because they remain unchanged over time unless modified manually (either through editing files directly or using an interface such as WordPress). They are usually served up via HTTP protocols – this means anyone can access them without having any special privileges like being part of a group who is allowed into restricted areas online; however, there may still exist some limitations depending upon where one lives geographically speaking.
How to
llama_print_timings: load time = 576.45 ms
llama_print_timings: sample time = 283.10 ms / 400 runs ( 0.71 ms per token, 1412.91 tokens per second)
llama_print_timings: prompt eval time = 599.83 ms / 19 tokens ( 31.57 ms per token, 31.68 tokens per second)
llama_print_timings: eval time = 24513.59 ms / 399 runs ( 61.44 ms per token, 16.28 tokens per second)
llama_print_timings: total time = 25431.49 ms
2023-03-10 19:47:46 +00:00
```
2023-03-10 22:51:46 +00:00
And here is another demo of running both LLaMA-7B and [whisper.cpp ](https://github.com/ggerganov/whisper.cpp ) on a single M1 Pro MacBook:
https://user-images.githubusercontent.com/1991296/224442907-7693d4be-acaa-4e01-8b4f-add84093ffff.mp4
2023-03-10 19:47:46 +00:00
## Usage
2023-10-17 18:13:21 +00:00
Here are the end-to-end binary build and model conversion steps for the LLaMA-7B model.
2023-04-13 13:43:22 +00:00
### Get the Code
2023-03-11 08:47:09 +00:00
2023-03-10 19:47:46 +00:00
```bash
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
2023-04-13 13:43:22 +00:00
```
### Build
2023-04-26 20:03:03 +00:00
In order to build llama.cpp you have three different options.
2023-04-13 13:43:22 +00:00
2023-04-26 20:03:03 +00:00
- Using `make` :
- On Linux or MacOS:
2023-04-13 13:43:22 +00:00
2023-04-26 20:03:03 +00:00
```bash
make
```
- On Windows:
2023-04-28 14:22:48 +00:00
1. Download the latest fortran version of [w64devkit ](https://github.com/skeeto/w64devkit/releases ).
2023-04-26 20:03:03 +00:00
2. Extract `w64devkit` on your pc.
3. Run `w64devkit.exe` .
4. Use the `cd` command to reach the `llama.cpp` folder.
5. From here you can run:
```bash
make
```
2023-03-10 19:47:46 +00:00
2023-04-26 20:03:03 +00:00
- Using `CMake` :
2023-04-05 14:36:12 +00:00
2023-04-13 13:43:22 +00:00
```bash
mkdir build
cd build
cmake ..
cmake --build . --config Release
```
2023-08-17 20:11:18 +00:00
- Using `Zig` (version 0.11 or later):
Building for optimization levels and CPU features can be accomplished using standard build arguments, for example AVX2, FMA, F16C,
it's also possible to cross compile for other operating systems and architectures:
2023-04-13 13:43:22 +00:00
```bash
2023-08-17 20:11:18 +00:00
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-windows-gnu -Dcpu=x86_64+avx2+fma+f16c
2023-04-13 13:43:22 +00:00
```
2023-08-17 20:11:18 +00:00
The `zig targets` command will give you valid options to use.
2023-07-23 11:52:08 +00:00
- Using `gmake` (FreeBSD):
1. Install and activate [DRM in FreeBSD ](https://wiki.freebsd.org/Graphics )
2. Add your user to **video** group
3. Install compilation dependencies.
```bash
sudo pkg install gmake automake autoconf pkgconf llvm15 clinfo clover \
opencl clblast openblas
2024-01-30 09:16:38 +00:00
gmake CC=/usr/local/bin/clang15 CXX=/usr/local/bin/clang++15 -j4
2023-07-23 11:52:08 +00:00
```
**Notes:** With this packages you can build llama.cpp with OPENBLAS and
CLBLAST support for use OpenCL GPU acceleration in FreeBSD. Please read
the instructions for use and activate this options in this document below.
2023-06-04 20:34:30 +00:00
### Metal Build
2023-09-04 19:26:24 +00:00
On MacOS, Metal is enabled by default. Using Metal makes the computation run on the GPU.
To disable the Metal build at compile time use the `LLAMA_NO_METAL=1` flag or the `LLAMA_METAL=OFF` cmake option.
2023-06-04 20:34:30 +00:00
2023-10-12 11:10:50 +00:00
When built with Metal support, you can explicitly disable GPU inference with the `--n-gpu-layers|-ngl 0` command-line
2023-09-04 19:26:24 +00:00
argument.
2023-06-04 20:34:30 +00:00
2023-07-10 15:49:56 +00:00
### MPI Build
MPI lets you distribute the computation over a cluster of machines. Because of the serial nature of LLM prediction, this won't yield any end-to-end speed-ups, but it will let you run larger models than would otherwise fit into RAM on a single machine.
First you will need MPI libraries installed on your system. The two most popular (only?) options are [MPICH ](https://www.mpich.org ) and [OpenMPI ](https://www.open-mpi.org ). Either can be installed with a package manager (`apt`, Homebrew, MacPorts, etc).
Next you will need to build the project with `LLAMA_MPI` set to true on all machines; if you're building with `make` , you will also need to specify an MPI-capable compiler (when building with CMake, this is configured automatically):
- Using `make` :
```bash
make CC=mpicc CXX=mpicxx LLAMA_MPI=1
```
- Using `CMake` :
```bash
cmake -S . -B build -DLLAMA_MPI=ON
```
Once the programs are built, download/convert the weights on all of the machines in your cluster. The paths to the weights and programs should be identical on all machines.
Next, ensure password-less SSH access to each machine from the primary host, and create a `hostfile` with a list of the hostnames and their relative "weights" (slots). If you want to use localhost for computation, use its local subnet IP address rather than the loopback address or "localhost".
Here is an example hostfile:
```
192.168.0.1:2
malvolio.local:1
```
The above will distribute the computation across 2 processes on the first host and 1 process on the second host. Each process will use roughly an equal amount of RAM. Try to keep these numbers small, as inter-process (intra-host) communication is expensive.
Finally, you're ready to run a computation using `mpirun` :
```bash
2023-08-21 20:07:43 +00:00
mpirun -hostfile hostfile -n 3 ./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
2023-07-10 15:49:56 +00:00
```
2023-04-26 20:03:03 +00:00
### BLAS Build
2023-11-30 21:49:21 +00:00
Building the program with BLAS support may lead to some performance improvements in prompt processing using batch sizes higher than 32 (the default is 512). Support with CPU-only BLAS implementations doesn't affect the normal generation performance. We may see generation performance improvements with GPU-involved BLAS implementations, e.g. cuBLAS, hipBLAS and CLBlast. There are currently several different BLAS implementations available for build and use:
2023-04-26 20:03:03 +00:00
2023-06-05 20:32:36 +00:00
- #### Accelerate Framework:
2023-04-26 20:03:03 +00:00
This is only available on Mac PCs and it's enabled by default. You can just build using the normal instructions.
2023-06-05 20:32:36 +00:00
- #### OpenBLAS:
2023-04-26 20:03:03 +00:00
This provides BLAS acceleration using only the CPU. Make sure to have OpenBLAS installed on your machine.
- Using `make` :
- On Linux:
```bash
make LLAMA_OPENBLAS=1
```
- On Windows:
1. Download the latest fortran version of [w64devkit ](https://github.com/skeeto/w64devkit/releases ).
2. Download the latest version of [OpenBLAS for Windows ](https://github.com/xianyi/OpenBLAS/releases ).
3. Extract `w64devkit` on your pc.
4. From the OpenBLAS zip that you just downloaded copy `libopenblas.a` , located inside the `lib` folder, inside `w64devkit\x86_64-w64-mingw32\lib` .
5. From the same OpenBLAS zip copy the content of the `include` folder inside `w64devkit\x86_64-w64-mingw32\include` .
6. Run `w64devkit.exe` .
7. Use the `cd` command to reach the `llama.cpp` folder.
8. From here you can run:
```bash
make LLAMA_OPENBLAS=1
```
- Using `CMake` on Linux:
```bash
mkdir build
cd build
2023-05-20 14:58:31 +00:00
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
2023-04-26 20:03:03 +00:00
cmake --build . --config Release
```
2023-06-05 20:32:36 +00:00
- #### BLIS
2023-05-20 14:58:31 +00:00
2023-06-10 14:08:11 +00:00
Check [BLIS.md ](docs/BLIS.md ) for more information.
2023-05-20 14:58:31 +00:00
2024-02-02 07:56:31 +00:00
- #### SYCL
SYCL is a higher-level programming model to improve programming productivity on various hardware accelerators.
llama.cpp based on SYCL is used to **support Intel GPU** (Data Center Max series, Flex series, Arc series, Built-in GPU and iGPU).
For detailed info, please refer to [llama.cpp for SYCL ](README-sycl.md ).
2023-12-30 08:07:48 +00:00
- #### Intel oneMKL
2024-02-02 07:56:31 +00:00
Building through oneAPI compilers will make avx_vnni instruction set available for intel processors that do not support avx512 and avx512_vnni. Please note that this build config **does not support Intel GPU** . For Intel GPU support, please refer to [llama.cpp for SYCL ](./README-sycl.md ).
2023-12-30 08:07:48 +00:00
- Using manual oneAPI installation:
By default, `LLAMA_BLAS_VENDOR` is set to `Generic` , so if you already sourced intel environment script and assign `-DLLAMA_BLAS=ON` in cmake, the mkl version of Blas will automatically been selected. Otherwise please install oneAPI and follow the below steps:
```bash
mkdir build
cd build
2024-02-02 07:56:31 +00:00
source /opt/intel/oneapi/setvars.sh # You can skip this step if in oneapi-basekit docker image, only required for manual installation
2023-12-30 08:07:48 +00:00
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_NATIVE=ON
cmake --build . --config Release
```
2023-05-20 14:58:31 +00:00
2023-12-30 08:07:48 +00:00
- Using oneAPI docker image:
2024-02-02 07:56:31 +00:00
If you do not want to source the environment vars and install oneAPI manually, you can also build the code using intel docker container: [oneAPI-basekit ](https://hub.docker.com/r/intel/oneapi-basekit ). Then, you can use the commands given above.
2023-12-30 08:07:48 +00:00
Check [Optimizing and Running LLaMA2 on Intel® CPU ](https://www.intel.com/content/www/us/en/content-details/791610/optimizing-and-running-llama2-on-intel-cpu.html ) for more information.
2023-05-20 14:58:31 +00:00
2023-06-05 20:32:36 +00:00
- #### cuBLAS
2023-04-26 20:03:03 +00:00
2023-10-06 19:13:36 +00:00
This provides BLAS acceleration using the CUDA cores of your Nvidia GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager (e.g. `apt install nvidia-cuda-toolkit` ) or from here: [CUDA Toolkit ](https://developer.nvidia.com/cuda-downloads ).
2023-12-22 15:11:12 +00:00
For Jetson user, if you have Jetson Orin, you can try this: [Offical Support ](https://www.jetson-ai-lab.com/tutorial_text-generation.html ). If you are using an old model(nano/TX2), need some additional operations before compiling.
2023-04-26 20:03:03 +00:00
- Using `make` :
```bash
make LLAMA_CUBLAS=1
```
- Using `CMake` :
```bash
mkdir build
cd build
cmake .. -DLLAMA_CUBLAS=ON
cmake --build . --config Release
```
2023-06-19 08:23:56 +00:00
The environment variable [`CUDA_VISIBLE_DEVICES` ](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars ) can be used to specify which GPU(s) will be used. The following compilation options are also available to tweak performance:
2023-07-31 13:44:35 +00:00
<!-- -
| LLAMA_CUDA_CUBLAS | Boolean | false | Use cuBLAS instead of custom CUDA kernels for prompt processing. Faster for all quantization formats except for q4_0 and q8_0, especially for k-quants. Increases VRAM usage (700 MiB for 7b, 970 MiB for 13b, 1430 MiB for 33b). |
--->
2023-09-17 14:37:53 +00:00
| Option | Legal values | Default | Description |
|--------------------------------|------------------------|---------|-------------|
| LLAMA_CUDA_FORCE_DMMV | Boolean | false | Force the use of dequantization + matrix vector multiplication kernels instead of using kernels that do matrix vector multiplication on quantized data. By default the decision is made based on compute capability (MMVQ for 6.1/Pascal/GTX 1000 or higher). Does not affect k-quants. |
| LLAMA_CUDA_DMMV_X | Positive integer >= 32 | 32 | Number of values in x direction processed by the CUDA dequantization + matrix vector multiplication kernel per iteration. Increasing this value can improve performance on fast GPUs. Power of 2 heavily recommended. Does not affect k-quants. |
| LLAMA_CUDA_MMV_Y | Positive integer | 1 | Block size in y direction for the CUDA mul mat vec kernels. Increasing this value can improve performance on fast GPUs. Power of 2 recommended. |
| LLAMA_CUDA_F16 | Boolean | false | If enabled, use half-precision floating point arithmetic for the CUDA dequantization + mul mat vec kernels and for the q4_1 and q5_1 matrix matrix multiplication kernels. Can improve performance on relatively recent GPUs. |
| LLAMA_CUDA_KQUANTS_ITER | 1 or 2 | 2 | Number of values processed per iteration and per CUDA thread for Q2_K and Q6_K quantization formats. Setting this value to 1 can improve performance for slow GPUs. |
| LLAMA_CUDA_PEER_MAX_BATCH_SIZE | Positive integer | 128 | Maximum batch size for which to enable peer access between multiple GPUs. Peer access requires either Linux or NVLink. When using NVLink enabling peer access for larger batch sizes is potentially beneficial. |
2023-06-03 13:35:20 +00:00
2023-08-25 09:09:42 +00:00
- #### hipBLAS
2023-09-08 16:04:32 +00:00
This provides BLAS acceleration on HIP-supported AMD GPUs.
2023-08-25 09:09:42 +00:00
Make sure to have ROCm installed.
You can download it from your Linux distro's package manager or from here: [ROCm Quick Start (Linux) ](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html ).
- Using `make` :
```bash
make LLAMA_HIPBLAS=1
```
2023-12-21 19:45:32 +00:00
- Using `CMake` for Linux (assuming a gfx1030-compatible AMD GPU):
2023-08-25 09:09:42 +00:00
```bash
2023-12-21 19:45:32 +00:00
CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++ \
cmake -H. -Bbuild -DLLAMA_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
& & cmake --build build -- -j 16
2023-08-25 09:09:42 +00:00
```
2023-12-21 19:45:32 +00:00
On Linux it is also possible to use unified memory architecture (UMA) to share main memory between the CPU and integrated GPU by setting `-DLLAMA_HIP_UMA=ON"` .
2023-12-22 08:03:25 +00:00
However, this hurts performance for non-integrated GPUs (but enables working with integrated GPUs).
- Using `make` (example for target gfx1030, build with 16 CPU threads):
```bash
make -j16 LLAMA_HIPBLAS=1 LLAMA_HIP_UMA=1 AMDGPU_TARGETS=gxf1030
```
2023-12-21 19:45:32 +00:00
- Using `CMake` for Windows (using x64 Native Tools Command Prompt for VS, and assuming a gfx1100-compatible AMD GPU):
2023-11-20 15:02:46 +00:00
```bash
2023-11-24 07:52:39 +00:00
set PATH=%HIP_PATH%\bin;%PATH%
2023-11-20 15:02:46 +00:00
mkdir build
cd build
cmake -G Ninja -DAMDGPU_TARGETS=gfx1100 -DLLAMA_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
cmake --build .
```
Make sure that `AMDGPU_TARGETS` is set to the GPU arch you want to compile for. The above example uses `gfx1100` that corresponds to Radeon RX 7900XTX/XT/GRE. You can find a list of targets [here ](https://llvm.org/docs/AMDGPUUsage.html#processors )
2023-12-21 19:45:32 +00:00
Find your gpu version string by matching the most significant version information from `rocminfo | grep gfx | head -1 | awk '{print $2}'` with the list of processors, e.g. `gfx1035` maps to `gfx1030` .
2023-11-20 15:02:46 +00:00
2023-08-25 09:09:42 +00:00
The environment variable [`HIP_VISIBLE_DEVICES` ](https://rocm.docs.amd.com/en/latest/understand/gpu_isolation.html#hip-visible-devices ) can be used to specify which GPU(s) will be used.
2023-12-21 19:45:32 +00:00
If your GPU is not officially supported you can use the environment variable [`HSA_OVERRIDE_GFX_VERSION`] set to a similar GPU, for example 10.3.0 on RDNA2 (e.g. gfx1030, gfx1031, or gfx1035) or 11.0.0 on RDNA3.
2023-08-25 09:09:42 +00:00
The following compilation options are also available to tweak performance (yes, they refer to CUDA, not HIP, because it uses the same code as the cuBLAS version above):
| Option | Legal values | Default | Description |
|-------------------------|------------------------|---------|-------------|
| LLAMA_CUDA_DMMV_X | Positive integer >= 32 | 32 | Number of values in x direction processed by the HIP dequantization + matrix vector multiplication kernel per iteration. Increasing this value can improve performance on fast GPUs. Power of 2 heavily recommended. Does not affect k-quants. |
| LLAMA_CUDA_MMV_Y | Positive integer | 1 | Block size in y direction for the HIP mul mat vec kernels. Increasing this value can improve performance on fast GPUs. Power of 2 recommended. Does not affect k-quants. |
| LLAMA_CUDA_KQUANTS_ITER | 1 or 2 | 2 | Number of values processed per iteration and per HIP thread for Q2_K and Q6_K quantization formats. Setting this value to 1 can improve performance for slow GPUs. |
2023-06-05 20:32:36 +00:00
- #### CLBlast
2023-05-27 15:47:55 +00:00
OpenCL acceleration is provided by the matrix multiplication kernels from the [CLBlast ](https://github.com/CNugteren/CLBlast ) project and custom kernels for ggml that can generate tokens on the GPU.
You will need the [OpenCL SDK ](https://github.com/KhronosGroup/OpenCL-SDK ).
- For Ubuntu or Debian, the packages `opencl-headers` , `ocl-icd` may be needed.
2023-09-02 12:53:18 +00:00
- For Windows, a pre-built SDK is available on the [OpenCL Releases ](https://github.com/KhronosGroup/OpenCL-SDK/releases ) page.
2023-05-27 15:47:55 +00:00
- < details >
< summary > Installing the OpenCL SDK from source< / summary >
```sh
git clone --recurse-submodules https://github.com/KhronosGroup/OpenCL-SDK.git
mkdir OpenCL-SDK/build
cd OpenCL-SDK/build
cmake .. -DBUILD_DOCS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DOPENCL_SDK_BUILD_SAMPLES=OFF \
-DOPENCL_SDK_TEST_SAMPLES=OFF
cmake --build . --config Release
cmake --install . --prefix /some/path
```
< / details >
2023-09-02 12:53:18 +00:00
##### Installing CLBlast
Pre-built CLBlast binaries may be found on the [CLBlast Releases ](https://github.com/CNugteren/CLBlast/releases ) page. For Unix variants, it may also be found in your operating system's packages.
Alternatively, they may be built from source.
2023-05-27 15:47:55 +00:00
- < details >
2023-09-02 12:53:18 +00:00
< summary > Windows:< / summary >
```cmd
set OPENCL_SDK_ROOT="C:/OpenCL-SDK-v2023.04.17-Win-x64"
git clone https://github.com/CNugteren/CLBlast.git
mkdir CLBlast\build
cd CLBlast\build
cmake .. -DBUILD_SHARED_LIBS=OFF -DOVERRIDE_MSVC_FLAGS_TO_MT=OFF -DTUNERS=OFF -DOPENCL_ROOT=%OPENCL_SDK_ROOT% -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
cmake --install . --prefix C:/CLBlast
```
- < details >
< summary > Unix:< / summary >
2023-05-27 15:47:55 +00:00
```sh
git clone https://github.com/CNugteren/CLBlast.git
mkdir CLBlast/build
2023-06-20 12:42:40 +00:00
cd CLBlast/build
2023-05-27 15:47:55 +00:00
cmake .. -DBUILD_SHARED_LIBS=OFF -DTUNERS=OFF
cmake --build . --config Release
cmake --install . --prefix /some/path
```
2023-06-03 13:35:20 +00:00
Where `/some/path` is where the built library will be installed (default is `/usr/local` ).
2023-05-27 15:47:55 +00:00
< / details >
2023-09-02 12:53:18 +00:00
##### Building Llama with CLBlast
2023-05-27 15:47:55 +00:00
- Build with make:
```sh
make LLAMA_CLBLAST=1
```
2023-09-02 12:53:18 +00:00
- CMake (Unix):
2023-05-27 15:47:55 +00:00
```sh
mkdir build
cd build
2023-09-25 18:24:52 +00:00
cmake .. -DLLAMA_CLBLAST=ON -DCLBlast_DIR=/some/path
2023-05-27 15:47:55 +00:00
cmake --build . --config Release
```
2023-09-02 12:53:18 +00:00
- CMake (Windows):
```cmd
set CL_BLAST_CMAKE_PKG="C:/CLBlast/lib/cmake/CLBlast"
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
mkdir build
cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DLLAMA_CLBLAST=ON -DCMAKE_PREFIX_PATH=%CL_BLAST_CMAKE_PKG% -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
cmake --install . --prefix C:/LlamaCPP
```
2023-05-27 15:47:55 +00:00
2023-09-02 12:53:18 +00:00
##### Running Llama with CLBlast
2023-05-27 15:47:55 +00:00
2023-06-04 20:34:30 +00:00
The CLBlast build supports `--gpu-layers|-ngl` like the CUDA version does.
2023-05-27 15:47:55 +00:00
To select the correct platform (driver) and device (GPU), you can use the environment variables `GGML_OPENCL_PLATFORM` and `GGML_OPENCL_DEVICE` .
The selection can be a number (starting from 0) or a text string to search:
```sh
GGML_OPENCL_PLATFORM=1 ./main ...
GGML_OPENCL_DEVICE=2 ./main ...
GGML_OPENCL_PLATFORM=Intel ./main ...
GGML_OPENCL_PLATFORM=AMD GGML_OPENCL_DEVICE=1 ./main ...
```
The default behavior is to find the first GPU device, but when it is an integrated GPU on a laptop, for instance, the selectors are useful.
Using the variables it is possible to select a CPU-based driver as well, if so desired.
You can get a list of platforms and devices from the `clinfo -l` command, etc.
2023-05-08 00:42:01 +00:00
2024-02-02 07:56:31 +00:00
- #### Vulkan
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
2024-02-02 07:56:31 +00:00
**With docker** :
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
2024-02-02 07:56:31 +00:00
You don't need to install Vulkan SDK. It will be installed inside the container.
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
2024-02-02 07:56:31 +00:00
```sh
# Build the image
docker build -t llama-cpp-vulkan -f .devops/main-vulkan.Dockerfile .
# Then, use it:
docker run -it --rm -v "$(pwd):/app:Z" --device /dev/dri/renderD128:/dev/dri/renderD128 --device /dev/dri/card1:/dev/dri/card1 llama-cpp-vulkan -m "/app/models/YOUR_MODEL_FILE" -p "Building a website can be done in 10 simple steps:" -n 400 -e -ngl 33
```
**Without docker** :
Firstly, you need to make sure you installed [Vulkan SDK ](https://vulkan.lunarg.com/doc/view/latest/linux/getting_started_ubuntu.html )
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
2024-02-02 07:56:31 +00:00
For example, on Ubuntu 22.04 (jammy), use the command below:
```bash
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key add -
wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
apt update -y
apt-get install -y vulkan-sdk
# To verify the installation, use the command below:
vulkaninfo
```
Then, build llama.cpp using the cmake command below:
```bash
mkdir -p build
cd build
cmake .. -DLLAMA_VULKAN=1
cmake --build . --config Release
# Test the output binary (with "-ngl 33" to offload all layers to GPU)
./bin/main -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4
# You should see in the output, ggml_vulkan detected your GPU. For example:
# ggml_vulkan: Using Intel(R) Graphics (ADL GT2) | uma: 1 | fp16: 1 | warp size: 32
```
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
2023-04-13 13:43:22 +00:00
### Prepare Data & Run
```bash
2023-03-10 19:47:46 +00:00
# obtain the original LLaMA model weights and place them in ./models
ls ./models
65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model
2024-01-30 09:16:38 +00:00
# [Optional] for models using BPE tokenizers
ls ./models
65B 30B 13B 7B vocab.json
2023-03-10 19:47:46 +00:00
2023-03-11 05:47:26 +00:00
# install Python dependencies
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.
2023-04-14 07:03:03 +00:00
python3 -m pip install -r requirements.txt
2023-03-11 05:47:26 +00:00
2023-03-10 19:47:46 +00:00
# convert the 7B model to ggml FP16 format
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.
2023-04-14 07:03:03 +00:00
python3 convert.py models/7B/
2023-03-10 19:47:46 +00:00
2024-01-30 09:16:38 +00:00
# [Optional] for models using BPE tokenizers
python convert.py models/7B/ --vocabtype bpe
2023-08-02 08:21:11 +00:00
2023-04-26 16:43:27 +00:00
# quantize the model to 4-bits (using q4_0 method)
2023-08-21 20:07:43 +00:00
./quantize ./models/7B/ggml-model-f16.gguf ./models/7B/ggml-model-q4_0.gguf q4_0
2023-03-10 19:47:46 +00:00
2023-09-21 19:00:24 +00:00
# update the gguf filetype to current if older version is unsupported by another application
./quantize ./models/7B/ggml-model-q4_0.gguf ./models/7B/ggml-model-q4_0-v2.gguf COPY
2023-03-10 19:47:46 +00:00
# run the inference
2023-08-21 20:07:43 +00:00
./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
2023-03-10 19:47:46 +00:00
```
2023-03-11 08:47:09 +00:00
When running the larger models, make sure you have enough disk space to store all the intermediate files.
2023-10-17 18:13:21 +00:00
### Running on Windows with prebuilt binaries
You will find prebuilt Windows binaries on the release page.
Simply download and extract the latest zip package of choice: (e.g. `llama-b1380-bin-win-avx2-x64.zip` )
From the unzipped folder, open a terminal/cmd window here and place a pre-converted `.gguf` model file. Test out the main example like so:
```
.\main -m llama-2-7b.Q4_0.gguf -n 128
```
2023-03-18 20:58:46 +00:00
### Memory/Disk Requirements
2023-04-19 19:52:14 +00:00
As the models are currently fully loaded into memory, you will need adequate disk space to save them and sufficient RAM to load them. At the moment, memory and disk requirements are the same.
2023-03-18 20:58:46 +00:00
2023-04-28 23:10:43 +00:00
| Model | Original size | Quantized size (4-bit) |
|------:|--------------:|-----------------------:|
| 7B | 13 GB | 3.9 GB |
| 13B | 24 GB | 7.8 GB |
| 30B | 60 GB | 19.5 GB |
| 65B | 120 GB | 38.5 GB |
2023-03-13 16:15:20 +00:00
2023-04-26 20:24:42 +00:00
### Quantization
Several quantization methods are supported. They differ in the resulting model disk size and inference speed.
2023-08-23 20:41:16 +00:00
*(outdated)*
2023-05-11 21:23:08 +00:00
| Model | Measure | F16 | Q4_0 | Q4_1 | Q5_0 | Q5_1 | Q8_0 |
|------:|--------------|-------:|-------:|-------:|-------:|-------:|-------:|
2023-05-19 19:17:18 +00:00
| 7B | perplexity | 5.9066 | 6.1565 | 6.0912 | 5.9862 | 5.9481 | 5.9070 |
| 7B | file size | 13.0G | 3.5G | 3.9G | 4.3G | 4.7G | 6.7G |
| 7B | ms/tok @ 4th | 127 | 55 | 54 | 76 | 83 | 72 |
| 7B | ms/tok @ 8th | 122 | 43 | 45 | 52 | 56 | 67 |
| 7B | bits/weight | 16.0 | 4.5 | 5.0 | 5.5 | 6.0 | 8.5 |
| 13B | perplexity | 5.2543 | 5.3860 | 5.3608 | 5.2856 | 5.2706 | 5.2548 |
| 13B | file size | 25.0G | 6.8G | 7.6G | 8.3G | 9.1G | 13G |
| 13B | ms/tok @ 4th | - | 103 | 105 | 148 | 160 | 131 |
| 13B | ms/tok @ 8th | - | 73 | 82 | 98 | 105 | 128 |
| 13B | bits/weight | 16.0 | 4.5 | 5.0 | 5.5 | 6.0 | 8.5 |
2023-04-26 20:24:42 +00:00
2023-09-27 15:30:36 +00:00
- [k-quants ](https://github.com/ggerganov/llama.cpp/pull/1684 )
- recent k-quants improvements
- [#2707 ](https://github.com/ggerganov/llama.cpp/pull/2707 )
- [#2807 ](https://github.com/ggerganov/llama.cpp/pull/2807 )
2023-05-08 14:41:54 +00:00
### Perplexity (measuring model quality)
You can use the `perplexity` example to measure perplexity over a given prompt (lower perplexity is better).
For more information, see [https://huggingface.co/docs/transformers/perplexity ](https://huggingface.co/docs/transformers/perplexity ).
The perplexity measurements in table above are done against the `wikitext2` test dataset (https://paperswithcode.com/dataset/wikitext-2), with context length of 512.
The time per token is measured on a MacBook M1 Pro 32GB RAM using 4 and 8 threads.
2023-10-06 19:13:36 +00:00
#### How to run
1. Download/extract: https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip?ref=salesforce-research
2. Run `./perplexity -m models/7B/ggml-model-q4_0.gguf -f wiki.test.raw`
3. Output:
```
perplexity : calculating perplexity over 655 chunks
24.43 seconds per pass - ETA 4.45 hours
[1]4.5970,[2]5.1807,[3]6.0382,...
```
And after 4.45 hours, you will have the final perplexity.
2023-03-12 21:13:28 +00:00
### Interactive mode
If you want a more ChatGPT-like experience, you can run in interactive mode by passing `-i` as a parameter.
2023-04-19 19:52:14 +00:00
In this mode, you can always interrupt generation by pressing Ctrl+C and entering one or more lines of text, which will be converted into tokens and appended to the current context. You can also specify a *reverse prompt* with the parameter `-r "reverse prompt string"` . This will result in user input being prompted whenever the exact tokens of the reverse prompt string are encountered in the generation. A typical use is to use a prompt that makes LLaMa emulate a chat between multiple users, say Alice and Bob, and pass `-r "Alice:"` .
2023-03-12 21:13:28 +00:00
2023-04-19 19:52:14 +00:00
Here is an example of a few-shot interaction, invoked with the command
2023-03-21 16:10:32 +00:00
```bash
2023-04-19 19:52:14 +00:00
# default arguments using a 7B model
2023-03-25 18:36:52 +00:00
./examples/chat.sh
2023-04-19 19:52:14 +00:00
# advanced chat with a 13B model
2023-03-25 18:36:52 +00:00
./examples/chat-13B.sh
2023-03-12 21:39:01 +00:00
2023-04-19 19:52:14 +00:00
# custom arguments using a 13B model
2023-08-21 20:07:43 +00:00
./main -m ./models/13B/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt
2023-03-12 21:13:28 +00:00
```
2023-03-21 16:10:32 +00:00
2023-04-24 15:45:32 +00:00
Note the use of `--color` to distinguish between user input and generated text. Other parameters are explained in more detail in the [README ](examples/main/README.md ) for the `main` example program.
2023-03-12 21:13:28 +00:00
2023-03-12 21:39:01 +00:00
![image ](https://user-images.githubusercontent.com/1991296/224575029-2af3c7dc-5a65-4f64-a6bb-517a532aea38.png )
2023-03-12 21:13:28 +00:00
2023-05-24 06:24:01 +00:00
### Persistent Interaction
The prompt, user inputs, and model generations can be saved and resumed across calls to `./main` by leveraging `--prompt-cache` and `--prompt-cache-all` . The `./examples/chat-persistent.sh` script demonstrates this with support for long-running, resumable chat sessions. To use this example, you must provide a file to cache the initial chat prompt and a directory to save the chat session, and may optionally provide the same variables as `chat-13B.sh` . The same prompt cache can be reused for new chat sessions. Note that both prompt cache and chat directory are tied to the initial prompt (`PROMPT_TEMPLATE`) and the model file.
```bash
# Start a new chat
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/default ./examples/chat-persistent.sh
# Resume that chat
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/default ./examples/chat-persistent.sh
# Start a different chat with the same prompt/model
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/another ./examples/chat-persistent.sh
# Different prompt cache for different prompt/model
PROMPT_TEMPLATE=./prompts/chat-with-bob.txt PROMPT_CACHE_FILE=bob.prompt.bin \
CHAT_SAVE_DIR=./chat/bob ./examples/chat-persistent.sh
```
2023-08-23 01:01:57 +00:00
### Constrained output with grammars
`llama.cpp` supports grammars to constrain model output. For example, you can force the model to output JSON only:
```bash
./main -m ./models/13B/ggml-model-q4_0.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:'
```
The `grammars/` folder contains a handful of sample grammars. To write your own, check out the [GBNF Guide ](./grammars/README.md ).
2023-09-29 11:15:57 +00:00
For authoring more complex JSON grammars, you can also check out https://grammar.intrinsiclabs.ai/, a browser app that lets you write TypeScript interfaces which it compiles to GBNF grammars that you can save for local use. Note that the app is built and maintained by members of the community, please file any issues or FRs on [its repo ](http://github.com/intrinsiclabsai/gbnfgen ) and not this one.
2023-03-19 16:49:50 +00:00
### Instruction mode with Alpaca
2023-03-23 11:30:40 +00:00
1. First, download the `ggml` Alpaca model into the `./models` folder
2. Run the `main` tool like this:
2023-03-19 16:49:50 +00:00
```
2023-03-25 18:36:52 +00:00
./examples/alpaca.sh
2023-03-19 16:49:50 +00:00
```
Sample run:
```
== Running in interactive mode. ==
- Press Ctrl+C to interject at any time.
- Press Return to return control to LLaMa.
- If you want to submit another line, end your input in '\'.
Below is an instruction that describes a task. Write a response that appropriately completes the request.
> How many letters are there in the English alphabet?
There 26 letters in the English Alphabet
> What is the most common way of transportation in Amsterdam?
The majority (54%) are using public transit. This includes buses, trams and metros with over 100 lines throughout the city which make it very accessible for tourists to navigate around town as well as locals who commute by tram or metro on a daily basis
2023-03-21 15:59:16 +00:00
> List 5 words that start with "ca".
2023-03-19 16:49:50 +00:00
cadaver, cauliflower, cabbage (vegetable), catalpa (tree) and Cailleach.
2023-04-11 19:45:44 +00:00
>
2023-03-19 16:49:50 +00:00
```
2023-06-23 08:38:01 +00:00
### Using [OpenLLaMA](https://github.com/openlm-research/open_llama)
OpenLLaMA is an openly licensed reproduction of Meta's original LLaMA model. It uses the same architecture and is a drop-in replacement for the original LLaMA weights.
- Download the [3B ](https://huggingface.co/openlm-research/open_llama_3b ), [7B ](https://huggingface.co/openlm-research/open_llama_7b ), or [13B ](https://huggingface.co/openlm-research/open_llama_13b ) model from Hugging Face.
- Convert the model to ggml FP16 format using `python convert.py <path to OpenLLaMA directory>`
2023-03-29 16:37:20 +00:00
### Using [GPT4All](https://github.com/nomic-ai/gpt4all)
2023-08-21 20:07:43 +00:00
*Note: these instructions are likely obsoleted by the GGUF update*
2023-04-23 08:21:26 +00:00
- Obtain the `tokenizer.model` file from LLaMA model and put it to `models`
- Obtain the `added_tokens.json` file from Alpaca model and put it to `models`
- Obtain the `gpt4all-lora-quantized.bin` file from GPT4All model and put it to `models/gpt4all-7B`
- It is distributed in the old `ggml` format which is now obsoleted
- You have to convert it to the new format using `convert.py` :
```bash
python3 convert.py models/gpt4all-7B/gpt4all-lora-quantized.bin
```
- You can now use the newly generated `models/gpt4all-7B/ggml-model-q4_0.bin` model in exactly the same way as all other models
- The newer GPT4All-J model is not yet supported!
2023-03-29 16:37:20 +00:00
2023-05-08 16:33:30 +00:00
### Using Pygmalion 7B & Metharme 7B
- Obtain the [LLaMA weights ](#obtaining-the-facebook-llama-original-model-and-stanford-alpaca-model-data )
- Obtain the [Pygmalion 7B ](https://huggingface.co/PygmalionAI/pygmalion-7b/ ) or [Metharme 7B ](https://huggingface.co/PygmalionAI/metharme-7b ) XOR encoded weights
- Convert the LLaMA model with [the latest HF convert script ](https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py )
- Merge the XOR files with the converted LLaMA weights by running the [xor_codec ](https://huggingface.co/PygmalionAI/pygmalion-7b/blob/main/xor_codec.py ) script
- Convert to `ggml` format using the `convert.py` script in this repo:
```bash
python3 convert.py pygmalion-7b/ --outtype q4_1
```
> The Pygmalion 7B & Metharme 7B weights are saved in [bfloat16](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format) precision. If you wish to convert to `ggml` without quantizating, please specify the `--outtype` as `f32` instead of `f16`.
2023-05-03 15:31:28 +00:00
### Obtaining the Facebook LLaMA original model and Stanford Alpaca model data
2023-03-20 20:14:06 +00:00
2023-04-19 19:52:14 +00:00
- **Under no circumstances should IPFS, magnet links, or any other links to model downloads be shared anywhere in this repository, including in issues, discussions, or pull requests. They will be immediately deleted.**
2023-04-11 19:45:44 +00:00
- The LLaMA models are officially distributed by Facebook and will **never** be provided through this repository.
2023-03-24 15:23:09 +00:00
- Refer to [Facebook's LLaMA repository ](https://github.com/facebookresearch/llama/pull/73/files ) if you need to request access to the model data.
2023-03-20 20:14:06 +00:00
2023-07-28 01:14:11 +00:00
### Obtaining and using the Facebook LLaMA 2 model
- Refer to [Facebook's LLaMA download page ](https://ai.meta.com/resources/models-and-libraries/llama-downloads/ ) if you want to access the model data.
- Alternatively, if you want to save time and space, you can download already converted and quantized models from [TheBloke ](https://huggingface.co/TheBloke ), including:
2023-09-08 10:32:55 +00:00
- [LLaMA 2 7B base ](https://huggingface.co/TheBloke/Llama-2-7B-GGUF )
- [LLaMA 2 13B base ](https://huggingface.co/TheBloke/Llama-2-13B-GGUF )
- [LLaMA 2 70B base ](https://huggingface.co/TheBloke/Llama-2-70B-GGUF )
- [LLaMA 2 7B chat ](https://huggingface.co/TheBloke/Llama-2-7B-chat-GGUF )
- [LLaMA 2 13B chat ](https://huggingface.co/TheBloke/Llama-2-13B-chat-GGUF )
- [LLaMA 2 70B chat ](https://huggingface.co/TheBloke/Llama-2-70B-chat-GGUF )
2023-07-28 01:14:11 +00:00
2023-05-03 15:31:28 +00:00
### Verifying the model files
2023-03-20 20:14:06 +00:00
2023-05-03 15:31:28 +00:00
Please verify the [sha256 checksums ](SHA256SUMS ) of all downloaded model files to confirm that you have the correct model data files before creating an issue relating to your model files.
- The following python script will verify if you have all possible latest files in your self-installed `./models` subdirectory:
2023-03-20 20:14:06 +00:00
2023-05-03 15:31:28 +00:00
```bash
# run the verification script
2023-07-16 19:54:47 +00:00
./scripts/verify-checksum-models.py
2023-05-03 15:31:28 +00:00
```
- On linux or macOS it is also possible to run the following commands to verify if you have all possible latest files in your self-installed `./models` subdirectory:
2023-05-03 17:09:42 +00:00
- On Linux: `sha256sum --ignore-missing -c SHA256SUMS`
2023-05-03 15:31:28 +00:00
- on macOS: `shasum -a 256 --ignore-missing -c SHA256SUMS`
### Seminal papers and background on the models
2023-03-20 20:14:06 +00:00
2023-05-03 15:31:28 +00:00
If your issue is with model generation quality, then please at least scan the following links and papers to understand the limitations of LLaMA models. This is especially important when choosing an appropriate model size and appreciating both the significant and subtle differences between LLaMA models and ChatGPT:
2023-04-19 19:52:14 +00:00
- LLaMA:
2023-05-03 15:31:28 +00:00
- [Introducing LLaMA: A foundational, 65-billion-parameter large language model ](https://ai.facebook.com/blog/large-language-model-llama-meta-ai/ )
- [LLaMA: Open and Efficient Foundation Language Models ](https://arxiv.org/abs/2302.13971 )
2023-04-19 19:52:14 +00:00
- GPT-3
2023-05-03 15:31:28 +00:00
- [Language Models are Few-Shot Learners ](https://arxiv.org/abs/2005.14165 )
2023-04-19 19:52:14 +00:00
- GPT-3.5 / InstructGPT / ChatGPT:
2023-05-03 15:31:28 +00:00
- [Aligning language models to follow instructions ](https://openai.com/research/instruction-following )
- [Training language models to follow instructions with human feedback ](https://arxiv.org/abs/2203.02155 )
2023-04-11 19:45:44 +00:00
2023-03-14 13:30:08 +00:00
### Android
2023-06-17 09:01:06 +00:00
#### Building the Project using Android NDK
2023-04-01 14:57:30 +00:00
You can easily run `llama.cpp` on Android device with [termux ](https://termux.dev/ ).
2023-06-18 08:28:26 +00:00
First, install the essential packages for termux:
```
pkg install clang wget git cmake
```
Second, obtain the [Android NDK ](https://developer.android.com/ndk ) and then build with CMake:
2023-03-14 13:30:08 +00:00
```
$ mkdir build-android
$ cd build-android
$ export NDK=< your_ndk_directory >
$ cmake -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -DCMAKE_C_FLAGS=-march=armv8.4a+dotprod ..
$ make
```
2023-04-01 14:57:30 +00:00
Install [termux ](https://termux.dev/ ) on your device and run `termux-setup-storage` to get access to your SD card.
2023-03-14 13:30:08 +00:00
Finally, copy the `llama` binary and the model files to your device storage. Here is a demo of an interactive session running on Pixel 5 phone:
https://user-images.githubusercontent.com/271616/225014776-1d567049-ad71-4ef2-b050-55b0b3b9274c.mp4
2023-06-17 09:01:06 +00:00
#### Building the Project using Termux (F-Droid)
Termux from F-Droid offers an alternative route to execute the project on an Android device. This method empowers you to construct the project right from within the terminal, negating the requirement for a rooted device or SD Card.
Outlined below are the directives for installing the project using OpenBLAS and CLBlast. This combination is specifically designed to deliver peak performance on recent devices that feature a GPU.
If you opt to utilize OpenBLAS, you'll need to install the corresponding package.
```
apt install libopenblas
```
Subsequently, if you decide to incorporate CLBlast, you'll first need to install the requisite OpenCL packages:
```
apt install ocl-icd opencl-headers opencl-clhpp clinfo
```
In order to compile CLBlast, you'll need to first clone the respective Git repository, which can be found at this URL: https://github.com/CNugteren/CLBlast. Alongside this, clone this repository into your home directory. Once this is done, navigate to the CLBlast folder and execute the commands detailed below:
```
cmake .
make
cp libclblast.so* $PREFIX/lib
cp ./include/clblast.h ../llama.cpp
```
Following the previous steps, navigate to the LlamaCpp directory. To compile it with OpenBLAS and CLBlast, execute the command provided below:
```
cp /data/data/com.termux/files/usr/include/openblas/cblas.h .
cp /data/data/com.termux/files/usr/include/openblas/openblas_config.h .
make LLAMA_CLBLAST=1 //(sometimes you need to run this command twice)
```
Upon completion of the aforementioned steps, you will have successfully compiled the project. To run it using CLBlast, a slight adjustment is required: a command must be issued to direct the operations towards your device's physical GPU, rather than the virtual one. The necessary command is detailed below:
```
GGML_OPENCL_PLATFORM=0
GGML_OPENCL_DEVICE=0
2023-06-24 10:32:13 +00:00
export LD_LIBRARY_PATH=/vendor/lib64:$LD_LIBRARY_PATH
2023-06-17 09:01:06 +00:00
```
2023-06-26 19:34:45 +00:00
(Note: some Android devices, like the Zenfone 8, need the following command instead - "export LD_LIBRARY_PATH=/system/vendor/lib64:$LD_LIBRARY_PATH". Source: https://www.reddit.com/r/termux/comments/kc3ynp/opencl_working_in_termux_more_in_comments/ )
2023-06-17 09:01:06 +00:00
For easy and swift re-execution, consider documenting this final part in a .sh script file. This will enable you to rerun the process with minimal hassle.
2023-07-09 08:20:43 +00:00
Place your desired model into the `~/llama.cpp/models/` directory and execute the `./main (...)` script.
2023-06-24 10:32:13 +00:00
2023-03-17 09:47:06 +00:00
### Docker
#### Prerequisites
* Docker must be installed and running on your system.
2023-04-19 19:52:14 +00:00
* Create a folder to store big models & intermediate files (ex. /llama/models)
2023-03-17 09:47:06 +00:00
#### Images
2024-01-28 07:55:31 +00:00
We have three Docker images available for this project:
2023-03-17 09:47:06 +00:00
2023-09-14 16:47:00 +00:00
1. `ghcr.io/ggerganov/llama.cpp:full` : This image includes both the main executable file and the tools to convert LLaMA models into ggml and convert into 4-bit quantization. (platforms: `linux/amd64` , `linux/arm64` )
2. `ghcr.io/ggerganov/llama.cpp:light` : This image only includes the main executable file. (platforms: `linux/amd64` , `linux/arm64` )
2024-01-28 07:55:31 +00:00
3. `ghcr.io/ggerganov/llama.cpp:server` : This image only includes the server executabhle file. (platforms: `linux/amd64` , `linux/arm64` )
2023-09-14 16:47:00 +00:00
Additionally, there the following images, similar to the above:
- `ghcr.io/ggerganov/llama.cpp:full-cuda` : Same as `full` but compiled with CUDA support. (platforms: `linux/amd64` )
- `ghcr.io/ggerganov/llama.cpp:light-cuda` : Same as `light` but compiled with CUDA support. (platforms: `linux/amd64` )
2024-01-28 07:55:31 +00:00
- `ghcr.io/ggerganov/llama.cpp:server-cuda` : Same as `server` but compiled with CUDA support. (platforms: `linux/amd64` )
2023-09-14 16:47:00 +00:00
- `ghcr.io/ggerganov/llama.cpp:full-rocm` : Same as `full` but compiled with ROCm support. (platforms: `linux/amd64` , `linux/arm64` )
- `ghcr.io/ggerganov/llama.cpp:light-rocm` : Same as `light` but compiled with ROCm support. (platforms: `linux/amd64` , `linux/arm64` )
2024-01-28 07:55:31 +00:00
- `ghcr.io/ggerganov/llama.cpp:server-rocm` : Same as `server` but compiled with ROCm support. (platforms: `linux/amd64` , `linux/arm64` )
2023-09-14 16:47:00 +00:00
2023-11-30 21:43:32 +00:00
The GPU enabled images are not currently tested by CI beyond being built. They are not built with any variation from the ones in the Dockerfiles defined in [.devops/ ](.devops/ ) and the GitHub Action defined in [.github/workflows/docker.yml ](.github/workflows/docker.yml ). If you need different settings (for example, a different CUDA or ROCm library, you'll need to build the images locally for now).
2023-03-17 09:47:06 +00:00
#### Usage
The easiest way to download the models, convert them to ggml and optimize them is with the --all-in-one command which includes the full docker image.
2023-04-06 06:56:58 +00:00
Replace `/path/to/models` below with the actual path where you downloaded the models.
2023-04-19 19:52:14 +00:00
```bash
2023-04-06 06:56:58 +00:00
docker run -v /path/to/models:/models ghcr.io/ggerganov/llama.cpp:full --all-in-one "/models/" 7B
2023-03-17 09:47:06 +00:00
```
2023-04-19 19:52:14 +00:00
On completion, you are ready to play!
2023-03-17 09:47:06 +00:00
```bash
2023-08-21 20:07:43 +00:00
docker run -v /path/to/models:/models ghcr.io/ggerganov/llama.cpp:full --run -m /models/7B/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 512
2023-03-17 09:47:06 +00:00
```
2023-04-19 19:52:14 +00:00
or with a light image:
2023-03-17 09:47:06 +00:00
```bash
2023-08-21 20:07:43 +00:00
docker run -v /path/to/models:/models ghcr.io/ggerganov/llama.cpp:light -m /models/7B/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 512
2023-03-17 09:47:06 +00:00
```
2023-03-14 13:30:08 +00:00
2024-01-28 07:55:31 +00:00
or with a server image:
```bash
docker run -v /path/to/models:/models -p 8000:8000 ghcr.io/ggerganov/llama.cpp:server -m /models/7B/ggml-model-q4_0.gguf --port 8000 --host 0.0.0.0 -n 512
```
2023-07-07 18:25:25 +00:00
### Docker With CUDA
Assuming one has the [nvidia-container-toolkit ](https://github.com/NVIDIA/nvidia-container-toolkit ) properly installed on Linux, or is using a GPU enabled cloud, `cuBLAS` should be accessible inside the container.
#### Building Locally
```bash
docker build -t local/llama.cpp:full-cuda -f .devops/full-cuda.Dockerfile .
docker build -t local/llama.cpp:light-cuda -f .devops/main-cuda.Dockerfile .
2024-01-28 07:55:31 +00:00
docker build -t local/llama.cpp:server-cuda -f .devops/server-cuda.Dockerfile .
2023-07-07 18:25:25 +00:00
```
You may want to pass in some different `ARGS` , depending on the CUDA environment supported by your container host, as well as the GPU architecture.
The defaults are:
- `CUDA_VERSION` set to `11.7.1`
- `CUDA_DOCKER_ARCH` set to `all`
The resulting images, are essentially the same as the non-CUDA images:
1. `local/llama.cpp:full-cuda` : This image includes both the main executable file and the tools to convert LLaMA models into ggml and convert into 4-bit quantization.
2. `local/llama.cpp:light-cuda` : This image only includes the main executable file.
2024-01-28 07:55:31 +00:00
3. `local/llama.cpp:server-cuda` : This image only includes the server executable file.
2023-07-07 18:25:25 +00:00
#### Usage
After building locally, Usage is similar to the non-CUDA examples, but you'll need to add the `--gpus` flag. You will also want to use the `--n-gpu-layers` flag.
```bash
2023-08-21 20:07:43 +00:00
docker run --gpus all -v /path/to/models:/models local/llama.cpp:full-cuda --run -m /models/7B/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 512 --n-gpu-layers 1
docker run --gpus all -v /path/to/models:/models local/llama.cpp:light-cuda -m /models/7B/ggml-model-q4_0.gguf -p "Building a website can be done in 10 simple steps:" -n 512 --n-gpu-layers 1
2024-01-28 07:55:31 +00:00
docker run --gpus all -v /path/to/models:/models local/llama.cpp:server-cuda -m /models/7B/ggml-model-q4_0.gguf --port 8000 --host 0.0.0.0 -n 512 --n-gpu-layers 1
2023-07-07 18:25:25 +00:00
```
2023-03-13 07:42:26 +00:00
### Contributing
2023-03-13 17:21:51 +00:00
- Contributors can open PRs
2023-03-16 06:55:13 +00:00
- Collaborators can push to branches in the `llama.cpp` repo and merge PRs into the `master` branch
2023-03-13 07:42:26 +00:00
- Collaborators will be invited based on contributions
2023-03-16 06:55:13 +00:00
- Any help with managing issues and PRs is very appreciated!
2023-03-17 18:30:04 +00:00
- Make sure to read this: [Inference at the edge ](https://github.com/ggerganov/llama.cpp/discussions/205 )
2023-03-23 08:46:58 +00:00
- A bit of backstory for those who are interested: [Changelog podcast ](https://changelog.com/podcast/532 )
2023-03-13 07:42:26 +00:00
2023-03-14 07:43:52 +00:00
### Coding guidelines
2023-03-13 07:42:26 +00:00
- Avoid adding third-party dependencies, extra files, extra headers, etc.
- Always consider cross-compatibility with other operating systems and architectures
2023-03-14 07:43:52 +00:00
- Avoid fancy looking modern STL constructs, use basic `for` loops, avoid templates, keep it simple
2023-03-13 07:42:26 +00:00
- There are no strict rules for the code style, but try to follow the patterns in the code (indentation, spaces, etc.). Vertical alignment makes things more readable and easier to batch edit
2023-04-19 19:52:14 +00:00
- Clean-up any trailing whitespaces, use 4 spaces for indentation, brackets on the same line, `void * ptr` , `int & a`
2023-03-14 07:43:52 +00:00
- See [good first issues ](https://github.com/ggerganov/llama.cpp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 ) for tasks suitable for first contributions
2023-12-21 17:27:14 +00:00
- Tensors store data in row-major order. We refer to dimension 0 as columns, 1 as rows, 2 as matrices
- Matrix multiplication is unconventional: [`z = ggml_mul_mat(ctx, x, y)` ](https://github.com/ggerganov/llama.cpp/blob/880e352277fc017df4d5794f0c21c44e1eae2b84/ggml.h#L1058-L1064 ) means `zT = x @ yT`
2023-03-23 11:30:40 +00:00
2023-04-05 15:56:20 +00:00
### Docs
2023-07-09 07:38:42 +00:00
- [main ](./examples/main/README.md )
- [server ](./examples/server/README.md )
- [jeopardy ](./examples/jeopardy/README.md )
- [BLIS ](./docs/BLIS.md )
2023-06-05 20:32:36 +00:00
- [Performance troubleshooting ](./docs/token_generation_performance_tips.md )
2023-07-09 07:38:42 +00:00
- [GGML tips & tricks ](https://github.com/ggerganov/llama.cpp/wiki/GGML-Tips-&-Tricks )
2023-08-23 01:01:57 +00:00
- [GBNF grammars ](./grammars/README.md )