One: Compiler FE: Invalid buffer index after one-optimize

Created on 19 Jul 2021  路  4Comments  路  Source: Samsung/ONE

When I tested mobilenet tflite model with fuse_batchnorm_with_tconv option, most tensor's buffer index changed to special purpose buffer 0.

.cfg file for one-build

[one-build]
one-import-tf=False
one-import-tflite=True
one-import-bcq=False
one-import-onnx=False
one-optimize=True
one-quantize=True
one-pack=False
one-codegen=False

[one-import-tflite]
input_path=./mobilenet_v1_1.0_128.tflite
output_path=./mobilenet_v1_1.0_128.circle

[one-optimize]
input_path=./mobilenet_v1_1.0_128.circle
output_path=./mobilenet_v1_1.0_128.opt.circle
fuse_batchnorm_with_tconv=True

[one-quantize]
input_path=./mobilenet_v1_1.0_128.opt.circle
output_path=./mobilenet_v1_1.0_128.opt.q8.circle

Parsing optimized model

$ python3 ./tools/tflitefile_tool/model_parser.py mobilenet_v1_1.0_128.opt.circle
[#0 b'' (MAIN)]

#0 b'' (MAIN) input tensors: [0]
        Tensor    0 : buffer Empty |  Empty | FLOAT32 | Memory 192.0K | Shape [1, 128, 128, 3] (b'input')
#0 b'' (MAIN) output tensors: [88]
        Tensor   88 : buffer Empty |  Empty | FLOAT32 | Memory 3.9K   | Shape [1, 1001] (b'MobilenetV1/Predictions/Reshape_1')

Operator 0: CONV_2D
        Fused Activation: RELU6
        Input Tensors[0, 1, 2]
                Tensor    0 : buffer Empty |  Empty | FLOAT32 | Memory 192.0K | Shape [1, 128, 128, 3] (b'input')
                Tensor    1 : buffer 1     | Filled | FLOAT32 | Memory 3.4K   | Shape [32, 3, 3, 3] (b'MobilenetV1/Conv2d_0/weights')
                Tensor    2 : buffer 2     | Filled | FLOAT32 | Memory 128.0B | Shape [32] (b'MobilenetV1/MobilenetV1/Conv2d_0/convolution_bias')
        Output Tensors[3]
                Tensor    3 : buffer Empty |  Empty | FLOAT32 | Memory 512.0K | Shape [1, 64, 64, 32] (b'MobilenetV1/MobilenetV1/Conv2d_0/Relu6')
        Options 
                Stride W:H = 2:2, Dilation W:H = 1:1, Padding = SAME

.....

buffer Empty means buffer index is 0.

Parsing model before optimized

$ python3 ./tools/tflitefile_tool/model_parser.py mobilenet_v1_1.0_128.circle
[#0 None (MAIN)]

#0 None (MAIN) input tensors: [88]
        Tensor   88 : buffer 88    |  Empty | FLOAT32 | Memory 192.0K | Shape [1, 128, 128, 3] (b'input')
#0 None (MAIN) output tensors: [87]
        Tensor   87 : buffer 24    |  Empty | FLOAT32 | Memory 3.9K   | Shape [1, 1001] (b'MobilenetV1/Predictions/Reshape_1')

Operator 0: CONV_2D
        Fused Activation: RELU6
        Input Tensors[88, 0, 32]
                Tensor   88 : buffer 88    |  Empty | FLOAT32 | Memory 192.0K | Shape [1, 128, 128, 3] (b'input')
                Tensor    0 : buffer 55    | Filled | FLOAT32 | Memory 3.4K   | Shape [32, 3, 3, 3] (b'MobilenetV1/Conv2d_0/weights')
                Tensor   32 : buffer 23    | Filled | FLOAT32 | Memory 128.0B | Shape [32] (b'MobilenetV1/MobilenetV1/Conv2d_0/convolution_bias')
        Output Tensors[31]
                Tensor   31 : buffer 41    |  Empty | FLOAT32 | Memory 512.0K | Shape [1, 64, 64, 32] (b'MobilenetV1/MobilenetV1/Conv2d_0/Relu6')
        Options 
                Stride W:H = 2:2, Dilation W:H = 1:1, Padding = SAME

...

cc/ @llFreetimell

bug

All 4 comments

I got same result on with/without fuse_batchnorm_with_tconv option. And same result on inception v3,

Maybe related with #4754 ?

It is totally my mistake because I misunderstood following sentence in schema.fbs :(

  // An index that refers to the buffers table at the root of the model. Or,
  // if there is no data buffer associated (i.e. intermediate results), then
  // this is 0 (which refers to an always existent empty buffer).

I thought that no data buffer associated means that not constant.
However, 0 index buffer is used for dynamic tensor.

I will fix it right now...!

With #7257, following result is generated for mobilenet_v1

[#0 b'' (MAIN)]

#0 b'' (MAIN) input tensors: [0]
    Tensor    0 : buffer 1     |  Empty | FLOAT32 | Memory 588.0K | Shape [1, 224, 224, 3] (b'input')
#0 b'' (MAIN) output tensors: [88]
    Tensor   88 : buffer 89    |  Empty | FLOAT32 | Memory 3.9K   | Shape [1, 1001] (b'MobilenetV1/Predictions/Reshape_1')

Operator 0: CONV_2D
    Fused Activation: RELU6
    Input Tensors[0, 1, 2]
        Tensor    0 : buffer 1     |  Empty | FLOAT32 | Memory 588.0K | Shape [1, 224, 224, 3] (b'input')
        Tensor    1 : buffer 2     | Filled | FLOAT32 | Memory 3.4K   | Shape [32, 3, 3, 3] (b'MobilenetV1/Conv2d_0/weights')
        Tensor    2 : buffer 3     | Filled | FLOAT32 | Memory 128.0B | Shape [32] (b'MobilenetV1/MobilenetV1/Conv2d_0/convolution_bias')
    Output Tensors[3]
        Tensor    3 : buffer 4     |  Empty | FLOAT32 | Memory 1.5M   | Shape [1, 112, 112, 32] (b'MobilenetV1/MobilenetV1/Conv2d_0/Relu6')
    Options
        Stride W:H = 2:2, Dilation W:H = 1:1, Padding = SAME

...
Was this page helpful?
0 / 5 - 0 ratings