File tree Expand file tree Collapse file tree 3 files changed +22
-46
lines changed Expand file tree Collapse file tree 3 files changed +22
-46
lines changed Original file line number Diff line number Diff line change @@ -412,6 +412,26 @@ def _make_outputs_channels_first(self):
412
412
413
413
self .get_sub_graph ().outputs .tmp_outputs = new_outputs
414
414
415
+ def _keep_one_empty_buffer (self ):
416
+ """Create a single empty `Buffer` object and assign it to all tensors in the model that don't have static data."""
417
+ empty_buffer = self .get_first_empty_buffer ()
418
+
419
+ for t in self .get_tensors ().vector :
420
+ if tensor_has_data (t ):
421
+ # The buffer of `t` is not empty.
422
+ continue
423
+
424
+ if t .tmp_buffer == empty_buffer :
425
+ # Already optimized.
426
+ continue
427
+
428
+ if t .is_variable :
429
+ # The data of the tensor will change at runtime, so it shouldn't share the buffer with other tensors.
430
+ continue
431
+
432
+ # It's safe to replace the buffer.
433
+ t .tmp_buffer = empty_buffer
434
+
415
435
def finish (self ) -> tflite_model .Model :
416
436
"""Finalize and optimize the converted TFLite model. Then return it.
417
437
@@ -430,6 +450,8 @@ def finish(self) -> tflite_model.Model:
430
450
self .conversion_config .optimization_blacklist ,
431
451
)
432
452
453
+ self ._keep_one_empty_buffer ()
454
+
433
455
# Remove outputs, which are not produced by any node. Otherwise, there would be errors after inference.
434
456
operator_outputs = []
435
457
for op in self .get_operators ().vector :
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 20
20
from executorch .backends .nxp .backend .ir .tflite_optimizer .optimizations .fuse_fully_connected_and_add_operators import (
21
21
FuseFullyConnectedAndAddOperators ,
22
22
)
23
- from executorch .backends .nxp .backend .ir .tflite_optimizer .optimizations .keep_one_empty_buffer import (
24
- KeepOneEmptyBuffer ,
25
- )
26
23
from executorch .backends .nxp .backend .ir .tflite_optimizer .optimizations .move_relu_before_concat import (
27
24
MoveActivationBeforeConcatenation ,
28
25
)
36
33
37
34
38
35
class Optimization (Enum ):
39
- KEEP_ONE_EMPTY_BUFFER = 0
40
36
FUSE_ACTIVATION_FUNCTIONS = 1
41
37
FUSE_FULLY_CONNECTED_AND_ADD = 2
42
38
@@ -76,9 +72,6 @@ def __init__(
76
72
self ._builder = builder
77
73
78
74
self .optimization_map = {
79
- Optimization .KEEP_ONE_EMPTY_BUFFER : KeepOneEmptyBuffer (
80
- builder , conversion_config
81
- ),
82
75
Optimization .FUSE_ACTIVATION_FUNCTIONS : FuseActivationFunctions (
83
76
builder , conversion_config
84
77
),
You can’t perform that action at this time.
0 commit comments