docstr: Create an Estimator for torch.
  
  :param model: PyTorch model or model creator function if backend="bigdl", PyTorch
         model creator function if backend="horovod" or "torch_distributed"
  :param optimizer: Orca/PyTorch optimizer or optimizer creator function if backend="bigdl"
         , PyTorch optimizer creator function if backend="horovod" or "torch_distributed"
  :param loss: PyTorch loss or loss creator function if backend="bigdl", PyTorch loss creator
         function if backend="horovod" or "torch_distributed"
  :param metrics: Orca validation methods for evaluate.
  :param scheduler_creator: parameter for `horovod` and `torch_distributed` backends. a
         learning rate scheduler wrapping the optimizer. You will need to set
         ``scheduler_step_freq="epoch"`` for the scheduler to be incremented correctly.
  :param config: parameter config dict to create model, optimizer loss and data.
  :param scheduler_step_freq: parameter for `horovod` and `torch_distributed` backends.
         "batch", "epoch" or None. This will determine when ``scheduler.step`` is called. If
         "batch", ``step`` will be called after every optimizer step. If "epoch", ``step``
         will be called after one pass of the DataLoader. If a scheduler is passed in, this
         value is expected to not be None.
  :param use_tqdm: parameter for `horovod` and `torch_distributed` backends. You can monitor
         training progress if use_tqdm=True.
  :param workers_per_node: parameter for `horovod` and `torch_distributed` backends. worker
         number on each node. default: 1.
  :param model_dir: parameter for `bigdl` backend. The path to save model. During the
         training, if checkpoint_trigger is defined and triggered, the model will be saved to
         model_dir.
  :param backend: You can choose "horovod",  "torch_distributed" or "bigdl" as backend.
         Default: `bigdl`.
  :return: an Estimator object.
