Skip to content

Commit 41b463e

Browse files
lucylqfacebook-github-bot
authored andcommitted
Do not load constant_segment if only the placeholder exists (#5229)
Summary: Pull Request resolved: #5229 1. 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. (T201034228) 2. Clean up before returning error in `prepare_input_tensors`. (T201103889) Reviewed By: dbort Differential Revision: D62455987 fbshipit-source-id: ecd3ff792e4501b00c778242e89bdb97a6211e64
1 parent 92d0559 commit 41b463e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

extension/runner_util/inputs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Result<BufferCleanup> prepare_input_tensors(Method& method) {
3131
for (size_t i = 0; i < num_inputs; i++) {
3232
auto tag = method_meta.input_tag(i);
3333
if (!tag.ok()) {
34+
BufferCleanup cleanup({inputs, num_allocated});
3435
return tag.error();
3536
}
3637
if (tag.get() != Tag::Tensor) {

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)