From 120c4da5128ee5730f66e972a058a5dcd20fa358 Mon Sep 17 00:00:00 2001 From: Dwayne Robinson Date: Fri, 24 Feb 2023 02:12:57 -0800 Subject: [PATCH] README.md proposed clarity (#181) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * README.md proposed clarity I had to look via a hex editor at an existing .safetensors file to figure it out (maybe this will accelerate others slightly to adopt it 😅), because parentheses "(...)" are not legal JSON, and it wasn't clear to me whether the offsets were file relative or byte buffer relative. * Update other readme. --------- Co-authored-by: Nicolas Patry --- README.md | 2 +- safetensors/README.md | 2 +- safetensors/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 87bda92..ee71960 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ with safe_open("model.safetensors", framework="pt", device="cpu") as f: - 8 bytes: `N`, a u64 int, containing the size of the header - N bytes: a JSON utf-8 string representing the header. - - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": (X, Y)}}, where X and Y are the offsets in the byte buffer of the tensor data + - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": [BEGIN, END]}, "NEXT_TENSOR_NAME": {...}, ...}, where offsets point to the tensor data relative to the beginning of the byte buffer, with BEGIN as the starting offset and END as the one-past offset (so total tensor byte size = END - BEGIN). - A special key `__metadata__` is allowed to contain free form text map. - Rest of the file: byte-buffer. diff --git a/safetensors/README.md b/safetensors/README.md index 87bda92..ee71960 100644 --- a/safetensors/README.md +++ b/safetensors/README.md @@ -54,7 +54,7 @@ with safe_open("model.safetensors", framework="pt", device="cpu") as f: - 8 bytes: `N`, a u64 int, containing the size of the header - N bytes: a JSON utf-8 string representing the header. - - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": (X, Y)}}, where X and Y are the offsets in the byte buffer of the tensor data + - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": [BEGIN, END]}, "NEXT_TENSOR_NAME": {...}, ...}, where offsets point to the tensor data relative to the beginning of the byte buffer, with BEGIN as the starting offset and END as the one-past offset (so total tensor byte size = END - BEGIN). - A special key `__metadata__` is allowed to contain free form text map. - Rest of the file: byte-buffer. diff --git a/safetensors/src/lib.rs b/safetensors/src/lib.rs index efbd3fe..b34446a 100644 --- a/safetensors/src/lib.rs +++ b/safetensors/src/lib.rs @@ -53,7 +53,7 @@ //! //! - 8 bytes: `N`, a u64 int, containing the size of the header //! - N bytes: a JSON utf-8 string representing the header. -//! - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": (X, Y)}}, where X and Y are the offsets in the byte buffer of the tensor data +//! - The header is a dict like {"TENSOR_NAME": {"dtype": "float16", "shape": [1, 16, 256], "offsets": [BEGIN, END]}, "NEXT_TENSOR_NAME": {...}, ...}, where offsets point to the tensor data relative to the beginning of the byte buffer, with BEGIN as the starting offset and END as the one-past offset (so total tensor byte size = END - BEGIN). //! - A special key `__metadata__` is allowed to contain free form text map. //! - Rest of the file: byte-buffer. //! -- 2.43.0