]> khamidou — GitHub mirrors - safetensors.git/commitdiff
README.md proposed clarity (#181)
authorDwayne Robinson <fdwr@hotmail.com>
Fri, 24 Feb 2023 10:12:57 +0000 (02:12 -0800)
committerGitHub <noreply@github.com>
Fri, 24 Feb 2023 10:12:57 +0000 (11:12 +0100)
* 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 <patry.nicolas@protonmail.com>
README.md
safetensors/README.md
safetensors/src/lib.rs

index 87bda92c2c7a5c622f867aaeb04fe0599b4cacbf..ee719604120d999558344008a7136ba39bc2b6fd 100644 (file)
--- 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.
 
index 87bda92c2c7a5c622f867aaeb04fe0599b4cacbf..ee719604120d999558344008a7136ba39bc2b6fd 100644 (file)
@@ -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.
 
index efbd3fee6858dc0206ba64ac66d1b4ee251e1948..b34446af54724ae8d85f4ff04dd0fd6088baa9d5 100644 (file)
@@ -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.
 //!