Skip to content

Do not load constant_segment if only the placeholder exists #5229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions extension/runner_util/inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Result<BufferCleanup> prepare_input_tensors(Method& method) {
for (size_t i = 0; i < num_inputs; i++) {
auto tag = method_meta.input_tag(i);
if (!tag.ok()) {
BufferCleanup cleanup({inputs, num_allocated});
return tag.error();
}
if (tag.get() != Tag::Tensor) {
Expand Down
5 changes: 4 additions & 1 deletion runtime/executor/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ Result<executorch_flatbuffer::ExecutionPlan*> get_execution_plan(

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