Add getDimName to DimAnalysis to get the name of a dynamic dimension - #3638
Add getDimName to DimAnalysis to get the name of a dynamic dimension#3638tungld wants to merge 3 commits into
Conversation
The name of a dynamic dimension comes from the onnx.dim_params attribute of a function argument/result when the model provides one, e.g. "batch_size". Otherwise a name is synthesized from the argument itself, using its onnx.name attribute or its position, e.g. "X_1" or "arg0_0". Function results are never named that way, so a name always traces back to a value the caller supplies. Since all the dynamic dimensions of a group are equal at runtime, one name is elected per group, and a dimension of an intermediate tensor is named as soon as the analysis proves it equal to a named one. Groups are named at the end of analyze(), where the sets are final, because merging moves dimensions between sets and makes set ids disappear. Dimensions are indexed by their set at the same time so that looking up a name does not traverse the sets. The --onnx-dim-analysis pass exposes the elected name as the new optional group_name attribute of onnx.DimGroup, which is how the LIT tests check this, and dump() prints the name of each set. Signed-off-by: Tung D. Le <tung@jp.ibm.com>
AlexandreEichenberger
left a comment
There was a problem hiding this comment.
LGTM, it should be helpful to decisions for parallel.
I already "propagated" the names in utils/AnalyzeShape.py. If you have the time, maybe try to just run that script once to see if it needs fixing because of the new info.
| : name(std::move(name)), fromDimParam(fromDimParam), argPos(argPos), | ||
| dimPos(dimPos) {} | ||
|
|
||
| // Returns true if this name is a better candidate than `other`. |
There was a problem hiding this comment.
just curious how this works? if you have a name "arg0_2" already but the new name is "batch_size", then it would keep the "batch_size" name?
There was a problem hiding this comment.
A name from dim_params has the highest priority, so "batch_size" is used.
Signed-off-by: Tung D. Le <tungld@gmail.com> Signed-off-by: Tung D. Le <tung@jp.ibm.com>
Yes, changed the script to use the new info (group_namein DimGroup) instead of "propagate" again. |
The name of a dynamic dimension comes from the onnx.dim_params attribute of a function argument/result when the model provides one, e.g. "batch_size". Otherwise a name is synthesized from the argument itself, using its onnx.name attribute or its position, e.g. "X_1" or "arg0_0".
Since all the dynamic dimensions of a group are equal at runtime, one name is elected per group, and a dimension of an intermediate tensor is named as soon as the analysis proves it equal to a named one. Groups are named at the end of analyze(), where the sets are final, because merging moves dimensions between sets and makes set ids disappear. Dimensions are indexed by their set at the same time so that looking up a name does not traverse the sets.
The --onnx-dim-analysis pass exposes the elected name as the new optional group_name attribute of onnx.DimGroup, which is how the LIT tests check this, and dump() prints the name of each set.
Example to show how to call getDimName: