class_docstr: Experimental API implementing a multi-GPU Random Forest classifier
  model which fits multiple decision tree classifiers in an
  ensemble. This uses Dask to partition data over multiple GPUs
  (possibly on different nodes).
  
  Currently, this API makes the following assumptions:
   * The set of Dask workers used between instantiation, fit,         and predict are all consistent
   * Training data comes in the form of cuDF dataframes or Dask Arrays         distributed so that each worker has at least one partition.
   * The get_summary_text and get_detailed_text functions provides the         text representation of the forest on the worker.
  
  Future versions of the API will support more flexible data
  distribution and additional input types.
  
  The distributed algorithm uses an *embarrassingly-parallel*
  approach. For a forest with `N` trees being built on `w` workers, each
  worker simply builds `N/w` trees on the data it has available
  locally. In many cases, partitioning the data so that each worker
  builds trees on a subset of the total dataset works well, but
  it generally requires the data to be well-shuffled in advance.
  Alternatively, callers can replicate all of the data across
  workers so that ``rf.fit`` receives `w` partitions, each containing the
  same data. This would produce results approximately identical to
  single-GPU fitting.
  
  Please check the single-GPU implementation of Random Forest
  classifier for more information about the underlying algorithm.
  
  Parameters
  ----------
  n_estimators : int (default = 100)
                 total number of trees in the forest (not per-worker)
  handle : cuml.Handle
      Specifies the cuml.handle that holds internal CUDA state for
      computations in this model. Most importantly, this specifies the CUDA
      stream that will be used for the model's computations, so users can
      run different models concurrently in different streams by creating
      handles in several streams.
      If it is None, a new one is created.
  split_criterion : int or string (default = ``0`` (``'gini'``))
      The criterion used to split nodes.
  
       * ``0`` or ``'gini'`` for gini impurity
       * ``1`` or ``'entropy'`` for information gain (entropy)
       * ``2`` or ``'mse'`` for mean squared error
       * ``4`` or ``'poisson'`` for poisson half deviance
       * ``5`` or ``'gamma'`` for gamma half deviance
       * ``6`` or ``'inverse_gaussian'`` for inverse gaussian deviance
  
      ``2``, ``'mse'``, ``4``, ``'poisson'``, ``5``, ``'gamma'``, ``6``,
      ``'inverse_gaussian'`` not valid for classification
  bootstrap : boolean (default = True)
      Control bootstrapping.
  
       * If ``True``, each tree in the forest is built on a bootstrapped
         sample with replacement.
       * If ``False``, the whole dataset is used to build each tree.
  max_samples : float (default = 1.0)
      Ratio of dataset rows used while fitting each tree.
  max_depth : int (default = 16)
      Maximum tree depth. Must be greater than 0.
      Unlimited depth (i.e, until leaves are pure)
      is not supported.
  
      .. note:: This default differs from scikit-learn's
        random forest, which defaults to unlimited depth.
  max_leaves : int (default = -1)
      Maximum leaf nodes per tree. Soft constraint. Unlimited, If ``-1``.
  max_features : float (default = 'auto')
      Ratio of number of features (columns) to consider
      per node split.
  
       * If type ``int`` then ``max_features`` is the absolute count of
         features to be used.
       * If type ``float`` then ``max_features`` is a fraction.
       * If ``'auto'`` then ``max_features=n_features = 1.0``.
       * If ``'sqrt'`` then ``max_features=1/sqrt(n_features)``.
       * If ``'log2'`` then ``max_features=log2(n_features)/n_features``.
       * If ``None``, then ``max_features = 1.0``.
  
  n_bins : int (default = 128)
      Maximum number of bins used by the split algorithm per feature.
  min_samples_leaf : int or float (default = 1)
      The minimum number of samples (rows) in each leaf node.
  
       * If type ``int``, then ``min_samples_leaf`` represents the minimum
         number.
       * If ``float``, then ``min_samples_leaf`` represents a fraction
         and ``ceil(min_samples_leaf * n_rows)`` is the minimum number of
         samples for each leaf node.
  
  min_samples_split : int or float (default = 2)
      The minimum number of samples required to split an internal
      node.
  
       * If type ``int``, then ``min_samples_split`` represents the minimum
         number.
       * If type ``float``, then ``min_samples_split`` represents a fraction
         and ``ceil(min_samples_split * n_rows)`` is the minimum number of
         samples for each split.
  
  n_streams : int (default = 4 )
      Number of parallel streams used for forest building
  workers : optional, list of strings
      Dask addresses of workers to use for computation.
      If None, all available Dask workers will be used.
  random_state : int (default = None)
      Seed for the random number generator. Unseeded by default.
  
  ignore_empty_partitions: Boolean (default = False)
      Specify behavior when a worker does not hold any data
      while splitting. When True, it returns the results from workers
      with data (the number of trained estimators will be less than
      n_estimators) When False, throws a RuntimeError.
      This is an experimental parameter, and may be removed
      in the future.
  
  Examples
  --------
  For usage examples, please see the RAPIDS notebooks repository:
  https://github.com/rapidsai/cuml/blob/main/notebooks/random_forest_mnmg_demo.ipynb
class_docstr_tok: ["Experimental","API","implementing","a","multi-GPU","Random","Forest","classifier","model","which","fits","multiple","decision","tree","classifiers","in","an","ensemble",".","This","uses","Dask","to","partition","data","over","multiple","GPUs","(","possibly","on","different","nodes",")",".","Currently",",","this","API","makes","the","following","assumptions",":","*","The","set","of","Dask","workers","used","between","instantiation",",","fit",",","and","predict","are","all","consistent","*","Training","data","comes","in","the","form","of","cuDF","dataframes","or","Dask","Arrays","distributed","so","that","each","worker","has","at","least","one","partition",".","*","The","get_summary_text","and","get_detailed_text","functions","provides","the","text","representation","of","the","forest","on","the","worker",".","Future","versions","of","the","API","will","support","more","flexible","data","distribution","and","additional","input","types",".","The","distributed","algorithm","uses","an","*","embarrassingly-parallel","*","approach",".","For","a","forest","with","`","N","`","trees","being","built","on","`","w","`","workers",",","each","worker","simply","builds","`","N\/w","`","trees","on","the","data","it","has","available","locally",".","In","many","cases",",","partitioning","the","data","so","that","each","worker","builds","trees","on","a","subset","of","the","total","dataset","works","well",",","but","it","generally","requires","the","data","to","be","well-shuffled","in","advance",".","Alternatively",",","callers","can","replicate","all","of","the","data","across","workers","so","that","``","rf.fit","``","receives","`","w","`","partitions",",","each","containing","the","same","data",".","This","would","produce","results","approximately","identical","to","single-GPU","fitting",".","Please","check","the","single-GPU","implementation","of","Random","Forest","classifier","for","more","information","about","the","underlying","algorithm",".","Parameters","--","--","--","--","--","n_estimators",":","int","(","default","=","100",")","total","number","of","trees","in","the","forest","(","not","per-worker",")","handle",":","cuml.Handle","Specifies","the","cuml.handle","that","holds","internal","CUDA","state","for","computations","in","this","model",".","Most","importantly",",","this","specifies","the","CUDA","stream","that","will","be","used","for","the","model","'s","computations",",","so","users","can","run","different","models","concurrently","in","different","streams","by","creating","handles","in","several","streams",".","If","it","is","None",",","a","new","one","is","created",".","split_criterion",":","int","or","string","(","default","=","``","0","``","(","``","'gini","'","``",")",")","The","criterion","used","to","split","nodes",".","*","``","0","``","or","``","'gini","'","``","for","gini","impurity","*","``","1","``","or","``","'entropy","'","``","for","information","gain","(","entropy",")","*","``","2","``","or","``","'mse","'","``","for","mean","squared","error","*","``","4","``","or","``","'poisson","'","``","for","poisson","half","deviance","*","``","5","``","or","``","'gamma","'","``","for","gamma","half","deviance","*","``","6","``","or","``","'inverse_gaussian","'","``","for","inverse","gaussian","deviance","``","2","``",",","``","'mse","'","``",",","``","4","``",",","``","'poisson","'","``",",","``","5","``",",","``","'gamma","'","``",",","``","6","``",",","``","'inverse_gaussian","'","``","not","valid","for","classification","bootstrap",":","boolean","(","default","=","True",")","Control","bootstrapping",".","*","If","``","True","``",",","each","tree","in","the","forest","is","built","on","a","bootstrapped","sample","with","replacement",".","*","If","``","False","``",",","the","whole","dataset","is","used","to","build","each","tree",".","max_samples",":","float","(","default","=","1.0",")","Ratio","of","dataset","rows","used","while","fitting","each","tree",".","max_depth",":","int","(","default","=","16",")","Maximum","tree","depth",".","Must","be","greater","than","0",".","Unlimited","depth","(","i.e",",","until","leaves","are","pure",")","is","not","supported",".","..","note",":",":","This","default","differs","from","scikit-learn's","random","forest",",","which","defaults","to","unlimited","depth",".","max_leaves",":","int","(","default","=","-1",")","Maximum","leaf","nodes","per","tree",".","Soft","constraint",".","Unlimited",",","If","``","-1","``",".","max_features",":","float","(","default","=","'auto","'",")","Ratio","of","number","of","features","(","columns",")","to","consider","per","node","split",".","*","If","type","``","int","``","then","``","max_features","``","is","the","absolute","count","of","features","to","be","used",".","*","If","type","``","float","``","then","``","max_features","``","is","a","fraction",".","*","If","``","'auto","'","``","then","``","max_features=n_features","=","1.0","``",".","*","If","``","'sqrt","'","``","then","``","max_features=1\/sqrt","(","n_features",")","``",".","*","If","``","'log2","'","``","then","``","max_features=log2","(","n_features",")","\/n_features","``",".","*","If","``","None","``",",","then","``","max_features","=","1.0","``",".","n_bins",":","int","(","default","=","128",")","Maximum","number","of","bins","used","by","the","split","algorithm","per","feature",".","min_samples_leaf",":","int","or","float","(","default","=","1",")","The","minimum","number","of","samples","(","rows",")","in","each","leaf","node",".","*","If","type","``","int","``",",","then","``","min_samples_leaf","``","represents","the","minimum","number",".","*","If","``","float","``",",","then","``","min_samples_leaf","``","represents","a","fraction","and","``","ceil","(","min_samples_leaf","*","n_rows",")","``","is","the","minimum","number","of","samples","for","each","leaf","node",".","min_samples_split",":","int","or","float","(","default","=","2",")","The","minimum","number","of","samples","required","to","split","an","internal","node",".","*","If","type","``","int","``",",","then","``","min_samples_split","``","represents","the","minimum","number",".","*","If","type","``","float","``",",","then","``","min_samples_split","``","represents","a","fraction","and","``","ceil","(","min_samples_split","*","n_rows",")","``","is","the","minimum","number","of","samples","for","each","split",".","n_streams",":","int","(","default","=","4",")","Number","of","parallel","streams","used","for","forest","building","workers",":","optional",",","list","of","strings","Dask","addresses","of","workers","to","use","for","computation",".","If","None",",","all","available","Dask","workers","will","be","used",".","random_state",":","int","(","default","=","None",")","Seed","for","the","random","number","generator",".","Unseeded","by","default",".","ignore_empty_partitions",":","Boolean","(","default","=","False",")","Specify","behavior","when","a","worker","does","not","hold","any","data","while","splitting",".","When","True",",","it","returns","the","results","from","workers","with","data","(","the","number","of","trained","estimators","will","be","less","than","n_estimators",")","When","False",",","throws","a","RuntimeError",".","This","is","an","experimental","parameter",",","and","may","be","removed","in","the","future",".","Examples","--","--","--","--","For","usage","examples",",","please","see","the","RAPIDS","notebooks","repository",":","https",":","\/\/github.com\/rapidsai\/cuml\/blob\/main\/notebooks\/random_forest_mnmg_demo.ipynb"]
docstr: Predicts the labels for X.
  
  GPU-based prediction in a multi-node, multi-GPU context works
  by sending the sub-forest from each worker to the client,
  concatenating these into one forest with the full
  `n_estimators` set of trees, and sending this combined forest to
  the workers, which will each infer on their local set of data.
  Within the worker, this uses the cuML Forest Inference Library
  (cuml.fil) for high-throughput prediction.
  
  This allows inference to scale to large datasets, but the forest
  transmission incurs overheads for very large trees. For inference
  on small datasets, this overhead may dominate prediction time.
  
  The 'CPU' fallback method works with sub-forests in-place,
  broadcasting the datasets to all workers and combining predictions
  via a voting method at the end. This method is slower
  on a per-row basis but may be faster for problems with many trees
  and few rows.
  
  In the 0.15 cuML release, inference will be updated with much
  faster tree transfer. Preliminary builds with this updated approach
  will be available from rapids.ai
  
  Parameters
  ----------
  X : Dask cuDF dataframe  or CuPy backed Dask Array (n_rows, n_features)
      Distributed dense matrix (floats or doubles) of shape
      (n_samples, n_features).
  algo : string (default = 'auto')
      This is optional and required only while performing the
      predict operation on the GPU.
  
       * ``'naive'`` - simple inference using shared memory
       * ``'tree_reorg'`` - similar to naive but trees rearranged to be
         more coalescing-friendly
       * ``'batch_tree_reorg'`` - similar to tree_reorg but predicting
         multiple rows per thread block
       * ``'auto'`` - choose the algorithm automatically. (Default)
       * ``'batch_tree_reorg'`` is used for dense storage
         and 'naive' for sparse storage
  
  threshold : float (default = 0.5)
      Threshold used for classification. Optional and required only
      while performing the predict operation on the GPU, that is for,
      predict_model='GPU'.
  convert_dtype : bool, optional (default = True)
      When set to True, the predict method will, when necessary, convert
      the input to the data type which was used to train the model. This
      will increase memory used for the method.
  predict_model : String (default = 'GPU')
      'GPU' to predict using the GPU, 'CPU' otherwise. The GPU can only
      be used if the model was trained on float32 data and `X` is float32
      or convert_dtype is set to True.
  fil_sparse_format : boolean or string (default = auto)
      This variable is used to choose the type of forest that will be
      created in the Forest Inference Library. It is not required
      while using predict_model='CPU'.
  
       * ``'auto'`` - choose the storage type automatically
         (currently True is chosen by auto)
       * ``False`` - create a dense forest
       * ``True`` - create a sparse forest, requires algo='naive'
         or algo='auto'
  
  delayed : bool (default = True)
      Whether to do a lazy prediction (and return Delayed objects) or an
      eagerly executed one.  It is not required  while using
      predict_model='CPU'.
  broadcast_data : bool (default = False)
      If broadcast_data=False, the trees are merged in a single model
      before the workers perform inference on their share of the
      prediction workload. When broadcast_data=True, trees aren't merged.
      Instead each of the workers infer the whole prediction work
      from trees at disposal. The results are reduced on the client.
      May be advantageous when the model is larger than the data used
      for inference.
  
  Returns
  -------
  y : Dask cuDF dataframe or CuPy backed Dask Array (n_rows, 1)
