Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.15.0 #1014

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-08-31

### 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