]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
gguf-py : make sentencepiece optional (#14200)
authorAlex Trotta <redacted>
Thu, 19 Jun 2025 13:56:12 +0000 (09:56 -0400)
committerGitHub <redacted>
Thu, 19 Jun 2025 13:56:12 +0000 (15:56 +0200)
* Make sentencepiece optional

* Bump to 0.18.0

* Bump patch instead of minor

Co-authored-by: compilade <redacted>
---------

Co-authored-by: compilade <redacted>
gguf-py/gguf/vocab.py
gguf-py/pyproject.toml

index cca0979862a71495bf9ff41c1a48016dc7185865..44d066ee75a7ece48dabb168c5054fb4053f5d48 100644 (file)
@@ -7,7 +7,10 @@ import os
 from pathlib import Path
 from typing import Any, Callable, Sequence, Mapping, Iterable, Protocol, ClassVar, runtime_checkable
 
-from sentencepiece import SentencePieceProcessor
+try:
+    from sentencepiece import SentencePieceProcessor
+except ImportError:
+    SentencePieceProcessor = None
 
 import gguf
 
@@ -302,6 +305,9 @@ class SentencePieceVocab(Vocab):
     name = "spm"
 
     def __init__(self, base_path: Path):
+        if SentencePieceProcessor is None:
+            raise RuntimeError("sentencepiece is not installed")
+
         added_tokens: dict[str, int] = {}
         if (fname_tokenizer := base_path / 'tokenizer.model').exists():
             # normal location
index f11351cba17677e262cf600504ebd19eda0a5279..0f3a1eeee8304ac9c04656e885fbcfabd44e74a8 100644 (file)
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "gguf"
-version = "0.17.0"
+version = "0.17.1"
 description = "Read and write ML models in GGUF for GGML"
 authors = ["GGML <ggml@ggml.ai>"]
 packages = [
@@ -22,7 +22,7 @@ python = ">=3.8"
 numpy = ">=1.17"
 tqdm = ">=4.27"
 pyyaml = ">=5.1"
-sentencepiece = ">=0.1.98,<=0.2.0"
+sentencepiece = { version = ">=0.1.98,<=0.2.0", optional = true }
 PySide6 = { version = "^6.9", python = ">=3.9,<3.14", optional = true }
 
 [tool.poetry.dev-dependencies]