ONE icon indicating copy to clipboard operation
ONE copied to clipboard

[circle-optimizer] Support constant folding of Gather/SparseToDense

Open jinevening opened this issue 3 years ago • 4 comments

What

Let's support constant folding of Gather and SparseToDense.

Why

Reshape Op in onnx model is translated to Gather->SparseToDense->AddV2->Cast in circle.

onnx reshape

circle tflite

A similar pattern was resolved by https://github.com/Samsung/ONE/issues/5598, but the pattern tackled by this issue is slightly different (more specifically, the input shape of SparseToDense is different).

I think we will face similar issues whenever supporting new models. General constant folding (https://github.com/Samsung/ONE/issues/7129) will significantly reduce the burden of implementing constant folding passes.

CC @seanshpark @llFreetimell

jinevening avatar Feb 03 '22 03:02 jinevening

General constant folding (https://github.com/Samsung/ONE/issues/7129) will significantly reduce the burden of implementing constant folding passes.

I agree with this :) If so, we can further expect reduction of logic duplication between luci-interpreter and luci/pass.

llFreetimell avatar Feb 08 '22 00:02 llFreetimell

Сould you tell me how I can make an onyx model with this pattern or where I can find it? I would like to try to work on this issue :)

BalyshevArtem avatar Mar 16 '22 09:03 BalyshevArtem

The pattern may appear when reshape's shape has a negative value as below.

image

I've made a small (sliced) tflite model converted from the onnx model.

image

The final result of the model would be just Transpose -> Reshape.

example.zip

jinevening avatar Mar 17 '22 03:03 jinevening

example.zip

It would be nice if this can be added to our tflite recipes. with tflchef-reverse tool, we can generate it. (in build/compiler/tflchef/tools/reverse folder)

seanshpark avatar Mar 17 '22 03:03 seanshpark