class_docstr: A predictor for PyTorch models.
  
  Args:
      model: The torch module to use for predictions.
      preprocessor: A preprocessor used to transform data batches prior
          to prediction.
      use_gpu: If set, the model will be moved to GPU on instantiation and
          prediction happens on GPU.
class_docstr_tok: ["A","predictor","for","PyTorch","models",".","Args",":","model",":","The","torch","module","to","use","for","predictions",".","preprocessor",":","A","preprocessor","used","to","transform","data","batches","prior","to","prediction",".","use_gpu",":","If","set",",","the","model","will","be","moved","to","GPU","on","instantiation","and","prediction","happens","on","GPU","."]
docstr: Instantiate the predictor from a TorchCheckpoint.
  
  Args:
      checkpoint: The checkpoint to load the model and preprocessor from.
      model: If the checkpoint contains a model state dict, and not
          the model itself, then the state dict will be loaded to this
          ``model``. If the checkpoint already contains the model itself,
          this model argument will be discarded.
      use_gpu: If set, the model will be moved to GPU on instantiation and
          prediction happens on GPU.
docstr_tok: ["Instantiate","the","predictor","from","a","TorchCheckpoint",".","Args",":","checkpoint",":","The","checkpoint","to","load","the","model","and","preprocessor","from",".","model",":","If","the","checkpoint","contains","a","model","state","dict",",","and","not","the","model","itself",",","then","the","state","dict","will","be","loaded","to","this","``","model","``",".","If","the","checkpoint","already","contains","the","model","itself",",","this","model","argument","will","be","discarded",".","use_gpu",":","If","set",",","the","model","will","be","moved","to","GPU","on","instantiation","and","prediction","happens","on","GPU","."]
code: def from_checkpoint(
      cls,
      checkpoint: TorchCheckpoint,
      model: Optional[torch.nn.Module] = None,
      use_gpu: bool = False,
  ) -> "TorchPredictor":
      """Instantiate the predictor from a TorchCheckpoint.
  
      Args:
          checkpoint: The checkpoint to load the model and preprocessor from.
          model: If the checkpoint contains a model state dict, and not
              the model itself, then the state dict will be loaded to this
              ``model``. If the checkpoint already contains the model itself,
              this model argument will be discarded.
          use_gpu: If set, the model will be moved to GPU on instantiation and
              prediction happens on GPU.
      """
      model = checkpoint.get_model(model)
      preprocessor = checkpoint.get_preprocessor()
      return cls(
          model=model, preprocessor=preprocessor, use_gpu=use_gpu
      )
  
file_path: ray/python/ray/train/torch/torch_predictor.py
imports: import logging
  from typing import TYPE_CHECKING, Dict, Optional, Union
  import numpy
  import torch
  from ray.air._internal.torch_utils import convert_ndarray_batch_to_torch_tensor_batch
  from ray.train._internal.dl_predictor import DLPredictor
  from ray.train.predictor import DataBatchType
  from ray.train.torch import TorchCheckpoint
  from ray.util import log_once
  from ray.util.annotations import DeveloperAPI, PublicAPI
label_desc: Use image node_id 3 for calling the TorchPredictor obj's underlying member method code with example usage: obj.from_checkpoint(cls, checkpoint, model, use_gpu) and returns: cls