From 6df988d5f12f44d735286c6c56cb96ba1be6404b Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Sun, 1 Oct 2023 17:49:22 -0400 Subject: [PATCH] gguf : do not store defaults in class vars Making an assignment in a class outside of a method does not set the default value, it actually sets the attribute on the class itself. Instances of the class inherit these, but it's incorrect to expose these fields here. --- gguf-py/gguf/gguf.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gguf-py/gguf/gguf.py b/gguf-py/gguf/gguf.py index 6b7d65429..518002091 100644 --- a/gguf-py/gguf/gguf.py +++ b/gguf-py/gguf/gguf.py @@ -638,15 +638,7 @@ class GGUFValueType(IntEnum): class GGUFWriter: fout: BufferedWriter - arch: str - offset_tensor = 0 - data_alignment = GGUF_DEFAULT_ALIGNMENT - kv_data = b"" - kv_data_count = 0 - ti_data = b"" - ti_data_count = 0 - use_temp_file: bool - temp_file: tempfile.SpooledTemporaryFile[bytes] | None = None + temp_file: tempfile.SpooledTemporaryFile[bytes] | None tensors: list[tuple[np.ndarray[Any, Any], int]] @property @@ -673,12 +665,20 @@ class GGUFWriter: GGUFValueType.FLOAT64: f"{self.pack_prefix}d", GGUFValueType.BOOL: "?" , } - self.add_architecture() + self.offset_tensor = 0 + self.data_alignment = GGUF_DEFAULT_ALIGNMENT + self.kv_data = b"" + self.kv_data_count = 0 + self.ti_data = b"" + self.ti_data_count = 0 self.use_temp_file = use_temp_file + self.temp_file = None self.tensors = [] endianess_str = "Big Endian" if self.endianess == GGUFEndian.BIG else "Little Endian" print(f"This gguf file is for {endianess_str} only") + self.add_architecture() + def write_header_to_file(self): self.fout.write(struct.pack(" None: