Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[luci/service] Support dynamic shape inference for reshape #1

Closed
wants to merge 6 commits into from

Conversation

jongwonyang
Copy link
Owner

@jongwonyang jongwonyang commented Sep 11, 2024

This commit supports dynamic shape inference for reshape operation

Dynamic shape inference algorithm

from: Samsung#13927 (comment), Samsung#13927 (comment)

  • CircleReshape always has two inputs: tensor and shape.
    • otherwise, throw an error
  • The shape input can be CircleConst, CircleOutputDummy, or CircleNode.
  • When the shape input is CircleConst
    • The shape is inferred from the constant shape
    • output_shape would be static
    • e.g. reshape(tensor, [2, 3]) --> [2, 3]
  • When the shape input is CircleOutputDummy
    • First, try to inference shape using node's attribute (newShape)
    • If there's no attribute (and no shape input), propagate the shape of node itself
  • When the shape input is CircleNode
    • The shape is inferred by shape input's size (because the exact shape cannot be determined at compile time)
    • output_shape would be dynamic
    • e.g. reshape(tensor, shape_node(with size 3)) --> [?, ?, ?]
  • If there is single unknown dimension in output_shape and input tensor is fully known, that dimension is inferred by the count of the elements

When should not infer?

Unknown dimension of output_shape is NOT inferred (by the should_infer) when:

  • the shape input is CircleNode. Because if it's not constant, the only thing we can infer at compile time is the size of dimensions.
  • the tensor input is not fully known. Because shape inference of reshape is based on the sameness of elements count.

Exclude Net_Gather_SparseToDense_AddV2_000

from: Samsung#13935 (comment), FoldSparseToDensePass.cpp

Net_Gather_SparseToDense_AddV2_000 is excluded from optimization test because constant folding of SparseToDense is not fully supported.

Remaining own_shape?

from: Samsung#13935 (comment), Samsung#13935 (comment)

The usage of circle_shape might seems to be remaining of own_shape which should be removed by the new shape inference algorithm.

First, this logic is used to support this recipe(Reshape_003) which has no attribute, no shape input.
I've tried to revise this recipe according to this comment, and have read the related PRs (Samsung#1554, Samsung#1519).
But it was hard to make a policy about no attribute, no shape input case.
So, we decided not to fix another code(importer, recipes) and do it best in shape inference logic.
As a result, I followed the suggestion from Samsung#13927 (comment).

Neg test cases

from: Samsung#13977

Some of the neg test cases might not directly related to the changes that have been made in this PR.
(which means the false return and throws are not made in CircleReshape.cpp.)
Please tell me if these are inappropriate.


Related: Samsung#13927
Draft: Samsung#13935
Depends on: Samsung#13989

ONE-DCO-1.0-Signed-off-by: Jongwon Yang [email protected]

* [fm-equalize] Add DumpFMEParams script

This commit adds DumpFMEParams script.

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>

* revise comments.
This commit revises overall codes.

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>
@jongwonyang jongwonyang marked this pull request as ready for review September 12, 2024 04:28
@jongwonyang jongwonyang marked this pull request as draft September 12, 2024 04:28
hseok-oh and others added 4 commits September 12, 2024 13:35
This commit moves NNAPI implementation into test library.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
…13968)

This partially supports dynamic shape inference for StridedSlice op
when input node has dynamic shape and other nodes are const
and input node has static shape and begin, end nodes are non const.

ONE-DCO-1.0-Signed-off-by: sunki <[email protected]>
Samsung#13989)

This commit migrates Reshape shape inference rule to sinf::Algorithm.

ONE-DCO-1.0-Signed-off-by: Jongwon Yang <[email protected]>
This commit supports dynamic shape inference for reshape operation

ONE-DCO-1.0-Signed-off-by: Jongwon Yang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants