Skip to content

Commit 834e76a

Browse files
lucylqfacebook-github-bot
authored andcommitted
Do not load constant_segment if only the placeholder exists (#5229)
Summary: Pull Request resolved: #5229 If constant segment offsets only contains one value, it is the placeholder value for non-const tensors. This means the constant segment is empty, and does not need to be loaded. Differential Revision: D62455987
1 parent d38ca81 commit 834e76a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

runtime/executor/program.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,12 @@ Result<executorch_flatbuffer::ExecutionPlan*> get_execution_plan(
150150

151151
// Constant data may live inside the flatbuffer data (constant_buffer) or in a
152152
// separate segment (constant_segment). It should not be in both.
153+
// Check constant_segment->offsets()->size() > 1, as the offsets list will
154+
// always contain a placeholder value 0 for non-const tensors. If this is the
155+
// only offset, the constant segment is empty and does not need to be loaded.
153156
const auto* constant_segment = flatbuffer_program->constant_segment();
154157
if (constant_segment != nullptr && constant_segment->offsets() != nullptr &&
155-
constant_segment->offsets()->size() > 0) {
158+
constant_segment->offsets()->size() > 1) {
156159
// The constant data is inside a separate segment.
157160
const auto* constant_buffer = flatbuffer_program->constant_buffer();
158161
ET_CHECK_OR_RETURN_ERROR(

0 commit comments

Comments
 (0)