llama.cpp

Siehe auch

llama.cpp ist eine freie Inferencing-Software und ermöglicht die Unterhaltung mit diversen initial mit Torch trainierten Sprachmodellen auf der Kommandozeile. Deren Entwickler nutzen es als Test-Tool bei der Entwicklung der GGML-Bibliotheken.

Links:

Installation auf RHEL/Fedora:

dnf -y install gcc-c++
REPO='ggerganov/llama.cpp'
curl --output $(basename ${REPO}).tar.gz https://codeload.github.com/${REPO}/tar.gz/refs/tags/$(curl --silent https://api.github.com/repos/${REPO}/releases/latest | jq -r '.tag_name')
tar xvzf llama.cpp.tar.gz
cd llama.cpp-*

# without NVIDIA/CUDA support:
make

# with NVIDIA/CUDA support:
make LLAMA_CUBLAS=1

Start des Tools:

./main
# main: error: unable to load model

Sprachmodell nach Name oder per Tags auf https://huggingface.co/models aussuchen, Beispiel:

  • Tasks: Text Generation

  • Libraries: PyTorch

  • Languages: de

Im nachfolgenden Beispiel wird TheBloke/CodeLlama-34B-Instruct-GGUF verwendet. Nach Studium der „Model Card“ auf der Hugging Face-Seite zu dem Modell haben wir uns für das File „Q5_K_M“ entschieden (25 GB Download, max. 27 GB RAM required).

Download des Modells am einfachsten mit Hilfe des Tools HuggingFace Model Downloader:

# takes 10 minutes or more
bash <(curl -sSL https://g.bodaay.io/hfd) --model TheBloke/CodeLlama-34B-Instruct-GGUF:Q5_K_M --concurrent 8 --storage models/

Um mit dem obigen, auf Chats feingetunten Modell auf der Kommandozeile zu schreiben:

# --color: colorise output to distinguish prompt and user input from generations
# --file: prompt file to start generation
# --interactive: run in interactive mode
# --model: model path
# --n-predict: number of tokens to predict
# --repeat_penalty: penalize repeat sequence of tokens
./main \
    --color \
    --file ./prompts/chat-with-bob.txt \
    --interactive \
    --model ./models/TheBloke_CodeLlama-34B-Instruct-GGUF/codellama-34b-instruct.Q5_K_M.gguf \
    --n-predict 128 \
    --repeat_penalty 1.0

Server starten - dieser hört erst einmal auf http://127.0.0.1:8080/:

./server \
    --model ./models/TheBloke_CodeLlama-34B-Instruct-GGUF/codellama-34b-instruct.Q5_K_M.gguf

Auf einem Laptop mit 8 Cores und 16 GB RAM benötigt die Antwort auf eine Frage mehrere Minuten.

Built on 2024-04-18