Skip to content

Commit

Permalink
Remove dependency from pytorch core as git submodule (pytorch#3530)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: pytorch#3530

Reviewed By: larryliu0820

Differential Revision: D57078775

Pulled By: mergennachin

fbshipit-source-id: 5a6047bd779e59e7833ca01453ca8efb4657cdab
  • Loading branch information
mergennachin authored and facebook-github-bot committed May 8, 2024
1 parent c86128e commit 0492eeb
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 69 deletions.
1 change: 0 additions & 1 deletion .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
ignore = \
.git, \
**/.git, \
third-party/pytorch/third_party, \
cmake-out, \
pip-out
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "third-party/flatbuffers"]
path = third-party/flatbuffers
url = https://github.com/google/flatbuffers.git
[submodule "third-party/pytorch"]
path = third-party/pytorch
url = https://github.com/pytorch/pytorch.git
[submodule "third-party/gflags"]
path = third-party/gflags
url = https://github.com/gflags/gflags.git
Expand Down
5 changes: 0 additions & 5 deletions backends/cadence/hifi/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)

Expand Down
15 changes: 12 additions & 3 deletions build/Codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,28 @@ function(generate_bindings_for_kernels)

# Command to generate selected_operators.yaml from custom_ops.yaml.
file(GLOB_RECURSE _codegen_templates "${EXECUTORCH_ROOT}/codegen/templates/*")
file(GLOB_RECURSE _torchgen_srcs "${TORCH_ROOT}/torchgen/*.py")

set(_out_dir ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME})
# By default selective build output is selected_operators.yaml
set(_oplist_yaml ${_out_dir}/selected_operators.yaml)

# Command to codegen C++ wrappers to register custom ops to both PyTorch and
# Executorch runtime.
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"
OUTPUT_VARIABLE site-packages-out
ERROR_VARIABLE site-packages-out-error
RESULT_VARIABLE site-packages-result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
file(GLOB_RECURSE _torchgen_srcs "${site-packages-out}/torchgen/*.py")
set(_gen_command
"${PYTHON_EXECUTABLE}" -m torchgen.gen_executorch
--source-path=${EXECUTORCH_ROOT}/codegen --install-dir=${_out_dir}
--tags-path=${TORCH_ROOT}/aten/src/ATen/native/tags.yaml
--aten-yaml-path=${TORCH_ROOT}/aten/src/ATen/native/native_functions.yaml
--tags-path=${site-packages-out}/torchgen/packaged/ATen/native/tags.yaml
--aten-yaml-path=${site-packages-out}/torchgen/packaged/ATen/native/native_functions.yaml
--op-selection-yaml-path=${_oplist_yaml}
)

Expand Down
4 changes: 0 additions & 4 deletions configurations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
endif()
# Source root directory for pytorch. This is needed for kernel binding.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)

Expand Down
5 changes: 0 additions & 5 deletions examples/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

add_compile_options("-Wall" "-Werror")

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
Expand Down
5 changes: 0 additions & 5 deletions examples/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()

# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

set(_common_compile_options -Wno-deprecated-declarations -fPIC)

# Let files say "include <executorch/path/to/header.h>".
Expand Down
5 changes: 0 additions & 5 deletions examples/models/llama2/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
endif()

# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

set(_common_compile_options -Wno-deprecated-declarations -fPIC)

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
Expand Down
4 changes: 0 additions & 4 deletions examples/portable/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
endif()
# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
Expand Down
4 changes: 0 additions & 4 deletions examples/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ project(qualcomm_runner_example)
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
Expand Down
4 changes: 0 additions & 4 deletions examples/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

include(${EXECUTORCH_ROOT}/build/Utils.cmake)
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
Expand Down
3 changes: 1 addition & 2 deletions install_requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ done
#

# Since ExecuTorch often uses main-branch features of pytorch, only the nightly
# pip versions will have the required features. The NIGHTLY_VERSION value should
# agree with the third-party/pytorch pinned submodule commit.
# pip versions will have the required features.
#
# NOTE: If a newly-fetched version of the executorch repo changes the value of
# NIGHTLY_VERSION, you should re-run this script to install the necessary
Expand Down
4 changes: 0 additions & 4 deletions kernels/optimized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
# Source root directory for pytorch. This is needed for kernel binding.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

set(_common_compile_options -Wno-deprecated-declarations)

Expand Down
4 changes: 0 additions & 4 deletions kernels/portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

set(_common_compile_options -Wno-deprecated-declarations)

Expand Down
4 changes: 0 additions & 4 deletions kernels/quantized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ endif()
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
# Source root directory for pytorch.
if(NOT TORCH_ROOT)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
endif()

set(_common_compile_options -Wno-deprecated-declarations)

Expand Down
38 changes: 27 additions & 11 deletions third-party/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,31 @@ prebuilt_python_library_defs = {

add_prebuilt_python_library_targets(prebuilt_python_library_defs)

runtime.genrule(
name = "torchgen_files",
outs = {
"torchgen": ["torchgen"],
},
default_outs = ["."],
srcs = ["link_torch.sh"],
bash = "bash $SRCS -f torchgen -o ${OUT}",
)

runtime.genrule(
name = "yaml_files",
outs = {
"tags": ["aten/src/ATen/native/tags.yaml"],
"native_functions": ["aten/src/ATen/native/native_functions.yaml"],
},
default_outs = ["."],
srcs = ["link_torch.sh"],
bash = "mkdir -p ${OUT}/aten/src/ATen/native/ && bash $SRCS -f torchgen/packaged/ATen/native/tags.yaml,torchgen/packaged/ATen/native/native_functions.yaml -o ${OUT}/aten/src/ATen/native/",
)

runtime.python_library(
name = "torchgen",
srcs = subdir_glob(
[
("pytorch/torchgen", "**/*.py"),
],
),
base_module = "torchgen",
srcs = [":torchgen_files[torchgen]"] + glob(["**/*.py"]),
base_module = "torchgen,torchgen.executorch",
visibility = ["PUBLIC"],
deps = [
"//third-party:pyyaml",
Expand Down Expand Up @@ -78,11 +95,10 @@ runtime.python_binary(

runtime.filegroup(
name = "aten_src_path",
srcs = subdir_glob([
("pytorch", "aten/src/ATen/templates/*"),
("pytorch", "aten/src/ATen/native/native_functions.yaml"),
("pytorch", "aten/src/ATen/native/tags.yaml"),
]),
srcs = [
":yaml_files[tags]",
":yaml_files[native_functions]",
],
visibility = [
"PUBLIC",
],
Expand Down
1 change: 0 additions & 1 deletion third-party/pytorch
Submodule pytorch deleted from b19842

0 comments on commit 0492eeb

Please sign in to comment.