mlflow / mlflow

Open source platform for the machine learning lifecycle
https://mlflow.org
Apache License 2.0
18.44k stars 4.17k forks source link

Pytorch serving doesn't work for multiple inputs, multiple outputs model #4811

Open piseabhijeet opened 3 years ago

piseabhijeet commented 3 years ago

Thank you for submitting a feature request. Before proceeding, please review MLflow's Issue Policy for feature requests and the MLflow Contributing Guide.

Please fill in this feature request template to ensure a timely and thorough response.

Willingness to contribute

The MLflow Community encourages new feature contributions. Would you or another member of your organization be willing to contribute an implementation of this feature (either as an MLflow Plugin or an enhancement to the MLflow code base)?

Proposal Summary

Currently pytorch model serving works for single input and single output model. To make it generic and flexible, it would be great if it supports multi input and multi output serving.

Motivation

This has many use cases. In fact most of the real world models output multiple features.

What component(s), interfaces, languages, and integrations does this feature affect?

Components

Interfaces

Languages

Integrations

Details

I am using a single input - multiple output model in this example using Pytorch lightning:

model = CustomModel(args)' 'model_dict = {'input1': np.zeros((1, 256, 256, 3))}' 'input_schema = Schema([TensorSpec(np.dtype(np.float32), (-1, 256,256,3)),])' 'output_schema = Schema([TensorSpec(np.dtype(np.float32), (-1, 2), name='out1'), TensorSpec(np.dtype(np.float32), (-1, 3), name='out2')])' 'signature = ModelSignature(inputs=input_schema, outputs=output_schema)' 'mlflow.pytorch.log_model(model,"Models", input_example=model_dict['input1'], signature=signature)

When this model is served, it throws this error:

"xxxxxxx in predict\n \"but got output of type '{}'\".format(type(preds))\nTypeError: Expected PyTorch model to output a single output tensor, but got output of type '<class 'dict'>'\n"

pjh4993 commented 1 year ago

@piseabhijeet Do we have any progress in this issue? I am willing to engage on this enhancement.