From d09772a6d01260013964b3af5e4043edef442027 Mon Sep 17 00:00:00 2001 From: cebtenzzre Date: Tue, 31 Oct 2023 11:52:32 -0400 Subject: [PATCH] gguf : prevent adding tensors after header is written --- gguf-py/gguf/gguf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gguf-py/gguf/gguf.py b/gguf-py/gguf/gguf.py index 6cce3dbb0..152b0a0e3 100644 --- a/gguf-py/gguf/gguf.py +++ b/gguf-py/gguf/gguf.py @@ -806,6 +806,9 @@ class GGUFWriter: return ((x + n - 1) // n) * n def add_tensor_info(self, name: str, tensor_shape: Sequence[int], tensor_dtype: np.dtype[np.float16] | np.dtype[np.float32], tensor_nbytes: int, raw_dtype: GGMLQuantizationType | None = None): + if self.state is not WriterState.EMPTY: + raise ValueError(f'Expected output file to be empty, got {self.state}') + assert raw_dtype is not None or tensor_dtype in (np.float32, np.float16), "Only F32 and F16 tensors are supported for now" encoded_name = name.encode("utf8")