From 62f6a55a9b1427ae7715c70fac574020ce30cbed Mon Sep 17 00:00:00 2001 From: wuxun-zhang Date: Wed, 25 Dec 2019 16:44:27 +0800 Subject: [PATCH 1/3] fix_copyto --- src/imperative/imperative_utils.h | 24 ++----------------- .../python/quantization/test_quantization.py | 20 +++++++++------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/imperative/imperative_utils.h b/src/imperative/imperative_utils.h index edc2f2adf4c2..b8de105a1066 100644 --- a/src/imperative/imperative_utils.h +++ b/src/imperative/imperative_utils.h @@ -477,18 +477,8 @@ inline void PushFComputeEx(const FComputeEx& fn, // copying A to B may not happen, and will corrupt A's memory. InvalidateOutputs(outputs, req); } - // add for mkldnn OP + no mkldnn OP - const auto is_mkldnn = Op::GetAttr("TIsMKLDNN"); - if (!is_mkldnn.get(attrs.op, false)) { - std::vector inputs_fallback; - CreateDefaultInputs(inputs, &inputs_fallback); - fn(attrs, opctx, inputs_fallback, req, outputs); - } else { - fn(attrs, opctx, inputs, req, outputs); - } -#else - fn(attrs, opctx, inputs, req, outputs); #endif + fn(attrs, opctx, inputs, req, outputs); if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync && !rctx.is_bulk) { rctx.get_stream()->Wait(); } @@ -541,18 +531,8 @@ inline void PushOperator(const OpStatePtr& state, // copying A to B may not happen, and will corrupt A's memory. InvalidateOutputs(outputs, req); } - // add for mkldnn OP + no mkldnn OP - const auto is_mkldnn = Op::GetAttr("TIsMKLDNN"); - if (!is_mkldnn.get(attrs.op, false)) { - std::vector inputs_fallback; - CreateDefaultInputs(inputs, &inputs_fallback); - fcompute_ex(state, opctx, inputs_fallback, req, outputs); - } else { - fcompute_ex(state, opctx, inputs, req, outputs); - } -#else - fcompute_ex(state, opctx, inputs, req, outputs); #endif + fcompute_ex(state, opctx, inputs, req, outputs); if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync && rctx.get_stream() && !rctx.is_bulk) { rctx.get_stream()->Wait(); diff --git a/tests/python/quantization/test_quantization.py b/tests/python/quantization/test_quantization.py index 8f433524b325..ec6ddfdf67f4 100644 --- a/tests/python/quantization/test_quantization.py +++ b/tests/python/quantization/test_quantization.py @@ -1137,15 +1137,17 @@ def check_quantize_net(qdtype): quantized_resnet18_v1.hybridize(static_alloc=True, static_shape=True) quantized_resnet18_v1(random_data) - quantized_resnet18_v1 = mx.contrib.quant.quantize_net(resnet18_v1, quantized_dtype=qdtype, - exclude_layers=None, - exclude_layers_match=excluded_names_match, - calib_data=calib_data, - calib_mode='naive', - num_calib_examples=num_calib_examples, - ctx=mx.current_context()) - quantized_resnet18_v1.hybridize(static_alloc=True, static_shape=True) - quantized_resnet18_v1(random_data) + for mode in ['naive', 'entropy']: + qdtype = qdtype if mode is 'naive' else 'auto' + quantized_resnet18_v1 = mx.contrib.quant.quantize_net(resnet18_v1, quantized_dtype=qdtype, + exclude_layers=None, + exclude_layers_match=excluded_names_match, + calib_data=calib_data, + calib_mode=mode, + num_calib_examples=num_calib_examples, + ctx=mx.current_context()) + quantized_resnet18_v1.hybridize(static_alloc=True, static_shape=True) + quantized_resnet18_v1(random_data) for qdtype in ['int8', 'uint8']: check_quantize_net(qdtype) From 007b502b567de3169700f23b66eea233227108b2 Mon Sep 17 00:00:00 2001 From: wuxun-zhang Date: Mon, 30 Dec 2019 11:49:41 +0800 Subject: [PATCH 2/3] only exclude _copyto --- src/imperative/imperative_utils.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/imperative/imperative_utils.h b/src/imperative/imperative_utils.h index b8de105a1066..c6d9b8b7b969 100644 --- a/src/imperative/imperative_utils.h +++ b/src/imperative/imperative_utils.h @@ -477,8 +477,18 @@ inline void PushFComputeEx(const FComputeEx& fn, // copying A to B may not happen, and will corrupt A's memory. InvalidateOutputs(outputs, req); } -#endif + // add for mkldnn OP + no mkldnn OP + const auto is_mkldnn = Op::GetAttr("TIsMKLDNN"); + if (!is_mkldnn.get(attrs.op, false) && exec_type != ExecType::kCrossDeviceCopy) { + std::vector inputs_fallback; + CreateDefaultInputs(inputs, &inputs_fallback); + fn(attrs, opctx, inputs_fallback, req, outputs); + } else { + fn(attrs, opctx, inputs, req, outputs); + } +#else fn(attrs, opctx, inputs, req, outputs); +#endif if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync && !rctx.is_bulk) { rctx.get_stream()->Wait(); } @@ -531,8 +541,18 @@ inline void PushOperator(const OpStatePtr& state, // copying A to B may not happen, and will corrupt A's memory. InvalidateOutputs(outputs, req); } -#endif + // add for mkldnn OP + no mkldnn OP + const auto is_mkldnn = Op::GetAttr("TIsMKLDNN"); + if (!is_mkldnn.get(attrs.op, false) && exec_type != ExecType::kCrossDeviceCopy) { + std::vector inputs_fallback; + CreateDefaultInputs(inputs, &inputs_fallback); + fcompute_ex(state, opctx, inputs_fallback, req, outputs); + } else { + fcompute_ex(state, opctx, inputs, req, outputs); + } +#else fcompute_ex(state, opctx, inputs, req, outputs); +#endif if (ctx.dev_mask() == gpu::kDevMask && exec_type == ExecType::kSync && rctx.get_stream() && !rctx.is_bulk) { rctx.get_stream()->Wait(); From d9f58ebefe8e6a99beeeb17d0568dc958f1376e4 Mon Sep 17 00:00:00 2001 From: wuxun-zhang Date: Tue, 31 Dec 2019 09:16:08 +0800 Subject: [PATCH 3/3] trigger CI