Shortcuts

batch_to_device

torchtune.utils.batch_to_device(batch: dict, device: device) None[source]

该函数接受一个张量(或嵌套张量)的字典,并将它们全部设置为相同的设备。此工具旨在用于将数据批次移动到设备上,更新是就地进行的。

Parameters:
  • batch (dict) – 张量的字典或更嵌套的张量字典。

  • device (torch.device) – 用于移动张量的torch设备

Raises:

AttributeError – 如果批次字典包含除张量以外的任何内容