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.
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.
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.
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).
Nicolas Patry [Thu, 29 Sep 2022 07:34:13 +0000 (09:34 +0200)]
Big revamp: (#10)
* Adding slicing support on tensorview.
Clippy 1.64.
Improve the comment.
[WIP] Bad python slice API for now, still looking for a nice pythonesque
one
But at least this works !
Much better API.
Pros:
- handles a lot of boilerplate for caller.
- Feels more pythonesque
Cons:
- Unsure about soundness of keeping Mmap struct.
- Lots more boilerplate in the binding
Removing unused code.
Improved API names hopefully.
Adding .keys() support.
Big revamp:
- Remove `Tensor` to fuse with `TensorView` (the price to pay for shape
cloning should be small enough that it shouldn't make too much of a
difference
- Remove `deserialize_file`, now that we have `safe_open` facility.
- Tried to remove `torch` dependency on `numpy` (Still need the
`torch.Tensor` to bytes without copying facility.
- Revamped the speed tests to show metrics side by side. They need
to be taken with extreme caution, timings are never reproducible.
New possibility to save metadata.
Fixing the workflow.
Rename.
Black.
Installing other libs.
Make windows happy.
Non venv.
Install jax on windows is impossible ?
More private python functions + Windows(flax) shenanigans.
Nicolas Patry [Tue, 22 Feb 2022 16:45:50 +0000 (17:45 +0100)]
Getting something decent.
- Still a copy at the Rust/Python boundaries (ideally we need to
std::mem::forget, and pass raw pointers to Python world to avoid the
copy)
- Saving/Loading, use pure bytes array to avoid writing to disk, but
that does incure more memory usage, maybe something to add later.