Instructions to use Felipe97/llama-cpp-compiled with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Felipe97/llama-cpp-compiled with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: llama cli -hf Felipe97/llama-cpp-compiled
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: llama cli -hf Felipe97/llama-cpp-compiled
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: ./build/bin/llama cli -hf Felipe97/llama-cpp-compiled
Use Docker
docker model run hf.co/Felipe97/llama-cpp-compiled
- Llama new
- LM Studio
- Jan
- Ollama
How to use Felipe97/llama-cpp-compiled with Ollama:
ollama run hf.co/Felipe97/llama-cpp-compiled
- Unsloth Desktop
- Docker Model Runner
How to use Felipe97/llama-cpp-compiled with Docker Model Runner:
docker model run hf.co/Felipe97/llama-cpp-compiled
- Lemonade
How to use Felipe97/llama-cpp-compiled with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Felipe97/llama-cpp-compiled
Run and chat with the model
lemonade run user.llama-cpp-compiled-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub (part 10)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +26 -0
- gguf-py/pyproject.toml +45 -0
- gguf-py/tests/__init__.py +1 -0
- gguf-py/tests/test_gguf_reader_validation.py +37 -0
- gguf-py/tests/test_metadata.py +238 -0
- gguf-py/tests/test_quants.py +248 -0
- grammars/README.md +402 -0
- grammars/arithmetic.gbnf +6 -0
- grammars/c.gbnf +42 -0
- grammars/chess.gbnf +13 -0
- grammars/english.gbnf +6 -0
- grammars/japanese.gbnf +7 -0
- grammars/json.gbnf +25 -0
- grammars/json_arr.gbnf +34 -0
- grammars/list.gbnf +4 -0
- include/llama-cpp.h +30 -0
- include/llama.h +1646 -0
- licenses/LICENSE-jsonhpp +21 -0
- media/llama0-banner.png +3 -0
- media/llama0-logo.png +3 -0
- media/llama1-banner.png +0 -0
- media/llama1-icon-transparent.png +0 -0
- media/llama1-icon-transparent.svg +77 -0
- media/llama1-icon.png +0 -0
- media/llama1-icon.svg +87 -0
- media/llama1-logo.png +0 -0
- media/llama1-logo.svg +34 -0
- media/matmul.png +3 -0
- media/matmul.svg +1238 -0
- models/.editorconfig +1 -0
- models/ggml-vocab-aquila.gguf +3 -0
- models/ggml-vocab-baichuan.gguf +3 -0
- models/ggml-vocab-bert-bge.gguf +3 -0
- models/ggml-vocab-bert-bge.gguf.inp +112 -0
- models/ggml-vocab-bert-bge.gguf.out +46 -0
- models/ggml-vocab-command-r.gguf +3 -0
- models/ggml-vocab-command-r.gguf.inp +112 -0
- models/ggml-vocab-command-r.gguf.out +46 -0
- models/ggml-vocab-deepseek-coder.gguf +3 -0
- models/ggml-vocab-deepseek-coder.gguf.inp +112 -0
- models/ggml-vocab-deepseek-coder.gguf.out +46 -0
- models/ggml-vocab-deepseek-llm.gguf +3 -0
- models/ggml-vocab-deepseek-llm.gguf.inp +112 -0
- models/ggml-vocab-deepseek-llm.gguf.out +46 -0
- models/ggml-vocab-falcon.gguf +3 -0
- models/ggml-vocab-falcon.gguf.inp +112 -0
- models/ggml-vocab-falcon.gguf.out +46 -0
- models/ggml-vocab-gemma-4.gguf +3 -0
- models/ggml-vocab-gemma-4.gguf.inp +111 -0
- models/ggml-vocab-gemma-4.gguf.out +46 -0
.gitattributes
CHANGED
|
@@ -53,3 +53,29 @@ build/tools/ui/ui-gzip/_gzip/_app/immutable/bundle.IcoPeDQ-.js filter=lfs diff=l
|
|
| 53 |
build/tools/ui/ui.cpp filter=lfs diff=lfs merge=lfs -text
|
| 54 |
docs/android/imported-into-android-studio.jpg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
docs/development/llama-star/idea-arch.key filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
build/tools/ui/ui.cpp filter=lfs diff=lfs merge=lfs -text
|
| 54 |
docs/android/imported-into-android-studio.jpg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
docs/development/llama-star/idea-arch.key filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
media/llama0-banner.png filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
media/llama0-logo.png filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
media/matmul.png filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
models/ggml-vocab-aquila.gguf filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
models/ggml-vocab-baichuan.gguf filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
models/ggml-vocab-bert-bge.gguf filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
models/ggml-vocab-command-r.gguf filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
models/ggml-vocab-deepseek-coder.gguf filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
models/ggml-vocab-deepseek-llm.gguf filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
models/ggml-vocab-falcon.gguf filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
models/ggml-vocab-gemma-4.gguf filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
models/ggml-vocab-gpt-2.gguf filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
models/ggml-vocab-gpt-neox.gguf filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
models/ggml-vocab-llama-bpe.gguf filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
models/ggml-vocab-llama-spm.gguf filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
models/ggml-vocab-mpt.gguf filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
models/ggml-vocab-nomic-bert-moe.gguf filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
models/ggml-vocab-phi-3.gguf filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
models/ggml-vocab-qwen2.gguf filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
models/ggml-vocab-qwen35.gguf filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
models/ggml-vocab-refact.gguf filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
models/ggml-vocab-starcoder.gguf filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
tools/mtmd/test-1.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
tools/mtmd/test-2.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
tools/mtmd/test-3.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
tools/mtmd/tests/test-1-positive.png filter=lfs diff=lfs merge=lfs -text
|
gguf-py/pyproject.toml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "gguf"
|
| 3 |
+
version = "0.19.0"
|
| 4 |
+
description = "Read and write ML models in GGUF for GGML"
|
| 5 |
+
keywords = ["ggml", "gguf", "llama.cpp"]
|
| 6 |
+
dynamic = ["classifiers"]
|
| 7 |
+
readme = "README.md"
|
| 8 |
+
authors = [{name = "GGML", email = "ggml@ggml.ai"}]
|
| 9 |
+
requires-python = '>=3.10'
|
| 10 |
+
dependencies = ['numpy (>=2.2.6)', 'tqdm (>=4.27)', 'pyyaml (>=5.1)', 'requests (>=2.25)']
|
| 11 |
+
classifiers = [
|
| 12 |
+
"Programming Language :: Python :: 3",
|
| 13 |
+
"License :: OSI Approved :: MIT License",
|
| 14 |
+
"Operating System :: OS Independent",
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
[project.urls]
|
| 18 |
+
homepage = "https://ggml.ai"
|
| 19 |
+
repository = "https://github.com/ggml-org/llama.cpp"
|
| 20 |
+
|
| 21 |
+
[project.scripts]
|
| 22 |
+
gguf-convert-endian = "gguf.scripts.gguf_convert_endian:main"
|
| 23 |
+
gguf-dump = "gguf.scripts.gguf_dump:main"
|
| 24 |
+
gguf-set-metadata = "gguf.scripts.gguf_set_metadata:main"
|
| 25 |
+
gguf-new-metadata = "gguf.scripts.gguf_new_metadata:main"
|
| 26 |
+
gguf-editor-gui = "gguf.scripts.gguf_editor_gui:main"
|
| 27 |
+
|
| 28 |
+
[project.optional-dependencies]
|
| 29 |
+
gui = ['PySide6 (>=6.9,<7.0) ; python_version >= "3.9" and python_version < "3.14"']
|
| 30 |
+
|
| 31 |
+
[tool.poetry]
|
| 32 |
+
packages = [
|
| 33 |
+
{include = "gguf"},
|
| 34 |
+
{include = "gguf/py.typed"},
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
[tool.poetry.dependencies]
|
| 38 |
+
python = ">=3.10"
|
| 39 |
+
|
| 40 |
+
[tool.poetry.group.dev.dependencies]
|
| 41 |
+
pytest = "^5.2"
|
| 42 |
+
|
| 43 |
+
[build-system]
|
| 44 |
+
requires = ["poetry-core>=1.0.0"]
|
| 45 |
+
build-backend = "poetry.core.masonry.api"
|
gguf-py/tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .test_metadata import *
|
gguf-py/tests/test_gguf_reader_validation.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import struct
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from gguf.gguf_reader import GGUFReader
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _write_gguf(path, n_dims_field, dims):
|
| 9 |
+
buf = b'GGUF' + struct.pack('<IQQ', 3, 1, 0) # version 3, 1 tensor, 0 kv
|
| 10 |
+
name = b'bad_tensor'
|
| 11 |
+
buf += struct.pack('<Q', len(name)) + name
|
| 12 |
+
buf += struct.pack('<I', n_dims_field)
|
| 13 |
+
for d in dims:
|
| 14 |
+
buf += struct.pack('<Q', d)
|
| 15 |
+
buf += struct.pack('<I', 0) # dtype F32
|
| 16 |
+
buf += struct.pack('<Q', 0) # tensor offset
|
| 17 |
+
buf += b'\x00' * 64
|
| 18 |
+
path.write_bytes(buf)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_n_dims_upper_bound(tmp_path):
|
| 22 |
+
# crafted file claims 1_000_000 dims; must be rejected, not read past EOF
|
| 23 |
+
p = tmp_path / 'evil_ndims.gguf'
|
| 24 |
+
_write_gguf(p, 1_000_000, [1] * 8)
|
| 25 |
+
with pytest.raises(ValueError, match='exceeds GGML_MAX_DIMS'):
|
| 26 |
+
GGUFReader(p)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_dims_product_no_uint64_wraparound(tmp_path):
|
| 30 |
+
# dims whose true product overflows uint64; np.prod would wrap to 4 and
|
| 31 |
+
# silently pass an undersized read. The reader must not accept it.
|
| 32 |
+
dims = [4194305, 4194305, 211106198978564]
|
| 33 |
+
assert int(np.prod(np.array(dims, dtype=np.uint64))) == 4 # the wrap bug
|
| 34 |
+
p = tmp_path / 'evil_overflow.gguf'
|
| 35 |
+
_write_gguf(p, len(dims), dims)
|
| 36 |
+
with pytest.raises(ValueError):
|
| 37 |
+
GGUFReader(p)
|
gguf-py/tests/test_metadata.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
# Necessary to load the local gguf package
|
| 9 |
+
if "NO_LOCAL_GGUF" not in os.environ and (Path(__file__).parent.parent.parent / 'gguf-py').exists():
|
| 10 |
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 11 |
+
|
| 12 |
+
import gguf
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestMetadataMethod(unittest.TestCase):
|
| 16 |
+
|
| 17 |
+
def test_id_to_title(self):
|
| 18 |
+
self.assertEqual(gguf.Metadata.id_to_title("Mixtral-8x7B-Instruct-v0.1"), "Mixtral 8x7B Instruct v0.1")
|
| 19 |
+
self.assertEqual(gguf.Metadata.id_to_title("Meta-Llama-3-8B"), "Meta Llama 3 8B")
|
| 20 |
+
self.assertEqual(gguf.Metadata.id_to_title("hermes-2-pro-llama-3-8b-DPO"), "Hermes 2 Pro Llama 3 8b DPO")
|
| 21 |
+
|
| 22 |
+
def test_get_model_id_components(self):
|
| 23 |
+
# This is the basic standard form with organization marker
|
| 24 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mistral/Mixtral-8x7B-Instruct-v0.1"),
|
| 25 |
+
('Mixtral-8x7B-Instruct-v0.1', "Mistral", 'Mixtral', 'Instruct', 'v0.1', '8x7B'))
|
| 26 |
+
|
| 27 |
+
# Similar to basic standard form but without organization marker
|
| 28 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral-8x7B-Instruct-v0.1"),
|
| 29 |
+
('Mixtral-8x7B-Instruct-v0.1', None, 'Mixtral', 'Instruct', 'v0.1', '8x7B'))
|
| 30 |
+
|
| 31 |
+
# Missing version
|
| 32 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral-8x7B-Instruct"),
|
| 33 |
+
('Mixtral-8x7B-Instruct', None, 'Mixtral', 'Instruct', None, '8x7B'))
|
| 34 |
+
|
| 35 |
+
# Missing finetune
|
| 36 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral-8x7B-v0.1"),
|
| 37 |
+
('Mixtral-8x7B-v0.1', None, 'Mixtral', None, 'v0.1', '8x7B'))
|
| 38 |
+
|
| 39 |
+
# Base name and size label only
|
| 40 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral-8x7B"),
|
| 41 |
+
('Mixtral-8x7B', None, 'Mixtral', None, None, '8x7B'))
|
| 42 |
+
|
| 43 |
+
# Base name and version only
|
| 44 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral-v0.1"),
|
| 45 |
+
('Mixtral-v0.1', None, 'Mixtral', None, 'v0.1', None))
|
| 46 |
+
|
| 47 |
+
## Edge Cases ##
|
| 48 |
+
|
| 49 |
+
# This is too ambiguous... best to err on caution and output nothing
|
| 50 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Mixtral"),
|
| 51 |
+
('Mixtral', None, None, None, None, None))
|
| 52 |
+
|
| 53 |
+
# Basename has numbers mixed in and also size label provided. Must avoid capturing number in basename
|
| 54 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("NousResearch/Meta-Llama-3-8B"),
|
| 55 |
+
('Meta-Llama-3-8B', "NousResearch", 'Meta-Llama-3', None, None, '8B'))
|
| 56 |
+
|
| 57 |
+
# Non standard naming
|
| 58 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Qwen1.5-MoE-A2.7B-Chat"),
|
| 59 |
+
('Qwen1.5-MoE-A2.7B-Chat', None, 'Qwen1.5-MoE', 'Chat', None, 'A2.7B'))
|
| 60 |
+
|
| 61 |
+
# Capture 'sub size labels' e.g. A14B in '57B-A14B' usually refers to activated params/weight count
|
| 62 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Qwen2-57B-A14B-Instruct"),
|
| 63 |
+
('Qwen2-57B-A14B-Instruct', None, 'Qwen2', 'Instruct', None, '57B-A14B'))
|
| 64 |
+
|
| 65 |
+
# Check that it can handle a real model id with no version code
|
| 66 |
+
# Note that 4k in this string is non standard and microsoft were referring to context length rather than weight count
|
| 67 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("microsoft/Phi-3-mini-4k-instruct", 4 * 10**9),
|
| 68 |
+
('Phi-3-mini-4k-instruct', 'microsoft', 'Phi-3', '4k-instruct', None, 'mini'))
|
| 69 |
+
|
| 70 |
+
# There is some legitimate models with only thousands of parameters
|
| 71 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("delphi-suite/stories-llama2-50k", 50 * 10**3),
|
| 72 |
+
('stories-llama2-50k', 'delphi-suite', 'stories-llama2', None, None, '50K'))
|
| 73 |
+
|
| 74 |
+
# Non standard and not easy to disambiguate
|
| 75 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("DeepSeek-Coder-V2-Lite-Instruct"),
|
| 76 |
+
('DeepSeek-Coder-V2-Lite-Instruct', None, 'DeepSeek-Coder-V2-Lite', 'Instruct', None, None))
|
| 77 |
+
|
| 78 |
+
# This is a real model_id where they append 2DPO to refer to Direct Preference Optimization
|
| 79 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("crestf411/daybreak-kunoichi-2dpo-7b"),
|
| 80 |
+
('daybreak-kunoichi-2dpo-7b', 'crestf411', 'daybreak-kunoichi', '2dpo', None, '7B'))
|
| 81 |
+
|
| 82 |
+
# This is a real model id where the weight size has a decimal point
|
| 83 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Qwen2-0.5B-Instruct"),
|
| 84 |
+
('Qwen2-0.5B-Instruct', None, 'Qwen2', 'Instruct', None, '0.5B'))
|
| 85 |
+
|
| 86 |
+
# Uses an underscore in the size label
|
| 87 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("smallcloudai/Refact-1_6B-fim"),
|
| 88 |
+
('Refact-1_6B-fim', 'smallcloudai', 'Refact', 'fim', None, '1.6B'))
|
| 89 |
+
|
| 90 |
+
# Uses Iter3 for the version
|
| 91 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("UCLA-AGI/Gemma-2-9B-It-SPPO-Iter3"),
|
| 92 |
+
('Gemma-2-9B-It-SPPO-Iter3', 'UCLA-AGI', 'Gemma-2', 'It-SPPO', 'Iter3', '9B'))
|
| 93 |
+
|
| 94 |
+
# Has two potential versions in the basename
|
| 95 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("NousResearch/Hermes-2-Theta-Llama-3-8B"),
|
| 96 |
+
('Hermes-2-Theta-Llama-3-8B', 'NousResearch', 'Hermes-2-Theta-Llama-3', None, None, '8B'))
|
| 97 |
+
|
| 98 |
+
# Potential version in the basename
|
| 99 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("SeaLLMs/SeaLLMs-v3-7B-Chat"),
|
| 100 |
+
('SeaLLMs-v3-7B-Chat', 'SeaLLMs', 'SeaLLMs-v3', 'Chat', None, '7B'))
|
| 101 |
+
|
| 102 |
+
# Underscore in the basename, and 1m for the context size
|
| 103 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("internlm/internlm2_5-7b-chat-1m", 7 * 10**9),
|
| 104 |
+
('internlm2_5-7b-chat-1m', 'internlm', 'internlm2_5', 'chat-1m', None, '7B'))
|
| 105 |
+
|
| 106 |
+
# Version before the finetune name
|
| 107 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("pszemraj/jamba-900M-v0.13-KIx2"),
|
| 108 |
+
('jamba-900M-v0.13-KIx2', 'pszemraj', 'jamba', 'KIx2', 'v0.13', '900M'))
|
| 109 |
+
|
| 110 |
+
# TODO: hf suffix which could be ignored but isn't
|
| 111 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("state-spaces/mamba-2.8b-hf"),
|
| 112 |
+
('mamba-2.8b-hf', 'state-spaces', 'mamba', 'hf', None, '2.8B'))
|
| 113 |
+
|
| 114 |
+
# Two sizes, don't merge them, the other is the number of tokens on which it was trained
|
| 115 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("abacaj/llama-161M-100B", 161 * 10**6),
|
| 116 |
+
('llama-161M-100B', 'abacaj', 'llama', '100b', None, '161M'))
|
| 117 |
+
|
| 118 |
+
# It's a trap, there is no size label
|
| 119 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("SparseLLM/relu-100B", 1340 * 10**6),
|
| 120 |
+
('relu-100B', 'SparseLLM', 'relu', '100b', None, None))
|
| 121 |
+
|
| 122 |
+
# Weird size notation
|
| 123 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("bigscience/bloom-7b1-petals"),
|
| 124 |
+
('bloom-7b1-petals', 'bigscience', 'bloom', 'petals', None, '7.1B'))
|
| 125 |
+
|
| 126 |
+
# Ignore full-text size labels when there are number-based ones, and deduplicate size labels
|
| 127 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("MaziyarPanahi/GreenNode-mini-7B-multilingual-v1olet-Mistral-7B-Instruct-v0.1"),
|
| 128 |
+
('GreenNode-mini-7B-multilingual-v1olet-Mistral-7B-Instruct-v0.1', 'MaziyarPanahi', 'GreenNode-mini', 'multilingual-v1olet-Mistral-Instruct', 'v0.1', '7B'))
|
| 129 |
+
|
| 130 |
+
# Instruct in a name without a size label
|
| 131 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("mistralai/Mistral-Nemo-Instruct-2407"),
|
| 132 |
+
('Mistral-Nemo-Instruct-2407', 'mistralai', 'Mistral-Nemo', 'Instruct', '2407', None))
|
| 133 |
+
|
| 134 |
+
# Non-obvious splitting relying on 'chat' keyword
|
| 135 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("deepseek-ai/DeepSeek-V2-Chat-0628"),
|
| 136 |
+
('DeepSeek-V2-Chat-0628', 'deepseek-ai', 'DeepSeek-V2', 'Chat', '0628', None))
|
| 137 |
+
|
| 138 |
+
# Multiple versions
|
| 139 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("OpenGVLab/Mini-InternVL-Chat-2B-V1-5"),
|
| 140 |
+
('Mini-InternVL-Chat-2B-V1-5', 'OpenGVLab', 'Mini-InternVL', 'Chat', 'V1-5', '2B'))
|
| 141 |
+
|
| 142 |
+
# TODO: DPO in the name
|
| 143 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("jondurbin/bagel-dpo-2.8b-v0.2"),
|
| 144 |
+
('bagel-dpo-2.8b-v0.2', 'jondurbin', 'bagel-dpo', None, 'v0.2', '2.8B'))
|
| 145 |
+
|
| 146 |
+
# DPO in name, but can't be used for the finetune to keep 'LLaMA-3' in the basename
|
| 147 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("voxmenthe/SFR-Iterative-DPO-LLaMA-3-8B-R-unquantized"),
|
| 148 |
+
('SFR-Iterative-DPO-LLaMA-3-8B-R-unquantized', 'voxmenthe', 'SFR-Iterative-DPO-LLaMA-3', 'R-unquantized', None, '8B'))
|
| 149 |
+
|
| 150 |
+
# Too ambiguous
|
| 151 |
+
# TODO: should "base" be a 'finetune' or 'size_label'?
|
| 152 |
+
# (in this case it should be a size label, but other models use it to signal that they are not finetuned)
|
| 153 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("microsoft/Florence-2-base"),
|
| 154 |
+
('Florence-2-base', 'microsoft', None, None, None, None))
|
| 155 |
+
|
| 156 |
+
## Invalid cases ##
|
| 157 |
+
|
| 158 |
+
# Start with a dash and has dashes in rows
|
| 159 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("mistralai/-Mistral--Nemo-Base-2407-"),
|
| 160 |
+
('-Mistral--Nemo-Base-2407-', 'mistralai', 'Mistral-Nemo-Base', None, '2407', None))
|
| 161 |
+
|
| 162 |
+
## LoRA ##
|
| 163 |
+
|
| 164 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Llama-3-Instruct-abliteration-LoRA-8B"),
|
| 165 |
+
('Llama-3-Instruct-abliteration-LoRA-8B', None, 'Llama-3', 'Instruct-abliteration-LoRA', None, '8B'))
|
| 166 |
+
|
| 167 |
+
# Negative size --> output is a LoRA adapter --> prune "LoRA" out of the name to avoid redundancy with the suffix
|
| 168 |
+
self.assertEqual(gguf.Metadata.get_model_id_components("Llama-3-Instruct-abliteration-LoRA-8B", -1234),
|
| 169 |
+
('Llama-3-Instruct-abliteration-LoRA-8B', None, 'Llama-3', 'Instruct-abliteration', None, '8B'))
|
| 170 |
+
|
| 171 |
+
def test_apply_metadata_heuristic_from_model_card(self):
|
| 172 |
+
model_card = {
|
| 173 |
+
'tags': ['Llama-3', 'instruct', 'finetune', 'chatml', 'DPO', 'RLHF', 'gpt4', 'synthetic data', 'distillation', 'function calling', 'json mode', 'axolotl'],
|
| 174 |
+
'model-index': [{'name': 'Mixtral-8x7B-Instruct-v0.1', 'results': []}],
|
| 175 |
+
'language': ['en'],
|
| 176 |
+
'datasets': ['teknium/OpenHermes-2.5'],
|
| 177 |
+
'widget': [{'example_title': 'Hermes 2 Pro', 'messages': [{'role': 'system', 'content': 'You are a sentient, superintelligent artificial general intelligence, here to teach and assist me.'}, {'role': 'user', 'content': 'Write a short story about Goku discovering kirby has teamed up with Majin Buu to destroy the world.'}]}],
|
| 178 |
+
'base_model': ["EmbeddedLLM/Mistral-7B-Merge-14-v0", "janai-hq/trinity-v1"]
|
| 179 |
+
}
|
| 180 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 181 |
+
expect = gguf.Metadata()
|
| 182 |
+
expect.base_models=[{'name': 'Mistral 7B Merge 14 v0', 'organization': 'EmbeddedLLM', 'version': '14-v0', 'repo_url': 'https://huggingface.co/EmbeddedLLM/Mistral-7B-Merge-14-v0'}, {'name': 'Trinity v1', 'organization': 'Janai Hq', 'version': 'v1', 'repo_url': 'https://huggingface.co/janai-hq/trinity-v1'}]
|
| 183 |
+
expect.tags=['Llama-3', 'instruct', 'finetune', 'chatml', 'DPO', 'RLHF', 'gpt4', 'synthetic data', 'distillation', 'function calling', 'json mode', 'axolotl']
|
| 184 |
+
expect.languages=['en']
|
| 185 |
+
expect.datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}]
|
| 186 |
+
self.assertEqual(got, expect)
|
| 187 |
+
|
| 188 |
+
# Base Model spec is inferred from model id
|
| 189 |
+
model_card = {'base_models': 'teknium/OpenHermes-2.5'}
|
| 190 |
+
expect = gguf.Metadata(base_models=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 191 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 192 |
+
self.assertEqual(got, expect)
|
| 193 |
+
|
| 194 |
+
# Base Model spec is only url
|
| 195 |
+
model_card = {'base_models': ['https://huggingface.co/teknium/OpenHermes-2.5']}
|
| 196 |
+
expect = gguf.Metadata(base_models=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 197 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 198 |
+
self.assertEqual(got, expect)
|
| 199 |
+
|
| 200 |
+
# Base Model spec is given directly
|
| 201 |
+
model_card = {'base_models': [{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}]}
|
| 202 |
+
expect = gguf.Metadata(base_models=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 203 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 204 |
+
self.assertEqual(got, expect)
|
| 205 |
+
|
| 206 |
+
# Dataset spec is inferred from model id
|
| 207 |
+
model_card = {'datasets': 'teknium/OpenHermes-2.5'}
|
| 208 |
+
expect = gguf.Metadata(datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 209 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 210 |
+
self.assertEqual(got, expect)
|
| 211 |
+
|
| 212 |
+
# Dataset spec is only url
|
| 213 |
+
model_card = {'datasets': ['https://huggingface.co/teknium/OpenHermes-2.5']}
|
| 214 |
+
expect = gguf.Metadata(datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 215 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 216 |
+
self.assertEqual(got, expect)
|
| 217 |
+
|
| 218 |
+
# Dataset spec is given directly
|
| 219 |
+
model_card = {'datasets': [{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}]}
|
| 220 |
+
expect = gguf.Metadata(datasets=[{'name': 'OpenHermes 2.5', 'organization': 'Teknium', 'version': '2.5', 'repo_url': 'https://huggingface.co/teknium/OpenHermes-2.5'}])
|
| 221 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card, None, None)
|
| 222 |
+
self.assertEqual(got, expect)
|
| 223 |
+
|
| 224 |
+
def test_apply_metadata_heuristic_from_hf_parameters(self):
|
| 225 |
+
hf_params = {"_name_or_path": "./hermes-2-pro-llama-3-8b-DPO"}
|
| 226 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card=None, hf_params=hf_params, model_path=None)
|
| 227 |
+
expect = gguf.Metadata(name='Hermes 2 Pro Llama 3 8b DPO', finetune='DPO', basename='hermes-2-pro-llama-3', size_label='8B')
|
| 228 |
+
self.assertEqual(got, expect)
|
| 229 |
+
|
| 230 |
+
def test_apply_metadata_heuristic_from_model_dir(self):
|
| 231 |
+
model_dir_path = Path("./hermes-2-pro-llama-3-8b-DPO")
|
| 232 |
+
got = gguf.Metadata.apply_metadata_heuristic(gguf.Metadata(), model_card=None, hf_params=None, model_path=model_dir_path)
|
| 233 |
+
expect = gguf.Metadata(name='Hermes 2 Pro Llama 3 8b DPO', finetune='DPO', basename='hermes-2-pro-llama-3', size_label='8B')
|
| 234 |
+
self.assertEqual(got, expect)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if __name__ == "__main__":
|
| 238 |
+
unittest.main()
|
gguf-py/tests/test_quants.py
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
|
| 3 |
+
# Test gguf.quants so that it exactly matches the C implementation of the (de)quantization
|
| 4 |
+
|
| 5 |
+
# NOTE: this is kind of a mess, but at least it worked for initially testing the Python implementations.
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
from math import prod
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
import ctypes
|
| 15 |
+
import logging
|
| 16 |
+
import numpy as np
|
| 17 |
+
|
| 18 |
+
# Necessary to load the local gguf package
|
| 19 |
+
if "NO_LOCAL_GGUF" not in os.environ and (Path(__file__).parent.parent.parent / 'gguf-py').exists():
|
| 20 |
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 21 |
+
|
| 22 |
+
import gguf
|
| 23 |
+
from gguf.constants import GGMLQuantizationType
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
logger = logging.getLogger("test-quants")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
c_float_p = ctypes.POINTER(ctypes.c_float)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class ggml_init_params(ctypes.Structure):
|
| 33 |
+
_fields_ = [
|
| 34 |
+
("mem_size", ctypes.c_size_t),
|
| 35 |
+
("mem_buffer", ctypes.c_void_p),
|
| 36 |
+
("no_alloc", ctypes.c_bool),
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class GGMLQuants:
|
| 41 |
+
libggml: ctypes.CDLL
|
| 42 |
+
|
| 43 |
+
def __init__(self, libggml: Path):
|
| 44 |
+
self.libggml = ctypes.CDLL(str(libggml))
|
| 45 |
+
self.libggml.ggml_quantize_chunk.restype = ctypes.c_size_t
|
| 46 |
+
# enum ggml_type type,
|
| 47 |
+
# const float * src,
|
| 48 |
+
# void * dst,
|
| 49 |
+
# int64_t start,
|
| 50 |
+
# int64_t nrows,
|
| 51 |
+
# int64_t n_per_row,
|
| 52 |
+
# const float * imatrix) {
|
| 53 |
+
self.libggml.ggml_quantize_chunk.argtypes = (
|
| 54 |
+
ctypes.c_int,
|
| 55 |
+
ctypes.POINTER(ctypes.c_float),
|
| 56 |
+
ctypes.c_void_p,
|
| 57 |
+
ctypes.c_int64,
|
| 58 |
+
ctypes.c_int64,
|
| 59 |
+
ctypes.c_int64,
|
| 60 |
+
ctypes.POINTER(ctypes.c_float),
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
self.libggml.ggml_quantize_requires_imatrix.restype = ctypes.c_bool
|
| 64 |
+
self.libggml.ggml_quantize_requires_imatrix.argtypes = (ctypes.c_int,)
|
| 65 |
+
|
| 66 |
+
for t in (
|
| 67 |
+
"q4_0", "q4_1", "q5_0", "q5_1", "q8_0",
|
| 68 |
+
"q2_K", "q3_K", "q4_K", "q5_K", "q6_K",
|
| 69 |
+
"tq1_0", "tq2_0",
|
| 70 |
+
"mxfp4",
|
| 71 |
+
"nvfp4",
|
| 72 |
+
"iq2_xxs", "iq2_xs", "iq2_s", "iq3_xxs", "iq3_s", "iq1_s", "iq1_m",
|
| 73 |
+
"iq4_nl", "iq4_xs",
|
| 74 |
+
):
|
| 75 |
+
dequant_func: ctypes._NamedFuncPointer = getattr(self.libggml, "dequantize_row_" + t)
|
| 76 |
+
dequant_func.restype = None
|
| 77 |
+
dequant_func.argtypes = (ctypes.c_void_p, ctypes.POINTER(ctypes.c_float), ctypes.c_int64)
|
| 78 |
+
|
| 79 |
+
self.libggml.ggml_fp16_to_fp32_row.restype = None
|
| 80 |
+
self.libggml.ggml_fp16_to_fp32_row.argtypes = (ctypes.POINTER(ctypes.c_uint16), ctypes.POINTER(ctypes.c_float), ctypes.c_int64)
|
| 81 |
+
self.libggml.ggml_bf16_to_fp32_row.restype = None
|
| 82 |
+
self.libggml.ggml_bf16_to_fp32_row.argtypes = (ctypes.POINTER(ctypes.c_uint16), ctypes.POINTER(ctypes.c_float), ctypes.c_int64)
|
| 83 |
+
|
| 84 |
+
self.libggml.ggml_init.argtypes = (ggml_init_params,)
|
| 85 |
+
|
| 86 |
+
self.libggml.ggml_init(ggml_init_params(1 * 1024 * 1024, 0, False))
|
| 87 |
+
|
| 88 |
+
def dequantize(self, tensor: np.ndarray, qtype: GGMLQuantizationType) -> np.ndarray:
|
| 89 |
+
result = np.zeros(gguf.quant_shape_from_byte_shape(tensor.shape, qtype), dtype=np.float32, order="C")
|
| 90 |
+
if qtype == GGMLQuantizationType.F32:
|
| 91 |
+
# no-op
|
| 92 |
+
result = tensor.view(np.float32)
|
| 93 |
+
elif qtype == GGMLQuantizationType.F16:
|
| 94 |
+
self.libggml.ggml_fp16_to_fp32_row(tensor.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16)), result.ctypes.data_as(c_float_p), result.size)
|
| 95 |
+
elif qtype == GGMLQuantizationType.BF16:
|
| 96 |
+
self.libggml.ggml_bf16_to_fp32_row(tensor.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16)), result.ctypes.data_as(c_float_p), result.size)
|
| 97 |
+
else:
|
| 98 |
+
lw_qname = qtype.name.lower()
|
| 99 |
+
if lw_qname[-1] == "k":
|
| 100 |
+
lw_qname = lw_qname[:-1] + "K"
|
| 101 |
+
dequant_func: ctypes._NamedFuncPointer = getattr(self.libggml, "dequantize_row_" + lw_qname)
|
| 102 |
+
dequant_func(tensor.ctypes.data_as(ctypes.c_void_p), result.ctypes.data_as(c_float_p), result.size)
|
| 103 |
+
return result
|
| 104 |
+
|
| 105 |
+
def quantize(self, data: np.ndarray, qtype: GGMLQuantizationType) -> np.ndarray:
|
| 106 |
+
result = np.zeros(gguf.quant_shape_to_byte_shape(data.shape, qtype), dtype=np.uint8, order="C")
|
| 107 |
+
if self.libggml.ggml_quantize_requires_imatrix(qtype.value):
|
| 108 |
+
# TODO: is a column-wise sum of squares appropriate?
|
| 109 |
+
qw = np.sum((data * data).reshape((-1, data.shape[-1])), axis=0).ctypes.data_as(c_float_p)
|
| 110 |
+
else:
|
| 111 |
+
qw = ctypes.cast(0, c_float_p)
|
| 112 |
+
result_size = self.libggml.ggml_quantize_chunk(qtype.value, data.ctypes.data_as(c_float_p), result.ctypes.data_as(ctypes.c_void_p), 0, prod(data.shape[:-1]), data.shape[-1], qw)
|
| 113 |
+
assert result.size == result_size
|
| 114 |
+
return result
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def compare_tensors(t1: np.ndarray, t2: np.ndarray, qtype: GGMLQuantizationType) -> bool:
|
| 118 |
+
same = np.array_equal(t1, t2)
|
| 119 |
+
if same:
|
| 120 |
+
return True
|
| 121 |
+
else:
|
| 122 |
+
block_size, type_size = gguf.GGML_QUANT_SIZES[qtype]
|
| 123 |
+
if t1.dtype == np.float32:
|
| 124 |
+
t1 = t1.reshape((-1, block_size))
|
| 125 |
+
t2 = t2.reshape((-1, block_size))
|
| 126 |
+
else:
|
| 127 |
+
t1 = t1.reshape((-1, type_size))
|
| 128 |
+
t2 = t2.reshape((-1, type_size))
|
| 129 |
+
x = t1.view(np.uint8) ^ t2.view(np.uint8)
|
| 130 |
+
diff_bits = np.count_nonzero(np.unpackbits(x, axis=-1), axis=-1)
|
| 131 |
+
num_bad_blocks = np.count_nonzero(diff_bits, axis=0)
|
| 132 |
+
if num_bad_blocks == 0 and t1.shape == t2.shape:
|
| 133 |
+
logger.debug("Bits are equal, but arrays don't match, likely contains NANs")
|
| 134 |
+
return True
|
| 135 |
+
logger.debug(f"{num_bad_blocks} bad blocks ({100 * num_bad_blocks / x.shape[0]:.6f}%)")
|
| 136 |
+
bad_block_id = np.argmax(diff_bits, axis=0)
|
| 137 |
+
logger.debug(f"Worst block id: {bad_block_id}")
|
| 138 |
+
logger.debug(f"Sample bad block ({diff_bits[bad_block_id]} differing bits):\n{t1[bad_block_id]}\nReference:\n{t2[bad_block_id]}")
|
| 139 |
+
|
| 140 |
+
sum_diff_bits = np.sum(diff_bits)
|
| 141 |
+
logger.debug(f"{sum_diff_bits} bits differ ({100 * sum_diff_bits / (x.size * 8):.6f}%)")
|
| 142 |
+
return False
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def do_test(libggml_path: Path, quick: bool = False, user_type: GGMLQuantizationType | None = None):
|
| 146 |
+
ggml_quants = GGMLQuants(libggml_path)
|
| 147 |
+
|
| 148 |
+
np.set_printoptions(precision=None, threshold=(4 * 256) + 1, formatter={"int": lambda n: "0x%02X" % n})
|
| 149 |
+
|
| 150 |
+
r = np.random.randn(8, 1024, 1024).astype(np.float32, copy=False)
|
| 151 |
+
# test zero blocks
|
| 152 |
+
r[0, 0, :] = 0
|
| 153 |
+
## Maybe test infinities? (can make NANs, not really useful in practice)
|
| 154 |
+
# r[0, 1, 0] = np.inf
|
| 155 |
+
# r[0, 2, 0] = -np.inf
|
| 156 |
+
# r[0, 3, 0] = np.inf
|
| 157 |
+
# r[0, 3, 1] = -np.inf
|
| 158 |
+
|
| 159 |
+
for qtype in ((GGMLQuantizationType.F16, *gguf.quants._type_traits.keys()) if user_type is None else (user_type,)):
|
| 160 |
+
has_dequantize = False
|
| 161 |
+
has_quantize = False
|
| 162 |
+
|
| 163 |
+
try:
|
| 164 |
+
gguf.dequantize(np.zeros((gguf.GGML_QUANT_SIZES[qtype][1]), dtype=np.uint8), qtype)
|
| 165 |
+
has_dequantize = True
|
| 166 |
+
except (NotImplementedError, AssertionError) as e:
|
| 167 |
+
if isinstance(e, AssertionError):
|
| 168 |
+
logger.error(f"Error with {qtype.name}: {e}")
|
| 169 |
+
raise e
|
| 170 |
+
try:
|
| 171 |
+
gguf.quantize(np.zeros((gguf.GGML_QUANT_SIZES[qtype][0]), dtype=np.float32), qtype)
|
| 172 |
+
has_quantize = True
|
| 173 |
+
except (NotImplementedError, AssertionError) as e:
|
| 174 |
+
if isinstance(e, AssertionError):
|
| 175 |
+
logger.error(f"Error with {qtype.name}: {e}")
|
| 176 |
+
raise e
|
| 177 |
+
|
| 178 |
+
if not has_dequantize and not has_quantize:
|
| 179 |
+
continue
|
| 180 |
+
|
| 181 |
+
logger.info(f"Testing {qtype.name}")
|
| 182 |
+
|
| 183 |
+
rc = r.copy(order="C")
|
| 184 |
+
|
| 185 |
+
pyq = None
|
| 186 |
+
ggq = None
|
| 187 |
+
|
| 188 |
+
if has_quantize:
|
| 189 |
+
logger.debug(f"Quantizing to {qtype.name} with Python")
|
| 190 |
+
pyq = gguf.quants.quantize(rc, qtype)
|
| 191 |
+
|
| 192 |
+
logger.debug(f"Quantizing to {qtype.name} with C")
|
| 193 |
+
ggq = ggml_quants.quantize(rc, qtype)
|
| 194 |
+
|
| 195 |
+
if qtype == GGMLQuantizationType.F16:
|
| 196 |
+
pyq = pyq.view(np.uint8)
|
| 197 |
+
quant_equal = compare_tensors(pyq, ggq, qtype)
|
| 198 |
+
|
| 199 |
+
if not quant_equal:
|
| 200 |
+
logger.error(f"Quantization to {qtype.name} does not match ❌")
|
| 201 |
+
else:
|
| 202 |
+
logger.info(f"Quantization to {qtype.name} matches exactly ✅")
|
| 203 |
+
|
| 204 |
+
if has_dequantize:
|
| 205 |
+
if ggq is None and not quick:
|
| 206 |
+
logger.debug(f"Quantizing to {qtype.name} with C")
|
| 207 |
+
ggq = ggml_quants.quantize(rc, qtype)
|
| 208 |
+
|
| 209 |
+
if ggq is not None:
|
| 210 |
+
logger.debug(f"Dequantizing from {qtype.name} with Python")
|
| 211 |
+
pydq = gguf.quants.dequantize(ggq, qtype)
|
| 212 |
+
logger.debug(f"Dequantizing from {qtype.name} with C")
|
| 213 |
+
ggdq = ggml_quants.dequantize(ggq, qtype)
|
| 214 |
+
|
| 215 |
+
dequant_equal = compare_tensors(pydq, ggdq, qtype)
|
| 216 |
+
|
| 217 |
+
if not dequant_equal:
|
| 218 |
+
logger.error(f"Dequantization from {qtype.name} does not match ❌")
|
| 219 |
+
else:
|
| 220 |
+
logger.info(f"Dequantization from {qtype.name} matches exactly ✅")
|
| 221 |
+
|
| 222 |
+
rq_shape = gguf.quants.quant_shape_to_byte_shape((8, 1024, 1024 // 2), qtype)
|
| 223 |
+
rq = np.random.random(rq_shape).astype(np.float16).view(np.uint8)
|
| 224 |
+
|
| 225 |
+
logger.debug(f"Dequantizing random f16 data as {qtype.name} with Python")
|
| 226 |
+
pydq = gguf.quants.dequantize(rq, qtype)
|
| 227 |
+
logger.debug(f"Dequantizing random f16 data as {qtype.name} with C")
|
| 228 |
+
ggdq = ggml_quants.dequantize(rq, qtype)
|
| 229 |
+
|
| 230 |
+
dequant_equal = compare_tensors(pydq, ggdq, qtype)
|
| 231 |
+
|
| 232 |
+
if not dequant_equal:
|
| 233 |
+
logger.error(f"Dequantization from random f16 data as {qtype.name} does not match ❌")
|
| 234 |
+
else:
|
| 235 |
+
logger.info(f"Dequantization from random f16 data as {qtype.name} matches exactly ✅")
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
if __name__ == "__main__":
|
| 239 |
+
parser = argparse.ArgumentParser(description="Test Python (de)quantization against the reference C implementation")
|
| 240 |
+
parser.add_argument("--libggml", type=Path, default=Path(__file__).parent.parent.parent / "build" / "bin" / "libggml.so", help="The path to libggml.so")
|
| 241 |
+
parser.add_argument("--quick", action="store_true", help="Don't quantize with C when it's not strictly necessary")
|
| 242 |
+
parser.add_argument("--type", type=str, help="The quant type to test (all by default)")
|
| 243 |
+
|
| 244 |
+
args = parser.parse_args()
|
| 245 |
+
|
| 246 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 247 |
+
|
| 248 |
+
do_test(args.libggml, args.quick, GGMLQuantizationType[args.type.upper()] if args.type is not None else None)
|
grammars/README.md
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GBNF Guide
|
| 2 |
+
|
| 3 |
+
GBNF (GGML BNF) is a format for defining [formal grammars](https://en.wikipedia.org/wiki/Formal_grammar) to constrain model outputs in `llama.cpp`. For example, you can use it to force the model to generate valid JSON, or speak only in emojis. GBNF grammars are supported in various ways in `tools/cli`, `tools/completion` and `tools/server`.
|
| 4 |
+
|
| 5 |
+
## Background
|
| 6 |
+
|
| 7 |
+
[Backus-Naur Form (BNF)](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) is a notation for describing the syntax of formal languages like programming languages, file formats, and protocols. GBNF is an extension of BNF that primarily adds a few modern regex-like features.
|
| 8 |
+
|
| 9 |
+
## Basics
|
| 10 |
+
|
| 11 |
+
In GBNF, we define *production rules* that specify how a *non-terminal* (rule name) can be replaced with sequences of *terminals* (characters, specifically Unicode [code points](https://en.wikipedia.org/wiki/Code_point)) and other non-terminals. The basic format of a production rule is `nonterminal ::= sequence...`.
|
| 12 |
+
|
| 13 |
+
## Example
|
| 14 |
+
|
| 15 |
+
Before going deeper, let's look at some of the features demonstrated in `grammars/chess.gbnf`, a small chess notation grammar:
|
| 16 |
+
```
|
| 17 |
+
# `root` specifies the pattern for the overall output
|
| 18 |
+
root ::= (
|
| 19 |
+
# it must start with the characters "1. " followed by a sequence
|
| 20 |
+
# of characters that match the `move` rule, followed by a space, followed
|
| 21 |
+
# by another move, and then a newline
|
| 22 |
+
"1. " move " " move "\n"
|
| 23 |
+
|
| 24 |
+
# it's followed by one or more subsequent moves, numbered with one or two digits
|
| 25 |
+
([1-9] [0-9]? ". " move " " move "\n")+
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# `move` is an abstract representation, which can be a pawn, nonpawn, or castle.
|
| 29 |
+
# The `[+#]?` denotes the possibility of checking or mate signs after moves
|
| 30 |
+
move ::= (pawn | nonpawn | castle) [+#]?
|
| 31 |
+
|
| 32 |
+
pawn ::= ...
|
| 33 |
+
nonpawn ::= ...
|
| 34 |
+
castle ::= ...
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
## Non-Terminals and Terminals
|
| 38 |
+
|
| 39 |
+
Non-terminal symbols (rule names) stand for a pattern of terminals and other non-terminals. They are required to be a dashed lowercase word, like `move`, `castle`, or `check-mate`.
|
| 40 |
+
|
| 41 |
+
Terminals are actual characters ([code points](https://en.wikipedia.org/wiki/Code_point)). They can be specified as a sequence like `"1"` or `"O-O"` or as ranges like `[1-9]` or `[NBKQR]`.
|
| 42 |
+
|
| 43 |
+
## Characters and character ranges
|
| 44 |
+
|
| 45 |
+
Terminals support the full range of Unicode. Unicode characters can be specified directly in the grammar, for example `hiragana ::= [ぁ-ゟ]`, or with escapes: 8-bit (`\xXX`), 16-bit (`\uXXXX`) or 32-bit (`\UXXXXXXXX`).
|
| 46 |
+
|
| 47 |
+
Character ranges can be negated with `^`:
|
| 48 |
+
```
|
| 49 |
+
single-line ::= [^\n]+ "\n"
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## Sequences and Alternatives
|
| 53 |
+
|
| 54 |
+
The order of symbols in a sequence matters. For example, in `"1. " move " " move "\n"`, the `"1. "` must come before the first `move`, etc.
|
| 55 |
+
|
| 56 |
+
Alternatives, denoted by `|`, give different sequences that are acceptable. For example, in `move ::= pawn | nonpawn | castle`, `move` can be a `pawn` move, a `nonpawn` move, or a `castle`.
|
| 57 |
+
|
| 58 |
+
Parentheses `()` can be used to group sequences, which allows for embedding alternatives in a larger rule or applying repetition and optional symbols (below) to a sequence.
|
| 59 |
+
|
| 60 |
+
## Repetition and Optional Symbols
|
| 61 |
+
|
| 62 |
+
- `*` after a symbol or sequence means that it can be repeated zero or more times (equivalent to `{0,}`).
|
| 63 |
+
- `+` denotes that the symbol or sequence should appear one or more times (equivalent to `{1,}`).
|
| 64 |
+
- `?` makes the preceding symbol or sequence optional (equivalent to `{0,1}`).
|
| 65 |
+
- `{m}` repeats the precedent symbol or sequence exactly `m` times
|
| 66 |
+
- `{m,}` repeats the precedent symbol or sequence at least `m` times
|
| 67 |
+
- `{m,n}` repeats the precedent symbol or sequence at between `m` and `n` times (included)
|
| 68 |
+
- `{0,n}` repeats the precedent symbol or sequence at most `n` times (included)
|
| 69 |
+
|
| 70 |
+
## Tokens
|
| 71 |
+
|
| 72 |
+
Tokens allow grammars to match specific tokenizer tokens rather than character sequences. This is useful for constraining outputs based on special tokens (like `<think>` or `</think>`).
|
| 73 |
+
|
| 74 |
+
Tokens can be specified in two ways:
|
| 75 |
+
|
| 76 |
+
1. **Token ID**: Use angle brackets with the token ID in square brackets: `<[token-id]>`. For example, `<[1000]>` matches the token with ID 1000.
|
| 77 |
+
|
| 78 |
+
2. **Token string**: Use angle brackets with the token text directly: `<token>`. For example, `<think>` will match the token whose text is exactly `<think>`. This only works if the string tokenizes to exactly one token in the vocabulary, otherwise the grammar will fail to parse.
|
| 79 |
+
|
| 80 |
+
You can negate token matches using the `!` prefix: `!<[1000]>` or `!<think>` matches any token *except* the specified one.
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
# Match a thinking block: <think>...</think>
|
| 84 |
+
# Using token strings (requires these to be single tokens in the vocab)
|
| 85 |
+
root ::= <think> thinking </think> .*
|
| 86 |
+
thinking ::= !</think>*
|
| 87 |
+
|
| 88 |
+
# Equivalent grammar using explicit token IDs
|
| 89 |
+
# Assumes token 1000 = <think>, token 1001 = </think>
|
| 90 |
+
root ::= <[1000]> thinking <[1001]> .*
|
| 91 |
+
thinking ::= !<[1001]>*
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## Comments and newlines
|
| 95 |
+
|
| 96 |
+
Comments can be specified with `#`:
|
| 97 |
+
```
|
| 98 |
+
# defines optional whitespace
|
| 99 |
+
ws ::= [ \t\n]+
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
Newlines are allowed between rules and between symbols or sequences nested inside parentheses. Additionally, a newline after an alternate marker `|` will continue the current rule, even outside of parentheses.
|
| 103 |
+
|
| 104 |
+
## The root rule
|
| 105 |
+
|
| 106 |
+
In a full grammar, the `root` rule always defines the starting point of the grammar. In other words, it specifies what the entire output must match.
|
| 107 |
+
|
| 108 |
+
```
|
| 109 |
+
# a grammar for lists
|
| 110 |
+
root ::= ("- " item)+
|
| 111 |
+
item ::= [^\n]+ "\n"
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
## Next steps
|
| 115 |
+
|
| 116 |
+
This guide provides a brief overview. Check out the GBNF files in this directory (`grammars/`) for examples of full grammars. You can try them out with:
|
| 117 |
+
```
|
| 118 |
+
./llama-cli -m <model> --grammar-file grammars/some-grammar.gbnf -p 'Some prompt'
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
`llama.cpp` can also convert JSON schemas to grammars either ahead of time or at each request, see below.
|
| 122 |
+
|
| 123 |
+
## Troubleshooting
|
| 124 |
+
|
| 125 |
+
Grammars currently have performance gotchas (see https://github.com/ggml-org/llama.cpp/issues/4218).
|
| 126 |
+
|
| 127 |
+
### Efficient optional repetitions
|
| 128 |
+
|
| 129 |
+
A common pattern is to allow repetitions of a pattern `x` up to N times.
|
| 130 |
+
|
| 131 |
+
While semantically correct, the syntax `x? x? x?.... x?` (with N repetitions) may result in extremely slow sampling. Instead, you can write `x{0,N}` (or `(x (x (x ... (x)?...)?)?)?` w/ N-deep nesting in earlier llama.cpp versions).
|
| 132 |
+
|
| 133 |
+
## Using GBNF grammars
|
| 134 |
+
|
| 135 |
+
You can use GBNF grammars:
|
| 136 |
+
|
| 137 |
+
- In [llama-server](../tools/server)'s completion endpoints, passed as the `grammar` body field
|
| 138 |
+
- In [llama-cli](../tools/cli) and [llama-completion](../tools/completion), passed as the `--grammar` & `--grammar-file` flags
|
| 139 |
+
- With [test-gbnf-validator](../tests/test-gbnf-validator.cpp), to test them against strings.
|
| 140 |
+
|
| 141 |
+
## JSON Schemas → GBNF
|
| 142 |
+
|
| 143 |
+
`llama.cpp` supports converting a subset of https://json-schema.org/ to GBNF grammars:
|
| 144 |
+
|
| 145 |
+
- In [llama-server](../tools/server):
|
| 146 |
+
- For any completion endpoints, passed as the `json_schema` body field
|
| 147 |
+
- For the `/chat/completions` endpoint, passed inside the `response_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}` or `{ type: "json_schema", json_schema: {"schema": ...} }`)
|
| 148 |
+
- In [llama-cli](../tools/cli) and [llama-completion](../tools/completion), passed as the `--json` / `-j` flag
|
| 149 |
+
|
| 150 |
+
> [!NOTE]
|
| 151 |
+
> The JSON schema is only used to constrain the model output and is not injected into the prompt. The model has no visibility into the schema, so if you want it to understand the expected structure, describe it explicitly in your prompt. This does not apply to tool calling, where schemas are injected into the prompt.
|
| 152 |
+
|
| 153 |
+
Take a look at [tests](../tests/test-json-schema-to-grammar.cpp) to see which features are likely supported (you'll also find usage examples in https://github.com/ggml-org/llama.cpp/pull/5978, https://github.com/ggml-org/llama.cpp/pull/6659 & https://github.com/ggml-org/llama.cpp/pull/6555).
|
| 154 |
+
|
| 155 |
+
```bash
|
| 156 |
+
llama-cli \
|
| 157 |
+
-hfr bartowski/Phi-3-medium-128k-instruct-GGUF \
|
| 158 |
+
-hff Phi-3-medium-128k-instruct-Q8_0.gguf \
|
| 159 |
+
-j '{
|
| 160 |
+
"type": "array",
|
| 161 |
+
"items": {
|
| 162 |
+
"type": "object",
|
| 163 |
+
"properties": {
|
| 164 |
+
"name": {
|
| 165 |
+
"type": "string",
|
| 166 |
+
"minLength": 1,
|
| 167 |
+
"maxLength": 100
|
| 168 |
+
},
|
| 169 |
+
"age": {
|
| 170 |
+
"type": "integer",
|
| 171 |
+
"minimum": 0,
|
| 172 |
+
"maximum": 150
|
| 173 |
+
}
|
| 174 |
+
},
|
| 175 |
+
"required": ["name", "age"],
|
| 176 |
+
"additionalProperties": false
|
| 177 |
+
},
|
| 178 |
+
"minItems": 10,
|
| 179 |
+
"maxItems": 100
|
| 180 |
+
}' \
|
| 181 |
+
-p 'Generate a {name, age}[] JSON array with famous actors of all ages.'
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
<details>
|
| 185 |
+
|
| 186 |
+
<summary>Show grammar</summary>
|
| 187 |
+
|
| 188 |
+
The schema above converts to:
|
| 189 |
+
|
| 190 |
+
```
|
| 191 |
+
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
| 192 |
+
item ::= "{" space item-name-kv "," space item-age-kv "}" space
|
| 193 |
+
item-age ::= ([0-9] | ([1-8] [0-9] | [9] [0-9]) | "1" ([0-4] [0-9] | [5] "0")) space
|
| 194 |
+
item-age-kv ::= "\"age\"" space ":" space item-age
|
| 195 |
+
item-name ::= "\"" char{1,100} "\"" space
|
| 196 |
+
item-name-kv ::= "\"name\"" space ":" space item-name
|
| 197 |
+
root ::= "[" space item ("," space item){9,99} "]" space
|
| 198 |
+
space ::= | " " | "\n" [ \t]{0,20}
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
</details>
|
| 202 |
+
|
| 203 |
+
Here is also a list of known limitations (contributions welcome):
|
| 204 |
+
|
| 205 |
+
- `additionalProperties` defaults to `false` (produces faster grammars + reduces hallucinations).
|
| 206 |
+
- `"additionalProperties": true` may produce keys that contain unescaped newlines.
|
| 207 |
+
- Unsupported features are skipped silently. It is currently advised to use the command-line Python converter (see above) to see any warnings, and to inspect the resulting grammar / test it w/ [llama-gbnf-validator](../examples/gbnf-validator/gbnf-validator.cpp).
|
| 208 |
+
- Can't mix `properties` w/ `anyOf` / `oneOf` in the same type (https://github.com/ggml-org/llama.cpp/issues/7703)
|
| 209 |
+
- [prefixItems](https://json-schema.org/draft/2020-12/json-schema-core#name-prefixitems) is broken (but [items](https://json-schema.org/draft/2020-12/json-schema-core#name-items) works)
|
| 210 |
+
- `minimum`, `exclusiveMinimum`, `maximum`, `exclusiveMaximum`: only supported for `"type": "integer"` for now, not `number`
|
| 211 |
+
- Nested `$ref`s are broken (https://github.com/ggml-org/llama.cpp/issues/8073)
|
| 212 |
+
- [pattern](https://json-schema.org/draft/2020-12/json-schema-validation#name-pattern)s must start with `^` and end with `$`
|
| 213 |
+
- Remote `$ref`s not supported in the C++ version (Python & JavaScript versions fetch https refs)
|
| 214 |
+
- `string` [formats](https://json-schema.org/draft/2020-12/json-schema-validation#name-defined-formats) lack `uri`, `email`
|
| 215 |
+
- No [`patternProperties`](https://json-schema.org/draft/2020-12/json-schema-core#name-patternproperties)
|
| 216 |
+
|
| 217 |
+
And a non-exhaustive list of other unsupported features that are unlikely to be implemented (hard and/or too slow to support w/ stateless grammars):
|
| 218 |
+
|
| 219 |
+
- [`uniqueItems`](https://json-schema.org/draft/2020-12/json-schema-validation#name-uniqueitems)
|
| 220 |
+
- [`contains`](https://json-schema.org/draft/2020-12/json-schema-core#name-contains) / `minContains`
|
| 221 |
+
- `$anchor` (cf. [dereferencing](https://json-schema.org/draft/2020-12/json-schema-core#name-dereferencing))
|
| 222 |
+
- [`not`](https://json-schema.org/draft/2020-12/json-schema-core#name-not)
|
| 223 |
+
- [Conditionals](https://json-schema.org/draft/2020-12/json-schema-core#name-keywords-for-applying-subsche) `if` / `then` / `else` / `dependentSchemas`
|
| 224 |
+
|
| 225 |
+
### A word about additionalProperties
|
| 226 |
+
|
| 227 |
+
> [!WARNING]
|
| 228 |
+
> The JSON schemas spec states `object`s accept [additional properties](https://json-schema.org/understanding-json-schema/reference/object#additionalproperties) by default.
|
| 229 |
+
> Since this is slow and seems prone to hallucinations, we default to no additional properties.
|
| 230 |
+
> You can set `"additionalProperties": true` in the schema of any object to explicitly allow additional properties.
|
| 231 |
+
|
| 232 |
+
If you're using [Pydantic](https://pydantic.dev/) to generate schemas, you can enable additional properties with the `extra` config on each model class:
|
| 233 |
+
|
| 234 |
+
```python
|
| 235 |
+
# pip install pydantic
|
| 236 |
+
import json
|
| 237 |
+
from typing import Annotated, List
|
| 238 |
+
from pydantic import BaseModel, Extra, Field
|
| 239 |
+
class QAPair(BaseModel):
|
| 240 |
+
class Config:
|
| 241 |
+
extra = 'allow' # triggers additionalProperties: true in the JSON schema
|
| 242 |
+
question: str
|
| 243 |
+
concise_answer: str
|
| 244 |
+
justification: str
|
| 245 |
+
|
| 246 |
+
class Summary(BaseModel):
|
| 247 |
+
class Config:
|
| 248 |
+
extra = 'allow'
|
| 249 |
+
key_facts: List[Annotated[str, Field(pattern='- .{5,}')]]
|
| 250 |
+
question_answers: List[Annotated[List[QAPair], Field(min_items=5)]]
|
| 251 |
+
|
| 252 |
+
print(json.dumps(Summary.model_json_schema(), indent=2))
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
<details>
|
| 256 |
+
<summary>Show JSON schema & grammar</summary>
|
| 257 |
+
|
| 258 |
+
```json
|
| 259 |
+
{
|
| 260 |
+
"$defs": {
|
| 261 |
+
"QAPair": {
|
| 262 |
+
"additionalProperties": true,
|
| 263 |
+
"properties": {
|
| 264 |
+
"question": {
|
| 265 |
+
"title": "Question",
|
| 266 |
+
"type": "string"
|
| 267 |
+
},
|
| 268 |
+
"concise_answer": {
|
| 269 |
+
"title": "Concise Answer",
|
| 270 |
+
"type": "string"
|
| 271 |
+
},
|
| 272 |
+
"justification": {
|
| 273 |
+
"title": "Justification",
|
| 274 |
+
"type": "string"
|
| 275 |
+
}
|
| 276 |
+
},
|
| 277 |
+
"required": [
|
| 278 |
+
"question",
|
| 279 |
+
"concise_answer",
|
| 280 |
+
"justification"
|
| 281 |
+
],
|
| 282 |
+
"title": "QAPair",
|
| 283 |
+
"type": "object"
|
| 284 |
+
}
|
| 285 |
+
},
|
| 286 |
+
"additionalProperties": true,
|
| 287 |
+
"properties": {
|
| 288 |
+
"key_facts": {
|
| 289 |
+
"items": {
|
| 290 |
+
"pattern": "^- .{5,}$",
|
| 291 |
+
"type": "string"
|
| 292 |
+
},
|
| 293 |
+
"title": "Key Facts",
|
| 294 |
+
"type": "array"
|
| 295 |
+
},
|
| 296 |
+
"question_answers": {
|
| 297 |
+
"items": {
|
| 298 |
+
"items": {
|
| 299 |
+
"$ref": "#/$defs/QAPair"
|
| 300 |
+
},
|
| 301 |
+
"minItems": 5,
|
| 302 |
+
"type": "array"
|
| 303 |
+
},
|
| 304 |
+
"title": "Question Answers",
|
| 305 |
+
"type": "array"
|
| 306 |
+
}
|
| 307 |
+
},
|
| 308 |
+
"required": [
|
| 309 |
+
"key_facts",
|
| 310 |
+
"question_answers"
|
| 311 |
+
],
|
| 312 |
+
"title": "Summary",
|
| 313 |
+
"type": "object"
|
| 314 |
+
}
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
```
|
| 318 |
+
QAPair ::= "{" space QAPair-question-kv "," space QAPair-concise-answer-kv "," space QAPair-justification-kv ( "," space ( QAPair-additional-kv ( "," space QAPair-additional-kv )* ) )? "}" space
|
| 319 |
+
QAPair-additional-k ::= ["] ( [c] ([o] ([n] ([c] ([i] ([s] ([e] ([_] ([a] ([n] ([s] ([w] ([e] ([r] char+ | [^"r] char*) | [^"e] char*) | [^"w] char*) | [^"s] char*) | [^"n] char*) | [^"a] char*) | [^"_] char*) | [^"e] char*) | [^"s] char*) | [^"i] char*) | [^"c] char*) | [^"n] char*) | [^"o] char*) | [j] ([u] ([s] ([t] ([i] ([f] ([i] ([c] ([a] ([t] ([i] ([o] ([n] char+ | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"a] char*) | [^"c] char*) | [^"i] char*) | [^"f] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"u] char*) | [q] ([u] ([e] ([s] ([t] ([i] ([o] ([n] char+ | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"e] char*) | [^"u] char*) | [^"cjq] char* )? ["] space
|
| 320 |
+
QAPair-additional-kv ::= QAPair-additional-k ":" space value
|
| 321 |
+
QAPair-concise-answer-kv ::= "\"concise_answer\"" space ":" space string
|
| 322 |
+
QAPair-justification-kv ::= "\"justification\"" space ":" space string
|
| 323 |
+
QAPair-question-kv ::= "\"question\"" space ":" space string
|
| 324 |
+
additional-k ::= ["] ( [k] ([e] ([y] ([_] ([f] ([a] ([c] ([t] ([s] char+ | [^"s] char*) | [^"t] char*) | [^"c] char*) | [^"a] char*) | [^"f] char*) | [^"_] char*) | [^"y] char*) | [^"e] char*) | [q] ([u] ([e] ([s] ([t] ([i] ([o] ([n] ([_] ([a] ([n] ([s] ([w] ([e] ([r] ([s] char+ | [^"s] char*) | [^"r] char*) | [^"e] char*) | [^"w] char*) | [^"s] char*) | [^"n] char*) | [^"a] char*) | [^"_] char*) | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"e] char*) | [^"u] char*) | [^"kq] char* )? ["] space
|
| 325 |
+
additional-kv ::= additional-k ":" space value
|
| 326 |
+
array ::= "[" space ( value ("," space value)* )? "]" space
|
| 327 |
+
boolean ::= ("true" | "false") space
|
| 328 |
+
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
| 329 |
+
decimal-part ::= [0-9]{1,16}
|
| 330 |
+
dot ::= [^\x0A\x0D]
|
| 331 |
+
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
| 332 |
+
key-facts ::= "[" space (key-facts-item ("," space key-facts-item)*)? "]" space
|
| 333 |
+
key-facts-item ::= "\"" "- " key-facts-item-1{5,} "\"" space
|
| 334 |
+
key-facts-item-1 ::= dot
|
| 335 |
+
key-facts-kv ::= "\"key_facts\"" space ":" space key-facts
|
| 336 |
+
null ::= "null" space
|
| 337 |
+
number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
|
| 338 |
+
object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
|
| 339 |
+
question-answers ::= "[" space (question-answers-item ("," space question-answers-item)*)? "]" space
|
| 340 |
+
question-answers-item ::= "[" space question-answers-item-item ("," space question-answers-item-item){4,} "]" space
|
| 341 |
+
question-answers-item-item ::= QAPair
|
| 342 |
+
question-answers-kv ::= "\"question_answers\"" space ":" space question-answers
|
| 343 |
+
root ::= "{" space key-facts-kv "," space question-answers-kv ( "," space ( additional-kv ( "," space additional-kv )* ) )? "}" space
|
| 344 |
+
space ::= | " " | "\n" [ \t]{0,20}
|
| 345 |
+
string ::= "\"" char* "\"" space
|
| 346 |
+
value ::= object | array | string | number | boolean | null
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
</details>
|
| 350 |
+
|
| 351 |
+
If you're using [Zod](https://zod.dev/), you can make your objects to explicitly allow extra properties w/ `nonstrict()` / `passthrough()` (or explicitly no extra props w/ `z.object(...).strict()` or `z.strictObject(...)`) but note that [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema) currently always sets `"additionalProperties": false` anyway.
|
| 352 |
+
|
| 353 |
+
```js
|
| 354 |
+
import { z } from 'zod';
|
| 355 |
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
| 356 |
+
|
| 357 |
+
const Foo = z.object({
|
| 358 |
+
age: z.number().positive(),
|
| 359 |
+
email: z.string().email(),
|
| 360 |
+
}).strict();
|
| 361 |
+
|
| 362 |
+
console.log(zodToJsonSchema(Foo));
|
| 363 |
+
```
|
| 364 |
+
|
| 365 |
+
<details>
|
| 366 |
+
<summary>Show JSON schema & grammar</summary>
|
| 367 |
+
|
| 368 |
+
```json
|
| 369 |
+
{
|
| 370 |
+
"type": "object",
|
| 371 |
+
"properties": {
|
| 372 |
+
"age": {
|
| 373 |
+
"type": "number",
|
| 374 |
+
"exclusiveMinimum": 0
|
| 375 |
+
},
|
| 376 |
+
"email": {
|
| 377 |
+
"type": "string",
|
| 378 |
+
"format": "email"
|
| 379 |
+
}
|
| 380 |
+
},
|
| 381 |
+
"required": [
|
| 382 |
+
"age",
|
| 383 |
+
"email"
|
| 384 |
+
],
|
| 385 |
+
"additionalProperties": false,
|
| 386 |
+
"$schema": "http://json-schema.org/draft-07/schema#"
|
| 387 |
+
}
|
| 388 |
+
```
|
| 389 |
+
|
| 390 |
+
```
|
| 391 |
+
age-kv ::= "\"age\"" space ":" space number
|
| 392 |
+
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
| 393 |
+
decimal-part ::= [0-9]{1,16}
|
| 394 |
+
email-kv ::= "\"email\"" space ":" space string
|
| 395 |
+
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
| 396 |
+
number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
|
| 397 |
+
root ::= "{" space age-kv "," space email-kv "}" space
|
| 398 |
+
space ::= | " " | "\n" [ \t]{0,20}
|
| 399 |
+
string ::= "\"" char* "\"" space
|
| 400 |
+
```
|
| 401 |
+
|
| 402 |
+
</details>
|
grammars/arithmetic.gbnf
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root ::= (expr "=" ws term "\n")+
|
| 2 |
+
expr ::= term ([-+*/] term)*
|
| 3 |
+
term ::= ident | num | "(" ws expr ")" ws
|
| 4 |
+
ident ::= [a-z] [a-z0-9_]* ws
|
| 5 |
+
num ::= [0-9]+ ws
|
| 6 |
+
ws ::= [ \t\n]*
|
grammars/c.gbnf
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root ::= (declaration)*
|
| 2 |
+
|
| 3 |
+
declaration ::= dataType identifier "(" parameter? ")" "{" statement* "}"
|
| 4 |
+
|
| 5 |
+
dataType ::= "int" ws | "float" ws | "char" ws
|
| 6 |
+
identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
|
| 7 |
+
|
| 8 |
+
parameter ::= dataType identifier
|
| 9 |
+
|
| 10 |
+
statement ::=
|
| 11 |
+
( dataType identifier ws "=" ws expression ";" ) |
|
| 12 |
+
( identifier ws "=" ws expression ";" ) |
|
| 13 |
+
( identifier ws "(" argList? ")" ";" ) |
|
| 14 |
+
( "return" ws expression ";" ) |
|
| 15 |
+
( "while" "(" condition ")" "{" statement* "}" ) |
|
| 16 |
+
( "for" "(" forInit ";" ws condition ";" ws forUpdate ")" "{" statement* "}" ) |
|
| 17 |
+
( "if" "(" condition ")" "{" statement* "}" ("else" "{" statement* "}")? ) |
|
| 18 |
+
( singleLineComment ) |
|
| 19 |
+
( multiLineComment )
|
| 20 |
+
|
| 21 |
+
forInit ::= dataType identifier ws "=" ws expression | identifier ws "=" ws expression
|
| 22 |
+
forUpdate ::= identifier ws "=" ws expression
|
| 23 |
+
|
| 24 |
+
condition ::= expression relationOperator expression
|
| 25 |
+
relationOperator ::= ("<=" | "<" | "==" | "!=" | ">=" | ">")
|
| 26 |
+
|
| 27 |
+
expression ::= term (("+" | "-") term)*
|
| 28 |
+
term ::= factor(("*" | "/") factor)*
|
| 29 |
+
|
| 30 |
+
factor ::= identifier | number | unaryTerm | funcCall | parenExpression
|
| 31 |
+
unaryTerm ::= "-" factor
|
| 32 |
+
funcCall ::= identifier "(" argList? ")"
|
| 33 |
+
parenExpression ::= "(" ws expression ws ")"
|
| 34 |
+
|
| 35 |
+
argList ::= expression ("," ws expression)*
|
| 36 |
+
|
| 37 |
+
number ::= [0-9]+
|
| 38 |
+
|
| 39 |
+
singleLineComment ::= "//" [^\n]* "\n"
|
| 40 |
+
multiLineComment ::= "/*" ( [^*] | ("*" [^/]) )* "*/"
|
| 41 |
+
|
| 42 |
+
ws ::= ([ \t\n]+)
|
grammars/chess.gbnf
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Specifies chess moves as a list in algebraic notation, using PGN conventions
|
| 2 |
+
|
| 3 |
+
# Force first move to "1. ", then any 1-2 digit number after, relying on model to follow the pattern
|
| 4 |
+
root ::= "1. " move " " move "\n" ([1-9] [0-9]? ". " move " " move "\n")+
|
| 5 |
+
move ::= (pawn | nonpawn | castle) [+#]?
|
| 6 |
+
|
| 7 |
+
# piece type, optional file/rank, optional capture, dest file & rank
|
| 8 |
+
nonpawn ::= [NBKQR] [a-h]? [1-8]? "x"? [a-h] [1-8]
|
| 9 |
+
|
| 10 |
+
# optional file & capture, dest file & rank, optional promotion
|
| 11 |
+
pawn ::= ([a-h] "x")? [a-h] [1-8] ("=" [NBKQR])?
|
| 12 |
+
|
| 13 |
+
castle ::= "O-O" "-O"?
|
grammars/english.gbnf
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# note: this might be incomplete, mostly an example
|
| 2 |
+
root ::= en-char+ ([ \t\n] en-char+)*
|
| 3 |
+
en-char ::= letter | digit | punctuation
|
| 4 |
+
letter ::= [a-zA-Z]
|
| 5 |
+
digit ::= [0-9]
|
| 6 |
+
punctuation ::= [!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]
|
grammars/japanese.gbnf
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# A probably incorrect grammar for Japanese
|
| 2 |
+
root ::= jp-char+ ([ \t\n] jp-char+)*
|
| 3 |
+
jp-char ::= hiragana | katakana | punctuation | cjk
|
| 4 |
+
hiragana ::= [ぁ-ゟ]
|
| 5 |
+
katakana ::= [ァ-ヿ]
|
| 6 |
+
punctuation ::= [、-〾]
|
| 7 |
+
cjk ::= [一-鿿]
|
grammars/json.gbnf
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root ::= object
|
| 2 |
+
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
| 3 |
+
|
| 4 |
+
object ::=
|
| 5 |
+
"{" ws (
|
| 6 |
+
string ":" ws value
|
| 7 |
+
("," ws string ":" ws value)*
|
| 8 |
+
)? "}" ws
|
| 9 |
+
|
| 10 |
+
array ::=
|
| 11 |
+
"[" ws (
|
| 12 |
+
value
|
| 13 |
+
("," ws value)*
|
| 14 |
+
)? "]" ws
|
| 15 |
+
|
| 16 |
+
string ::=
|
| 17 |
+
"\"" (
|
| 18 |
+
[^"\\\x7F\x00-\x1F] |
|
| 19 |
+
"\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes
|
| 20 |
+
)* "\"" ws
|
| 21 |
+
|
| 22 |
+
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws
|
| 23 |
+
|
| 24 |
+
# Optional space: by convention, applied in this grammar after literal chars when allowed
|
| 25 |
+
ws ::= | " " | "\n" [ \t]{0,20}
|
grammars/json_arr.gbnf
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This is the same as json.gbnf but we restrict whitespaces at the end of the root array
|
| 2 |
+
# Useful for generating JSON arrays
|
| 3 |
+
|
| 4 |
+
root ::= arr
|
| 5 |
+
value ::= object | array | string | number | ("true" | "false" | "null") ws
|
| 6 |
+
|
| 7 |
+
arr ::=
|
| 8 |
+
"[\n" ws (
|
| 9 |
+
value
|
| 10 |
+
(",\n" ws value)*
|
| 11 |
+
)? "]"
|
| 12 |
+
|
| 13 |
+
object ::=
|
| 14 |
+
"{" ws (
|
| 15 |
+
string ":" ws value
|
| 16 |
+
("," ws string ":" ws value)*
|
| 17 |
+
)? "}" ws
|
| 18 |
+
|
| 19 |
+
array ::=
|
| 20 |
+
"[" ws (
|
| 21 |
+
value
|
| 22 |
+
("," ws value)*
|
| 23 |
+
)? "]" ws
|
| 24 |
+
|
| 25 |
+
string ::=
|
| 26 |
+
"\"" (
|
| 27 |
+
[^"\\\x7F\x00-\x1F] |
|
| 28 |
+
"\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes
|
| 29 |
+
)* "\"" ws
|
| 30 |
+
|
| 31 |
+
number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws
|
| 32 |
+
|
| 33 |
+
# Optional space: by convention, applied in this grammar after literal chars when allowed
|
| 34 |
+
ws ::= | " " | "\n" [ \t]{0,20}
|
grammars/list.gbnf
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
root ::= item+
|
| 2 |
+
|
| 3 |
+
# Excludes various line break characters
|
| 4 |
+
item ::= "- " [^\r\n\x0b\x0c\x85\u2028\u2029]+ "\n"
|
include/llama-cpp.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#ifndef __cplusplus
|
| 4 |
+
#error "This header is for C++ only"
|
| 5 |
+
#endif
|
| 6 |
+
|
| 7 |
+
#include <memory>
|
| 8 |
+
|
| 9 |
+
#include "llama.h"
|
| 10 |
+
|
| 11 |
+
struct llama_model_deleter {
|
| 12 |
+
void operator()(llama_model * model) { llama_model_free(model); }
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
struct llama_context_deleter {
|
| 16 |
+
void operator()(llama_context * context) { llama_free(context); }
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
struct llama_sampler_deleter {
|
| 20 |
+
void operator()(llama_sampler * sampler) { llama_sampler_free(sampler); }
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
struct llama_adapter_lora_deleter {
|
| 24 |
+
void operator()(llama_adapter_lora * adapter) { llama_adapter_lora_free(adapter); }
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
typedef std::unique_ptr<llama_model, llama_model_deleter> llama_model_ptr;
|
| 28 |
+
typedef std::unique_ptr<llama_context, llama_context_deleter> llama_context_ptr;
|
| 29 |
+
typedef std::unique_ptr<llama_sampler, llama_sampler_deleter> llama_sampler_ptr;
|
| 30 |
+
typedef std::unique_ptr<llama_adapter_lora, llama_adapter_lora_deleter> llama_adapter_lora_ptr;
|
include/llama.h
ADDED
|
@@ -0,0 +1,1646 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#ifndef LLAMA_H
|
| 2 |
+
#define LLAMA_H
|
| 3 |
+
|
| 4 |
+
#include "ggml.h"
|
| 5 |
+
#include "ggml-cpu.h"
|
| 6 |
+
#include "ggml-backend.h"
|
| 7 |
+
#include "ggml-opt.h"
|
| 8 |
+
#include "gguf.h"
|
| 9 |
+
|
| 10 |
+
#include <stddef.h>
|
| 11 |
+
#include <stdint.h>
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stdbool.h>
|
| 14 |
+
|
| 15 |
+
#ifdef LLAMA_SHARED
|
| 16 |
+
# if defined(_WIN32) && !defined(__MINGW32__)
|
| 17 |
+
# ifdef LLAMA_BUILD
|
| 18 |
+
# define LLAMA_API __declspec(dllexport)
|
| 19 |
+
# else
|
| 20 |
+
# define LLAMA_API __declspec(dllimport)
|
| 21 |
+
# endif
|
| 22 |
+
# else
|
| 23 |
+
# define LLAMA_API __attribute__ ((visibility ("default")))
|
| 24 |
+
# endif
|
| 25 |
+
#else
|
| 26 |
+
# define LLAMA_API
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
#ifdef __GNUC__
|
| 30 |
+
# define DEPRECATED(func, hint) func __attribute__((deprecated(hint)))
|
| 31 |
+
#elif defined(_MSC_VER)
|
| 32 |
+
# define DEPRECATED(func, hint) __declspec(deprecated(hint)) func
|
| 33 |
+
#else
|
| 34 |
+
# define DEPRECATED(func, hint) func
|
| 35 |
+
#endif
|
| 36 |
+
|
| 37 |
+
#define LLAMA_DEFAULT_SEED 0xFFFFFFFF
|
| 38 |
+
|
| 39 |
+
#define LLAMA_TOKEN_NULL -1
|
| 40 |
+
|
| 41 |
+
#define LLAMA_FILE_MAGIC_GGLA 0x67676c61u // 'ggla'
|
| 42 |
+
#define LLAMA_FILE_MAGIC_GGSN 0x6767736eu // 'ggsn'
|
| 43 |
+
#define LLAMA_FILE_MAGIC_GGSQ 0x67677371u // 'ggsq'
|
| 44 |
+
|
| 45 |
+
#define LLAMA_SESSION_MAGIC LLAMA_FILE_MAGIC_GGSN
|
| 46 |
+
#define LLAMA_SESSION_VERSION 10
|
| 47 |
+
|
| 48 |
+
#define LLAMA_STATE_SEQ_MAGIC LLAMA_FILE_MAGIC_GGSQ
|
| 49 |
+
#define LLAMA_STATE_SEQ_VERSION 3
|
| 50 |
+
|
| 51 |
+
#ifdef __cplusplus
|
| 52 |
+
extern "C" {
|
| 53 |
+
#endif
|
| 54 |
+
|
| 55 |
+
//
|
| 56 |
+
// C interface
|
| 57 |
+
//
|
| 58 |
+
// TODO: show sample usage
|
| 59 |
+
//
|
| 60 |
+
|
| 61 |
+
struct llama_vocab;
|
| 62 |
+
struct llama_model;
|
| 63 |
+
struct llama_context;
|
| 64 |
+
struct llama_sampler;
|
| 65 |
+
|
| 66 |
+
typedef struct llama_memory_i * llama_memory_t;
|
| 67 |
+
|
| 68 |
+
typedef int32_t llama_pos;
|
| 69 |
+
typedef int32_t llama_token;
|
| 70 |
+
typedef int32_t llama_seq_id;
|
| 71 |
+
|
| 72 |
+
enum llama_vocab_type {
|
| 73 |
+
LLAMA_VOCAB_TYPE_NONE = 0, // For models without vocab
|
| 74 |
+
LLAMA_VOCAB_TYPE_SPM = 1, // LLaMA tokenizer based on byte-level BPE with byte fallback
|
| 75 |
+
LLAMA_VOCAB_TYPE_BPE = 2, // GPT-2 tokenizer based on byte-level BPE
|
| 76 |
+
LLAMA_VOCAB_TYPE_WPM = 3, // BERT tokenizer based on WordPiece
|
| 77 |
+
LLAMA_VOCAB_TYPE_UGM = 4, // T5 tokenizer based on Unigram
|
| 78 |
+
LLAMA_VOCAB_TYPE_RWKV = 5, // RWKV tokenizer based on greedy tokenization
|
| 79 |
+
LLAMA_VOCAB_TYPE_PLAMO2 = 6, // PLaMo-2 tokenizer based on Aho-Corasick with dynamic programming
|
| 80 |
+
LLAMA_VOCAB_TYPE_TEST = 7, // Dummy tokenizer for testing: rolling hash of fixed-size chunks -> tokens, tokens -> hex
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
enum llama_rope_type {
|
| 84 |
+
LLAMA_ROPE_TYPE_NONE = -1,
|
| 85 |
+
LLAMA_ROPE_TYPE_NORM = 0,
|
| 86 |
+
LLAMA_ROPE_TYPE_NEOX = GGML_ROPE_TYPE_NEOX,
|
| 87 |
+
LLAMA_ROPE_TYPE_MROPE = GGML_ROPE_TYPE_MROPE,
|
| 88 |
+
LLAMA_ROPE_TYPE_IMROPE = GGML_ROPE_TYPE_IMROPE,
|
| 89 |
+
LLAMA_ROPE_TYPE_VISION = GGML_ROPE_TYPE_VISION,
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
enum llama_token_type { //TODO: remove, required until per token attributes are available from GGUF file
|
| 93 |
+
LLAMA_TOKEN_TYPE_UNDEFINED = 0,
|
| 94 |
+
LLAMA_TOKEN_TYPE_NORMAL = 1,
|
| 95 |
+
LLAMA_TOKEN_TYPE_UNKNOWN = 2,
|
| 96 |
+
LLAMA_TOKEN_TYPE_CONTROL = 3,
|
| 97 |
+
LLAMA_TOKEN_TYPE_USER_DEFINED = 4,
|
| 98 |
+
LLAMA_TOKEN_TYPE_UNUSED = 5,
|
| 99 |
+
LLAMA_TOKEN_TYPE_BYTE = 6,
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
enum llama_token_attr {
|
| 103 |
+
LLAMA_TOKEN_ATTR_UNDEFINED = 0,
|
| 104 |
+
LLAMA_TOKEN_ATTR_UNKNOWN = 1 << 0,
|
| 105 |
+
LLAMA_TOKEN_ATTR_UNUSED = 1 << 1,
|
| 106 |
+
LLAMA_TOKEN_ATTR_NORMAL = 1 << 2,
|
| 107 |
+
LLAMA_TOKEN_ATTR_CONTROL = 1 << 3, // SPECIAL?
|
| 108 |
+
LLAMA_TOKEN_ATTR_USER_DEFINED = 1 << 4,
|
| 109 |
+
LLAMA_TOKEN_ATTR_BYTE = 1 << 5,
|
| 110 |
+
LLAMA_TOKEN_ATTR_NORMALIZED = 1 << 6,
|
| 111 |
+
LLAMA_TOKEN_ATTR_LSTRIP = 1 << 7,
|
| 112 |
+
LLAMA_TOKEN_ATTR_RSTRIP = 1 << 8,
|
| 113 |
+
LLAMA_TOKEN_ATTR_SINGLE_WORD = 1 << 9,
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
// model file types
|
| 117 |
+
enum llama_ftype {
|
| 118 |
+
LLAMA_FTYPE_ALL_F32 = 0,
|
| 119 |
+
LLAMA_FTYPE_MOSTLY_F16 = 1, // except 1d tensors
|
| 120 |
+
LLAMA_FTYPE_MOSTLY_Q4_0 = 2, // except 1d tensors
|
| 121 |
+
LLAMA_FTYPE_MOSTLY_Q4_1 = 3, // except 1d tensors
|
| 122 |
+
// LLAMA_FTYPE_MOSTLY_Q4_1_SOME_F16 = 4, // tok_embeddings.weight and output.weight are F16
|
| 123 |
+
// LLAMA_FTYPE_MOSTLY_Q4_2 = 5, // support has been removed
|
| 124 |
+
// LLAMA_FTYPE_MOSTLY_Q4_3 = 6, // support has been removed
|
| 125 |
+
LLAMA_FTYPE_MOSTLY_Q8_0 = 7, // except 1d tensors
|
| 126 |
+
LLAMA_FTYPE_MOSTLY_Q5_0 = 8, // except 1d tensors
|
| 127 |
+
LLAMA_FTYPE_MOSTLY_Q5_1 = 9, // except 1d tensors
|
| 128 |
+
LLAMA_FTYPE_MOSTLY_Q2_K = 10, // except 1d tensors
|
| 129 |
+
LLAMA_FTYPE_MOSTLY_Q3_K_S = 11, // except 1d tensors
|
| 130 |
+
LLAMA_FTYPE_MOSTLY_Q3_K_M = 12, // except 1d tensors
|
| 131 |
+
LLAMA_FTYPE_MOSTLY_Q3_K_L = 13, // except 1d tensors
|
| 132 |
+
LLAMA_FTYPE_MOSTLY_Q4_K_S = 14, // except 1d tensors
|
| 133 |
+
LLAMA_FTYPE_MOSTLY_Q4_K_M = 15, // except 1d tensors
|
| 134 |
+
LLAMA_FTYPE_MOSTLY_Q5_K_S = 16, // except 1d tensors
|
| 135 |
+
LLAMA_FTYPE_MOSTLY_Q5_K_M = 17, // except 1d tensors
|
| 136 |
+
LLAMA_FTYPE_MOSTLY_Q6_K = 18, // except 1d tensors
|
| 137 |
+
LLAMA_FTYPE_MOSTLY_IQ2_XXS = 19, // except 1d tensors
|
| 138 |
+
LLAMA_FTYPE_MOSTLY_IQ2_XS = 20, // except 1d tensors
|
| 139 |
+
LLAMA_FTYPE_MOSTLY_Q2_K_S = 21, // except 1d tensors
|
| 140 |
+
LLAMA_FTYPE_MOSTLY_IQ3_XS = 22, // except 1d tensors
|
| 141 |
+
LLAMA_FTYPE_MOSTLY_IQ3_XXS = 23, // except 1d tensors
|
| 142 |
+
LLAMA_FTYPE_MOSTLY_IQ1_S = 24, // except 1d tensors
|
| 143 |
+
LLAMA_FTYPE_MOSTLY_IQ4_NL = 25, // except 1d tensors
|
| 144 |
+
LLAMA_FTYPE_MOSTLY_IQ3_S = 26, // except 1d tensors
|
| 145 |
+
LLAMA_FTYPE_MOSTLY_IQ3_M = 27, // except 1d tensors
|
| 146 |
+
LLAMA_FTYPE_MOSTLY_IQ2_S = 28, // except 1d tensors
|
| 147 |
+
LLAMA_FTYPE_MOSTLY_IQ2_M = 29, // except 1d tensors
|
| 148 |
+
LLAMA_FTYPE_MOSTLY_IQ4_XS = 30, // except 1d tensors
|
| 149 |
+
LLAMA_FTYPE_MOSTLY_IQ1_M = 31, // except 1d tensors
|
| 150 |
+
LLAMA_FTYPE_MOSTLY_BF16 = 32, // except 1d tensors
|
| 151 |
+
//LLAMA_FTYPE_MOSTLY_Q4_0_4_4 = 33, // removed from gguf files, use Q4_0 and runtime repack
|
| 152 |
+
//LLAMA_FTYPE_MOSTLY_Q4_0_4_8 = 34, // removed from gguf files, use Q4_0 and runtime repack
|
| 153 |
+
//LLAMA_FTYPE_MOSTLY_Q4_0_8_8 = 35, // removed from gguf files, use Q4_0 and runtime repack
|
| 154 |
+
LLAMA_FTYPE_MOSTLY_TQ1_0 = 36, // except 1d tensors
|
| 155 |
+
LLAMA_FTYPE_MOSTLY_TQ2_0 = 37, // except 1d tensors
|
| 156 |
+
LLAMA_FTYPE_MOSTLY_MXFP4_MOE = 38, // except 1d tensors
|
| 157 |
+
LLAMA_FTYPE_MOSTLY_NVFP4 = 39, // except 1d tensors
|
| 158 |
+
LLAMA_FTYPE_MOSTLY_Q1_0 = 40, // except 1d tensors
|
| 159 |
+
LLAMA_FTYPE_MOSTLY_Q2_0 = 41, // except 1d tensors
|
| 160 |
+
|
| 161 |
+
LLAMA_FTYPE_GUESSED = 1024, // not specified in the model file
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
// Get the model file type (quantization) as a string, e.g. "Q8_0" or "Q4_K - Medium"
|
| 165 |
+
LLAMA_API const char * llama_ftype_name(enum llama_ftype ftype);
|
| 166 |
+
|
| 167 |
+
enum llama_rope_scaling_type {
|
| 168 |
+
LLAMA_ROPE_SCALING_TYPE_UNSPECIFIED = -1,
|
| 169 |
+
LLAMA_ROPE_SCALING_TYPE_NONE = 0,
|
| 170 |
+
LLAMA_ROPE_SCALING_TYPE_LINEAR = 1,
|
| 171 |
+
LLAMA_ROPE_SCALING_TYPE_YARN = 2,
|
| 172 |
+
LLAMA_ROPE_SCALING_TYPE_LONGROPE = 3,
|
| 173 |
+
LLAMA_ROPE_SCALING_TYPE_MAX_VALUE = LLAMA_ROPE_SCALING_TYPE_LONGROPE,
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
enum llama_pooling_type {
|
| 177 |
+
LLAMA_POOLING_TYPE_UNSPECIFIED = -1,
|
| 178 |
+
LLAMA_POOLING_TYPE_NONE = 0,
|
| 179 |
+
LLAMA_POOLING_TYPE_MEAN = 1,
|
| 180 |
+
LLAMA_POOLING_TYPE_CLS = 2,
|
| 181 |
+
LLAMA_POOLING_TYPE_LAST = 3,
|
| 182 |
+
LLAMA_POOLING_TYPE_RANK = 4, // used by reranking models to attach the classification head to the graph
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
enum llama_attention_type {
|
| 186 |
+
LLAMA_ATTENTION_TYPE_UNSPECIFIED = -1,
|
| 187 |
+
LLAMA_ATTENTION_TYPE_CAUSAL = 0,
|
| 188 |
+
LLAMA_ATTENTION_TYPE_NON_CAUSAL = 1,
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
enum llama_flash_attn_type {
|
| 192 |
+
LLAMA_FLASH_ATTN_TYPE_AUTO = -1,
|
| 193 |
+
LLAMA_FLASH_ATTN_TYPE_DISABLED = 0,
|
| 194 |
+
LLAMA_FLASH_ATTN_TYPE_ENABLED = 1,
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
LLAMA_API const char * llama_flash_attn_type_name(enum llama_flash_attn_type flash_attn_type);
|
| 198 |
+
|
| 199 |
+
enum llama_split_mode {
|
| 200 |
+
LLAMA_SPLIT_MODE_NONE = 0, // single GPU
|
| 201 |
+
LLAMA_SPLIT_MODE_LAYER = 1, // split layers and KV across GPUs
|
| 202 |
+
LLAMA_SPLIT_MODE_ROW = 2, // split layers and KV across GPUs, use tensor parallelism if supported
|
| 203 |
+
LLAMA_SPLIT_MODE_TENSOR = 3,
|
| 204 |
+
};
|
| 205 |
+
|
| 206 |
+
enum llama_load_mode {
|
| 207 |
+
LLAMA_LOAD_MODE_AUTO = -1, // auto-detect based on device capabilities
|
| 208 |
+
LLAMA_LOAD_MODE_NONE = 0, // no special loading mode
|
| 209 |
+
LLAMA_LOAD_MODE_MMAP = 1, // memory map the model
|
| 210 |
+
LLAMA_LOAD_MODE_MLOCK = 2, // force system to keep model in RAM rather than swapping or compressing
|
| 211 |
+
LLAMA_LOAD_MODE_MMAP_MLOCK = 3, // mmap + force system to keep model in RAM rather than swapping or compressing
|
| 212 |
+
LLAMA_LOAD_MODE_DIRECT_IO = 4, // use direct I/O if available
|
| 213 |
+
};
|
| 214 |
+
|
| 215 |
+
LLAMA_API const char * llama_load_mode_name(enum llama_load_mode load_mode);
|
| 216 |
+
LLAMA_API enum llama_load_mode llama_load_mode_from_str(const char * str);
|
| 217 |
+
|
| 218 |
+
enum llama_lazy_mode {
|
| 219 |
+
LLAMA_LAZY_MODE_OFF = 0, // always read the whole tensor up front
|
| 220 |
+
LLAMA_LAZY_MODE_AUTO = 1, // lazy only for marked tensors larger than 4 GiB (requires mmap)
|
| 221 |
+
LLAMA_LAZY_MODE_ON = 2, // read the rows of tensors marked by the arch on demand (requires mmap)
|
| 222 |
+
};
|
| 223 |
+
|
| 224 |
+
enum llama_context_type {
|
| 225 |
+
LLAMA_CONTEXT_TYPE_DEFAULT = 0,
|
| 226 |
+
LLAMA_CONTEXT_TYPE_MTP = 1,
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
// TODO: simplify (https://github.com/ggml-org/llama.cpp/pull/9294#pullrequestreview-2286561979)
|
| 230 |
+
typedef struct llama_token_data {
|
| 231 |
+
llama_token id; // token id
|
| 232 |
+
float logit; // log-odds of the token
|
| 233 |
+
float p; // probability of the token
|
| 234 |
+
} llama_token_data;
|
| 235 |
+
|
| 236 |
+
typedef struct llama_token_data_array {
|
| 237 |
+
// TODO: consider SoA
|
| 238 |
+
// NOTE: this pointer can be modified by the samplers
|
| 239 |
+
llama_token_data * data;
|
| 240 |
+
size_t size;
|
| 241 |
+
int64_t selected; // this is the index in the data array (i.e. not the token id)
|
| 242 |
+
bool sorted; // note: do not assume the data is sorted - always check this flag
|
| 243 |
+
} llama_token_data_array;
|
| 244 |
+
|
| 245 |
+
typedef bool (*llama_progress_callback)(float progress, void * user_data);
|
| 246 |
+
|
| 247 |
+
// Input data for llama_encode/llama_decode
|
| 248 |
+
// A llama_batch object can contain input about one or many sequences
|
| 249 |
+
// The provided arrays (i.e. token, embd, pos, etc.) must have size of n_tokens
|
| 250 |
+
//
|
| 251 |
+
// - token : the token ids of the input (used when embd is NULL)
|
| 252 |
+
// - embd : token embeddings (i.e. float vector of size n_embd) (used when token is NULL)
|
| 253 |
+
// - pos : the positions of the respective token in the sequence
|
| 254 |
+
// (if set to NULL, the token position will be tracked automatically by llama_encode/llama_decode)
|
| 255 |
+
// - seq_id : the sequence to which the respective token belongs
|
| 256 |
+
// (if set to NULL, the sequence ID will be assumed to be 0)
|
| 257 |
+
// - logits : if zero, the logits (and/or the embeddings) for the respective token will not be output
|
| 258 |
+
// (if set to NULL:
|
| 259 |
+
// - if embeddings: all tokens are output
|
| 260 |
+
// - if not: only the last token is output
|
| 261 |
+
// )
|
| 262 |
+
//
|
| 263 |
+
typedef struct llama_batch {
|
| 264 |
+
int32_t n_tokens;
|
| 265 |
+
|
| 266 |
+
llama_token * token;
|
| 267 |
+
float * embd;
|
| 268 |
+
llama_pos * pos;
|
| 269 |
+
int32_t * n_seq_id;
|
| 270 |
+
llama_seq_id ** seq_id;
|
| 271 |
+
int8_t * logits; // TODO: rename this to "output"
|
| 272 |
+
} llama_batch;
|
| 273 |
+
|
| 274 |
+
enum llama_model_kv_override_type {
|
| 275 |
+
LLAMA_KV_OVERRIDE_TYPE_INT,
|
| 276 |
+
LLAMA_KV_OVERRIDE_TYPE_FLOAT,
|
| 277 |
+
LLAMA_KV_OVERRIDE_TYPE_BOOL,
|
| 278 |
+
LLAMA_KV_OVERRIDE_TYPE_STR,
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
enum llama_model_meta_key {
|
| 282 |
+
LLAMA_MODEL_META_KEY_SAMPLING_SEQUENCE,
|
| 283 |
+
LLAMA_MODEL_META_KEY_SAMPLING_TOP_K,
|
| 284 |
+
LLAMA_MODEL_META_KEY_SAMPLING_TOP_P,
|
| 285 |
+
LLAMA_MODEL_META_KEY_SAMPLING_MIN_P,
|
| 286 |
+
LLAMA_MODEL_META_KEY_SAMPLING_XTC_PROBABILITY,
|
| 287 |
+
LLAMA_MODEL_META_KEY_SAMPLING_XTC_THRESHOLD,
|
| 288 |
+
LLAMA_MODEL_META_KEY_SAMPLING_TEMP,
|
| 289 |
+
LLAMA_MODEL_META_KEY_SAMPLING_PENALTY_LAST_N,
|
| 290 |
+
LLAMA_MODEL_META_KEY_SAMPLING_PENALTY_REPEAT,
|
| 291 |
+
LLAMA_MODEL_META_KEY_SAMPLING_MIROSTAT,
|
| 292 |
+
LLAMA_MODEL_META_KEY_SAMPLING_MIROSTAT_TAU,
|
| 293 |
+
LLAMA_MODEL_META_KEY_SAMPLING_MIROSTAT_ETA,
|
| 294 |
+
};
|
| 295 |
+
|
| 296 |
+
struct llama_model_kv_override {
|
| 297 |
+
enum llama_model_kv_override_type tag;
|
| 298 |
+
|
| 299 |
+
char key[128];
|
| 300 |
+
|
| 301 |
+
union {
|
| 302 |
+
int64_t val_i64;
|
| 303 |
+
double val_f64;
|
| 304 |
+
bool val_bool;
|
| 305 |
+
char val_str[128];
|
| 306 |
+
};
|
| 307 |
+
};
|
| 308 |
+
|
| 309 |
+
struct llama_model_tensor_buft_override {
|
| 310 |
+
const char * pattern;
|
| 311 |
+
ggml_backend_buffer_type_t buft;
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
struct llama_model_params {
|
| 315 |
+
// NULL-terminated list of devices to use for offloading (if NULL, all available devices are used)
|
| 316 |
+
ggml_backend_dev_t * devices;
|
| 317 |
+
|
| 318 |
+
// NULL-terminated list of buffer types to use for tensors that match a pattern
|
| 319 |
+
const struct llama_model_tensor_buft_override * tensor_buft_overrides;
|
| 320 |
+
|
| 321 |
+
int32_t n_gpu_layers; // number of layers to store in VRAM, a negative value means all layers
|
| 322 |
+
enum llama_split_mode split_mode; // how to split the model across multiple GPUs
|
| 323 |
+
enum llama_load_mode load_mode; // how to load the model
|
| 324 |
+
|
| 325 |
+
enum llama_lazy_mode lazy_mode; // on-demand reading of tensors marked by the arch
|
| 326 |
+
|
| 327 |
+
// the GPU that is used for the entire model when split_mode is LLAMA_SPLIT_MODE_NONE
|
| 328 |
+
int32_t main_gpu;
|
| 329 |
+
|
| 330 |
+
// proportion of the model (layers or rows) to offload to each GPU, size: llama_max_devices()
|
| 331 |
+
const float * tensor_split;
|
| 332 |
+
|
| 333 |
+
// Called with a progress value between 0.0 and 1.0. Pass NULL to disable.
|
| 334 |
+
// If the provided progress_callback returns true, model loading continues.
|
| 335 |
+
// If it returns false, model loading is immediately aborted.
|
| 336 |
+
llama_progress_callback progress_callback;
|
| 337 |
+
|
| 338 |
+
// context pointer passed to the progress callback
|
| 339 |
+
void * progress_callback_user_data;
|
| 340 |
+
|
| 341 |
+
// override key-value pairs of the model meta data
|
| 342 |
+
const struct llama_model_kv_override * kv_overrides;
|
| 343 |
+
|
| 344 |
+
// Keep the booleans together to avoid misalignment during copy-by-value.
|
| 345 |
+
bool vocab_only; // only load the vocabulary, no weights
|
| 346 |
+
bool check_tensors; // validate model tensor data
|
| 347 |
+
bool use_extra_bufts; // use extra buffer types (used for weight repacking)
|
| 348 |
+
bool no_host; // bypass host buffer allowing extra buffers to be used
|
| 349 |
+
bool no_alloc; // only load metadata and simulate memory allocations
|
| 350 |
+
bool load_mtp; // whether to load MTP layers
|
| 351 |
+
};
|
| 352 |
+
|
| 353 |
+
struct llama_sampler_seq_config {
|
| 354 |
+
llama_seq_id seq_id;
|
| 355 |
+
struct llama_sampler * sampler;
|
| 356 |
+
};
|
| 357 |
+
|
| 358 |
+
// NOTE: changing the default values of parameters marked as [EXPERIMENTAL] may cause crashes or incorrect results in certain configurations
|
| 359 |
+
// https://github.com/ggml-org/llama.cpp/pull/7544
|
| 360 |
+
struct llama_context_params {
|
| 361 |
+
uint32_t n_ctx; // text context, 0 = from model
|
| 362 |
+
uint32_t n_batch; // logical maximum batch size that can be submitted to llama_decode
|
| 363 |
+
uint32_t n_ubatch; // physical maximum batch size
|
| 364 |
+
uint32_t n_seq_max; // max number of sequences (i.e. distinct states for recurrent models)
|
| 365 |
+
uint32_t n_rs_seq; // number of recurrent-state snapshots per seq for rollback (0 = no rollback) [EXPERIMENTAL]
|
| 366 |
+
uint32_t n_outputs_max; // max outputs in a ubatch (0 = n_batch)
|
| 367 |
+
uint32_t n_outputs_max_per_seq; // max outputs per sequence (0 = n_outputs_max)
|
| 368 |
+
int32_t n_threads; // number of threads to use for generation
|
| 369 |
+
int32_t n_threads_batch; // number of threads to use for batch processing
|
| 370 |
+
|
| 371 |
+
enum llama_context_type ctx_type; // set the context type (e.g. MTP)
|
| 372 |
+
enum llama_rope_scaling_type rope_scaling_type; // RoPE scaling type, from `enum llama_rope_scaling_type`
|
| 373 |
+
enum llama_pooling_type pooling_type; // whether to pool (sum) embedding results by sequence id
|
| 374 |
+
enum llama_attention_type attention_type; // attention type to use for embeddings
|
| 375 |
+
enum llama_flash_attn_type flash_attn_type; // when to enable Flash Attention
|
| 376 |
+
|
| 377 |
+
// ref: https://github.com/ggml-org/llama.cpp/pull/2054
|
| 378 |
+
float rope_freq_base; // RoPE base frequency, 0 = from model
|
| 379 |
+
float rope_freq_scale; // RoPE frequency scaling factor, 0 = from model
|
| 380 |
+
float yarn_ext_factor; // YaRN extrapolation mix factor, negative = from model
|
| 381 |
+
float yarn_attn_factor; // YaRN magnitude scaling factor
|
| 382 |
+
float yarn_beta_fast; // YaRN low correction dim
|
| 383 |
+
float yarn_beta_slow; // YaRN high correction dim
|
| 384 |
+
uint32_t yarn_orig_ctx; // YaRN original context size
|
| 385 |
+
float defrag_thold; // [DEPRECATED] defragment the KV cache if holes/size > thold, <= 0 disabled (default)
|
| 386 |
+
|
| 387 |
+
ggml_backend_sched_eval_callback cb_eval;
|
| 388 |
+
void * cb_eval_user_data;
|
| 389 |
+
|
| 390 |
+
enum ggml_type type_k; // data type for K cache [EXPERIMENTAL]
|
| 391 |
+
enum ggml_type type_v; // data type for V cache [EXPERIMENTAL]
|
| 392 |
+
|
| 393 |
+
// Abort callback
|
| 394 |
+
// if it returns true, execution of llama_decode() will be aborted
|
| 395 |
+
// currently works only with CPU execution
|
| 396 |
+
ggml_abort_callback abort_callback;
|
| 397 |
+
void * abort_callback_data;
|
| 398 |
+
|
| 399 |
+
// Keep the booleans together and at the end of the struct to avoid misalignment during copy-by-value.
|
| 400 |
+
bool embeddings; // if true, extract embeddings (together with logits)
|
| 401 |
+
bool offload_kqv; // offload the KQV ops (including the KV cache) to GPU
|
| 402 |
+
bool no_perf; // measure performance timings
|
| 403 |
+
bool op_offload; // offload host tensor operations to device
|
| 404 |
+
bool swa_full; // use full-size SWA cache (https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)
|
| 405 |
+
// NOTE: setting to false when n_seq_max > 1 can cause bad performance in some cases
|
| 406 |
+
// ref: https://github.com/ggml-org/llama.cpp/pull/13845#issuecomment-2924800573
|
| 407 |
+
bool kv_unified; // use a unified buffer across the input sequences when computing the attention
|
| 408 |
+
// try to disable when n_seq_max > 1 for improved performance when the sequences do not share a large prefix
|
| 409 |
+
// ref: https://github.com/ggml-org/llama.cpp/pull/14363
|
| 410 |
+
|
| 411 |
+
// [EXPERIMENTAL]
|
| 412 |
+
// backend sampler chain configuration (make sure the caller keeps the sampler chains alive)
|
| 413 |
+
// note: the samplers must be sampler chains (i.e. use llama_sampler_chain_init)
|
| 414 |
+
struct llama_sampler_seq_config * samplers;
|
| 415 |
+
size_t n_samplers;
|
| 416 |
+
|
| 417 |
+
// a source/target/parent context
|
| 418 |
+
// can be utilized in various ways, for example by sharing results or llama_memory between 2 contexts
|
| 419 |
+
struct llama_context * ctx_other;
|
| 420 |
+
};
|
| 421 |
+
|
| 422 |
+
struct llama_model_tensor_override {
|
| 423 |
+
const char * pattern;
|
| 424 |
+
enum ggml_type type;
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
struct llama_model_imatrix_data {
|
| 428 |
+
const char * name;
|
| 429 |
+
const float * data;
|
| 430 |
+
size_t size;
|
| 431 |
+
};
|
| 432 |
+
|
| 433 |
+
// model quantization parameters
|
| 434 |
+
typedef struct llama_model_quantize_params {
|
| 435 |
+
int32_t nthread; // number of threads to use for quantizing, if <=0 will use std::thread::hardware_concurrency()
|
| 436 |
+
enum llama_ftype ftype; // quantize to this llama_ftype
|
| 437 |
+
enum ggml_type output_tensor_type; // output tensor type
|
| 438 |
+
enum ggml_type token_embedding_type; // token embeddings tensor type
|
| 439 |
+
bool allow_requantize; // allow quantizing non-f32/f16 tensors
|
| 440 |
+
bool quantize_output_tensor; // quantize output.weight
|
| 441 |
+
bool only_copy; // only copy tensors - ftype, allow_requantize and quantize_output_tensor are ignored
|
| 442 |
+
bool pure; // quantize all tensors to the default type
|
| 443 |
+
bool keep_split; // quantize to the same number of shards
|
| 444 |
+
bool dry_run; // calculate and show the final quantization size without performing quantization
|
| 445 |
+
const struct llama_model_imatrix_data * imatrix; // pointer to importance matrix data
|
| 446 |
+
const struct llama_model_kv_override * kv_overrides; // pointer to kv overrides
|
| 447 |
+
const struct llama_model_tensor_override * tt_overrides; // pointer to tensor overrides
|
| 448 |
+
const int32_t * prune_layers; // pointer to layer indices to prune
|
| 449 |
+
size_t max_buf_size; // max bytes of tensor rows kept in memory at once, 0 = default (8 GiB)
|
| 450 |
+
} llama_model_quantize_params;
|
| 451 |
+
|
| 452 |
+
typedef struct llama_logit_bias {
|
| 453 |
+
llama_token token;
|
| 454 |
+
float bias;
|
| 455 |
+
} llama_logit_bias;
|
| 456 |
+
|
| 457 |
+
typedef struct llama_sampler_chain_params {
|
| 458 |
+
bool no_perf; // whether to measure performance timings
|
| 459 |
+
} llama_sampler_chain_params;
|
| 460 |
+
|
| 461 |
+
// used in chat template
|
| 462 |
+
typedef struct llama_chat_message {
|
| 463 |
+
const char * role;
|
| 464 |
+
const char * content;
|
| 465 |
+
} llama_chat_message;
|
| 466 |
+
|
| 467 |
+
// lora adapter
|
| 468 |
+
struct llama_adapter_lora;
|
| 469 |
+
|
| 470 |
+
LLAMA_API const char * llama_version(void);
|
| 471 |
+
|
| 472 |
+
// Helpers for getting default parameters
|
| 473 |
+
// TODO: update API to start accepting pointers to params structs (https://github.com/ggml-org/llama.cpp/discussions/9172)
|
| 474 |
+
LLAMA_API struct llama_model_params llama_model_default_params(void);
|
| 475 |
+
LLAMA_API struct llama_context_params llama_context_default_params(void);
|
| 476 |
+
LLAMA_API struct llama_sampler_chain_params llama_sampler_chain_default_params(void);
|
| 477 |
+
LLAMA_API struct llama_model_quantize_params llama_model_quantize_default_params(void);
|
| 478 |
+
|
| 479 |
+
// Initialize the llama + ggml backend
|
| 480 |
+
// If numa is true, use NUMA optimizations
|
| 481 |
+
// Call once at the start of the program
|
| 482 |
+
LLAMA_API void llama_backend_init(void);
|
| 483 |
+
|
| 484 |
+
// Call once at the end of the program - currently only used for MPI
|
| 485 |
+
LLAMA_API void llama_backend_free(void);
|
| 486 |
+
|
| 487 |
+
//optional:
|
| 488 |
+
LLAMA_API void llama_numa_init(enum ggml_numa_strategy numa);
|
| 489 |
+
|
| 490 |
+
// Optional: an auto threadpool gets created in ggml if not passed explicitly
|
| 491 |
+
LLAMA_API void llama_attach_threadpool(
|
| 492 |
+
struct llama_context * ctx,
|
| 493 |
+
ggml_threadpool_t threadpool,
|
| 494 |
+
ggml_threadpool_t threadpool_batch);
|
| 495 |
+
|
| 496 |
+
LLAMA_API void llama_detach_threadpool(struct llama_context * ctx);
|
| 497 |
+
|
| 498 |
+
typedef void (*llama_model_set_tensor_data_t)(struct ggml_tensor * tensor, void * userdata);
|
| 499 |
+
|
| 500 |
+
// Create a new model from GGUF metadata as well as a function to set the tensor data
|
| 501 |
+
// - tensors are created as GGML_TYPE_F32 by default,
|
| 502 |
+
// override by adding a tensor with the same name but a different name to the context
|
| 503 |
+
LLAMA_API struct llama_model * llama_model_init_from_user(
|
| 504 |
+
struct gguf_context * metadata,
|
| 505 |
+
llama_model_set_tensor_data_t set_tensor_data, // function to initialize tensor data with
|
| 506 |
+
void * set_tensor_data_ud, // userdata for function
|
| 507 |
+
struct llama_model_params params);
|
| 508 |
+
|
| 509 |
+
DEPRECATED(LLAMA_API struct llama_model * llama_load_model_from_file(
|
| 510 |
+
const char * path_model,
|
| 511 |
+
struct llama_model_params params),
|
| 512 |
+
"use llama_model_load_from_file instead");
|
| 513 |
+
|
| 514 |
+
// Load a model from a file
|
| 515 |
+
// If the file is split into multiple parts, the file name must follow this pattern: <name>-%05d-of-%05d.gguf
|
| 516 |
+
// If the split file name does not follow this pattern, use llama_model_load_from_splits
|
| 517 |
+
LLAMA_API struct llama_model * llama_model_load_from_file(
|
| 518 |
+
const char * path_model,
|
| 519 |
+
struct llama_model_params params);
|
| 520 |
+
|
| 521 |
+
// Load a model from an open FILE pointer
|
| 522 |
+
// The GGUF is read from the current position, so it can be embedded in a larger file
|
| 523 |
+
// mmap needs the GGUF data section at a file offset to be aligned to the CPU tensor alignment (32 bytes)
|
| 524 |
+
LLAMA_API struct llama_model * llama_model_load_from_file_ptr(
|
| 525 |
+
FILE * file,
|
| 526 |
+
struct llama_model_params params);
|
| 527 |
+
|
| 528 |
+
// Load a model from multiple splits (support custom naming scheme)
|
| 529 |
+
// The paths must be in the correct order
|
| 530 |
+
LLAMA_API struct llama_model * llama_model_load_from_splits(
|
| 531 |
+
const char ** paths,
|
| 532 |
+
size_t n_paths,
|
| 533 |
+
struct llama_model_params params);
|
| 534 |
+
|
| 535 |
+
LLAMA_API void llama_model_save_to_file(
|
| 536 |
+
const struct llama_model * model,
|
| 537 |
+
const char * path_model);
|
| 538 |
+
|
| 539 |
+
DEPRECATED(LLAMA_API void llama_free_model(struct llama_model * model),
|
| 540 |
+
"use llama_model_free instead");
|
| 541 |
+
|
| 542 |
+
LLAMA_API void llama_model_free(struct llama_model * model);
|
| 543 |
+
|
| 544 |
+
LLAMA_API struct llama_context * llama_init_from_model(
|
| 545 |
+
struct llama_model * model,
|
| 546 |
+
struct llama_context_params params);
|
| 547 |
+
|
| 548 |
+
DEPRECATED(LLAMA_API struct llama_context * llama_new_context_with_model(
|
| 549 |
+
struct llama_model * model,
|
| 550 |
+
struct llama_context_params params),
|
| 551 |
+
"use llama_init_from_model instead");
|
| 552 |
+
|
| 553 |
+
// Frees all allocated memory
|
| 554 |
+
LLAMA_API void llama_free(struct llama_context * ctx);
|
| 555 |
+
|
| 556 |
+
LLAMA_API int64_t llama_time_us(void);
|
| 557 |
+
|
| 558 |
+
LLAMA_API size_t llama_max_devices(void);
|
| 559 |
+
LLAMA_API size_t llama_max_parallel_sequences(void);
|
| 560 |
+
LLAMA_API size_t llama_max_tensor_buft_overrides(void);
|
| 561 |
+
|
| 562 |
+
LLAMA_API bool llama_supports_mmap (void);
|
| 563 |
+
LLAMA_API bool llama_supports_mlock (void);
|
| 564 |
+
LLAMA_API bool llama_supports_gpu_offload(void);
|
| 565 |
+
LLAMA_API bool llama_supports_rpc (void);
|
| 566 |
+
|
| 567 |
+
// NOTE: After creating a llama_context, it is recommended to query the actual values using these functions
|
| 568 |
+
// In some cases the requested values via llama_context_params may differ from the actual values used by the context
|
| 569 |
+
// ref: https://github.com/ggml-org/llama.cpp/pull/17046#discussion_r2503085732
|
| 570 |
+
LLAMA_API uint32_t llama_n_ctx (const struct llama_context * ctx);
|
| 571 |
+
LLAMA_API uint32_t llama_n_ctx_seq (const struct llama_context * ctx);
|
| 572 |
+
LLAMA_API uint32_t llama_n_batch (const struct llama_context * ctx);
|
| 573 |
+
LLAMA_API uint32_t llama_n_ubatch (const struct llama_context * ctx);
|
| 574 |
+
LLAMA_API uint32_t llama_n_seq_max (const struct llama_context * ctx);
|
| 575 |
+
LLAMA_API uint32_t llama_n_rs_seq (const struct llama_context * ctx);
|
| 576 |
+
|
| 577 |
+
DEPRECATED(LLAMA_API int32_t llama_n_ctx_train(const struct llama_model * model), "use llama_model_n_ctx_train instead");
|
| 578 |
+
DEPRECATED(LLAMA_API int32_t llama_n_embd (const struct llama_model * model), "use llama_model_n_embd instead");
|
| 579 |
+
DEPRECATED(LLAMA_API int32_t llama_n_layer (const struct llama_model * model), "use llama_model_n_layer instead");
|
| 580 |
+
DEPRECATED(LLAMA_API int32_t llama_n_head (const struct llama_model * model), "use llama_model_n_head instead");
|
| 581 |
+
|
| 582 |
+
DEPRECATED(LLAMA_API int32_t llama_n_vocab (const struct llama_vocab * vocab), "use llama_vocab_n_tokens instead");
|
| 583 |
+
|
| 584 |
+
LLAMA_API const struct llama_model * llama_get_model (const struct llama_context * ctx);
|
| 585 |
+
LLAMA_API llama_memory_t llama_get_memory (const struct llama_context * ctx);
|
| 586 |
+
LLAMA_API enum llama_pooling_type llama_pooling_type(const struct llama_context * ctx); // TODO: rename to llama_get_pooling_type
|
| 587 |
+
|
| 588 |
+
LLAMA_API const struct llama_vocab * llama_model_get_vocab(const struct llama_model * model);
|
| 589 |
+
LLAMA_API enum llama_rope_type llama_model_rope_type(const struct llama_model * model);
|
| 590 |
+
|
| 591 |
+
LLAMA_API int32_t llama_model_n_ctx_train (const struct llama_model * model);
|
| 592 |
+
LLAMA_API int32_t llama_model_n_embd (const struct llama_model * model);
|
| 593 |
+
LLAMA_API int32_t llama_model_n_embd_inp (const struct llama_model * model);
|
| 594 |
+
LLAMA_API int32_t llama_model_n_embd_out (const struct llama_model * model);
|
| 595 |
+
LLAMA_API int32_t llama_model_n_layer (const struct llama_model * model);
|
| 596 |
+
LLAMA_API int32_t llama_model_n_layer_nextn(const struct llama_model * model);
|
| 597 |
+
LLAMA_API int32_t llama_model_n_head (const struct llama_model * model);
|
| 598 |
+
LLAMA_API int32_t llama_model_n_head_kv (const struct llama_model * model);
|
| 599 |
+
LLAMA_API int32_t llama_model_n_swa (const struct llama_model * model);
|
| 600 |
+
|
| 601 |
+
// Get the model's RoPE frequency scaling factor
|
| 602 |
+
LLAMA_API float llama_model_rope_freq_scale_train(const struct llama_model * model);
|
| 603 |
+
|
| 604 |
+
// Returns the number of classifier outputs (only valid for classifier models)
|
| 605 |
+
// Undefined behavior for non-classifier models
|
| 606 |
+
LLAMA_API uint32_t llama_model_n_cls_out(const struct llama_model * model);
|
| 607 |
+
|
| 608 |
+
// Returns label of classifier output by index (<n_cls_out). Returns nullptr if no label provided
|
| 609 |
+
LLAMA_API const char * llama_model_cls_label(const struct llama_model * model, uint32_t i);
|
| 610 |
+
|
| 611 |
+
LLAMA_API enum llama_vocab_type llama_vocab_type(const struct llama_vocab * vocab);
|
| 612 |
+
|
| 613 |
+
LLAMA_API int32_t llama_vocab_n_tokens(const struct llama_vocab * vocab);
|
| 614 |
+
|
| 615 |
+
// Functions to access the model's GGUF metadata scalar values
|
| 616 |
+
// - The functions return the length of the string on success, or -1 on failure
|
| 617 |
+
// - The output string is always null-terminated and cleared on failure
|
| 618 |
+
// - When retrieving a string, an extra byte must be allocated to account for the null terminator
|
| 619 |
+
// - GGUF array values are not supported by these functions
|
| 620 |
+
|
| 621 |
+
// Get metadata value as a string by key name
|
| 622 |
+
LLAMA_API int32_t llama_model_meta_val_str(const struct llama_model * model, const char * key, char * buf, size_t buf_size);
|
| 623 |
+
|
| 624 |
+
// Get the number of metadata key/value pairs
|
| 625 |
+
LLAMA_API int32_t llama_model_meta_count(const struct llama_model * model);
|
| 626 |
+
|
| 627 |
+
// Get sampling metadata key name. Returns nullptr if the key is invalid
|
| 628 |
+
LLAMA_API const char * llama_model_meta_key_str(enum llama_model_meta_key key);
|
| 629 |
+
|
| 630 |
+
// Get metadata key name by index
|
| 631 |
+
LLAMA_API int32_t llama_model_meta_key_by_index(const struct llama_model * model, int32_t i, char * buf, size_t buf_size);
|
| 632 |
+
|
| 633 |
+
// Get metadata value as a string by index
|
| 634 |
+
LLAMA_API int32_t llama_model_meta_val_str_by_index(const struct llama_model * model, int32_t i, char * buf, size_t buf_size);
|
| 635 |
+
|
| 636 |
+
// Get a string describing the model type
|
| 637 |
+
LLAMA_API int32_t llama_model_desc(const struct llama_model * model, char * buf, size_t buf_size);
|
| 638 |
+
|
| 639 |
+
// Get the model file type (quantization), e.g. LLAMA_FTYPE_MOSTLY_Q8_0
|
| 640 |
+
LLAMA_API enum llama_ftype llama_model_ftype(const struct llama_model * model);
|
| 641 |
+
|
| 642 |
+
// Returns the total size of all the tensors in the model in bytes
|
| 643 |
+
LLAMA_API uint64_t llama_model_size(const struct llama_model * model);
|
| 644 |
+
|
| 645 |
+
// Get the default chat template. Returns nullptr if not available
|
| 646 |
+
// If name is NULL, returns the default chat template
|
| 647 |
+
LLAMA_API const char * llama_model_chat_template(const struct llama_model * model, const char * name);
|
| 648 |
+
|
| 649 |
+
// Returns the total number of parameters in the model
|
| 650 |
+
LLAMA_API uint64_t llama_model_n_params(const struct llama_model * model);
|
| 651 |
+
|
| 652 |
+
// Returns true if the model contains an encoder that requires llama_encode() call
|
| 653 |
+
LLAMA_API bool llama_model_has_encoder(const struct llama_model * model);
|
| 654 |
+
|
| 655 |
+
// Returns true if the model contains a decoder that requires llama_decode() call
|
| 656 |
+
LLAMA_API bool llama_model_has_decoder(const struct llama_model * model);
|
| 657 |
+
|
| 658 |
+
// For encoder-decoder models, this function returns id of the token that must be provided
|
| 659 |
+
// to the decoder to start generating output sequence. For other models, it returns -1.
|
| 660 |
+
LLAMA_API llama_token llama_model_decoder_start_token(const struct llama_model * model);
|
| 661 |
+
|
| 662 |
+
// Returns true if the model is recurrent (like Mamba, RWKV, etc.)
|
| 663 |
+
LLAMA_API bool llama_model_is_recurrent(const struct llama_model * model);
|
| 664 |
+
|
| 665 |
+
// Returns true if the model is hybrid (like Jamba, Granite, etc.)
|
| 666 |
+
LLAMA_API bool llama_model_is_hybrid(const struct llama_model * model);
|
| 667 |
+
|
| 668 |
+
// Returns true if the model is diffusion-based (like LLaDA, Dream, etc.)
|
| 669 |
+
LLAMA_API bool llama_model_is_diffusion(const struct llama_model * model);
|
| 670 |
+
|
| 671 |
+
// Returns 0 on success
|
| 672 |
+
LLAMA_API uint32_t llama_model_quantize(
|
| 673 |
+
const char * fname_inp,
|
| 674 |
+
const char * fname_out,
|
| 675 |
+
const llama_model_quantize_params * params);
|
| 676 |
+
|
| 677 |
+
//
|
| 678 |
+
// Adapters
|
| 679 |
+
//
|
| 680 |
+
|
| 681 |
+
// Load a LoRA adapter from file
|
| 682 |
+
// The adapter is valid as long as the associated model is not freed
|
| 683 |
+
LLAMA_API struct llama_adapter_lora * llama_adapter_lora_init(
|
| 684 |
+
struct llama_model * model,
|
| 685 |
+
const char * path_lora);
|
| 686 |
+
|
| 687 |
+
// Load a LoRA adapter from an open FILE pointer, reading from its current position
|
| 688 |
+
LLAMA_API struct llama_adapter_lora * llama_adapter_lora_init_from_file_ptr(
|
| 689 |
+
struct llama_model * model,
|
| 690 |
+
FILE * file);
|
| 691 |
+
|
| 692 |
+
// Functions to access the adapter's GGUF metadata scalar values
|
| 693 |
+
// - The functions return the length of the string on success, or -1 on failure
|
| 694 |
+
// - The output string is always null-terminated and cleared on failure
|
| 695 |
+
// - When retrieving a string, an extra byte must be allocated to account for the null terminator
|
| 696 |
+
// - GGUF array values are not supported by these functions
|
| 697 |
+
|
| 698 |
+
// Get metadata value as a string by key name
|
| 699 |
+
LLAMA_API int32_t llama_adapter_meta_val_str(const struct llama_adapter_lora * adapter, const char * key, char * buf, size_t buf_size);
|
| 700 |
+
|
| 701 |
+
// Get the number of metadata key/value pairs
|
| 702 |
+
LLAMA_API int32_t llama_adapter_meta_count(const struct llama_adapter_lora * adapter);
|
| 703 |
+
|
| 704 |
+
// Get metadata key name by index
|
| 705 |
+
LLAMA_API int32_t llama_adapter_meta_key_by_index(const struct llama_adapter_lora * adapter, int32_t i, char * buf, size_t buf_size);
|
| 706 |
+
|
| 707 |
+
// Get metadata value as a string by index
|
| 708 |
+
LLAMA_API int32_t llama_adapter_meta_val_str_by_index(const struct llama_adapter_lora * adapter, int32_t i, char * buf, size_t buf_size);
|
| 709 |
+
|
| 710 |
+
// Manually free a LoRA adapter
|
| 711 |
+
// NOTE: loaded adapters that are not manually freed will be freed when the associated model is deleted
|
| 712 |
+
LLAMA_API void llama_adapter_lora_free(struct llama_adapter_lora * adapter);
|
| 713 |
+
|
| 714 |
+
// Get the invocation tokens if the current lora is an alora
|
| 715 |
+
LLAMA_API uint64_t llama_adapter_get_alora_n_invocation_tokens(const struct llama_adapter_lora * adapter);
|
| 716 |
+
LLAMA_API const llama_token * llama_adapter_get_alora_invocation_tokens (const struct llama_adapter_lora * adapter);
|
| 717 |
+
|
| 718 |
+
// The following functions operate on a llama_context, hence the naming: llama_verb_...
|
| 719 |
+
|
| 720 |
+
// Set LoRa adapters on the context. Will only modify if the adapters currently in context are different.
|
| 721 |
+
LLAMA_API int32_t llama_set_adapters_lora(
|
| 722 |
+
struct llama_context * ctx,
|
| 723 |
+
struct llama_adapter_lora ** adapters,
|
| 724 |
+
size_t n_adapters,
|
| 725 |
+
float * scales);
|
| 726 |
+
|
| 727 |
+
// Apply a loaded control vector to a llama_context, or if data is NULL, clear
|
| 728 |
+
// the currently loaded vector.
|
| 729 |
+
// n_embd should be the size of a single layer's control, and data should point
|
| 730 |
+
// to an n_embd x n_layers buffer starting from layer 1.
|
| 731 |
+
// il_start and il_end are the layer range the vector should apply to (both inclusive)
|
| 732 |
+
// See llama_control_vector_load in common to load a control vector.
|
| 733 |
+
LLAMA_API int32_t llama_set_adapter_cvec(
|
| 734 |
+
struct llama_context * ctx,
|
| 735 |
+
const float * data,
|
| 736 |
+
size_t len,
|
| 737 |
+
int32_t n_embd,
|
| 738 |
+
int32_t il_start,
|
| 739 |
+
int32_t il_end);
|
| 740 |
+
|
| 741 |
+
//
|
| 742 |
+
// Memory
|
| 743 |
+
//
|
| 744 |
+
|
| 745 |
+
// Clear the memory contents
|
| 746 |
+
// If data == true, the data buffers will also be cleared together with the metadata
|
| 747 |
+
LLAMA_API void llama_memory_clear(
|
| 748 |
+
llama_memory_t mem,
|
| 749 |
+
bool data);
|
| 750 |
+
|
| 751 |
+
// Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
|
| 752 |
+
// Returns false if a partial sequence cannot be removed. Removing a whole sequence never fails
|
| 753 |
+
// seq_id < 0 : match any sequence [TAG_LLAMA_SEQ_ID_NEG]
|
| 754 |
+
// p0 < 0 : [0, p1]
|
| 755 |
+
// p1 < 0 : [p0, inf)
|
| 756 |
+
LLAMA_API bool llama_memory_seq_rm(
|
| 757 |
+
llama_memory_t mem,
|
| 758 |
+
llama_seq_id seq_id,
|
| 759 |
+
llama_pos p0,
|
| 760 |
+
llama_pos p1);
|
| 761 |
+
|
| 762 |
+
// Copy all tokens that belong to the specified sequence to another sequence
|
| 763 |
+
// p0 < 0 : [0, p1]
|
| 764 |
+
// p1 < 0 : [p0, inf)
|
| 765 |
+
LLAMA_API void llama_memory_seq_cp(
|
| 766 |
+
llama_memory_t mem,
|
| 767 |
+
llama_seq_id seq_id_src,
|
| 768 |
+
llama_seq_id seq_id_dst,
|
| 769 |
+
llama_pos p0,
|
| 770 |
+
llama_pos p1);
|
| 771 |
+
|
| 772 |
+
// Removes all tokens that do not belong to the specified sequence
|
| 773 |
+
LLAMA_API void llama_memory_seq_keep(
|
| 774 |
+
llama_memory_t mem,
|
| 775 |
+
llama_seq_id seq_id);
|
| 776 |
+
|
| 777 |
+
// Adds relative position "delta" to all tokens that belong to the specified sequence and have positions in [p0, p1)
|
| 778 |
+
// p0 < 0 : [0, p1]
|
| 779 |
+
// p1 < 0 : [p0, inf)
|
| 780 |
+
LLAMA_API void llama_memory_seq_add(
|
| 781 |
+
llama_memory_t mem,
|
| 782 |
+
llama_seq_id seq_id,
|
| 783 |
+
llama_pos p0,
|
| 784 |
+
llama_pos p1,
|
| 785 |
+
llama_pos delta);
|
| 786 |
+
|
| 787 |
+
// Integer division of the positions by factor of `d > 1`
|
| 788 |
+
// p0 < 0 : [0, p1]
|
| 789 |
+
// p1 < 0 : [p0, inf)
|
| 790 |
+
LLAMA_API void llama_memory_seq_div(
|
| 791 |
+
llama_memory_t mem,
|
| 792 |
+
llama_seq_id seq_id,
|
| 793 |
+
llama_pos p0,
|
| 794 |
+
llama_pos p1,
|
| 795 |
+
int d);
|
| 796 |
+
|
| 797 |
+
// Returns the smallest position present in the memory for the specified sequence
|
| 798 |
+
// This is typically non-zero only for SWA caches
|
| 799 |
+
// Note that all positions in the range [pos_min, pos_max] are guaranteed to be present in the memory
|
| 800 |
+
// Return -1 if the sequence is empty
|
| 801 |
+
LLAMA_API llama_pos llama_memory_seq_pos_min(
|
| 802 |
+
llama_memory_t mem,
|
| 803 |
+
llama_seq_id seq_id);
|
| 804 |
+
|
| 805 |
+
// Returns the largest position present in the memory for the specified sequence
|
| 806 |
+
// Note that all positions in the range [pos_min, pos_max] are guaranteed to be present in the memory
|
| 807 |
+
// Return -1 if the sequence is empty
|
| 808 |
+
LLAMA_API llama_pos llama_memory_seq_pos_max(
|
| 809 |
+
llama_memory_t mem,
|
| 810 |
+
llama_seq_id seq_id);
|
| 811 |
+
|
| 812 |
+
// Check if the memory supports shifting
|
| 813 |
+
LLAMA_API bool llama_memory_can_shift(llama_memory_t mem);
|
| 814 |
+
|
| 815 |
+
//
|
| 816 |
+
// State / sessions
|
| 817 |
+
//
|
| 818 |
+
|
| 819 |
+
// Returns the *actual* size in bytes of the state
|
| 820 |
+
// (logits, embedding and memory)
|
| 821 |
+
// Only use when saving the state, not when restoring it, otherwise the size may be too small.
|
| 822 |
+
LLAMA_API size_t llama_state_get_size(struct llama_context * ctx);
|
| 823 |
+
LLAMA_API DEPRECATED(size_t llama_get_state_size(struct llama_context * ctx),
|
| 824 |
+
"use llama_state_get_size instead");
|
| 825 |
+
|
| 826 |
+
// Copies the state to the specified destination address.
|
| 827 |
+
// Destination needs to have allocated enough memory.
|
| 828 |
+
// Returns the number of bytes copied
|
| 829 |
+
LLAMA_API size_t llama_state_get_data(
|
| 830 |
+
struct llama_context * ctx,
|
| 831 |
+
uint8_t * dst,
|
| 832 |
+
size_t size);
|
| 833 |
+
LLAMA_API DEPRECATED(size_t llama_copy_state_data(
|
| 834 |
+
struct llama_context * ctx,
|
| 835 |
+
uint8_t * dst),
|
| 836 |
+
"use llama_state_get_data instead");
|
| 837 |
+
|
| 838 |
+
// Set the state reading from the specified address
|
| 839 |
+
// Returns the number of bytes read
|
| 840 |
+
LLAMA_API size_t llama_state_set_data(
|
| 841 |
+
struct llama_context * ctx,
|
| 842 |
+
const uint8_t * src,
|
| 843 |
+
size_t size);
|
| 844 |
+
LLAMA_API DEPRECATED(size_t llama_set_state_data(
|
| 845 |
+
struct llama_context * ctx,
|
| 846 |
+
const uint8_t * src),
|
| 847 |
+
"use llama_state_set_data instead");
|
| 848 |
+
|
| 849 |
+
// Save/load session file
|
| 850 |
+
LLAMA_API bool llama_state_load_file(
|
| 851 |
+
struct llama_context * ctx,
|
| 852 |
+
const char * path_session,
|
| 853 |
+
llama_token * tokens_out,
|
| 854 |
+
size_t n_token_capacity,
|
| 855 |
+
size_t * n_token_count_out);
|
| 856 |
+
LLAMA_API DEPRECATED(bool llama_load_session_file(
|
| 857 |
+
struct llama_context * ctx,
|
| 858 |
+
const char * path_session,
|
| 859 |
+
llama_token * tokens_out,
|
| 860 |
+
size_t n_token_capacity,
|
| 861 |
+
size_t * n_token_count_out),
|
| 862 |
+
"use llama_state_load_file instead");
|
| 863 |
+
|
| 864 |
+
LLAMA_API bool llama_state_save_file(
|
| 865 |
+
struct llama_context * ctx,
|
| 866 |
+
const char * path_session,
|
| 867 |
+
const llama_token * tokens,
|
| 868 |
+
size_t n_token_count);
|
| 869 |
+
LLAMA_API DEPRECATED(bool llama_save_session_file(
|
| 870 |
+
struct llama_context * ctx,
|
| 871 |
+
const char * path_session,
|
| 872 |
+
const llama_token * tokens,
|
| 873 |
+
size_t n_token_count),
|
| 874 |
+
"use llama_state_save_file instead");
|
| 875 |
+
|
| 876 |
+
// Get the exact size needed to copy the state of a single sequence
|
| 877 |
+
LLAMA_API size_t llama_state_seq_get_size(
|
| 878 |
+
struct llama_context * ctx,
|
| 879 |
+
llama_seq_id seq_id);
|
| 880 |
+
|
| 881 |
+
// Copy the state of a single sequence into the specified buffer
|
| 882 |
+
LLAMA_API size_t llama_state_seq_get_data(
|
| 883 |
+
struct llama_context * ctx,
|
| 884 |
+
uint8_t * dst,
|
| 885 |
+
size_t size,
|
| 886 |
+
llama_seq_id seq_id);
|
| 887 |
+
|
| 888 |
+
// Copy the sequence data (originally copied with `llama_state_seq_get_data`) into the specified sequence
|
| 889 |
+
// Returns:
|
| 890 |
+
// - Positive: Ok
|
| 891 |
+
// - Zero: Failed to load
|
| 892 |
+
LLAMA_API size_t llama_state_seq_set_data(
|
| 893 |
+
struct llama_context * ctx,
|
| 894 |
+
const uint8_t * src,
|
| 895 |
+
size_t size,
|
| 896 |
+
llama_seq_id dest_seq_id);
|
| 897 |
+
|
| 898 |
+
LLAMA_API size_t llama_state_seq_save_file(
|
| 899 |
+
struct llama_context * ctx,
|
| 900 |
+
const char * filepath,
|
| 901 |
+
llama_seq_id seq_id,
|
| 902 |
+
const llama_token * tokens,
|
| 903 |
+
size_t n_token_count);
|
| 904 |
+
|
| 905 |
+
// If tokens_out is NULL, only the token count is reported through n_token_count_out and no state is loaded
|
| 906 |
+
LLAMA_API size_t llama_state_seq_load_file(
|
| 907 |
+
struct llama_context * ctx,
|
| 908 |
+
const char * filepath,
|
| 909 |
+
llama_seq_id dest_seq_id,
|
| 910 |
+
llama_token * tokens_out,
|
| 911 |
+
size_t n_token_capacity,
|
| 912 |
+
size_t * n_token_count_out);
|
| 913 |
+
|
| 914 |
+
#define LLAMA_STATE_SEQ_FLAGS_NONE 0
|
| 915 |
+
|
| 916 |
+
// for backwards-compat
|
| 917 |
+
#define LLAMA_STATE_SEQ_FLAGS_SWA_ONLY 1
|
| 918 |
+
|
| 919 |
+
// work only with partial states, such as SWA KV cache or recurrent cache (e.g. Mamba)
|
| 920 |
+
#define LLAMA_STATE_SEQ_FLAGS_PARTIAL_ONLY 1
|
| 921 |
+
|
| 922 |
+
// Keeps the tensor data on device buffers (i.e. not accessible in host memory, but faster save/load).
|
| 923 |
+
// Getting the state for a seq_id with this flag invalidates all prior states gotten for that seq_id with this flag.
|
| 924 |
+
#define LLAMA_STATE_SEQ_FLAGS_ON_DEVICE 2
|
| 925 |
+
|
| 926 |
+
typedef uint32_t llama_state_seq_flags;
|
| 927 |
+
|
| 928 |
+
LLAMA_API size_t llama_state_seq_get_size_ext(
|
| 929 |
+
struct llama_context * ctx,
|
| 930 |
+
llama_seq_id seq_id,
|
| 931 |
+
llama_state_seq_flags flags);
|
| 932 |
+
|
| 933 |
+
LLAMA_API size_t llama_state_seq_get_data_ext(
|
| 934 |
+
struct llama_context * ctx,
|
| 935 |
+
uint8_t * dst,
|
| 936 |
+
size_t size,
|
| 937 |
+
llama_seq_id seq_id,
|
| 938 |
+
llama_state_seq_flags flags);
|
| 939 |
+
|
| 940 |
+
LLAMA_API size_t llama_state_seq_set_data_ext(
|
| 941 |
+
struct llama_context * ctx,
|
| 942 |
+
const uint8_t * src,
|
| 943 |
+
size_t size,
|
| 944 |
+
llama_seq_id dest_seq_id,
|
| 945 |
+
llama_state_seq_flags flags);
|
| 946 |
+
|
| 947 |
+
//
|
| 948 |
+
// Decoding
|
| 949 |
+
//
|
| 950 |
+
|
| 951 |
+
// Return batch for single sequence of tokens
|
| 952 |
+
// The sequence ID will be fixed to 0
|
| 953 |
+
// The position of the tokens will be tracked automatically by llama_decode
|
| 954 |
+
//
|
| 955 |
+
// NOTE: this is a helper function to facilitate transition to the new batch API - avoid using it
|
| 956 |
+
//
|
| 957 |
+
LLAMA_API struct llama_batch llama_batch_get_one(
|
| 958 |
+
llama_token * tokens,
|
| 959 |
+
int32_t n_tokens);
|
| 960 |
+
|
| 961 |
+
// Allocates a batch of tokens on the heap that can hold a maximum of n_tokens
|
| 962 |
+
// Each token can be assigned up to n_seq_max sequence ids
|
| 963 |
+
// The batch has to be freed with llama_batch_free()
|
| 964 |
+
// If embd != 0, llama_batch.embd will be allocated with size of n_tokens * embd * sizeof(float)
|
| 965 |
+
// Otherwise, llama_batch.token will be allocated to store n_tokens llama_token
|
| 966 |
+
// The rest of the llama_batch members are allocated with size n_tokens
|
| 967 |
+
// All members are left uninitialized
|
| 968 |
+
LLAMA_API struct llama_batch llama_batch_init(
|
| 969 |
+
int32_t n_tokens,
|
| 970 |
+
int32_t embd,
|
| 971 |
+
int32_t n_seq_max);
|
| 972 |
+
|
| 973 |
+
// Frees a batch of tokens allocated with llama_batch_init()
|
| 974 |
+
LLAMA_API void llama_batch_free(struct llama_batch batch);
|
| 975 |
+
|
| 976 |
+
// Process a batch of tokens.
|
| 977 |
+
// In contrast to llama_decode() - this call does not use KV cache.
|
| 978 |
+
// For encode-decoder contexts, processes the batch using the encoder.
|
| 979 |
+
// Can store the encoder output internally for later use by the decoder's cross-attention layers.
|
| 980 |
+
// 0 - success
|
| 981 |
+
// < 0 - error. the memory state is restored to the state before this call
|
| 982 |
+
LLAMA_API int32_t llama_encode(
|
| 983 |
+
struct llama_context * ctx,
|
| 984 |
+
struct llama_batch batch);
|
| 985 |
+
|
| 986 |
+
// Process a batch of tokens.
|
| 987 |
+
// Requires the context to have a memory.
|
| 988 |
+
// For encode-decoder contexts, processes the batch using the decoder.
|
| 989 |
+
// Positive return values does not mean a fatal error, but rather a warning.
|
| 990 |
+
// Upon fatal-error or abort, the ubatches that managed to be been processed will remain in the memory state of the context
|
| 991 |
+
// To handle this correctly, query the memory state using llama_memory_seq_pos_min() and llama_memory_seq_pos_max()
|
| 992 |
+
// Upon other return values, the memory state is restored to the state before this call
|
| 993 |
+
// 0 - success
|
| 994 |
+
// 1 - could not find a KV slot for the batch (try reducing the size of the batch or increase the context)
|
| 995 |
+
// 2 - aborted (processed ubatches will remain in the context's memory)
|
| 996 |
+
// -1 - invalid input batch
|
| 997 |
+
// < -1 - fatal error (processed ubatches will remain in the context's memory)
|
| 998 |
+
LLAMA_API int32_t llama_decode(
|
| 999 |
+
struct llama_context * ctx,
|
| 1000 |
+
struct llama_batch batch);
|
| 1001 |
+
|
| 1002 |
+
// Set the number of threads used for decoding
|
| 1003 |
+
// n_threads is the number of threads used for generation (single token)
|
| 1004 |
+
// n_threads_batch is the number of threads used for prompt and batch processing (multiple tokens)
|
| 1005 |
+
LLAMA_API void llama_set_n_threads(struct llama_context * ctx, int32_t n_threads, int32_t n_threads_batch);
|
| 1006 |
+
|
| 1007 |
+
// Get the number of threads used for generation of a single token.
|
| 1008 |
+
LLAMA_API int32_t llama_n_threads(struct llama_context * ctx);
|
| 1009 |
+
|
| 1010 |
+
// Get the number of threads used for prompt and batch processing (multiple token).
|
| 1011 |
+
LLAMA_API int32_t llama_n_threads_batch(struct llama_context * ctx);
|
| 1012 |
+
|
| 1013 |
+
// Set whether the context outputs embeddings or not
|
| 1014 |
+
// TODO: rename to avoid confusion with llama_get_embeddings()
|
| 1015 |
+
LLAMA_API void llama_set_embeddings(struct llama_context * ctx, bool embeddings);
|
| 1016 |
+
|
| 1017 |
+
// Set whether to use causal attention or not
|
| 1018 |
+
// If set to true, the model will only attend to the past tokens
|
| 1019 |
+
LLAMA_API void llama_set_causal_attn(struct llama_context * ctx, bool causal_attn);
|
| 1020 |
+
|
| 1021 |
+
// Set whether the model is in warmup mode or not
|
| 1022 |
+
// If true, all model tensors are activated during llama_decode() to load and cache their weights.
|
| 1023 |
+
//
|
| 1024 |
+
// note: using this can cause extra graph reallocations because it changes the graph topology with MoE models,
|
| 1025 |
+
// so it is generally not recommended to use in practice. will be removed in the future
|
| 1026 |
+
DEPRECATED(LLAMA_API void llama_set_warmup(struct llama_context * ctx, bool warmup),
|
| 1027 |
+
"user code should do warmup runs manually [TAG_LLAMA_GRAPH_NO_WARMUP]");
|
| 1028 |
+
|
| 1029 |
+
// Set abort callback
|
| 1030 |
+
LLAMA_API void llama_set_abort_callback(struct llama_context * ctx, ggml_abort_callback abort_callback, void * abort_callback_data);
|
| 1031 |
+
|
| 1032 |
+
// Wait until all computations are finished
|
| 1033 |
+
// This is automatically done when using one of the functions below to obtain the computation results
|
| 1034 |
+
// and is not necessary to call it explicitly in most cases
|
| 1035 |
+
LLAMA_API void llama_synchronize(struct llama_context * ctx);
|
| 1036 |
+
|
| 1037 |
+
// Token logits obtained from the last call to llama_decode()
|
| 1038 |
+
// The logits for which llama_batch.logits[i] != 0 are stored contiguously
|
| 1039 |
+
// in the order they have appeared in the batch.
|
| 1040 |
+
// Rows: number of tokens for which llama_batch.logits[i] != 0
|
| 1041 |
+
// Cols: n_vocab
|
| 1042 |
+
// TODO: deprecate in favor of llama_get_logits_ith() (ref: https://github.com/ggml-org/llama.cpp/pull/14853#issuecomment-3113143522)
|
| 1043 |
+
LLAMA_API float * llama_get_logits(struct llama_context * ctx);
|
| 1044 |
+
|
| 1045 |
+
// Logits for the ith token. For positive indices, Equivalent to:
|
| 1046 |
+
// llama_get_logits(ctx) + ctx->output_ids[i]*n_vocab
|
| 1047 |
+
// Negative indices can be used to access logits in reverse order, -1 is the last logit.
|
| 1048 |
+
// returns NULL for invalid ids.
|
| 1049 |
+
LLAMA_API float * llama_get_logits_ith(struct llama_context * ctx, int32_t i);
|
| 1050 |
+
|
| 1051 |
+
// Get all output token embeddings.
|
| 1052 |
+
// when pooling_type == LLAMA_POOLING_TYPE_NONE or when using a generative model,
|
| 1053 |
+
// the embeddings for which llama_batch.logits[i] != 0 are stored contiguously
|
| 1054 |
+
// in the order they have appeared in the batch.
|
| 1055 |
+
// shape: [n_outputs*n_embd]
|
| 1056 |
+
// Otherwise, returns NULL.
|
| 1057 |
+
// TODO: deprecate in favor of llama_get_embeddings_ith() (ref: https://github.com/ggml-org/llama.cpp/pull/14853#issuecomment-3113143522)
|
| 1058 |
+
LLAMA_API float * llama_get_embeddings(struct llama_context * ctx);
|
| 1059 |
+
|
| 1060 |
+
// Get the embeddings for the ith token. For positive indices, Equivalent to:
|
| 1061 |
+
// llama_get_embeddings(ctx) + ctx->output_ids[i]*n_embd
|
| 1062 |
+
// Negative indices can be used to access embeddings in reverse order, -1 is the last embedding.
|
| 1063 |
+
// shape: [n_embd] (1-dimensional)
|
| 1064 |
+
// returns NULL for invalid ids.
|
| 1065 |
+
LLAMA_API float * llama_get_embeddings_ith(struct llama_context * ctx, int32_t i);
|
| 1066 |
+
|
| 1067 |
+
// Get the embeddings for a sequence id
|
| 1068 |
+
// Returns NULL if pooling_type is LLAMA_POOLING_TYPE_NONE
|
| 1069 |
+
// when pooling_type == LLAMA_POOLING_TYPE_RANK, returns float[n_cls_out] with the rank(s) of the sequence
|
| 1070 |
+
// otherwise: float[n_embd] (1-dimensional)
|
| 1071 |
+
LLAMA_API float * llama_get_embeddings_seq(struct llama_context * ctx, llama_seq_id seq_id);
|
| 1072 |
+
|
| 1073 |
+
//
|
| 1074 |
+
// backend sampling API [EXPERIMENTAL]
|
| 1075 |
+
// note: use only if the llama_context was created with at least one llama_sampler_seq_config
|
| 1076 |
+
//
|
| 1077 |
+
|
| 1078 |
+
// Get the backend sampled token for the ith token.
|
| 1079 |
+
// With multiple outputs, sampler state advances when the token is accepted,
|
| 1080 |
+
// not when it is read through this function.
|
| 1081 |
+
// When accepting multiple outputs, accept a contiguous prefix in output order.
|
| 1082 |
+
// Returns LLAMA_TOKEN_NULL if no token was sampled.
|
| 1083 |
+
LLAMA_API llama_token llama_get_sampled_token_ith(struct llama_context * ctx, int32_t i);
|
| 1084 |
+
|
| 1085 |
+
// Get the backend sampled probabilities for the ith token
|
| 1086 |
+
// The index matches llama_get_sampled_token_ith().
|
| 1087 |
+
// Returns NULL if no probabilities were generated.
|
| 1088 |
+
LLAMA_API float * llama_get_sampled_probs_ith (struct llama_context * ctx, int32_t i);
|
| 1089 |
+
LLAMA_API uint32_t llama_get_sampled_probs_count_ith(struct llama_context * ctx, int32_t i);
|
| 1090 |
+
|
| 1091 |
+
// Get the backend sampled logits for the ith token
|
| 1092 |
+
// Returns NULL if no logits were sampled.
|
| 1093 |
+
LLAMA_API float * llama_get_sampled_logits_ith (struct llama_context * ctx, int32_t i);
|
| 1094 |
+
LLAMA_API uint32_t llama_get_sampled_logits_count_ith(struct llama_context * ctx, int32_t i);
|
| 1095 |
+
|
| 1096 |
+
// Get the backend sampled candidates (token ids) for the ith token
|
| 1097 |
+
// These are needed to map probability/logit indices to vocab token ids.
|
| 1098 |
+
// Returns NULL if no candidates were sampled.
|
| 1099 |
+
LLAMA_API llama_token * llama_get_sampled_candidates_ith (struct llama_context * ctx, int32_t i);
|
| 1100 |
+
LLAMA_API uint32_t llama_get_sampled_candidates_count_ith(struct llama_context * ctx, int32_t i);
|
| 1101 |
+
|
| 1102 |
+
//
|
| 1103 |
+
// Vocab
|
| 1104 |
+
//
|
| 1105 |
+
|
| 1106 |
+
LLAMA_API const char * llama_vocab_get_text(const struct llama_vocab * vocab, llama_token token);
|
| 1107 |
+
|
| 1108 |
+
LLAMA_API float llama_vocab_get_score(const struct llama_vocab * vocab, llama_token token);
|
| 1109 |
+
|
| 1110 |
+
LLAMA_API enum llama_token_attr llama_vocab_get_attr(const struct llama_vocab * vocab, llama_token token);
|
| 1111 |
+
|
| 1112 |
+
// Check if the token is supposed to end generation (end-of-generation, eg. EOS, EOT, etc.)
|
| 1113 |
+
LLAMA_API bool llama_vocab_is_eog(const struct llama_vocab * vocab, llama_token token);
|
| 1114 |
+
|
| 1115 |
+
// Identify if Token Id is a control token or a render-able token
|
| 1116 |
+
LLAMA_API bool llama_vocab_is_control(const struct llama_vocab * vocab, llama_token token);
|
| 1117 |
+
|
| 1118 |
+
// Special tokens
|
| 1119 |
+
LLAMA_API llama_token llama_vocab_bos(const struct llama_vocab * vocab); // beginning-of-sentence
|
| 1120 |
+
LLAMA_API llama_token llama_vocab_eos(const struct llama_vocab * vocab); // end-of-sentence
|
| 1121 |
+
LLAMA_API llama_token llama_vocab_eot(const struct llama_vocab * vocab); // end-of-turn
|
| 1122 |
+
LLAMA_API llama_token llama_vocab_sep(const struct llama_vocab * vocab); // sentence separator
|
| 1123 |
+
LLAMA_API llama_token llama_vocab_nl (const struct llama_vocab * vocab); // next-line
|
| 1124 |
+
LLAMA_API llama_token llama_vocab_pad(const struct llama_vocab * vocab); // padding
|
| 1125 |
+
LLAMA_API llama_token llama_vocab_mask(const struct llama_vocab * vocab); // mask
|
| 1126 |
+
|
| 1127 |
+
LLAMA_API bool llama_vocab_get_add_bos(const struct llama_vocab * vocab);
|
| 1128 |
+
LLAMA_API bool llama_vocab_get_add_eos(const struct llama_vocab * vocab);
|
| 1129 |
+
LLAMA_API bool llama_vocab_get_add_sep(const struct llama_vocab * vocab);
|
| 1130 |
+
|
| 1131 |
+
// model-specific suppress tokens (gguf key: tokenizer.ggml.suppress_tokens)
|
| 1132 |
+
LLAMA_API const llama_token * llama_vocab_get_suppress_tokens(const struct llama_vocab * vocab, int32_t * n_suppress_tokens);
|
| 1133 |
+
|
| 1134 |
+
LLAMA_API llama_token llama_vocab_fim_pre(const struct llama_vocab * vocab);
|
| 1135 |
+
LLAMA_API llama_token llama_vocab_fim_suf(const struct llama_vocab * vocab);
|
| 1136 |
+
LLAMA_API llama_token llama_vocab_fim_mid(const struct llama_vocab * vocab);
|
| 1137 |
+
LLAMA_API llama_token llama_vocab_fim_pad(const struct llama_vocab * vocab);
|
| 1138 |
+
LLAMA_API llama_token llama_vocab_fim_rep(const struct llama_vocab * vocab);
|
| 1139 |
+
LLAMA_API llama_token llama_vocab_fim_sep(const struct llama_vocab * vocab);
|
| 1140 |
+
|
| 1141 |
+
DEPRECATED(LLAMA_API const char * llama_token_get_text(const struct llama_vocab * vocab, llama_token token), "use llama_vocab_get_text instead");
|
| 1142 |
+
DEPRECATED(LLAMA_API float llama_token_get_score(const struct llama_vocab * vocab, llama_token token), "use llama_vocab_get_score instead");
|
| 1143 |
+
DEPRECATED(LLAMA_API enum llama_token_attr llama_token_get_attr(const struct llama_vocab * vocab, llama_token token), "use llama_vocab_get_attr instead");
|
| 1144 |
+
DEPRECATED(LLAMA_API bool llama_token_is_eog(const struct llama_vocab * vocab, llama_token token), "use llama_vocab_is_eog instead");
|
| 1145 |
+
DEPRECATED(LLAMA_API bool llama_token_is_control(const struct llama_vocab * vocab, llama_token token), "use llama_vocab_is_control instead");
|
| 1146 |
+
DEPRECATED(LLAMA_API llama_token llama_token_bos(const struct llama_vocab * vocab), "use llama_vocab_bos instead");
|
| 1147 |
+
DEPRECATED(LLAMA_API llama_token llama_token_eos(const struct llama_vocab * vocab), "use llama_vocab_eos instead");
|
| 1148 |
+
DEPRECATED(LLAMA_API llama_token llama_token_eot(const struct llama_vocab * vocab), "use llama_vocab_eot instead");
|
| 1149 |
+
DEPRECATED(LLAMA_API llama_token llama_token_cls(const struct llama_vocab * vocab), "use llama_vocab_cls instead");
|
| 1150 |
+
DEPRECATED(LLAMA_API llama_token llama_token_sep(const struct llama_vocab * vocab), "use llama_vocab_sep instead");
|
| 1151 |
+
DEPRECATED(LLAMA_API llama_token llama_token_nl (const struct llama_vocab * vocab), "use llama_vocab_nl instead");
|
| 1152 |
+
DEPRECATED(LLAMA_API llama_token llama_token_pad(const struct llama_vocab * vocab), "use llama_vocab_pad instead");
|
| 1153 |
+
DEPRECATED(LLAMA_API bool llama_add_bos_token(const struct llama_vocab * vocab), "use llama_vocab_get_add_bos instead");
|
| 1154 |
+
DEPRECATED(LLAMA_API bool llama_add_eos_token(const struct llama_vocab * vocab), "use llama_vocab_get_add_eos instead");
|
| 1155 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_pre(const struct llama_vocab * vocab), "use llama_vocab_fim_pre instead");
|
| 1156 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_suf(const struct llama_vocab * vocab), "use llama_vocab_fim_suf instead");
|
| 1157 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_mid(const struct llama_vocab * vocab), "use llama_vocab_fim_mid instead");
|
| 1158 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_pad(const struct llama_vocab * vocab), "use llama_vocab_fim_pad instead");
|
| 1159 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_rep(const struct llama_vocab * vocab), "use llama_vocab_fim_rep instead");
|
| 1160 |
+
DEPRECATED(LLAMA_API llama_token llama_token_fim_sep(const struct llama_vocab * vocab), "use llama_vocab_fim_sep instead");
|
| 1161 |
+
|
| 1162 |
+
// CLS is equivalent to BOS
|
| 1163 |
+
DEPRECATED(LLAMA_API llama_token llama_vocab_cls(const struct llama_vocab * vocab), // classification
|
| 1164 |
+
"use llama_vocab_bos instead");
|
| 1165 |
+
|
| 1166 |
+
//
|
| 1167 |
+
// Tokenization
|
| 1168 |
+
//
|
| 1169 |
+
// The API is thread-safe.
|
| 1170 |
+
//
|
| 1171 |
+
|
| 1172 |
+
/// @details Convert the provided text into tokens.
|
| 1173 |
+
/// @param tokens The tokens pointer must be large enough to hold the resulting tokens.
|
| 1174 |
+
/// @return Returns the number of tokens on success, no more than n_tokens_max
|
| 1175 |
+
/// @return Returns a negative number on failure - the number of tokens that would have been returned
|
| 1176 |
+
/// @return Returns INT32_MIN on overflow (e.g., tokenization result size exceeds int32_t limit)
|
| 1177 |
+
/// @param add_special Allow to add BOS and EOS tokens if model is configured to do so.
|
| 1178 |
+
/// @param parse_special Allow tokenizing special and/or control tokens which otherwise are not exposed and treated
|
| 1179 |
+
/// as plaintext. Does not insert a leading space.
|
| 1180 |
+
LLAMA_API int32_t llama_tokenize(
|
| 1181 |
+
const struct llama_vocab * vocab,
|
| 1182 |
+
const char * text,
|
| 1183 |
+
int32_t text_len,
|
| 1184 |
+
llama_token * tokens,
|
| 1185 |
+
int32_t n_tokens_max,
|
| 1186 |
+
bool add_special,
|
| 1187 |
+
bool parse_special);
|
| 1188 |
+
|
| 1189 |
+
// Token Id -> Piece.
|
| 1190 |
+
// Uses the vocabulary in the provided context.
|
| 1191 |
+
// Does not write null terminator to the buffer.
|
| 1192 |
+
// User can skip up to 'lstrip' leading spaces before copying (useful when encoding/decoding multiple tokens with 'add_space_prefix')
|
| 1193 |
+
// @param special If true, special tokens are rendered in the output.
|
| 1194 |
+
LLAMA_API int32_t llama_token_to_piece(
|
| 1195 |
+
const struct llama_vocab * vocab,
|
| 1196 |
+
llama_token token,
|
| 1197 |
+
char * buf,
|
| 1198 |
+
int32_t length,
|
| 1199 |
+
int32_t lstrip,
|
| 1200 |
+
bool special);
|
| 1201 |
+
|
| 1202 |
+
/// @details Convert the provided tokens into text (inverse of llama_tokenize()).
|
| 1203 |
+
/// @param text The char pointer must be large enough to hold the resulting text.
|
| 1204 |
+
/// @return Returns the number of chars/bytes on success, no more than text_len_max.
|
| 1205 |
+
/// @return Returns a negative number on failure - the number of chars/bytes that would have been returned.
|
| 1206 |
+
/// @param remove_special Allow to remove BOS and EOS tokens if model is configured to do so.
|
| 1207 |
+
/// @param unparse_special If true, special tokens are rendered in the output.
|
| 1208 |
+
LLAMA_API int32_t llama_detokenize(
|
| 1209 |
+
const struct llama_vocab * vocab,
|
| 1210 |
+
const llama_token * tokens,
|
| 1211 |
+
int32_t n_tokens,
|
| 1212 |
+
char * text,
|
| 1213 |
+
int32_t text_len_max,
|
| 1214 |
+
bool remove_special,
|
| 1215 |
+
bool unparse_special);
|
| 1216 |
+
|
| 1217 |
+
//
|
| 1218 |
+
// Chat templates
|
| 1219 |
+
//
|
| 1220 |
+
|
| 1221 |
+
/// Apply chat template. Inspired by hf apply_chat_template() on python.
|
| 1222 |
+
///
|
| 1223 |
+
/// NOTE: This function does not use a jinja parser. It only support a pre-defined list of template. See more: https://github.com/ggml-org/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template
|
| 1224 |
+
/// @param tmpl A Jinja template to use for this chat.
|
| 1225 |
+
/// @param chat Pointer to a list of multiple llama_chat_message
|
| 1226 |
+
/// @param n_msg Number of llama_chat_message in this chat
|
| 1227 |
+
/// @param add_ass Whether to end the prompt with the token(s) that indicate the start of an assistant message.
|
| 1228 |
+
/// @param buf A buffer to hold the output formatted prompt. The recommended alloc size is 2 * (total number of characters of all messages)
|
| 1229 |
+
/// @param length The size of the allocated buffer
|
| 1230 |
+
/// @return The total number of bytes of the formatted prompt. If is it larger than the size of buffer, you may need to re-alloc it and then re-apply the template.
|
| 1231 |
+
LLAMA_API int32_t llama_chat_apply_template(
|
| 1232 |
+
const char * tmpl,
|
| 1233 |
+
const struct llama_chat_message * chat,
|
| 1234 |
+
size_t n_msg,
|
| 1235 |
+
bool add_ass,
|
| 1236 |
+
char * buf,
|
| 1237 |
+
int32_t length);
|
| 1238 |
+
|
| 1239 |
+
// Get list of built-in chat templates
|
| 1240 |
+
LLAMA_API int32_t llama_chat_builtin_templates(const char ** output, size_t len);
|
| 1241 |
+
|
| 1242 |
+
//
|
| 1243 |
+
// Sampling API
|
| 1244 |
+
//
|
| 1245 |
+
// Sample usage:
|
| 1246 |
+
//
|
| 1247 |
+
// // prepare the sampling chain at the start
|
| 1248 |
+
// auto sparams = llama_sampler_chain_default_params();
|
| 1249 |
+
//
|
| 1250 |
+
// llama_sampler * smpl = llama_sampler_chain_init(sparams);
|
| 1251 |
+
//
|
| 1252 |
+
// llama_sampler_chain_add(smpl, llama_sampler_init_top_k(50));
|
| 1253 |
+
// llama_sampler_chain_add(smpl, llama_sampler_init_top_p(0.9, 1));
|
| 1254 |
+
// llama_sampler_chain_add(smpl, llama_sampler_init_temp (0.8));
|
| 1255 |
+
//
|
| 1256 |
+
// // typically, the chain should end with a sampler such as "greedy", "dist" or "mirostat"
|
| 1257 |
+
// // this sampler will be responsible to select the actual token
|
| 1258 |
+
// llama_sampler_chain_add(smpl, llama_sampler_init_dist(seed));
|
| 1259 |
+
//
|
| 1260 |
+
// ...
|
| 1261 |
+
//
|
| 1262 |
+
// // decoding loop:
|
| 1263 |
+
// while (...) {
|
| 1264 |
+
// ...
|
| 1265 |
+
//
|
| 1266 |
+
// llama_decode(ctx, batch);
|
| 1267 |
+
//
|
| 1268 |
+
// // sample from the logits of the last token in the batch
|
| 1269 |
+
// const llama_token id = llama_sampler_sample(smpl, ctx, -1);
|
| 1270 |
+
//
|
| 1271 |
+
// ...
|
| 1272 |
+
// }
|
| 1273 |
+
//
|
| 1274 |
+
// llama_sampler_free(smpl);
|
| 1275 |
+
//
|
| 1276 |
+
|
| 1277 |
+
typedef void * llama_sampler_context_t;
|
| 1278 |
+
|
| 1279 |
+
struct llama_sampler_data {
|
| 1280 |
+
struct ggml_tensor * logits;
|
| 1281 |
+
struct ggml_tensor * probs;
|
| 1282 |
+
struct ggml_tensor * sampled;
|
| 1283 |
+
struct ggml_tensor * candidates;
|
| 1284 |
+
};
|
| 1285 |
+
|
| 1286 |
+
// user code can implement the interface below in order to create custom llama_sampler
|
| 1287 |
+
struct llama_sampler_i {
|
| 1288 |
+
const char * (*name) (const struct llama_sampler * smpl); // can be NULL
|
| 1289 |
+
void (*accept)( struct llama_sampler * smpl, llama_token token); // can be NULL
|
| 1290 |
+
void (*apply) ( struct llama_sampler * smpl, llama_token_data_array * cur_p); // required
|
| 1291 |
+
void (*reset) ( struct llama_sampler * smpl); // can be NULL
|
| 1292 |
+
struct llama_sampler * (*clone) (const struct llama_sampler * smpl); // can be NULL if ctx is NULL
|
| 1293 |
+
void (*free) ( struct llama_sampler * smpl); // can be NULL if ctx is NULL
|
| 1294 |
+
|
| 1295 |
+
// [EXPERIMENTAL]
|
| 1296 |
+
// backend sampling interface:
|
| 1297 |
+
|
| 1298 |
+
// return true if the backend supports all ops needed by the sampler and can handle up to n_outputs_max_per_seq outputs per sequence
|
| 1299 |
+
// note: call once per sampler
|
| 1300 |
+
bool (*backend_init)(
|
| 1301 |
+
struct llama_sampler * smpl,
|
| 1302 |
+
ggml_backend_buffer_type_t buft,
|
| 1303 |
+
uint32_t n_outputs_max_per_seq);
|
| 1304 |
+
|
| 1305 |
+
// call after .backend_apply()
|
| 1306 |
+
void (*backend_accept)(
|
| 1307 |
+
struct llama_sampler * smpl,
|
| 1308 |
+
struct ggml_context * ctx,
|
| 1309 |
+
struct ggml_cgraph * gf,
|
| 1310 |
+
struct ggml_tensor * selected_token);
|
| 1311 |
+
|
| 1312 |
+
// call after .backend_init()
|
| 1313 |
+
void (*backend_apply)(
|
| 1314 |
+
struct llama_sampler * smpl,
|
| 1315 |
+
struct ggml_context * ctx,
|
| 1316 |
+
struct ggml_cgraph * gf,
|
| 1317 |
+
struct llama_sampler_data * data);
|
| 1318 |
+
|
| 1319 |
+
// called before graph execution to set inputs for the current ubatch
|
| 1320 |
+
void (*backend_set_input)(struct llama_sampler * smpl);
|
| 1321 |
+
|
| 1322 |
+
// called before rebuilding a sampling graph to clear any internal sampler state
|
| 1323 |
+
void (*backend_reset)(struct llama_sampler * smpl);
|
| 1324 |
+
|
| 1325 |
+
// copy mutable state from src into dst while keeping dst's references to the current sampling graph
|
| 1326 |
+
// src and dst must have the same type and configuration
|
| 1327 |
+
void (*copy_state)(const struct llama_sampler * src, struct llama_sampler * dst);
|
| 1328 |
+
};
|
| 1329 |
+
|
| 1330 |
+
struct llama_sampler {
|
| 1331 |
+
struct llama_sampler_i * iface;
|
| 1332 |
+
|
| 1333 |
+
llama_sampler_context_t ctx;
|
| 1334 |
+
};
|
| 1335 |
+
|
| 1336 |
+
// [EXPERIMENTAL]
|
| 1337 |
+
// attach a sampler to the context
|
| 1338 |
+
// note: prefer initializing the context with llama_context_params.samplers when possible
|
| 1339 |
+
LLAMA_API bool llama_set_sampler(struct llama_context * ctx, llama_seq_id seq_id, struct llama_sampler * smpl);
|
| 1340 |
+
|
| 1341 |
+
// mirror of llama_sampler_i:
|
| 1342 |
+
LLAMA_API struct llama_sampler * llama_sampler_init ( struct llama_sampler_i * iface, llama_sampler_context_t ctx);
|
| 1343 |
+
LLAMA_API const char * llama_sampler_name (const struct llama_sampler * smpl);
|
| 1344 |
+
LLAMA_API void llama_sampler_accept( struct llama_sampler * smpl, llama_token token);
|
| 1345 |
+
LLAMA_API void llama_sampler_apply ( struct llama_sampler * smpl, llama_token_data_array * cur_p);
|
| 1346 |
+
LLAMA_API void llama_sampler_reset ( struct llama_sampler * smpl);
|
| 1347 |
+
LLAMA_API struct llama_sampler * llama_sampler_clone (const struct llama_sampler * smpl);
|
| 1348 |
+
LLAMA_API void llama_sampler_copy (const struct llama_sampler * src, struct llama_sampler * dst);
|
| 1349 |
+
// important: do not free if the sampler has been added to a llama_sampler_chain (via llama_sampler_chain_add)
|
| 1350 |
+
LLAMA_API void llama_sampler_free ( struct llama_sampler * smpl);
|
| 1351 |
+
|
| 1352 |
+
// llama_sampler_chain
|
| 1353 |
+
// a type of llama_sampler that can chain multiple samplers one after another
|
| 1354 |
+
|
| 1355 |
+
LLAMA_API struct llama_sampler * llama_sampler_chain_init(struct llama_sampler_chain_params params);
|
| 1356 |
+
|
| 1357 |
+
// important: takes ownership of the sampler object and will free it when llama_sampler_free is called
|
| 1358 |
+
LLAMA_API void llama_sampler_chain_add( struct llama_sampler * chain, struct llama_sampler * smpl);
|
| 1359 |
+
|
| 1360 |
+
// return NULL if:
|
| 1361 |
+
// - the sampler is NULL
|
| 1362 |
+
// - the sampler is not a llama_sampler_chain
|
| 1363 |
+
// - the index is out of bounds, unless i == -1
|
| 1364 |
+
// - if i == -1, returns the chain itself (can be used to check if the sampler is a chain)
|
| 1365 |
+
LLAMA_API struct llama_sampler * llama_sampler_chain_get( struct llama_sampler * chain, int32_t i);
|
| 1366 |
+
|
| 1367 |
+
// the total number of samplers in the chain
|
| 1368 |
+
LLAMA_API int32_t llama_sampler_chain_n (const struct llama_sampler * chain);
|
| 1369 |
+
|
| 1370 |
+
// after removing a sampler, the chain will no longer own it, and it will not be freed when the chain is freed
|
| 1371 |
+
LLAMA_API struct llama_sampler * llama_sampler_chain_remove( struct llama_sampler * chain, int32_t i);
|
| 1372 |
+
|
| 1373 |
+
// available samplers:
|
| 1374 |
+
|
| 1375 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_greedy(void);
|
| 1376 |
+
|
| 1377 |
+
/// seed == LLAMA_DEFAULT_SEED to use a random seed.
|
| 1378 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_dist(uint32_t seed);
|
| 1379 |
+
|
| 1380 |
+
/// @details Top-K sampling described in academic paper "The Curious Case of Neural Text Degeneration" https://arxiv.org/abs/1904.09751
|
| 1381 |
+
/// Setting k <= 0 makes this a noop
|
| 1382 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_top_k (int32_t k);
|
| 1383 |
+
|
| 1384 |
+
/// @details Nucleus sampling described in academic paper "The Curious Case of Neural Text Degeneration" https://arxiv.org/abs/1904.09751
|
| 1385 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_top_p (float p, size_t min_keep);
|
| 1386 |
+
|
| 1387 |
+
/// @details Minimum P sampling as described in https://github.com/ggml-org/llama.cpp/pull/3841
|
| 1388 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_min_p (float p, size_t min_keep);
|
| 1389 |
+
|
| 1390 |
+
/// @details Locally Typical Sampling implementation described in the paper https://arxiv.org/abs/2202.00666.
|
| 1391 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_typical (float p, size_t min_keep);
|
| 1392 |
+
|
| 1393 |
+
/// #details Updates the logits l_i` = l_i/t. When t <= 0.0f, the maximum logit is kept at it's original value, the rest are set to -inf
|
| 1394 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_temp (float t);
|
| 1395 |
+
|
| 1396 |
+
/// @details Dynamic temperature implementation (a.k.a. entropy) described in the paper https://arxiv.org/abs/2309.02772.
|
| 1397 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_temp_ext (float t, float delta, float exponent);
|
| 1398 |
+
|
| 1399 |
+
/// @details XTC sampler as described in https://github.com/oobabooga/text-generation-webui/pull/6335
|
| 1400 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_xtc (float p, float t, size_t min_keep, uint32_t seed);
|
| 1401 |
+
|
| 1402 |
+
/// @details Top n sigma sampling as described in academic paper "Top-nσ: Not All Logits Are You Need" https://arxiv.org/pdf/2411.07641
|
| 1403 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_top_n_sigma(float n);
|
| 1404 |
+
|
| 1405 |
+
/// @details Mirostat 1.0 algorithm described in the paper https://arxiv.org/abs/2007.14966. Uses tokens instead of words.
|
| 1406 |
+
/// @param candidates A vector of `llama_token_data` containing the candidate tokens, their probabilities (p), and log-odds (logit) for the current position in the generated text.
|
| 1407 |
+
/// @param tau The target cross-entropy (or surprise) value you want to achieve for the generated text. A higher value corresponds to more surprising or less predictable text, while a lower value corresponds to less surprising or more predictable text.
|
| 1408 |
+
/// @param eta The learning rate used to update `mu` based on the error between the target and observed surprisal of the sampled word. A larger learning rate will cause `mu` to be updated more quickly, while a smaller learning rate will result in slower updates.
|
| 1409 |
+
/// @param m The number of tokens considered in the estimation of `s_hat`. This is an arbitrary value that is used to calculate `s_hat`, which in turn helps to calculate the value of `k`. In the paper, they use `m = 100`, but you can experiment with different values to see how it affects the performance of the algorithm.
|
| 1410 |
+
/// @param mu Maximum cross-entropy. This value is initialized to be twice the target cross-entropy (`2 * tau`) and is updated in the algorithm based on the error between the target and observed surprisal.
|
| 1411 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_mirostat(
|
| 1412 |
+
int32_t n_vocab,
|
| 1413 |
+
uint32_t seed,
|
| 1414 |
+
float tau,
|
| 1415 |
+
float eta,
|
| 1416 |
+
int32_t m);
|
| 1417 |
+
|
| 1418 |
+
/// @details Mirostat 2.0 algorithm described in the paper https://arxiv.org/abs/2007.14966. Uses tokens instead of words.
|
| 1419 |
+
/// @param candidates A vector of `llama_token_data` containing the candidate tokens, their probabilities (p), and log-odds (logit) for the current position in the generated text.
|
| 1420 |
+
/// @param tau The target cross-entropy (or surprise) value you want to achieve for the generated text. A higher value corresponds to more surprising or less predictable text, while a lower value corresponds to less surprising or more predictable text.
|
| 1421 |
+
/// @param eta The learning rate used to update `mu` based on the error between the target and observed surprisal of the sampled word. A larger learning rate will cause `mu` to be updated more quickly, while a smaller learning rate will result in slower updates.
|
| 1422 |
+
/// @param mu Maximum cross-entropy. This value is initialized to be twice the target cross-entropy (`2 * tau`) and is updated in the algorithm based on the error between the target and observed surprisal.
|
| 1423 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_mirostat_v2(
|
| 1424 |
+
uint32_t seed,
|
| 1425 |
+
float tau,
|
| 1426 |
+
float eta);
|
| 1427 |
+
|
| 1428 |
+
/// @details Initializes a GBNF grammar, see grammars/README.md for details.
|
| 1429 |
+
/// @param vocab The vocabulary that this grammar will be used with.
|
| 1430 |
+
/// @param grammar_str The production rules for the grammar, encoded as a string. Returns an empty grammar if empty. Returns NULL if parsing of grammar_str fails.
|
| 1431 |
+
/// @param grammar_root The name of the start symbol for the grammar.
|
| 1432 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_grammar(
|
| 1433 |
+
const struct llama_vocab * vocab,
|
| 1434 |
+
const char * grammar_str,
|
| 1435 |
+
const char * grammar_root);
|
| 1436 |
+
|
| 1437 |
+
DEPRECATED(LLAMA_API struct llama_sampler * llama_sampler_init_grammar_lazy(
|
| 1438 |
+
const struct llama_vocab * vocab,
|
| 1439 |
+
const char * grammar_str,
|
| 1440 |
+
const char * grammar_root,
|
| 1441 |
+
const char ** trigger_words,
|
| 1442 |
+
size_t num_trigger_words,
|
| 1443 |
+
const llama_token * trigger_tokens,
|
| 1444 |
+
size_t num_trigger_tokens),
|
| 1445 |
+
"use llama_sampler_init_grammar_lazy_patterns instead");
|
| 1446 |
+
|
| 1447 |
+
|
| 1448 |
+
/// @details Lazy grammar sampler, introduced in https://github.com/ggml-org/llama.cpp/pull/9639
|
| 1449 |
+
/// @param trigger_patterns A list of patterns that will trigger the grammar sampler. Pattern will be matched from the start of the generation output, and grammar sampler will be fed content starting from its first match group.
|
| 1450 |
+
/// @param trigger_tokens A list of tokens that will trigger the grammar sampler. Grammar sampler will be fed content starting from the trigger token included.
|
| 1451 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_grammar_lazy_patterns(
|
| 1452 |
+
const struct llama_vocab * vocab,
|
| 1453 |
+
const char * grammar_str,
|
| 1454 |
+
const char * grammar_root,
|
| 1455 |
+
const char ** trigger_patterns,
|
| 1456 |
+
size_t num_trigger_patterns,
|
| 1457 |
+
const llama_token * trigger_tokens,
|
| 1458 |
+
size_t num_trigger_tokens);
|
| 1459 |
+
|
| 1460 |
+
|
| 1461 |
+
/// NOTE: Avoid using on the full vocabulary as searching for repeated tokens can become slow. For example, apply top-k or top-p sampling first.
|
| 1462 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_penalties(
|
| 1463 |
+
int32_t n_vocab,
|
| 1464 |
+
int32_t penalty_last_n, // last n tokens to penalize (0 = disable penalty)
|
| 1465 |
+
float penalty_repeat, // must be > 0.0, 1.0 = disabled
|
| 1466 |
+
float penalty_freq, // must be finite, 0.0 = disabled
|
| 1467 |
+
float penalty_present); // must be finite, 0.0 = disabled
|
| 1468 |
+
|
| 1469 |
+
/// @details DRY sampler, designed by p-e-w, as described in: https://github.com/oobabooga/text-generation-webui/pull/5677, porting Koboldcpp implementation authored by pi6am: https://github.com/LostRuins/koboldcpp/pull/982
|
| 1470 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_dry(
|
| 1471 |
+
const struct llama_vocab * vocab,
|
| 1472 |
+
float dry_multiplier,
|
| 1473 |
+
float dry_base,
|
| 1474 |
+
int32_t dry_allowed_length,
|
| 1475 |
+
int32_t dry_penalty_last_n, // last n tokens to penalize (0 = disable penalty)
|
| 1476 |
+
const char ** seq_breakers,
|
| 1477 |
+
size_t num_breakers);
|
| 1478 |
+
|
| 1479 |
+
/// adaptive-p: select tokens near a configurable target probability over time.
|
| 1480 |
+
///
|
| 1481 |
+
/// the adaptive-p sampler transforms the token probability distribution to favor tokens
|
| 1482 |
+
/// that fall near a user-configurable probability target.
|
| 1483 |
+
///
|
| 1484 |
+
/// internally, the sampler maintains an exponential moving average of the *ORIGINAL*
|
| 1485 |
+
/// probabilities of selected tokens at each sampling step. it uses this EMA to compute an
|
| 1486 |
+
/// adapted target probability at each sampling step, thus maintaining the desired target
|
| 1487 |
+
/// probability over time.
|
| 1488 |
+
///
|
| 1489 |
+
/// adaptive-p selects a token ID rather than just mutating candidates, so it must be last
|
| 1490 |
+
/// in the sampler chain (like mirostat, dist, greedy).
|
| 1491 |
+
///
|
| 1492 |
+
/// only mild truncation before this sampler is recommended. we suggest applying min-p
|
| 1493 |
+
/// before adaptive-p as the only other active sampler in the chain.
|
| 1494 |
+
///
|
| 1495 |
+
/// @param target select tokens near this probability (valid range 0.0 to 1.0; negative = disabled)
|
| 1496 |
+
/// @param decay EMA decay for adaptation; history ≈ 1/(1-decay) tokens (valid range 0.0 - 0.99)
|
| 1497 |
+
/// @param seed RNG seed
|
| 1498 |
+
///
|
| 1499 |
+
/// ref: https://github.com/ggml-org/llama.cpp/pull/17927
|
| 1500 |
+
///
|
| 1501 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_adaptive_p(
|
| 1502 |
+
float target,
|
| 1503 |
+
float decay,
|
| 1504 |
+
uint32_t seed);
|
| 1505 |
+
|
| 1506 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_logit_bias(
|
| 1507 |
+
int32_t n_vocab,
|
| 1508 |
+
int32_t n_logit_bias,
|
| 1509 |
+
const llama_logit_bias * logit_bias);
|
| 1510 |
+
|
| 1511 |
+
// this sampler is meant to be used for fill-in-the-middle infilling
|
| 1512 |
+
// it's supposed to be used after top_k + top_p sampling
|
| 1513 |
+
//
|
| 1514 |
+
// 1. if the sum of the EOG probs times the number of candidates is higher than the sum of the other probs -> pick EOG
|
| 1515 |
+
// 2. combine probs of tokens that have the same prefix
|
| 1516 |
+
//
|
| 1517 |
+
// example:
|
| 1518 |
+
//
|
| 1519 |
+
// - before:
|
| 1520 |
+
// "hel": 0.5
|
| 1521 |
+
// "hell": 0.2
|
| 1522 |
+
// "hello": 0.1
|
| 1523 |
+
// "dummy": 0.1
|
| 1524 |
+
//
|
| 1525 |
+
// - after:
|
| 1526 |
+
// "hel": 0.8
|
| 1527 |
+
// "dummy": 0.1
|
| 1528 |
+
//
|
| 1529 |
+
// 3. discard non-EOG tokens with low prob
|
| 1530 |
+
// 4. if no tokens are left -> pick EOT
|
| 1531 |
+
//
|
| 1532 |
+
LLAMA_API struct llama_sampler * llama_sampler_init_infill(const struct llama_vocab * vocab);
|
| 1533 |
+
|
| 1534 |
+
// Returns the seed used by the sampler if applicable, LLAMA_DEFAULT_SEED otherwise
|
| 1535 |
+
LLAMA_API uint32_t llama_sampler_get_seed(const struct llama_sampler * smpl);
|
| 1536 |
+
|
| 1537 |
+
/// @details Sample and accept a token from the idx-th output of the last evaluation
|
| 1538 |
+
// For multiple outputs from one sampler, call this function in output order without gaps.
|
| 1539 |
+
//
|
| 1540 |
+
// Shorthand for:
|
| 1541 |
+
// const auto * logits = llama_get_logits_ith(ctx, idx);
|
| 1542 |
+
// llama_token_data_array cur_p = { ... init from logits ... };
|
| 1543 |
+
// llama_sampler_apply(smpl, &cur_p);
|
| 1544 |
+
// auto token = cur_p.data[cur_p.selected].id;
|
| 1545 |
+
// llama_sampler_accept(smpl, token);
|
| 1546 |
+
// return token;
|
| 1547 |
+
// Returns the sampled token
|
| 1548 |
+
LLAMA_API llama_token llama_sampler_sample(struct llama_sampler * smpl, struct llama_context * ctx, int32_t idx);
|
| 1549 |
+
|
| 1550 |
+
// TODO: extend in the future
|
| 1551 |
+
//LLAMA_API void llama_decode_with_sampler(struct llama_context * ctx, struct llama_sampler * smpl, struct llama_batch batch, ...);
|
| 1552 |
+
|
| 1553 |
+
//
|
| 1554 |
+
// Model split
|
| 1555 |
+
//
|
| 1556 |
+
|
| 1557 |
+
/// @details Build a split GGUF final path for this chunk.
|
| 1558 |
+
/// llama_split_path(split_path, sizeof(split_path), "/models/ggml-model-q4_0", 2, 4) => split_path = "/models/ggml-model-q4_0-00002-of-00004.gguf"
|
| 1559 |
+
// Returns the split_path length.
|
| 1560 |
+
LLAMA_API int32_t llama_split_path(char * split_path, size_t maxlen, const char * path_prefix, int32_t split_no, int32_t split_count);
|
| 1561 |
+
|
| 1562 |
+
/// @details Extract the path prefix from the split_path if and only if the split_no and split_count match.
|
| 1563 |
+
/// llama_split_prefix(split_prefix, 64, "/models/ggml-model-q4_0-00002-of-00004.gguf", 2, 4) => split_prefix = "/models/ggml-model-q4_0"
|
| 1564 |
+
// Returns the split_prefix length.
|
| 1565 |
+
LLAMA_API int32_t llama_split_prefix(char * split_prefix, size_t maxlen, const char * split_path, int32_t split_no, int32_t split_count);
|
| 1566 |
+
|
| 1567 |
+
// Print system information
|
| 1568 |
+
LLAMA_API const char * llama_print_system_info(void);
|
| 1569 |
+
|
| 1570 |
+
// Set callback for all future logging events.
|
| 1571 |
+
// If this is not called, or NULL is supplied, everything is output on stderr.
|
| 1572 |
+
// The logger state is global so these functions are NOT thread safe.
|
| 1573 |
+
LLAMA_API void llama_log_get(ggml_log_callback * log_callback, void ** user_data);
|
| 1574 |
+
LLAMA_API void llama_log_set(ggml_log_callback log_callback, void * user_data);
|
| 1575 |
+
|
| 1576 |
+
//
|
| 1577 |
+
// Performance utils
|
| 1578 |
+
//
|
| 1579 |
+
// NOTE: Used by llama.cpp examples/tools, avoid using in third-party apps. Instead, do your own performance measurements.
|
| 1580 |
+
//
|
| 1581 |
+
|
| 1582 |
+
struct llama_perf_context_data {
|
| 1583 |
+
// ms == milliseconds
|
| 1584 |
+
double t_start_ms; // absolute start time
|
| 1585 |
+
double t_load_ms; // time needed for loading the model
|
| 1586 |
+
double t_p_eval_ms; // time needed for processing the prompt
|
| 1587 |
+
double t_eval_ms; // time needed for generating tokens
|
| 1588 |
+
|
| 1589 |
+
int32_t n_p_eval; // number of prompt tokens
|
| 1590 |
+
int32_t n_eval; // number of generated tokens
|
| 1591 |
+
int32_t n_reused; // number of times a ggml compute graph had been reused
|
| 1592 |
+
};
|
| 1593 |
+
|
| 1594 |
+
struct llama_perf_sampler_data {
|
| 1595 |
+
double t_sample_ms; // time needed for sampling in ms
|
| 1596 |
+
|
| 1597 |
+
int32_t n_sample; // number of sampled tokens
|
| 1598 |
+
};
|
| 1599 |
+
|
| 1600 |
+
LLAMA_API struct llama_perf_context_data llama_perf_context (const struct llama_context * ctx);
|
| 1601 |
+
LLAMA_API void llama_perf_context_print(const struct llama_context * ctx);
|
| 1602 |
+
LLAMA_API void llama_perf_context_reset( struct llama_context * ctx);
|
| 1603 |
+
|
| 1604 |
+
// NOTE: the following work only with samplers constructed via llama_sampler_chain_init
|
| 1605 |
+
LLAMA_API struct llama_perf_sampler_data llama_perf_sampler (const struct llama_sampler * chain);
|
| 1606 |
+
LLAMA_API void llama_perf_sampler_print(const struct llama_sampler * chain);
|
| 1607 |
+
LLAMA_API void llama_perf_sampler_reset( struct llama_sampler * chain);
|
| 1608 |
+
|
| 1609 |
+
//
|
| 1610 |
+
// training
|
| 1611 |
+
//
|
| 1612 |
+
|
| 1613 |
+
// function that returns whether or not a given tensor contains trainable parameters
|
| 1614 |
+
typedef bool (*llama_opt_param_filter)(const struct ggml_tensor * tensor, void * userdata);
|
| 1615 |
+
|
| 1616 |
+
// always returns true
|
| 1617 |
+
LLAMA_API bool llama_opt_param_filter_all(const struct ggml_tensor * tensor, void * userdata);
|
| 1618 |
+
|
| 1619 |
+
struct llama_opt_params {
|
| 1620 |
+
uint32_t n_ctx_train; // assumed context size post training, use context size specified in llama_context if 0
|
| 1621 |
+
|
| 1622 |
+
llama_opt_param_filter param_filter; // callback for determining which tensors contain trainable parameters
|
| 1623 |
+
void * param_filter_ud; // userdata for determining which tensors contain trainable parameters
|
| 1624 |
+
|
| 1625 |
+
ggml_opt_get_optimizer_params get_opt_pars; // callback for calculating optimizer parameters
|
| 1626 |
+
void * get_opt_pars_ud; // userdata for calculating optimizer parameters
|
| 1627 |
+
|
| 1628 |
+
enum ggml_opt_optimizer_type optimizer_type;
|
| 1629 |
+
};
|
| 1630 |
+
|
| 1631 |
+
LLAMA_API void llama_opt_init(struct llama_context * lctx, struct llama_model * model, struct llama_opt_params lopt_params);
|
| 1632 |
+
|
| 1633 |
+
LLAMA_API void llama_opt_epoch(
|
| 1634 |
+
struct llama_context * lctx,
|
| 1635 |
+
ggml_opt_dataset_t dataset,
|
| 1636 |
+
ggml_opt_result_t result_train,
|
| 1637 |
+
ggml_opt_result_t result_eval,
|
| 1638 |
+
int64_t idata_split,
|
| 1639 |
+
ggml_opt_epoch_callback callback_train,
|
| 1640 |
+
ggml_opt_epoch_callback callback_eval);
|
| 1641 |
+
|
| 1642 |
+
#ifdef __cplusplus
|
| 1643 |
+
}
|
| 1644 |
+
#endif
|
| 1645 |
+
|
| 1646 |
+
#endif // LLAMA_H
|
licenses/LICENSE-jsonhpp
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2013-2025 Niels Lohmann
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
media/llama0-banner.png
ADDED
|
Git LFS Details
|
media/llama0-logo.png
ADDED
|
Git LFS Details
|
media/llama1-banner.png
ADDED
|
media/llama1-icon-transparent.png
ADDED
|
|
media/llama1-icon-transparent.svg
ADDED
|
|
media/llama1-icon.png
ADDED
|
|
media/llama1-icon.svg
ADDED
|
|
media/llama1-logo.png
ADDED
|
media/llama1-logo.svg
ADDED
|
|
media/matmul.png
ADDED
|
Git LFS Details
|
media/matmul.svg
ADDED
|
|
models/.editorconfig
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
root = true
|
models/ggml-vocab-aquila.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c53c3c516ac67c7ca12977b9690fdea3d2ef13bbaed6378f98191a13ef5ca00
|
| 3 |
+
size 4825676
|
models/ggml-vocab-baichuan.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4f5b955697f3bd3108070b1d5936c7eb9fc542b81c6932e59abddec75bca1963
|
| 3 |
+
size 1340998
|
models/ggml-vocab-bert-bge.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fbcbe22278fb302694d5f4a41bfe48c5f90e8e3554eab1c0435387dff654a854
|
| 3 |
+
size 627549
|
models/ggml-vocab-bert-bge.gguf.inp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
| 112 |
+
__ggml_vocab_test__
|
models/ggml-vocab-bert-bge.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
29464 2094 1018 1092 2706
|
| 2 |
+
9706 7959 2140
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
7592 2088
|
| 13 |
+
7592 2088
|
| 14 |
+
7592 2088
|
| 15 |
+
7592 2088
|
| 16 |
+
7592 2088 999
|
| 17 |
+
7592 1010 2088 999
|
| 18 |
+
7592 1010 2088 999
|
| 19 |
+
2023 2003 100 1012 18133 2361
|
| 20 |
+
1059 2692 18139 1021 8525 28418 2243 16233 20952 6979
|
| 21 |
+
1192 15290 29754 14150 1192 10260 1181 29755 29436 29741 10260 16856 29747 23925 10325
|
| 22 |
+
100
|
| 23 |
+
100 1006 3671 1007 100 1006 3674 7861 29147 2483 9530 16280 23854 1007 100 1006 2069 7861 29147 2072 2008 2038 2049 2219 19204 1007
|
| 24 |
+
7592
|
| 25 |
+
7592
|
| 26 |
+
7592
|
| 27 |
+
7592
|
| 28 |
+
7592
|
| 29 |
+
7592 7592
|
| 30 |
+
1006
|
| 31 |
+
1027
|
| 32 |
+
1005 3690
|
| 33 |
+
7592 1010 1061 1005 2035 999 2129 2024 2017 100 1029 1855 100 100 6207 100 100 14677 23632 22203 1811 1995
|
| 34 |
+
999 999 999 999 999 999
|
| 35 |
+
1017
|
| 36 |
+
3943
|
| 37 |
+
21211
|
| 38 |
+
21211 2509
|
| 39 |
+
21211 22394
|
| 40 |
+
21211 22394 2509
|
| 41 |
+
21211 22394 22394
|
| 42 |
+
21211 22394 22394 2509
|
| 43 |
+
21211 22394 22394 22394
|
| 44 |
+
12731 2050 19710
|
| 45 |
+
5860 18117
|
| 46 |
+
100 1006 3671 1007 100 1006 3674 7861 29147 2483 9530 16280 23854 1007 100 100 1017 3943 21211 21211 2509 21211 22394 21211 22394 2509 21211 22394 22394 21211 22394 22394 2509 1017 1012 1017 1017 1012 1012 1017 1017 1012 1012 1012 1017 100 1029 1855 100 100 6207 100 100 14677 23632 22203 1811 1995 1011 1011 1011 1011 1011 1011 1027 1027 1027 1027 1027 1027 1027 1192 15290 29754 14150 1192 10260 1181 29755 29436 29741 10260 16856 29747 23925 10325 1005 1005 1005 1005 1005 1005 1036 1036 1036 1036 1036 1036 1036 1000 1000 1000 1000 1012 1012 1012 1012 1012 1012 999 999 999 999 999 999 1029 1029 1029 1029 1029 1029 1045 1005 2310 2042 1005 2409 2002 1005 1055 2045 1010 1005 2128 2017 2469 1029 1005 1049 2025 2469 1045 1005 2222 2191 2009 1010 1005 1040 2017 2066 2070 5572 1029 2057 1005 2310 1037 1005 2222
|
models/ggml-vocab-command-r.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2f8cfea952ef7c391a6d92a1c309d0bd32e36384d9b9230569a7425732f27d9
|
| 3 |
+
size 10874545
|
models/ggml-vocab-command-r.gguf.inp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
| 112 |
+
__ggml_vocab_test__
|
models/ggml-vocab-command-r.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2536 228 27 228 22957 6983
|
| 2 |
+
90711 87 20910
|
| 3 |
+
|
| 4 |
+
228
|
| 5 |
+
1667
|
| 6 |
+
1742
|
| 7 |
+
205
|
| 8 |
+
206
|
| 9 |
+
2126
|
| 10 |
+
11516
|
| 11 |
+
34777
|
| 12 |
+
28339 3845
|
| 13 |
+
46609 3845
|
| 14 |
+
28339 3930
|
| 15 |
+
46609 3930
|
| 16 |
+
46609 3930 8
|
| 17 |
+
28339 19 3845 8
|
| 18 |
+
46609 19 3845 8
|
| 19 |
+
2075 1801 11254 107 255 21 19317
|
| 20 |
+
94 23 27 31 228 30 21213 20752 39267 6405 9980
|
| 21 |
+
4929 40071 2196 3236 8750 1764 37097 41168
|
| 22 |
+
38111 230 174833 38111 249 86325 241 38111 245 86325 232 38111 252 38111 123 38111 261 165 24629 38111 261 38111 103 174833 38111 235 38111 231 38111 257 38111 235 165 24629 38111 239
|
| 23 |
+
2226 256 230 1737 18258 16 80503 122 35927 2226 242 112 57462 1737 54457 223165 106230 2096 16 48389 1737 10203 109160 1875 2222 2517 3342 12523 16
|
| 24 |
+
28339
|
| 25 |
+
46609
|
| 26 |
+
228 46609
|
| 27 |
+
1667 46609
|
| 28 |
+
1742 46609
|
| 29 |
+
1742 46609 1856 46609
|
| 30 |
+
1737
|
| 31 |
+
206 1857
|
| 32 |
+
14 4515
|
| 33 |
+
28339 19 1770 14 1954 8 4070 1955 1933 80503 231 5691 12081 13336 2648 29325 14315 24 26 24 27 24 28 24 5123 18372
|
| 34 |
+
57178 10251
|
| 35 |
+
26
|
| 36 |
+
26 26
|
| 37 |
+
26 26 26
|
| 38 |
+
26 26 26 26
|
| 39 |
+
26 26 26 26 26
|
| 40 |
+
26 26 26 26 26 26
|
| 41 |
+
26 26 26 26 26 26 26
|
| 42 |
+
26 26 26 26 26 26 26 26
|
| 43 |
+
26 26 26 26 26 26 26 26 26
|
| 44 |
+
42 30719 12584
|
| 45 |
+
3642 4388
|
| 46 |
+
127731 51628 205 57788 18494 97469 126134 206 2226 256 230 1737 18258 16 80503 122 35927 2226 242 112 57462 1737 54457 223165 106230 2096 16 48389 11254 107 255 2226 107 255 228 26 228 26 26 228 26 26 26 228 26 26 26 26 228 26 26 26 26 26 228 26 26 26 26 26 26 228 26 26 26 26 26 26 26 228 26 26 26 26 26 26 26 26 228 26 21 26 228 26 2271 26 228 26 3834 26 182018 230 174833 38111 249 86325 241 38111 245 86325 232 38111 252 38111 123 38111 261 165 24629 38111 261 38111 103 174833 38111 235 188568 231 5691 12081 13336 2648 29325 14315 24 26 24 27 24 28 24 5123 18372 8391 158343 3512 40071 2196 3236 8750 1764 37097 41168 29721 32797 25646 3802 4975 4975 116167 57178 10251 154048 27292 1767 5125 2632 2155 91 2378 1919 1914 2782 19 2155 3354 1933 5470 38 2155 52 2068 5470 1767 4961 3059 1894 19 2155 43 1933 3026 2725 23186 38 2930 14 20676 1671 14 83 51
|
models/ggml-vocab-deepseek-coder.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91cb1379f2e33af1c4866b194622b7a0e12e8f0c9dba7ba2f10d55978730bec1
|
| 3 |
+
size 1156067
|
models/ggml-vocab-deepseek-coder.gguf.inp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
| 112 |
+
__ggml_vocab_test__
|
models/ggml-vocab-deepseek-coder.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1050 207 19 207 19192 4217
|
| 2 |
+
125 213 26862 282
|
| 3 |
+
|
| 4 |
+
207
|
| 5 |
+
243
|
| 6 |
+
315
|
| 7 |
+
184
|
| 8 |
+
185
|
| 9 |
+
185 185
|
| 10 |
+
185 185 185
|
| 11 |
+
184 185
|
| 12 |
+
17535 1835
|
| 13 |
+
414 9489 1835
|
| 14 |
+
17535 5414
|
| 15 |
+
414 9489 5414
|
| 16 |
+
414 9489 5414 0
|
| 17 |
+
17535 11 1835 0
|
| 18 |
+
414 9489 11 1835 0
|
| 19 |
+
437 317 12394 99 234 13 14789
|
| 20 |
+
86 15 19 23 207 22 83 3963 27659 26078 3934 14072
|
| 21 |
+
1593 6478 616 2251 14994
|
| 22 |
+
155 239 209 155 239 114 155 239 228 155 240 220 155 239 224 155 240 211 155 239 231 155 239 115 155 239 240 155 240 210 155 239 240 155 239 95 155 239 114 155 239 214 155 239 210 155 239 236 155 239 214 155 240 210 155 239 218
|
| 23 |
+
10047 235 209 334 8760 8 12394 233 114 350 222 10047 221 104 169 116 224 334 4684 3909 992 24330 262 29651 612 8 207 156 237 214 334 5950 992 78 12896 344 638 891 1372 10736 8
|
| 24 |
+
17535
|
| 25 |
+
414 9489
|
| 26 |
+
207 414 9489
|
| 27 |
+
243 414 9489
|
| 28 |
+
315 414 9489
|
| 29 |
+
315 414 9489 185 315 414 9489
|
| 30 |
+
334
|
| 31 |
+
185 405
|
| 32 |
+
6 2895
|
| 33 |
+
17535 11 320 6 435 0 1717 417 340 12394 233 210 3015 19100 608 9413 2668 16 18 16 19 16 20 16 1393 169 121 239
|
| 34 |
+
15330 3023
|
| 35 |
+
18
|
| 36 |
+
18 18
|
| 37 |
+
18 18 18
|
| 38 |
+
18 18 18 18
|
| 39 |
+
18 18 18 18 18
|
| 40 |
+
18 18 18 18 18 18
|
| 41 |
+
18 18 18 18 18 18 18
|
| 42 |
+
18 18 18 18 18 18 18 18
|
| 43 |
+
18 18 18 18 18 18 18 18 18
|
| 44 |
+
34 155 119 242 64 24297 155 119 216 83
|
| 45 |
+
1607 2539
|
| 46 |
+
185 207 185 185 207 185 185 185 207 12405 459 22758 185 243 185 315 185 251 185 730 185 10047 235 209 334 8760 8 12394 233 114 350 222 10047 221 104 169 116 224 334 4684 3909 992 24330 262 29651 612 8 207 156 237 214 12394 99 234 10047 99 234 207 18 207 18 18 207 18 18 18 207 18 18 18 18 207 18 18 18 18 18 207 18 18 18 18 18 18 207 18 18 18 18 18 18 18 207 18 18 18 18 18 18 18 18 207 18 13 18 207 18 524 18 207 18 1202 18 207 155 239 209 155 239 114 155 239 228 155 240 220 155 239 224 155 240 211 155 239 231 155 239 115 155 239 240 155 240 210 155 239 240 155 239 95 155 239 114 155 239 214 10047 233 210 3015 19100 608 9413 2668 16 18 16 19 16 20 16 1393 169 121 239 18155 374 17194 28 2861 6478 616 2251 14994 31269 4191 6 4686 4686 10252 3358 3358 3409 524 15330 3023 15031 5668 303 6 312 798 651 83 839 362 6 82 741 11 651 1369 340 2037 30 651 44 441 2037 303 6 642 1098 359 11 651 35 340 833 738 10860 30 998 6 10709 245 6 75 43
|
models/ggml-vocab-deepseek-llm.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:867f77537b54565f0d81d508c04edc41aa1d4ffc1a92745f225b4c1b02755f76
|
| 3 |
+
size 3970167
|
models/ggml-vocab-deepseek-llm.gguf.inp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
| 112 |
+
__ggml_vocab_test__
|
models/ggml-vocab-deepseek-llm.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1052 207 19 207 19109 4223
|
| 2 |
+
82077 26723 282
|
| 3 |
+
|
| 4 |
+
207
|
| 5 |
+
243
|
| 6 |
+
300
|
| 7 |
+
184
|
| 8 |
+
185
|
| 9 |
+
185 185
|
| 10 |
+
185 185 185
|
| 11 |
+
184 185
|
| 12 |
+
17464 1843
|
| 13 |
+
37727 1843
|
| 14 |
+
17464 5427
|
| 15 |
+
37727 5427
|
| 16 |
+
37727 5427 0
|
| 17 |
+
17464 11 1843 0
|
| 18 |
+
37727 11 1843 0
|
| 19 |
+
437 317 12356 99 234 13 14743
|
| 20 |
+
86 15 19 23 207 22 83 3970 27519 26016 3944 14025
|
| 21 |
+
1603 6476 620 91754
|
| 22 |
+
71374 209 71374 114 71374 228 155 240 220 71374 224 155 240 211 71374 231 71374 115 71374 240 155 240 210 71374 240 71374 95 71374 114 71374 214 71374 210 71374 236 71374 214 155 240 210 71374 218
|
| 23 |
+
10044 95300 334 8754 8 33701 114 350 222 10044 221 104 46713 334 34732 996 24250 262 80923 8 207 37103 214 334 5956 89213 344 643 895 1377 10728 8
|
| 24 |
+
17464
|
| 25 |
+
37727
|
| 26 |
+
207 37727
|
| 27 |
+
243 37727
|
| 28 |
+
300 37727
|
| 29 |
+
300 37727 185 300 37727
|
| 30 |
+
334
|
| 31 |
+
185 403
|
| 32 |
+
6 2906
|
| 33 |
+
17464 11 320 6 436 0 1724 418 340 33701 210 3025 19017 612 9407 2681 16 18 16 19 16 20 16 1398 68940 239
|
| 34 |
+
15278 3033
|
| 35 |
+
18
|
| 36 |
+
18 18
|
| 37 |
+
18 18 18
|
| 38 |
+
18 18 18 18
|
| 39 |
+
18 18 18 18 18
|
| 40 |
+
18 18 18 18 18 18
|
| 41 |
+
18 18 18 18 18 18 18
|
| 42 |
+
18 18 18 18 18 18 18 18
|
| 43 |
+
18 18 18 18 18 18 18 18 18
|
| 44 |
+
34 32555 242 64 23708 32555 216 83
|
| 45 |
+
1763 2550
|
| 46 |
+
185 207 185 185 207 185 185 185 207 11969 486 22504 185 243 185 300 185 251 185 663 185 10044 95300 334 8754 8 33701 114 350 222 10044 221 104 46713 334 34732 996 24250 262 80923 8 207 37103 214 12356 99 234 10044 99 234 207 18 207 18 18 207 18 18 18 207 18 18 18 18 207 18 18 18 18 18 207 18 18 18 18 18 18 207 18 18 18 18 18 18 18 207 18 18 18 18 18 18 18 18 207 18 13 18 207 18 526 18 207 18 1204 18 207 71374 209 71374 114 71374 228 155 240 220 71374 224 155 240 211 71374 231 71374 115 71374 240 155 240 210 71374 240 71374 95 71374 114 71374 214 71899 210 3025 19017 612 9407 2681 16 18 16 19 16 20 16 1398 68940 239 78827 55170 76659 620 91754 31116 36804 4885 4885 10897 4390 4390 41047 15278 3033 14986 5675 304 6 313 803 655 33326 362 6 82 745 11 655 1374 340 2049 30 655 44 441 2049 304 6 647 1099 359 11 655 35 340 837 742 10842 30 1003 6 10699 245 6 75 43
|
models/ggml-vocab-falcon.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f0bf8b0733680398b72e652e90f260f43782f326e75545fc0e49611a5ba35ad
|
| 3 |
+
size 2287728
|
models/ggml-vocab-falcon.gguf.inp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
| 112 |
+
__ggml_vocab_test__
|
models/ggml-vocab-falcon.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
878 204 31 3068 133 2137
|
| 2 |
+
34502 18614 286
|
| 3 |
+
|
| 4 |
+
204
|
| 5 |
+
258
|
| 6 |
+
466
|
| 7 |
+
192
|
| 8 |
+
193
|
| 9 |
+
1001
|
| 10 |
+
11331
|
| 11 |
+
19125
|
| 12 |
+
9856 1079
|
| 13 |
+
23090 1079
|
| 14 |
+
9856 2889
|
| 15 |
+
23090 2889
|
| 16 |
+
23090 2889 12
|
| 17 |
+
9856 23 1079 12
|
| 18 |
+
23090 23 1079 12
|
| 19 |
+
414 304 3346 111 231 25 29247
|
| 20 |
+
98 55866 204 34 16682 7149 36190 6869 11481
|
| 21 |
+
150 133 6207 151 215 150 134 5052 133 6279 5052 223 151 216 49679 123 53110 47043 7795
|
| 22 |
+
38154 206 38154 126 38154 225 167 237 217 38154 221 167 237 208 38154 228 38154 127 38154 237 167 237 207 38154 237 38154 107 38154 126 38154 211 38154 207 38154 233 38154 211 167 237 207 38154 215
|
| 23 |
+
2571 232 206 204 19 11003 20 8196 126 283 219 48778 116 13392 204 19 51831 732 63209 1741 7955 522 20 22438 211 204 19 7927 53360 325 504 701 946 10930 20
|
| 24 |
+
9856
|
| 25 |
+
23090
|
| 26 |
+
204 23090
|
| 27 |
+
258 23090
|
| 28 |
+
466 23090
|
| 29 |
+
466 23090 742 23090
|
| 30 |
+
204 19
|
| 31 |
+
1212 40
|
| 32 |
+
18 4932
|
| 33 |
+
9856 23 291 18 436 12 1265 362 299 8196 207 204 42 50087 123 2727 20300 32022 133 234 17419 30137 28 7858 181 133 236
|
| 34 |
+
51520
|
| 35 |
+
30
|
| 36 |
+
3138
|
| 37 |
+
22287
|
| 38 |
+
22287 30
|
| 39 |
+
22287 3138
|
| 40 |
+
22287 22287
|
| 41 |
+
22287 22287 30
|
| 42 |
+
22287 22287 3138
|
| 43 |
+
22287 22287 22287
|
| 44 |
+
46 19768 239 76 9634 19768 213 95
|
| 45 |
+
1080 1502
|
| 46 |
+
1212 4824 1001 1212 192 204 663 49453 2069 742 561 1501 193 2571 232 206 204 19 11003 20 8196 126 283 219 48778 116 13392 204 19 51831 732 63209 1741 7955 522 20 22438 211 3346 111 231 2571 111 231 204 30 204 3138 204 22287 204 22287 30 204 22287 3138 204 22287 22287 204 22287 22287 30 204 22287 22287 3138 204 30 25 30 204 30 513 30 204 30 951 30 27171 236 206 38154 126 38154 225 167 237 217 38154 221 167 237 208 38154 228 38154 127 38154 237 167 237 207 38154 237 38154 107 38154 126 38154 211 20589 207 204 42 50087 123 2727 20300 32022 133 234 17419 30137 28 7858 181 133 236 204 37057 2228 10666 5052 133 6207 151 215 150 134 5052 133 6279 5052 223 151 216 49679 123 53110 47043 7795 204 7544 7544 7544 8543 8543 17593 3513 3513 12844 51520 17664 4247 295 18 298 650 204 18 95 693 332 18 94 629 23 204 18 1553 299 1310 42 204 18 56 416 1310 295 18 567 717 334 23 204 18 47 299 606 596 6696 42 703 18 16139 241 18 87 55
|
models/ggml-vocab-gemma-4.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:58b1ba0b57f3b4d7c468ba4ffd91ad85190346a3d7ad7e71d1cabaae8a14bb65
|
| 3 |
+
size 15776467
|
models/ggml-vocab-gemma-4.gguf.inp
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ied 4 ½ months
|
| 2 |
+
__ggml_vocab_test__
|
| 3 |
+
Äpfel
|
| 4 |
+
__ggml_vocab_test__
|
| 5 |
+
|
| 6 |
+
__ggml_vocab_test__
|
| 7 |
+
|
| 8 |
+
__ggml_vocab_test__
|
| 9 |
+
|
| 10 |
+
__ggml_vocab_test__
|
| 11 |
+
|
| 12 |
+
__ggml_vocab_test__
|
| 13 |
+
|
| 14 |
+
__ggml_vocab_test__
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__ggml_vocab_test__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
__ggml_vocab_test__
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
__ggml_vocab_test__
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__ggml_vocab_test__
|
| 30 |
+
Hello world
|
| 31 |
+
__ggml_vocab_test__
|
| 32 |
+
Hello world
|
| 33 |
+
__ggml_vocab_test__
|
| 34 |
+
Hello World
|
| 35 |
+
__ggml_vocab_test__
|
| 36 |
+
Hello World
|
| 37 |
+
__ggml_vocab_test__
|
| 38 |
+
Hello World!
|
| 39 |
+
__ggml_vocab_test__
|
| 40 |
+
Hello, world!
|
| 41 |
+
__ggml_vocab_test__
|
| 42 |
+
Hello, world!
|
| 43 |
+
__ggml_vocab_test__
|
| 44 |
+
this is 🦙.cpp
|
| 45 |
+
__ggml_vocab_test__
|
| 46 |
+
w048 7tuijk dsdfhu
|
| 47 |
+
__ggml_vocab_test__
|
| 48 |
+
нещо на Български
|
| 49 |
+
__ggml_vocab_test__
|
| 50 |
+
កាន់តែពិសេសអាចខលចេញ
|
| 51 |
+
__ggml_vocab_test__
|
| 52 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)
|
| 53 |
+
__ggml_vocab_test__
|
| 54 |
+
Hello
|
| 55 |
+
__ggml_vocab_test__
|
| 56 |
+
Hello
|
| 57 |
+
__ggml_vocab_test__
|
| 58 |
+
Hello
|
| 59 |
+
__ggml_vocab_test__
|
| 60 |
+
Hello
|
| 61 |
+
__ggml_vocab_test__
|
| 62 |
+
Hello
|
| 63 |
+
__ggml_vocab_test__
|
| 64 |
+
Hello
|
| 65 |
+
Hello
|
| 66 |
+
__ggml_vocab_test__
|
| 67 |
+
(
|
| 68 |
+
__ggml_vocab_test__
|
| 69 |
+
|
| 70 |
+
=
|
| 71 |
+
__ggml_vocab_test__
|
| 72 |
+
' era
|
| 73 |
+
__ggml_vocab_test__
|
| 74 |
+
Hello, y'all! How are you 😁 ?我想在apple工作1314151天~
|
| 75 |
+
__ggml_vocab_test__
|
| 76 |
+
!!!!!!
|
| 77 |
+
__ggml_vocab_test__
|
| 78 |
+
3
|
| 79 |
+
__ggml_vocab_test__
|
| 80 |
+
33
|
| 81 |
+
__ggml_vocab_test__
|
| 82 |
+
333
|
| 83 |
+
__ggml_vocab_test__
|
| 84 |
+
3333
|
| 85 |
+
__ggml_vocab_test__
|
| 86 |
+
33333
|
| 87 |
+
__ggml_vocab_test__
|
| 88 |
+
333333
|
| 89 |
+
__ggml_vocab_test__
|
| 90 |
+
3333333
|
| 91 |
+
__ggml_vocab_test__
|
| 92 |
+
33333333
|
| 93 |
+
__ggml_vocab_test__
|
| 94 |
+
333333333
|
| 95 |
+
__ggml_vocab_test__
|
| 96 |
+
Cửa Việt
|
| 97 |
+
__ggml_vocab_test__
|
| 98 |
+
discards
|
| 99 |
+
__ggml_vocab_test__
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ 🦙🦙 3 33 333 3333 33333 333333 3333333 33333333 3.3 3..3 3...3 កាន់តែពិសេសអាច😁 ?我想在apple工作1314151天~ ------======= нещо на Български ''''''```````""""......!!!!!!?????? I've been 'told he's there, 'RE you sure? 'M not sure I'll make it, 'D you like some tea? We'Ve a'lL
|
models/ggml-vocab-gemma-4.gguf.out
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1178 236743 236812 47041 3794
|
| 2 |
+
239122 22744 535
|
| 3 |
+
|
| 4 |
+
236743
|
| 5 |
+
138
|
| 6 |
+
139
|
| 7 |
+
255968
|
| 8 |
+
107
|
| 9 |
+
108
|
| 10 |
+
109
|
| 11 |
+
255968 107
|
| 12 |
+
9259 1902
|
| 13 |
+
26352 1902
|
| 14 |
+
9259 4109
|
| 15 |
+
26352 4109
|
| 16 |
+
26352 4109 236888
|
| 17 |
+
9259 236764 1902 236888
|
| 18 |
+
26352 236764 1902 236888
|
| 19 |
+
672 563 236743 478 397 404 391 236761 12362
|
| 20 |
+
236765 236771 236812 236828 236743 236832 11372 12065 31806 3405 9360
|
| 21 |
+
1337 12515 1333 4632 165543 3830
|
| 22 |
+
234889 63031 219876 66212 239077 237907 144494
|
| 23 |
+
242015 568 7382 236768 236743 247717 237243 248989 238178 568 43819 111730 150567 236768 113452 568 8960 64334 600 815 1061 1852 8369 236768
|
| 24 |
+
9259
|
| 25 |
+
26352
|
| 26 |
+
138 9259
|
| 27 |
+
139 9259
|
| 28 |
+
140 9259
|
| 29 |
+
140 9259 107 140 9259
|
| 30 |
+
568
|
| 31 |
+
107 578
|
| 32 |
+
236789 6933
|
| 33 |
+
9259 236764 570 236789 712 236888 2088 659 611 170124 2360 62133 237075 17641 11700 236770 236800 236770 236812 236770 236810 236770 237471 238352
|
| 34 |
+
123947
|
| 35 |
+
236800
|
| 36 |
+
236800 236800
|
| 37 |
+
236800 236800 236800
|
| 38 |
+
236800 236800 236800 236800
|
| 39 |
+
236800 236800 236800 236800 236800
|
| 40 |
+
236800 236800 236800 236800 236800 236800
|
| 41 |
+
236800 236800 236800 236800 236800 236800 236800
|
| 42 |
+
236800 236800 236800 236800 236800 236800 236800 236800
|
| 43 |
+
236800 236800 236800 236800 236800 236800 236800 236800 236800
|
| 44 |
+
236780 29719 33154
|
| 45 |
+
2243 2206
|
| 46 |
+
107 236743 108 236743 109 236743 255968 236743 255969 236743 255968 107 138 107 139 107 140 107 141 107 242015 568 7382 236768 236743 247717 237243 248989 238178 568 43819 111730 150567 236768 113452 236743 478 397 404 391 478 397 404 391 236743 236800 236743 236800 236800 236743 236800 236800 236800 236743 236800 236800 236800 236800 236743 236800 236800 236800 236800 236800 236743 236800 236800 236800 236800 236800 236800 236743 236800 236800 236800 236800 236800 236800 236800 236743 236800 236800 236800 236800 236800 236800 236800 236800 236743 236800 236761 236800 236743 236800 856 236800 236743 236800 1390 236800 90986 92814 63031 219876 66212 241702 2360 62133 237075 17641 11700 236770 236800 236770 236812 236770 236810 236770 237471 238352 80448 120697 210119 1333 4632 165543 3830 9451 159561 2629 2629 2717 84491 19938 123947 38950 10371 564 236789 560 1010 756 151812 668 236789 236751 993 236764 756 1357 611 2889 236881 756 236792 711 2889 564 236789 859 1386 625 236764 756 236796 611 1133 1070 11115 236881 1191 236789 32541 496 236789 95635
|