From 78e62aa07c946a7942dcbb027031ffee66a08c49 Mon Sep 17 00:00:00 2001 From: lucylq Date: Fri, 18 Jul 2025 22:14:03 -0700 Subject: [PATCH] Add test when there are no segments Differential Revision: D78568839 Pull Request resolved: https://github.com/pytorch/executorch/pull/12646 (cherry picked from commit 4d7f9cacd60dfc94fd28a7ba87785e12f1b66b94) --- runtime/executor/program.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/runtime/executor/program.cpp b/runtime/executor/program.cpp index 238c806b1d6..6550c047e49 100644 --- a/runtime/executor/program.cpp +++ b/runtime/executor/program.cpp @@ -172,7 +172,18 @@ Result get_execution_plan( // 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() > 1) { + constant_segment->offsets()->size() > 0) { + if (constant_segment->offsets()->size() == 1) { + // No constants; the constant segment is empty and does not + // need to be loaded. + return Program( + loader, + segment_base_offset, + std::move(program_data.get()), + flatbuffer_program, + /*constant_segment_data=*/FreeableBuffer{}, + std::move(pte_data_map)); + } // The constant data is inside a separate segment. const auto* constant_buffer = flatbuffer_program->constant_buffer(); ET_CHECK_OR_RETURN_ERROR(