Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions backends/nxp/backend/ir/converter/builder/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ def _make_outputs_channels_first(self):

self.get_sub_graph().outputs.tmp_outputs = new_outputs

def _keep_one_empty_buffer(self):
"""Create a single empty `Buffer` object and assign it to all tensors in the model that don't have static data."""
empty_buffer = self.get_first_empty_buffer()

for t in self.get_tensors().vector:
if tensor_has_data(t):
# The buffer of `t` is not empty.
continue

if t.tmp_buffer == empty_buffer:
# Already optimized.
continue

if t.is_variable:
# The data of the tensor will change at runtime, so it shouldn't share the buffer with other tensors.
continue

# It's safe to replace the buffer.
t.tmp_buffer = empty_buffer

def finish(self) -> tflite_model.Model:
"""Finalize and optimize the converted TFLite model. Then return it.

Expand All @@ -430,6 +450,8 @@ def finish(self) -> tflite_model.Model:
self.conversion_config.optimization_blacklist,
)

self._keep_one_empty_buffer()

# Remove outputs, which are not produced by any node. Otherwise, there would be errors after inference.
operator_outputs = []
for op in self.get_operators().vector:
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions backends/nxp/backend/ir/tflite_optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
from executorch.backends.nxp.backend.ir.tflite_optimizer.optimizations.fuse_fully_connected_and_add_operators import (
FuseFullyConnectedAndAddOperators,
)
from executorch.backends.nxp.backend.ir.tflite_optimizer.optimizations.keep_one_empty_buffer import (
KeepOneEmptyBuffer,
)
from executorch.backends.nxp.backend.ir.tflite_optimizer.optimizations.move_relu_before_concat import (
MoveActivationBeforeConcatenation,
)
Expand All @@ -36,7 +33,6 @@


class Optimization(Enum):
KEEP_ONE_EMPTY_BUFFER = 0
FUSE_ACTIVATION_FUNCTIONS = 1
FUSE_FULLY_CONNECTED_AND_ADD = 2

Expand Down Expand Up @@ -76,9 +72,6 @@ def __init__(
self._builder = builder

self.optimization_map = {
Optimization.KEEP_ONE_EMPTY_BUFFER: KeepOneEmptyBuffer(
builder, conversion_config
),
Optimization.FUSE_ACTIVATION_FUNCTIONS: FuseActivationFunctions(
builder, conversion_config
),
Expand Down
Loading