Skip to content

Device agnostic code #282

Answered by mrdbourke
ra9hur asked this question in Q&A
Jan 29, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @ra9hur,

Good questions!

  1. Any thoughts on why we have to choose device explicitly in PyTorch ?

This is for maximum customizability of the code.

And the ability to choose which device the computation happens on.

E.g. some computation may be better on GPU, some better on CPU.

  1. Choosing device for the model makes sense since model has to run on a given device.

2a. Why should we choose device for data ?

Model + data have to be on the same device for computation to happen.

If a model is on GPU and data on CPU, an error will occur (the data isn't stored in the same place).

2b. If we choose GPU:1 for data and and gpu:0 for model (separate devices for model and data), it should introd…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ra9hur
Comment options

Answer selected by ra9hur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants