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

How can we specify nested python class in .s2i/environment? #465

Closed
yu-iskw opened this issue Mar 13, 2019 · 2 comments · Fixed by #503
Closed

How can we specify nested python class in .s2i/environment? #465

yu-iskw opened this issue Mar 13, 2019 · 2 comments · Fixed by #503

Comments

@yu-iskw
Copy link

yu-iskw commented Mar 13, 2019

Motivation

We want to manage the training code and the serving code as well. But, we want to manage the files in a directory. So, our question is can we specify such a nested python class in .s2i/environment or not.

Expectaed Behavior

We want to specify a nested class as below.

Example .s2i/environment

MODEL_NAME=src.v1.IrisClassifier
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0

Example Directory Structure

.
├── IrisClassifier.sav
├── contract.json
├── requirements.txt
├── sklearn_iris.ipynb
├── sklearn_iris_deployment.json
├── src
│   └── v1
│       └── IrisClassifier.py
│       └── train_iris.py

Error Message

starting microservice
2019-03-13 17:44:26,507 - seldon_core.microservice:main:261 - INFO:  Starting microservice.py:main
2019-03-13 17:44:26,510 - seldon_core.microservice:main:292 - INFO:  Annotations: {}
Traceback (most recent call last):
  File "/usr/local/bin/seldon-core-microservice", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/seldon_core/microservice.py", line 295, in main
    user_class = getattr(interface_file, args.interface_name)
AttributeError: module 'src.v1.IrisClassifier' has no attribute 'src.v1.IrisClassifier'
@ukclivecox
Copy link
Contributor

We use Importlib specifically importlib.import_module which should handle the dot notation. We have not tested this case, but we definitely need a story to provide this.

@jlewi
Copy link

jlewi commented Apr 10, 2019

Won't we have problems here

user_class = getattr(interface_file, args.interface_name)

if interface_name contains a dotted path.

e.g. in this case suppose interface_name = "v1.IrisClassifier"

So we end up calling

    interface_file = importlib.import_module("v1.IrisClassifier")
    user_class = getattr(interface_file, "v1.IrisClassifier)

The call to getattr is using the full module dotted name of the package which doesn't match the class name; I think it should be

  user_class = getattr(interface_file, "IrisClassifier")

Would it make sense to allow the module path and class to be specified separately?

One option would be to just assume everything after the last "." is the class name and everything before is the module you could then parse it doing something like

full_module, user_class = args.interface_name.rsplit(".", 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants