flâneur — a map of the web's best reading

python - pytorch when do I need to use `.to(device)` on a model or tensor? - Stack Overflow

stackoverflow.com · 1,393 words · saved by 1 readers

Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams Find centralized, trusted content and collaborate around the technologies you use most. Teams Q&A for work Connect and share knowledge within a single location that is structured and easy to search. Get early access and see previews of new features. I am new to Pytorch, but it seems pretty nice. My only question was when to use tensor.to(device) or Module.nn.to(device). I was reading the documentation on this topic, and it indicates that this method will move the tensor or model to the specified device. But I was not clear for what operations this is necessary, and what kind of errors I will get if I don't use .to() at the right time? For example, if I just create a tensor, I imagine that the tensor is stored in CPU accessible memory until I move the tensor to the GPU. Once the tensor is on the GPU, then the GPU will execute any mathematical operations on that tensor. However, d

python - pytorch when do I need to use `.to(device)` on a model or tensor? - Stack Overflow The 2026 Annual Developer Survey is live— take the Survey today! Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives Stack Internal Knowledge at work Bring the best of human thought and AI automation together at your work. Explore Stack Internal pytorch when do I need to use `.to(device)` on a model or tensor? Ask Question Asked 6 years ago Modified 2 years, 8 months ago Viewed 107k times 50 I am new t

Explore this link on the map →

related reading