Learn Before
Concept
Explicit Cross-Device Tensor Transfer
To perform mathematical operations on tensors that reside on different hardware devices, one of the tensors must be explicitly copied to the device where the other tensor is stored. Deep learning frameworks provide specific programmatic methods to transfer tensor data across devices: Z = X.cuda(1) in PyTorch, Z = X.copyto(try_gpu(1)) in MXNet, Z = jax.device_put(X, try_gpu(1)) in JAX, and assigning the tensor within a with device scope such as with try_gpu(1): Z = X in TensorFlow. For example, if tensor is on a CPU and tensor is on a specific GPU, must be moved to that exact GPU before they can be added together.
0
1
Updated 2026-05-09
Tags
D2L
Dive into Deep Learning @ D2L