Skip to content

Commit aeefac4

Browse files
authored
scripts: Use local gguf package when running from repo (#2927)
* scripts: Use local gguf when running from repo
1 parent e8422de commit aeefac4

5 files changed

+22
-5
lines changed

convert-falcon-hf-to-gguf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
from pathlib import Path
1212
from typing import Any
1313

14-
import gguf
1514
import numpy as np
1615
import torch
1716
from transformers import AutoTokenizer # type: ignore[import]
1817

18+
if 'NO_LOCAL_GGUF' not in os.environ:
19+
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
20+
import gguf
21+
1922

2023
def bytes_to_unicode():
2124
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py

convert-gptneox-hf-to-gguf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
from pathlib import Path
1212
from typing import Any
1313

14-
import gguf
1514
import numpy as np
1615
import torch
1716
from transformers import AutoTokenizer # type: ignore[import]
1817

18+
if 'NO_LOCAL_GGUF' not in os.environ:
19+
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
20+
import gguf
21+
1922
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
2023

2124

convert-llama-ggmlv3-to-gguf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
import sys
88
from pathlib import Path
99

10-
import gguf
1110
import numpy as np
1211

12+
import os
13+
if 'NO_LOCAL_GGUF' not in os.environ:
14+
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
15+
import gguf
16+
1317
# Note: Does not support GGML_QKK_64
1418
QK_K = 256
1519
# Items here are (block size, type size)

convert.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
from pathlib import Path
2626
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, Iterable, Literal, Sequence, TypeVar
2727

28-
import gguf
2928
import numpy as np
3029
from sentencepiece import SentencePieceProcessor # type: ignore[import]
3130

31+
import os
32+
if 'NO_LOCAL_GGUF' not in os.environ:
33+
sys.path.insert(1, str(Path(__file__).parent / 'gguf-py' / 'gguf'))
34+
import gguf
35+
3236
if TYPE_CHECKING:
3337
from typing import TypeAlias
3438

examples/train-text-from-scratch/convert-train-checkpoint-to-gguf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
# train-text-from-scratch checkpoint --> gguf conversion
33

44
import argparse
5-
import gguf
65
import os
76
import struct
87
import sys
98
import numpy as np
109
from pathlib import Path
1110

11+
if 'NO_LOCAL_GGUF' not in os.environ:
12+
sys.path.insert(1, str(Path(__file__).parent / '..' / '..' / 'gguf-py' / 'gguf'))
13+
import gguf
14+
1215
# gguf constants
1316
LLM_KV_OPTIMIZER_TYPE = "optimizer.type"
1417
LLM_KV_OPTIMIZER_TYPE_ADAM = "adam"

0 commit comments

Comments
 (0)