onnxruntime/onnxruntime/core
pengwa bf32dbbd9b
Share more constant initializers (#15461)
### Share more constant initializers.

`ConstantSharing` transformer originally only handle single value
initializer (scalar or 1D).

This PR tried to share more cases to make common subexpression
elimination transformer to remove more duplicated nodes.

Originally, we used a single
vector<std::variant<float,half,int32,int64>> to store different scalar
values. In this PR, we create a unordered map with its key being
data_type + rank + element count, and its value is a vector of
`InitializerValue`.

For one specific initializer, if it fulfils the condition, then finally
will find the corresponding vector of `InitializerValue` by its
<data_type + rank + element count>, then search from the vector whether
the constant tensor already exist or not. After that, a value id is
returned, which will be combined together with <data_type + rank +
element count> to form the pattern key to decide which tensor to reuse
(legacy code).

### Motivation and Context

One example we see here is:

```mermaid
stateDiagram
    [*] --> LayerNorm(b,s,64)
    LayerNorm(b,s,64) --> Reshape1
    Shape1_Const[b*s,64] --> Reshape1

    LayerNorm(b,s,64) --> Reshape2
    Shape2_Const[b*s,64] --> Reshape2


    Reshape1 --> AttentionSubGraph
    Reshape2 -->  Add
    AttentionSubGraph--> Add
   Add --> [*]
```

Ideally CommonSubexpressionElimination can remove one of `Reshape1` and
`Reshape2`, while since `Shape1_Const` and `Shape2_Const` are different
NodeArg*, so it did not remove the duplication.

This is an example: removing the duplication will bring more
opportunities to apply graph transformations.
2023-04-14 07:41:07 -07:00
..
codegen
common Cfu fp16 (#14538) 2023-02-15 12:51:53 -08:00
dll
dlpack
eager
flatbuffers Adopt linrtunner as the linting tool - take 2 (#15085) 2023-03-24 15:29:03 -07:00
framework Implement Optional Metadata support and C# test support (#15314) 2023-04-11 09:41:59 -07:00
graph Fix bug in handling of variadics in function schema creation (#15409) 2023-04-12 14:32:24 -07:00
language_interop_ops
mlas Fuse 'Add' operator into FP16 Conv (#15213) 2023-04-07 09:51:03 -07:00
optimizer Share more constant initializers (#15461) 2023-04-14 07:41:07 -07:00
platform Remove Win8 support (#15219) 2023-03-27 18:51:49 -07:00
providers [ROCm] Add hipBLASLt GEMM support to Tunable op. (#15351) 2023-04-14 17:56:01 +08:00
quantization
session Implement Optional Metadata support and C# test support (#15314) 2023-04-11 09:41:59 -07:00
util FP16 conv (#15062) 2023-03-21 10:32:43 -07:00