Skip to content

.to_device()

Move all parameters to the target device in-place.

Transfers every parameter tensor's underlying array to the backend of the given device (e.g. from numpy to cupy when moving to CUDA). Returns self for chaining.

Parameters:

  • device (str) –

    Target device string, e.g. "cpu" or "cuda:0".

Returns:

  • Module

    This module (mutated in-place).

Raises:

  • ValueError

    If the device string is invalid.