Skip to content

Nets now can be loaded even if device=None#876

Merged
BenjaminBossan merged 2 commits intomasterfrom
bugfix/loading-net-when-device-is-none
Jul 28, 2022
Merged

Nets now can be loaded even if device=None#876
BenjaminBossan merged 2 commits intomasterfrom
bugfix/loading-net-when-device-is-none

Conversation

@BenjaminBossan
Copy link
Copy Markdown
Collaborator

@BenjaminBossan BenjaminBossan commented Jul 28, 2022

Description

In #600, we introduced the option to set device=None, which means that
skorch should not move any data to any device. However, this setting
introduced a bug when trying to load the net, as that code didn't
explicitly deal with device=None. With this PR, the bug is fixed.

Implementation

If device=None, we really have no way of knowing what device to map the
parameters to. The most reasonable thing to do is to use the fallback,
which is 'cpu'.

In #600, we introduced the option to set device=None, which means that
skorch should not move any data to any device. However, this setting
introduced a bug when trying to load the net, as that code didn't
explicitly deal with device=None. With this PR, the bug is fixed.

Implementation

If device=None, we really have no way of knowing what device to map the
parameters to. The most reasonable thing to do is to use the fallback,
which is 'cpu'.
Was in "Changed" but should be in "Fixed"
Copy link
Copy Markdown
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with this PR.

Side note: with this fix, models that are pickled with AccelerateMixin and trained on GPU, will fall back to CPU when unpickled. I think that is okay behavior, but not obvious.

@BenjaminBossan
Copy link
Copy Markdown
Collaborator Author

Side note: with this fix, models that are pickled with AccelerateMixin and trained on GPU, will fall back to CPU when unpickled. I think that is okay behavior, but not obvious.

@thomasjpfan Yes, absolutely, that's how I discovered the error. I did think about adding a special case for models with an accelerator attribute, and I might yet do that. But since the error can occur independently, I thought I'd keep this PR small and work on the other stuff later.

@BenjaminBossan BenjaminBossan merged commit ef23ce4 into master Jul 28, 2022
@BenjaminBossan BenjaminBossan deleted the bugfix/loading-net-when-device-is-none branch July 28, 2022 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants