python - pytorch when do I need to use `.to(device)` on a model or tensor? - Stack Overflow
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
related reading
- python - Understanding `torch.nn.Parameter()` - Stack Overflowstackoverflow.com
- python - How to convert a PyTorch sparse_coo_tensor into a PyTorch dense tensor? - Stack Overflowstackoverflow.com
- Making Deep Learning go Brrrr From First Principleshorace.io
- PyTorch in One Hour: From Tensors to Training Neural Networks on Multiple GPUssebastianraschka.com
- PyTorch internals : ezyang's blogblog.ezyang.com
- python - How to do gradient clipping in pytorch? - Stack Overflowstackoverflow.com
- Tensors — PyTorch Tutorials 2.12.0+cu130 documentationpytorch.org
- How to check which cuda version my pytorch is using - PyTorch Forumsdiscuss.pytorch.org
- Tensors — PyTorch Tutorials 2.13.0+cu130 documentationdocs.pytorch.org
- Learning PyTorch with Examples — PyTorch Tutorials 2.12.0+cu130 documentationpytorch.org
- Taking PyTorch for Granted | whnrehiew.github.io
- The Best GPUs for Deep Learning in 2023 — An In-depth Analysistimdettmers.com