onnxruntime/onnxruntime
pengwa 0668600255
Share scalar constant initializer (#12878)
**Description**: 
1. Share scalar constant for same data type, value and shape. 
2. Fix the order of Graph resolve context clear and
CleanUnusedInitializersAndNodeArgs().

**Share initializer for those who hold same value in same type and
shape, currently only handle scalar value or 1-D single value array.**
  
The transformation itself did not bring much impact on memory/perf,
instead is helpful to simplify the graph, making it easier for common
subexpression eliminations (CSE). Imagine graphs like this:


![image](https://user-images.githubusercontent.com/10530022/188895598-e06f9bf9-5466-4009-a68c-6b339133936c.png)

Add is NOT shared as inputs of Clip after CSE transformation because,
all Add's second constant input are different NodeArg*, so if we change
all constant initializer share the same NodeArg*, then only one Add will
be preserved after CSE transformation. There are few other similar cases
in one of 1P deberta models.

E2E measurement on 1P DEBERTA model, we see an increase from
SamplesPerSec=562.041593991271 to 568.0106130440271, 1.07% gains.

**Fix the order of Graph resolve context clear and
CleanUnusedInitializersAndNodeArgs().**

Graph resolve context will be cleared every time by end of
Graph.Resolve(), one of the thing to be cleared is the
"inputs_and_initializers" who hold string_view of all initializers.
While CleanUnusedInitializersAndNodeArgs removed some initializers, so
some strings that is referenced by string_view in
"inputs_and_initializers" remain to be there BUT in an invalid state.

**Motivation and Context**
- Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here.
2022-10-10 13:32:33 +08:00
..
contrib_ops Share scalar constant initializer (#12878) 2022-10-10 13:32:33 +08:00
core Share scalar constant initializer (#12878) 2022-10-10 13:32:33 +08:00
gsl
python Share scalar constant initializer (#12878) 2022-10-10 13:32:33 +08:00
test Share scalar constant initializer (#12878) 2022-10-10 13:32:33 +08:00
tool/etw
wasm [js/web] add 'xnnpack' to EP list (#12723) 2022-10-03 10:38:45 -07:00
__init__.py Bump ort version number (#11948) 2022-07-22 12:55:53 -07:00
ReformatSource.ps1
ReformatSourcePython.bat Add python docstring linting in vscode settings (#11316) 2022-04-23 06:23:04 -07:00
VSCodeCoverage.runsettings