class_docstr: TorchNano for BigDL-Nano pytorch.
  
  It can be used to accelerate custom pytorch training loops with very few code changes.
class_docstr_tok: ["TorchNano","for","BigDL-Nano","pytorch",".","It","can","be","used","to","accelerate","custom","pytorch","training","loops","with","very","few","code","changes","."]
docstr: Create a TorchNano with nano acceleration.
  
  :param num_processes: number of processes in distributed training, defaults to ``1``
  :param use_ipex: whether use ipex acceleration, defaults to ``False``
  :param distributed_backend: use which backend in distributed mode, defaults to
      ``'subprocess'``, now avaiable backends are ``'spawn'``, ``'subprocess'`` and ``'ray'``
  :param process_group_backend: use which process group backend in distributed mode, defaults
      to ``None``, means using ``'gloo'`` with CPU, while using ``'nccl'`` with GPU, now
      avaiable backends are ``None`` and ``'ccl'``.
  :param precision: Double precision (``64``), full precision (``32``),
      half precision (``16``) or bfloat16 precision (``'bf16'``), defaults to ``32``.
      Enable ipex bfloat16 weight prepack when ``use_ipex=True`` and ``precision='bf16'``
  :param cpu_for_each_process: specify the cpu cores which will be used by each process,
      if ``None``, cpu cores will be distributed evenly by all processes,
      only take effect when ``num_processes`` > 1
  :param channels_last: whether convert input to channels last memory formats,
      defaults to ``False``.
  :param auto_lr: whether to scale the learning rate linearly by ``num_processes`` times.
      Defaults to ``True``.
      If ``num_processes=1`` or other ``lr_scheduler`` is set, ``auto_lr`` will be ignored.
code: def __init__(
      self,
      num_processes: Optional[int] = None,
      use_ipex: bool = False,
      distributed_backend: str = "subprocess",
      process_group_backend: Optional[str] = None,
      precision: Union[str, int] = 32,
      cpu_for_each_process: Optional[List[List[int]]] = None,
      channels_last: bool = False,
      auto_lr: bool = True,
      *args,
      **kwargs,
  ) -> None:
      """
      Create a TorchNano with nano acceleration.
  
      :param num_processes: number of processes in distributed training, defaults to ``1``
      :param use_ipex: whether use ipex acceleration, defaults to ``False``
      :param distributed_backend: use which backend in distributed mode, defaults to
          ``'subprocess'``, now avaiable backends are ``'spawn'``, ``'subprocess'`` and ``'ray'``
      :param process_group_backend: use which process group backend in distributed mode, defaults
          to ``None``, means using ``'gloo'`` with CPU, while using ``'nccl'`` with GPU, now
          avaiable backends are ``None`` and ``'ccl'``.
      :param precision: Double precision (``64``), full precision (``32``),
          half precision (``16``) or bfloat16 precision (``'bf16'``), defaults to ``32``.
          Enable ipex bfloat16 weight prepack when ``use_ipex=True`` and ``precision='bf16'``
      :param cpu_for_each_process: specify the cpu cores which will be used by each process,
          if ``None``, cpu cores will be distributed evenly by all processes,
          only take effect when ``num_processes`` > 1
      :param channels_last: whether convert input to channels last memory formats,
          defaults to ``False``.
      :param auto_lr: whether to scale the learning rate linearly by ``num_processes`` times.
          Defaults to ``True``.
          If ``num_processes=1`` or other ``lr_scheduler`` is set, ``auto_lr`` will be ignored.
      """
      self.num_processes = num_processes
      self.use_ipex = use_ipex
      self.dtype = None
      self.cpu_for_each_process = cpu_for_each_process
      self.channels_last = channels_last
      self.auto_lr = auto_lr
  
      if self.use_ipex and precision == "bf16":
          # Enable ipex bfloat16 weight prepack and disable native AMP
          self.dtype = torch.bfloat16
          precision = 32
  
      # Confirm if cpu supports AVX512
      if self.use_ipex and not _avx512_checker():
          if TORCH_VERSION_LESS_1_11:
              warning(
                  "Enable ipex<=1.10 in a cpu instruction set"
                  " without avx512 will crash."
                  "Fall back to regular pytorch."
              )
              self.use_ipex = False
          elif self.dtype == torch.bfloat16:
              warning(
                  "Enable IPEX bfloat16 in a cpu instruction set"
                  " without avx512 will crash. "
                  "Using 32-bit precision"
              )
              self.dtype = None
  
      kwargs["precision"] = precision
  
      if self.num_processes is None and distributed_backend != "k8s":
          self.num_processes = 1
  
      if self.num_processes == 1:
          if self.use_ipex:
              strategy = IPEXStrategy(dtype=self.dtype)
          else:
              strategy = None  # type: ignore
      elif distributed_backend in backends_class_map:
          check_ccl(process_group_backend)
          cls = backends_class_map[distributed_backend]
          strategy = cls(
              num_processes=self.num_processes,  # type: ignore
              cpu_for_each_process=self.cpu_for_each_process,
              use_ipex=self.use_ipex,
              dtype=self.dtype,
              process_group_backend=process_group_backend,
          )
      else:
          warning(
              f"BigDL-Nano doesn't support '{distributed_backend}' backend now, "
              f"'{distributed_backend}' strategy of pytorch_lightning will be used. "
              f"Supported backends are 'spawn', 'subprocess' and 'ray'."
          )
          strategy = distributed_backend  # type: ignore
  
      kwargs["strategy"] = strategy
      super().__init__(*args, **kwargs)
  
      setattr(self, "train", partial(self._run_impl, self.train))
  
imports: from typing import Any, Union, List, Optional, Mapping
  from logging import warning
  from functools import partial, wraps
  from abc import abstractmethod
  import torch
  from torch import nn
  from torch.optim import Optimizer
  from torch.utils.data import DataLoader
  from torch.nn.parallel.distributed import DistributedDataParallel
  from pytorch_lightning.lite import LightningLite
  from pytorch_lightning.lite.wrappers import _LiteModule, _LiteOptimizer
  from pytorch_lightning.utilities.apply_func import apply_to_collection
  from pytorch_lightning.strategies import Strategy
  from pytorch_lightning.strategies import DeepSpeedStrategy
  from bigdl.nano.utils.common import _avx512_checker
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.nano.utils.pytorch import TORCH_VERSION_LESS_1_11, TORCH_VERSION_LESS_1_13, check_ccl
  from bigdl.nano.deps.ipex.ipex_api import ipex_optimize
  from bigdl.nano.pytorch.strategies import IPEXStrategy, DDPSpawnStrategy, DDPSubprocessStrategy, create_ray_strategy, DDPK8sStrategy
label_desc: Use image node_id 1 to create a new TorchNano object from inherited base classes: LightningLite with example: obj = TorchNano(num_processes, use_ipex, distributed_backend, process_group_backend, precision, cpu_for_each_process, channels_last, auto_lr)