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

Pass missing infer parameters during conversion #3368

Merged
merged 5 commits into from
Jan 26, 2024

Conversation

sivanantha321
Copy link
Member

@sivanantha321 sivanantha321 commented Jan 16, 2024

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3365

Type of changes
Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Feature/Issue validation/testing:

Please describe the tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.

  • Test A

  • Test B

  • Logs

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Checklist:

  • Have you added unit/e2e tests that prove your fix is effective or that this feature works?
  • Has code been commented, particularly in hard-to-understand areas?
  • Have you made corresponding changes to the documentation?

Release note:

Pass missing infer parameters during conversion

@sivanantha321 sivanantha321 force-pushed the pass-infer-parameters branch 2 times, most recently from db56d96 to 4f9852c Compare January 18, 2024 09:17
@ajstewart
Copy link
Contributor

I saw this PR linked to my issue and had a look out of interest as I wondered about the to_grpc method. In my own work around I had to make sure that the to_grpc was setting the parameters as kserve.protocol.grpc.grpc_predict_v2_pb2.InferParameter objects. This is in the transformer. Then in the predictor I had to do some conversion back to either string, int, float or bool with prior knowledge as to what they should be (I couldn't see a helper on that object to transform back to the intended format).

This is all new to me and I'm not very familiar with kserve so I might be talking nonsense but I couldn't see an elegant way to deal with that.

I must admit I'm using them to place extra information into the request to change some predictor behaviour and some custom component settings, so I could be abusing the functionality.

@sivanantha321
Copy link
Member Author

I saw this PR linked to my issue and had a look out of interest as I wondered about the to_grpc method. In my own work around I had to make sure that the to_grpc was setting the parameters as kserve.protocol.grpc.grpc_predict_v2_pb2.InferParameter objects. This is in the transformer. Then in the predictor I had to do some conversion back to either string, int, float or bool with prior knowledge as to what they should be (I couldn't see a helper on that object to transform back to the intended format).

This is all new to me and I'm not very familiar with kserve so I might be talking nonsense but I couldn't see an elegant way to deal with that.

I must admit I'm using them to place extra information into the request to change some predictor behaviour and some custom component settings, so I could be abusing the functionality.

Can you try with these changes and give some feedback ?

@yuzisun
Copy link
Member

yuzisun commented Jan 22, 2024

The change looks good, discussed with @Siva to add a few tests

@sivanantha321 sivanantha321 force-pushed the pass-infer-parameters branch 3 times, most recently from cbba47d to 3a773e7 Compare January 24, 2024 08:33
@sivanantha321
Copy link
Member Author

The change looks good, discussed with @Siva to add a few tests

Tests added.

@@ -240,14 +243,14 @@ def test_list_models_v1(self, http_server_client):

def test_predict_v1(self, http_server_client):
resp = http_server_client.post('/v1/models/TestModel:predict',
data=b'{"instances":[[1,2]]}')
content=b'{"instances":[[1,2]]}')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the warning
DeprecationWarning: Use 'content=<...>' to upload raw bytes/text content.

@ajstewart
Copy link
Contributor

ajstewart commented Jan 24, 2024

Can you try with these changes and give some feedback ?

A gave your branch a go (3a773e7) but I'm hitting an assignment error pasted below. I think I remember hitting the same problem in my workaround and I ended not trying to reassign on the current parameters but instead recreating them.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.10/site-packages/timing_asgi/middleware.py", line 68, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/rest/v2_endpoints.py", line 151, in infer
    response, response_headers = self.dataplane.encode(model_name=model_name,
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/dataplane.py", line 273, in encode
    response = response.to_rest()
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/infer_type.py", line 611, in to_rest
    res['parameters'] = to_http_parameters(self.parameters)
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/infer_type.py", line 688, in to_http_parameters
    parameters[key] = val.string_param
ValueError: Direct assignment of submessage not allowed

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
@sivanantha321
Copy link
Member Author

Can you try with these changes and give some feedback ?

A gave your branch a go (3a773e7) but I'm hitting an assignment error pasted below. I think I remember hitting the same problem in my workaround and I ended not trying to reassign on the current parameters but instead recreating them.

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.10/site-packages/timing_asgi/middleware.py", line 68, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
    return await dependant.call(**values)
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/rest/v2_endpoints.py", line 151, in infer
    response, response_headers = self.dataplane.encode(model_name=model_name,
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/dataplane.py", line 273, in encode
    response = response.to_rest()
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/infer_type.py", line 611, in to_rest
    res['parameters'] = to_http_parameters(self.parameters)
  File "/usr/local/lib/python3.10/site-packages/kserve/protocol/infer_type.py", line 688, in to_http_parameters
    parameters[key] = val.string_param
ValueError: Direct assignment of submessage not allowed

I am not reassigning the parameters dict anymore. Can you retry with these changes ?

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
@ajstewart
Copy link
Contributor

I am not reassigning the parameters dict anymore. Can you retry with these changes ?

Yep these are being passed through now! The model I am testing is using grpc so once they get to the predictor I have to run the to_http_parameters so I can easily make use of the values in the dict of InferParameter types. But all the functionality is there now to do what I wanted to do, thanks!

@yuzisun
Copy link
Member

yuzisun commented Jan 26, 2024

Thanks @sivanantha321 fixing this!

/lgtm
/approve

Copy link

oss-prow-bot bot commented Jan 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sivanantha321, yuzisun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@oss-prow-bot oss-prow-bot bot merged commit 1bfba02 into kserve:master Jan 26, 2024
58 checks passed
timothyjlaurent pushed a commit to timothyjlaurent/kserve that referenced this pull request Feb 21, 2024
* Pass missing infer parameters

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>

* Add tests

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>

* Fix warnings

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>

* Add equal magic method for infer types

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>

* Avoid inplace modification of parameters in conversion

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>

---------

Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python SDK: Optional InferInput.parameters missing from InferRequest.to_rest()/.to_grpc()
3 participants