tensorflow / community

Stores documents used by the TensorFlow developer community
Apache License 2.0
1.26k stars 576 forks source link

RFC: Micro mutable op resolver generator #408

Closed mansnils closed 2 years ago

mansnils commented 2 years ago

This RFC will be open for comment until Friday, February 25th, 2022.

MicroMutableOpResolver Generation

Status Proposed
RFC # 408
Author(s) Sebastian Larsson (sebastian.larsson@arm.com), Oscar Andersson (oscar.andersson@arm.com), Måns Nilsson (mans.nilsson@arm.com)
Sponsor Advait Jain (advaitjain@google.com)

Objective

The objective is to simplify the process of parsing a tflite file for operators, and to generate code that can easily be integrated into an application.

Goals

When using an interpreter, you need an operator resolver. For this, you have two options:

1) Using the AllOpsResolver will link all the TFLM operators into the executable, which will add significantly to the memory footprint. A model typically only requires a small subset of operators and considering that microcontrollers have a limited memory size, MicroMutableOpResolver is a better option. Example usage of AllOpsResolver:

#include "tensorflow/lite/micro/all_ops_resolver.h"

tflite::AllOpsResolver resolver;

2) Using the MicroMutableOpResolver will include the operators specified by the user. This requires manually finding out which operators are used in the model, through the use of a visualization tool. Due to the smaller memory footprint this is preferable for real world usage, but it does require some more work for the user. This becomes impractical when running automated tests as you manually need to find the operators and add them. Example usage:

#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"

tflite::MicroMutableOpResolver<8> micro_op_resolver;

micro_op_resolver.AddConv2D();
micro_op_resolver.AddStridedSlice();
micro_op_resolver.AddMul();
micro_op_resolver.AddAdd();
micro_op_resolver.AddRelu6();
micro_op_resolver.AddPad();
micro_op_resolver.AddAveragePool2D();
micro_op_resolver.AddReshape();
ematejska commented 2 years ago

@advaitjain Has this been socialized on develpers@tensorflow.org? I don't see it there yet.

advaitjain commented 2 years ago

@advaitjain Has this been socialized on develpers@tensorflow.org? I don't see it there yet.

No it hasn't. I became the RFC sponsor a week ago with c236808 (#408)

The updated decision is that the proposed script will be implemented in the TFLM repository instead of the Tensorflow repo and additional discussion will happen on https://github.com/tensorflow/tflite-micro/issues/911.

https://github.com/tensorflow/tflite-micro/issues/911#issuecomment-1030287467 has some additional context.

@mansnils @ematejska, if one of you could close this PR, that would be great.

ematejska commented 2 years ago

Sure, thanks for the explanation. Closing.