-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from HughWen/dev
v0.2.0
- Loading branch information
Showing
9 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
### 0.2.0 | ||
|
||
- change the input type of web agent from single item to batch item | ||
- support model collection | ||
|
||
### 0.1.0 | ||
|
||
- serialize the request data | ||
- put data into redis broker | ||
- get and process data from redis broker then put back | ||
- web server gets output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
import uuid | ||
import time | ||
import pickle | ||
from typing import List | ||
|
||
import redis | ||
|
||
|
||
class WebAgent: | ||
def __init__(self, redis_broker='localhost:6379', redis_queue='broker', web_sleep=0.1, max_tries=6000): | ||
def __init__(self, redis_broker='localhost:6379', redis_queue='broker', web_sleep=0.1, max_tries=6000, unpickling=True): | ||
parse = lambda x: {'host': x.split(':')[0], 'port': int(x.split(':')[1])} | ||
self.db = redis.StrictRedis(**parse(redis_broker)) | ||
self.redis_queue = redis_queue | ||
self.web_sleep = web_sleep | ||
self.max_tries = max_tries | ||
self.unpickling = unpickling | ||
|
||
def process(self, batch: List) -> List: | ||
""" | ||
input a batch, send items to redis broker and polling | ||
""" | ||
keys = [str(uuid.uuid4()) for _ in range(len(batch))] | ||
with self.db.pipeline() as pipe: | ||
for key, model_input in zip(keys, batch): | ||
message = {'key': key, 'model_input': model_input} | ||
pipe.rpush(self.redis_queue, pickle.dumps(message)) | ||
pipe.execute() | ||
|
||
def process(self, model_input): | ||
key = str(uuid.uuid4()) | ||
message = {'key': key, 'model_input': model_input} | ||
self.db.rpush(self.redis_queue, pickle.dumps(message)) | ||
num_tries = 0 | ||
# polling the redis broker | ||
num_tries = 0 | ||
while num_tries < self.max_tries: | ||
time.sleep(self.web_sleep) | ||
num_tries += 1 | ||
result = self.db.get(key) | ||
if result: | ||
model_output = pickle.loads(result) | ||
self.db.delete(key) | ||
return model_output | ||
outputs = self.db.mget(keys) | ||
if None not in outputs: | ||
self.db.delete(*keys) | ||
if self.unpickling: | ||
outputs = [pickle.loads(x) for x in outputs] | ||
return outputs | ||
else: | ||
return None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
|
||
setup( | ||
name='serving_agent', | ||
version="0.1.0", | ||
version="0.2.0", | ||
description='A middleware for model serving to speedup online inference.', | ||
author="wwen", | ||
author_email="[email protected]", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
# long_description=long_description, | ||
# long_description_content_type="text/markdown", | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Programming Language :: Python :: 3.5', | ||
|