From 03cf68ed451d7395556f3698c2959f428d8ffbca Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:41:15 -0800 Subject: [PATCH] [reduced-operator-config-file.md] Add documentation about globally allowed types. --- .../operators/reduced-operator-config-file.md | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/reference/operators/reduced-operator-config-file.md b/docs/reference/operators/reduced-operator-config-file.md index cd7793e4c3c91..5bdf9d98a0e08 100644 --- a/docs/reference/operators/reduced-operator-config-file.md +++ b/docs/reference/operators/reduced-operator-config-file.md @@ -62,6 +62,8 @@ Additionally, the ONNX operator specs for [DNN](https://github.com/onnx/onnx/blo ## Type reduction format +### Per-operator type information + If the types an operator implementation supports can be limited to a specific set of types, this is specified in a JSON string immediately after the operator name in the configuration file. **It is highly recommended that you first generate the configuration file using ORT format models with type reduction enabled in order to see which operators support type reduction, and how the entry is defined for the individual operators.** @@ -69,17 +71,42 @@ If the types an operator implementation supports can be limited to a specific se The required types are generally listed per input and/or output of the operator. The type information is in a map, with 'inputs' and 'outputs' keys. The value for 'inputs' or 'outputs' is a map between the index number of the input/output and the required list of types. For example, both the input and output types are relevant to ai.onnx:Cast. Type information for input 0 and output 0 could look like this: - `{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}}` -which is added directly after the operator name in the configuration file. -e.g. - `ai.onnx;12;Add,Cast{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}},Concat,Squeeze` +``` +{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}} +``` + +which is added directly after the operator name in the configuration file. E.g.: + +``` +ai.onnx;12;Add,Cast{"inputs": {"0": ["float", "int32_t"]}, "outputs": {"0": ["float", "int64_t"]}},Concat,Squeeze +``` If, for example, the types of inputs 0 and 1 were important, the entry may look like this (e.g. ai.onnx:Gather): - `{"inputs": {"0": ["float", "int32_t"], "1": ["int32_t"]}}` + +``` +{"inputs": {"0": ["float", "int32_t"], "1": ["int32_t"]}} +``` Finally some operators do non-standard things and store their type information under a 'custom' key. ai.onnx.OneHot is an example of this, where the three input types are combined into a triple. - `{"custom": [["float", "int64_t", "int64_t"], ["int64_t", "std::string", "int64_t"]]}` + +``` +{"custom": [["float", "int64_t", "int64_t"], ["int64_t", "std::string", "int64_t"]]} +``` For these reasons, it is best to generate the configuration file first, and manually edit any entries if needed. + +### Globally allowed types + +It is also possible to limit the types supported by all operators to a specific set of types. These are referred to as *globally allowed types*. They may be specified in the configuration file on a separate line. + +The format for specifying globally allowed types for all operators is: + +``` +!globally_allowed_types;T0,T1,... +``` + +`Ti` should be a C++ scalar type supported by ONNX and ORT. At most one globally allowed types specification is allowed. + +Specifying per-operator type information and specifying globally allowed types are mutually exclusive - it is an error to specify both.