[PATCH] D135739: [MLGO] Force persistency in tflite buffers.
Jacob Hegna via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 11 19:11:54 PDT 2022
jacobhegna created this revision.
jacobhegna added a reviewer: mtrofin.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jacobhegna requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When training large models, we encounter use-after-free bugs when
writing to the input tensors for various MLGO models. This patch fixes the
issue by marking the tensors as "persistent".
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135739
Files:
llvm/lib/Analysis/TFLiteUtils.cpp
Index: llvm/lib/Analysis/TFLiteUtils.cpp
===================================================================
--- llvm/lib/Analysis/TFLiteUtils.cpp
+++ llvm/lib/Analysis/TFLiteUtils.cpp
@@ -121,6 +121,15 @@
tflite::InterpreterBuilder Builder(*Model, Resolver);
Builder(&Interpreter);
+ // We assume the input buffers are valid for the lifetime of the interpreter.
+ // By default, tflite allocates memory in an arena and will periodically take
+ // away memory and reallocate it in a different location after evaluations in
+ // order to improve utilization of the buffers owned in the arena. So, we
+ // explicitly mark our input buffers as persistent to avoid this behavior.
+ for (size_t I = 0; I < Interpreter->inputs().size(); ++I)
+ Interpreter->tensor(I)->allocation_type =
+ TfLiteAllocationType::kTfLiteArenaRwPersistent;
+
if (!Interpreter ||
Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
invalidate();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135739.466995.patch
Type: text/x-patch
Size: 966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221012/f6050f90/attachment.bin>
More information about the llvm-commits
mailing list