diff options
author | Cebtenzzre <cebtenzzre@gmail.com> | 2023-08-31 01:02:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 08:02:23 +0300 |
commit | 92d0b751a77a089e650983e9f1564ef4d31b32b9 (patch) | |
tree | 28beced44af777ec563f489518a14509994187dd /convert-llama-ggmlv3-to-gguf.py | |
parent | 8afe2280009ecbfc9de2c93b8f41283dc810609a (diff) |
convert : fix python 3.8 support, modernize type annotations (#2916)
* convert : fix python 3.8 support
* convert : sort imports
* convert : fix required parameters in convert-llama-ggmlv3-to-gguf
* convert : fix mypy errors in convert-llama-ggmlv3-to-gguf
* convert : use PEP 585 generics and PEP 604 unions
Now that we have `from __future__ import annotations`, we can use this
modern syntax in Python 3.7 instead of restricting support to Python 3.9
or 3.10 respectively.
* gguf.py : a tuple is already a tuple
* add mypy.ini
* convert : add necessary `type: ignore` comments
* gguf-py: bump version
Diffstat (limited to 'convert-llama-ggmlv3-to-gguf.py')
-rwxr-xr-x | convert-llama-ggmlv3-to-gguf.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/convert-llama-ggmlv3-to-gguf.py b/convert-llama-ggmlv3-to-gguf.py index c8e7f176..3f39bc39 100755 --- a/convert-llama-ggmlv3-to-gguf.py +++ b/convert-llama-ggmlv3-to-gguf.py @@ -1,10 +1,14 @@ #!/usr/bin/env python3 -import sys, struct, math, argparse -from pathlib import Path +from __future__ import annotations -import numpy as np +import argparse +import math +import struct +import sys +from pathlib import Path import gguf +import numpy as np # Note: Does not support GGML_QKK_64 QK_K = 256 @@ -72,7 +76,7 @@ class Vocab: class Tensor: def __init__(self): self.name = None - self.dims = () + self.dims: tuple[int, ...] = () self.dtype = None self.start_offset = 0 self.len_bytes = np.int64(0) @@ -119,7 +123,7 @@ class GGMLV3Model: offset += hp.load(data, offset) vocab = Vocab() offset += vocab.load(data, offset, hp.n_vocab) - tensors = [] + tensors: list[Tensor] = [] tensor_map = {} while offset < len(data): tensor = Tensor() @@ -305,8 +309,8 @@ def handle_metadata(cfg, hp): def handle_args(): parser = argparse.ArgumentParser(description = 'Convert GGMLv3 models to GGUF') - parser.add_argument('--input', '-i', type = Path, help = 'Input GGMLv3 filename') - parser.add_argument('--output', '-o', type = Path, help ='Output GGUF filename') + parser.add_argument('--input', '-i', type = Path, required = True, help = 'Input GGMLv3 filename') + parser.add_argument('--output', '-o', type = Path, required = True, help ='Output GGUF filename') parser.add_argument('--name', help = 'Set model name') parser.add_argument('--desc', help = 'Set model description') parser.add_argument('--gqa', type = int, default = 1, help = 'grouped-query attention factor (use 8 for LLaMA2 70B)') |