Skip to content

Commit e342884

Browse files
authored
test directory modify mkldnn [fluid_ops] - part (#74458)
* Fix * Fix
1 parent 2cae1e4 commit e342884

File tree

58 files changed

+218
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+218
-185
lines changed

paddle/common/layout.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ inline DataLayout StringToDataLayout(const std::string& str) {
8585
return DataLayout::kAnyLayout;
8686
} else if (s == "MKLDNNLAYOUT") {
8787
return DataLayout::kMKLDNN;
88+
} else if (s == "ONEDNNLAYOUT") {
89+
return DataLayout::ONEDNN;
8890
} else if (s == "SPARSE_COO") {
8991
return DataLayout::SPARSE_COO;
9092
} else if (s == "SPARSE_CSR") {

paddle/fluid/framework/op_registry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ inline void RegisterKernelClass(const char* op_type,
170170
std::string library(library_type);
171171
std::string data_layout = "ANYLAYOUT";
172172
if (library == "MKLDNN") {
173-
data_layout = "MKLDNNLAYOUT";
173+
data_layout = "ONEDNNLAYOUT";
174174
}
175175
#ifdef PADDLE_WITH_CUSTOM_DEVICE
176176
if (std::is_same<PlaceType, phi::CustomPlace>::value) {

python/paddle/static/quantization/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
)
2020
from .quant2_int8_onednn_pass import ( # noqa: F401
2121
Quant2Int8MkldnnPass,
22+
Quant2Int8OnednnPass,
2223
)
2324
from .quant_int8_onednn_pass import ( # noqa: F401
2425
QuantInt8MkldnnPass,
26+
QuantInt8OnednnPass,
2527
)
2628
from .quanter import ( # noqa: F401
2729
convert,

python/paddle/static/quantization/quant2_int8_onednn_pass.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
import numpy as np
1616

17+
from paddle.utils import deprecated
18+
1719
from ...base.framework import IrGraph
1820
from ...framework import _get_paddle_place, core
1921

2022
OpRole = core.op_proto_and_checker_maker.OpRole
2123

2224

23-
class Quant2Int8MkldnnPass:
25+
class Quant2Int8OnednnPass:
2426
"""
2527
Transform a quant model IrGraph into MKL-DNN supported INT8 IrGraph.
2628
The pass consists of the following transformations:
@@ -721,3 +723,14 @@ def _quantize_fp32_graph(self, graph):
721723
graph = self._apply_pass(graph, 'int8_scale_calculation_onednn_pass')
722724
graph = self._apply_pass(graph, 'params_quantization_onednn_pass')
723725
return graph
726+
727+
728+
class Quant2Int8MkldnnPass(Quant2Int8OnednnPass):
729+
@deprecated(
730+
since="3.1.0",
731+
update_to="paddle.static.quantization.Quant2Int8OnednnPass",
732+
level=1,
733+
reason="Quant2Int8MkldnnPass will be removed in future",
734+
)
735+
def __init__(self, *args, **kwargs):
736+
super().__init__(*args, **kwargs)

python/paddle/static/quantization/quant_int8_onednn_pass.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
import numpy as np
1616

17+
from paddle.utils import deprecated
18+
1719
from ...base.framework import IrGraph
1820
from ...framework import _get_paddle_place
1921

2022

21-
class QuantInt8MkldnnPass:
23+
class QuantInt8OnednnPass:
2224
"""
2325
Convert QuantizationFreezePass generated IrGraph to MKL-DNN supported INT8
2426
IrGraph. Following transformations did in this pass:
@@ -48,13 +50,13 @@ def __init__(self, _scope=None, _place=None):
4850
>>> # The original graph will be rewrite.
4951
>>> import paddle
5052
>>> from paddle import static
51-
>>> from paddle.static.quantization import QuantInt8MkldnnPass
53+
>>> from paddle.static.quantization import QuantInt8OnednnPass
5254
>>> from paddle.framework import IrGraph
5355
>>> from paddle.framework import core
5456
5557
>>> graph = IrGraph(core.Graph(static.Program().desc), for_test=False)
5658
>>> place = paddle.CPUPlace()
57-
>>> onednn_pass = QuantInt8MkldnnPass(static.global_scope(), place)
59+
>>> onednn_pass = QuantInt8OnednnPass(static.global_scope(), place)
5860
>>> onednn_pass.apply(graph)
5961
"""
6062

@@ -245,7 +247,7 @@ def _transform_to_quantize_onednn(self, graph, op_node):
245247
quant_op_node = graph.create_op_node(
246248
op_type='quantize',
247249
attrs={
248-
'data_format': 'MKLDNNLAYOUT',
250+
'data_format': 'ONEDNNLAYOUT',
249251
'use_mkldnn': 1,
250252
'Scale': scale_in,
251253
'is_negative_input': 1,
@@ -287,3 +289,14 @@ def _remove_unused_var_nodes(self, graph):
287289
)
288290
)
289291
graph.safe_remove_nodes(all_unused_vars)
292+
293+
294+
class QuantInt8MkldnnPass(QuantInt8OnednnPass):
295+
@deprecated(
296+
since="3.1.0",
297+
update_to="paddle.static.quantization.QuantInt8OnednnPass",
298+
level=1,
299+
reason="QuantInt8MkldnnPass will be removed in future",
300+
)
301+
def __init__(self, *args, **kwargs):
302+
super().__init__(*args, **kwargs)

test/cpp/inference/api/config_printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::ostream &operator<<(std::ostream &os, const AnalysisConfig &config) {
7575
<< "cpu_num_threads: " << config.cpu_math_library_num_threads() << "\n";
7676
os << GenSpaces(num_spaces)
7777
<< "use_tensorrt: " << config.tensorrt_engine_enabled() << "\n";
78-
os << GenSpaces(num_spaces) << "use_mkldnn: " << config.mkldnn_enabled()
78+
os << GenSpaces(num_spaces) << "use_onednn: " << config.onednn_enabled()
7979
<< "\n";
8080
num_spaces--;
8181
os << GenSpaces(num_spaces) << "}\n";

test/deprecated/cpp/inference/api/analysis_predictor_tester.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,15 @@ TEST(AnalysisPredictor, bf16_pass_strategy) {
335335
passStrategy.EnableMkldnnBfloat16();
336336
}
337337

338-
TEST(AnalysisPredictor, mkldnn_fc_pass_strategy) {
338+
TEST(AnalysisPredictor, onednn_fc_pass_strategy) {
339339
std::vector<std::string> passes;
340340
PassStrategy passStrategy(passes);
341341
passStrategy.DisableOnednnFcPasses();
342342
ASSERT_EQ(passes.size(), (size_t)0);
343343
}
344344

345345
#ifdef PADDLE_WITH_DNNL
346-
TEST(AnalysisPredictor, mkldnn_fc_passes_cpu_pass_strategy) {
346+
TEST(AnalysisPredictor, onednn_fc_passes_cpu_pass_strategy) {
347347
CpuPassStrategy cpuPassStrategy;
348348
cpuPassStrategy.EnableONEDNN();
349349
const std::vector<std::string> fc_passes_to_erase(
@@ -359,15 +359,15 @@ TEST(AnalysisPredictor, mkldnn_fc_passes_cpu_pass_strategy) {
359359
#endif
360360

361361
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
362-
TEST(AnalysisPredictor, mkldnn_fc_passes_gpu_pass_strategy) {
362+
TEST(AnalysisPredictor, onednn_fc_passes_gpu_pass_strategy) {
363363
AnalysisConfig config;
364364
config.EnableUseGpu(100, 0);
365365
config.EnableONEDNN();
366366
config.DisableOnednnFcPasses();
367367
#ifdef PADDLE_WITH_DNNL
368-
ASSERT_TRUE(config.mkldnn_fc_passes_disabled());
368+
ASSERT_TRUE(config.onednn_fc_passes_disabled());
369369
#else
370-
ASSERT_FALSE(config.mkldnn_fc_passes_disabled());
370+
ASSERT_FALSE(config.onednn_fc_passes_disabled());
371371
#endif
372372
}
373373
#endif

test/deprecated/cpp/inference/api/analyzer_bert_tester_deprecated.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ namespace inference {
2222

2323
using paddle::PaddleTensor;
2424

25-
void profile(bool use_mkldnn = false, bool use_bfloat16 = false);
25+
void profile(bool use_onednn = false, bool use_bfloat16 = false);
2626
std::vector<std::vector<paddle::PaddleTensor>> LoadInputData();
27-
void CompareNativeAndAnalysisWrapper(bool use_mkldnn = false);
27+
void CompareNativeAndAnalysisWrapper(bool use_onednn = false);
2828
std::vector<paddle::PaddleTensor> ParseInputStreamToVector(
2929
const std::string &line);
3030

31-
AnalysisConfig SetConfig(bool use_mkldnn = false, bool use_bfloat16 = false);
31+
AnalysisConfig SetConfig(bool use_onednn = false, bool use_bfloat16 = false);
3232

3333
template <typename T>
3434
paddle::PaddleTensor ParseTensor(const std::string &field);
@@ -50,15 +50,15 @@ TEST(Analyzer_bert, profile) {
5050
}
5151

5252
#ifdef PADDLE_WITH_DNNL
53-
TEST(Analyzer_bert, profile_mkldnn) {
54-
auto use_mkldnn = true;
55-
profile(use_mkldnn);
53+
TEST(Analyzer_bert, profile_onednn) {
54+
auto use_onednn = true;
55+
profile(use_onednn);
5656
}
5757

58-
TEST(Analyzer_bert, profile_mkldnn_bf16) {
59-
auto use_mkldnn = true;
58+
TEST(Analyzer_bert, profile_onednn_bf16) {
59+
auto use_onednn = true;
6060
auto use_bfloat16 = true;
61-
profile(use_mkldnn, use_bfloat16);
61+
profile(use_onednn, use_bfloat16);
6262
}
6363
#endif
6464

@@ -70,8 +70,8 @@ TEST(Analyzer_bert, compare) {
7070
}
7171
#ifdef PADDLE_WITH_DNNL
7272
TEST(Analyzer_bert, compare_mkldnn) {
73-
auto use_mkldnn = true;
74-
CompareNativeAndAnalysisWrapper(use_mkldnn);
73+
auto use_onednn = true;
74+
CompareNativeAndAnalysisWrapper(use_onednn);
7575
}
7676
#endif
7777

@@ -135,8 +135,8 @@ TEST(Analyzer_bert, transfer_scope_cache) {
135135
"The size of data cache is not equal to thread number."));
136136
}
137137

138-
void profile(bool use_mkldnn, bool use_bfloat16) {
139-
auto config(SetConfig(use_mkldnn, use_bfloat16));
138+
void profile(bool use_onednn, bool use_bfloat16) {
139+
auto config(SetConfig(use_onednn, use_bfloat16));
140140
std::vector<std::vector<PaddleTensor>> outputs;
141141
auto inputs = LoadInputData();
142142
TestPrediction(reinterpret_cast<const PaddlePredictor::Config *>(&config),
@@ -168,8 +168,8 @@ std::vector<std::vector<paddle::PaddleTensor>> LoadInputData() {
168168
return inputs;
169169
}
170170

171-
void CompareNativeAndAnalysisWrapper(bool use_mkldnn) {
172-
auto cfg(SetConfig(use_mkldnn));
171+
void CompareNativeAndAnalysisWrapper(bool use_onednn) {
172+
auto cfg(SetConfig(use_onednn));
173173
auto inputs = LoadInputData();
174174
CompareNativeAndAnalysis(
175175
reinterpret_cast<const PaddlePredictor::Config *>(&cfg), inputs);
@@ -201,12 +201,12 @@ std::vector<paddle::PaddleTensor> ParseInputStreamToVector(
201201
return tensors;
202202
}
203203

204-
AnalysisConfig SetConfig(bool use_mkldnn, bool use_bfloat16) {
204+
AnalysisConfig SetConfig(bool use_onednn, bool use_bfloat16) {
205205
AnalysisConfig config;
206206
config.SetModel(FLAGS_infer_model);
207207
config.DisableFCPadding();
208208

209-
if (use_mkldnn) {
209+
if (use_onednn) {
210210
config.EnableONEDNN();
211211
}
212212

test/deprecated/ir/inference/auto_scan_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def create_inference_config(
239239
if use_gpu:
240240
config.enable_use_gpu(100, 0)
241241
if not use_mkldnn:
242-
config.disable_mkldnn()
242+
config.disable_onednn()
243243
if use_xpu:
244244
config.enable_xpu()
245245
if passes is not None:
@@ -248,7 +248,7 @@ def create_inference_config(
248248
return config
249249

250250

251-
class MkldnnAutoScanTest(AutoScanTest):
251+
class OnednnAutoScanTest(AutoScanTest):
252252
def __init__(self, *args, **kwargs):
253253
super().__init__(*args, **kwargs)
254254

@@ -336,14 +336,14 @@ def run_test(self, quant=False, *args, **kwargs):
336336

337337
def inference_config_str(self, config) -> str:
338338
dic = {}
339-
enable_mkldnn = config.mkldnn_enabled()
340-
dic["use_mkldnn"] = enable_mkldnn
339+
enable_onednn = config.onednn_enabled()
340+
dic["use_mkldnn"] = enable_onednn
341341
enable_gpu = config.use_gpu()
342342
dic["use_gpu"] = enable_gpu
343343
return str(dic)
344344

345345

346-
class PirMkldnnAutoScanTest(MkldnnAutoScanTest):
346+
class PirOnednnAutoScanTest(OnednnAutoScanTest):
347347
def __init__(self, *args, **kwargs):
348348
super().__init__(*args, **kwargs)
349349

@@ -572,8 +572,8 @@ def run_test(self, quant=False, prog_configs=None):
572572

573573
def inference_config_str(self, config) -> str:
574574
dic = {}
575-
enable_mkldnn = config.mkldnn_enabled()
576-
dic["use_mkldnn"] = enable_mkldnn
575+
enable_onednn = config.onednn_enabled()
576+
dic["use_mkldnn"] = enable_onednn
577577
enable_gpu = config.use_gpu()
578578
dic['use_gpu'] = enable_gpu
579579
enable_xpu = config.use_xpu()

test/deprecated/ir/inference/inference_pass_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, methodName='runTest'):
3838
self.fetch_list = None
3939

4040
self.enable_mkldnn = False
41-
self.enable_mkldnn_bfloat16 = False
41+
self.enable_onednn_bfloat16 = False
4242
self.enable_trt = False
4343
self.enable_tensorrt_varseqlen = False
4444
self.trt_parameters = None
@@ -143,7 +143,7 @@ def _get_analysis_config(
143143
self.path + ".pdmodel", self.path + ".pdiparams"
144144
)
145145
config.disable_gpu()
146-
config.disable_mkldnn()
146+
config.disable_onednn()
147147
config.switch_specify_input_names(True)
148148
config.switch_ir_optim(True)
149149
config.switch_use_feed_fetch_ops(False)
@@ -179,7 +179,7 @@ def _get_analysis_config(
179179

180180
elif use_mkldnn:
181181
config.enable_onednn()
182-
if self.enable_mkldnn_bfloat16:
182+
if self.enable_onednn_bfloat16:
183183
config.enable_onednn_bfloat16()
184184
return config
185185

@@ -285,23 +285,23 @@ def check_output_with_option(
285285

286286
# Check whether the onednn results and the CPU results are the same.
287287
if (not use_gpu) and self.enable_mkldnn:
288-
mkldnn_outputs = self._get_inference_outs(
288+
onednn_outputs = self._get_inference_outs(
289289
self._get_analysis_config(
290290
use_gpu=use_gpu, use_mkldnn=self.enable_mkldnn
291291
)
292292
)
293293

294294
self.assertTrue(
295-
len(paddle_outs) == len(mkldnn_outputs),
295+
len(paddle_outs) == len(onednn_outputs),
296296
"The number of outputs is different between CPU and MKLDNN. ",
297297
)
298298

299-
if self.enable_mkldnn_bfloat16:
299+
if self.enable_onednn_bfloat16:
300300
atol = 0.01
301-
for paddle_out, mkldnn_output in zip(paddle_outs, mkldnn_outputs):
301+
for paddle_out, onednn_output in zip(paddle_outs, onednn_outputs):
302302
np.testing.assert_allclose(
303303
np.array(paddle_out),
304-
mkldnn_output,
304+
onednn_output,
305305
rtol=1e-05,
306306
atol=atol,
307307
err_msg='Output has diff between CPU and MKLDNN. ',

0 commit comments

Comments
 (0)