class_docstr: Provides capabilities to run training using the DeepSpeed library, with training optimizations for large
      billion parameter models. `For more information: https://pytorch-
      lightning.readthedocs.io/en/stable/advanced/model_parallel.html#deepspeed`.
  
      .. warning:: ``DeepSpeedStrategy`` is in beta and subject to change.
  
      Defaults have been set to enable ZeRO-Offload and some have been taken from the link below.
      These defaults have been set generally, but may require tuning for optimum performance based on your model size.
      `For more information: https://www.deepspeed.ai/docs/config-json/#zero-optimizations-for-fp16-training`.
class_docstr_tok: ["Provides","capabilities","to","run","training","using","the","DeepSpeed","library",",","with","training","optimizations","for","large","billion","parameter","models",".","`","For","more","information",":","https",":","\/\/pytorch-","lightning.readthedocs.io\/en\/stable\/advanced\/model_parallel.html","#","deepspeed","`",".","..","warning",":",":","``","DeepSpeedStrategy","``","is","in","beta","and","subject","to","change",".","Defaults","have","been","set","to","enable","ZeRO-Offload","and","some","have","been","taken","from","the","link","below",".","These","defaults","have","been","set","generally",",","but","may","require","tuning","for","optimum","performance","based","on","your","model","size",".","`","For","more","information",":","https",":","\/\/www.deepspeed.ai\/docs\/config-json\/","#","zero-optimizations-for-fp16-training","`","."]
code: def init_deepspeed(self) -> None:
      assert self.lightning_module is not None
      # deepspeed handles gradient clipping internally
      if is_overridden(
          "configure_gradient_clipping",
          self.lightning_module,
          pl.LightningModule,
      ):
          rank_zero_warn(
              "Since DeepSpeed handles gradient clipping internally, the default"
              " `LightningModule.configure_gradient_clipping` implementation will not actually clip gradients."
              " The hook will still be called. Consider setting"
              " `Trainer(gradient_clip_val=..., gradient_clip_algorithm='norm')`"
              " which will use the internal mechanism."
          )
  
      if (
          self.lightning_module.trainer.gradient_clip_algorithm
          == GradClipAlgorithmType.VALUE
      ):
          raise MisconfigurationException(
              "DeepSpeed does not support clipping gradients by value."
          )
  
      if not isinstance(self.accelerator, CUDAAccelerator):
          raise MisconfigurationException(
              f"DeepSpeed strategy is only supported on GPU but `{self.accelerator.__class__.__name__}` is used."
          )
  
      accumulation_scheduler = (
          self.lightning_module.trainer.accumulation_scheduler
      )
  
      if accumulation_scheduler.epochs != [0]:
          raise MisconfigurationException(
              "DeepSpeed currently does not support different `accumulate_grad_batches` at different epochs."
          )
  
      assert isinstance(
          self.model,
          (pl.LightningModule, _LightningPrecisionModuleWrapperBase),
      )
      model = _LightningModuleWrapperBase(pl_module=self.model)
  
      self._initialize_deepspeed_train(model)
  
file_path: autogluon/multimodal/src/autogluon/multimodal/optimization/deepspeed.py
imports: import logging
  from typing import Any, Dict, Generator, List, Mapping, Optional, Tuple, Union, cast
  import lightning.pytorch
  import torch
  from lightning.pytorch.accelerators.cuda import CUDAAccelerator
  from lightning.pytorch.overrides.base import _LightningModuleWrapperBase, _LightningPrecisionModuleWrapperBase
  from lightning.pytorch.plugins.environments.cluster_environment import ClusterEnvironment
  from lightning.pytorch.plugins.precision import PrecisionPlugin
  from lightning.pytorch.strategies import DeepSpeedStrategy
  from lightning.pytorch.utilities import GradClipAlgorithmType
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.model_helpers import is_overridden
  from lightning.pytorch.utilities.rank_zero import rank_zero_warn
  from lightning.pytorch.utilities.types import _PATH
label_desc: Use image node_id 2 for calling the CustomDeepSpeedStrategy obj's underlying member method code with example usage: obj.init_deepspeed() without return types