class_docstr: A DDP Strategy which uses ray as backend.
class_docstr_tok: ["A","DDP","Strategy","which","uses","ray","as","backend","."]
docstr: Setup the distributed environment of ray executor, we add ipex optimization here.
docstr_tok: ["Setup","the","distributed","environment","of","ray","executor",",","we","add","ipex","optimization","here","."]
code: def setup(self, trainer: "pl.Trainer") -> None:
      """Setup the distributed environment of ray executor, we add ipex optimization here."""
      self.accelerator.setup(trainer)
  
      trainer_fn = trainer.state.fn
      if trainer_fn == TrainerFn.FITTING:
          if self._layer_sync:
              self.model = self._layer_sync.apply(self.model)
  
      self.setup_precision_plugin()
  
      # `configure_ddp` will create a `DistributedDataParallel`, which has no
      # `test_step` method in pytorch_lightning 1.6, which causes error when
      # calling `trainer.test()`, so we call `configure_ddp` only when fitting
      if trainer_fn == TrainerFn.FITTING:
          self.configure_ddp()
      else:
          # `trainer.test()` won't set `model.training` to `False` automatically in pl 1.6,
          # then the following `ipex_optimize()` call will report an error,
          # so we need to set it to `False` manuallay
          self.model.eval()
  
      if trainer.training and self.auto_lr:
  
          def _unpack_lightning_optimizer(opt):
              return (
                  opt._optimizer
                  if isinstance(opt, LightningOptimizer)
                  else opt
              )
  
          optimizers = self.optimizers
          optimizers = [
              _unpack_lightning_optimizer(opt) for opt in optimizers
          ]
  
          for optimizer in optimizers:
              for param_group in optimizer.param_groups:
                  param_group["lr"] *= self.world_size
  
          lr_scheduler_configs = self.lr_scheduler_configs
          for config in lr_scheduler_configs:
              scheduler = config.scheduler
              if isinstance(scheduler, _LRScheduler):
                  scheduler.base_lrs = [  # type: ignore
                      lr * self.world_size for lr in scheduler.base_lrs  # type: ignore
                  ]
      if self.use_ipex:
          ipex_optimize(
              self.model,
              optimizers=optimizer,
              inplace=True,
              dtype=self.dtype,
          )
  
      # some operations in `configure_ddp` do not support XPU,
      # which is used by ipex==1.9, so we move this line here
      self.model_to_device()
  
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 7 for calling the RayStrategy obj's underlying member method code with example usage: obj.setup(trainer) and returns: unknown