This commit is contained in:
rachguo 2022-03-01 17:20:56 -08:00
parent f19bae944b
commit 65550ea420
5 changed files with 14 additions and 10 deletions

View file

@ -70,8 +70,8 @@ static const char* const kOrtSessionOptionsConfigAllowIntraOpSpinning = "session
static const char* const kOrtSessionOptionsConfigUseORTModelBytesDirectly = "session.use_ort_model_bytes_directly";
// It controls whether qdq is int8 allowed in QDQ format model or not.
// "0": not allowed; "1": allowed. It is used as a forced option when exporting to ort format model do disable certain
// usage of unsupported qdq transformers(in minimal build), such as QDQS8ToU8Transformer.
// "0": not allowed; "1": allowed. It's used as a forced option when exporting to ort model to disable certain usage of
// unsupported qdq transformers (in minimal build), such as QDQS8ToU8Transformer and also passed into several qdq selectors.
static const char* const kOrtSessionOptionsQDQIsInt8Allowed = "session.qdqisint8allowed";
// Save information for replaying graph optimizations later instead of applying them directly.

View file

@ -6,6 +6,7 @@
#include <algorithm>
#include "core/optimizer/qdq_transformer/selectors_actions/qdq_selector_action_transformer.h"
#include "core/optimizer/selectors_actions/selector_action_transformer_apply_contexts.h"
#include "core/session/onnxruntime_session_options_config_keys.h"
#if !defined(ORT_MINIMAL_BUILD)
@ -159,7 +160,7 @@ InlinedVector<std::unique_ptr<GraphTransformer>> GenerateTransformers(
const bool disable_quant_qdq =
session_options.config_options.GetConfigOrDefault(kOrtSessionOptionsDisableQuantQDQ, "0") == "1";
const bool qdq_is_int8_allowed =
session_options.config_options.GetConfigOrDefault(kOrtSessionOptionsQDQIsInt8Allowed, "1") == "1";
session_options.config_options.GetConfigOrDefault(kOrtSessionOptionsQDQIsInt8Allowed, QDQIsInt8Allowed() ? "1" : "0") == "1";
#ifndef DISABLE_CONTRIB_OPS
const bool enable_gelu_approximation =
session_options.config_options.GetConfigOrDefault(kOrtSessionOptionsEnableGeluApproximation, "0") == "1";
@ -213,7 +214,7 @@ InlinedVector<std::unique_ptr<GraphTransformer>> GenerateTransformers(
if (!qdq_is_int8_allowed) {
transformers.emplace_back(std::make_unique<QDQS8ToU8Transformer>(cpu_ep));
}
transformers.emplace_back(std::make_unique<QDQSelectorActionTransformer>());
transformers.emplace_back(std::make_unique<QDQSelectorActionTransformer>(SatApplyContextVariant{}, qdq_is_int8_allowed));
}
transformers.emplace_back(std::make_unique<GemmActivationFusion>(cpu_ep));

View file

@ -204,10 +204,10 @@ SelectorActionRegistry CreateSelectorActionRegistry(bool is_int8_allowed) {
} // namespace
QDQSelectorActionTransformer::QDQSelectorActionTransformer(const SatApplyContextVariant& apply_context)
QDQSelectorActionTransformer::QDQSelectorActionTransformer(const SatApplyContextVariant& apply_context, bool is_int8_allowed)
: SelectorActionTransformer{
"QDQSelectorActionTransformer",
CreateSelectorActionRegistry(QDQIsInt8Allowed()),
CreateSelectorActionRegistry(is_int8_allowed),
apply_context} {
}

View file

@ -22,7 +22,7 @@ Transformer that fuses QDQ and fp32 ops into quantized ops.
*/
class QDQSelectorActionTransformer : public SelectorActionTransformer {
public:
QDQSelectorActionTransformer(const SatApplyContextVariant& apply_context = SatApplyContextVariant{});
QDQSelectorActionTransformer(const SatApplyContextVariant& apply_context = SatApplyContextVariant{}, bool is_int8_allowed = false);
};
} // namespace onnxruntime

View file

@ -198,10 +198,11 @@ def parse_args():
'In particular, specify the value of the "ep.nnapi.partitioning_stop_ops" session '
'options config entry.')
parser.add_argument('--target_platform', type=str, default='arm', choices=['arm', 'amd64'],
parser.add_argument('--target_platform', type=str, default=None, choices=['arm', 'amd64'],
help='Specify the target platform where the exported model will be used.'
'This parameter can be used to choose between platform specifically related options,'
'such as QDQIsInt8Allowed or not, NCHWc (amd64) and NHWC (arm) format optimizer level options,etc.')
'This parameter can be used to choose between platform specific options,'
'such as QDQIsInt8Allowed(arm), NCHWc (amd64) and NHWC (arm/amd64) format different'
'optimizer level options,etc.')
parser.add_argument('model_path_or_dir', type=pathlib.Path,
help='Provide path to ONNX model or directory containing ONNX model/s to convert. '
@ -235,6 +236,8 @@ def convert_onnx_models_to_ort():
if args.target_platform == 'arm':
session_options_config_entries["session.qdqisint8allowed"] = "1"
else:
session_options_config_entries["session.qdqisint8allowed"] = "0"
for optimization_level in args.optimization_level:
print(f"Converting models and creating configuration file for optimization level '{optimization_level}'")