Skip to content

Commit 7974c9d

Browse files
author
zhenyanzhang
committed
[ExecuTorch][#10447] Extend PyBundledModule with extension.BundledModule
Pull Request resolved: #10450 #10447 # Context This issue is a step of #9638. In #9638, we want to have `extension.Module` as the single source of implementation in `pybindings`, which means that `pybindings.PyModule` should use `extension.Module` rather than its own `pybindings.Module`. # Proposal Now that we have `extension.BundledModule` ready, we want to test it out by having our existing `PyBundledModule` to extend it, and let `verify_result_with_bundled_expected_output` to use it, so that we can test out the whole thing with https://github.com/pytorch/executorch/blob/fb45e19055a92d2a91a4d4b7008e135232cbb14b/devtools/bundled_program/test/test_end2end.py ghstack-source-id: 280178134 Differential Revision: [D73564127](https://our.internmc.facebook.com/intern/diff/D73564127/)
1 parent cef0001 commit 7974c9d

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

extension/pybindings/pybindings.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <executorch/extension/data_loader/buffer_data_loader.h>
2424
#include <executorch/extension/data_loader/mmap_data_loader.h>
2525
#include <executorch/extension/memory_allocator/malloc_memory_allocator.h>
26+
#include <executorch/extension/module/module.h>
2627
#include <executorch/extension/threadpool/threadpool.h>
2728
#include <executorch/runtime/backend/interface.h>
2829
#include <executorch/runtime/core/data_loader.h>
@@ -442,11 +443,12 @@ inline std::unique_ptr<Module> load_module_from_file(
442443

443444
static constexpr size_t kDEFAULT_BUNDLED_INPUT_POOL_SIZE = 16 * 1024U;
444445

445-
struct PyBundledModule final {
446+
struct PyBundledModule : public BundledModule {
446447
explicit PyBundledModule(
447448
const py::bytes& buffer,
448449
uint32_t bundled_input_pool_size)
449-
: bundled_program_ptr_(buffer),
450+
: BundledModule(buffer.cast<std::string_view>().data()),
451+
bundled_program_ptr_(buffer),
450452
program_ptr_(static_cast<const void*>(
451453
bundled_program_flatbuffer::GetBundledProgram(
452454
get_bundled_program_ptr())
@@ -840,22 +842,26 @@ struct PyModule final {
840842
size_t testset_idx,
841843
double rtol = 1e-5,
842844
double atol = 1e-8) {
843-
const void* bundled_program_ptr = m.get_bundled_program_ptr();
844-
auto& method = module_->get_method(method_name);
845-
Error status = executorch::BUNDLED_PROGRAM_NAMESPACE::load_bundled_input(
846-
method, bundled_program_ptr, testset_idx);
845+
auto status = m.load_bundled_input(method_name, testset_idx);
847846
THROW_IF_ERROR(
848847
status,
849-
"load_bundled_input failed with status 0x%" PRIx32,
848+
"Load input from bundled to method failed with status %" PRIu32,
850849
static_cast<uint32_t>(status));
851-
py::list outputs = plan_execute(method_name);
852-
status = executorch::BUNDLED_PROGRAM_NAMESPACE::verify_method_outputs(
853-
method, bundled_program_ptr, testset_idx, rtol, atol);
850+
851+
auto outputs = m.Module::execute(method_name);
852+
853+
THROW_IF_ERROR(
854+
outputs.error(),
855+
"Execution failed with status 0x%" PRIx32,
856+
static_cast<uint32_t>(outputs.error()));
857+
858+
status = m.verify_method_outputs(method_name, testset_idx, rtol, atol);
854859
THROW_IF_ERROR(
855860
status,
856861
"Result verification failed with status %" PRIu32,
857862
static_cast<uint32_t>(status));
858-
return outputs;
863+
864+
return get_outputs_as_py_list(outputs.get());
859865
}
860866

861867
py::list plan_execute(

shim_et/xplat/executorch/extension/pybindings/pybindings.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PORTABLE_MODULE_DEPS = [
1616
"//executorch/extension/data_loader:buffer_data_loader",
1717
"//executorch/extension/data_loader:mmap_data_loader",
1818
"//executorch/extension/memory_allocator:malloc_memory_allocator",
19+
"//executorch/extension/module:module",
1920
"//executorch/runtime/executor/test:test_backend_compiler_lib",
2021
"//executorch/devtools/etdump:etdump_flatcc",
2122
] + get_all_cpu_backend_targets()
@@ -28,6 +29,7 @@ ATEN_MODULE_DEPS = [
2829
"//executorch/extension/data_loader:buffer_data_loader",
2930
"//executorch/extension/data_loader:mmap_data_loader",
3031
"//executorch/extension/memory_allocator:malloc_memory_allocator",
32+
"//executorch/extension/module:module_aten",
3133
"//executorch/devtools/bundled_program:runtime_aten",
3234
"//executorch/runtime/executor/test:test_backend_compiler_lib_aten",
3335
"//executorch/devtools/etdump:etdump_flatcc",

0 commit comments

Comments
 (0)