From 096563546742ba81adb6f012ab718d196a48e02d Mon Sep 17 00:00:00 2001 From: David Davis Date: Mon, 13 Jul 2026 11:10:56 -0700 Subject: [PATCH] Fix benchmark tool alternate profiler (#3629) @tensorflow/micro Set the alternate profiler in the benchmark tool prior to the `Prepare` phase (before calling `MicroInterpreter::AllocateTensors`). This is because the DECODE operator requires the alternate `MicroProfilerInterface` to already be initialized during the `Prepare` phase. Previously the alternate profiler was only required during the `Eval` phase with the legacy compression code. This fix does not change the functionality of the benchmark tool with respect to the legacy compression. bug=#3628 --- .../benchmarking/generic_model_benchmark.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc b/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc index 0bed434e..e311448e 100644 --- a/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc +++ b/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc @@ -259,6 +259,15 @@ int Benchmark(const uint8_t* model_data, tflite::PrettyPrintType print_type) { profiler.EndEvent(event_handle); #endif // USE_ALT_DECOMPRESSION_MEM + if (using_compression) { + MicroPrintf("profiler2 %p", &profiler2); + status = interpreter.SetAlternateProfiler(&profiler2); + if (status != kTfLiteOk) { + MicroPrintf("tflite::MicroInterpreter::SetAlternateProfiler failed"); + return -1; + } + } + event_handle = profiler.BeginEvent("tflite::MicroInterpreter::AllocateTensors"); status = interpreter.AllocateTensors(); @@ -271,14 +280,6 @@ int Benchmark(const uint8_t* model_data, tflite::PrettyPrintType print_type) { profiler.LogTicksPerTagCsv(); profiler.ClearEvents(); - if (using_compression) { - status = interpreter.SetAlternateProfiler(&profiler2); - if (status != kTfLiteOk) { - MicroPrintf("tflite::MicroInterpreter::SetAlternateProfiler failed"); - return -1; - } - } - MicroPrintf(""); // null MicroPrintf serves as a newline. // For streaming models, the interpreter will return kTfLiteAbort if the