Skip to content

Commit 381174b

Browse files
Ahajhacompilade
andauthored
gguf-py : make sentencepiece optional (#14200)
* Make sentencepiece optional * Bump to 0.18.0 * Bump patch instead of minor Co-authored-by: compilade <[email protected]> --------- Co-authored-by: compilade <[email protected]>
1 parent d67341d commit 381174b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

gguf-py/gguf/vocab.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from pathlib import Path
88
from typing import Any, Callable, Sequence, Mapping, Iterable, Protocol, ClassVar, runtime_checkable
99

10-
from sentencepiece import SentencePieceProcessor
10+
try:
11+
from sentencepiece import SentencePieceProcessor
12+
except ImportError:
13+
SentencePieceProcessor = None
1114

1215
import gguf
1316

@@ -302,6 +305,9 @@ class SentencePieceVocab(Vocab):
302305
name = "spm"
303306

304307
def __init__(self, base_path: Path):
308+
if SentencePieceProcessor is None:
309+
raise RuntimeError("sentencepiece is not installed")
310+
305311
added_tokens: dict[str, int] = {}
306312
if (fname_tokenizer := base_path / 'tokenizer.model').exists():
307313
# normal location

gguf-py/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gguf"
3-
version = "0.17.0"
3+
version = "0.17.1"
44
description = "Read and write ML models in GGUF for GGML"
55
authors = ["GGML <[email protected]>"]
66
packages = [
@@ -22,7 +22,7 @@ python = ">=3.8"
2222
numpy = ">=1.17"
2323
tqdm = ">=4.27"
2424
pyyaml = ">=5.1"
25-
sentencepiece = ">=0.1.98,<=0.2.0"
25+
sentencepiece = { version = ">=0.1.98,<=0.2.0", optional = true }
2626
PySide6 = { version = "^6.9", python = ">=3.9,<3.14", optional = true }
2727

2828
[tool.poetry.dev-dependencies]

0 commit comments

Comments
 (0)