]> khamidou — GitHub mirrors - safetensors.git/log
safetensors.git
3 years agoBetter error messages on outdated context manager. (#168)
Nicolas Patry [Fri, 20 Jan 2023 14:05:24 +0000 (15:05 +0100)]
Better error messages on outdated context manager. (#168)

* Better error messages on outdated context manager.

* Clippy.

* Remove unwrap.

* Fix.

3 years agoMinor pydoc fixes for torch bindings (#167)
John B Nelson [Fri, 20 Jan 2023 10:07:11 +0000 (02:07 -0800)]
Minor pydoc fixes for torch bindings (#167)

3 years agoFixing the fact that the context manager wasn't properly cleaning up after itself...
Nicolas Patry [Thu, 19 Jan 2023 13:30:56 +0000 (14:30 +0100)]
Fixing the fact that the context manager wasn't properly cleaning up after itself. (#166)

* Adding failing test for windows.

* This should fail.

* Fixing Windows issue by actually dropping the rust resources.

* Making the rust module private.

3 years agoAdding custom error type for users to properly catch. (#165)
Nicolas Patry [Tue, 17 Jan 2023 17:06:34 +0000 (18:06 +0100)]
Adding custom error type for users to properly catch. (#165)

3 years agoAdded JSONSchema of the header. (#151)
KOLANICH [Tue, 17 Jan 2023 16:39:47 +0000 (16:39 +0000)]
Added JSONSchema of the header. (#151)

3 years agoEnabling 3.8 support for M1. (#162)
Nicolas Patry [Tue, 17 Jan 2023 09:04:04 +0000 (10:04 +0100)]
Enabling 3.8 support for M1. (#162)

3 years agoUpdate README.md (#163)
Thomas Wang [Tue, 17 Jan 2023 09:02:28 +0000 (10:02 +0100)]
Update README.md (#163)

* Update README.md

Link to huggingface.co documentation

* Make rust doc match

* Why is the documentation at three different places?

3 years agoNew unreleased version. (#161)
Nicolas Patry [Mon, 16 Jan 2023 15:40:29 +0000 (16:40 +0100)]
New unreleased version. (#161)

* New unreleased version.

* Making only 1 release now.

3 years agoImprove type hinting (#159)
Thomas Wang [Mon, 16 Jan 2023 14:28:18 +0000 (15:28 +0100)]
Improve type hinting (#159)

3 years agoFix byte order detection for `np.uint8` and other types for which byte order is not...
Nicolas Patry [Mon, 16 Jan 2023 12:42:22 +0000 (13:42 +0100)]
Fix byte order detection for `np.uint8` and other types for which byte order is not defined. (#160)

* Fix byte order detection for `np.uint8` and other types for which byte order is not defined.

* Fixing np.uint8 endianness for `save`.

Co-authored-by: KOLANICH <kolan_n@mail.ru>
3 years agoPreparing next version. (#158)
Nicolas Patry [Mon, 16 Jan 2023 09:34:28 +0000 (10:34 +0100)]
Preparing next version. (#158)

3 years agoUpdating rust ergonomics. (#144)
Nicolas Patry [Fri, 30 Dec 2022 13:28:44 +0000 (14:28 +0100)]
Updating rust ergonomics. (#144)

- `get_` prefix removed in a few functions.
- Make error implement Error.

3 years agoFixing torch version parsing. (#143)
Nicolas Patry [Thu, 29 Dec 2022 07:17:56 +0000 (08:17 +0100)]
Fixing torch version parsing. (#143)

* Fixing torch version parsing.

* Anticipating a bit more variations of this.

3 years agoUpdate docstrings & type-hints (#139)
Alvaro Bartolome [Tue, 27 Dec 2022 09:02:52 +0000 (10:02 +0100)]
Update docstrings & type-hints (#139)

3 years agoMaking SAFETENSORS_FAST_GPU=1 work on Windows again. (#140)
Nicolas Patry [Tue, 27 Dec 2022 08:13:28 +0000 (09:13 +0100)]
Making SAFETENSORS_FAST_GPU=1 work on Windows again. (#140)

* Making Windows load cudart differently.

* Remove unsafe.

* Misplaced comment

3 years agoAdding stale bot. (#135)
Nicolas Patry [Mon, 19 Dec 2022 12:50:15 +0000 (13:50 +0100)]
Adding stale bot. (#135)

* Adding stale bot.

* Clippy.

3 years agoFix readme typos (#133)
Vilém Zouhar [Thu, 15 Dec 2022 08:38:37 +0000 (09:38 +0100)]
Fix readme typos (#133)

* fix readme typos

* Replicating docs on all 3 files.

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
3 years agoNew version. (#132)
Nicolas Patry [Wed, 14 Dec 2022 12:55:28 +0000 (13:55 +0100)]
New version. (#132)

3 years agoUpdate README.md (#131)
Thomas Wang [Wed, 14 Dec 2022 10:23:50 +0000 (11:23 +0100)]
Update README.md (#131)

* Update README.md

* Update other files.

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
3 years agoFixing it for `diffusers`. (#130)
Nicolas Patry [Tue, 13 Dec 2022 16:17:42 +0000 (17:17 +0100)]
Fixing it for `diffusers`. (#130)

3 years agoNecessary modifications to publish on Rust. (#129)
Nicolas Patry [Tue, 13 Dec 2022 15:14:56 +0000 (16:14 +0100)]
Necessary modifications to publish on Rust. (#129)

* Adding Info to publish.

* Bench.

* Update README.

3 years agoRelease rust. (#126)
Nicolas Patry [Mon, 12 Dec 2022 13:59:19 +0000 (14:59 +0100)]
Release rust. (#126)

3 years agoKeras new format is not safe. (#127)
Nicolas Patry [Mon, 12 Dec 2022 10:40:56 +0000 (11:40 +0100)]
Keras new format is not safe. (#127)

3 years agoAdding support for Python 3.11 on Linux + fix the source build wheel. (#125)
Nicolas Patry [Mon, 12 Dec 2022 09:24:49 +0000 (10:24 +0100)]
Adding support for Python 3.11 on Linux + fix the source build wheel. (#125)

3 years agoPython fuzzing. (#123)
Nicolas Patry [Wed, 7 Dec 2022 16:04:03 +0000 (17:04 +0100)]
Python fuzzing. (#123)

3 years agoMinor typo (#121)
lsb [Tue, 6 Dec 2022 09:25:11 +0000 (01:25 -0800)]
Minor typo (#121)

* Minor typo

* READMEs.

* Fix the reamde? ??

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
3 years agoAdding `cargo fuzz` and found sanitation opportunities. (#119)
Nicolas Patry [Mon, 5 Dec 2022 17:33:12 +0000 (18:33 +0100)]
Adding `cargo fuzz` and found sanitation opportunities. (#119)

* Adding `cargo fuzz` and found sanitation opportunities.

* Better code.

3 years agoSupporting stable-diffusion by default. (#118)
Nicolas Patry [Wed, 30 Nov 2022 16:01:55 +0000 (17:01 +0100)]
Supporting stable-diffusion by default. (#118)

* New updates.

* Force load checkpoint on cpu.

3 years agoSupporting stable-diffusion by default. (#117)
Nicolas Patry [Wed, 30 Nov 2022 13:46:38 +0000 (14:46 +0100)]
Supporting stable-diffusion by default. (#117)

3 years agoAdd pip installation guide (#116)
Patrick von Platen [Mon, 28 Nov 2022 13:26:04 +0000 (14:26 +0100)]
Add pip installation guide (#116)

* Add pip installation guide

* Update the 3 locations.

* Those are not doctests.

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
4 years agoNew version. (#114)
Nicolas Patry [Sat, 26 Nov 2022 21:17:34 +0000 (22:17 +0100)]
New version. (#114)

4 years agoI hate yaml. (#110)
Nicolas Patry [Wed, 23 Nov 2022 19:57:32 +0000 (20:57 +0100)]
I hate yaml. (#110)

4 years agoUpdate workflow. (#109)
Nicolas Patry [Wed, 23 Nov 2022 19:27:02 +0000 (20:27 +0100)]
Update workflow. (#109)

4 years agoM1 fix (pyenv cannot use `3.11`. (#108)
Nicolas Patry [Wed, 23 Nov 2022 18:28:38 +0000 (19:28 +0100)]
M1 fix (pyenv cannot use `3.11`. (#108)

4 years agoFixes https://github.com/huggingface/safetensors/actions/runs/3534003128/jobs/5930362...
Nicolas Patry [Wed, 23 Nov 2022 17:11:10 +0000 (18:11 +0100)]
Fixes https://github.com/huggingface/safetensors/actions/runs/3534003128/jobs/5930362952 (#107)

4 years agoImprove error message when saving bogus object. (#106)
Nicolas Patry [Wed, 23 Nov 2022 14:41:36 +0000 (15:41 +0100)]
Improve error message when saving bogus object. (#106)

4 years agoFix `convert.py` to handle diffusers, and its transformers part (#105)
Nicolas Patry [Wed, 23 Nov 2022 14:41:15 +0000 (15:41 +0100)]
Fix `convert.py` to handle diffusers, and its transformers part (#105)

Turns out `diffusers` does rely on `transformers`:

`pytorch_model.safetensors` was not a recognized filename by
`transformers` which expects it to be named `model.safetensors`.

The convert_generic works by simply creating the new files and changing
the extension, which broke this.

Current proposed fix is to handle specially files named
`pytorch_model.bin` since they are more likely to be `transformers`
files.

This is however not necessarily true, we might want to protect with
checking against `model_info.library_name` though I feel like this is
better to just check against the name, since it's still likely to be a
transformers/diffusers/sentence-transformers thing.

4 years agoPreparing for release. (#104)
Nicolas Patry [Wed, 23 Nov 2022 10:47:35 +0000 (11:47 +0100)]
Preparing for release. (#104)

4 years agoconvert hotfix. (#102)
Nicolas Patry [Tue, 22 Nov 2022 16:00:05 +0000 (17:00 +0100)]
convert hotfix. (#102)

4 years agoSmall qol. (#101)
Nicolas Patry [Tue, 22 Nov 2022 15:07:47 +0000 (16:07 +0100)]
Small qol. (#101)

4 years agoAdding suppot for 3.11 where possible (conda does not support 3.11 yet). (#97)
Nicolas Patry [Tue, 22 Nov 2022 14:36:11 +0000 (15:36 +0100)]
Adding suppot for 3.11 where possible (conda does not support 3.11 yet). (#97)

* Adding suppot for 3.11 where possible (conda does not support 3.11 yet).

* Update .github/workflows/python-release.yml

* Update .github/workflows/python-release-conda.yml

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
4 years agoMaking convertion working with diffusers/stable-diffusion. (#96)
Nicolas Patry [Tue, 22 Nov 2022 14:25:30 +0000 (15:25 +0100)]
Making convertion working with diffusers/stable-diffusion. (#96)

* Making convertion working with diffusers/stable-diffusion.

* Update bindings/python/convert.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
4 years agoFixing Windows overflow issue with `c_long`. (#99)
Nicolas Patry [Tue, 22 Nov 2022 14:07:31 +0000 (15:07 +0100)]
Fixing Windows overflow issue with `c_long`. (#99)

* Fixing Windows overflow issue with `c_long`.

* Adding comment to remove the code once fixed.

* Fixing just like PyO3.

4 years agoIgnore unsound criterion. (#100)
Nicolas Patry [Tue, 22 Nov 2022 12:12:42 +0000 (13:12 +0100)]
Ignore unsound criterion. (#100)

4 years ago[docs] we want markdnwo headings to show (#94)
Mishig [Fri, 18 Nov 2022 14:47:04 +0000 (15:47 +0100)]
[docs] we want markdnwo headings to show (#94)

4 years agoAccepting `pathlib.Path` in `save_file/load_file/safe_open`. (#86)
Nicolas Patry [Fri, 18 Nov 2022 14:24:35 +0000 (15:24 +0100)]
Accepting `pathlib.Path` in `save_file/load_file/safe_open`. (#86)

* Accepting `pathlib.Path` in `save_file/load_file/safe_open`.

* as_path.

* Update docstrings.

- Removed unused `:obj:`
- Put `os.PathLike` everywhere it's needed
- python stub.py

4 years agoTorch fixes (#90)
Nicolas Patry [Fri, 18 Nov 2022 13:40:12 +0000 (14:40 +0100)]
Torch fixes (#90)

* Fix `KeyError: torch.float64` when serializing tensors of doubles and `KeyError: BF16` when parsing.

* Fix non-working `_view2torch` because of the forgotten returns.
Added some tests.

* Test in the same style.

* Like previous style.

Co-authored-by: KOLANICH <kolan_n@mail.ru>
4 years ago[docs] fix notebook automatic creation (#92)
Mishig [Fri, 18 Nov 2022 13:39:31 +0000 (14:39 +0100)]
[docs] fix notebook automatic creation (#92)

4 years ago[docs] Fixes the colab btn on speed page (#91)
Mishig [Fri, 18 Nov 2022 13:15:53 +0000 (14:15 +0100)]
[docs] Fixes the colab btn on speed page (#91)

4 years agoAdd missing doc build token (#89)
Mishig [Fri, 18 Nov 2022 12:47:01 +0000 (13:47 +0100)]
Add missing doc build token (#89)

4 years ago[docs] Loading speed benchmark (#80)
Mishig [Fri, 18 Nov 2022 12:18:05 +0000 (13:18 +0100)]
[docs] Loading speed benchmark (#80)

* [docs] Loading speed benchmark

* Add speed reference in index

* chore

* make print statement clearer

* remove repetition

* add notebooks folder

* fuse `device` lines

* add specs

* rm unneded lines

* Update docs/source/speed.mdx

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
4 years agodelete_doc_comment.yml should only run on pull request closed (#88)
Mishig [Fri, 18 Nov 2022 11:04:01 +0000 (12:04 +0100)]
delete_doc_comment.yml should only run on pull request closed (#88)

4 years agoTrigger doc build on specific changes (#87)
Mishig [Fri, 18 Nov 2022 10:40:30 +0000 (11:40 +0100)]
Trigger doc build on specific changes (#87)

* Trigger doc build on specific changes

* chore

4 years agoMade the rust version consistent between `safetensors` and this crate. (#83)
KOLANICH [Fri, 18 Nov 2022 09:19:54 +0000 (09:19 +0000)]
Made the rust version consistent between `safetensors` and this crate. (#83)

4 years agoPreventing big endian files to be saved. (#82)
Nicolas Patry [Fri, 18 Nov 2022 09:19:27 +0000 (10:19 +0100)]
Preventing big endian files to be saved. (#82)

4 years agoFixing unimplemented into real exception. (#78)
Nicolas Patry [Thu, 17 Nov 2022 19:08:25 +0000 (20:08 +0100)]
Fixing unimplemented into real exception. (#78)

4 years agoAdd installation section (#71)
Mishig [Thu, 17 Nov 2022 10:16:11 +0000 (11:16 +0100)]
Add installation section (#71)

4 years agoFix doc build actions (#70)
Mishig [Thu, 17 Nov 2022 09:37:40 +0000 (10:37 +0100)]
Fix doc build actions (#70)

* Fix doc build actions

* Add remaining doc gh ymls

4 years agopip install .[dev] (#68)
Mishig [Wed, 16 Nov 2022 15:35:03 +0000 (16:35 +0100)]
pip install .[dev] (#68)

* Update setup.py

* add click==8.0.4 to setup.py

* gh actions use pip install .[dev]

* Update binding local dev readme

* fix gh action

* fix gh action

* fix gh action ?

* don't install jax flax on windows

* try removing unused deps

4 years agoNew version. (#63)
Nicolas Patry [Tue, 8 Nov 2022 14:47:29 +0000 (15:47 +0100)]
New version. (#63)

* New version.

* mmap2.

4 years agoAdding cargo audit check. (#64)
Nicolas Patry [Tue, 8 Nov 2022 14:47:22 +0000 (15:47 +0100)]
Adding cargo audit check. (#64)

* Adding cargo audit check.

* Update command line.

* Update affected crates.

4 years agoAdding the convert scripts which will now prevent converting models (#59)
Nicolas Patry [Fri, 4 Nov 2022 16:38:58 +0000 (17:38 +0100)]
Adding the convert scripts which will now prevent converting models (#59)

* Adding the convert scripts which will now prevent converting models

in case they will trigger warnigns in the `transformers` side.
Even if the model is perfectly fine, core maintainers fear an influx
of opened issues.

This is perfectly legit.
On the `transformers` side fixes are on the way: https://github.com/huggingface/transformers/pull/20042

We can wait for this PR to hit `main` before communicating super widely.

In the meantime this script of convertion will now prevent converting
models that would trigger such warnings (so the output of the script
**will** depend on the `transformers` freshness.

* Adding a nicer diff for the error when reloading.

4 years agoPreparing for release. (#60)
Nicolas Patry [Fri, 4 Nov 2022 14:42:43 +0000 (15:42 +0100)]
Preparing for release. (#60)

4 years agoFound out about `torch.asarray` + `torch.Storage` combo. (#56)
Nicolas Patry [Fri, 4 Nov 2022 14:02:30 +0000 (15:02 +0100)]
Found out about `torch.asarray` + `torch.Storage` combo. (#56)

* Found out about `torch.asarray` + `torch.Storage` combo.

Extremely fast (I'm guessing it's just pointer arithmetic and actual
load time would it when actually using the tensors.)

* Dropping 1.10 support (no `asarray`.)

* Accepting torch==1.10.0 in slow mode.

* Adding a comment about `Storage`.

4 years agoSupporting `safe_open` for TF and Flax. (#58)
Nicolas Patry [Thu, 3 Nov 2022 16:04:27 +0000 (17:04 +0100)]
Supporting `safe_open` for TF and Flax. (#58)

* Supporting `safe_open` for TF and Flax.

* Move tensors only on Pytorch.

4 years agoMake GPU loading faster by removing all extra CPU copies. (#33)
Nicolas Patry [Wed, 2 Nov 2022 15:53:50 +0000 (16:53 +0100)]
Make GPU loading faster by removing all extra CPU copies. (#33)

* Faster gpu load.

Use cuda-sys directly.

For slice too.

Fun unsafe.

Reduce unsafe.

Removing CPU unsafe.

Using shared `cuda-sys` (temporary, we need to use torch's cuda version).

Tmp rework

Cleaner device.

Adding some statistics...

Warmup steps.

Removing unsafe GPU accesses.

Removing dead code.

Removing libloading.

Revert "Removing unsafe GPU accesses."

This reverts commit 5325ba2b73fffc16416130193da1690353e0a7db.

Unsafe comments.

Using GILOnceCell for module reuse.

Finding the lib through the real python workload.
Still requires transitive library parsing.

Stable with global lib ref.

Abort.

Weird bug on torch 1.13.

We **need** to get the data_ptr within the loop ?

* Fixing speedup by loading directly the loaded C library within Python.

* Cleanup.

* Finishing touches.

* Remove some code duplication.

Some very weird errors in calling the `cudaMemcpy` that fail depending
on order. Even aliasing the `Symbol` seem to be unsafe.

* Adding some comments.

* Better signature. Static symbol instead of lib.

4 years agoAdding more docs: (#53)
Nicolas Patry [Wed, 2 Nov 2022 15:53:33 +0000 (16:53 +0100)]
Adding more docs: (#53)

- Simple python example on the README.md
- Added `npz` and `arrow` formats to the table (not exhaustively)
- Added `benefits` section.

4 years agoAdding M1 (mps) benchmarks (going first through CPU seems faster though? (#51)
Nicolas Patry [Wed, 2 Nov 2022 15:53:16 +0000 (16:53 +0100)]
Adding M1 (mps) benchmarks (going first through CPU seems faster though? (#51)

but PT is just as slow going directly on MPS.).

4 years agoBenching only after merging. (#54)
Nicolas Patry [Wed, 2 Nov 2022 15:52:53 +0000 (16:52 +0100)]
Benching only after merging. (#54)

4 years agoAdding docs (#55)
Mishig [Wed, 2 Nov 2022 15:52:39 +0000 (16:52 +0100)]
Adding docs (#55)

* Initialize docs

* Add build pr github action

* Adding a bunch of documentation.

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
4 years agoRe-enabling manylinux2014 builds. (#52)
Nicolas Patry [Wed, 2 Nov 2022 09:31:45 +0000 (10:31 +0100)]
Re-enabling manylinux2014 builds. (#52)

* Debugging creating manylinux release.

* Using git-cli to reduce memory usage.

* Fixed it.

4 years agoSplitting up tests from benchmarks. (#50)
Nicolas Patry [Tue, 1 Nov 2022 18:00:24 +0000 (19:00 +0100)]
Splitting up tests from benchmarks. (#50)

* Splitting up tests from benchmarks.

* Skipping if cuda is not available.

* Fix condition.

* Working directory.

* Different location.

* Auto-push on GH pages.

* Benching for real.

4 years agoAdd convert all (#47)
Nicolas Patry [Tue, 1 Nov 2022 08:05:18 +0000 (09:05 +0100)]
Add convert all (#47)

* More convertion tool.

* Hardened convert script.

* Even more hardening.

* Style.

* Adding conversion scripts for all.

* Use api (with token) to get repo discussion.

Some models have discussions disabled, ignore them.

4 years agoSharing modules. (#48)
Nicolas Patry [Tue, 1 Nov 2022 08:04:40 +0000 (09:04 +0100)]
Sharing modules. (#48)

4 years agoTesting torch==1.10 (lowest available on transformers with `frombuffer`) too. (#46)
Nicolas Patry [Tue, 1 Nov 2022 07:52:03 +0000 (08:52 +0100)]
Testing torch==1.10 (lowest available on transformers with `frombuffer`) too. (#46)

* Testing torch==1.7 (lowest available on transformers) too.

* Running the checks every single time.

* Minimum required version is going to be torch==1.10.

Before that `frombuffer` didn't exist.
And since we want `bfloat16` support it's pretty much impossible
to use `numpy` or copy directly to the buffer with `set_`.

We could technically `memcpy` the buffer directly but it feels
overkill.

4 years agoFormat "Format" better for GitHub markdown flavor (#43)
Julien Chaumond [Mon, 31 Oct 2022 11:04:24 +0000 (12:04 +0100)]
Format "Format" better for GitHub markdown flavor (#43)

* Format "Format" better for GitHub markdown flavor

* Format needs to change the rustdoc.

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
4 years agoSupporting torch==1.13.0 (#45)
Nicolas Patry [Mon, 31 Oct 2022 09:13:32 +0000 (10:13 +0100)]
Supporting torch==1.13.0 (#45)

4 years agoUse BTreeMap instead of HashMap (#42)
Thomas Wang [Sat, 29 Oct 2022 14:08:45 +0000 (16:08 +0200)]
Use BTreeMap instead of HashMap (#42)

* Use BTreeMap instead of HashMap

Co-authored-by: OlivierDehaene <23298448+OlivierDehaene@users.noreply.github.com>
4 years agoPreparing for next release. (#38)
Nicolas Patry [Thu, 27 Oct 2022 16:20:04 +0000 (18:20 +0200)]
Preparing for next release. (#38)

* Preparing for next release.

* Actually, let's release to remove `importlib`.

4 years agoMoving tensor validation (length wise) directly in validate. (#37)
Nicolas Patry [Thu, 27 Oct 2022 11:48:45 +0000 (13:48 +0200)]
Moving tensor validation (length wise) directly in validate. (#37)

4 years agoMake sure we're python3.7 compliant. (#40)
Nicolas Patry [Thu, 27 Oct 2022 11:48:30 +0000 (13:48 +0200)]
Make sure we're python3.7 compliant. (#40)

4 years agoPreparing for release 0.2.2 (#36)
Nicolas Patry [Wed, 26 Oct 2022 14:43:18 +0000 (16:43 +0200)]
Preparing for release 0.2.2 (#36)

4 years agoSome PyO3 specifics. (#35)
Nicolas Patry [Wed, 26 Oct 2022 13:49:10 +0000 (15:49 +0200)]
Some PyO3 specifics. (#35)

* Faster gpu load.

* Use cuda-sys directly.

* For slice too.

* Fun unsafe.

* Reduce unsafe.

* Removing CPU unsafe.

* Using shared `cuda-sys` (temporary, we need to use torch's cuda version).

* Tmp rework

* Cleaner device.

* Adding some statistics...

* Warmup steps.

* Removing unsafe GPU accesses.

* Removing dead code.

* Removing libloading.

* Accepting `int` as device.

4 years agoActually pass along metadata (#34)
Sylvain Gugger [Wed, 26 Oct 2022 08:42:11 +0000 (04:42 -0400)]
Actually pass along metadata (#34)

4 years agoLess GIL locks speeds things up apparently ? (#31)
Nicolas Patry [Fri, 21 Oct 2022 08:57:15 +0000 (10:57 +0200)]
Less GIL locks speeds things up apparently ? (#31)

* Less GIL locks speeds things up apparently ?

* Fixing `.to()` which cannot be called for non PT frameworks.

* Forgot to update.

* Skipping GPU if not available.

* Fixing tests by removing filename clash.

4 years agoUpdating convert script + fixing index. (#29)
Nicolas Patry [Fri, 21 Oct 2022 07:09:55 +0000 (09:09 +0200)]
Updating convert script + fixing index. (#29)

* Updating convert script + fixing index.

* Cleaning even when exceptions occur.

4 years ago Fixing potential DOS attacks. (#26)
Nicolas Patry [Thu, 20 Oct 2022 16:33:56 +0000 (18:33 +0200)]
 Fixing potential DOS attacks. (#26)

* Fixing potential DOS attacks.

- Fixed code sharing between rust package and python bindings in
  `safe_open` (where possible).
- Added a maximum size for the header (now hardcoded to 100Mo).
  A very large JSON header could indeed slow things down effectively
  (takes a few seconds to parse). This one is debattable.
- Added a safety check when deserializing the header.
  If offsets could overlap, then we could still DOS users because we
  could force them into allocating over and over the same buffer,
  leading to RAM explosion. This fixes it by checking out that the offset
  ranges are contiguous after loading the header.

* Make `Metadata::new()` faillible.

so we sanitize before writing to file.

4 years agoUpdate bindings readme (#30)
Mishig [Thu, 20 Oct 2022 16:33:26 +0000 (18:33 +0200)]
Update bindings readme (#30)

* Update README.md

* dev mode

4 years agoCreating a few range of attacks against classic formats. (#25)
Nicolas Patry [Thu, 20 Oct 2022 15:18:28 +0000 (17:18 +0200)]
Creating a few range of attacks against classic formats. (#25)

- pickle (ACE affecting PT)
- zip (Denial of Service affecting numpy + PT)
- marshal (affecting Keras, not directly in the h5 file format)

- Created 8 proposals to abuse the current format.
  Found 2 kind of flaws that could also cause some form of denial of
  service). PRs coming up.

4 years ago[MINOR FIX] Fix markdown header (#28)
Christopher Akiki [Thu, 20 Oct 2022 10:49:27 +0000 (12:49 +0200)]
[MINOR FIX] Fix markdown header (#28)

* Fix markdown header

* Add fixed README

4 years agoExplaining the `__metadata__` in the spec. (#23)
Nicolas Patry [Wed, 19 Oct 2022 23:26:56 +0000 (01:26 +0200)]
Explaining the `__metadata__` in the spec. (#23)

4 years agoAdding `convert.py` utility tool to convert models on the hub easily. (#24)
Nicolas Patry [Wed, 19 Oct 2022 17:30:51 +0000 (19:30 +0200)]
Adding `convert.py` utility tool to convert models on the hub easily. (#24)

* Adding `convert.py` utility tool to convert models on the hub easily.

It creates a PR so it should be safe to use on any repo.

* Fixing the `convert.py` script for multi

Catching on EntryNotFoundError.

* Update bindings/python/convert.py

Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
4 years agoPush for `.safetensors` instead of `.bin`. (#22)
Nicolas Patry [Wed, 19 Oct 2022 10:16:07 +0000 (12:16 +0200)]
Push for `.safetensors` instead of `.bin`. (#22)

* Push for `.safetensors` instead of `.bin`.

* Bad replace.

4 years agoMaking sure the main README is in sync with the rustdoc. (#21)
Nicolas Patry [Wed, 19 Oct 2022 08:58:48 +0000 (10:58 +0200)]
Making sure the main README is in sync with the rustdoc. (#21)

(Makes it easier to have a single groundtruth).

4 years agoImplement benchmarking using Criterion (#19)
Mishig [Fri, 7 Oct 2022 14:10:34 +0000 (16:10 +0200)]
Implement benchmarking using Criterion (#19)

4 years agoRefusing to save non contiguous tensors now. (#17)
Nicolas Patry [Wed, 5 Oct 2022 08:18:56 +0000 (10:18 +0200)]
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>
4 years agoUse np.prod for compatibility with Python 3.7 (#14)
Sylvain Gugger [Fri, 30 Sep 2022 11:36:02 +0000 (07:36 -0400)]
Use np.prod for compatibility with Python 3.7 (#14)

4 years agoBump version number for next release. (#13)
Nicolas Patry [Fri, 30 Sep 2022 08:37:19 +0000 (10:37 +0200)]
Bump version number for next release. (#13)

4 years agoRemoving dev suffix. (#12)
Nicolas Patry [Thu, 29 Sep 2022 13:31:17 +0000 (15:31 +0200)]
Removing dev suffix. (#12)

4 years agoUpdate README.md (#11)
Nicolas Patry [Thu, 29 Sep 2022 13:21:07 +0000 (15:21 +0200)]
Update README.md (#11)

* Update README.md

* Update bindings/python/README.md

Co-authored-by: Mishig Davaadorj <mishig.davaadorj@coloradocollege.edu>
Co-authored-by: Mishig Davaadorj <mishig.davaadorj@coloradocollege.edu>