Skip to content

breaking: refactor name of RealTimePredictor to Predictor #1629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/inference/predictors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Predictors

Make real-time predictions against SageMaker endpoints with Python objects

.. autoclass:: sagemaker.predictor.RealTimePredictor
.. autoclass:: sagemaker.predictor.Predictor
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion doc/frameworks/chainer/using_chainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ You can provide your own implementations for these functions in your hosting scr
If you omit any definition then the SageMaker Chainer model server will use its default implementation for that
function.

The ``RealTimePredictor`` used by Chainer in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
The ``Predictor`` used by Chainer in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
by default, with Content-Type ``application/x-npy``. The SageMaker Chainer model server can deserialize NPY-formatted
data (along with JSON and CSV data).

Expand Down
2 changes: 1 addition & 1 deletion doc/frameworks/pytorch/using_pytorch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ You can provide your own implementations for these functions in your hosting scr
If you omit any definition then the SageMaker PyTorch model server will use its default implementation for that
function.

The ``RealTimePredictor`` used by PyTorch in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
The ``Predictor`` used by PyTorch in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
by default, with Content-Type ``application/x-npy``. The SageMaker PyTorch model server can deserialize NPY-formatted
data (along with JSON and CSV data).

Expand Down
2 changes: 1 addition & 1 deletion doc/frameworks/sklearn/using_sklearn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ You can provide your own implementations for these functions in your hosting scr
If you omit any definition then the SageMaker Scikit-learn model server will use its default implementation for that
function.

The ``RealTimePredictor`` used by Scikit-learn in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
The ``Predictor`` used by Scikit-learn in the SageMaker Python SDK serializes NumPy arrays to the `NPY <https://docs.scipy.org/doc/numpy/neps/npy-format.html>`_ format
by default, with Content-Type ``application/x-npy``. The SageMaker Scikit-learn model server can deserialize NPY-formatted
data (along with JSON and CSV data).

Expand Down
6 changes: 3 additions & 3 deletions doc/frameworks/tensorflow/upgrade_from_legacy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ From a model:
Predictors
----------

If you want to use your model for endpoints, then you can use the :class:`sagemaker.predictor.RealTimePredictor` class instead of the legacy ``sagemaker.tensorflow.TensorFlowPredictor`` class:
If you want to use your model for endpoints, then you can use the :class:`sagemaker.predictor.Predictor` class instead of the legacy ``sagemaker.tensorflow.TensorFlowPredictor`` class:

.. code:: python

from sagemaker.model import FrameworkModel
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor

model = FrameworkModel(
...
predictor_cls=RealTimePredictor,
predictor_cls=Predictor,
)

predictor = model.deploy(...)
Expand Down
2 changes: 1 addition & 1 deletion doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ How do I make predictions against an existing endpoint?
Create a ``Predictor`` object and provide it with your endpoint name,
then call its ``predict()`` method with your input.

You can use either the generic ``RealTimePredictor`` class, which by default does not perform any serialization/deserialization transformations on your input,
You can use either the generic ``Predictor`` class, which by default does not perform any serialization/deserialization transformations on your input,
but can be configured to do so through constructor arguments:
http://sagemaker.readthedocs.io/en/stable/predictors.html

Expand Down
2 changes: 1 addition & 1 deletion src/sagemaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

from sagemaker.model import Model, ModelPackage # noqa: F401
from sagemaker.pipeline import PipelineModel # noqa: F401
from sagemaker.predictor import RealTimePredictor # noqa: F401
from sagemaker.predictor import Predictor # noqa: F401
from sagemaker.processing import Processor, ScriptProcessor # noqa: F401
from sagemaker.session import Session # noqa: F401
from sagemaker.session import container_def, pipeline_container_def # noqa: F401
Expand Down
10 changes: 4 additions & 6 deletions src/sagemaker/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sagemaker import vpc_utils
from sagemaker.estimator import EstimatorBase
from sagemaker.transformer import Transformer
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor


class AlgorithmEstimator(EstimatorBase):
Expand Down Expand Up @@ -246,15 +246,15 @@ def create_model(
"""Create a model to deploy.

The serializer, deserializer, content_type, and accept arguments are
only used to define a default RealTimePredictor. They are ignored if an
only used to define a default Predictor. They are ignored if an
explicit predictor class is passed in. Other arguments are passed
through to the Model class.

Args:
role (str): The ``ExecutionRoleArn`` IAM Role ARN for the ``Model``,
which is also used during transform jobs. If not specified, the
role from the Estimator will be used.
predictor_cls (RealTimePredictor): The predictor class to use when
predictor_cls (Predictor): The predictor class to use when
deploying the model.
serializer (callable): Should accept a single argument, the input
data, and return a sequence of bytes. May provide a content_type
Expand Down Expand Up @@ -285,9 +285,7 @@ def create_model(
if predictor_cls is None:

def predict_wrapper(endpoint, session):
return RealTimePredictor(
endpoint, session, serializer, deserializer, content_type, accept
)
return Predictor(endpoint, session, serializer, deserializer, content_type, accept)

predictor_cls = predict_wrapper

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/factorization_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import gt, isin, ge
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -261,13 +261,13 @@ def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):
)


class FactorizationMachinesPredictor(RealTimePredictor):
class FactorizationMachinesPredictor(Predictor):
"""Performs binary-classification or regression prediction from input
vectors.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/ipinsights.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sagemaker.amazon.amazon_estimator import AmazonAlgorithmEstimatorBase, registry
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import ge, le
from sagemaker.predictor import RealTimePredictor, csv_serializer, json_deserializer
from sagemaker.predictor import Predictor, csv_serializer, json_deserializer
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -173,13 +173,13 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
)


