summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerfuffle <44031344+KerfuffleV2@users.noreply.github.com>2023-08-31 16:49:24 -0600
committerGitHub <noreply@github.com>2023-08-31 16:49:24 -0600
commitaeefac4ff760acea5afe66fbfe8d7eca1937b79c (patch)
tree785cbf67f86773165b1d31471233a5539c6d67a1
parente8422de39e4aa2f7e50574124b060a80607e654a (diff)
scripts: Use local gguf package when running from repo (#2927)
* scripts: Use local gguf when running from repo
-rwxr-xr-xconvert-falcon-hf-to-gguf.py5
-rwxr-xr-xconvert-gptneox-hf-to-gguf.py5
-rwxr-xr-xconvert-llama-ggmlv3-to-gguf.py6
-rwxr-xr-xconvert.py6
-rw-r--r--examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py5
5 files changed, 22 insertions, 5 deletions
diff --git a/convert-falcon-hf-to-gguf.py b/convert-falcon-hf-to-gguf.py
index ec786ff6..271e5897 100755
--- a/convert-falcon-hf-to-gguf.py
+++ b/convert-falcon-hf-to-gguf.py
@@ -11,11 +11,14 @@ import sys
from pathlib import Path
from typing import Any
-import gguf
import numpy as np
import torch
from transformers import AutoTokenizer # type: ignore[import]
+if 'NO_LOCAL_GGUF' not in os.environ:
+ sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
+import gguf
+
def bytes_to_unicode():
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
diff --git a/convert-gptneox-hf-to-gguf.py b/convert-gptneox-hf-to-gguf.py
index 852123d9..b9c8b460 100755
--- a/convert-gptneox-hf-to-gguf.py
+++ b/convert-gptneox-hf-to-gguf.py
@@ -11,11 +11,14 @@ import sys
from pathlib import Path
from typing import Any
-import gguf
import numpy as np
import torch
from transformers import AutoTokenizer # type: ignore[import]
+if 'NO_LOCAL_GGUF' not in os.environ:
+ sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
+import gguf
+
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
diff --git a/convert-llama-ggmlv3-to-gguf.py b/convert-llama-ggmlv3-to-gguf.py
index 3f39bc39..08ba0c49 100755
--- a/convert-llama-ggmlv3-to-gguf.py
+++ b/convert-llama-ggmlv3-to-gguf.py
@@ -7,9 +7,13 @@ import struct
import sys
from pathlib import Path
-import gguf
import numpy as np
+import os
+if 'NO_LOCAL_GGUF' not in os.environ:
+ sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
+import gguf
+
# Note: Does not support GGML_QKK_64
QK_K = 256
# Items here are (block size, type size)
diff --git a/convert.py b/convert.py
index 9a39edb9..5cc3f6e6 100755
--- a/convert.py
+++ b/convert.py
@@ -25,10 +25,14 @@ from dataclasses import dataclass
from pathlib import Path
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, Iterable, Literal, Sequence, TypeVar
-import gguf
import numpy as np
from sentencepiece import SentencePieceProcessor # type: ignore[import]
+import os
+if 'NO_LOCAL_GGUF' not in os.environ:
+ sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
+import gguf
+
if TYPE_CHECKING:
from typing import TypeAlias
diff --git a/examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py b/examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py
index 01b3ee92..a527d615 100644
--- a/examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py
+++ b/examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py
@@ -2,13 +2,16 @@
# train-text-from-scratch checkpoint --> gguf conversion
import argparse
-import gguf
import os
import struct
import sys
import numpy as np
from pathlib import Path
+if 'NO_LOCAL_GGUF' not in os.environ:
+ sys.path.insert(1, str(Path(__file__).parent / '..' / '..' / 'gguf-py' / 'gguf'))
+import gguf
+
# gguf constants
LLM_KV_OPTIMIZER_TYPE = "optimizer.type"
LLM_KV_OPTIMIZER_TYPE_ADAM = "adam"