inference_server.testing
Functions for testing inference-server plugins
- class ImplementsDeserialize(*args, **kwargs)[source]
Bases:
ProtocolInterface compatible with
sagemaker.deserializers.BaseDeserializer
- class ImplementsSerialize(*args, **kwargs)[source]
Bases:
ProtocolInterface compatible with
sagemaker.serializers.BaseSerializer
- client() Client[source]
Return an HTTP test client for
inference_serverThe test client is simply a
werkzeug.test.Clientinstance which loads the inference-server WSGI app. Consult thewerkzeugdocumentation for details how to use the test client.
- hookimpl_is_valid(function: Callable) bool[source]
Return whether the given function is a valid implementation of an
inference_serverhook- Parameters:
function – The hook function to validate
- plugin_is_registered(plugin: Type | ModuleType) bool[source]
Return whether the given plugin is registered with
inference_serverThis validates whether a plugin entrypoint is defined in
pyproject.tomllike this:[project.entry-points.inference_server] my_plugin_name = "my_module_name"
- Parameters:
plugin – The plugin, typically a module containg the hook functions.
- post_invocations(*, model_dir: Path | None = None, **kwargs) TestResponse[source]
Send an HTTP POST request to
/invocationsusing a test HTTP client and return the responseThis function should be used to verify an inference request using the full inference-server logic.
- Parameters:
model_dir – Optional pass a custom model directory to load the model from. Default is
/opt/ml/model/.kwargs – Keyword arguments passed to
werkzeug.test.Client.post()
- predict(data: Any, *, model_dir: Path | None = None, serializer: ImplementsSerialize | None = None, deserializer: ImplementsDeserialize | None = None) Any[source]
Invoke the model and return a prediction
- Parameters:
data – Model input data
model_dir – Optional pass a custom model directory to load the model from. Default is
/opt/ml/model/.serializer – Optional. A serializer for sending the data as bytes to the model server. Should be compatible with
sagemaker.serializers.BaseSerializer. Default: bytes pass-through.deserializer – Optional. A deserializer for processing the prediction as sent by the model server. Should be compatible with
sagemaker.deserializers.BaseDeserializer. Default: bytes pass-through.