[PATCH] D133451: [MLGO] Make TFLiteUtils throw an error if some features haven't been passed to the model

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 7 13:41:43 PDT 2022


aidengrossman created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In the Tensorflow C lib utilities, an error gets thrown if some features
haven't gotten passed into the model (due to differences in ordering
which now don't exist with the transition to TFLite). However, this is
not currently the case when using TFLiteUtils. This patch makes some
minor changes to throw an error when not all inputs of the model have
been passed, which when not handled will result in a seg fault within
TFLite.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133451

Files:
  llvm/lib/Analysis/TFLiteUtils.cpp


Index: llvm/lib/Analysis/TFLiteUtils.cpp
===================================================================
--- llvm/lib/Analysis/TFLiteUtils.cpp
+++ llvm/lib/Analysis/TFLiteUtils.cpp
@@ -131,6 +131,7 @@
   for (size_t I = 0; I < Interpreter->outputs().size(); ++I)
     OutputsMap[Interpreter->GetOutputName(I)] = I;
 
+  size_t NumberFeaturesPassed = 0;
   for (size_t I = 0; I < InputSpecs.size(); ++I) {
     auto &InputSpec = InputSpecs[I];
     auto MapI = InputsMap.find(InputSpec.name() + ":" +
@@ -144,6 +145,14 @@
       return;
     std::memset(Input[I]->data.data, 0,
                 InputSpecs[I].getTotalTensorBufferSize());
+    ++NumberFeaturesPassed;
+  }
+
+  if (NumberFeaturesPassed < Interpreter->inputs().size()) {
+    // we haven't passed all the required features to the model, throw an error.
+    errs() << "Required feature(s) have not been passed to the ML model";
+    invalidate();
+    return;
   }
 
   for (size_t I = 0; I < OutputSpecsSize; ++I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133451.458550.patch
Type: text/x-patch
Size: 985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220907/d38ca44f/attachment.bin>


More information about the llvm-commits mailing list