The Wayback Machine - https://web.archive.org/web/20201212014223/https://github.com/skorch-dev/skorch/issues/576
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

device='auto' should select the fastest possible device #576

Open
ottonemo opened this issue Dec 16, 2019 · 6 comments
Open

device='auto' should select the fastest possible device #576

ottonemo opened this issue Dec 16, 2019 · 6 comments

Comments

@ottonemo
Copy link
Member

@ottonemo ottonemo commented Dec 16, 2019

I see the code

device = ‘cuda’ if torch.cuda.is_available() else ‘cpu’

repeated often in user code. Maybe we should introduce device='auto' exactly for this case?

@BenjaminBossan
Copy link
Collaborator

@BenjaminBossan BenjaminBossan commented Dec 16, 2019

I think this is from the offical pytorch documentation, maybe it's okay to leave it as is?

@BenAjayiObe
Copy link
Contributor

@BenAjayiObe BenAjayiObe commented Jan 17, 2020

Hi @ottonemo & @BenjaminBossan , I would be quite interested in creating a PR for this issue if this is something that you decide you want to have.

@BenjaminBossan
Copy link
Collaborator

@BenjaminBossan BenjaminBossan commented Jan 18, 2020

I don't see the feature as strictly necessary but would be okay with it being added. @ottonemo @thomasjpfan any opinions on that?

If this change is made, I would suggest to keep the default as is. Also, @BenAjayiObe, please have a look at this function we introduced:

skorch/skorch/utils.py

Lines 128 to 136 in 09be626

def to_device(X, device):
"""Generic function to move module output(s) to a device.
Deals with X being a torch tensor or a tuple of torch tensors.
"""
if isinstance(X, tuple):
return tuple(x.to(device) for x in X)
return X.to(device)

The functionality should be added there. However, this function is not used consistently in our codebase each time we cast, this would need to be fixed.

What I did wonder: Should we also allow the option to set device to None (or 'none'?) so as to prevent any kind of casting?

@BenAjayiObe
Copy link
Contributor

@BenAjayiObe BenAjayiObe commented Jan 20, 2020

Thanks for the info @BenjaminBossan , that's very helpful. 👍

What would be the use case for preventing casting?

@BenjaminBossan
Copy link
Collaborator

@BenjaminBossan BenjaminBossan commented Jan 20, 2020

What would be the use case for preventing casting?

I can imagine that some people would like to have complete control over it, say run part of the model on cpu and part of it on gpu. If we force the casting, this could be annoying to them.

@ottonemo
Copy link
Member Author

@ottonemo ottonemo commented Jan 21, 2020

What I did wonder: Should we also allow the option to set device to None (or 'none'?) so as to prevent any kind of casting?

Definitely a good idea.

@ottonemo @thomasjpfan any opinions on that?

Well I made the suggestion, so I'm in favor (although this is strictly a small convenience feature). Leaving the default as is sounds good to me. As long as the feature doesn't blow up complexity too much it is fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.