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

Missing dependencies in notebooks/kubectl_demo_minikube.ipynb #101

Closed
mirekphd opened this issue Feb 21, 2018 · 1 comment · Fixed by #102
Closed

Missing dependencies in notebooks/kubectl_demo_minikube.ipynb #101

mirekphd opened this issue Feb 21, 2018 · 1 comment · Fixed by #102

Comments

@mirekphd
Copy link

This issue refers to the 'Deploying Machine Learning Models using kubectl' Jupyter Notebook (notebooks/kubectl_demo_minikube.ipynb) run under Python 3 (rather than 2). It was tested in Python 3.5 with Minikube 0.25.0 installation (KVM virtualization) running on Ubuntu 16.04 LTS.

Eventually I managed to get responses from the REST API, obtaining predictions for the model deployed in the notebook (seldonio/mock_classifier:1.0 /notebooks/resources/model.json). However, some dependencies were initially missing that required modification before the code could be executable in Python 3.x

  1. Two modules from the 'proto' library were unavailable or not exposed, raising this error:
ImportError                               Traceback (most recent call last)
<ipython-input-42-f18b8a6f5241> in <module>()
      3 # import proto
      4 from proto import prediction_pb2
----> 5 from proto import prediction_pb2_grpc
      6 import grpc
      7 # import commands

~/Documents/python/seldon/seldon-core/notebooks/proto/prediction_pb2_grpc.py in <module>()
      2 import grpc
      3 
----> 4 import prediction_pb2 as prediction__pb2
      5 
      6 
ImportError: No module named 'prediction_pb2'

This issue can be solved by replacing the specific modules with the entire 'proto' library:

import proto
# from proto import prediction_pb2
# from proto import prediction_pb2_grpc

  1. The 'commands' module has been deprecated and removed from Python 3.x (link). Trying to use it in Python 3.x will cause this error message:
ImportError                               Traceback (most recent call last)
<ipython-input-44-f4c737095fff> in <module>()
      5 # from proto import prediction_pb2_grpc
      6 import grpc
----> 7 import commands
      8 # import subprocess
      9 
ImportError: No module named 'commands'

This issue can be solved by replacing all references to this module in the Notebook with its successor module 'subprocess' (which has compatible function names), leaving a code like this:

# import commands
import subprocess

NAMESPACE='seldon'
MINIKUBE_IP=subprocess.getoutput('minikube ip')
MINIKUBE_HTTP_PORT=subprocess.getoutput("kubectl get svc -n "+NAMESPACE+" -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[0].nodePort}'")
MINIKUBE_GRPC_PORT=subprocess.getoutput("kubectl get svc -n "+NAMESPACE+" -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[1].nodePort}'")

Collecting the above corrections produces a code that executes cleanly in Python 3.x and we finally get our predictions from the server:


import requests
from requests.auth import HTTPBasicAuth
import proto
# from proto import prediction_pb2
# from proto import prediction_pb2_grpc
import grpc
# import commands
import subprocess

NAMESPACE='seldon'
MINIKUBE_IP=subprocess.getoutput('minikube ip')
MINIKUBE_HTTP_PORT=subprocess.getoutput("kubectl get svc -n "+NAMESPACE+" -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[0].nodePort}'")
MINIKUBE_GRPC_PORT=subprocess.getoutput("kubectl get svc -n "+NAMESPACE+" -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].spec.ports[1].nodePort}'")
[..]

However, all gRPC requests fail due to the missing 'prediction_pb2_grpc' module:

{"access_token":"7f5646a1-35c2-431d-a775-aca2b59307b7","token_type":"bearer","expires_in":28304,"scope":"read write"}
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-46-b1d1323ec6bf> in <module>()
----> 1 grpc_request()

<ipython-input-45-f36a438b7865> in grpc_request()
     44     request = prediction_pb2.SeldonMessage(data = datadef)
     45     channel = grpc.insecure_channel(MINIKUBE_IP+":"+MINIKUBE_GRPC_PORT)
---> 46     stub = prediction_pb2_grpc.SeldonStub(channel)
     47     metadata = [('oauth_token', token)]
     48     response = stub.Predict(request=request,metadata=metadata)
NameError: name 'prediction_pb2_grpc' is not defined


@Maximophone
Copy link
Contributor

Hi,

Thanks for reporting this. The code that generates the pb2 files in notebooks/Makefile needs to be updated to make them compatible with python 3. This has been done in wrappers/Makefile but we forgot this one. We will fix that and then you should be able to import them without a problem.

We will also replace commands with subprocess like you did.

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

Successfully merging a pull request may close this issue.

2 participants