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

Method offload_states

deepspeed/runtime/engine.py:6229–6257  ·  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

6227 return include
6228
6229 def offload_states(self,
6230 include: Container[OffloadStateTypeEnum] = None,
6231 device: OffloadDeviceEnum = OffloadDeviceEnum.cpu,
6232 pin_memory: bool = True,
6233 non_blocking: bool = False) -> None:
6234 """Offload the engine's states to the specified device.
6235
6236 Arguments:
6237 include: Optional. The set of states to offload. If not provided, all states are offloaded.
6238 device: Optional. The device to move the ZeRO optimizer buffers to. Currently only `OffloadDeviceEnum.cpu` is supported.
6239 pin_memory: Optional. Whether to pin the memory of the offloaded states.
6240 non_blocking: Optional. Whether to offload the states asynchronously.
6241 """
6242 include = self._refine_include_states(include)
6243 param_offload_config = self.zero_offload_param()
6244 assert param_offload_config is None or param_offload_config.device == OffloadDeviceEnum.none, "Moving states across devices is not supported for offloaded parameters."
6245
6246 assert not isinstance(
6247 self.optimizer,
6248 DeepSpeedZeRoOffload), "Moving states across devices is not supported without an optimizer."
6249
6250 if device == OffloadDeviceEnum.none:
6251 logger.warning("No device specified for offloading states.")
6252 return
6253
6254 if device == OffloadDeviceEnum.nvme:
6255 raise ValueError("NVMe offload is not supported for offloading states.")
6256
6257 self.optimizer.offload_states(include=include, device=device, pin_memory=pin_memory, non_blocking=non_blocking)
6258
6259 def reload_states(self, non_blocking: bool = False) -> None:
6260 """Reload the engine states to the original device.

Calls 3

zero_offload_paramMethod · 0.95
warningMethod · 0.80