Implementé un punto final de sagemaker usando el siguiente código:
from sagemaker.pytorch import PyTorchModel from sagemaker import get_execution_role, Session sess = Session() role = get_execution_role() model = PyTorchModel(model_data=my_trained_model_location, role=role, sagemaker_session=sess, framework_version='1.5.0', entry_point='inference.py', source_dir='.') predictor = model.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge', endpoint_name='my_endpoint')Si ejecuto:
import numpy as np pseudo_data = [np.random.randn(1, 300), np.random.randn(6, 300), np.random.randn(3, 300), np.random.randn(7, 300), np.random.randn(5, 300)] # input data is a list of 2D numpy arrays with variable first dimension and fixed second dimension result = predictor.predict(pseudo_data)Puedo generar el resultado sin errores. Sin embargo, si quiero invocar el punto final y hacer una predicción ejecutando:
from sagemaker.predictor import RealTimePredictor predictor = RealTimePredictor(endpoint='my_endpoint') result = predictor.predict(pseudo_data)obtendría un error:
Traceback (most recent call last): File "default_local.py", line 77, in <module> score = predictor.predict(input_data) File "/home/biggytruck/.local/lib/python3.6/site-packages/sagemaker/predictor.py", line 113, in predict response = self.sagemaker_session.sagemaker_runtime_client.invoke_endpoint(**request_args) File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 608, in _make_api_call api_params, operation_model, context=request_context) File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/client.py", line 656, in _convert_to_request_dict api_params, operation_model) File "/home/biggytruck/.local/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request raise ParamValidationError(report=report.generate_report()) botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter Body Según tengo entendido, el error ocurre porque no pasé inference.py como el archivo de punto de entrada, que es necesario para manejar la entrada, ya que no está en un formato estándar compatible con Sagemaker. Sin embargo, sagemaker.predictor.RealTimePredictor no me permite definir el archivo de punto de entrada. ¿Como puedo resolver esto?
El error que está viendo proviene de la biblioteca del SDK de Python de SageMaker del lado del cliente, no del extremo remoto que ha publicado.
Aquí está la documentación para el argumento de data (en su caso, esto es pseudo_data )
data (object) – Input data for which you want the model to provide inference. If a serializer was specified when creating the RealTimePredictor, the result of the serializer is sent as input data. Otherwise the data must be sequence of bytes, and the predict method then sends the bytes in the request body as is.
Supongo que pseudo_data no es el tipo que espera el SDK de Python de SageMaker, que es una secuencia de bytes .