-
Notifications
You must be signed in to change notification settings - Fork 814
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
Fix/ptl fixes #806
Merged
Merged
Fix/ptl fixes #806
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
effdf7c
fixed lr schedulers and added tests
dennisbader 85d9b99
added check for invalid model creation params
dennisbader 8e88d37
additional lr scheduler fix
dennisbader 31db666
added deprecated to docs
dennisbader a6ce1d2
move torch import in tests for flavors
dennisbader 55d3993
fix wrong parameter docs
dennisbader 9aede12
updated torch device docs
dennisbader 96a2305
Merge branch 'master' into fix/ptl_fixes
hrzn File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,8 +161,15 @@ def __init__( | |
Number of epochs to wait before evaluating the validation loss (if a validation | ||
``TimeSeries`` is passed to the :func:`fit()` method). | ||
torch_device_str | ||
Optionally, a string indicating the torch device to use. (default: "cuda:0" if a GPU | ||
Optionally, a string indicating the torch device to use. (default: ``None``. Set "cuda:0" if a GPU | ||
is available, otherwise "cpu") | ||
|
||
.. deprecated:: v0.17.0 | ||
``torch_device_str`` has been deprecated in v0.17.0 and will be removed in a future version. | ||
Instead, specify this with keys ``"accelerator", "gpus", "auto_select_gpus"`` in your | ||
``pl_trainer_kwargs`` dict. For more info, see here: | ||
https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#trainer-flags , and | ||
https://pytorch-lightning.readthedocs.io/en/stable/advanced/multi_gpu.html#select-gpu-devices | ||
force_reset | ||
If set to ``True``, any previously-existing model with the same name will be reset (all checkpoints will | ||
be discarded). | ||
|
@@ -336,7 +343,9 @@ def __init__( | |
self.pl_module_params: Optional[Dict] = None | ||
|
||
@staticmethod | ||
def _extract_torch_devices(torch_device_str) -> Tuple[str, Optional[list], bool]: | ||
def _extract_torch_devices( | ||
torch_device_str, | ||
) -> Tuple[str, Optional[Union[list, int]], bool]: | ||
"""This method handles the deprecated `torch_device_str` and should be removed in a future Darts version. | ||
|
||
Returns | ||
|
@@ -372,13 +381,13 @@ def _extract_torch_devices(torch_device_str) -> Tuple[str, Optional[list], bool] | |
|
||
gpus = None | ||
auto_select_gpus = False | ||
accelerator = device_split[0] | ||
if len(device_split) == 2 and accelerator == "cuda": | ||
accelerator = "gpu" if device_split[0] == "cuda" else device_split[0] | ||
|
||
if len(device_split) == 2 and accelerator == "gpu": | ||
gpus = device_split[1] | ||
gpus = [int(gpus)] | ||
elif len(device_split) == 1: | ||
if accelerator == "cuda": | ||
accelerator = "gpu" | ||
if accelerator == "gpu": | ||
gpus = -1 | ||
auto_select_gpus = True | ||
else: | ||
|
@@ -389,9 +398,29 @@ def _extract_torch_devices(torch_device_str) -> Tuple[str, Optional[list], bool] | |
) | ||
return accelerator, gpus, auto_select_gpus | ||
|
||
@staticmethod | ||
def _extract_torch_model_params(**kwargs): | ||
@classmethod | ||
def _validate_model_kwargs(cls, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
"""validate that kwargs used at model creation are part of :class:`TorchForecastingModel`, | ||
:class:`PLForecastingModule` or cls __init__ methods. | ||
""" | ||
valid_kwargs = ( | ||
set(inspect.signature(TorchForecastingModel.__init__).parameters.keys()) | ||
| set(inspect.signature(PLForecastingModule.__init__).parameters.keys()) | ||
| set(inspect.signature(cls.__init__).parameters.keys()) | ||
) | ||
|
||
invalid_kwargs = [kwarg for kwarg in kwargs if kwarg not in valid_kwargs] | ||
|
||
raise_if( | ||
len(invalid_kwargs) > 0, | ||
f"Invalid model creation parameters. Model `{cls.__name__}` has no args/kwargs `{invalid_kwargs}`", | ||
logger=logger, | ||
) | ||
|
||
@classmethod | ||
def _extract_torch_model_params(cls, **kwargs): | ||
"""extract params from model creation to set up TorchForecastingModels""" | ||
cls._validate_model_kwargs(**kwargs) | ||
get_params = list( | ||
inspect.signature(TorchForecastingModel.__init__).parameters.keys() | ||
) | ||
|
@@ -619,6 +648,13 @@ def fit( | |
override Darts' default trainer. | ||
verbose | ||
Optionally, whether to print progress. | ||
|
||
.. deprecated:: v0.17.0 | ||
``verbose`` has been deprecated in v0.17.0 and will be removed in a future version. | ||
Instead, control verbosity with PyTorch Lightning Trainer parameters ``enable_progress_bar``, | ||
``progress_bar_refresh_rate`` and ``enable_model_summary`` in the ``pl_trainer_kwargs`` dict | ||
at model creation. See for example here: | ||
https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#enable-progress-bar | ||
epochs | ||
If specified, will train the model for ``epochs`` (additional) epochs, irrespective of what ``n_epochs`` | ||
was provided to the model constructor. | ||
|
@@ -764,6 +800,13 @@ def fit_from_dataset( | |
override Darts' default trainer. | ||
verbose | ||
Optionally, whether to print progress. | ||
|
||
.. deprecated:: v0.17.0 | ||
``verbose`` has been deprecated in v0.17.0 and will be removed in a future version. | ||
Instead, control verbosity with PyTorch Lightning Trainer parameters ``enable_progress_bar``, | ||
``progress_bar_refresh_rate`` and ``enable_model_summary`` in the ``pl_trainer_kwargs`` dict | ||
at model creation. See for example here: | ||
https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#enable-progress-bar | ||
epochs | ||
If specified, will train the model for ``epochs`` (additional) epochs, irrespective of what ``n_epochs`` | ||
was provided to the model constructor. | ||
|
@@ -965,6 +1008,13 @@ def predict( | |
Size of batches during prediction. Defaults to the models' training ``batch_size`` value. | ||
verbose | ||
Optionally, whether to print progress. | ||
|
||
.. deprecated:: v0.17.0 | ||
``verbose`` has been deprecated in v0.17.0 and will be removed in a future version. | ||
Instead, control verbosity with PyTorch Lightning Trainer parameters ``enable_progress_bar``, | ||
``progress_bar_refresh_rate`` and ``enable_model_summary`` in the ``pl_trainer_kwargs`` dict | ||
at model creation. See for example here: | ||
https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#enable-progress-bar | ||
n_jobs | ||
The number of jobs to run in parallel. ``-1`` means using all processors. Defaults to ``1``. | ||
roll_size | ||
|
@@ -1084,7 +1134,14 @@ def predict_from_dataset( | |
batch_size | ||
Size of batches during prediction. Defaults to the models ``batch_size`` value. | ||
verbose | ||
Shows the progress bar for batch predicition. Off by default. | ||
Optionally, whether to print progress. | ||
|
||
.. deprecated:: v0.17.0 | ||
``verbose`` has been deprecated in v0.17.0 and will be removed in a future version. | ||
Instead, control verbosity with PyTorch Lightning Trainer parameters ``enable_progress_bar``, | ||
``progress_bar_refresh_rate`` and ``enable_model_summary`` in the ``pl_trainer_kwargs`` dict | ||
at model creation. See for example here: | ||
https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html#enable-progress-bar | ||
n_jobs | ||
The number of jobs to run in parallel. ``-1`` means using all processors. Defaults to ``1``. | ||
roll_size | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe write down which device will be used by default?
Also, you could maybe add a small example here. e.g. "use:
gpus=-1
to use all available GPUs" or something along those lines. Or maybe using "auto"?