]> khamidou — GitHub mirrors - safetensors.git/commit
Refusing to save non contiguous tensors now. (#17)
authorNicolas Patry <patry.nicolas@protonmail.com>
Wed, 5 Oct 2022 08:18:56 +0000 (10:18 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 08:18:56 +0000 (10:18 +0200)
commit9ebf05848467f2fb255039a83649c462875c3b95
tree96d800a3354cf8e0da5818ecac2c03299b68c5a8
parent0d97bcd7869d55af2cbeebafdcf73a16c09c018d
Refusing to save non contiguous tensors now. (#17)

* Refusing to save non contiguous tensors now.

Refusing to save non contiguous tensors now.

It causes weird issues.

1/ It is hard to make it play well with lazy-loading since you would
have 2 call sites, 1 needing to refer to some mother tensor (and
potentially a whole graph of them) that might not yet exist.

```python
x = torch.zeros((20, 20))
y = x[:, 0]

torch.save([x, y], filename)

x1, y1 = torch.load(filename)
y1.fill_(1)
```

This exists because some two different tensors can refer to the same
buffer with different striding, and pytorch save can persist them.

This library and format doesn't enable that so we should just
discard them.

2/ There was a bug when saving from something else than `cpu`
because the pointer would point to a GPU address for instance
so every tensor needs to be brought back before saving
(Unless there's a better way).

3/ Disable saving sparse tensors.

Forcing contiguous tensors from PT.

* Black.

* Fixing sparse.

* Skip if no gpu.

* X

* Y.

* Update bindings/python/py_src/safetensors/torch.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
* Updating quality.

* Rewrite warning multiline.

* Remove `doc-builder` not there yet.

* Factor out flattening.

* Forgot the workflows.

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
15 files changed:
.github/workflows/python.yml
.pre-commit-config.yaml [new file with mode: 0644]
bindings/python/Makefile [new file with mode: 0644]
bindings/python/py_src/safetensors/__init__.py
bindings/python/py_src/safetensors/flax.py
bindings/python/py_src/safetensors/numpy.py
bindings/python/py_src/safetensors/tensorflow.py
bindings/python/py_src/safetensors/torch.py
bindings/python/pyproject.toml [new file with mode: 0644]
bindings/python/setup.cfg [new file with mode: 0644]
bindings/python/setup.py
bindings/python/tests/test_flax_comparison.py
bindings/python/tests/test_pt_comparison.py
bindings/python/tests/test_simple.py
bindings/python/tests/test_tf_comparison.py