- class ray.train.predictor.Predictor(preprocessor: Optional[ray.data.preprocessor.Preprocessor] = None)[source]#
Predictors load models from checkpoints to perform inference.
Predictorclass cannot be instantiated directly. Only one of its subclasses can be used.
How does a Predictor work?
Predictors expose a
predictmethod that accepts an input batch of type
DataBatchTypeand outputs predictions of the same type as the input batch.
predictmethod is called the following occurs:
The input batch is converted into a pandas DataFrame. Tensor input (like a
np.ndarray) will be converted into a single column Pandas Dataframe.
If there is a Preprocessor saved in the provided Checkpoint, the preprocessor will be used to transform the DataFrame.
The transformed DataFrame will be passed to the model for inference (via the
The predictions will be outputted by
predictin the same type as the original input.
How do I create a new Predictor?
To implement a new Predictor for your particular framework, you should subclass the base
Predictorand implement the following two methods:
_predict_pandas: Given a pandas.DataFrame input, return a pandas.DataFrame containing predictions.
from_checkpoint: Logic for creating a Predictor from an AIR Checkpoint.
_predict_numpyfor better performance when working with tensor data to avoid extra copies from Pandas conversions.
PublicAPI (beta): This API is in beta and may change before becoming stable.
Subclasseses must call Predictor.__init__() to set a preprocessor.
Create a specific predictor from a checkpoint.
Create a Predictor from a Pandas UDF.
Get the preprocessor to use prior to executing predictions.
Perform inference on a batch of data.
Batch format hint for upstream producers to try yielding best block format.
Set the preprocessor to use prior to executing predictions.