safetensors 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of safetensors might be problematic. Click here for more details.
- {safetensors-0.5.0 → safetensors-0.5.1}/PKG-INFO +1 -1
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/Cargo.lock +2 -2
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/Cargo.toml +1 -1
- safetensors-0.5.1/bindings/python/py_src/safetensors/__init__.pyi +149 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/src/lib.rs +3 -1
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/stub.py +30 -7
- safetensors-0.5.1/py_src/safetensors/__init__.pyi +149 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/Cargo.toml +1 -1
- safetensors-0.5.0/bindings/python/py_src/safetensors/__init__.pyi +0 -73
- safetensors-0.5.0/py_src/safetensors/__init__.pyi +0 -73
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/.gitignore +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/MANIFEST.in +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/Makefile +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/README.md +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/benches/test_flax.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/benches/test_mlx.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/benches/test_paddle.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/benches/test_pt.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/benches/test_tf.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/convert.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/convert_all.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/fuzz.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/__init__.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/flax.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/mlx.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/numpy.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/paddle.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/py.typed +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/tensorflow.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/py_src/safetensors/torch.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/setup.cfg +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/data/__init__.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_flax_comparison.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_mlx_comparison.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_paddle_comparison.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_pt_comparison.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_pt_model.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_simple.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/bindings/python/tests/test_tf_comparison.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/__init__.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/flax.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/mlx.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/numpy.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/paddle.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/py.typed +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/tensorflow.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/py_src/safetensors/torch.py +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/pyproject.toml +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/LICENSE +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/README.md +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/benches/benchmark.rs +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/src/lib.rs +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/src/slice.rs +0 -0
- {safetensors-0.5.0 → safetensors-0.5.1}/safetensors/src/tensor.rs +0 -0
|
@@ -163,7 +163,7 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
|
|
163
163
|
|
|
164
164
|
[[package]]
|
|
165
165
|
name = "safetensors"
|
|
166
|
-
version = "0.5.
|
|
166
|
+
version = "0.5.1"
|
|
167
167
|
dependencies = [
|
|
168
168
|
"serde",
|
|
169
169
|
"serde_json",
|
|
@@ -171,7 +171,7 @@ dependencies = [
|
|
|
171
171
|
|
|
172
172
|
[[package]]
|
|
173
173
|
name = "safetensors-python"
|
|
174
|
-
version = "0.5.
|
|
174
|
+
version = "0.5.1"
|
|
175
175
|
dependencies = [
|
|
176
176
|
"memmap2",
|
|
177
177
|
"pyo3",
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Generated content DO NOT EDIT
|
|
2
|
+
@staticmethod
|
|
3
|
+
def deserialize(bytes):
|
|
4
|
+
"""
|
|
5
|
+
Opens a safetensors lazily and returns tensors as asked
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
data (`bytes`):
|
|
9
|
+
The byte content of a file
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
(`List[str, Dict[str, Dict[str, any]]]`):
|
|
13
|
+
The deserialized content is like:
|
|
14
|
+
[("tensor_name", {"shape": [2, 3], "dtype": "F32", "data": b"\0\0.." }), (...)]
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def serialize(tensor_dict, metadata=None):
|
|
20
|
+
"""
|
|
21
|
+
Serializes raw data.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
tensor_dict (`Dict[str, Dict[Any]]`):
|
|
25
|
+
The tensor dict is like:
|
|
26
|
+
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
27
|
+
metadata (`Dict[str, str]`, *optional*):
|
|
28
|
+
The optional purely text annotations
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
(`bytes`):
|
|
32
|
+
The serialized content.
|
|
33
|
+
"""
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def serialize_file(tensor_dict, filename, metadata=None):
|
|
38
|
+
"""
|
|
39
|
+
Serializes raw data.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
tensor_dict (`Dict[str, Dict[Any]]`):
|
|
43
|
+
The tensor dict is like:
|
|
44
|
+
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
45
|
+
filename (`str`, or `os.PathLike`):
|
|
46
|
+
The name of the file to write into.
|
|
47
|
+
metadata (`Dict[str, str]`, *optional*):
|
|
48
|
+
The optional purely text annotations
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
(`bytes`):
|
|
52
|
+
The serialized content.
|
|
53
|
+
"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
class safe_open:
|
|
57
|
+
"""
|
|
58
|
+
Opens a safetensors lazily and returns tensors as asked
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
filename (`str`, or `os.PathLike`):
|
|
62
|
+
The filename to open
|
|
63
|
+
|
|
64
|
+
framework (`str`):
|
|
65
|
+
The framework you want you tensors in. Supported values:
|
|
66
|
+
`pt`, `tf`, `flax`, `numpy`.
|
|
67
|
+
|
|
68
|
+
device (`str`, defaults to `"cpu"`):
|
|
69
|
+
The device on which you want the tensors.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(filename, framework, device=...):
|
|
73
|
+
pass
|
|
74
|
+
def __enter__(self):
|
|
75
|
+
"""
|
|
76
|
+
Start the context manager
|
|
77
|
+
"""
|
|
78
|
+
pass
|
|
79
|
+
def __exit__(self, _exc_type, _exc_value, _traceback):
|
|
80
|
+
"""
|
|
81
|
+
Exits the context manager
|
|
82
|
+
"""
|
|
83
|
+
pass
|
|
84
|
+
def get_slice(self, name):
|
|
85
|
+
"""
|
|
86
|
+
Returns a full slice view object
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
name (`str`):
|
|
90
|
+
The name of the tensor you want
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
(`PySafeSlice`):
|
|
94
|
+
A dummy object you can slice into to get a real tensor
|
|
95
|
+
Example:
|
|
96
|
+
```python
|
|
97
|
+
from safetensors import safe_open
|
|
98
|
+
|
|
99
|
+
with safe_open("model.safetensors", framework="pt", device=0) as f:
|
|
100
|
+
tensor_part = f.get_slice("embedding")[:, ::8]
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
"""
|
|
104
|
+
pass
|
|
105
|
+
def get_tensor(self, name):
|
|
106
|
+
"""
|
|
107
|
+
Returns a full tensor
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
name (`str`):
|
|
111
|
+
The name of the tensor you want
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
(`Tensor`):
|
|
115
|
+
The tensor in the framework you opened the file for.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
```python
|
|
119
|
+
from safetensors import safe_open
|
|
120
|
+
|
|
121
|
+
with safe_open("model.safetensors", framework="pt", device=0) as f:
|
|
122
|
+
tensor = f.get_tensor("embedding")
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
"""
|
|
126
|
+
pass
|
|
127
|
+
def keys(self):
|
|
128
|
+
"""
|
|
129
|
+
Returns the names of the tensors in the file.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
(`List[str]`):
|
|
133
|
+
The name of the tensors contained in that file
|
|
134
|
+
"""
|
|
135
|
+
pass
|
|
136
|
+
def metadata(self):
|
|
137
|
+
"""
|
|
138
|
+
Return the special non tensor information in the header
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
(`Dict[str, str]`):
|
|
142
|
+
The freeform metadata.
|
|
143
|
+
"""
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
class SafetensorError(Exception):
|
|
147
|
+
"""
|
|
148
|
+
Custom Python Exception for Safetensor errors.
|
|
149
|
+
"""
|
|
@@ -406,7 +406,7 @@ impl Open {
|
|
|
406
406
|
|
|
407
407
|
// SAFETY: Mmap is used to prevent allocating in Rust
|
|
408
408
|
// before making a copy within Python.
|
|
409
|
-
let buffer = unsafe { MmapOptions::new().
|
|
409
|
+
let buffer = unsafe { MmapOptions::new().map_copy_read_only(&file)? };
|
|
410
410
|
|
|
411
411
|
let (n, metadata) = SafeTensors::read_metadata(&buffer).map_err(|e| {
|
|
412
412
|
SafetensorError::new_err(format!("Error while deserializing header: {e:?}"))
|
|
@@ -755,10 +755,12 @@ impl safe_open {
|
|
|
755
755
|
self.inner()?.get_slice(name)
|
|
756
756
|
}
|
|
757
757
|
|
|
758
|
+
/// Start the context manager
|
|
758
759
|
pub fn __enter__(slf: Py<Self>) -> Py<Self> {
|
|
759
760
|
slf
|
|
760
761
|
}
|
|
761
762
|
|
|
763
|
+
/// Exits the context manager
|
|
762
764
|
pub fn __exit__(&mut self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) {
|
|
763
765
|
self.inner = None;
|
|
764
766
|
}
|
|
@@ -39,7 +39,14 @@ def member_sort(member):
|
|
|
39
39
|
def fn_predicate(obj):
|
|
40
40
|
value = inspect.ismethoddescriptor(obj) or inspect.isbuiltin(obj)
|
|
41
41
|
if value:
|
|
42
|
-
return
|
|
42
|
+
return (
|
|
43
|
+
obj.__doc__
|
|
44
|
+
and obj.__text_signature__
|
|
45
|
+
and (
|
|
46
|
+
not obj.__name__.startswith("_")
|
|
47
|
+
or obj.__name__ in {"__enter__", "__exit__"}
|
|
48
|
+
)
|
|
49
|
+
)
|
|
43
50
|
if inspect.isgetsetdescriptor(obj):
|
|
44
51
|
return obj.__doc__ and not obj.__name__.startswith("_")
|
|
45
52
|
return False
|
|
@@ -74,7 +81,9 @@ def pyi_file(obj, indent=""):
|
|
|
74
81
|
|
|
75
82
|
body = ""
|
|
76
83
|
if obj.__doc__:
|
|
77
|
-
body +=
|
|
84
|
+
body += (
|
|
85
|
+
f'{indent}"""\n{indent}{do_indent(obj.__doc__, indent)}\n{indent}"""\n'
|
|
86
|
+
)
|
|
78
87
|
|
|
79
88
|
fns = inspect.getmembers(obj, fn_predicate)
|
|
80
89
|
|
|
@@ -84,7 +93,7 @@ def pyi_file(obj, indent=""):
|
|
|
84
93
|
body += f"{indent+INDENT}pass\n"
|
|
85
94
|
body += "\n"
|
|
86
95
|
|
|
87
|
-
for
|
|
96
|
+
for name, fn in fns:
|
|
88
97
|
body += pyi_file(fn, indent=indent)
|
|
89
98
|
|
|
90
99
|
if not body:
|
|
@@ -130,13 +139,18 @@ def do_black(content, is_pyi):
|
|
|
130
139
|
experimental_string_processing=False,
|
|
131
140
|
)
|
|
132
141
|
try:
|
|
142
|
+
content = content.replace("$self", "self")
|
|
133
143
|
return black.format_file_contents(content, fast=True, mode=mode)
|
|
134
144
|
except black.NothingChanged:
|
|
135
145
|
return content
|
|
136
146
|
|
|
137
147
|
|
|
138
148
|
def write(module, directory, origin, check=False):
|
|
139
|
-
submodules = [
|
|
149
|
+
submodules = [
|
|
150
|
+
(name, member)
|
|
151
|
+
for name, member in inspect.getmembers(module)
|
|
152
|
+
if inspect.ismodule(member)
|
|
153
|
+
]
|
|
140
154
|
|
|
141
155
|
filename = os.path.join(directory, "__init__.pyi")
|
|
142
156
|
pyi_content = pyi_file(module)
|
|
@@ -145,7 +159,9 @@ def write(module, directory, origin, check=False):
|
|
|
145
159
|
if check:
|
|
146
160
|
with open(filename, "r") as f:
|
|
147
161
|
data = f.read()
|
|
148
|
-
assert
|
|
162
|
+
assert (
|
|
163
|
+
data == pyi_content
|
|
164
|
+
), f"The content of {filename} seems outdated, please run `python stub.py`"
|
|
149
165
|
else:
|
|
150
166
|
with open(filename, "w") as f:
|
|
151
167
|
f.write(pyi_content)
|
|
@@ -168,7 +184,9 @@ def write(module, directory, origin, check=False):
|
|
|
168
184
|
if check:
|
|
169
185
|
with open(filename, "r") as f:
|
|
170
186
|
data = f.read()
|
|
171
|
-
assert
|
|
187
|
+
assert (
|
|
188
|
+
data == py_content
|
|
189
|
+
), f"The content of {filename} seems outdated, please run `python stub.py`"
|
|
172
190
|
else:
|
|
173
191
|
with open(filename, "w") as f:
|
|
174
192
|
f.write(py_content)
|
|
@@ -184,4 +202,9 @@ if __name__ == "__main__":
|
|
|
184
202
|
args = parser.parse_args()
|
|
185
203
|
import safetensors
|
|
186
204
|
|
|
187
|
-
write(
|
|
205
|
+
write(
|
|
206
|
+
safetensors._safetensors_rust,
|
|
207
|
+
"py_src/safetensors/",
|
|
208
|
+
"safetensors",
|
|
209
|
+
check=args.check,
|
|
210
|
+
)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Generated content DO NOT EDIT
|
|
2
|
+
@staticmethod
|
|
3
|
+
def deserialize(bytes):
|
|
4
|
+
"""
|
|
5
|
+
Opens a safetensors lazily and returns tensors as asked
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
data (`bytes`):
|
|
9
|
+
The byte content of a file
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
(`List[str, Dict[str, Dict[str, any]]]`):
|
|
13
|
+
The deserialized content is like:
|
|
14
|
+
[("tensor_name", {"shape": [2, 3], "dtype": "F32", "data": b"\0\0.." }), (...)]
|
|
15
|
+
"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def serialize(tensor_dict, metadata=None):
|
|
20
|
+
"""
|
|
21
|
+
Serializes raw data.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
tensor_dict (`Dict[str, Dict[Any]]`):
|
|
25
|
+
The tensor dict is like:
|
|
26
|
+
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
27
|
+
metadata (`Dict[str, str]`, *optional*):
|
|
28
|
+
The optional purely text annotations
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
(`bytes`):
|
|
32
|
+
The serialized content.
|
|
33
|
+
"""
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def serialize_file(tensor_dict, filename, metadata=None):
|
|
38
|
+
"""
|
|
39
|
+
Serializes raw data.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
tensor_dict (`Dict[str, Dict[Any]]`):
|
|
43
|
+
The tensor dict is like:
|
|
44
|
+
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
45
|
+
filename (`str`, or `os.PathLike`):
|
|
46
|
+
The name of the file to write into.
|
|
47
|
+
metadata (`Dict[str, str]`, *optional*):
|
|
48
|
+
The optional purely text annotations
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
(`bytes`):
|
|
52
|
+
The serialized content.
|
|
53
|
+
"""
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
class safe_open:
|
|
57
|
+
"""
|
|
58
|
+
Opens a safetensors lazily and returns tensors as asked
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
filename (`str`, or `os.PathLike`):
|
|
62
|
+
The filename to open
|
|
63
|
+
|
|
64
|
+
framework (`str`):
|
|
65
|
+
The framework you want you tensors in. Supported values:
|
|
66
|
+
`pt`, `tf`, `flax`, `numpy`.
|
|
67
|
+
|
|
68
|
+
device (`str`, defaults to `"cpu"`):
|
|
69
|
+
The device on which you want the tensors.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
def __init__(filename, framework, device=...):
|
|
73
|
+
pass
|
|
74
|
+
def __enter__(self):
|
|
75
|
+
"""
|
|
76
|
+
Start the context manager
|
|
77
|
+
"""
|
|
78
|
+
pass
|
|
79
|
+
def __exit__(self, _exc_type, _exc_value, _traceback):
|
|
80
|
+
"""
|
|
81
|
+
Exits the context manager
|
|
82
|
+
"""
|
|
83
|
+
pass
|
|
84
|
+
def get_slice(self, name):
|
|
85
|
+
"""
|
|
86
|
+
Returns a full slice view object
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
name (`str`):
|
|
90
|
+
The name of the tensor you want
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
(`PySafeSlice`):
|
|
94
|
+
A dummy object you can slice into to get a real tensor
|
|
95
|
+
Example:
|
|
96
|
+
```python
|
|
97
|
+
from safetensors import safe_open
|
|
98
|
+
|
|
99
|
+
with safe_open("model.safetensors", framework="pt", device=0) as f:
|
|
100
|
+
tensor_part = f.get_slice("embedding")[:, ::8]
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
"""
|
|
104
|
+
pass
|
|
105
|
+
def get_tensor(self, name):
|
|
106
|
+
"""
|
|
107
|
+
Returns a full tensor
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
name (`str`):
|
|
111
|
+
The name of the tensor you want
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
(`Tensor`):
|
|
115
|
+
The tensor in the framework you opened the file for.
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
```python
|
|
119
|
+
from safetensors import safe_open
|
|
120
|
+
|
|
121
|
+
with safe_open("model.safetensors", framework="pt", device=0) as f:
|
|
122
|
+
tensor = f.get_tensor("embedding")
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
"""
|
|
126
|
+
pass
|
|
127
|
+
def keys(self):
|
|
128
|
+
"""
|
|
129
|
+
Returns the names of the tensors in the file.
|
|
130
|
+
|
|
131
|
+
Returns:
|
|
132
|
+
(`List[str]`):
|
|
133
|
+
The name of the tensors contained in that file
|
|
134
|
+
"""
|
|
135
|
+
pass
|
|
136
|
+
def metadata(self):
|
|
137
|
+
"""
|
|
138
|
+
Return the special non tensor information in the header
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
(`Dict[str, str]`):
|
|
142
|
+
The freeform metadata.
|
|
143
|
+
"""
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
class SafetensorError(Exception):
|
|
147
|
+
"""
|
|
148
|
+
Custom Python Exception for Safetensor errors.
|
|
149
|
+
"""
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Generated content DO NOT EDIT
|
|
2
|
-
@staticmethod
|
|
3
|
-
def deserialize(bytes):
|
|
4
|
-
"""
|
|
5
|
-
Opens a safetensors lazily and returns tensors as asked
|
|
6
|
-
|
|
7
|
-
Args:
|
|
8
|
-
data (:obj:`bytes`):
|
|
9
|
-
The byte content of a file
|
|
10
|
-
|
|
11
|
-
Returns:
|
|
12
|
-
(:obj:`List[str, Dict[str, Dict[str, any]]]`):
|
|
13
|
-
The deserialized content is like:
|
|
14
|
-
[("tensor_name", {"shape": [2, 3], "dtype": "F32", "data": b"\0\0.." }), (...)]
|
|
15
|
-
"""
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def serialize(tensor_dict, metadata=None):
|
|
20
|
-
"""
|
|
21
|
-
Serializes raw data.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
tensor_dict (:obj:`Dict[str, Dict[Any]]`):
|
|
25
|
-
The tensor dict is like:
|
|
26
|
-
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
27
|
-
metadata (:obj:`Dict[str, str]`, *optional*):
|
|
28
|
-
The optional purely text annotations
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
(:obj:`bytes`):
|
|
32
|
-
The serialized content.
|
|
33
|
-
"""
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
@staticmethod
|
|
37
|
-
def serialize_file(tensor_dict, filename, metadata=None):
|
|
38
|
-
"""
|
|
39
|
-
Serializes raw data.
|
|
40
|
-
|
|
41
|
-
Args:
|
|
42
|
-
tensor_dict (:obj:`Dict[str, Dict[Any]]`):
|
|
43
|
-
The tensor dict is like:
|
|
44
|
-
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
45
|
-
filename (:obj:`str`):
|
|
46
|
-
The name of the file to write into.
|
|
47
|
-
metadata (:obj:`Dict[str, str]`, *optional*):
|
|
48
|
-
The optional purely text annotations
|
|
49
|
-
|
|
50
|
-
Returns:
|
|
51
|
-
(:obj:`bytes`):
|
|
52
|
-
The serialized content.
|
|
53
|
-
"""
|
|
54
|
-
pass
|
|
55
|
-
|
|
56
|
-
class safe_open:
|
|
57
|
-
"""
|
|
58
|
-
Opens a safetensors lazily and returns tensors as asked
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
filename (:obj:`str`):
|
|
62
|
-
The filename to open
|
|
63
|
-
|
|
64
|
-
framework (:obj:`str`):
|
|
65
|
-
The framework you want your tensors in. Supported values:
|
|
66
|
-
`pt`, `tf`, `flax`, `numpy`.
|
|
67
|
-
|
|
68
|
-
device (:obj:`str`, defaults to :obj:`"cpu"`):
|
|
69
|
-
The device on which you want the tensors.
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
def __init__(self, filename, framework, device="cpu"):
|
|
73
|
-
pass
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Generated content DO NOT EDIT
|
|
2
|
-
@staticmethod
|
|
3
|
-
def deserialize(bytes):
|
|
4
|
-
"""
|
|
5
|
-
Opens a safetensors lazily and returns tensors as asked
|
|
6
|
-
|
|
7
|
-
Args:
|
|
8
|
-
data (:obj:`bytes`):
|
|
9
|
-
The byte content of a file
|
|
10
|
-
|
|
11
|
-
Returns:
|
|
12
|
-
(:obj:`List[str, Dict[str, Dict[str, any]]]`):
|
|
13
|
-
The deserialized content is like:
|
|
14
|
-
[("tensor_name", {"shape": [2, 3], "dtype": "F32", "data": b"\0\0.." }), (...)]
|
|
15
|
-
"""
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def serialize(tensor_dict, metadata=None):
|
|
20
|
-
"""
|
|
21
|
-
Serializes raw data.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
tensor_dict (:obj:`Dict[str, Dict[Any]]`):
|
|
25
|
-
The tensor dict is like:
|
|
26
|
-
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
27
|
-
metadata (:obj:`Dict[str, str]`, *optional*):
|
|
28
|
-
The optional purely text annotations
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
(:obj:`bytes`):
|
|
32
|
-
The serialized content.
|
|
33
|
-
"""
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
@staticmethod
|
|
37
|
-
def serialize_file(tensor_dict, filename, metadata=None):
|
|
38
|
-
"""
|
|
39
|
-
Serializes raw data.
|
|
40
|
-
|
|
41
|
-
Args:
|
|
42
|
-
tensor_dict (:obj:`Dict[str, Dict[Any]]`):
|
|
43
|
-
The tensor dict is like:
|
|
44
|
-
{"tensor_name": {"dtype": "F32", "shape": [2, 3], "data": b"\0\0"}}
|
|
45
|
-
filename (:obj:`str`):
|
|
46
|
-
The name of the file to write into.
|
|
47
|
-
metadata (:obj:`Dict[str, str]`, *optional*):
|
|
48
|
-
The optional purely text annotations
|
|
49
|
-
|
|
50
|
-
Returns:
|
|
51
|
-
(:obj:`bytes`):
|
|
52
|
-
The serialized content.
|
|
53
|
-
"""
|
|
54
|
-
pass
|
|
55
|
-
|
|
56
|
-
class safe_open:
|
|
57
|
-
"""
|
|
58
|
-
Opens a safetensors lazily and returns tensors as asked
|
|
59
|
-
|
|
60
|
-
Args:
|
|
61
|
-
filename (:obj:`str`):
|
|
62
|
-
The filename to open
|
|
63
|
-
|
|
64
|
-
framework (:obj:`str`):
|
|
65
|
-
The framework you want your tensors in. Supported values:
|
|
66
|
-
`pt`, `tf`, `flax`, `numpy`.
|
|
67
|
-
|
|
68
|
-
device (:obj:`str`, defaults to :obj:`"cpu"`):
|
|
69
|
-
The device on which you want the tensors.
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
|
-
def __init__(self, filename, framework, device="cpu"):
|
|
73
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|