mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-25 05:48:47 +01:00
6381d4e110
* gguf : first API pass
* gguf : read header + meta data
* gguf : read tensor info
* gguf : initial model loading - not tested
* gguf : add gguf_get_tensor_name()
* gguf : do not support passing existing ggml_context to gguf_init
* gguf : simplify gguf_get_val
* gguf : gguf.c is now part of ggml.c
* gguf : read / write sample models
* gguf : add comments
* refactor : reduce code duplication and better API (#2415)
* gguf : expose the gguf_type enum through the API for now
* gguf : add array support
* gguf.py : some code style changes
* convert.py : start a new simplified implementation by removing old stuff
* convert.py : remove GGML vocab + other obsolete stuff
* GGUF : write tensor (#2426)
* WIP: Write tensor
* GGUF : Support writing tensors in Python
* refactor : rm unused import and upd todos
* fix : fix errors upd writing example
* rm example.gguf
* gitignore *.gguf
* undo formatting
* gguf : add gguf_find_key (#2438)
* gguf.cpp : find key example
* ggml.h : add gguf_find_key
* ggml.c : add gguf_find_key
* gguf : fix writing tensors
* gguf : do not hardcode tensor names to read
* gguf : write sample tensors to read
* gguf : add tokenization constants
* quick and dirty conversion example
* gguf : fix writing gguf arrays
* gguf : write tensors one by one and code reuse
* gguf : fix writing gguf arrays
* gguf : write tensors one by one
* gguf : write tensors one by one
* gguf : write tokenizer data
* gguf : upd gguf conversion script
* Update convert-llama-h5-to-gguf.py
* gguf : handle already encoded string
* ggml.h : get array str and f32
* ggml.c : get arr str and f32
* gguf.py : support any type
* Update convert-llama-h5-to-gguf.py
* gguf : fix set is not subscriptable
* gguf : update convert-llama-h5-to-gguf.py
* constants.py : add layer norm eps
* gguf.py : add layer norm eps and merges
* ggml.h : increase GGML_MAX_NAME to 64
* ggml.c : add gguf_get_arr_n
* Update convert-llama-h5-to-gguf.py
* add gptneox gguf example
* Makefile : add gptneox gguf example
* Update convert-llama-h5-to-gguf.py
* add gptneox gguf example
* Update convert-llama-h5-to-gguf.py
* Update convert-gptneox-h5-to-gguf.py
* Update convert-gptneox-h5-to-gguf.py
* Update convert-llama-h5-to-gguf.py
* gguf : support custom alignment value
* gguf : fix typo in function call
* gguf : mmap tensor data example
* fix : update convert-llama-h5-to-gguf.py
* Update convert-llama-h5-to-gguf.py
* convert-gptneox-h5-to-gguf.py : Special tokens
* gptneox-main.cpp : special tokens
* Update gptneox-main.cpp
* constants.py : special tokens
* gguf.py : accumulate kv and tensor info data + special tokens
* convert-gptneox-h5-to-gguf.py : accumulate kv and ti + special tokens
* gguf : gguf counterpart of llama-util.h
* gguf-util.h : update note
* convert-llama-h5-to-gguf.py : accumulate kv / ti + special tokens
* convert-llama-h5-to-gguf.py : special tokens
* Delete gptneox-common.cpp
* Delete gptneox-common.h
* convert-gptneox-h5-to-gguf.py : gpt2bpe tokenizer
* gptneox-main.cpp : gpt2 bpe tokenizer
* gpt2 bpe tokenizer (handles merges and unicode)
* Makefile : remove gptneox-common
* gguf.py : bytesarray for gpt2bpe tokenizer
* cmpnct_gpt2bpe.hpp : comments
* gguf.py : use custom alignment if present
* gguf : minor stuff
* Update gptneox-main.cpp
* map tensor names
* convert-gptneox-h5-to-gguf.py : map tensor names
* convert-llama-h5-to-gguf.py : map tensor names
* gptneox-main.cpp : map tensor names
* gguf : start implementing libllama in GGUF (WIP)
* gguf : start implementing libllama in GGUF (WIP)
* rm binary commited by mistake
* upd .gitignore
* gguf : calculate n_mult
* gguf : inference with 7B model working (WIP)
* gguf : rm deprecated function
* gguf : start implementing gguf_file_saver (WIP)
* gguf : start implementing gguf_file_saver (WIP)
* gguf : start implementing gguf_file_saver (WIP)
* gguf : add gguf_get_kv_type
* gguf : add gguf_get_kv_type
* gguf : write metadata in gguf_file_saver (WIP)
* gguf : write metadata in gguf_file_saver (WIP)
* gguf : write metadata in gguf_file_saver
* gguf : rm references to old file formats
* gguf : shorter name for member variable
* gguf : rm redundant method
* gguf : get rid of n_mult, read n_ff from file
* Update gguf_tensor_map.py
* Update gptneox-main.cpp
* gguf : rm references to old file magics
* gguf : start implementing quantization (WIP)
* gguf : start implementing quantization (WIP)
* gguf : start implementing quantization (WIP)
* gguf : start implementing quantization (WIP)
* gguf : start implementing quantization (WIP)
* gguf : start implementing quantization (WIP)
* gguf : quantization is working
* gguf : roper closing of file
* gguf.py : no need to convert tensors twice
* convert-gptneox-h5-to-gguf.py : no need to convert tensors twice
* convert-llama-h5-to-gguf.py : no need to convert tensors twice
* convert-gptneox-h5-to-gguf.py : simplify nbytes
* convert-llama-h5-to-gguf.py : simplify nbytes
* gptneox-main.cpp : n_layer --> n_block
* constants.py : n_layer --> n_block
* gguf.py : n_layer --> n_block
* convert-gptneox-h5-to-gguf.py : n_layer --> n_block
* convert-llama-h5-to-gguf.py : n_layer --> n_block
* gptneox-main.cpp : n_layer --> n_block
* Update gguf_tensor_map.py
* convert-gptneox-h5-to-gguf.py : load model in parts to save memory
* convert-llama-h5-to-gguf.py : load model in parts to save memory
* convert : write more metadata for LLaMA
* convert : rm quantization version
* convert-gptneox-h5-to-gguf.py : add file_type key
* gptneox-main.cpp : add file_type key
* fix conflicts
* gguf : add todos and comments
* convert-gptneox-h5-to-gguf.py : tensor name map changes
* Create gguf_namemap.py : tensor name map changes
* Delete gguf_tensor_map.py
* gptneox-main.cpp : tensor name map changes
* convert-llama-h5-to-gguf.py : fixes
* gguf.py : dont add empty strings
* simple : minor style changes
* gguf : use UNIX line ending
* Create convert-llama-7b-pth-to-gguf.py
* llama : sync gguf-llama.cpp with latest llama.cpp (#2608)
* llama : sync gguf-llama.cpp with latest llama.cpp
* minor : indentation + assert
* llama : refactor gguf_buffer and gguf_ctx_buffer
* llama : minor
* gitignore : add gptneox-main
* llama : tokenizer fixes (#2549)
* Merge tokenizer fixes into the gguf branch.
* Add test vocabularies
* convert : update convert-new.py with tokenizer fixes (#2614)
* Merge tokenizer fixes into the gguf branch.
* Add test vocabularies
* Adapt convert-new.py (and fix a clang-cl compiler error on windows)
* llama : sync gguf-llama with llama (#2613)
* llama : sync gguf-llama with llama
* tests : fix build + warnings (test-tokenizer-1 still fails)
* tests : fix wstring_convert
* convert : fix layer names
* llama : sync gguf-llama.cpp
* convert : update HF converter to new tokenizer voodoo magics
* llama : update tokenizer style
* convert-llama-h5-to-gguf.py : add token types
* constants.py : add token types
* gguf.py : add token types
* convert-llama-7b-pth-to-gguf.py : add token types
* gguf-llama.cpp : fix n_head_kv
* convert-llama-h5-to-gguf.py : add 70b gqa support
* gguf.py : add tensor data layout
* convert-llama-h5-to-gguf.py : add tensor data layout
* convert-llama-7b-pth-to-gguf.py : add tensor data layout
* gptneox-main.cpp : add tensor data layout
* convert-llama-h5-to-gguf.py : clarify the reverse permute
* llama : refactor model loading code (#2620)
* llama : style formatting + remove helper methods
* llama : fix quantization using gguf tool
* llama : simplify gguf_file_saver
* llama : fix method names
* llama : simplify write_header()
* llama : no need to pass full file loader to the file saver
just gguf_ctx
* llama : gguf_file_saver write I32
* llama : refactor tensor names (#2622)
* gguf: update tensor names searched in quantization
* gguf : define tensor names as constants
* gguf : initial write API (not tested yet)
* gguf : write to file API (not tested)
* gguf : initial write API ready + example
* gguf : fix header write
* gguf : fixes + simplify example + add ggml_nbytes_pad()
* gguf : minor
* llama : replace gguf_file_saver with new gguf write API
* gguf : streaming support when writing files
* gguf : remove oboslete write methods
* gguf : remove obosolete gguf_get_arr_xxx API
* llama : simplify gguf_file_loader
* llama : move hparams and vocab from gguf_file_loader to llama_model_loader
* llama : merge gguf-util.h in llama.cpp
* llama : reorder definitions in .cpp to match .h
* llama : minor simplifications
* llama : refactor llama_model_loader (WIP)
wip : remove ggml_ctx from llama_model_loader
wip : merge gguf_file_loader in llama_model_loader
* llama : fix shape prints
* llama : fix Windows build + fix norm_rms_eps key
* llama : throw error on missing KV paris in model meta data
* llama : improve printing + log meta data
* llama : switch print order of meta data
---------
Co-authored-by: M. Yusuf Sarıgöz <yusufsarigoz@gmail.com>
* gguf : deduplicate (#2629)
* gguf : better type names
* dedup : CPU + Metal is working
* ggml : fix warnings about unused results
* llama.cpp : fix line feed and compiler warning
* llama : fix strncpy warning + note token_to_str does not write null
* llama : restore the original load/save session implementation
Will migrate this to GGUF in the future
* convert-llama-h5-to-gguf.py : support alt ctx param name
* ggml : assert when using ggml_mul with non-F32 src1
* examples : dedup simple
---------
Co-authored-by: klosax <131523366+klosax@users.noreply.github.com>
* gguf.py : merge all files in gguf.py
* convert-new.py : pick #2427 for HF 70B support
* examples/gguf : no need to keep q option for quantization any more
* llama.cpp : print actual model size
* llama.cpp : use ggml_elements()
* convert-new.py : output gguf (#2635)
* convert-new.py : output gguf (WIP)
* convert-new.py : add gguf key-value pairs
* llama : add hparams.ctx_train + no longer print ftype
* convert-new.py : minor fixes
* convert-new.py : vocab-only option should work now
* llama : fix tokenizer to use llama_char_to_byte
* tests : add new ggml-vocab-llama.gguf
* convert-new.py : tensor name mapping
* convert-new.py : add map for skipping tensor serialization
* convert-new.py : convert script now works
* gguf.py : pick some of the refactoring from #2644
* convert-new.py : minor fixes
* convert.py : update to support GGUF output
* Revert "ci : disable CI temporary to not waste energy"
This reverts commit 7e82d25f40
.
* convert.py : n_head_kv optional and .gguf file extension
* convert.py : better always have n_head_kv and default it to n_head
* llama : sync with recent PRs on master
* editorconfig : ignore models folder
ggml-ci
* ci : update ".bin" to ".gguf" extension
ggml-ci
* llama : fix llama_model_loader memory leak
* gptneox : move as a WIP example
* llama : fix lambda capture
ggml-ci
* ggml : fix bug in gguf_set_kv
ggml-ci
* common.h : .bin --> .gguf
* quantize-stats.cpp : .bin --> .gguf
* convert.py : fix HF tensor permuting / unpacking
ggml-ci
* llama.cpp : typo
* llama : throw error if gguf fails to init from file
ggml-ci
* llama : fix tensor name grepping during quantization
ggml-ci
* gguf.py : write tensors in a single pass (#2644)
* gguf : single pass for writing tensors + refactoring writer
* gguf : single pass for writing tensors + refactoring writer
* gguf : single pass for writing tensors + refactoring writer
* gguf : style fixes in simple conversion script
* gguf : refactor gptneox conversion script
* gguf : rename h5 to hf (for HuggingFace)
* gguf : refactor pth to gguf conversion script
* gguf : rm file_type key and method
* gguf.py : fix vertical alignment
* gguf.py : indentation
---------
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* convert-gptneox-hf-to-gguf.py : fixes
* gguf.py : gptneox mapping
* convert-llama-hf-to-gguf.py : fixes
* convert-llama-7b-pth-to-gguf.py : fixes
* ggml.h : reverse GGUF_MAGIC
* gguf.py : reverse GGUF_MAGIC
* test-tokenizer-0.cpp : fix warning
* llama.cpp : print kv general.name
* llama.cpp : get special token kv and linefeed token id
* llama : print number of tensors per type + print arch + style
* tests : update vocab file with new magic
* editorconfig : fix whitespaces
* llama : re-order functions
* llama : remove C++ API + reorganize common source in /common dir
* llama : minor API updates
* llama : avoid hardcoded special tokens
* llama : fix MPI build
ggml-ci
* llama : introduce enum llama_vocab_type + remove hardcoded string constants
* convert-falcon-hf-to-gguf.py : falcon HF --> gguf conversion, not tested
* falcon-main.cpp : falcon inference example
* convert-falcon-hf-to-gguf.py : remove extra kv
* convert-gptneox-hf-to-gguf.py : remove extra kv
* convert-llama-7b-pth-to-gguf.py : remove extra kv
* convert-llama-hf-to-gguf.py : remove extra kv
* gguf.py : fix for falcon 40b
* falcon-main.cpp : fix for falcon 40b
* convert-falcon-hf-to-gguf.py : update ref
* convert-falcon-hf-to-gguf.py : add tensor data layout
* cmpnct_gpt2bpe.hpp : fixes
* falcon-main.cpp : fixes
* gptneox-main.cpp : fixes
* cmpnct_gpt2bpe.hpp : remove non-general stuff
* Update examples/server/README.md
Co-authored-by: slaren <slarengh@gmail.com>
* cmpnct_gpt2bpe.hpp : cleanup
* convert-llama-hf-to-gguf.py : special tokens
* convert-llama-7b-pth-to-gguf.py : special tokens
* convert-permute-debug.py : permute debug print
* convert-permute-debug-master.py : permute debug for master
* convert-permute-debug.py : change permute type of attn_q
* convert.py : 70b model working (change attn_q permute)
* Delete convert-permute-debug-master.py
* Delete convert-permute-debug.py
* convert-llama-hf-to-gguf.py : fix attn_q permute
* gguf.py : fix rope scale kv
* convert-llama-hf-to-gguf.py : rope scale and added tokens
* convert-llama-7b-pth-to-gguf.py : rope scale and added tokens
* llama.cpp : use rope scale kv
* convert-llama-7b-pth-to-gguf.py : rope scale fix
* convert-llama-hf-to-gguf.py : rope scale fix
* py : fix whitespace
* gguf : add Python script to convert GGMLv3 LLaMA models to GGUF (#2682)
* First pass at converting GGMLv3 LLaMA models to GGUF
* Cleanups, better output during conversion
* Fix vocab space conversion logic
* More vocab conversion fixes
* Add description to converted GGUF files
* Improve help text, expand warning
* Allow specifying name and description for output GGUF
* Allow overriding vocab and hyperparams from original model metadata
* Use correct params override var name
* Fix wrong type size for Q8_K
Better handling of original style metadata
* Set default value for gguf add_tensor raw_shape KW arg
* llama : improve token type support (#2668)
* Merge tokenizer fixes into the gguf branch.
* Add test vocabularies
* Adapt convert-new.py (and fix a clang-cl compiler error on windows)
* Improved tokenizer test
But does it work on MacOS?
* Improve token type support
- Added @klosax code to convert.py
- Improved token type support in vocabulary
* Exclude platform dependent tests
* More sentencepiece compatibility by eliminating magic numbers
* Restored accidentally removed comment
* llama : add API for token type
ggml-ci
* tests : use new tokenizer type API (#2692)
* Merge tokenizer fixes into the gguf branch.
* Add test vocabularies
* Adapt convert-new.py (and fix a clang-cl compiler error on windows)
* Improved tokenizer test
But does it work on MacOS?
* Improve token type support
- Added @klosax code to convert.py
- Improved token type support in vocabulary
* Exclude platform dependent tests
* More sentencepiece compatibility by eliminating magic numbers
* Restored accidentally removed comment
* Improve commentary
* Use token type API in test-tokenizer-1.cpp
* py : cosmetics
* readme : add notice about new file format
ggml-ci
---------
Co-authored-by: M. Yusuf Sarıgöz <yusufsarigoz@gmail.com>
Co-authored-by: klosax <131523366+klosax@users.noreply.github.com>
Co-authored-by: goerch <jhr.walter@t-online.de>
Co-authored-by: slaren <slarengh@gmail.com>
Co-authored-by: Kerfuffle <44031344+KerfuffleV2@users.noreply.github.com>
888 lines
41 KiB
Markdown
888 lines
41 KiB
Markdown
# llama.cpp
|
||
|
||
![llama](https://user-images.githubusercontent.com/1991296/230134379-7181e485-c521-4d23-a0d6-f7b3b61ba524.png)
|
||
|
||
[![Actions Status](https://github.com/ggerganov/llama.cpp/workflows/CI/badge.svg)](https://github.com/ggerganov/llama.cpp/actions)
|
||
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
||
|
||
[Roadmap](https://github.com/users/ggerganov/projects/7) / [Manifesto](https://github.com/ggerganov/llama.cpp/discussions/205) / [ggml](https://github.com/ggerganov/ggml)
|
||
|
||
Inference of [LLaMA](https://arxiv.org/abs/2302.13971) model in pure C/C++
|
||
|
||
### Hot topics
|
||
|
||
A new file format has been introduced: [GGUF](https://github.com/ggerganov/llama.cpp/pull/2398)
|
||
|
||
Last revision compatible with the old format: [dadbed9](https://github.com/ggerganov/llama.cpp/commit/dadbed99e65252d79f81101a392d0d6497b86caa)
|
||
|
||
### Current `master` should be considered in Beta - expect some issues for a few days!
|
||
|
||
### Be prepared to re-convert and / or re-quantize your GGUF models while this notice is up!
|
||
|
||
### Issues with non-GGUF models will be considered with low priority!
|
||
|
||
----
|
||
|
||
<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>
|
||
<li><a href="#instruction-mode-with-alpaca">Instruction mode with Alpaca</a></li>
|
||
<li><a href="#using-openllama">Using OpenLLaMA</a></li>
|
||
<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>
|
||
|
||
## Description
|
||
|
||
The main goal of `llama.cpp` is to run the LLaMA model using 4-bit integer quantization on a MacBook
|
||
|
||
- Plain C/C++ implementation without dependencies
|
||
- Apple silicon first-class citizen - optimized via ARM NEON, Accelerate and Metal frameworks
|
||
- AVX, AVX2 and AVX512 support for x86 architectures
|
||
- Mixed F16 / F32 precision
|
||
- 4-bit, 5-bit and 8-bit integer quantization support
|
||
- Supports OpenBLAS/Apple BLAS/ARM Performance Lib/ATLAS/BLIS/Intel MKL/NVHPC/ACML/SCSL/SGIMATH and [more](https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors) in BLAS
|
||
- cuBLAS and CLBlast support
|
||
|
||
The original implementation of `llama.cpp` was [hacked in an evening](https://github.com/ggerganov/llama.cpp/issues/33#issuecomment-1465108022).
|
||
Since then, the project has improved significantly thanks to many contributions. This project is for educational purposes and serves
|
||
as the main playground for developing new features for the [ggml](https://github.com/ggerganov/ggml) library.
|
||
|
||
**Supported platforms:**
|
||
|
||
- [X] Mac OS
|
||
- [X] Linux
|
||
- [X] Windows (via CMake)
|
||
- [X] Docker
|
||
|
||
**Supported models:**
|
||
|
||
- [X] LLaMA 🦙
|
||
- [x] LLaMA 2 🦙🦙
|
||
- [X] [Alpaca](https://github.com/ggerganov/llama.cpp#instruction-mode-with-alpaca)
|
||
- [X] [GPT4All](https://github.com/ggerganov/llama.cpp#using-gpt4all)
|
||
- [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)
|
||
- [X] [Vigogne (French)](https://github.com/bofenghuang/vigogne)
|
||
- [X] [Vicuna](https://github.com/ggerganov/llama.cpp/discussions/643#discussioncomment-5533894)
|
||
- [X] [Koala](https://bair.berkeley.edu/blog/2023/04/03/koala/)
|
||
- [X] [OpenBuddy 🐶 (Multilingual)](https://github.com/OpenBuddy/OpenBuddy)
|
||
- [X] [Pygmalion 7B / Metharme 7B](#using-pygmalion-7b--metharme-7b)
|
||
- [X] [WizardLM](https://github.com/nlpxucan/WizardLM)
|
||
- [X] [Baichuan-7B](https://huggingface.co/baichuan-inc/baichuan-7B) and its derivations (such as [baichuan-7b-sft](https://huggingface.co/hiyouga/baichuan-7b-sft))
|
||
- [X] [Aquila-7B](https://huggingface.co/BAAI/Aquila-7B) / [AquilaChat-7B](https://huggingface.co/BAAI/AquilaChat-7B)
|
||
|
||
**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)
|
||
- Node.js: [hlhr202/llama-node](https://github.com/hlhr202/llama-node)
|
||
- Ruby: [yoshoku/llama_cpp.rb](https://github.com/yoshoku/llama_cpp.rb)
|
||
- Rust: [mdrokz/rust-llama.cpp](https://github.com/mdrokz/rust-llama.cpp)
|
||
- C#/.NET: [SciSharp/LLamaSharp](https://github.com/SciSharp/LLamaSharp)
|
||
- Scala 3: [donderom/llm4s](https://github.com/donderom/llm4s)
|
||
- Clojure: [phronmophobic/llama.clj](https://github.com/phronmophobic/llama.clj)
|
||
|
||
**UI:**
|
||
|
||
- [nat/openplayground](https://github.com/nat/openplayground)
|
||
- [oobabooga/text-generation-webui](https://github.com/oobabooga/text-generation-webui)
|
||
|
||
---
|
||
|
||
Here is a typical run using LLaMA-7B:
|
||
|
||
```java
|
||
make -j && ./main -m ./models/7B/ggml-model-q4_0.bin -p "Building a website can be done in 10 simple steps:" -n 512
|
||
I llama.cpp build info:
|
||
I UNAME_S: Darwin
|
||
I UNAME_P: arm
|
||
I UNAME_M: arm64
|
||
I CFLAGS: -I. -O3 -DNDEBUG -std=c11 -fPIC -pthread -DGGML_USE_ACCELERATE
|
||
I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread
|
||
I LDFLAGS: -framework Accelerate
|
||
I CC: Apple clang version 14.0.0 (clang-1400.0.29.202)
|
||
I CXX: Apple clang version 14.0.0 (clang-1400.0.29.202)
|
||
|
||
make: Nothing to be done for `default'.
|
||
main: seed = 1678486056
|
||
llama_model_load: loading model from './models/7B/ggml-model-q4_0.bin' - please wait ...
|
||
llama_model_load: n_vocab = 32000
|
||
llama_model_load: n_ctx = 512
|
||
llama_model_load: n_embd = 4096
|
||
llama_model_load: n_mult = 256
|
||
llama_model_load: n_head = 32
|
||
llama_model_load: n_layer = 32
|
||
llama_model_load: n_rot = 128
|
||
llama_model_load: f16 = 2
|
||
llama_model_load: n_ff = 11008
|
||
llama_model_load: ggml ctx size = 4529.34 MB
|
||
llama_model_load: memory_size = 512.00 MB, n_mem = 16384
|
||
llama_model_load: .................................... done
|
||
llama_model_load: model size = 4017.27 MB / num tensors = 291
|
||
|
||
main: prompt: 'Building a website can be done in 10 simple steps:'
|
||
main: number of tokens in prompt = 15
|
||
1 -> ''
|
||
8893 -> 'Build'
|
||
292 -> 'ing'
|
||
263 -> ' a'
|
||
4700 -> ' website'
|
||
508 -> ' can'
|
||
367 -> ' be'
|
||
2309 -> ' done'
|
||
297 -> ' in'
|
||
29871 -> ' '
|
||
29896 -> '1'
|
||
29900 -> '0'
|
||
2560 -> ' simple'
|
||
6576 -> ' steps'
|
||
29901 -> ':'
|
||
|
||
sampling parameters: temp = 0.800000, top_k = 40, top_p = 0.950000
|
||
|
||
|
||
Building a website can be done in 10 simple steps:
|
||
1) Select a domain name and web hosting plan
|
||
2) Complete a sitemap
|
||
3) List your products
|
||
4) Write product descriptions
|
||
5) Create a user account
|
||
6) Build the template
|
||
7) Start building the website
|
||
8) Advertise the website
|
||
9) Provide email support
|
||
10) Submit the website to search engines
|
||
A website is a collection of web pages that are formatted with HTML. HTML is the code that defines what the website looks like and how it behaves.
|
||
The HTML code is formatted into a template or a format. Once this is done, it is displayed on the user's browser.
|
||
The web pages are stored in a web server. The web server is also called a host. When the website is accessed, it is retrieved from the server and displayed on the user's computer.
|
||
A website is known as a website when it is hosted. This means that it is displayed on a host. The host is usually a web server.
|
||
A website can be displayed on different browsers. The browsers are basically the software that renders the website on the user's screen.
|
||
A website can also be viewed on different devices such as desktops, tablets and smartphones.
|
||
Hence, to have a website displayed on a browser, the website must be hosted.
|
||
A domain name is an address of a website. It is the name of the website.
|
||
The website is known as a website when it is hosted. This means that it is displayed on a host. The host is usually a web server.
|
||
A website can be displayed on different browsers. The browsers are basically the software that renders the website on the user’s screen.
|
||
A website can also be viewed on different devices such as desktops, tablets and smartphones. Hence, to have a website displayed on a browser, the website must be hosted.
|
||
A domain name is an address of a website. It is the name of the website.
|
||
A website is an address of a website. It is a collection of web pages that are formatted with HTML. HTML is the code that defines what the website looks like and how it behaves.
|
||
The HTML code is formatted into a template or a format. Once this is done, it is displayed on the user’s browser.
|
||
A website is known as a website when it is hosted
|
||
|
||
main: mem per token = 14434244 bytes
|
||
main: load time = 1332.48 ms
|
||
main: sample time = 1081.40 ms
|
||
main: predict time = 31378.77 ms / 61.41 ms per token
|
||
main: total time = 34036.74 ms
|
||
```
|
||
|
||
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
|
||
|
||
## Usage
|
||
|
||
Here are the steps for the LLaMA-7B model.
|
||
|
||
### Get the Code
|
||
|
||
```bash
|
||
git clone https://github.com/ggerganov/llama.cpp
|
||
cd llama.cpp
|
||
```
|
||
|
||
### Build
|
||
|
||
In order to build llama.cpp you have three different options.
|
||
|
||
- Using `make`:
|
||
- On Linux or MacOS:
|
||
|
||
```bash
|
||
make
|
||
```
|
||
|
||
- On Windows:
|
||
|
||
1. Download the latest fortran version of [w64devkit](https://github.com/skeeto/w64devkit/releases).
|
||
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
|
||
```
|
||
|
||
- Using `CMake`:
|
||
|
||
```bash
|
||
mkdir build
|
||
cd build
|
||
cmake ..
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
- 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:
|
||
|
||
```bash
|
||
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-windows-gnu -Dcpu=x86_64+avx2+fma+f16c
|
||
```
|
||
|
||
The `zig targets` command will give you valid options to use.
|
||
|
||
- 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
|
||
|
||
gmake CC=/usr/local/bin/clang15 CXX=/usr/local/bin/clang++15 -j4
|
||
```
|
||
|
||
**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.
|
||
|
||
### Metal Build
|
||
|
||
Using Metal allows the computation to be executed on the GPU for Apple devices:
|
||
|
||
- Using `make`:
|
||
|
||
```bash
|
||
LLAMA_METAL=1 make
|
||
```
|
||
|
||
- Using `CMake`:
|
||
|
||
```bash
|
||
mkdir build-metal
|
||
cd build-metal
|
||
cmake -DLLAMA_METAL=ON ..
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
When built with Metal support, you can enable GPU inference with the `--gpu-layers|-ngl` command-line argument.
|
||
Any value larger than 0 will offload the computation to the GPU. For example:
|
||
|
||
```bash
|
||
./main -m ./models/7B/ggml-model-q4_0.gguf -n 128 -ngl 1
|
||
```
|
||
|
||
### 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
|
||
mpirun -hostfile hostfile -n 3 ./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
|
||
```
|
||
|
||
### BLAS Build
|
||
|
||
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). BLAS doesn't affect the normal generation performance. There are currently three different implementations of it:
|
||
|
||
- #### Accelerate Framework:
|
||
|
||
This is only available on Mac PCs and it's enabled by default. You can just build using the normal instructions.
|
||
|
||
- #### OpenBLAS:
|
||
|
||
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
|
||
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
- #### BLIS
|
||
|
||
Check [BLIS.md](docs/BLIS.md) for more information.
|
||
|
||
- #### Intel MKL
|
||
|
||
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. You may also specify it by:
|
||
|
||
```bash
|
||
mkdir build
|
||
cd build
|
||
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
- #### cuBLAS
|
||
|
||
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 or from here: [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads).
|
||
- Using `make`:
|
||
```bash
|
||
make LLAMA_CUBLAS=1
|
||
```
|
||
- Using `CMake`:
|
||
|
||
```bash
|
||
mkdir build
|
||
cd build
|
||
cmake .. -DLLAMA_CUBLAS=ON
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
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:
|
||
|
||
<!---
|
||
| 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). |
|
||
--->
|
||
| 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. |
|
||
|
||
- #### CLBlast
|
||
|
||
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.
|
||
|
||
- <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>
|
||
|
||
Installing CLBlast: it may be found in your operating system's packages.
|
||
|
||
- <details>
|
||
<summary>If not, then installing from source:</summary>
|
||
|
||
```sh
|
||
git clone https://github.com/CNugteren/CLBlast.git
|
||
mkdir CLBlast/build
|
||
cd CLBlast/build
|
||
cmake .. -DBUILD_SHARED_LIBS=OFF -DTUNERS=OFF
|
||
cmake --build . --config Release
|
||
cmake --install . --prefix /some/path
|
||
```
|
||
|
||
Where `/some/path` is where the built library will be installed (default is `/usr/local`).
|
||
</details>
|
||
|
||
Building:
|
||
|
||
- Build with make:
|
||
```sh
|
||
make LLAMA_CLBLAST=1
|
||
```
|
||
- CMake:
|
||
```sh
|
||
mkdir build
|
||
cd build
|
||
cmake .. -DLLAMA_CLBLAST=ON -DCLBlast_dir=/some/path
|
||
cmake --build . --config Release
|
||
```
|
||
|
||
Running:
|
||
|
||
The CLBlast build supports `--gpu-layers|-ngl` like the CUDA version does.
|
||
|
||
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.
|
||
|
||
### Prepare Data & Run
|
||
|
||
```bash
|
||
# obtain the original LLaMA model weights and place them in ./models
|
||
ls ./models
|
||
65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model
|
||
# [Optional] for models using BPE tokenizers
|
||
ls ./models
|
||
65B 30B 13B 7B vocab.json
|
||
|
||
# install Python dependencies
|
||
python3 -m pip install -r requirements.txt
|
||
|
||
# convert the 7B model to ggml FP16 format
|
||
python3 convert.py models/7B/
|
||
|
||
# [Optional] for models using BPE tokenizers
|
||
python convert.py models/7B/ --vocabtype bpe
|
||
|
||
# quantize the model to 4-bits (using q4_0 method)
|
||
./quantize ./models/7B/ggml-model-f16.gguf ./models/7B/ggml-model-q4_0.gguf q4_0
|
||
|
||
# run the inference
|
||
./main -m ./models/7B/ggml-model-q4_0.gguf -n 128
|
||
```
|
||
|
||
When running the larger models, make sure you have enough disk space to store all the intermediate files.
|
||
|
||
### Memory/Disk Requirements
|
||
|
||
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.
|
||
|
||
| 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 |
|
||
|
||
### Quantization
|
||
|
||
Several quantization methods are supported. They differ in the resulting model disk size and inference speed.
|
||
|
||
| Model | Measure | F16 | Q4_0 | Q4_1 | Q5_0 | Q5_1 | Q8_0 |
|
||
|------:|--------------|-------:|-------:|-------:|-------:|-------:|-------:|
|
||
| 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 |
|
||
|
||
### 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.
|
||
|
||
### Interactive mode
|
||
|
||
If you want a more ChatGPT-like experience, you can run in interactive mode by passing `-i` as a parameter.
|
||
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:"`.
|
||
|
||
Here is an example of a few-shot interaction, invoked with the command
|
||
|
||
```bash
|
||
# default arguments using a 7B model
|
||
./examples/chat.sh
|
||
|
||
# advanced chat with a 13B model
|
||
./examples/chat-13B.sh
|
||
|
||
# custom arguments using a 13B model
|
||
./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
|
||
```
|
||
|
||
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.
|
||
|
||
![image](https://user-images.githubusercontent.com/1991296/224575029-2af3c7dc-5a65-4f64-a6bb-517a532aea38.png)
|
||
|
||
### 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
|
||
```
|
||
|
||
### Instruction mode with Alpaca
|
||
|
||
1. First, download the `ggml` Alpaca model into the `./models` folder
|
||
2. Run the `main` tool like this:
|
||
|
||
```
|
||
./examples/alpaca.sh
|
||
```
|
||
|
||
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
|
||
> List 5 words that start with "ca".
|
||
cadaver, cauliflower, cabbage (vegetable), catalpa (tree) and Cailleach.
|
||
>
|
||
```
|
||
|
||
### 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>`
|
||
|
||
### Using [GPT4All](https://github.com/nomic-ai/gpt4all)
|
||
|
||
*Note: these instructions are likely obsoleted by the GGUF update*
|
||
|
||
- 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!
|
||
|
||
### 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`.
|
||
|
||
|
||
### Obtaining the Facebook LLaMA original model and Stanford Alpaca model data
|
||
|
||
- **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.**
|
||
- The LLaMA models are officially distributed by Facebook and will **never** be provided through this repository.
|
||
- Refer to [Facebook's LLaMA repository](https://github.com/facebookresearch/llama/pull/73/files) if you need to request access to the model data.
|
||
|
||
### 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:
|
||
- [LLaMA 2 7B base](https://huggingface.co/TheBloke/Llama-2-7B-GGML)
|
||
- [LLaMA 2 13B base](https://huggingface.co/TheBloke/Llama-2-13B-GGML)
|
||
- [LLaMA 2 70B base](https://huggingface.co/TheBloke/Llama-2-70B-GGML)
|
||
- [LLaMA 2 7B chat](https://huggingface.co/TheBloke/Llama-2-7B-chat-GGML)
|
||
- [LLaMA 2 13B chat](https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML)
|
||
- [LLaMA 2 70B chat](https://huggingface.co/TheBloke/Llama-2-70B-chat-GGML)
|
||
- Specify `-eps 1e-5` for best generation quality
|
||
- Specify `-gqa 8` for 70B models to work
|
||
|
||
### Verifying the model files
|
||
|
||
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:
|
||
|
||
```bash
|
||
# run the verification script
|
||
./scripts/verify-checksum-models.py
|
||
```
|
||
|
||
- 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:
|
||
- On Linux: `sha256sum --ignore-missing -c SHA256SUMS`
|
||
- on macOS: `shasum -a 256 --ignore-missing -c SHA256SUMS`
|
||
|
||
### Seminal papers and background on the models
|
||
|
||
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:
|
||
- LLaMA:
|
||
- [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)
|
||
- GPT-3
|
||
- [Language Models are Few-Shot Learners](https://arxiv.org/abs/2005.14165)
|
||
- GPT-3.5 / InstructGPT / ChatGPT:
|
||
- [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)
|
||
|
||
#### 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.
|
||
|
||
### Android
|
||
|
||
#### Building the Project using Android NDK
|
||
You can easily run `llama.cpp` on Android device with [termux](https://termux.dev/).
|
||
|
||
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:
|
||
```
|
||
$ 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
|
||
```
|
||
Install [termux](https://termux.dev/) on your device and run `termux-setup-storage` to get access to your SD card.
|
||
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
|
||
|
||
#### 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
|
||
export LD_LIBRARY_PATH=/vendor/lib64:$LD_LIBRARY_PATH
|
||
```
|
||
|
||
(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/ )
|
||
|
||
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.
|
||
|
||
Place your desired model into the `~/llama.cpp/models/` directory and execute the `./main (...)` script.
|
||
|
||
### Docker
|
||
|
||
#### Prerequisites
|
||
* Docker must be installed and running on your system.
|
||
* Create a folder to store big models & intermediate files (ex. /llama/models)
|
||
|
||
#### Images
|
||
We have two Docker images available for this project:
|
||
|
||
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.
|
||
2. `ghcr.io/ggerganov/llama.cpp:light`: This image only includes the main executable file.
|
||
|
||
#### 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.
|
||
|
||
Replace `/path/to/models` below with the actual path where you downloaded the models.
|
||
|
||
```bash
|
||
docker run -v /path/to/models:/models ghcr.io/ggerganov/llama.cpp:full --all-in-one "/models/" 7B
|
||
```
|
||
|
||
On completion, you are ready to play!
|
||
|
||
```bash
|
||
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
|
||
```
|
||
|
||
or with a light image:
|
||
|
||
```bash
|
||
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
|
||
```
|
||
|
||
### 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 .
|
||
```
|
||
|
||
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.
|
||
|
||
#### 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
|
||
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
|
||
```
|
||
|
||
### Contributing
|
||
|
||
- Contributors can open PRs
|
||
- Collaborators can push to branches in the `llama.cpp` repo and merge PRs into the `master` branch
|
||
- Collaborators will be invited based on contributions
|
||
- Any help with managing issues and PRs is very appreciated!
|
||
- Make sure to read this: [Inference at the edge](https://github.com/ggerganov/llama.cpp/discussions/205)
|
||
- A bit of backstory for those who are interested: [Changelog podcast](https://changelog.com/podcast/532)
|
||
|
||
### Coding guidelines
|
||
|
||
- Avoid adding third-party dependencies, extra files, extra headers, etc.
|
||
- Always consider cross-compatibility with other operating systems and architectures
|
||
- Avoid fancy looking modern STL constructs, use basic `for` loops, avoid templates, keep it simple
|
||
- 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
|
||
- Clean-up any trailing whitespaces, use 4 spaces for indentation, brackets on the same line, `void * ptr`, `int & a`
|
||
- 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
|
||
|
||
### Docs
|
||
|
||
- [main](./examples/main/README.md)
|
||
- [server](./examples/server/README.md)
|
||
- [embd-input](./examples/embd-input/README.md)
|
||
- [jeopardy](./examples/jeopardy/README.md)
|
||
- [BLIS](./docs/BLIS.md)
|
||
- [Performance troubleshooting](./docs/token_generation_performance_tips.md)
|
||
- [GGML tips & tricks](https://github.com/ggerganov/llama.cpp/wiki/GGML-Tips-&-Tricks)
|