1
1
#include < fstream>
2
+ #include " serving/processor/serving/message_coding.h"
2
3
#include " serving/processor/serving/model_instance.h"
3
4
#include " serving/processor/serving/model_partition.h"
4
5
#include " serving/processor/serving/model_session.h"
@@ -24,6 +25,7 @@ namespace processor {
24
25
namespace {
25
26
constexpr int _60_Seconds = 60 ;
26
27
constexpr int MAX_TRY_COUNT = 10 ;
28
+ constexpr int WARMUP_COUNT = 5 ;
27
29
28
30
Tensor CreateTensor (const TensorInfo& tensor_info) {
29
31
auto real_ts = tensor_info.tensor_shape ();
@@ -71,44 +73,35 @@ Tensor CreateTensor(const TensorInfo& tensor_info) {
71
73
return tensor;
72
74
}
73
75
74
- Call CreateWarmupParams (SignatureDef& sig_def) {
75
- Call call;
76
+ Status CreateWarmupParams (SignatureDef& sig_def, Call* call) {
76
77
for (auto it : sig_def.inputs ()) {
77
78
const auto & tensor = CreateTensor (it.second );
78
- call. request .inputs .emplace_back (it.second .name (), tensor);
79
+ call-> request .inputs .emplace_back (it.second .name (), tensor);
79
80
}
80
81
81
82
for (auto it : sig_def.outputs ()) {
82
- call. request .output_tensor_names .emplace_back (it.second .name ());
83
+ call-> request .output_tensor_names .emplace_back (it.second .name ());
83
84
}
84
85
85
- return call;
86
+ return Status::OK ();
86
87
}
87
88
88
- Call CreateWarmupParams (SignatureDef& sig_def,
89
- const std::string& warmup_file_name) {
89
+ Status CreateWarmupParams (SignatureDef& sig_def,
90
+ const std::string& warmup_file_name,
91
+ Call* call, IParser* parser,
92
+ const SignatureInfo& signature_info) {
90
93
// Parse warmup file
91
94
eas::PredictRequest request;
92
95
std::fstream input (warmup_file_name, std::ios::in | std::ios::binary);
93
- request.ParseFromIstream (&input);
94
- input.close ();
95
-
96
- Call call;
97
- for (auto & input : request.inputs ()) {
98
- call.request .inputs .emplace_back (input.first ,
99
- util::Proto2Tensor (input.second ));
100
- }
101
-
102
- call.request .output_tensor_names =
103
- std::vector<std::string>(request.output_filter ().begin (),
104
- request.output_filter ().end ());
105
-
106
- // User need to set fetches
107
- if (call.request .output_tensor_names .size () == 0 ) {
108
- LOG (FATAL) << " warmup file must be contain fetches." ;
96
+ bool success = request.ParseFromIstream (&input);
97
+ if (!success) {
98
+ LOG (ERROR) << " Read warmp file failed: " << warmup_file_name;
99
+ return Status (error::Code::INTERNAL,
100
+ " Read warmp file failed, please check warmp file path" );
109
101
}
102
+ input.close ();
110
103
111
- return call;
104
+ return parser-> ParseRequest (request, &signature_info, * call);
112
105
}
113
106
114
107
bool ShouldWarmup (SignatureDef& sig_def) {
@@ -264,6 +257,7 @@ Status LocalSessionInstance::Init(ModelConfig* config,
264
257
{kSavedModelTagServe }, &meta_graph_def_));
265
258
266
259
warmup_file_name_ = config->warmup_file_name ;
260
+ parser_ = ParserFactory::GetInstance (config->serialize_protocol , 4 );
267
261
268
262
GraphOptimizerOption option;
269
263
option.native_tf_mode = true ;
@@ -352,21 +346,38 @@ Status LocalSessionInstance::Warmup(
352
346
return Status::OK ();
353
347
}
354
348
349
+ LOG (INFO) << " Try to warmup model: " << warmup_file_name_;
350
+ Status s;
355
351
Call call;
356
352
if (warmup_file_name_.empty ()) {
357
- call = CreateWarmupParams (model_signature_.second );
353
+ s = CreateWarmupParams (model_signature_.second , &call );
358
354
} else {
359
- call = CreateWarmupParams (model_signature_.second ,
360
- warmup_file_name_);
355
+ s = CreateWarmupParams (model_signature_.second ,
356
+ warmup_file_name_, &call,
357
+ parser_, signature_info_);
358
+ }
359
+ if (!s.ok ()) {
360
+ LOG (ERROR) << " Create warmup params failed, warmup will be canceled." ;
361
+ return s;
361
362
}
362
363
363
- if (warmup_session) {
364
- return warmup_session->LocalPredict (
365
- call.request , call.response );
364
+ int left_try_count = WARMUP_COUNT;
365
+ while (left_try_count > 0 ) {
366
+ if (warmup_session) {
367
+ s = warmup_session->LocalPredict (
368
+ call.request , call.response );
369
+ } else {
370
+ s = session_mgr_->LocalPredict (
371
+ call.request , call.response );
372
+ }
373
+ if (!s.ok ()) return s;
374
+
375
+ --left_try_count;
376
+ call.response .outputs .clear ();
366
377
}
378
+ LOG (INFO) << " Warmup model successful: " << warmup_file_name_;
367
379
368
- return session_mgr_->LocalPredict (
369
- call.request , call.response );
380
+ return Status::OK ();
370
381
}
371
382
372
383
std::string LocalSessionInstance::DebugString () {
@@ -474,6 +485,7 @@ Status RemoteSessionInstance::Init(ModelConfig* model_config,
474
485
backup_storage_ = new FeatureStoreMgr (&backup_model_config);
475
486
476
487
warmup_file_name_ = model_config->warmup_file_name ;
488
+ parser_ = ParserFactory::GetInstance (model_config->serialize_protocol , 4 );
477
489
478
490
// set active flag
479
491
serving_storage_->SetStorageActiveStatus (active);
@@ -534,21 +546,36 @@ Status RemoteSessionInstance::Warmup(
534
546
return Status::OK ();
535
547
}
536
548
549
+ Status s;
537
550
Call call;
538
551
if (warmup_file_name_.empty ()) {
539
- call = CreateWarmupParams (model_signature_.second );
552
+ s = CreateWarmupParams (model_signature_.second , &call );
540
553
} else {
541
- call = CreateWarmupParams (model_signature_.second ,
542
- warmup_file_name_);
554
+ s = CreateWarmupParams (model_signature_.second ,
555
+ warmup_file_name_, &call,
556
+ parser_, signature_info_);
557
+ }
558
+ if (!s.ok ()) {
559
+ LOG (ERROR) << " Create warmup params failed, warmup will be canceled." ;
560
+ return s;
543
561
}
544
562
545
- if (warmup_session) {
546
- return warmup_session->Predict (
547
- call.request , call.response );
563
+ int left_try_count = WARMUP_COUNT;
564
+ while (left_try_count > 0 ) {
565
+ if (warmup_session) {
566
+ s = warmup_session->LocalPredict (
567
+ call.request , call.response );
568
+ } else {
569
+ s = session_mgr_->LocalPredict (
570
+ call.request , call.response );
571
+ }
572
+ if (!s.ok ()) return s;
573
+
574
+ --left_try_count;
575
+ call.response .outputs .clear ();
548
576
}
549
577
550
- return session_mgr_->Predict (
551
- call.request , call.response );
578
+ return Status::OK ();
552
579
}
553
580
554
581
Status RemoteSessionInstance::FullModelUpdate (
0 commit comments