W3cubDocs

/PyTorch 2.9

torch.utils.swap_tensors

torch.utils.swap_tensors(t1, t2) [source]

This function swaps the content of the two Tensor objects. At a high level, this will make t1 have the content of t2 while preserving its identity.

This will not work if t1 and t2 have different slots.

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.utils.swap_tensors.html