class_docstr: The parent class for TorchDistributor. This class shouldn't be instantiated directly.
class_docstr_tok: ["The","parent","class","for","TorchDistributor",".","This","class","should","n't","be","instantiated","directly","."]
docstr: Returns the number of Spark tasks to use for distributed training
  
  Returns
  -------
  int
      The number of Spark tasks to use for distributed training
  
  Raises
  ------
  RuntimeError
      Raised when the SparkConf was misconfigured.
docstr_tok: ["Returns","the","number","of","Spark","tasks","to","use","for","distributed","training","Returns","--","--","--","-","int","The","number","of","Spark","tasks","to","use","for","distributed","training","Raises","--","--","--","RuntimeError","Raised","when","the","SparkConf","was","misconfigured","."]
code: def _get_num_tasks(self) -> int:
      """
      Returns the number of Spark tasks to use for distributed training
  
      Returns
      -------
      int
          The number of Spark tasks to use for distributed training
  
      Raises
      ------
      RuntimeError
          Raised when the SparkConf was misconfigured.
      """
      if self.use_gpu:
          if not self.local_mode:
              key = "spark.task.resource.gpu.amount"
              task_gpu_amount = int(_get_conf(self.spark, key, "0"))
              if task_gpu_amount < 1:
                  raise RuntimeError(
                      f"'{key}' was unset, so gpu usage is unavailable."
                  )
              # TODO(SPARK-41916): Address situation when spark.task.resource.gpu.amount > 1
              return math.ceil(self.num_processes / task_gpu_amount)
          else:
              key = "spark.driver.resource.gpu.amount"
              if "gpu" not in _get_resources(self.spark):
                  raise RuntimeError(
                      "GPUs were unable to be found on the driver."
                  )
              num_available_gpus = int(_get_conf(self.spark, key, "0"))
              if num_available_gpus == 0:
                  raise RuntimeError(
                      "GPU resources were not configured properly on the driver."
                  )
              if self.num_processes > num_available_gpus:
                  self.logger.warning(
                      "'num_processes' cannot be set to a value greater than the number of "
                      f"available GPUs on the driver, which is {num_available_gpus}. "
                      "'num_processes' was reset to be equal to the number of available GPUs.",
                  )
                  self.num_processes = num_available_gpus
      return self.num_processes
  
imports: import json
  from contextlib import contextmanager
  import collections
  import logging
  import math
  import os
  import random
  import re
  import shutil
  import subprocess
  import sys
  import tempfile
  import textwrap
  import time
  from typing import Union, Callable, List, Dict, Optional, Any, Tuple, Generator, Iterator
  from pyspark import cloudpickle
  from pyspark.resource.information import ResourceInformation
  from pyspark.sql import DataFrame, SparkSession
  from pyspark.taskcontext import BarrierTaskContext
  from pyspark.ml.torch.log_communication import LogStreamingClient, LogStreamingServer
  from pyspark.ml.dl_util import FunctionPickler
label_desc: Use image node_id 3 for calling the Distributor obj's underlying member method code with example usage: obj._get_num_tasks() and returns: self, math