class IPInsightsPredictor(RealTimePredictor):
class IPInsightsPredictor(Predictor):
"""Returns dot product of entity and IP address embeddings as a score for
compatibility.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain two columns. The first column should contain the entity ID. The
second column should contain the IPv4 address in dot notation.
"""
Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import gt, isin, ge, le
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -194,12 +194,12 @@ def hyperparameters(self):
return hp_dict


class KMeansPredictor(RealTimePredictor):
class KMeansPredictor(Predictor):
"""Assigns input vectors to their closest cluster in a KMeans model.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import ge, isin
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -182,12 +182,12 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
)


class KNNPredictor(RealTimePredictor):
class KNNPredictor(Predictor):
"""Performs classification or regression prediction from input vectors.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/lda.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import gt
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -166,12 +166,12 @@ def _prepare_for_training( # pylint: disable=signature-differs
)


class LDAPredictor(RealTimePredictor):
class LDAPredictor(Predictor):
"""Transforms input vectors to lower-dimesional representations.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/linear_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import isin, gt, lt, ge, le
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -426,13 +426,13 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
)


class LinearLearnerPredictor(RealTimePredictor):
class LinearLearnerPredictor(Predictor):
"""Performs binary-classification or regression prediction from input
vectors.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/ntm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import ge, le, isin
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -196,12 +196,12 @@ def _prepare_for_training( # pylint: disable=signature-differs
)


class NTMPredictor(RealTimePredictor):
class NTMPredictor(Predictor):
"""Transforms input vectors to lower-dimesional representations.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
6 changes: 3 additions & 3 deletions src/sagemaker/amazon/object2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sagemaker.amazon.amazon_estimator import AmazonAlgorithmEstimatorBase, registry
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import ge, le, isin
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -184,7 +184,7 @@ def __init__(
may be deployed to an Amazon SageMaker Endpoint by invoking
:meth:`~sagemaker.amazon.estimator.EstimatorBase.deploy`. As well as
deploying an Endpoint, deploy returns a
:class:`~sagemaker.amazon.RealTimePredictor` object that can be used for
:class:`~sagemaker.amazon.Predictor` object that can be used for
inference calls using the trained model hosted in the SageMaker
Endpoint.

Expand Down Expand Up @@ -358,7 +358,7 @@ def __init__(self, model_data, role, sagemaker_session=None, **kwargs):
image,
model_data,
role,
predictor_cls=RealTimePredictor,
predictor_cls=Predictor,
sagemaker_session=sagemaker_session,
**kwargs
)
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import gt, isin
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -178,12 +178,12 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
)


class PCAPredictor(RealTimePredictor):
class PCAPredictor(Predictor):
"""Transforms input vectors to lower-dimesional representations.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
8 changes: 4 additions & 4 deletions src/sagemaker/amazon/randomcutforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sagemaker.amazon.common import numpy_to_record_serializer, record_deserializer
from sagemaker.amazon.hyperparameter import Hyperparameter as hp # noqa
from sagemaker.amazon.validation import ge, le
from sagemaker.predictor import RealTimePredictor
from sagemaker.predictor import Predictor
from sagemaker.model import Model
from sagemaker.session import Session
from sagemaker.vpc_utils import VPC_CONFIG_DEFAULT
Expand Down Expand Up @@ -157,12 +157,12 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
)


class RandomCutForestPredictor(RealTimePredictor):
class RandomCutForestPredictor(Predictor):
"""Assigns an anomaly score to each of the datapoints provided.

The implementation of
:meth:`~sagemaker.predictor.RealTimePredictor.predict` in this
`RealTimePredictor` requires a numpy ``ndarray`` as input. The array should
:meth:`~sagemaker.predictor.Predictor.predict` in this
`Predictor` requires a numpy ``ndarray`` as input. The array should
contain the same number of columns as the feature-dimension of the data used
to fit the model this Predictor performs inference on.

Expand Down
6 changes: 3 additions & 3 deletions src/sagemaker/chainer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
)
from sagemaker.model import FrameworkModel, MODEL_SERVER_WORKERS_PARAM_NAME
from sagemaker.chainer import defaults
from sagemaker.predictor import RealTimePredictor, npy_serializer, numpy_deserializer
from sagemaker.predictor import Predictor, npy_serializer, numpy_deserializer

logger = logging.getLogger("sagemaker")


class ChainerPredictor(RealTimePredictor):
"""A RealTimePredictor for inference against Chainer Endpoints.
class ChainerPredictor(Predictor):
"""A Predictor for inference against Chainer Endpoints.

This is able to serialize Python lists, dictionaries, and numpy arrays to
multidimensional tensors for Chainer inference.
Expand Down
Loading