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 14 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
Show all changes
14 commits
Select commit Hold shift + click to select a range
940a338
[ExecuTorch][#10447] Extend `PyBundledModule` with `extension.Bundled…
Apr 24, 2025
a9498e7
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
Apr 24, 2025
fc541bb
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
Apr 24, 2025
cea7e74
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
Apr 24, 2025
1a45110
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 29, 2025
5d0c373
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 29, 2025
2ee4772
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
b6f52e2
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
4cc4721
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
c047287
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
580d013
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
f53e004
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
ec10e18
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
6a22698
Update on "[ExecuTorch][#10447] Extend `PyBundledModule` with `extens…
zhenyan-zhang-meta Apr 30, 2025
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
16 changes: 0 additions & 16 deletions devtools/bundled_program/test/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@
# LICENSE file in the root directory of this source tree.

# flake8: noqa: F401
import functools
import inspect
import os
import random
import unittest
from typing import Callable, Dict, Optional, Tuple, Type

import executorch.exir as exir

import executorch.exir.control_flow as control_flow

# @manual=//executorch/extension/pytree:pybindings
import executorch.extension.pytree as pytree

import torch

from executorch.devtools.bundled_program.core import BundledProgram
from executorch.devtools.bundled_program.serialize import (
Expand All @@ -35,7 +21,6 @@
try:
from executorch.extension.pybindings.portable_lib import (
_load_bundled_program_from_buffer,
_load_for_executorch_from_buffer,
_load_for_executorch_from_bundled_program,
)

Expand All @@ -47,7 +32,6 @@
try:
from executorch.extension.pybindings.aten_lib import ( # @manual=//executorch/extension/pybindings:aten_lib
_load_bundled_program_from_buffer,
_load_for_executorch_from_buffer,
_load_for_executorch_from_bundled_program,
)

Expand Down
27 changes: 14 additions & 13 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/bundled_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 @@ -96,6 +97,7 @@ using ::executorch::ET_RUNTIME_NAMESPACE::Program;
using ::executorch::extension::BufferDataLoader;
using ::executorch::extension::MallocMemoryAllocator;
using ::executorch::extension::MmapDataLoader;
using ::executorch::extension::ET_BUNDLED_MODULE_NAMESPACE::BundledModule;
using ::executorch::runtime::ArrayRef;
using ::executorch::runtime::DataLoader;
using ::executorch::runtime::Error;
Expand Down Expand Up @@ -442,11 +444,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 +843,20 @@ 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 outputs = m.execute(method_name, testset_idx);

THROW_IF_ERROR(
status,
"load_bundled_input failed with status 0x%" PRIx32,
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);
outputs.error(),
"Execution failed with status 0x%" PRIx32,
static_cast<uint32_t>(outputs.error()));

auto 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:bundled_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:bundled_module_aten",
"//executorch/devtools/bundled_program:runtime_aten",
"//executorch/runtime/executor/test:test_backend_compiler_lib_aten",
"//executorch/devtools/etdump:etdump_flatcc",
Expand Down