Skip to content

Commit

Permalink
Updated python wrappers. Reddis key of persisted model is now made of…
Browse files Browse the repository at this point in the history
… deployment, predictor and predictive unit ids. Added debug mode to persistence. Made truth seldon message in feedback optional for routers.
  • Loading branch information
Maximophone committed Jan 31, 2018
1 parent 4cca25b commit 8e6aed2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion helm-charts/seldon-core/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cluster_manager:
enabled: true
image:
pull_policy: IfNotPresent
tag: 0.1.4-SNAPSHOT
tag: SNAPSHOT-MF-0
java_opts: ''
rbac: false
spring_opts: ''
Expand Down
2 changes: 1 addition & 1 deletion wrappers/python/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def parse_parameters(parameters):
user_class = getattr(interface_file,args.interface_name)

if args.persistence:
user_object = persistence.restore(user_class,parameters)
user_object = persistence.restore(user_class,parameters,debug=DEBUG)
persistence.persist(user_object,parameters.get("push_frequency"))
else:
user_object = user_class(**parameters)
Expand Down
15 changes: 10 additions & 5 deletions wrappers/python/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@


PRED_UNIT_ID = os.environ.get("PREDICTIVE_UNIT_ID","0")
PREDICTOR_ID = os.environ.get("PREDICTOR_ID","0")
DEPLOYMENT_ID = os.environ.get("SELDON_DEPLOYMENT_ID","0")
REDIS_KEY = "persistence_{}_{}".format(DEPLOYMENT_ID,PRED_UNIT_ID)
REDIS_KEY = "persistence_{}_{}_{}".format(DEPLOYMENT_ID,PREDICTOR_ID,PRED_UNIT_ID)

REDIS_HOST = os.environ.get('REDIS_SERVICE_HOST','localhost')
REDIS_PORT = os.environ.get("REDIS_SERVICE_PORT",6379)
DEFAULT_PUSH_FREQUENCY = 60


def restore(user_class,parameters):

def restore(user_class,parameters,debug=False):
if debug:
print("Restoring saved model from redis")
redis_client = redis.StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
saved_state_binary = redis_client.get(REDIS_KEY)
if saved_state_binary is None:
print("Saved state is empty, restoration aborted")
return user_class(**parameters)
else:
return pickle.loads(saved_state_binary)

def persist(user_object,push_frequency=None):
def persist(user_object,push_frequency=None,debug=False):
if push_frequency is None:
push_frequency = DEFAULT_PUSH_FREQUENCY
if debug:
print("Creating persistence thread, with frequency {}".format(push_frequency))
persistence_thread = PersistenceThread(user_object,push_frequency)
persistence_thread.start()

Expand All @@ -38,7 +43,7 @@ def __init__(self,user_object,push_frequency):
super(PersistenceThread,self).__init__()

def stop(self):
print "Stopping Persistence Thread"
print("Stopping Persistence Thread")
self._stopped = True

def run(self):
Expand Down
2 changes: 1 addition & 1 deletion wrappers/python/router_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def SendFeedback():
datadef_request = feedback.get("request").get("data")
features = rest_datadef_to_array(datadef_request)

truth = rest_datadef_to_array(feedback.get("truth"))
truth = rest_datadef_to_array(feedback.get("truth",{}))
reward = feedback.get("reward")
routing = feedback.get("response").get("meta").get("routing").get(PRED_UNIT_ID)

Expand Down

0 comments on commit 8e6aed2

Please sign in to comment.