Skip to content
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

Fail validate when converting to numpy array in transformer #2291

Closed
eyalcha opened this issue Jun 30, 2022 · 4 comments
Closed

Fail validate when converting to numpy array in transformer #2291

eyalcha opened this issue Jun 30, 2022 · 4 comments

Comments

@eyalcha
Copy link
Contributor

eyalcha commented Jun 30, 2022

/kind bug

Issue #1972 removed np.array check and now conversion should be done in transformer (which is the correct approach).
The issue is that currently when converting to np.array it fails in validate function in transformer because it is not a list

def validate(self, request):

@yuzisun
Copy link
Member

yuzisun commented Jul 1, 2022

@eyalcha transformer needs to send the request to predictor over the wire so I think it still needs to convert to a list according to the protocol right?

@eyalcha
Copy link
Contributor Author

eyalcha commented Jul 3, 2022

@yuzisun the issue is here :

async def __call__(self, body, model_type: ModelType = ModelType.PREDICTOR):

If we need to convert to numpy array and then send to predict (with REST V1/V2), the validate function in transformer will fail.

import numpy as np

request = {
    "instances": [
      {}  
    ]
}
print(isinstance(request["instances"], list))
# True

request["instances"] = np.array(request["instances"])
print(isinstance(request["instances"], list))
# False

The assumption is that we need to convert the instances to array before sending it to predict. Before issue #1972 it was done in predictor, in the predict function with no validation. Now it was moved to pre process of transformer and the validate function fails because of the type change.

Am I missing something?

@yuzisun
Copy link
Member

yuzisun commented Feb 4, 2023

@eyalcha Can you provide a more detailed example for the issue ? As I understand sklearn predict is able to convert to either numpy or pandas data framework accordingly.

@yuzisun
Copy link
Member

yuzisun commented Apr 9, 2023

The validation is only done when the input is a dict type, you can pass the np array to the predict function.

if isinstance(payload, Dict) and "instances" in payload and not isinstance(payload["instances"], list):

@yuzisun yuzisun closed this as completed Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants