-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathensemble_tests.cpp
6409 lines (5578 loc) · 269 KB
/
ensemble_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//*****************************************************************************
// Copyright 2020 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include <cstdio>
#include <memory>
#include <optional>
#include <sstream>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <stdlib.h>
#include "../tfs_frontend/tfs_request_utils.hpp"
#include "../tfs_frontend/tfs_utils.hpp"
#include "../kfs_frontend/kfs_utils.hpp"
#include "../deserialization_main.hpp"
#include "../dags/dl_node.hpp"
#include "../dags/entry_node.hpp"
#include "../dags/exit_node.hpp"
#include "../dags/nodestreamidguard.hpp"
#include "../dags/pipeline.hpp"
#include "../dags/pipeline_factory.hpp"
#include "../dags/pipelinedefinition.hpp"
#include "../tfs_frontend/deserialization.hpp"
#include "../inference_executor.hpp"
#include "../localfilesystem.hpp"
#include "../logging.hpp"
#include "../metric_registry.hpp"
#include "../model_metric_reporter.hpp"
#include "../modelconfig.hpp"
#include "../modelinstance.hpp"
#include "../status.hpp"
#include "../tensor_conversion.hpp"
#include "../timer.hpp"
#include "test_utils.hpp"
using namespace ovms;
using namespace tensorflow;
using namespace tensorflow::serving;
using testing::_;
using testing::Return;
using ::testing::ElementsAre;
const uint32_t NIREQ = 2;
template <typename Pair,
typename RequestType = typename Pair::first_type,
typename ResponseType = typename Pair::second_type>
class EnsembleFlowBothApiTest : public TestWithTempDir {
public:
void SetUp() override {
TestWithTempDir::SetUp();
// Prepare manager
config = DUMMY_MODEL_CONFIG;
config.setNireq(NIREQ);
reporter = std::make_unique<ModelMetricReporter>(&this->metricConfig, &this->registry, "example_pipeline_name", 1);
// Prepare request
prepareRequest(bs1requestData, request, customPipelineInputName);
requestData = bs1requestData;
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
}
void prepareRequest(const std::vector<float>& requestData, TFSRequestType& request, const std::string& customPipelineInputName, const ovms::signed_shape_t& shape = {1, DUMMY_MODEL_INPUT_SIZE}) {
request.Clear();
preparePredictRequest(request, inputs_info_t{{customPipelineInputName, {shape, ovms::Precision::FP32}}}, requestData);
}
void prepareRequest(const std::vector<float>& requestData, KFSRequest& request, const std::string& customPipelineInputName, const ovms::signed_shape_t& shape = {1, DUMMY_MODEL_INPUT_SIZE}) {
request.Clear();
prepareKFSInferInputTensor(request, customPipelineInputName, std::make_tuple(shape, ovmsPrecisionToKFSPrecision(ovms::Precision::FP32)), requestData);
}
void checkDummyResponse(int seriesLength, int batchSize = 1, const std::string& servableName = "") {
::checkDummyResponse(customPipelineOutputName, requestData, request, response, seriesLength, batchSize, servableName);
}
void checkScalarResponse(float inputScalar, const std::string& pipelineName) {
::checkScalarResponse(customPipelineOutputName, inputScalar, response, pipelineName);
}
void checkStringResponse(const std::vector<std::string>& inputStrings, const std::string& pipelineName) {
::checkStringResponse(customPipelineOutputName, inputStrings, response, pipelineName);
}
ModelConfig config;
RequestType request;
ResponseType response;
MetricRegistry registry;
MetricConfig metricConfig;
std::unique_ptr<ModelMetricReporter> reporter;
std::string dummyModelName = "dummy";
std::optional<model_version_t> requestedModelVersion{std::nullopt};
const std::string customPipelineInputName = "custom_dummy_input";
const std::string customPipelineOutputName = "custom_dummy_output";
std::shared_ptr<const ovms::TensorInfo> dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
std::shared_ptr<const ovms::TensorInfo> dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
std::vector<float> requestData;
const std::vector<float> bs1requestData{-5.0, 3.0, 0.0, -12.0, 9.0, -100.0, 102.0, 92.0, -1.0, 12.0};
};
// New test suite. Tests both - TFS and KFS.
// Currently only tests which contain gather in exit node.
using MyTypes = ::testing::Types<TFSInterface, KFSInterface>;
TYPED_TEST_SUITE(EnsembleFlowBothApiTest, MyTypes);
// Old test suite. Tests only TFS API.
class EnsembleFlowTest : public TestWithTempDir {
protected:
void SetUp() override {
TestWithTempDir::SetUp();
// Prepare manager
config = DUMMY_MODEL_CONFIG;
config.setNireq(NIREQ);
reporter = std::make_unique<ModelMetricReporter>(&this->metricConfig, &this->registry, "example_pipeline_name", 1);
// Prepare request
prepareRequest(bs1requestData, request, customPipelineInputName);
requestData = bs1requestData;
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
}
void prepareRequest(const std::vector<float>& requestData, PredictRequest& request, const std::string& customPipelineInputName) {
request.Clear();
tensorflow::TensorProto& proto = (*request.mutable_inputs())[customPipelineInputName];
proto.set_dtype(tensorflow::DataType::DT_FLOAT);
proto.mutable_tensor_content()->assign((char*)requestData.data(), requestData.size() * sizeof(float));
proto.mutable_tensor_shape()->add_dim()->set_size(1);
proto.mutable_tensor_shape()->add_dim()->set_size(DUMMY_MODEL_INPUT_SIZE);
}
void prepareRequest(const std::vector<float>& requestData, PredictRequest& request, const std::string& customPipelineInputName, const std::vector<size_t>& shape) {
request.Clear();
tensorflow::TensorProto& proto = (*request.mutable_inputs())[customPipelineInputName];
proto.set_dtype(tensorflow::DataType::DT_FLOAT);
proto.mutable_tensor_content()->assign((char*)requestData.data(), requestData.size() * sizeof(float));
for (size_t i = 0; i < shape.size(); i++) {
proto.mutable_tensor_shape()->add_dim()->set_size(shape[i]);
}
}
void prepareBinaryRequest(const std::string& jpegPath, PredictRequest& request, const std::string& customPipelineInputName, int batchSize = 1) {
size_t filesize;
std::unique_ptr<char[]> image_bytes;
readImage(jpegPath, filesize, image_bytes);
request.Clear();
tensorflow::TensorProto& inputProto = (*request.mutable_inputs())[customPipelineInputName];
inputProto.set_dtype(tensorflow::DataType::DT_STRING);
for (int i = 0; i < batchSize; i++) {
inputProto.add_string_val(image_bytes.get(), filesize);
}
inputProto.mutable_tensor_shape()->add_dim()->set_size(batchSize);
}
void prepareMisalignedBinaryImageRequest(const std::string& image1, const std::string& image2, PredictRequest& request, const std::string& customPipelineInputName) {
request.Clear();
tensorflow::TensorProto& inputProto = (*request.mutable_inputs())[customPipelineInputName];
inputProto.set_dtype(tensorflow::DataType::DT_STRING);
size_t filesize;
std::unique_ptr<char[]> image_bytes;
readImage(image1, filesize, image_bytes);
inputProto.add_string_val(image_bytes.get(), filesize);
readImage(image2, filesize, image_bytes);
inputProto.add_string_val(image_bytes.get(), filesize);
inputProto.mutable_tensor_shape()->add_dim()->set_size(2);
}
void checkDummyResponse(int seriesLength, int batchSize = 1) {
::checkDummyResponse(customPipelineOutputName, requestData, request, response, seriesLength, batchSize);
}
void performWrongPipelineConfigTest(const char* configFileContent) {
std::string fileToReload = directoryPath + "/ovms_config_file1.json";
createConfigFileWithContent(adjustConfigForTargetPlatformCStr(configFileContent), fileToReload);
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.loadConfig(fileToReload);
std::unique_ptr<Pipeline> pipeline;
auto status = managerWithDummyModel.createPipeline(pipeline,
"pipeline1Dummy",
&request,
&response);
ASSERT_EQ(status, ovms::StatusCode::PIPELINE_DEFINITION_NAME_MISSING) << status.string();
}
ModelConfig config;
PredictRequest request;
PredictResponse response;
MetricRegistry registry;
MetricConfig metricConfig;
std::unique_ptr<ModelMetricReporter> reporter;
std::string dummyModelName = "dummy";
std::optional<model_version_t> requestedModelVersion{std::nullopt};
const std::string customPipelineInputName = "custom_dummy_input";
const std::string customPipelineOutputName = "custom_dummy_output";
std::shared_ptr<const ovms::TensorInfo> dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
std::shared_ptr<const ovms::TensorInfo> dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
DUMMY_MODEL_SHAPE_META,
Layout{"NC"});
std::vector<float> requestData;
const std::vector<float> bs1requestData{-5.0, 3.0, 0.0, -12.0, 9.0, -100.0, 102.0, 92.0, -1.0, 12.0};
};
TYPED_TEST(EnsembleFlowBothApiTest, DummyModel) {
// Most basic configuration, just process single dummy model request
// input dummy output
// O------->O------->O
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(this->config);
// Configure pipeline
const tensor_map_t inputsInfo{{this->customPipelineInputName, this->dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node = std::make_unique<DLNode>("dummy_node", this->dummyModelName, this->requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName, this->dagDummyModelOutputTensorInfo}};
std::set<std::string> gatherFromNode = {};
std::string pipelineName = "test_pipeline";
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo, gatherFromNode, true, pipelineName);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node, {{this->customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
const int dummySeriallyConnectedCount = 1;
this->checkDummyResponse(dummySeriallyConnectedCount, 1, pipelineName);
}
TYPED_TEST(EnsembleFlowBothApiTest, NativeStringModel) {
// Most basic configuration, just process single passthrough string model request
// input passthrough output
// O---------->O---------->O
ConstructorEnabledModelManager managerWithStringModel;
this->config = NATIVE_STRING_MODEL_CONFIG;
this->config.setBatchingParams("");
ASSERT_EQ(managerWithStringModel.reloadModelWithVersions(this->config), ovms::StatusCode::OK_RELOADED);
// Configure pipeline
this->dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineInputName,
ovms::Precision::STRING,
ovms::Shape{-1},
Layout{"N..."});
this->dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineOutputName,
ovms::Precision::STRING,
ovms::Shape{-1},
Layout{"N..."});
const tensor_map_t inputsInfo{{this->customPipelineInputName, this->dagDummyModelInputTensorInfo}};
std::vector<std::string> inputStrings = {"ala", "", "ma", "kota"};
this->request.Clear();
prepareInferStringRequest(this->request, this->customPipelineInputName, inputStrings);
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node = std::make_unique<DLNode>("string_node", "passthrough_string", this->requestedModelVersion, managerWithStringModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName, this->dagDummyModelOutputTensorInfo}};
std::set<std::string> gatherFromNode = {};
std::string pipelineName = "test_pipeline";
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo, gatherFromNode, true, pipelineName);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node, {{this->customPipelineInputName, PASSTHROUGH_STRING_MODEL_INPUT_NAME}});
pipeline.connect(*model_node, *output_node, {{PASSTHROUGH_STRING_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
this->checkStringResponse(inputStrings, pipelineName);
}
TYPED_TEST(EnsembleFlowBothApiTest, ScalarModel) {
// Most basic configuration, just process single scalar model request
// input scalar output
// O------->O------->O
ConstructorEnabledModelManager managerWithScalarModel;
this->config = SCALAR_MODEL_CONFIG;
managerWithScalarModel.reloadModelWithVersions(this->config);
float inputData = 5.4f;
this->prepareRequest(std::vector<float>{inputData}, this->request, this->customPipelineInputName, ovms::signed_shape_t{});
// Configure pipeline
const tensor_map_t inputsInfo{{this->customPipelineInputName,
std::make_shared<ovms::TensorInfo>(
this->customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{}, Layout{"..."})}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node = std::make_unique<DLNode>("scalar_node", "scalar", this->requestedModelVersion, managerWithScalarModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName,
std::make_shared<ovms::TensorInfo>(
this->customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{}, Layout{"..."})}};
std::set<std::string> gatherFromNode = {};
std::string pipelineName = "test_pipeline";
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo, gatherFromNode, true, pipelineName);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node, {{this->customPipelineInputName, SCALAR_MODEL_INPUT_NAME}});
pipeline.connect(*model_node, *output_node, {{SCALAR_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
this->checkScalarResponse(inputData, pipelineName);
}
TYPED_TEST(EnsembleFlowBothApiTest, SequenceOfDynamicDummyInferZeroBatch) {
// input 3x dynamic dummy output
// ===[0,10]===>O----------->O->O->O-------->O=====[0,10]===>
ConstructorEnabledModelManager managerWithDummyModel;
this->config = DUMMY_MODEL_CONFIG;
this->config.setBatchingParams("-1");
managerWithDummyModel.reloadModelWithVersions(this->config);
int batchSize = 0;
std::vector<float> inputData; // no data (0,10)
this->prepareRequest(inputData, this->request, this->customPipelineInputName, ovms::signed_shape_t{batchSize, 10});
// Configure pipeline
const tensor_map_t inputsInfo{{this->customPipelineInputName,
std::make_shared<ovms::TensorInfo>(
this->customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{-1, 10}, Layout{"..."})}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node1 = std::make_unique<DLNode>("dummy_node_1", "dummy", this->requestedModelVersion, managerWithDummyModel);
auto model_node2 = std::make_unique<DLNode>("dummy_node_2", "dummy", this->requestedModelVersion, managerWithDummyModel);
auto model_node3 = std::make_unique<DLNode>("dummy_node_3", "dummy", this->requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName,
std::make_shared<ovms::TensorInfo>(
this->customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{-1, 10}, Layout{"..."})}};
std::set<std::string> gatherFromNode = {};
std::string pipelineName = "test_pipeline";
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo, gatherFromNode, true, pipelineName);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node1, {{this->customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node1, *model_node2, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node2, *model_node3, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node3, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node1));
pipeline.push(std::move(model_node2));
pipeline.push(std::move(model_node3));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
int series = 3;
this->checkDummyResponse(series, batchSize, pipelineName);
}
TYPED_TEST(EnsembleFlowBothApiTest, TwoInnerNodesConnectedShapeRangePartiallyMatching) {
ConstructorEnabledModelManager managerWithDummyModel;
this->config = DUMMY_MODEL_CONFIG;
this->config.setName("dummy_A");
this->config.setBatchSize(std::nullopt);
this->config.parseShapeParameter("(-1,1:3)");
managerWithDummyModel.reloadModelWithVersions(this->config);
this->config = DUMMY_MODEL_CONFIG;
this->config.setName("dummy_B");
this->config.setBatchSize(std::nullopt);
this->config.parseShapeParameter("(-1,2:4)");
managerWithDummyModel.reloadModelWithVersions(this->config);
// Configure pipeline
this->dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{Dimension::any(), {1, 3}},
Layout{"NC"});
this->dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{Dimension::any(), {2, 4}},
Layout{"NC"});
// 2x2 passing
{
this->prepareRequest(std::vector<float>{5.0, 6.0, 15.0, 16.0}, this->request, this->customPipelineInputName, {2, 2});
this->response.Clear();
const tensor_map_t inputsInfo{{this->customPipelineInputName, this->dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node_A = std::make_unique<DLNode>("dummy_node_A", "dummy_A", this->requestedModelVersion, managerWithDummyModel);
auto model_node_B = std::make_unique<DLNode>("dummy_node_B", "dummy_B", this->requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName, this->dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node_A, {{this->customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_A, *model_node_B, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_B, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node_A));
pipeline.push(std::move(model_node_B));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
checkIncrement4DimResponse<float>(this->customPipelineOutputName, std::vector<float>{7.0, 8.0, 17.0, 18.0}, this->response, {2, 2});
}
// 2x4 not passing due to not matched dummy_A (but matching dummy_B)
{
this->prepareRequest(std::vector<float>{5.0, 6.0, 15.0, 16.0, 5.0, 6.0, 15.0, 16.0}, this->request, this->customPipelineInputName, {2, 4});
this->response.Clear();
const tensor_map_t inputsInfo{{this->customPipelineInputName, this->dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node_A = std::make_unique<DLNode>("dummy_node_A", "dummy_A", this->requestedModelVersion, managerWithDummyModel);
auto model_node_B = std::make_unique<DLNode>("dummy_node_B", "dummy_B", this->requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName, this->dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node_A, {{this->customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_A, *model_node_B, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_B, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node_A));
pipeline.push(std::move(model_node_B));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
// 2x1 not passing due to not matched dummy_B (but matching dummy_A)
{
this->prepareRequest(std::vector<float>{5.0, 6.0}, this->request, this->customPipelineInputName, {2, 1});
this->response.Clear();
const tensor_map_t inputsInfo{{this->customPipelineInputName, this->dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<typename TypeParam::first_type>>(&this->request, inputsInfo);
auto model_node_A = std::make_unique<DLNode>("dummy_node_A", "dummy_A", this->requestedModelVersion, managerWithDummyModel);
auto model_node_B = std::make_unique<DLNode>("dummy_node_B", "dummy_B", this->requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{this->customPipelineOutputName, this->dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<typename TypeParam::second_type>>(&this->response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node_A, {{this->customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_A, *model_node_B, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_B, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, this->customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node_A));
pipeline.push(std::move(model_node_B));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
}
// This test is only theoretical scenario, since pipeline validation should not allow such pipelines.
TEST_F(EnsembleFlowTest, TwoInnerNodesConnectedShapeRangeNotMatching) {
ConstructorEnabledModelManager managerWithDummyModel;
config = DUMMY_MODEL_CONFIG;
config.setName("dummy_A");
config.setBatchSize(std::nullopt);
config.parseShapeParameter("(-1,1:3)");
managerWithDummyModel.reloadModelWithVersions(config);
config = DUMMY_MODEL_CONFIG;
config.setName("dummy_B");
config.setBatchSize(std::nullopt);
config.parseShapeParameter("(-1,4:6)");
managerWithDummyModel.reloadModelWithVersions(config);
// Configure pipeline
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{Dimension::any(), {1, 3}},
Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{Dimension::any(), {4, 6}},
Layout{"NC"});
// 2x2 not matching dummy_B at execution time
prepareRequest(std::vector<float>{5.0, 6.0, 15.0, 16.0}, request, customPipelineInputName, {2, 2});
response.Clear();
const tensor_map_t inputsInfo{{customPipelineInputName, dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<PredictRequest>>(&request, inputsInfo);
auto model_node_A = std::make_unique<DLNode>("dummy_node_A", "dummy_A", requestedModelVersion, managerWithDummyModel);
auto model_node_B = std::make_unique<DLNode>("dummy_node_B", "dummy_B", requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{customPipelineOutputName, dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<PredictResponse>>(&response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node_A, {{customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_A, *model_node_B, {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node_B, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node_A));
pipeline.push(std::move(model_node_B));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
class EnsembleFlowValidationTest : public EnsembleFlowTest {
public:
std::unique_ptr<Pipeline> createDummyPipeline(ConstructorEnabledModelManager& managerWithDummyModel) {
const tensor_map_t inputsInfo{{customPipelineInputName, dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<PredictRequest>>(&request, inputsInfo);
auto model_node = std::make_unique<DLNode>("dummy_node", dummyModelName, requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{customPipelineOutputName, dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<PredictResponse>>(&response, outputsInfo);
auto pipeline = std::make_unique<Pipeline>(*input_node, *output_node, *this->reporter);
pipeline->connect(*input_node, *model_node, {{customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline->connect(*model_node, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, customPipelineOutputName}});
pipeline->push(std::move(input_node));
pipeline->push(std::move(model_node));
pipeline->push(std::move(output_node));
return pipeline;
}
};
TEST_F(EnsembleFlowValidationTest, DummyModelValid) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorNumberOfInputs) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())["input1"];
auto& proto2 = (*request.mutable_inputs())["input2"];
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_NO_OF_INPUTS);
proto1.Clear();
proto2.Clear();
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorMissingInput) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())["input1"];
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_MISSING_INPUT);
proto1.Clear();
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorShapeValueNegative) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(-10);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorBinaryInputWrongNumberOfShapeDimensions) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.set_dtype(tensorflow::DataType::DT_STRING);
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
// enforce the endpoint to be 4d to not fall into string handling
this->dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{1, 224, 224, 3},
ovms::Layout{"NHWC"});
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_NO_OF_SHAPE_DIMENSIONS);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorBinaryInputBatchSizeMismatch) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.set_dtype(tensorflow::DataType::DT_STRING);
proto1.mutable_tensor_shape()->add_dim()->set_size(2);
// enforce the endpoint to be 4d to not fall into string handling
this->dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(this->customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{1, 224, 224, 3},
ovms::Layout{"NHWC"});
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_BATCH_SIZE);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorPrecisionMismatch) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(10);
proto1.set_dtype(tensorflow::DataType::DT_INT32);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_PRECISION);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorInvalidNumberOfShapeDimensions) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(10);
proto1.mutable_tensor_shape()->add_dim()->set_size(3);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_NO_OF_SHAPE_DIMENSIONS);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorInvalidBatchSize) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(2);
proto1.mutable_tensor_shape()->add_dim()->set_size(10);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_BATCH_SIZE);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorInvalidShape) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(11);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
TEST_F(EnsembleFlowValidationTest, DummyModelProtoValidationErrorInvalidTensorContentSize) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.mutable_tensor_shape()->add_dim()->set_size(10);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
const std::vector<float> data{1.0f};
proto1.mutable_tensor_content()->assign((char*)data.data(), data.size() * sizeof(float));
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_CONTENT_SIZE);
}
class EnsembleFlowValidationShapeRangeTest : public EnsembleFlowValidationTest {
protected:
void SetUp() {
EnsembleFlowValidationTest::SetUp();
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{{1, 10}, {2, 11}},
Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{{1, 10}, {2, 11}},
Layout{"NC"});
config = DUMMY_MODEL_CONFIG;
config.setBatchingParams("");
config.parseShapeParameter("(1:10,2:11)");
}
};
TEST_F(EnsembleFlowValidationShapeRangeTest, DummyModelValid) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
}
TEST_F(EnsembleFlowValidationShapeRangeTest, DummyModelProtoValidationErrorInvalidBatchSize) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(11);
proto1.mutable_tensor_shape()->add_dim()->set_size(10);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_BATCH_SIZE);
}
TEST_F(EnsembleFlowValidationShapeRangeTest, DummyModelProtoValidationErrorInvalidShape) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
request.Clear();
auto& proto1 = (*request.mutable_inputs())[customPipelineInputName];
proto1.mutable_tensor_shape()->add_dim()->set_size(6);
proto1.mutable_tensor_shape()->add_dim()->set_size(1);
proto1.set_dtype(tensorflow::DataType::DT_FLOAT);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::INVALID_SHAPE);
}
class EnsembleFlowValidationShapeAnyTest : public EnsembleFlowValidationTest {
protected:
void SetUp() {
EnsembleFlowValidationTest::SetUp();
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName,
ovms::Precision::FP32,
ovms::Shape{ovms::Dimension::any(), ovms::Dimension::any()},
Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName,
ovms::Precision::FP32,
ovms::Shape{ovms::Dimension::any(), ovms::Dimension::any()},
Layout{"NC"});
config = DUMMY_MODEL_CONFIG;
config.setBatchingParams("");
config.parseShapeParameter("(-1,-1)");
}
};
TEST_F(EnsembleFlowValidationShapeAnyTest, DummyModelValid) {
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
auto pipeline = createDummyPipeline(managerWithDummyModel);
ASSERT_EQ(pipeline->execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
}
TEST_F(EnsembleFlowTest, DummyModelDirectAndPipelineInference) {
ConstructorEnabledModelManager managerWithDummyModel;
config.setNireq(1);
managerWithDummyModel.reloadModelWithVersions(config);
// Get dummy model instance
std::shared_ptr<ovms::ModelInstance> model;
std::unique_ptr<ovms::ModelInstanceUnloadGuard> unload_guard;
auto status = managerWithDummyModel.getModelInstance(dummyModelName, 0, model, unload_guard);
ASSERT_EQ(status, ovms::StatusCode::OK);
// Prepare request for dummy model directly
tensorflow::serving::PredictRequest simpleModelRequest;
preparePredictRequest(simpleModelRequest,
{{DUMMY_MODEL_INPUT_NAME,
std::tuple<ovms::signed_shape_t, ovms::Precision>{{1, 10}, ovms::Precision::FP32}}});
std::vector<float> requestData{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
auto& input = (*simpleModelRequest.mutable_inputs())[DUMMY_MODEL_INPUT_NAME];
input.mutable_tensor_content()->assign((char*)requestData.data(), requestData.size() * sizeof(float));
tensorflow::serving::PredictResponse simpleModelResponse;
// Do the inference directly on dummy model before inference on pipeline
ASSERT_EQ(ovms::infer(*model, &simpleModelRequest, &simpleModelResponse, unload_guard), ovms::StatusCode::OK);
ASSERT_EQ(simpleModelResponse.outputs().count(DUMMY_MODEL_OUTPUT_NAME), 1);
auto& output_tensor = (*simpleModelResponse.mutable_outputs())[DUMMY_MODEL_OUTPUT_NAME];
ASSERT_EQ(output_tensor.tensor_shape().dim_size(), 2);
EXPECT_EQ(output_tensor.tensor_shape().dim(0).size(), 1);
EXPECT_EQ(output_tensor.tensor_shape().dim(1).size(), 10);
std::vector<float> responseData = requestData;
std::for_each(responseData.begin(), responseData.end(), [](float& v) { v += 1.0; });
float* actual_output = (float*)output_tensor.tensor_content().data();
float* expected_output = responseData.data();
const int dataLengthToCheck = DUMMY_MODEL_OUTPUT_SIZE * sizeof(float);
EXPECT_EQ(0, std::memcmp(actual_output, expected_output, dataLengthToCheck))
<< readableError(expected_output, actual_output, dataLengthToCheck);
// Configure pipeline
const tensor_map_t inputsInfo{{customPipelineInputName, dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<PredictRequest>>(&request, inputsInfo);
auto model_node = std::make_unique<DLNode>("dummy_node", dummyModelName, requestedModelVersion, managerWithDummyModel);
const tensor_map_t outputsInfo{{customPipelineOutputName, dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<PredictResponse>>(&response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node, {{customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
const int dummySeriallyConnectedCount = 1;
checkDummyResponse(dummySeriallyConnectedCount);
// Do the inference directly on dummy model after inference on pipeline
ASSERT_EQ(ovms::infer(*model, &simpleModelRequest, &simpleModelResponse, unload_guard), ovms::StatusCode::OK);
ASSERT_EQ(simpleModelResponse.outputs().count(DUMMY_MODEL_OUTPUT_NAME), 1);
output_tensor = (*simpleModelResponse.mutable_outputs())[DUMMY_MODEL_OUTPUT_NAME];
ASSERT_EQ(output_tensor.tensor_shape().dim_size(), 2);
EXPECT_EQ(output_tensor.tensor_shape().dim(0).size(), 1);
EXPECT_EQ(output_tensor.tensor_shape().dim(1).size(), 10);
actual_output = (float*)output_tensor.tensor_content().data();
expected_output = responseData.data();
EXPECT_EQ(0, std::memcmp(actual_output, expected_output, dataLengthToCheck))
<< readableError(expected_output, actual_output, dataLengthToCheck);
}
TEST_F(EnsembleFlowTest, SeriesOfDummyModels) {
// Most basic configuration, just process single dummy model request
enum : unsigned int {
PREPARE,
EXECUTE,
COMPARE,
TIMER_END
};
Timer<TIMER_END> timer;
timer.start(PREPARE);
const int N = 100;
// input dummy x N output
// O------->O->O...O->O------->O
ConstructorEnabledModelManager managerWithDummyModel;
managerWithDummyModel.reloadModelWithVersions(config);
// Configure pipeline
const tensor_map_t inputsInfo{{customPipelineInputName, dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<PredictRequest>>(&request, inputsInfo);
const tensor_map_t outputsInfo{{customPipelineOutputName, dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<PredictResponse>>(&response, outputsInfo);
std::unique_ptr<DLNode> dummy_nodes[N];
for (int i = 0; i < N; i++) {
dummy_nodes[i] = std::make_unique<DLNode>("dummy_node_" + std::to_string(i), dummyModelName, requestedModelVersion, managerWithDummyModel);
}
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *(dummy_nodes[0]), {{customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*(dummy_nodes[N - 1]), *output_node, {{DUMMY_MODEL_OUTPUT_NAME, customPipelineOutputName}});
for (int i = 0; i < N - 1; i++) {
pipeline.connect(*(dummy_nodes[i]), *(dummy_nodes[i + 1]), {{DUMMY_MODEL_OUTPUT_NAME, DUMMY_MODEL_INPUT_NAME}});
}
pipeline.push(std::move(input_node));
pipeline.push(std::move(output_node));
for (auto& dummy_node : dummy_nodes) {
pipeline.push(std::move(dummy_node));
}
timer.stop(PREPARE);
timer.start(EXECUTE);
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
timer.stop(EXECUTE);
timer.start(COMPARE);
checkDummyResponse(N);
timer.stop(COMPARE);
std::cout << "prepare pipeline: " << timer.elapsed<std::chrono::microseconds>(PREPARE) / 1000 << "ms\n";
std::cout << "pipeline::execute: " << timer.elapsed<std::chrono::microseconds>(EXECUTE) / 1000 << "ms\n";
std::cout << "compare results: " << timer.elapsed<std::chrono::microseconds>(COMPARE) / 1000 << "ms\n";
}
TEST_F(EnsembleFlowTest, ExecutePipelineWithBatchSizeAny) {
// Scenario
// input(3x10) dummy(1x10), change batch size to any output(3x10)
// O-------------------------->O----------------------------->O
// input 3x10
// dummy is natively 1x10, batch size change to -1 (any)
// process dummy
// check if output is 3x10
tensorflow::TensorProto& proto = (*request.mutable_inputs())[customPipelineInputName];
const int batchSize = 3;
proto.mutable_tensor_shape()->mutable_dim(0)->set_size(batchSize);
requestData = {
-5, -4, -3, -2, -1, 1, 2, 3, 4, 5, // batch 1
-15, -14, -13, -12, -11, 11, 12, 13, 14, 15, // batch 2
-25, -24, -23, -22, -21, 21, 22, 23, 24, 25, // batch 3
};
proto.mutable_tensor_content()->assign((char*)requestData.data(), requestData.size() * sizeof(float));
config.setBatchingParams("-1");
ConstructorEnabledModelManager managerWithDynamicBatchDummyModel;
managerWithDynamicBatchDummyModel.reloadModelWithVersions(config);
// Configure pipeline
dagDummyModelOutputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineOutputName, ovms::Precision::FP32, ovms::Shape{ovms::Dimension::any(), 10}, Layout{"NC"});
dagDummyModelInputTensorInfo = std::make_shared<ovms::TensorInfo>(customPipelineInputName, ovms::Precision::FP32, ovms::Shape{ovms::Dimension::any(), 10}, Layout{"NC"});
const tensor_map_t inputsInfo{{customPipelineInputName, dagDummyModelInputTensorInfo}};
auto input_node = std::make_unique<EntryNode<PredictRequest>>(&request, inputsInfo);
auto model_node = std::make_unique<DLNode>("dummy_node", dummyModelName, requestedModelVersion, managerWithDynamicBatchDummyModel);
const tensor_map_t outputsInfo{{customPipelineOutputName, dagDummyModelOutputTensorInfo}};
auto output_node = std::make_unique<ExitNode<PredictResponse>>(&response, outputsInfo);
Pipeline pipeline(*input_node, *output_node, *this->reporter);
pipeline.connect(*input_node, *model_node, {{customPipelineInputName, DUMMY_MODEL_INPUT_NAME}});
pipeline.connect(*model_node, *output_node, {{DUMMY_MODEL_OUTPUT_NAME, customPipelineOutputName}});
pipeline.push(std::move(input_node));
pipeline.push(std::move(model_node));
pipeline.push(std::move(output_node));
ASSERT_EQ(pipeline.execute(DEFAULT_TEST_CONTEXT), StatusCode::OK);
const int seriallyConnectedDummyModels = 1;
checkDummyResponse(seriallyConnectedDummyModels, batchSize);
}
TEST_F(EnsembleFlowTest, ExecutePipelineWithBatchSizeRange) {
// Scenario
// input(3x10) dummy(1x10), change batch size to (1:5x10) output(3x10)
// O-------------------------->O------------------------------->O