Skip to content

Commit baf0580

Browse files
Preparation for release 0.11.0 (#807)
We are happy to announce the new skorch 0.11 release: Two basic but very useful features have been added to our collection of callbacks. First, by setting `load_best=True` on the [`Checkpoint` callback](https://skorch.readthedocs.io/en/latest/callbacks.html#skorch.callbacks.Checkpoint), the snapshot of the network with the best score will be loaded automatically when training ends. Second, we added a callback [`InputShapeSetter`](https://skorch.readthedocs.io/en/latest/callbacks.html#skorch.callbacks.InputShapeSetter) that automatically adjusts your input layer to have the size of your input data (useful e.g. when that size is not known beforehand). When it comes to integrations, the [`MlflowLogger`](https://skorch.readthedocs.io/en/latest/callbacks.html#skorch.callbacks.MlflowLogger) now allows to automatically log to [MLflow](https://mlflow.org/). Thanks to a contributor, some regressions in `net.history` have been fixed and it even runs faster now. On top of that, skorch now offers a new module, `skorch.probabilistic`. It contains new classes to work with **Gaussian Processes** using the familiar skorch API. This is made possible by the fantastic [GPyTorch](https://github.com/cornellius-gp/gpytorch) library, which skorch uses for this. So if you want to get started with Gaussian Processes in skorch, check out the [documentation](https://skorch.readthedocs.io/en/latest/user/probabilistic.html) and this [notebook](https://nbviewer.org/github/skorch-dev/skorch/blob/master/notebooks/Gaussian_Processes.ipynb). Since we're still learning, it's possible that we will change the API in the future, so please be aware of that. Morever, we introduced some changes to make skorch more customizable. First of all, we changed the signature of some methods so that they no longer assume the dataset to always return exactly 2 values. This way, it's easier to work with custom datasets that return e.g. 3 values. Normal users should not notice any difference, but if you often create custom nets, take a look at the [migration guide](https://skorch.readthedocs.io/en/latest/user/FAQ.html#migration-from-0-10-to-0-11). And finally, we made a change to how custom modules, criteria, and optimizers are handled. They are now "first class citizens" in skorch land, which means: If you add a second module to your custom net, it is treated exactly the same as the normal module. E.g., skorch takes care of moving it to CUDA if needed and of switching it to train or eval mode. This way, customizing your networks architectures with skorch is easier than ever. Check the [docs](https://skorch.readthedocs.io/en/latest/user/customization.html#initialization-and-custom-modules) for more details. Since these are some big changes, it's possible that you encounter issues. If that's the case, please check our [issue](https://github.com/skorch-dev/skorch/issues) page or create a new one. As always, this release was made possible by outside contributors. Many thanks to: - Autumnii - Cebtenzzre - Charles Cabergs - Immanuel Bayer - Jake Gardner - Matthias Pfenninger - Prabhat Kumar Sahu Find below the list of all changes: Added - Added `load_best` attribute to `Checkpoint` callback to automatically load state of the best result at the end of training - Added a `get_all_learnable_params` method to retrieve the named parameters of all PyTorch modules defined on the net, including of criteria if applicable - Added `MlflowLogger` callback for logging to Mlflow (#769) - Added `InputShapeSetter` callback for automatically setting the input dimension of the PyTorch module - Added a new module to support Gaussian Processes through [GPyTorch](https://gpytorch.ai/). To learn more about it, read the [GP documentation](https://skorch.readthedocs.io/en/latest/user/probabilistic.html) or take a look at the [GP notebook](https://nbviewer.jupyter.org/github/skorch-dev/skorch/blob/master/notebooks/Gaussian_Processes.ipynb). This feature is experimental, i.e. the API could be changed in the future in a backwards incompatible way (#782) Changed - Changed the signature of `validation_step`, `train_step_single`, `train_step`, `evaluation_step`, `on_batch_begin`, and `on_batch_end` such that instead of receiving `X` and `y`, they receive the whole batch; this makes it easier to deal with datasets that don't strictly return an `(X, y)` tuple, which is true for quite a few PyTorch datasets; please refer to the [migration guide](https://skorch.readthedocs.io/en/latest/user/FAQ.html#migration-from-0-10-to-0-11) if you encounter problems (#699) - Checking of arguments to `NeuralNet` is now during `.initialize()`, not during `__init__`, to avoid raising false positives for yet unknown module or optimizer attributes - Modules, criteria, and optimizers that are added to a net by the user are now first class: skorch takes care of setting train/eval mode, moving to the indicated device, and updating all learnable parameters during training (check the [docs](https://skorch.readthedocs.io/en/latest/user/customization.html#initialization-and-custom-modules) for more details, #751) - `CVSplit` is renamed to `ValidSplit` to avoid confusion (#752) Fixed - Fixed a few bugs in the `net.history` implementation (#776) - Fixed a bug in `TrainEndCheckpoint` that prevented it from being unpickled (#773)
1 parent c625ccf commit baf0580

File tree

8 files changed

+96
-96
lines changed

8 files changed

+96
-96
lines changed

CHANGES.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
### Changed
13+
14+
### Fixed
15+
16+
## [0.11.0] - 2021-10-11
17+
18+
### Added
19+
1220
- Added `load_best` attribute to `Checkpoint` callback to automatically load state of the best result at the end of training
1321
- Added a `get_all_learnable_params` method to retrieve the named parameters of all PyTorch modules defined on the net, including of criteria if applicable
1422
- Added `MlflowLogger` callback for logging to Mlflow (#769)
1523
- Added `InputShapeSetter` callback for automatically setting the input dimension of the PyTorch module
16-
- Added a new module to support Gaussian Processes through [GPyTorch](https://gpytorch.ai/). To learn more about it, read the [GP documentation](https://skorch.readthedocs.io/en/latest/user/probabilistic.html) or take a look at the [GP notebook](https://nbviewer.jupyter.org/github/skorch-dev/skorch/blob/master/notebooks/Gaussian_Processes.ipynb). This feature is experimental, i.e. the API could be changed in the future in a backwards incompatible way.
24+
- Added a new module to support Gaussian Processes through [GPyTorch](https://gpytorch.ai/). To learn more about it, read the [GP documentation](https://skorch.readthedocs.io/en/latest/user/probabilistic.html) or take a look at the [GP notebook](https://nbviewer.jupyter.org/github/skorch-dev/skorch/blob/master/notebooks/Gaussian_Processes.ipynb). This feature is experimental, i.e. the API could be changed in the future in a backwards incompatible way (#782)
1725

1826
### Changed
1927

20-
- Changed the signature of `validation_step`, `train_step_single`, `train_step`, `evaluation_step`, `on_batch_begin`, and `on_batch_end` such that instead of receiving `X` and `y`, they receive the whole batch; this makes it easier to deal with datasets that don't strictly return an `(X, y)` tuple, which is true for quite a few PyTorch datasets; please refer to the [migration guide](https://skorch.readthedocs.io/en/latest/user/FAQ.html#migration-from-0-9-to-0-10) if you encounter problems
28+
- Changed the signature of `validation_step`, `train_step_single`, `train_step`, `evaluation_step`, `on_batch_begin`, and `on_batch_end` such that instead of receiving `X` and `y`, they receive the whole batch; this makes it easier to deal with datasets that don't strictly return an `(X, y)` tuple, which is true for quite a few PyTorch datasets; please refer to the [migration guide](https://skorch.readthedocs.io/en/latest/user/FAQ.html#migration-from-0-10-to-0-11) if you encounter problems (#699)
2129
- Checking of arguments to `NeuralNet` is now during `.initialize()`, not during `__init__`, to avoid raising false positives for yet unknown module or optimizer attributes
22-
- Modules, criteria, and optimizers that are added to a net by the user are now first class: skorch takes care of setting train/eval mode, moving to the indicated device, and updating all learnable parameters during training (check the [docs](https://skorch.readthedocs.io/en/latest/user/customization.html#initialization-and-custom-modules) for more details)
30+
- Modules, criteria, and optimizers that are added to a net by the user are now first class: skorch takes care of setting train/eval mode, moving to the indicated device, and updating all learnable parameters during training (check the [docs](https://skorch.readthedocs.io/en/latest/user/customization.html#initialization-and-custom-modules) for more details, #751)
2331
- `CVSplit` is renamed to `ValidSplit` to avoid confusion (#752)
2432

2533
### Fixed
@@ -253,3 +261,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
253261
[0.8.0]: https://github.com/skorch-dev/skorch/compare/v0.7.0...v0.8.0
254262
[0.9.0]: https://github.com/skorch-dev/skorch/compare/v0.8.0...v0.9.0
255263
[0.10.0]: https://github.com/skorch-dev/skorch/compare/v0.9.0...v0.10.0
264+
[0.11.0]: https://github.com/skorch-dev/skorch/compare/v0.10.0...v0.11.0

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.1dev
1+
0.11.0

docs/user/FAQ.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ the **greatest** score.
408408
Migration guide
409409
---------------
410410

411-
Migration from 0.9 to 0.10
412-
^^^^^^^^^^^^^^^^^^^^^^^^^^
411+
Migration from 0.10 to 0.11
412+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
413413

414-
With skorch 0.10, we pushed the tuple unpacking of values returned by
414+
With skorch 0.11, we pushed the tuple unpacking of values returned by
415415
the iterator to methods lower down the call chain. This way, it is
416416
much easier to work with iterators that don't return exactly two
417417
values, as per the convention.

skorch/callbacks/training.py

+1
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ class InputShapeSetter(Callback):
775775
methods.
776776
777777
Basic usage:
778+
778779
>>> class MyModule(torch.nn.Module):
779780
... def __init__(self, input_dim=1):
780781
... super().__init__()

skorch/dataset.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,10 @@ def __init__(
252252
"but ValidSplit got {}".format(cv))
253253

254254
if not self._is_float(cv) and random_state is not None:
255-
# TODO: raise a ValueError instead of a warning
256-
warnings.warn(
255+
raise ValueError(
257256
"Setting a random_state has no effect since cv is not a float. "
258-
"This will raise an error in a future. You should leave "
259-
"random_state to its default (None), or set cv to a float value.",
260-
FutureWarning
257+
"You should leave random_state to its default (None), or set cv "
258+
"to a float value.",
261259
)
262260

263261
self.cv = cv

skorch/tests/callbacks/test_all.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def test_set_params_with_unknown_key_raises(self, base_cls):
4747
with pytest.raises(ValueError) as exc:
4848
base_cls().set_params(foo=123)
4949

50-
# TODO: check error message more precisely, depending on what
51-
# the intended message shouldb e from sklearn side
52-
assert exc.value.args[0].startswith('Invalid parameter foo for')
50+
msg_start = (
51+
"Invalid parameter foo for estimator <skorch.callbacks.base.Callback")
52+
msg_end = (
53+
"Check the list of available parameters with "
54+
"`estimator.get_params().keys()`.")
55+
msg = exc.value.args[0]
56+
assert msg.startswith(msg_start)
57+
assert msg.endswith(msg_end)

skorch/tests/callbacks/test_scoring.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class MySkorchDataset(skorch.dataset.Dataset):
401401
pass
402402

403403
rawsplit = lambda ds: (ds, ds)
404-
validsplit = ValidSplit(2, random_state=0)
404+
valid_split = ValidSplit(2)
405405

406406
def split_ignore_y(ds, y):
407407
return rawsplit(ds)
@@ -416,12 +416,12 @@ def split_ignore_y(ds, y):
416416
((MySkorchDataset(*data), None), rawsplit, MySkorchDataset, True),
417417

418418
# Test a split that splits datasets using torch Subset
419-
(data, validsplit, np.ndarray, False),
420-
(data, validsplit, Subset, True),
421-
((MyTorchDataset(*data), None), validsplit, Subset, False),
422-
((MyTorchDataset(*data), None), validsplit, Subset, True),
423-
((MySkorchDataset(*data), None), validsplit, np.ndarray, False),
424-
((MySkorchDataset(*data), None), validsplit, Subset, True),
419+
(data, valid_split, np.ndarray, False),
420+
(data, valid_split, Subset, True),
421+
((MyTorchDataset(*data), None), valid_split, Subset, False),
422+
((MyTorchDataset(*data), None), valid_split, Subset, True),
423+
((MySkorchDataset(*data), None), valid_split, np.ndarray, False),
424+
((MySkorchDataset(*data), None), valid_split, Subset, True),
425425
]
426426

427427
for input_data, train_split, expected_type, caching in table:

0 commit comments

Comments
 (0)