Skip to content

Commit b2866bf

Browse files
pymumuCarlosLeeGit
authored andcommitted
mnist: optimize UI message
1 parent 8964a4b commit b2866bf

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

examples/project/mnist-mindspore/src/flowunit/mnist_infer/mnist_infer.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ type = "float"
2929

3030
[output]
3131
[output.output1]
32-
name = "Default/fc3-Dense/BiasAdd-op21"
32+
name = "Default/fc3-Dense/BiasAdd-op229"
3333
type = "float"

examples/project/mnist-mindspore/src/graph/mnist.toml.in renamed to examples/project/mnist-mindspore/src/graph/mnist.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ graphconf = '''digraph mnist_sample {
1919
2020
httpserver_sync_receive:out_request_info -> mnist_preprocess:in_data
2121
mnist_preprocess:out_data -> mnist_infer:x
22-
mnist_infer:"Default/fc3-Dense/BiasAdd-op21" -> mnist_response:in_data
22+
mnist_infer:"Default/fc3-Dense/BiasAdd-op229" -> mnist_response:in_data
2323
mnist_response:out_data -> httpserver_sync_reply:in_reply_info
2424
}
2525
'''

src/drivers/common/flowunit/inference/model_decrypt.cc

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ Status ModelDecryption::Init(const std::string& model_path,
5151

5252
fmodel_.open(model_path, std::ios::binary);
5353
if (fmodel_.fail() || !fmodel_.is_open()) {
54-
MBLOG_ERROR << "open model '" << model_path << "' failed, "
55-
<< StrError(errno);
56-
return STATUS_FAULT;
54+
std::string errmsg = "open model '";
55+
errmsg += model_path + "' failed, " + StrError(errno);
56+
MBLOG_ERROR << errmsg;
57+
return {STATUS_INVALID, errmsg};
5758
}
59+
5860
fmodel_.seekg(0, std::ios::end);
5961
fsize_ = fmodel_.tellg();
6062
if (fsize_ <= 0) {
61-
MBLOG_ERROR << "empty model file: " << model_path;
62-
return STATUS_FAULT;
63+
std::string errmsg = "empty model file: " + model_path;
64+
MBLOG_ERROR << errmsg;
65+
return {STATUS_BADCONF, errmsg};
6366
}
6467

6568
auto plugin_name = config->GetString("encryption.plugin_name");
@@ -73,31 +76,36 @@ Status ModelDecryption::Init(const std::string& model_path,
7376
MBLOG_ERROR << "drivers_ptr is null";
7477
return STATUS_FAULT;
7578
}
79+
7680
auto plugin_driver = drivers_ptr->GetDriver(
7781
DRIVER_CLASS_MODEL_DECRYPT, DRIVER_TYPE, plugin_name, plugin_version);
7882
if (plugin_driver == nullptr) {
79-
MBLOG_ERROR << "Can not find drivers: " << plugin_name;
83+
std::string errmsg = "Can not find decrytp drivers: " + plugin_name;
84+
MBLOG_ERROR << errmsg;
8085
// fclose will call when ~ModelDecryption
81-
return STATUS_FAULT;
86+
return {STATUS_BADCONF, errmsg};
8287
}
88+
8389
cur_factory_ = plugin_driver->CreateFactory();
8490
if (cur_factory_ == nullptr) {
8591
MBLOG_ERROR << "Plugin : " << plugin_name << " factory create failed";
86-
return STATUS_FAULT;
92+
return {STATUS_FAULT, "decrypt driver create failed"};
8793
}
94+
8895
cur_plugin_ = std::dynamic_pointer_cast<IModelDecryptPlugin>(
8996
cur_factory_->GetDriver());
9097
if (cur_plugin_ == nullptr) {
9198
MBLOG_ERROR << "plugin : " << plugin_name
9299
<< " is not derived from IModelDecryptPlugin";
93-
return STATUS_FAULT;
100+
return {STATUS_FAULT, "decrypt driver create failed"};
94101
}
95102

96-
if (cur_plugin_->Init(model_path, config) == STATUS_SUCCESS) {
103+
auto ret = cur_plugin_->Init(model_path, config);
104+
if (ret == STATUS_SUCCESS) {
97105
model_state_ = MODEL_STATE_ENCRYPT;
98106
} else {
99107
MBLOG_ERROR << "drivers Init Error";
100-
return STATUS_FAULT;
108+
return ret;
101109
}
102110
} else {
103111
model_state_ = MODEL_STATE_PLAIN;
@@ -134,13 +142,15 @@ uint8_t* ModelDecryption::GetModelBuffer(int64_t& model_len) {
134142
model_len = 0;
135143
if (model_state_ == MODEL_STATE_ERROR) {
136144
MBLOG_ERROR << "model_state is error";
145+
modelbox::StatusError = {modelbox::STATUS_INVALID, "model_state is error"};
137146
return nullptr;
138147
}
139148

140149
// tensorflow TF_Buffer seems a c-style code, here use std::malloc
141150
uint8_t* model_buf = static_cast<uint8_t*>(malloc(fsize_));
142151
if (!model_buf) {
143152
MBLOG_ERROR << "memory alloc fail with size =." << fsize_;
153+
modelbox::StatusError = {modelbox::STATUS_NOMEM, "Read file fail."};
144154
return nullptr;
145155
}
146156

@@ -149,6 +159,7 @@ uint8_t* ModelDecryption::GetModelBuffer(int64_t& model_len) {
149159
if (fmodel_.gcount() != fsize_) {
150160
MBLOG_ERROR << "Read file fail.";
151161
free(model_buf);
162+
modelbox::StatusError = {modelbox::STATUS_INVALID, "Read file fail."};
152163
return nullptr;
153164
}
154165

@@ -163,6 +174,7 @@ uint8_t* ModelDecryption::GetModelBuffer(int64_t& model_len) {
163174
MBLOG_ERROR << "ModelDecrypt fail.";
164175
model_len = 0;
165176
free(plain_buf);
177+
modelbox::StatusError = {ret, "ModelDecrypt fail."};
166178
return nullptr;
167179
}
168180
model_len = plain_len;

src/drivers/inference_engine/mindspore/mindspore_inference.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ modelbox::Status MindSporeInference::CheckMindSporeIO(
129129
if (ret != modelbox::STATUS_OK) {
130130
auto err_msg = "check ms input failed " + ret.WrapErrormsgs();
131131
MBLOG_ERROR << err_msg;
132-
return {modelbox::STATUS_BADCONF, err_msg};
132+
return ret;
133133
}
134134

135135
auto output_tensor = model_->GetOutputs();
@@ -138,7 +138,7 @@ modelbox::Status MindSporeInference::CheckMindSporeIO(
138138
if (ret != modelbox::STATUS_OK) {
139139
auto err_msg = "check ms output failed " + ret.WrapErrormsgs();
140140
MBLOG_ERROR << err_msg;
141-
return {modelbox::STATUS_BADCONF, err_msg};
141+
return ret;
142142
}
143143

144144
return modelbox::STATUS_OK;
@@ -158,24 +158,25 @@ modelbox::Status MindSporeInference::Init(
158158
if (ret != modelbox::STATUS_OK) {
159159
auto err_msg = "get model type failed " + ret.WrapErrormsgs();
160160
MBLOG_ERROR << err_msg;
161-
return {modelbox::STATUS_BADCONF, err_msg};
161+
return ret;
162162
}
163163

164164
mindspore::Graph graph(nullptr);
165165
mindspore::Status ms_status{mindspore::kSuccess};
166166
ModelDecryption model_decrypt;
167-
if (modelbox::STATUS_SUCCESS !=
168-
model_decrypt.Init(model_entry, drivers_ptr, config)) {
169-
return {modelbox::STATUS_FAULT, "init model fail"};
167+
ret = model_decrypt.Init(model_entry, drivers_ptr, config);
168+
if (ret != modelbox::STATUS_SUCCESS) {
169+
return {ret, "init model fail"};
170170
}
171171

172172
if (model_decrypt.GetModelState() == ModelDecryption::MODEL_STATE_ENCRYPT) {
173173
int64_t model_len = 0;
174174
std::shared_ptr<uint8_t> modelBuf =
175175
model_decrypt.GetModelSharedBuffer(model_len);
176176
if (!modelBuf) {
177-
return {modelbox::STATUS_FAULT, "Decrypt model fail"};
177+
return {modelbox::StatusError, "Decrypt model fail"};
178178
}
179+
179180
ms_status = mindspore::Serialization::Load((const void *)modelBuf.get(),
180181
(size_t)model_len,
181182
mindspore_type, &graph);

src/libmodelbox/engine/graph.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ Status Graph::OpenNodes() {
749749

750750
auto ret = fut.get();
751751
if (!ret) {
752-
return Status(ret, msg);
752+
return ret;
753753
}
754754
}
755755

src/modelbox/server/plugin/tasks/modelbox_plugin.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ void ModelboxPlugin::HandlerPut(const httplib::Request& request,
398398
if (modelbox::JobStatus::JOB_STATUS_NOTEXIST !=
399399
jobmanager_.QueryJobStatus(jobid)) {
400400
error_code = "MODELBOX_005";
401-
error_msg = ERROR_INFO[error_code];
402401
return;
403402
}
404403

0 commit comments

Comments
 (0)