]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
gguf-py : support identity operation in TensorNameMap (#3095)
authorKerfuffle <redacted>
Thu, 14 Sep 2023 16:32:26 +0000 (10:32 -0600)
committerGitHub <redacted>
Thu, 14 Sep 2023 16:32:26 +0000 (19:32 +0300)
Make try_suffixes keyword param optional.

gguf-py/gguf/gguf.py
gguf-py/pyproject.toml

index bda13ac0067c2aae4eda32ff6fc28e8a3c1395d2..7f7204ea1d9ec4a3c728cbbad7c063a9354b3010 100644 (file)
@@ -333,6 +333,7 @@ class TensorNameMap:
             tensor_name = tensor_names.get(tensor)
             if tensor_name is None:
                 continue
+            mapping[tensor_name] = (tensor, tensor_name)
             for key in keys:
                 mapping[key] = (tensor, tensor_name)
         for bid in range(n_blocks):
@@ -341,11 +342,12 @@ class TensorNameMap:
                 if tensor_name is None:
                     continue
                 tensor_name = tensor_name.format(bid = bid)
+                mapping[tensor_name] = (tensor, tensor_name)
                 for key in keys:
                     key = key.format(bid = bid)
                     mapping[key] = (tensor, tensor_name)
 
-    def get_type_and_name(self, key: str, try_suffixes: Sequence[str]) -> tuple[MODEL_TENSOR, str] | None:
+    def get_type_and_name(self, key: str, try_suffixes: Sequence[str] = ()) -> tuple[MODEL_TENSOR, str] | None:
         result = self.mapping.get(key)
         if result is not None:
             return result
@@ -356,13 +358,13 @@ class TensorNameMap:
                     return (result[0], result[1] + suffix)
         return None
 
-    def get_name(self, key: str, try_suffixes: Sequence[str]) -> str | None:
+    def get_name(self, key: str, try_suffixes: Sequence[str] = ()) -> str | None:
         result = self.get_type_and_name(key, try_suffixes = try_suffixes)
         if result is None:
             return None
         return result[1]
 
-    def get_type(self, key: str, try_suffixes: Sequence[str]) -> MODEL_TENSOR | None:
+    def get_type(self, key: str, try_suffixes: Sequence[str] = ()) -> MODEL_TENSOR | None:
         result = self.get_type_and_name(key, try_suffixes = try_suffixes)
         if result is None:
             return None
index 8da60de1b3f3f806fcc65e3cfaf00313abc837e8..9489ccd6f2c011ee2ecc0d396ae53400f3ef7e74 100644 (file)
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "gguf"
-version = "0.3.2"
+version = "0.3.3"
 description = "Write ML models in GGUF for GGML"
 authors = ["GGML <ggml@ggml.ai>"]
 packages = [