docstr_tok: ["Predicts","the","labels","for","X.","GPU-based","prediction","in","a","multi-node",",","multi-GPU","context","works","by","sending","the","sub-forest","from","each","worker","to","the","client",",","concatenating","these","into","one","forest","with","the","full","`","n_estimators","`","set","of","trees",",","and","sending","this","combined","forest","to","the","workers",",","which","will","each","infer","on","their","local","set","of","data",".","Within","the","worker",",","this","uses","the","cuML","Forest","Inference","Library","(","cuml.fil",")","for","high-throughput","prediction",".","This","allows","inference","to","scale","to","large","datasets",",","but","the","forest","transmission","incurs","overheads","for","very","large","trees",".","For","inference","on","small","datasets",",","this","overhead","may","dominate","prediction","time",".","The","'CPU","'","fallback","method","works","with","sub-forests","in-place",",","broadcasting","the","datasets","to","all","workers","and","combining","predictions","via","a","voting","method","at","the","end",".","This","method","is","slower","on","a","per-row","basis","but","may","be","faster","for","problems","with","many","trees","and","few","rows",".","In","the","0.15","cuML","release",",","inference","will","be","updated","with","much","faster","tree","transfer",".","Preliminary","builds","with","this","updated","approach","will","be","available","from","rapids.ai","Parameters","--","--","--","--","--","X",":","Dask","cuDF","dataframe","or","CuPy","backed","Dask","Array","(","n_rows",",","n_features",")","Distributed","dense","matrix","(","floats","or","doubles",")","of","shape","(","n_samples",",","n_features",")",".","algo",":","string","(","default","=","'auto","'",")","This","is","optional","and","required","only","while","performing","the","predict","operation","on","the","GPU",".","*","``","'naive","'","``","-","simple","inference","using","shared","memory","*","``","'tree_reorg","'","``","-","similar","to","naive","but","trees","rearranged","to","be","more","coalescing-friendly","*","``","'batch_tree_reorg","'","``","-","similar","to","tree_reorg","but","predicting","multiple","rows","per","thread","block","*","``","'auto","'","``","-","choose","the","algorithm","automatically",".","(","Default",")","*","``","'batch_tree_reorg","'","``","is","used","for","dense","storage","and","'naive","'","for","sparse","storage","threshold",":","float","(","default","=","0.5",")","Threshold","used","for","classification",".","Optional","and","required","only","while","performing","the","predict","operation","on","the","GPU",",","that","is","for",",","predict_model='GPU","'",".","convert_dtype",":","bool",",","optional","(","default","=","True",")","When","set","to","True",",","the","predict","method","will",",","when","necessary",",","convert","the","input","to","the","data","type","which","was","used","to","train","the","model",".","This","will","increase","memory","used","for","the","method",".","predict_model",":","String","(","default","=","'GPU","'",")","'GPU","'","to","predict","using","the","GPU",",","'CPU","'","otherwise",".","The","GPU","can","only","be","used","if","the","model","was","trained","on","float32","data","and","`","X","`","is","float32","or","convert_dtype","is","set","to","True",".","fil_sparse_format",":","boolean","or","string","(","default","=","auto",")","This","variable","is","used","to","choose","the","type","of","forest","that","will","be","created","in","the","Forest","Inference","Library",".","It","is","not","required","while","using","predict_model='CPU","'",".","*","``","'auto","'","``","-","choose","the","storage","type","automatically","(","currently","True","is","chosen","by","auto",")","*","``","False","``","-","create","a","dense","forest","*","``","True","``","-","create","a","sparse","forest",",","requires","algo='naive'","or","algo='auto'","delayed",":","bool","(","default","=","True",")","Whether","to","do","a","lazy","prediction","(","and","return","Delayed","objects",")","or","an","eagerly","executed","one",".","It","is","not","required","while","using","predict_model='CPU","'",".","broadcast_data",":","bool","(","default","=","False",")","If","broadcast_data=False",",","the","trees","are","merged","in","a","single","model","before","the","workers","perform","inference","on","their","share","of","the","prediction","workload",".","When","broadcast_data=True",",","trees","are","n't","merged",".","Instead","each","of","the","workers","infer","the","whole","prediction","work","from","trees","at","disposal",".","The","results","are","reduced","on","the","client",".","May","be","advantageous","when","the","model","is","larger","than","the","data","used","for","inference",".","Returns","--","--","--","-","y",":","Dask","cuDF","dataframe","or","CuPy","backed","Dask","Array","(","n_rows",",","1",")"]
code: def predict(
      self,
      X,
      algo="auto",
      threshold=0.5,
      convert_dtype=True,
      predict_model="GPU",
      fil_sparse_format="auto",
      delayed=True,
      broadcast_data=False,
  ):
      """
      Predicts the labels for X.
  
      GPU-based prediction in a multi-node, multi-GPU context works
      by sending the sub-forest from each worker to the client,
      concatenating these into one forest with the full
      `n_estimators` set of trees, and sending this combined forest to
      the workers, which will each infer on their local set of data.
      Within the worker, this uses the cuML Forest Inference Library
      (cuml.fil) for high-throughput prediction.
  
      This allows inference to scale to large datasets, but the forest
      transmission incurs overheads for very large trees. For inference
      on small datasets, this overhead may dominate prediction time.
  
      The 'CPU' fallback method works with sub-forests in-place,
      broadcasting the datasets to all workers and combining predictions
      via a voting method at the end. This method is slower
      on a per-row basis but may be faster for problems with many trees
      and few rows.
  
      In the 0.15 cuML release, inference will be updated with much
      faster tree transfer. Preliminary builds with this updated approach
      will be available from rapids.ai
  
      Parameters
      ----------
      X : Dask cuDF dataframe  or CuPy backed Dask Array (n_rows, n_features)
          Distributed dense matrix (floats or doubles) of shape
          (n_samples, n_features).
      algo : string (default = 'auto')
          This is optional and required only while performing the
          predict operation on the GPU.
  
           * ``'naive'`` - simple inference using shared memory
           * ``'tree_reorg'`` - similar to naive but trees rearranged to be
             more coalescing-friendly
           * ``'batch_tree_reorg'`` - similar to tree_reorg but predicting
             multiple rows per thread block
           * ``'auto'`` - choose the algorithm automatically. (Default)
           * ``'batch_tree_reorg'`` is used for dense storage
             and 'naive' for sparse storage
  
      threshold : float (default = 0.5)
          Threshold used for classification. Optional and required only
          while performing the predict operation on the GPU, that is for,
          predict_model='GPU'.
      convert_dtype : bool, optional (default = True)
          When set to True, the predict method will, when necessary, convert
          the input to the data type which was used to train the model. This
          will increase memory used for the method.
      predict_model : String (default = 'GPU')
          'GPU' to predict using the GPU, 'CPU' otherwise. The GPU can only
          be used if the model was trained on float32 data and `X` is float32
          or convert_dtype is set to True.
      fil_sparse_format : boolean or string (default = auto)
          This variable is used to choose the type of forest that will be
          created in the Forest Inference Library. It is not required
          while using predict_model='CPU'.
  
           * ``'auto'`` - choose the storage type automatically
             (currently True is chosen by auto)
           * ``False`` - create a dense forest
           * ``True`` - create a sparse forest, requires algo='naive'
             or algo='auto'
  
      delayed : bool (default = True)
          Whether to do a lazy prediction (and return Delayed objects) or an
          eagerly executed one.  It is not required  while using
          predict_model='CPU'.
      broadcast_data : bool (default = False)
          If broadcast_data=False, the trees are merged in a single model
          before the workers perform inference on their share of the
          prediction workload. When broadcast_data=True, trees aren't merged.
          Instead each of the workers infer the whole prediction work
          from trees at disposal. The results are reduced on the client.
          May be advantageous when the model is larger than the data used
          for inference.
  
      Returns
      -------
      y : Dask cuDF dataframe or CuPy backed Dask Array (n_rows, 1)
      """
      if predict_model == "CPU":
          preds = self.predict_model_on_cpu(
              X=X, convert_dtype=convert_dtype
          )
      else:
          if broadcast_data:
              preds = self.partial_inference(
                  X,
                  algo=algo,
                  convert_dtype=convert_dtype,
                  fil_sparse_format=fil_sparse_format,
                  delayed=delayed,
              )
          else:
              preds = self._predict_using_fil(
                  X,
                  algo=algo,
                  threshold=threshold,
                  convert_dtype=convert_dtype,
                  fil_sparse_format=fil_sparse_format,
                  delayed=delayed,
              )
      return preds
  
imports: import dask
  from dask.distributed import default_client
  from cuml.dask.ensemble.base import BaseRandomForestModel
  from cuml.dask.common.base import DelayedPredictionMixin, DelayedPredictionProbaMixin
  from cuml.dask.common.input_utils import DistributedDataHandler
  from cuml.ensemble import RandomForestClassifier
  from cuml.dask.common.base import BaseEstimator
  from cuml.internals.safe_imports import gpu_only_import
  from cuml.internals.safe_imports import cpu_only_import
label_desc: Use image node_id 8 for calling the RandomForestClassifier obj's underlying member method code with example usage: obj.predict(X, algo, threshold, convert_dtype, predict_model, fil_sparse_format, delayed, broadcast_data) and returns: preds