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

WIP: Python wrappers rewrite #457

Merged
merged 28 commits into from
Mar 6, 2019
Merged

WIP: Python wrappers rewrite #457

merged 28 commits into from
Mar 6, 2019

Conversation

ukclivecox
Copy link
Contributor

Rewrite of python wrapper

  • Code is for python 3.X only
  • Adds type annotations
  • Consolidates REST and gRPC processing so all requests are parsed for correctness
  • Creates a SeldonClient reference library for call the Seldon API
  • Updates tester programs to use new SeldonClient
  • Extends tests

@jklaise jklaise self-requested a review February 25, 2019 10:21
Copy link
Contributor

@jklaise jklaise left a comment

Choose a reason for hiding this comment

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

A few points:

  • Add pytest-cov to tests_require in setup.py and the pytest flag --cov=seldon_core in setup.cfg under addopts to get test coverage report.
  • Expose SeldonClient at top level of package
  • max_grpc_msg_size.ipynb confusingly deletes seldon-core (!helm delete seldon-core --purge) between two examples which causes the notebook not to work end-to-end
  • Add a note for max_grpc_msg_size.ipynb to run the notebook with jupyter notebook --NotebookApp.iopub_data_rate_limit=1000000000 for it to run successfully

@ukclivecox ukclivecox added this to the 0.2.x milestone Feb 26, 2019
Copy link

@oshev oshev left a comment

Choose a reason for hiding this comment

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

I haven't found any serious problems. Left some comments, mostly formatting and style, a couple of suggestions for improvements and minor issues. Unfortunately, I didn't have time to pull the branch and inspect it in IDE yet, only checked on GitHub quickly. If you can wait, I'll have a bit more time on Friday. Otherwise, LGTM from me. Thank you for this rewrite!

python/seldon_core/flask_utils.py Show resolved Hide resolved
python/seldon_core/flask_utils.py Outdated Show resolved Hide resolved
python/seldon_core/microservice.py Outdated Show resolved Hide resolved
python/seldon_core/microservice_tester.py Outdated Show resolved Hide resolved
python/seldon_core/microservice_tester.py Show resolved Hide resolved
def main():
parser = argparse.ArgumentParser()
parser.add_argument("contract", type=str,
help="File that contains the data contract")
Copy link

Choose a reason for hiding this comment

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

We wrote a script to generate the contract automatically based on a dataset sample in pandas.DataFrame, let us know if you want it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be very useful!

Copy link

Choose a reason for hiding this comment

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

Great! How it's better proceed with it? Should I create a PR or just pass the code to you? I need to clean up a bit. Will be ready on Monday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A PR would be great.

python/seldon_core/persistence.py Outdated Show resolved Hide resolved
python/seldon_core/seldon_methods.py Show resolved Hide resolved
python/seldon_core/seldon_methods.py Show resolved Hide resolved
python/tests/resources/contract.json Outdated Show resolved Hide resolved
Copy link

@oshev oshev left a comment

Choose a reason for hiding this comment

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

some more minor stuff

python/seldon_core/microservice.py Show resolved Hide resolved
python/seldon_core/microservice.py Outdated Show resolved Hide resolved
python/seldon_core/persistence.py Outdated Show resolved Hide resolved
python/seldon_core/persistence.py Outdated Show resolved Hide resolved
@oshev
Copy link

oshev commented Mar 2, 2019

I can't see this branch when I do git branch --all so I can't pull it and observe it locally (I did git fetch and even tried to checkout the repo from scratch). Any ideas why does this happen?

@oshev
Copy link

oshev commented Mar 2, 2019

Sorry, I didn't realise Clive was merging from his fork of seldon-core. Never mind my question. Clear now.

@oshev
Copy link

oshev commented Mar 4, 2019

Shouldn't all API testing functionality go into a separate package inside seldon-core package? Otherwise, you're mixing it with production functionality.

Copy link

@oshev oshev left a comment

Choose a reason for hiding this comment

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

Some more minor issues plus several suggestions for further refactoring. I looked at the code in IDE but still didn't find any serious issues. This is as good as you get from me at the moment. To be more useful reviewer, I would need to contribute more regularly to better understand the logic of each component.

python/seldon_core/persistence.py Outdated Show resolved Hide resolved
python/seldon_core/microservice_tester.py Outdated Show resolved Hide resolved
python/seldon_core/microservice_tester.py Show resolved Hide resolved
python/seldon_core/seldon_client.py Outdated Show resolved Hide resolved
python/seldon_core/user_model.py Outdated Show resolved Hide resolved
python/seldon_core/user_model.py Outdated Show resolved Hide resolved
python/seldon_core/utils.py Show resolved Hide resolved
python/seldon_core/microservice.py Show resolved Hide resolved
python/seldon_core/microservice.py Outdated Show resolved Hide resolved
python/seldon_core/microservice.py Show resolved Hide resolved
@@ -193,19 +197,20 @@ def aggregate(user_model: object, request: prediction_pb2.SeldonMessageList) ->
request_json = json_format.MessageToJson(request)
response_json = user_model.aggregate_rest(request_json)
return json_to_seldon_message(response_json)
if hasattr(user_model, "aggregate_grpc"):
elif hasattr(user_model, "aggregate_grpc"):
Copy link

Choose a reason for hiding this comment

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

are you sure this kind of checks will still work if you inherit from SeldonComponent? all attributes will be in the child class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was trying to get round some type check failures. Solved by allowing Any at certain parts as the user is not required to sub class SeldonComponent at present. Will push an update.

Copy link

Choose a reason for hiding this comment

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

I liked the idea of having to instantiate SeldonComponent but then - yes - you can't rely on hasattr methods and should use a different mechanism. I reckon you could make it an Interface with no methods, and then branch from it child interfaces with specific set of methods (my guess is that not every method would form a separate interface but you could group some). Users would then inherit several interfaces they need and you would check if their class is an instance of specific interfaces instead of using hasattr. This way you could keep strong typing. It sounds more Java, I know, but with type annotations that's where Python seems to be shifting a bit. :-)

I realise that even if you agree, this a big change, probably requires a bit more thinking, and shouldn't go in this PR. I think using Any is a good solution for now. Not very elegant but works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think that all makes a lot of sense. We should add an issue when this is merged.

@ukclivecox ukclivecox merged commit 7ad5eee into SeldonIO:master Mar 6, 2019
@ukclivecox ukclivecox deleted the python_wrappers_rewrite branch February 14, 2020 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants