docstr: This component enables performing distributed multi-node multi-device training.
  
  Example::
  
      from lightning.app import LightningApp
      from lightning.app.components.training import LightningTrainerScript
      from lightning.app.utilities.packaging.cloud_compute import CloudCompute
  
      app = LightningApp(
          LightningTrainerScript(
              "train.py",
              num_nodes=2,
              cloud_compute=CloudCompute("gpu"),
          ),
      )
  
  Arguments:
      script_path: Path to the script to be executed.
      script_args: The arguments to be pass to the script.
      num_nodes: Number of nodes.
      cloud_compute: The cloud compute object used in the cloud.
      sanity_serving: Whether to validate that the model correctly implements
          the ServableModule API
docstr_tok: ["This","component","enables","performing","distributed","multi-node","multi-device","training",".","Example",":",":","from","lightning.app","import","LightningApp","from","lightning.app.components.training","import","LightningTrainerScript","from","lightning.app.utilities.packaging.cloud_compute","import","CloudCompute","app","=","LightningApp","(","LightningTrainerScript","(","``","train.py","''",",","num_nodes=2",",","cloud_compute=CloudCompute","(","``","gpu","''",")",",",")",",",")","Arguments",":","script_path",":","Path","to","the","script","to","be","executed",".","script_args",":","The","arguments","to","be","pass","to","the","script",".","num_nodes",":","Number","of","nodes",".","cloud_compute",":","The","cloud","compute","object","used","in","the","cloud",".","sanity_serving",":","Whether","to","validate","that","the","model","correctly","implements","the","ServableModule","API"]
code: def __init__(
      self,
      script_path: str,
      script_args: Optional[Union[list, str]] = None,
      num_nodes: int = 1,
      cloud_compute: CloudCompute = CloudCompute("default"),
      sanity_serving: bool = False,
      script_runner: Type[
          TracerPythonScript
      ] = PyTorchLightningScriptRunner,
      **script_runner_kwargs,
  ):
      """This component enables performing distributed multi-node multi-device training.
  
      Example::
  
          from lightning.app import LightningApp
          from lightning.app.components.training import LightningTrainerScript
          from lightning.app.utilities.packaging.cloud_compute import CloudCompute
  
          app = LightningApp(
              LightningTrainerScript(
                  "train.py",
                  num_nodes=2,
                  cloud_compute=CloudCompute("gpu"),
              ),
          )
  
      Arguments:
          script_path: Path to the script to be executed.
          script_args: The arguments to be pass to the script.
          num_nodes: Number of nodes.
          cloud_compute: The cloud compute object used in the cloud.
          sanity_serving: Whether to validate that the model correctly implements
              the ServableModule API
  
      """
      super().__init__()
      self.script_path = script_path
      self.script_args = script_args
      self.num_nodes = num_nodes
      self.sanity_serving = sanity_serving
      self._script_runner = script_runner
      self._script_runner_kwargs = script_runner_kwargs
  
      self.ws = _List()
      for node_rank in range(self.num_nodes):
          self.ws.append(
              self._script_runner(
                  script_path=self.script_path,
                  script_args=self.script_args,
                  cloud_compute=cloud_compute,
                  node_rank=node_rank,
                  sanity_serving=self.sanity_serving,
                  num_nodes=self.num_nodes,
                  **self._script_runner_kwargs,
              )
          )
  
imports: import os
  from typing import Any, Dict, List, Optional, Tuple, Type, Union
  from lightning.app.components.python import TracerPythonScript
  from lightning.app.core.flow import LightningFlow
  from lightning.app.storage.path import Path
  from lightning.app.structures import List
  from lightning.app.utilities.app_helpers import Logger
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute
label_desc: Use image node_id 1 to create a new LightningTrainerScript object from inherited base classes: LightningFlow with example: obj = LightningTrainerScript(script_path, script_args, num_nodes, cloud_compute, sanity_serving, script_runner)