-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
op_params.h
2351 lines (2077 loc) · 58.6 KB
/
op_params.h
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 (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// 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.
#pragma once
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "lite/api/paddle_place.h"
#include "lite/core/model/base/apis.h"
#include "lite/core/scope.h"
#include "lite/core/tensor.h"
#include "lite/core/types.h"
#include "lite/model_parser/cpp_desc.h"
#include "lite/utils/all.h"
/*
* This file contains all the argument parameter data structure for operators.
*/
namespace paddle {
namespace lite {
namespace operators {
struct ParamBase {};
using param_t = Any;
#define WITH_INT8_CONFIG \
bool enable_int8{false}; \
float input_scale{1.0f}; \
std::vector<float> weight_scale{}; \
float output_scale{1.0f}; \
int bit_length{8};
/// ----------------------- Functional operators ------------------------------
struct FeedParam : ParamBase {
std::vector<lite::Tensor>* feed_list{};
lite::Tensor* out{};
int col;
};
struct FetchParam : ParamBase {
const lite::Tensor* input{};
std::vector<lite::Tensor>* fetch_list{};
int col;
};
// Helper op for lite framework
struct IoCopyParam : ParamBase {
const lite::Tensor* x{nullptr};
const std::vector<lite::Tensor>* x_array{nullptr};
lite::Tensor* y{nullptr};
std::vector<lite::Tensor>* y_array{nullptr};
int process_type{0};
};
struct LayoutParam : ParamBase {
const lite::Tensor* x{};
lite::Tensor* y{};
int process_type{0};
};
struct CalibParam : ParamBase {
const lite::Tensor* input{};
lite::Tensor* output{};
float scale;
};
struct CalibInplaceParam : ParamBase {
lite::Tensor* input{};
lite::Tensor* output{};
float scale;
};
struct SubgraphParam : ParamBase {
std::vector<std::string> input_names{};
std::vector<std::string> output_names{};
std::vector<std::string> input_data_names{};
std::vector<std::string> output_data_names{};
std::vector<float> input_data_scales{};
std::vector<float> output_data_scales{};
int block_idx{-1};
std::shared_ptr<const cpp::ProgramDesc> program_desc{nullptr};
Scope* exec_scope{nullptr};
};
/// -------------------------- NN operators ------------------------------------
struct FcParam : ParamBase {
lite::Tensor* input{nullptr};
lite::Tensor* w{nullptr};
lite::Tensor* bias{nullptr};
lite::Tensor* Prelu_alpha{nullptr};
lite::Tensor* output{nullptr};
lite::DDim in_mat_dims;
// original dims of input weight
lite::DDim w_dims;
int in_num_col_dims{1};
std::string activation_type{""};
bool padding_weights{false};
std::string Prelu_mode{
"channel"}; // prelu param, can be "all", "channel" or "element"
std::string op_type{"mul"};
float alpha{6.f};
// for int8
WITH_INT8_CONFIG
};
struct SearchSeqFcParam : ParamBase {
lite::Tensor* x{nullptr};
lite::Tensor* w{nullptr};
lite::Tensor* b{nullptr};
lite::Tensor* out{nullptr};
int out_size;
};
// For Interpolate Op
struct InterpolateParam : ParamBase {
lite::Tensor* X{};
lite::Tensor* OutSize{};
lite::Tensor* Out{};
std::vector<const lite::Tensor*> SizeTensor;
lite::Tensor* Scale{};
float scale{0.f};
std::vector<float> scale_v{};
int out_h{-1};
int out_w{-1};
bool align_corners{true};
int align_mode{1};
bool version_2{false};
std::string interp_method{"Nearest"};
DataLayoutType data_layout{DATALAYOUT(kNCHW)};
};
// For Mul Op
struct MulParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* y{};
lite::Tensor* output{};
int x_num_col_dims{1};
int y_num_col_dims{1};
// for int8
WITH_INT8_CONFIG
};
struct MulGradParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* y{};
const lite::Tensor* output_grad{};
lite::Tensor* x_grad{};
lite::Tensor* y_grad{};
int x_num_col_dims{1};
int y_num_col_dims{1};
};
// For Stack Op
struct StackParam : ParamBase {
std::vector<lite::Tensor*> X;
lite::Tensor* Out{};
int axis{0};
};
// For Unstack Op
struct UnstackParam : ParamBase {
const lite::Tensor* X{nullptr};
std::vector<lite::Tensor*> Out{};
int axis{0};
int num{1};
};
// For Power Op
struct PowerParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
float scale{};
float shift{};
float power{};
};
// For Pow Op
struct PowParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
float factor{1.f};
};
// For Sign Op
struct SignParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
};
struct ShuffleChannelParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
int group;
};
// For Yolobox
struct YoloBoxParam : ParamBase {
lite::Tensor* X{};
lite::Tensor* ImgSize{};
lite::Tensor* Boxes{};
lite::Tensor* Scores{};
std::vector<int> anchors{};
int class_num{0};
float conf_thresh{0.f};
int downsample_ratio{0};
bool clip_bbox{true};
float scale_x_y{1.0f};
};
// For Scale Op
struct ScaleParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* output{};
float scale{1.f};
float bias{0.f};
bool bias_after_scale{true};
std::string activation_type{""};
bool fuse_relu{false};
float alpha{6.f};
bool fuse_scaleact{false};
float scale1{1.f};
float bias1{0.f};
};
// For Scatter OP
struct ScatterParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* indexs{};
lite::Tensor* updates{};
lite::Tensor* output{};
bool overwrite{true};
};
// For Softmax op
struct SoftmaxParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* output{};
int axis{-1};
bool eleminate_success{false};
};
// For LogSoftmax op
struct LogSoftmaxParam : ParamBase {
const lite::Tensor* x{};
lite::Tensor* output{};
int axis{-1};
};
// For Reshape and Reshape2 Op
struct ReshapeParam : ParamBase {
const lite::Tensor* x{};
std::vector<const lite::Tensor*> shape_tensor_vct{};
const lite::Tensor* shape_tensor{};
std::vector<int> shape_vct{};
lite::Tensor* output{};
lite::Tensor* xshape{};
bool inplace{false};
#ifdef LITE_WITH_METAL
std::vector<int> excepted_transpose_;
#endif
};
// For Concat op
struct ConcatParam : ParamBase {
std::vector<lite::Tensor*> x{};
lite::Tensor* output{};
int axis{0};
lite::Tensor* axis_tensor{};
};
/// ----------------------- activation operators ----------------------
struct ActivationParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
lite_api::ActivationType active_type{lite_api::ActivationType::kIndentity};
bool has_active{false};
float Leaky_relu_alpha{0.f}; // leaky_relu param
float Relu_clipped_coef{6.f}; // relu_clipped param
std::string Prelu_mode{
"channel"}; // prelu param, can be "all", "channel" or "element"
lite::Tensor* Prelu_alpha{}; // prelu param
float Swish_beta; // swish param
// hard_sigmoid param
float hard_sigmoid_slope{0.2f};
float hard_sigmoid_offset{0.5f};
// hard_swish param
float hard_swish_threshold{6.0f};
float hard_swish_scale{6.0f};
float hard_swish_offset{3.0f};
// swish param
float swish_scale{6.0f};
// thresholded_relu
float relu_threshold{1.0f};
// elu
float Elu_alpha{1.0f};
// relu6
float threshold{6.0f};
// gelu
bool gelu_approximate{false};
// softplus
float softplus_beta{1.0f};
float softplus_threshold{20.f};
};
struct ActivationGradParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Out{};
// for backward
lite::Tensor* X_grad{};
const lite::Tensor* Out_grad{};
};
// For Sparse Convolution op
struct SparseConvParam : ParamBase {
const lite::Tensor* x{};
// An array of float values storing non-zero kernel elements
lite::Tensor* nonzero_weights{};
/* An array of int32_t values storing scaled
* [by sizeof(input element)] difference between input channels
* corresponding to successive non-zero element
*/
lite::Tensor* diffs{};
// the number of non-zero kernel elements per each output channel
lite::Tensor* oc_nonzeros{};
lite::Tensor* bias{nullptr};
lite::Tensor* output{};
int first_ic{0};
int flag_semi{0};
std::vector<int> strides{1, 1};
std::shared_ptr<std::vector<int>> paddings;
int groups{1};
std::shared_ptr<std::vector<int>> dilations;
// for activation
bool fuse_relu{false};
ActivationParam activation_param;
bool enable_int8{false};
float input_scale{1.0f};
std::vector<float> weight_scale{};
float output_scale{1.0f};
int bit_length{8};
};
// For Convolution op
struct ConvParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* filter{};
lite::Tensor* bias{nullptr};
lite::Tensor* residualData{nullptr};
lite::Tensor* second_x{nullptr};
lite::Tensor* output{};
std::vector<int> strides{1, 1};
/* paddings type change
* from std::vector<int> to std::shared_ptr<std::vector<int>>
* to support dynamically modify padding
* let kernel param and operator param Synchronous update
*/
std::shared_ptr<std::vector<int>> paddings;
int groups{1};
/* dilations type change
* from std::vector<int> to std::shared_ptr<std::vector<int>>
* to support dynamically modify padding
* let kernel param and operator param Synchronous update
*/
std::shared_ptr<std::vector<int>> dilations;
bool fuse_relu_before_depthwise_conv{false};
bool use_mkldnn{false};
bool fuse_relu{false}; // only used in mkldnn kernel
bool fuse_sigmoid{false};
bool fuse_tanh{false};
bool fuse_swish{false};
bool fuse_exp{false};
bool fuse_abs{false};
bool use_quantizer{
false}; // set true for op that should be quantized, only used for cpu
bool fuse_residual_connection{false};
float scale_in{1.0f}; // only used with mkl-dnn int8
float scale_out{1.0f}; // only used with mkl-dnn int8
float scale_in_eltwise{1.0f}; // only used with mkl-dnn int8
float scale_weights{1.0f}; // only used with mkl-dnn int8
bool force_fp32_output{false}; // only used in mkl-dnn int8
std::string data_format{"Anylayout"};
// for activation
ActivationParam activation_param;
// for elementwise tree fuse
std::string fuse_elementwise_op_type{""};
// support var_length or not
bool var_length{false};
// only used in conv_transpose.
std::vector<int> output_size;
std::vector<int> output_padding;
// for int8
WITH_INT8_CONFIG
// for Conv2d+Scale fusion
std::string scale_activation_type{""};
};
// For BatchNorm op
struct BatchNormParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* bias{};
lite::Tensor* scale{};
lite::Tensor* mean{};
lite::Tensor* variance{};
lite::Tensor* y{};
lite::Tensor* mean_out{};
lite::Tensor* variance_out{};
lite::Tensor* saved_mean{};
lite::Tensor* saved_variance{};
bool is_test{true};
bool use_global_stats{false};
float epsilon;
float momentum;
DataLayoutType data_layout{DATALAYOUT(kNCHW)};
};
// For Pooling op
struct PoolParam : ParamBase {
lite::Tensor* x{};
lite::Tensor* output{};
lite::Tensor* mask{};
std::string pooling_type{""};
std::vector<int> ksize{};
bool global_pooling{
false}; // if true, knernel size and paddings will be ignored
std::vector<int> strides{1, 1};
/* paddings type change
* from std::vector<int> to std::shared_ptr<std::vector<int>>
* to support dynamically modify padding
* let kernel param and operator param Synchronous update
*/
std::shared_ptr<std::vector<int>> paddings;
bool exclusive{true};
bool adaptive{false};
bool ceil_mode{false};
bool use_quantizer{false};
std::string padding_algorithm{"EXPLICIT"};
std::string data_format{"AnyLayout"};
// for int8
WITH_INT8_CONFIG
#ifdef LITE_WITH_XPU
bool pad_zero{false};
#endif
};
// For Dropout op
struct DropoutParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* seed_tensor{};
lite::Tensor* output{};
lite::Tensor* mask{};
float dropout_prob{.5f};
bool is_test{false};
bool fix_seed{false};
int seed{0};
std::string dropout_implementation{"downgrade_in_infer"};
};
// For PadConstantLike op
struct PadConstantLikeParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* y{};
lite::Tensor* output{};
float pad_value{0.0f};
};
// For Split op
struct SplitParam : ParamBase {
const lite::Tensor* x{nullptr};
std::vector<lite::Tensor*> output{};
const lite::Tensor* axis_tensor{nullptr};
std::vector<lite::Tensor*> sections_tensor_list{};
int axis{-1};
int num{0};
std::vector<int> sections;
};
struct UnbindParam : ParamBase {
lite::Tensor* x{};
std::vector<lite::Tensor*> output{};
int axis{-1};
};
// For Transpose op
struct TransposeParam : ParamBase {
const lite::Tensor* x{};
lite::Tensor* output{};
lite::Tensor* xshape{};
std::vector<int> axis;
bool use_mkldnn{false};
std::string data_format{"AnyLayout"};
};
struct TrilTriuParam : ParamBase {
const lite::Tensor* x{nullptr};
lite::Tensor* out{nullptr};
int diagonal{0};
bool lower{true};
};
/// ----------------------- element wise operators ----------------------
struct ElementwiseParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Y{};
lite::Tensor* Out{};
int axis{-1}; // for broadcasting.
// for int8
WITH_INT8_CONFIG
float x_input_scale{1.0f};
float y_input_scale{1.0f};
// fuse ScaleParam
bool fuse_scale{false};
float scale{1.f};
float bias{0.f};
bool bias_after_scale{true};
float alpha{6.f};
std::string activation_type{""};
};
struct ElementwiseGradParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Y{};
const lite::Tensor* OutGrad{};
lite::Tensor* XGrad{};
lite::Tensor* YGrad{};
int axis{-1}; // for broadcasting.
};
struct FusionElementwiseActivationParam : public ElementwiseParam {
std::string act_type;
};
struct FusionElementwiseActivationGradParam : public ElementwiseGradParam {
std::string act_type;
};
/// ----------------------- mean operators ----------------------
struct MeanParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
};
struct MeanGradParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Out_grad{};
// for backward
lite::Tensor* X_grad{};
};
struct FillAnyLikeParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
float value{0.0f};
int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
};
/// ----------------------- fill_constant operators ----------------------
struct FillConstantParam : ParamBase {
int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
std::vector<int64_t> shape{};
lite::Tensor* shape_tensor{nullptr};
lite::Tensor* value_tensor{nullptr};
std::vector<lite::Tensor*> shape_tensor_list{};
float value{0.0f};
// useless for x86, keep it for compatibility
bool force_cpu{false};
lite::Tensor* in{};
lite::Tensor* out{};
};
struct FillConstantBatchSizeLikeParam : ParamBase {
const lite::Tensor* input{nullptr};
lite::Tensor* out{nullptr};
std::vector<int> shape{};
int input_dim_idx{0};
int output_dim_idx{0};
int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
float value{0.0f};
// useless for x86, keep it for compatibility
bool force_cpu{false};
};
//
struct FakeQuantizeMovingAvgMaxAbsParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* in_scale{};
const lite::Tensor* in_accum{};
const lite::Tensor* in_state{};
lite::Tensor* out{};
lite::Tensor* out_scale{};
lite::Tensor* out_state{};
lite::Tensor* out_accum{};
int bit_length;
bool is_test{true};
float moving_rate{0.9f};
};
struct FakeDequantizeMaxAbsParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* in_scale{};
lite::Tensor* out{};
float max_range;
};
struct FakeChannelWiseDequantizeMaxAbsParam : ParamBase {
const lite::Tensor* x{};
std::vector<const lite::Tensor*> scale_tensors{};
lite::Tensor* out{};
std::vector<int> quant_bits;
};
struct FakeQuantDequantAbsMaxParam : ParamBase {
const lite::Tensor* x{};
lite::Tensor* out{};
lite::Tensor* out_scale{};
int bit_length;
};
struct FakeChannelWiseQuantDequantAbsMaxParam : ParamBase {
const lite::Tensor* x{};
lite::Tensor* out{};
lite::Tensor* out_scale{};
int quant_axis;
int bit_length;
};
struct QuantizeLinearParam : ParamBase {
const lite::Tensor* x{};
const lite::Tensor* scale{};
const lite::Tensor* zero_point{};
lite::Tensor* y{};
int quant_axis;
int bit_length;
};
struct QuantizeLogParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Dict{};
lite::Tensor* Out{};
};
/// ----------------------- sgd operators ----------------------
struct SGDParam : ParamBase {
int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
const lite::Tensor* Param{};
const lite::Tensor* LearningRate{};
const lite::Tensor* Grad{};
lite::Tensor* ParamOut{};
};
/// ----------------------- uniform_random operators ----------------------
struct UniformRandomParam : ParamBase {
const lite::Tensor* shape_tensor{nullptr};
std::vector<lite::Tensor*> shape_tensor_list{};
std::vector<int64_t> shape{};
float min{-1.0f};
float max{1.0f};
int seed{0};
int dtype{static_cast<int>(VarDescAPI::VarDataType::FP32)};
lite::Tensor* Out{};
};
/// ----------------------- unfold operators ----------------------
struct UnfoldParam : ParamBase {
const lite::Tensor* X{nullptr};
std::vector<int> kernel_sizes{};
std::vector<int> strides{};
std::vector<int> paddings{};
std::vector<int> dilations{};
lite::Tensor* Y{nullptr};
};
/// ----------------------- negative operators --------------
struct NegativeParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
};
/// ----------------------- pad2d operators ----------------------
struct Pad2dParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
std::vector<int> paddings{0, 0, 0, 0};
std::string mode{"constant"};
float pad_value = 0.f;
std::string data_format{"NCHW"};
};
/// ----------------------- Crop operators ----------------------
struct CropParam : ParamBase {
const lite::Tensor* X{nullptr};
const lite::Tensor* Y{nullptr};
const lite::Tensor* Offsets{nullptr};
lite::Tensor* Out{nullptr};
std::vector<int> offsets;
std::vector<int> shape;
};
/// ----------------------- CropTensor operators ----------------------
struct CropTensorParam : ParamBase {
const lite::Tensor* X{nullptr};
const lite::Tensor* Shape{nullptr};
const lite::Tensor* Offsets{nullptr};
const std::vector<lite::Tensor>* ShapeTensor{nullptr};
const std::vector<lite::Tensor>* OffsetsTensor{nullptr};
lite::Tensor* Out{nullptr};
std::vector<int> offsets;
std::vector<int> shape;
};
///----------------------- argmax operators ----------------------
struct ArgmaxParam : ParamBase {
lite::Tensor* X{};
lite::Tensor* Out{};
int Axis{0};
int dtype{-1};
bool keepdims{false};
};
///----------------------- inverse operators ----------------------
struct InverseParam : ParamBase {
lite::Tensor* Input{};
lite::Tensor* Output{};
};
///----------------------- index_select operators ----------------------
struct Index_selectParam : ParamBase {
lite::Tensor* X{};
lite::Tensor* Index{};
lite::Tensor* Out{};
int dim{0};
};
///----------------------- reverse operators ----------------------
struct ReverseParam : ParamBase {
lite::Tensor* X{};
lite::Tensor* Out{};
// for tensor_array
std::vector<lite::Tensor>* X_array{nullptr};
std::vector<lite::Tensor>* Out_array{nullptr};
std::vector<int> Axis;
};
///----------------------- axpy operators ----------------------
struct AxpyParam : ParamBase {
lite::Tensor* Scale{};
lite::Tensor* X{};
lite::Tensor* Bias{};
lite::Tensor* Out{};
};
/// ----------------------- GRU unit operators ----------------------f
struct GRUUnitParam : ParamBase {
enum ActType { identity, sigmoid, tanh, relu };
const lite::Tensor* input{nullptr};
const lite::Tensor* hidden_prev{nullptr};
const lite::Tensor* weight{nullptr};
const lite::Tensor* bias{nullptr};
lite::Tensor* gate{nullptr};
lite::Tensor* reset_hidden_prev{nullptr};
lite::Tensor* hidden{nullptr};
int gate_activation{ActType::sigmoid};
int activation{ActType::tanh};
bool origin_mode{false};
};
/// ------------------------------ lrn operators ------------------------------
struct LrnParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
int n{5};
float alpha{1e-4f};
float beta{0.75f};
float k{1.f};
std::string norm_region{"AcrossChannels"};
};
/// ----------------------- decode_bboxes operators ----------------------
struct DecodeBboxesParam : ParamBase {
const lite::Tensor* loc_data{};
const lite::Tensor* prior_data{};
lite::Tensor* bbox_data{};
int batch_num;
int num_priors;
int num_loc_classes{0};
int background_label_id{0};
bool share_location{true};
bool variance_encoded_in_target;
// code_type: corner, cente_size, corner_size
std::string code_type;
};
/// ----------------------- box_coder operators ----------------------
struct BoxCoderParam : ParamBase {
const lite::Tensor* prior_box{};
const lite::Tensor* prior_box_var{};
const lite::Tensor* target_box{};
lite::Tensor* proposals{};
// code_type: encode_center_size and decode_center_size
std::string code_type{"encode_center_size"};
bool box_normalized{true};
int axis{0};
std::vector<float> variance{};
};
/// ----------------------- multiclass_nms operators ----------------------
struct MulticlassNmsParam : ParamBase {
const lite::Tensor* bboxes{};
const lite::Tensor* scores{};
lite::Tensor* out{};
lite::Tensor* index{};
int background_label{0};
float score_threshold{};
int nms_top_k{};
float nms_threshold{0.3f};
float nms_eta{1.0f};
int keep_top_k;
bool normalized{true};
const lite::Tensor* rois_num{};
lite::Tensor* nms_rois_num{};
};
/// ----------------------- matrix_nms operators ----------------------
struct MatrixNmsParam : ParamBase {
const lite::Tensor* bboxes{};
const lite::Tensor* scores{};
lite::Tensor* out{};
lite::Tensor* index{};
lite::Tensor* rois_num{};
int background_label{0};
float score_threshold{};
float post_threshold{0.0f};
int nms_top_k{};
int keep_top_k;
bool normalized{true};
bool use_gaussian{false};
float gaussian_sigma{2.0f};
};
/// ----------------------- priorbox operators ----------------------
struct PriorBoxParam : ParamBase {
lite::Tensor* input{};
lite::Tensor* image{};
lite::Tensor* boxes{};
lite::Tensor* variances{};
bool flip{true};
bool clip{true};
std::vector<float> min_sizes;
std::vector<float> max_sizes;
std::vector<float> aspect_ratios;
std::vector<float> variances_;
int img_w{0};
int img_h{0};
float step_w{0.f};
float step_h{0.f};
float offset{0.5f};
int prior_num{0};
bool flatten_to_2d{false};
// priortype: prior_min, prior_max, prior_com
std::vector<std::string> order;
bool min_max_aspect_ratios_order{false};
};
struct DensityPriorBoxParam : public PriorBoxParam {
std::vector<float> fixed_sizes;
std::vector<float> fixed_ratios;
std::vector<int> density_sizes;
};
/// ----------------------- GRU operators ----------------------f
struct GRUParam : ParamBase {
const lite::Tensor* input{nullptr};
const lite::Tensor* h0{nullptr};
const lite::Tensor* weight{nullptr};
const lite::Tensor* bias{nullptr};
lite::Tensor* batch_gate{nullptr};
lite::Tensor* batch_reset_hidden_prev{nullptr};
lite::Tensor* batch_hidden{nullptr};
lite::Tensor* hidden{nullptr};
std::string gate_activation{"sigmoid"};
std::string activation{"tanh"};
bool is_reverse{false};
bool origin_mode{false};
// for int8
WITH_INT8_CONFIG
};
struct BiGRUParam : ParamBase {
const lite::Tensor* input{nullptr};
const lite::Tensor* fw_mul_w{nullptr};
const lite::Tensor* fw_mul_b{nullptr};
const lite::Tensor* fw_gru_w{nullptr};
const lite::Tensor* fw_gru_b{nullptr};
const lite::Tensor* bw_mul_w{nullptr};
const lite::Tensor* bw_mul_b{nullptr};
const lite::Tensor* bw_gru_w{nullptr};
const lite::Tensor* bw_gru_b{nullptr};
lite::Tensor* fw_output{nullptr};
lite::Tensor* bw_output{nullptr};
int fw_mul_x_num_col_dims{1};
int fw_mul_y_num_col_dims{1};
int bw_mul_x_num_col_dims{1};
int bw_mul_y_num_col_dims{1};
std::string fw_gru_gate_activation{"sigmoid"};
std::string fw_gru_activation{"tanh"};
std::string bw_gru_gate_activation{"sigmoid"};
std::string bw_gru_activation{"tanh"};
bool fw_gru_origin_mode{false};
bool bw_gru_origin_mode{false};
bool has_mul_b{false};
bool has_gru_b{false};
};
/// ----------------------- BeamSearchDecode operators ----------------------f
struct BeamSearchDecodeParam : ParamBase {
std::vector<lite::Tensor>* ids{nullptr};
std::vector<lite::Tensor>* scores{nullptr};
lite::Tensor* sentence_ids{nullptr};
lite::Tensor* sentence_scores{nullptr};
int beam_size;
int end_id;
};
/// ----------------------- LookupTable operators ----------------------f
struct LookupTableParam : ParamBase {
const lite::Tensor* W{nullptr};
const lite::Tensor* Ids{nullptr};
lite::Tensor* Out{nullptr};
int64_t padding_idx{-1};
bool is_test{true};
std::string entry_config{""}; // used in distributed training
std::string entry{"none"};
};
struct LookupTableDequantParam : ParamBase {
lite::Tensor* W{nullptr};
lite::Tensor* Ids{nullptr};
lite::Tensor* Out{nullptr};
int64_t padding_idx{-1};
};
struct Im2SequenceParam : ParamBase {
const lite::Tensor* X{};
const lite::Tensor* Y{};
lite::Tensor* Out{};
std::vector<int> kernels{3, 3};
std::vector<int> strides{1, 1};
std::vector<int> paddings{0, 0, 0, 0};
std::vector<int> out_strides{1, 1};
};
struct SequenceSoftmaxParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
};
struct NormParam : ParamBase {
const lite::Tensor* X{};
lite::Tensor* Out{};
lite::Tensor* Norm{};
int axis{1};
float epsilon{1e-10f};
};