Skip to content

Commit

Permalink
Release 0.15.0 (#1014)
Browse files Browse the repository at this point in the history
* Update VERSION
* Remove code for backwards compatibility with v0.11
* Update CHANGES.md

Since skorch nets pickled with <= v0.11 can no longer be unpickled, I
added an entry on how to transition these pickle files.

Release text:

This is a smaller release, but it still contains changes which will be
interesting to some of you.

We added the possibility to store weights using safetensors. This can have
several advantages, listed here. When calling net.save_params and
net.load_params, just pass use_safetensors=True to use safetensors instead of
pickle.

Moreover, there is a new argument on NeuralNet: You can now pass
use_caching=False or True to disable or enable caching for all callbacks at
once. This is useful if you have a lot of scoring callbacks and don't want to
toggle caching on each individually.

Finally, we fixed a few issues related to using skorch with accelerate.

Thanks Zach Mueller (@ muellerzr) for his first contribution to skorch.
  • Loading branch information
BenjaminBossan committed Sep 4, 2023
1 parent 7fd4b6e commit 17c7675
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 56 deletions.
17 changes: 14 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Add the option to globally override the use of caching in scoring callbacks on the net by setting the `use_caching` argument on the net (this overrides the settings of individual callbacks)
- Add support for saving and loading parameters with [safetensors](https://github.com/huggingface/safetensors/); use `net.save_params(..., use_safetensors=True)` and `net.load_params(..., use_safetensors=True)` (requires to install the `safetensors` library)
### Changed
### Fixed

## [0.15.0] - 2023-09-04

### Added
- Add the option to globally override the use of caching in scoring callbacks on the net by setting the `use_caching` argument on the net (this overrides the settings of individual callbacks) (#971)
- Add support for saving and loading parameters with [safetensors](https://github.com/huggingface/safetensors/); use `net.save_params(..., use_safetensors=True)` and `net.load_params(..., use_safetensors=True)` (requires to install the `safetensors` library) (#970)

### Changed
- Nets pickled with skorch version 0.11 can no longer be loaded in version 0.15 (see #880); to transition these nets, pickle them in a skorch version between 0.12 and 0.14, then load them in 0.15

### Fixed

- Fixed a couple of issues when saving and loading parameters while using accelerate (via `AccelerateMixin`) in a multi-GPU setting (#1008)
- Fixed a couple of issues when saving and loading parameters while using accelerate (via `AccelerateMixin`) in a multi-GPU setting, and some other minor accelerate issues (#1008, #1009)
- Installing skorch with the `[testing]` option now installs all dev requirements (#1015)

## [0.14.0] - 2023-06-24

Expand Down Expand Up @@ -333,3 +343,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.12.1]: https://github.com/skorch-dev/skorch/compare/v0.12.0...v0.12.1
[0.13.0]: https://github.com/skorch-dev/skorch/compare/v0.12.1...v0.13.0
[0.14.0]: https://github.com/skorch-dev/skorch/compare/v0.13.0...v0.14.0
[0.15.0]: https://github.com/skorch-dev/skorch/compare/v0.14.0...v0.15.0
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.1dev0
0.15.0
18 changes: 0 additions & 18 deletions skorch/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,24 +2219,6 @@ def __getstate__(self):
return state

def __setstate__(self, state):
# TODO remove after 2023-09
# in skorch 0.11 -> 0.12, we made a change to parameter validation. We
# don't store key/vals in self._kwargs anymore, as the values were
# redundant and were not considered as possibly CUDA dependent. Instead,
# we now use the attribute '_params_to_validate', which only stores
# keys. The code below is to make the net backwards compatible.
if '_kwargs' in state:
if '_params_to_validate' in state:
# there should not be _kwargs AND _params_to_validate
raise ValueError(
"Something went wrong here. Please open an issue on "
"https://github.com/skorch-dev/skorch/issues detailing what "
"caused this error and the used skorch version."
)
kwargs = state.pop('_kwargs')
params_to_validate = set(kwargs.keys())
state['_params_to_validate'] = params_to_validate

# get_map_location will automatically choose the
# right device in cases where CUDA is not available.
map_location = get_map_location(state['device'])
Expand Down
34 changes: 0 additions & 34 deletions skorch/tests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,40 +441,6 @@ def test_pickle_load(self, cuda_available, pickled_cuda_net_path):
with open(pickled_cuda_net_path, 'rb') as f:
pickle.load(f)

def test_load_net_with_kwargs_attribute_to_net_without(self, net_pickleable):
# TODO remove after 2023-09
# in skorch 0.11 -> 0.12, we made a change to parameter validation. We
# don't store key/vals in self._kwargs anymore, as the values were
# redundant and were not considered as possibly CUDA dependent, which
# can cause errors when loading to CPU. Since we remove one attribute
# and add a new one ('_params_to_validate'), we have to take extra steps
# to ensure that old models can still be loaded correctly.

# emulate old net:
del net_pickleable._params_to_validate
net_pickleable._kwargs = {'foo': 123, 'bar__baz': 456}

# after loading, behaves like new net
net_loaded = pickle.loads(pickle.dumps(net_pickleable))
assert net_loaded._params_to_validate == {'foo', 'bar__baz'}
assert not hasattr(net_loaded, '_kwargs')

def test_load_net_with_both_kwargs_and_params_to_validate_attributes_raises(
self, net_pickleable
):
# TODO remove after 2023-09
# Check test_load_net_with_kwargs_attribute_to_net_without for more
# details
net_pickleable._kwargs = {'foo': 123}
net_pickleable._params_to_validate = {'foo'}
msg = (
"Something went wrong here. Please open an issue on "
"https://github.com/skorch-dev/skorch/issues detailing what "
"caused this error and the used skorch version."
)
with pytest.raises(ValueError, match=msg):
pickle.loads(pickle.dumps(net_pickleable))

@pytest.mark.parametrize('device', ['cpu', 'cuda'])
def test_device_torch_device(self, net_cls, module_cls, device):
# Check if native torch.device works as well.
Expand Down

0 comments on commit 17c7675

Please sign in to comment.