Skip to content

Commit 74e9313

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
move codegen pybindings out of public pybindings lib (#131)
Summary: Pull Request resolved: #131 These are only used by codegen. Moving them out of the general pybindings lib and restricting visibility. As a side note I dont think any of this stuff actually has to happen in c++. In fact it seems like itd be easier to do this on the Python Version of the schema object through deserialize_for_json. Reviewed By: larryliu0820, dbort Differential Revision: D48671946 fbshipit-source-id: e87c612de2505f139c26463e53d00e3406ac640c
1 parent b04fec2 commit 74e9313

File tree

10 files changed

+15
-377
lines changed

10 files changed

+15
-377
lines changed

codegen/tools/gen_oplist.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,38 @@ class KernelType(IntEnum):
7878

7979

8080
def _get_operators(model_file: str) -> List[str]:
81-
# pyre-ignore: Undefined import [21]: Could not find a module corresponding to import `executorch.extension.pybindings.operator`.
82-
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `operator`
83-
from executorch.extension.pybindings.operator import (
81+
from executorch.codegen.tools.selective_build import (
8482
_get_program_from_buffer,
8583
_get_program_operators,
8684
)
8785

8886
print("Processing model file: ", model_file)
8987
with open(model_file, "rb") as f:
9088
buf = f.read()
91-
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `operator`.
89+
9290
program = _get_program_from_buffer(buf)
93-
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `operator`.
9491
operators = _get_program_operators(program)
9592
print(f"Model file loaded, operators are: {operators}")
9693
return operators
9794

9895

9996
def _get_kernel_metadata_for_model(model_file: str) -> Dict[str, List[str]]:
10097

101-
from executorch.extension.pybindings.operator import (
98+
from executorch.codegen.tools.selective_build import (
10299
_get_io_metadata_for_program_operators,
103100
_get_program_from_buffer,
104-
IOMetaData,
101+
_IOMetaData,
105102
)
106103

107104
with open(model_file, "rb") as f:
108105
buf = f.read()
109-
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `operator`.
106+
110107
program = _get_program_from_buffer(buf)
111-
# pyre-ignore: Undefined attribute [16]: Module `executorch.extension.pybindings` has no attribute `operator`.
112108
operators_with_io_metadata = _get_io_metadata_for_program_operators(program)
113109

114110
op_kernel_key_list: Dict[str, List[str]] = {}
115111

116-
# pyre-ignore: Undefined or invalid type [11]: Annotation `IOMetaData` is not defined as a type.Pyre
117-
specialized_kernels: Set[List[IOMetaData]]
112+
specialized_kernels: Set[List[_IOMetaData]]
118113
for op_name, specialized_kernels in operators_with_io_metadata.items():
119114
print(op_name)
120115
if op_name not in op_kernel_key_list:
@@ -124,7 +119,7 @@ def _get_kernel_metadata_for_model(model_file: str) -> Dict[str, List[str]]:
124119
version = "v1"
125120
kernel_key = version + "/"
126121
for io_metadata in specialized_kernel:
127-
if io_metadata.type in [
122+
if io_metadata.kernel_type in [
128123
KernelType.TENSOR,
129124
KernelType.TENSOR_LIST,
130125
KernelType.OPTIONAL_TENSOR_LIST,

codegen/tools/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def define_common_targets(is_fbcode = False):
1818
external_deps = ["torchgen"],
1919
deps = select({
2020
"DEFAULT": [],
21-
"ovr_config//os:linux": [] if runtime.is_oss else ["//executorch/extension/pybindings:operator"], # TODO(larryliu0820): pybindings:operator doesn't build in OSS yet
21+
"ovr_config//os:linux": [] if runtime.is_oss else ["//executorch/codegen/tools/fb:selective_build"], # TODO(larryliu0820) :selective_build doesn't build in OSS yet
2222
}),
2323
)
2424

extension/pybindings/module.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <executorch/runtime/platform/profiler.h>
2727
#include <executorch/runtime/platform/runtime.h>
2828
#include <executorch/schema/bundled_program_schema_generated.h>
29-
#include <executorch/schema/program_generated.h>
3029
#include <executorch/util/TestMemoryConfig.h>
3130
#include <executorch/util/bundled_program_verification.h>
3231
#include <executorch/util/read_file.h>
@@ -463,7 +462,7 @@ void create_profile_block(const std::string& name) {
463462

464463
} // namespace
465464

466-
void init_module_functions(py::module_& m) {
465+
PYBIND11_MODULE(EXECUTORCH_PYTHON_MODULE_NAME, m) {
467466
m.def("_load_for_executorch", PyModule::load_from_file, py::arg("path"));
468467
m.def(
469468
"_load_for_executorch_from_buffer",

extension/pybindings/module_stub.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

extension/pybindings/pybindings.cpp

Lines changed: 0 additions & 273 deletions
This file was deleted.

0 commit comments

Comments
 (0)