MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / offload_states

Method offload_states

deepspeed/runtime/engine.py:6126–6154  ·  view source on GitHub ↗

Offload the engine's states to the specified device. Arguments: include: Optional. The set of states to offload. If not provided, all states are offloaded. device: Optional. The device to move the ZeRO optimizer buffers to. Currently only `OffloadDeviceEnum.cpu` is s

(self,
                       include: Container[OffloadStateTypeEnum] = None,
                       device: OffloadDeviceEnum = OffloadDeviceEnum.cpu,
                       pin_memory: bool = True,
                       non_blocking: bool = False)

Source from the content-addressed store, hash-verified

6124 return include
6125
6126 def offload_states(self,
6127 include: Container[OffloadStateTypeEnum] = None,
6128 device: OffloadDeviceEnum = OffloadDeviceEnum.cpu,
6129 pin_memory: bool = True,
6130 non_blocking: bool = False) -> None:
6131 """Offload the engine's states to the specified device.
6132
6133 Arguments:
6134 include: Optional. The set of states to offload. If not provided, all states are offloaded.
6135 device: Optional. The device to move the ZeRO optimizer buffers to. Currently only `OffloadDeviceEnum.cpu` is supported.
6136 pin_memory: Optional. Whether to pin the memory of the offloaded states.
6137 non_blocking: Optional. Whether to offload the states asynchronously.
6138 """
6139 include = self._refine_include_states(include)
6140 param_offload_config = self.zero_offload_param()
6141 assert param_offload_config is None or param_offload_config.device == OffloadDeviceEnum.none, "Moving states across devices is not supported for offloaded parameters."
6142
6143 assert not isinstance(
6144 self.optimizer,
6145 DeepSpeedZeRoOffload), "Moving states across devices is not supported without an optimizer."
6146
6147 if device == OffloadDeviceEnum.none:
6148 logger.warning("No device specified for offloading states.")
6149 return
6150
6151 if device == OffloadDeviceEnum.nvme:
6152 raise ValueError("NVMe offload is not supported for offloading states.")
6153
6154 self.optimizer.offload_states(include=include, device=device, pin_memory=pin_memory, non_blocking=non_blocking)
6155
6156 def reload_states(self, non_blocking: bool = False) -> None:
6157 """Reload the engine states to the original device.

Calls 3

zero_offload_paramMethod · 0.95
warningMethod · 0.80