diff --git a/convert-falcon-hf-to-gguf.py b/convert-falcon-hf-to-gguf.py index acd07cadd..b0f670fbc 100755 --- a/convert-falcon-hf-to-gguf.py +++ b/convert-falcon-hf-to-gguf.py @@ -15,8 +15,9 @@ import numpy as np import torch from transformers import AutoTokenizer # type: ignore[import] -if os.environ.get('NO_LOCAL_GGUF') is None and Path('gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('gguf-py', 'gguf').absolute())) +# Use local gguf module if available. +if 'NO_LOCAL_GGUF' not in os.environ and (Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf', '__init__.py')).is_file(): + sys.path.insert(1, str(Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf'))) import gguf diff --git a/convert-gptneox-hf-to-gguf.py b/convert-gptneox-hf-to-gguf.py index 3741a19ca..cc757b640 100755 --- a/convert-gptneox-hf-to-gguf.py +++ b/convert-gptneox-hf-to-gguf.py @@ -15,8 +15,9 @@ import numpy as np import torch from transformers import AutoTokenizer # type: ignore[import] -if os.environ.get('NO_LOCAL_GGUF') is None and Path('gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('gguf-py', 'gguf').absolute())) +# Use local gguf module if available. +if 'NO_LOCAL_GGUF' not in os.environ and (Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf', '__init__.py')).is_file(): + sys.path.insert(1, str(Path(__file__).parent.absolute().joinpath('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 2870088c4..3f08801bf 100755 --- a/convert-llama-ggmlv3-to-gguf.py +++ b/convert-llama-ggmlv3-to-gguf.py @@ -10,8 +10,9 @@ from pathlib import Path import numpy as np import os -if os.environ.get('NO_LOCAL_GGUF') is None and Path('gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('gguf-py', 'gguf').absolute())) +# Use local gguf module if available. +if 'NO_LOCAL_GGUF' not in os.environ and (Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf', '__init__.py')).is_file(): + sys.path.insert(1, str(Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf'))) import gguf # Note: Does not support GGML_QKK_64 diff --git a/convert.py b/convert.py index ba6ead707..b6641ea96 100755 --- a/convert.py +++ b/convert.py @@ -29,8 +29,9 @@ import numpy as np from sentencepiece import SentencePieceProcessor # type: ignore[import] import os -if os.environ.get('NO_LOCAL_GGUF') is None and Path('gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('gguf-py', 'gguf').absolute())) +# Use local gguf module if available. +if 'NO_LOCAL_GGUF' not in os.environ and (Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf', '__init__.py')).is_file(): + sys.path.insert(1, str(Path(__file__).parent.absolute().joinpath('gguf-py', 'gguf'))) import gguf if TYPE_CHECKING: 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 cde4e7314..0cd2892a3 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 @@ -8,11 +8,9 @@ import sys import numpy as np from pathlib import Path -if os.environ.get('NO_LOCAL_GGUF') is None: - if Path('gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('gguf-py', 'gguf').absolute())) - elif Path('..', '..', 'gguf-py', 'gguf', '__init__.py').is_file(): - sys.path.insert(1, str(Path('..', '..', 'gguf-py', 'gguf').absolute())) +# Use local gguf module if available. +if 'NO_LOCAL_GGUF' not in os.environ and (Path(__file__).parent.absolute().joinpath('..', '..', 'gguf-py', 'gguf', '__init__.py')).is_file(): + sys.path.insert(1, str(Path(__file__).parent.absolute().joinpath('..', '..', 'gguf-py', 'gguf'))) import gguf # gguf constants