-
Notifications
You must be signed in to change notification settings - Fork 867
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
fix failed to create model archive #1508
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"runtime": "python", | ||
"model": { | ||
"modelName": "noop", | ||
"serializedFile": "model.pt", | ||
"handler": "service.py" | ||
}, | ||
"modelServerVersion": "1.0", | ||
"implementationVersion": "1.0", | ||
"specificationVersion": "1.0" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to store a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, noop is an example. model.pt is an empty file. Manifest requires it to pass validation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
|
||
""" | ||
NoopService defines a no operational model handler. | ||
""" | ||
import logging | ||
import time | ||
|
||
|
||
class NoopService(object): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow why a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example noop_no_archive_no_version is copied from original noop_no_archive. I did slightly change (ie remove modelversion in manifest.json) for unit test the default manifest bug fixing. |
||
""" | ||
Noop Model handler implementation. | ||
|
||
Extend from BaseModelHandler is optional | ||
""" | ||
|
||
def __init__(self): | ||
self._context = None | ||
self.initialized = False | ||
|
||
def initialize(self, context): | ||
""" | ||
Initialize model. This will be called during model loading time | ||
|
||
:param context: model server context | ||
:return: | ||
""" | ||
self.initialized = True | ||
self._context = context | ||
|
||
@staticmethod | ||
def preprocess(data): | ||
""" | ||
Transform raw input into model input data. | ||
|
||
:param data: list of objects, raw input from request | ||
:return: list of model input data | ||
""" | ||
return data | ||
|
||
@staticmethod | ||
def inference(model_input): | ||
""" | ||
Internal inference methods | ||
|
||
:param model_input: transformed model input data | ||
:return: inference results | ||
""" | ||
return model_input | ||
|
||
@staticmethod | ||
def postprocess(model_output): | ||
return ["OK"] * len(model_output) | ||
|
||
def handle(self, data, context): | ||
""" | ||
Custom service entry point function. | ||
|
||
:param context: model server context | ||
:param data: list of objects, raw input from request | ||
:return: list of outputs to be send back to client | ||
""" | ||
# Add your initialization code here | ||
properties = context.system_properties | ||
server_name = properties.get("server_name") | ||
server_version = properties.get("server_version") | ||
model_dir = properties.get("model_dir") | ||
gpu_id = properties.get("gpu_id") | ||
batch_size = properties.get("batch_size") | ||
|
||
logging.debug("server_name: {}".format(server_name)) | ||
logging.debug("server_version: {}".format(server_version)) | ||
logging.debug("model_dir: {}".format(model_dir)) | ||
logging.debug("gpu_id: {}".format(gpu_id)) | ||
logging.debug("batch_size: {}".format(batch_size)) | ||
try: | ||
preprocess_start = time.time() | ||
data = self.preprocess(data) | ||
inference_start = time.time() | ||
data = self.inference(data) | ||
postprocess_start = time.time() | ||
data = self.postprocess(data) | ||
end_time = time.time() | ||
|
||
context.set_response_content_type(0, "text/plain") | ||
|
||
content_type = context.request_processor[0].get_request_property("Content-Type") | ||
logging.debug("content_type: {}".format(content_type)) | ||
|
||
metrics = context.metrics | ||
metrics.add_time("PreprocessTime", round((inference_start - preprocess_start) * 1000, 2)) | ||
metrics.add_time("InferenceTime", round((postprocess_start - inference_start) * 1000, 2)) | ||
metrics.add_time("PostprocessTime", round((end_time - postprocess_start) * 1000, 2)) | ||
return data | ||
except Exception as e: | ||
logging.error(e, exc_info=True) | ||
context.request_processor[0].report_status(500, "Unknown inference error.") | ||
return ["Error {}".format(str(e))] * len(data) | ||
|
||
|
||
_service = NoopService() | ||
|
||
|
||
def handle(data, context): | ||
if not _service.initialized: | ||
_service.initialize(context) | ||
|
||
if data is None: | ||
return None | ||
|
||
return _service.handle(data, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lxning how would we handle the case if there are multiple mar files in a directory? are we relying on user to have only one mar file in the /xxx/model_store/modelXXX directory? In this case we need to make sure we have documented it clearly.
Do you we have any documentation on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood this PR as no longer needing a
model_store
and just letting users link to various model files directyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In model_store dir, existing code ignores the mar files in the subdir (ie. /xxx/model_store/modelXXX).