Skip to content

[ExecuTorch][#10447] Extend PyBundledModule with extension.BundledModule #10450

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

Open
wants to merge 4 commits into
base: gh/zhenyan-zhang-meta/6/base
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 deletions extension/pybindings/pybindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <executorch/extension/data_loader/buffer_data_loader.h>
#include <executorch/extension/data_loader/mmap_data_loader.h>
#include <executorch/extension/memory_allocator/malloc_memory_allocator.h>
#include <executorch/extension/module/module.h>
#include <executorch/extension/threadpool/threadpool.h>
#include <executorch/runtime/backend/interface.h>
#include <executorch/runtime/core/data_loader.h>
Expand Down Expand Up @@ -442,11 +443,12 @@ inline std::unique_ptr<Module> load_module_from_file(

static constexpr size_t kDEFAULT_BUNDLED_INPUT_POOL_SIZE = 16 * 1024U;

struct PyBundledModule final {
struct PyBundledModule : public BundledModule {
explicit PyBundledModule(
const py::bytes& buffer,
uint32_t bundled_input_pool_size)
: bundled_program_ptr_(buffer),
: BundledModule(buffer.cast<std::string_view>().data()),
bundled_program_ptr_(buffer),
program_ptr_(static_cast<const void*>(
bundled_program_flatbuffer::GetBundledProgram(
get_bundled_program_ptr())
Expand Down Expand Up @@ -840,22 +842,26 @@ struct PyModule final {
size_t testset_idx,
double rtol = 1e-5,
double atol = 1e-8) {
const void* bundled_program_ptr = m.get_bundled_program_ptr();
auto& method = module_->get_method(method_name);
Error status = executorch::BUNDLED_PROGRAM_NAMESPACE::load_bundled_input(
method, bundled_program_ptr, testset_idx);
auto status = m.load_bundled_input(method_name, testset_idx);
THROW_IF_ERROR(
status,
"load_bundled_input failed with status 0x%" PRIx32,
"Load input from bundled to method failed with status %" PRIu32,
static_cast<uint32_t>(status));
py::list outputs = plan_execute(method_name);
status = executorch::BUNDLED_PROGRAM_NAMESPACE::verify_method_outputs(
method, bundled_program_ptr, testset_idx, rtol, atol);

auto outputs = m.Module::execute(method_name);

THROW_IF_ERROR(
outputs.error(),
"Execution failed with status 0x%" PRIx32,
static_cast<uint32_t>(outputs.error()));

status = m.verify_method_outputs(method_name, testset_idx, rtol, atol);
THROW_IF_ERROR(
status,
"Result verification failed with status %" PRIu32,
static_cast<uint32_t>(status));
return outputs;

return get_outputs_as_py_list(outputs.get());
}

py::list plan_execute(
Expand Down
2 changes: 2 additions & 0 deletions shim_et/xplat/executorch/extension/pybindings/pybindings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PORTABLE_MODULE_DEPS = [
"//executorch/extension/data_loader:buffer_data_loader",
"//executorch/extension/data_loader:mmap_data_loader",
"//executorch/extension/memory_allocator:malloc_memory_allocator",
"//executorch/extension/module:module",
"//executorch/runtime/executor/test:test_backend_compiler_lib",
"//executorch/devtools/etdump:etdump_flatcc",
] + get_all_cpu_backend_targets()
Expand All @@ -28,6 +29,7 @@ ATEN_MODULE_DEPS = [
"//executorch/extension/data_loader:buffer_data_loader",
"//executorch/extension/data_loader:mmap_data_loader",
"//executorch/extension/memory_allocator:malloc_memory_allocator",
"//executorch/extension/module:module_aten",
"//executorch/devtools/bundled_program:runtime_aten",
"//executorch/runtime/executor/test:test_backend_compiler_lib_aten",
"//executorch/devtools/etdump:etdump_flatcc",
Expand Down
Loading