]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
scripts: Use local gguf package when running from repo (#2927)
authorKerfuffle <redacted>
Thu, 31 Aug 2023 22:49:24 +0000 (16:49 -0600)
committerGitHub <redacted>
Thu, 31 Aug 2023 22:49:24 +0000 (16:49 -0600)
* scripts: Use local gguf when running from repo

convert-falcon-hf-to-gguf.py
convert-gptneox-hf-to-gguf.py
convert-llama-ggmlv3-to-gguf.py
convert.py
examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py

index ec786ff67c0961b94c033b2b66b35b75fa78a77a..271e589728e6449b60bd7253df60758aa6716374 100755 (executable)
@@ -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
index 852123d99e5bea200a5faaddb98b6ab4a4012743..b9c8b4607e5931eae2b57a3375239ee1ce11e801 100755 (executable)
@@ -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
 
 
index 3f39bc39e14a98856f64f4b0640a73e6dfb7f4b5..08ba0c490cd1ebca3d47b4b247d7bdcc963f11c7 100755 (executable)
@@ -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)
index 9a39edb994c27175ca61d8344c18fb00599e7e43..5cc3f6e66f6bbf893a33ef70b8ead7af6c518d98 100755 (executable)
@@ -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
 
index 01b3ee92a5a0c276f2ef0b02666312b491b40e3e..a527d615304b8abb88d07dc21b84c3b0381040eb 100644 (file)
@@ -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"