docstr: This component enables performing distributed multi-node multi-device training.
  
  Example::
  
      import torch
  
      from lightning.app import LightningWork, CloudCompute
      from lightning.components import MultiNode
  
      class AnyDistributedComponent(LightningWork):
          def run(
              self,
              main_address: str,
              main_port: int,
              node_rank: int,
          ):
              print(f"ADD YOUR DISTRIBUTED CODE: {main_address} {main_port} {node_rank}")
  
  
      compute = CloudCompute("gpu")
      app = LightningApp(
          MultiNode(
              AnyDistributedComponent,
              num_nodes=8,
              cloud_compute=compute,
          )
      )
  
  Arguments:
      work_cls: The work to be executed
      num_nodes: Number of nodes. Gets ignored when running locally. Launch the app with --cloud to run on
          multiple cloud machines.
      cloud_compute: The cloud compute object used in the cloud. The value provided here gets ignored when
          running locally.
      work_args: Arguments to be provided to the work on instantiation.
      work_kwargs: Keywords arguments to be provided to the work on instantiation.
docstr_tok: ["This","component","enables","performing","distributed","multi-node","multi-device","training",".","Example",":",":","import","torch","from","lightning.app","import","LightningWork",",","CloudCompute","from","lightning.components","import","MultiNode","class","AnyDistributedComponent","(","LightningWork",")",":","def","run","(","self",",","main_address",":","str",",","main_port",":","int",",","node_rank",":","int",",",")",":","print","(","f","''","ADD","YOUR","DISTRIBUTED","CODE",":","{","main_address","}","{","main_port","}","{","node_rank","}","''",")","compute","=","CloudCompute","(","``","gpu","''",")","app","=","LightningApp","(","MultiNode","(","AnyDistributedComponent",",","num_nodes=8",",","cloud_compute=compute",",",")",")","Arguments",":","work_cls",":","The","work","to","be","executed","num_nodes",":","Number","of","nodes",".","Gets","ignored","when","running","locally",".","Launch","the","app","with","--","cloud","to","run","on","multiple","cloud","machines",".","cloud_compute",":","The","cloud","compute","object","used","in","the","cloud",".","The","value","provided","here","gets","ignored","when","running","locally",".","work_args",":","Arguments","to","be","provided","to","the","work","on","instantiation",".","work_kwargs",":","Keywords","arguments","to","be","provided","to","the","work","on","instantiation","."]
code: def __init__(
      self,
      work_cls: Type["LightningWork"],
      num_nodes: int,
      cloud_compute: "CloudCompute",
      *work_args: Any,
      **work_kwargs: Any,
  ) -> None:
      """This component enables performing distributed multi-node multi-device training.
  
      Example::
  
          import torch
  
          from lightning.app import LightningWork, CloudCompute
          from lightning.components import MultiNode
  
          class AnyDistributedComponent(LightningWork):
              def run(
                  self,
                  main_address: str,
                  main_port: int,
                  node_rank: int,
              ):
                  print(f"ADD YOUR DISTRIBUTED CODE: {main_address} {main_port} {node_rank}")
  
  
          compute = CloudCompute("gpu")
          app = LightningApp(
              MultiNode(
                  AnyDistributedComponent,
                  num_nodes=8,
                  cloud_compute=compute,
              )
          )
  
      Arguments:
          work_cls: The work to be executed
          num_nodes: Number of nodes. Gets ignored when running locally. Launch the app with --cloud to run on
              multiple cloud machines.
          cloud_compute: The cloud compute object used in the cloud. The value provided here gets ignored when
              running locally.
          work_args: Arguments to be provided to the work on instantiation.
          work_kwargs: Keywords arguments to be provided to the work on instantiation.
  
      """
      super().__init__()
      if num_nodes > 1 and not is_running_in_cloud():
          warnings.warn(
              f"You set {type(self).__name__}(num_nodes={num_nodes}, ...)` but this app is running locally."
              " We assume you are debugging and will ignore the `num_nodes` argument."
              " To run on multiple nodes in the cloud, launch your app with `--cloud`."
          )
          num_nodes = 1
      self.ws = _List(
          *[
              work_cls(
                  *work_args,
                  cloud_compute=cloud_compute.clone(),
                  **work_kwargs,
                  parallel=True,
              )
              for _ in range(num_nodes)
          ]
      )
  
file_path: pytorch-lightning/src/lightning/app/components/multi_node/base.py
imports: import warnings
  from typing import Any, Type
  from lightning.app.core.flow import LightningFlow
  from lightning.app.core.work import LightningWork
  from lightning.app.structures import List
  from lightning.app.utilities.cloud import is_running_in_cloud
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute
label_desc: Use image node_id 1 to create a new MultiNode object from inherited base classes: LightningFlow with example: obj = MultiNode(work_cls, num_nodes, cloud_compute)