class_docstr: A DDP Strategy which uses ray as backend.
class_docstr_tok: ["A","DDP","Strategy","which","uses","ray","as","backend","."]
docstr: Create a RayStrategy.
docstr_tok: ["Create","a","RayStrategy","."]
code: def __init__(
      self,
      num_processes: int = 1,
      cpu_for_each_process: Optional[List[List[int]]] = None,
      num_cpus_per_worker: int = 1,
      use_gpu: bool = False,
      use_ipex: bool = False,
      dtype=None,
      init_hook: Callable = None,
      auto_lr: Union[bool, dict] = True,
      **ddp_kwargs: Any,
  ):
      """Create a RayStrategy."""
      # Unset MKL setting as bigdl.nano would give default values when init env.
      # Running different programs may need different configurations.
      # refer to https://analytics-zoo-doc.readthedocs.io/en/master/zoo.ray.html#
      # zoo.ray.raycontext.RayServiceFuncGenerator
      # Also KMP_AFFINITY may entangle something doing with ray._raylet.CoreWorker,
      # which is invoked by ray.init and leads to stocking.
      os.environ.pop("KMP_AFFINITY", None)
      os.environ.pop("OMP_NUM_THREADS", None)
  
      if not ray.is_initialized():  # type: ignore
          print(ray.init())  # type: ignore
  
      super().__init__(
          parallel_devices=[],
          cluster_environment=RayEnvironment(world_size=num_processes),
          **ddp_kwargs,
      )
  
      self.num_workers = num_processes
      self.num_cpus_per_worker = num_cpus_per_worker
      self.use_gpu = use_gpu
      self.use_ipex = use_ipex
      self.dtype = dtype
      self.auto_lr = auto_lr
  
      invalidInputError(
          not self.use_gpu or not self.use_ipex,
          "You can not specify gpu and ipex at the same time.",
      )
  
      self.workers = self._create_worker()
      self.init_hook = init_hook
      self._local_rank = 0
  
      if self.init_hook:
          ray.get(
              [w.execute.remote(self.init_hook) for w in self.workers]
          )
  
imports: import os
  import warnings
  from typing import Callable, Dict, List, Union, Any, Optional
  from collections import defaultdict
  import ray
  from ray.util.ml_utils.util import find_free_port
  import torch
  from torch.optim.lr_scheduler import _LRScheduler
  from torch.nn.parallel.distributed import DistributedDataParallel
  import pytorch_lightning
  from pytorch_lightning.core.datamodule import LightningDataModule
  from pytorch_lightning.trainer.states import TrainerFn
  from pytorch_lightning.utilities import rank_zero_only
  from pytorch_lightning.utilities.apply_func import move_data_to_device
  from pytorch_lightning.strategies.launchers import _SpawnLauncher
  from pytorch_lightning.strategies import DDPSpawnStrategy
  from pytorch_lightning.core.optimizer import _configure_schedulers_automatic_opt
  from pytorch_lightning.core.optimizer import _configure_schedulers_manual_opt
  from pytorch_lightning.core.optimizer import _set_scheduler_opt_idx, _validate_scheduler_api
  from pytorch_lightning.core.optimizer import LightningOptimizer
  from .ray_envbase import RayEnvironment
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.nano.utils.pytorch import TORCH_VERSION_LESS_1_12
  from bigdl.nano.deps.ipex.ipex_api import ipex_optimize
  from bigdl.nano.pytorch.dispatcher import _get_patch_status
label_desc: Use image node_id 1 to create a new RayStrategy object from inherited base classes: DDPSpawnStrategy with example: obj = RayStrategy(num_processes, cpu_for_each_process, num_cpus_per_worker, use_gpu, use_ipex, dtype, init_hook, auto_lr)