tensorflow / tensorflow/model-optimization
modify_model_interface removing input float tensor is not completed, memory allocator occupied this dummy tensor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 349
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 1
Description
1. System information
TFLM
Tensorflow r2.5
2. Code
code in tensorflow\tensorflow\lite\tools\optimize\modify_model_interface.cc
Function: RemoveInputTensor
code: c
// Removes the input tensor and the related operator.
for (auto tot : inputs) {
SubGraphT* subgraph = model->subgraphs.at(tot.subgraph_index).get();
TFLITE_DCHECK(tot.input_index < subgraph->tensors.size());
TFLITE_DCHECK(tot.op_index < subgraph->operators.size());
if (tot.input_index >= original_number_tensors) {
subgraph->tensors.erase(subgraph->tensors.begin() + tot.input_index); // DID NOT REMOVED
}
subgraph->operators.erase(subgraph->operators.begin() + tot.op_index);
subgraph->inputs[tot.model_index] = tot.output_index;
}
- We have float input/output from quantization aware model to, reduce tensor arena size, using tool "modify_model_interface" utility convert to int8 - int8.
- Convert result can run successfully, but memory allocator show unknown scratch buffer used.
To check it print memory plan enable TF_LITE_SHOW_MEMORY_USE in micro_allocator.cc, that show original float input tensor still exist.
0 (id=0): size=24576, offset=0, first_used=-1 last_used=-1
I think removing shift all other tensor index in the graph, that could not a easy to remove.
To workaround this I was resizing the dummy float input tensor to smaller one, and keep as it.
Thanks
Jim
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tensorflow/tensorflow/lite/tools/optimize/modify_model_interface.cc at RemoveInputTensor, then inspect the memory report enabled by TF_LITE_SHOW_MEMORY_USE in micro_allocator.cc. Reproduce the float-input/output conversion to int8-int8 and verify that the original dummy float input no longer occupies the tensor arena without breaking the converted model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100