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

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

Merged
merged 2 commits into from
Jul 28, 2022

Conversation

BenjaminBossan
Copy link
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
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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants