utvm_staticrt_codegen icon indicating copy to clipboard operation
utvm_staticrt_codegen copied to clipboard

Codegen not working properly for multi-input models

Open PhilippvK opened this issue 4 years ago • 3 comments

I have just realized that multi-output TFLite models do result in wrong output values using the utvm_staticrt_codegen. I have not look deeper into just but wanted to document this issue here. Will comment if found something out.

PhilippvK avatar Sep 23 '21 00:09 PhilippvK

I uploaded the model to reproduce the bug here because github does not allow attaching .tflite files in comments:

Direct download link: https://github.com/PhilippvK/tensorflow-operators-cmake/releases/download/v0.1/model_with_multiple_outputs.tflite

Model graph:

model_with_multiple_outputs tflite

PhilippvK avatar Sep 23 '21 00:09 PhilippvK

Ooops, it is actually not a problem of multi-output models but rather multi-input ones.

For the given graph, TVMWrap_GetNumInputs seems to return 6 instead of 3.

The generated inArgInfo looks like this which is probably because of the reused inputs by multiple operators:

static const ArgInfo inArgInfo[] = {{&g_storage_0[0],8}, {&g_storage_1[0],8}, {&g_storage_1[0],8}, {&g_storage_3[0],8}, {&g_storage_0[0],8}, {&g_storage_3[0],8}, };

PhilippvK avatar Sep 23 '21 00:09 PhilippvK

There is probably a check missing here to see if the input already has an arg assigned to it:

https://github.com/tum-ei-eda/utvm_staticrt_codegen/blob/master/src/TVMInfoExtraction.c#L190

Could also add a sanity check whether that previously assigned arg points to the same storage+offset.

Also, the order of inputs/outputs might be wrong for multi-in/out models, because they are just added in their op order. The correct order is probably the one in the GraphExecutor struct. Considering that I'd suggest a refactor where we just remember the EntryID->Arg_Info* mapping while going through the ops and later go through ins/outs in correct order.

rafzi avatar Sep 23 '21 12:09 rafzi