scripts: Use local gguf when running from repo
This commit is contained in:
parent
92d0b751a7
commit
4320055b22
5 changed files with 25 additions and 4 deletions
|
@ -11,11 +11,14 @@ import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import gguf
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
from transformers import AutoTokenizer # type: ignore[import]
|
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()))
|
||||||
|
import gguf
|
||||||
|
|
||||||
|
|
||||||
def bytes_to_unicode():
|
def bytes_to_unicode():
|
||||||
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
|
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
|
||||||
|
|
|
@ -16,6 +16,10 @@ import numpy as np
|
||||||
import torch
|
import torch
|
||||||
from transformers import AutoTokenizer # type: ignore[import]
|
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()))
|
||||||
|
import gguf
|
||||||
|
|
||||||
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
|
# ref: https://github.com/openai/gpt-2/blob/master/src/encoder.py
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,13 @@ import struct
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import gguf
|
|
||||||
import numpy as np
|
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()))
|
||||||
|
import gguf
|
||||||
|
|
||||||
# Note: Does not support GGML_QKK_64
|
# Note: Does not support GGML_QKK_64
|
||||||
QK_K = 256
|
QK_K = 256
|
||||||
# Items here are (block size, type size)
|
# Items here are (block size, type size)
|
||||||
|
|
|
@ -25,10 +25,14 @@ from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, Iterable, Literal, Sequence, TypeVar
|
from typing import IO, TYPE_CHECKING, Any, Callable, Generator, Iterable, Literal, Sequence, TypeVar
|
||||||
|
|
||||||
import gguf
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from sentencepiece import SentencePieceProcessor # type: ignore[import]
|
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()))
|
||||||
|
import gguf
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import TypeAlias
|
from typing import TypeAlias
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,19 @@
|
||||||
# train-text-from-scratch checkpoint --> gguf conversion
|
# train-text-from-scratch checkpoint --> gguf conversion
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import gguf
|
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pathlib import Path
|
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()))
|
||||||
|
import gguf
|
||||||
|
|
||||||
# gguf constants
|
# gguf constants
|
||||||
LLM_KV_OPTIMIZER_TYPE = "optimizer.type"
|
LLM_KV_OPTIMIZER_TYPE = "optimizer.type"
|
||||||
LLM_KV_OPTIMIZER_TYPE_ADAM = "adam"
|
LLM_KV_OPTIMIZER_TYPE_ADAM = "adam"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue