Skip to content

Remove remaining reference to torchgen.gen_executorch #11290

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

Merged
merged 1 commit into from
Jun 3, 2025
Merged
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
18 changes: 9 additions & 9 deletions codegen/api/et_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

from typing import TYPE_CHECKING

from executorch.codegen.api.types import (
ArrayRefCType,
BaseTypeToCppMapping,
OptionalCType,
scalarT,
tensorListT,
tensorT,
)

from torchgen import local
from torchgen.api.types import (
ArgName,
Expand Down Expand Up @@ -40,6 +31,15 @@
)
from typing_extensions import assert_never

from .types import (
ArrayRefCType,
BaseTypeToCppMapping,
OptionalCType,
scalarT,
tensorListT,
tensorT,
)


if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down
4 changes: 2 additions & 2 deletions codegen/api/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# flake8: noqa: F403, F401
from executorch.codegen.api.types.types import *
from .types import *

# flake8: noqa: F403, F401
from executorch.codegen.api.types.signatures import * # usort: skip
from .signatures import * # usort: skip
5 changes: 3 additions & 2 deletions codegen/api/types/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from typing import TYPE_CHECKING

import torchgen.api.cpp as aten_cpp
from executorch.codegen.api.types.types import contextArg

from .types import contextArg


if TYPE_CHECKING:
Expand Down Expand Up @@ -73,4 +74,4 @@ def from_native_function(
)


from executorch.codegen.api import et_cpp
from .. import et_cpp
35 changes: 26 additions & 9 deletions codegen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@
from typing import Any, Callable, TextIO, TYPE_CHECKING

import yaml
from executorch.codegen.api import et_cpp
from executorch.codegen.api.custom_ops import (
ComputeNativeFunctionStub,
gen_custom_ops_registration,
)
from executorch.codegen.api.types import contextArg, ExecutorchCppSignature
from executorch.codegen.api.unboxing import Unboxing
from executorch.codegen.model import ETKernelIndex, ETKernelKey, ETParsedYaml
from executorch.codegen.parse import ET_FIELDS, parse_et_yaml, parse_et_yaml_struct

try:
from executorch.codegen.api import et_cpp
from executorch.codegen.api.custom_ops import (
ComputeNativeFunctionStub,
gen_custom_ops_registration,
)
from executorch.codegen.api.types import contextArg, ExecutorchCppSignature
from executorch.codegen.api.unboxing import Unboxing
from executorch.codegen.model import ETKernelIndex, ETKernelKey, ETParsedYaml
from executorch.codegen.parse import ET_FIELDS, parse_et_yaml, parse_et_yaml_struct
except ImportError:
# If we build from source, executorch.codegen is not available.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noob q: why is this the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To build ET from source we need selective build and generated bindings. So these scripts will be called before they are being installed into site-packages.

from .api import et_cpp # type: ignore[no-redef]
from .api.custom_ops import ( # type: ignore
ComputeNativeFunctionStub,
gen_custom_ops_registration,
)
from .api.types import contextArg, ExecutorchCppSignature # type: ignore
from .api.unboxing import Unboxing # type: ignore
from .model import ETKernelIndex, ETKernelKey, ETParsedYaml # type: ignore
from .parse import ( # type: ignore[no-redef]
ET_FIELDS,
parse_et_yaml,
parse_et_yaml_struct,
)

# Parse native_functions.yaml into a sequence of NativeFunctions and Backend Indices.
from torchgen import dest
Expand Down
2 changes: 1 addition & 1 deletion codegen/test/test_executorch_custom_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import torchgen
from executorch.codegen.api.custom_ops import ComputeNativeFunctionStub
from executorch.codegen.gen import gen_headers
from executorch.codegen.model import ETKernelIndex
from torchgen.gen_executorch import gen_headers
from torchgen.model import Location, NativeFunction
from torchgen.selective_build.selector import SelectiveBuilder
from torchgen.utils import FileManager
Expand Down
8 changes: 4 additions & 4 deletions codegen/test/test_executorch_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import unittest

import yaml

from executorch.codegen.model import ETKernelIndex, ETKernelKey
from torchgen.gen import LineLoader
from torchgen.gen_executorch import (
from executorch.codegen.gen import (
ComputeCodegenUnboxedKernels,
gen_functions_declarations,
parse_yaml_files,
translate_native_yaml,
)

from executorch.codegen.model import ETKernelIndex, ETKernelKey
from torchgen.gen import LineLoader
from torchgen.model import (
BackendIndex,
BackendMetadata,
Expand Down
1 change: 1 addition & 0 deletions codegen/tools/gen_oplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# We can use relative import instead.
from ..parse import strip_et_fields


from torchgen.gen import LineLoader, parse_native_yaml_struct
from torchgen.selective_build.operator import SelectiveBuildOperator
from torchgen.selective_build.selector import merge_et_kernel_metadata
Expand Down
12 changes: 0 additions & 12 deletions third-party/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ runtime.python_binary(
_is_external_target = True,
)

runtime.python_binary(
name = "gen_executorch",
main_module = "torchgen.gen_executorch",
visibility = [
"PUBLIC",
],
deps = [
":torchgen",
],
_is_external_target = True,
)

runtime.filegroup(
name = "aten_src_path",
srcs = [
Expand Down
3 changes: 2 additions & 1 deletion tools/cmake/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ function(generate_bindings_for_kernels)
OUTPUT_STRIP_TRAILING_WHITESPACE
)
file(GLOB_RECURSE _torchgen_srcs "${torchgen-out}/*.py")
# Not using module executorch.codegen.gen because it's not installed yet.
set(_gen_command
"${PYTHON_EXECUTABLE}" -m torchgen.gen_executorch
"${PYTHON_EXECUTABLE}" -m codegen.gen
--source-path=${EXECUTORCH_ROOT}/codegen --install-dir=${_out_dir}
--tags-path=${torchgen-out}/packaged/ATen/native/tags.yaml
--aten-yaml-path=${torchgen-out}/packaged/ATen/native/native_functions.yaml
Expand Down
Loading