docstr_tok: ["Create","an","Estimator","for","torch",".",":","param","model",":","PyTorch","model","or","model","creator","function","if","backend=","''","bigdl","''",",","PyTorch","model","creator","function","if","backend=","''","horovod","''","or","``","torch_distributed","''",":","param","optimizer",":","Orca\/PyTorch","optimizer","or","optimizer","creator","function","if","backend=","''","bigdl","''",",","PyTorch","optimizer","creator","function","if","backend=","''","horovod","''","or","``","torch_distributed","''",":","param","loss",":","PyTorch","loss","or","loss","creator","function","if","backend=","''","bigdl","''",",","PyTorch","loss","creator","function","if","backend=","''","horovod","''","or","``","torch_distributed","''",":","param","metrics",":","Orca","validation","methods","for","evaluate",".",":","param","scheduler_creator",":","parameter","for","`","horovod","`","and","`","torch_distributed","`","backends",".","a","learning","rate","scheduler","wrapping","the","optimizer",".","You","will","need","to","set","``","scheduler_step_freq=","''","epoch","''","``","for","the","scheduler","to","be","incremented","correctly",".",":","param","config",":","parameter","config","dict","to","create","model",",","optimizer","loss","and","data",".",":","param","scheduler_step_freq",":","parameter","for","`","horovod","`","and","`","torch_distributed","`","backends",".","``","batch","''",",","``","epoch","''","or","None",".","This","will","determine","when","``","scheduler.step","``","is","called",".","If","``","batch","''",",","``","step","``","will","be","called","after","every","optimizer","step",".","If","``","epoch","''",",","``","step","``","will","be","called","after","one","pass","of","the","DataLoader",".","If","a","scheduler","is","passed","in",",","this","value","is","expected","to","not","be","None",".",":","param","use_tqdm",":","parameter","for","`","horovod","`","and","`","torch_distributed","`","backends",".","You","can","monitor","training","progress","if","use_tqdm=True",".",":","param","workers_per_node",":","parameter","for","`","horovod","`","and","`","torch_distributed","`","backends",".","worker","number","on","each","node",".","default",":","1.",":","param","model_dir",":","parameter","for","`","bigdl","`","backend",".","The","path","to","save","model",".","During","the","training",",","if","checkpoint_trigger","is","defined","and","triggered",",","the","model","will","be","saved","to","model_dir",".",":","param","backend",":","You","can","choose","``","horovod","''",",","``","torch_distributed","''","or","``","bigdl","''","as","backend",".","Default",":","`","bigdl","`",".",":","return",":","an","Estimator","object","."]
code: def from_torch(
      *,
      model,
      optimizer,
      loss=None,
      metrics=None,
      scheduler_creator=None,
      training_operator_cls=TrainingOperator,
      initialization_hook=None,
      config=None,
      scheduler_step_freq="batch",
      use_tqdm=False,
      workers_per_node=1,
      model_dir=None,
      backend="bigdl",
  ):
      """
      Create an Estimator for torch.
  
      :param model: PyTorch model or model creator function if backend="bigdl", PyTorch
             model creator function if backend="horovod" or "torch_distributed"
      :param optimizer: Orca/PyTorch optimizer or optimizer creator function if backend="bigdl"
             , PyTorch optimizer creator function if backend="horovod" or "torch_distributed"
      :param loss: PyTorch loss or loss creator function if backend="bigdl", PyTorch loss creator
             function if backend="horovod" or "torch_distributed"
      :param metrics: Orca validation methods for evaluate.
      :param scheduler_creator: parameter for `horovod` and `torch_distributed` backends. a
             learning rate scheduler wrapping the optimizer. You will need to set
             ``scheduler_step_freq="epoch"`` for the scheduler to be incremented correctly.
      :param config: parameter config dict to create model, optimizer loss and data.
      :param scheduler_step_freq: parameter for `horovod` and `torch_distributed` backends.
             "batch", "epoch" or None. This will determine when ``scheduler.step`` is called. If
             "batch", ``step`` will be called after every optimizer step. If "epoch", ``step``
             will be called after one pass of the DataLoader. If a scheduler is passed in, this
             value is expected to not be None.
      :param use_tqdm: parameter for `horovod` and `torch_distributed` backends. You can monitor
             training progress if use_tqdm=True.
      :param workers_per_node: parameter for `horovod` and `torch_distributed` backends. worker
             number on each node. default: 1.
      :param model_dir: parameter for `bigdl` backend. The path to save model. During the
             training, if checkpoint_trigger is defined and triggered, the model will be saved to
             model_dir.
      :param backend: You can choose "horovod",  "torch_distributed" or "bigdl" as backend.
             Default: `bigdl`.
      :return: an Estimator object.
      """
      if backend in {"horovod", "torch_distributed"}:
          return PyTorchRayEstimator(
              model_creator=model,
              optimizer_creator=optimizer,
              loss_creator=loss,
              metrics=metrics,
              scheduler_creator=scheduler_creator,
              training_operator_cls=training_operator_cls,
              initialization_hook=initialization_hook,
              config=config,
              scheduler_step_freq=scheduler_step_freq,
              use_tqdm=use_tqdm,
              workers_per_node=workers_per_node,
              backend=backend,
          )
      elif backend == "bigdl":
          return PyTorchSparkEstimator(
              model=model,
              loss=loss,
              optimizer=optimizer,
              config=config,
              metrics=metrics,
              model_dir=model_dir,
              bigdl_type="float",
          )
      else:
          raise ValueError(
              "Only horovod, torch_distributed and bigdl backends are supported"
              f" for now, got backend: {backend}"
          )
  
imports: from zoo.common.utils import enable_multi_fs_load, enable_multi_fs_save
  from zoo.orca.data.utils import row_to_sample, xshard_to_sample
  from zoo.orca.learn.utils import convert_predict_rdd_to_dataframe, bigdl_metric_results_to_dict, process_xshards_of_pandas_dataframe
  from zoo.pipeline.estimator.estimator import Estimator
  from zoo.orca.learn.ray_estimator import Estimator
  from zoo.orca.learn.pytorch.training_operator import TrainingOperator
  from zoo.orca.learn.spark_estimator import Estimator
  from zoo.orca.learn.optimizers import Optimizer, SGD
  from zoo.orca.learn.metrics import Accuracy
  from zoo.orca.data import SparkXShards
  from bigdl.optim.optimizer import MaxEpoch, OptimMethod
  from zoo.feature.common import FeatureSet
  from torch.optim.optimizer import Optimizer
  from torch.utils.data import DataLoader
  from pyspark.sql import DataFrame
  import warnings
  import torch
  import types
label_desc: Use image node_id 1 for calling the Estimator obj's underlying member method code with example usage: obj.from_torch() and returns: PyTorchRayEstimator, PyTorchSparkEstimator