Skip to content

Commit a2ac96c

Browse files
malfetpytorchmergebot
authored andcommitted
[BE] Rectify some references to caffe2 (pytorch#140204)
- Rename `tools.build_pytorch_libs.build_caffe2` to `tools.build_pytorch_libs.build_pytorch` - Delete number of `if BUILD_CAFFE2` conditions Pull Request resolved: pytorch#140204 Approved by: https://github.com/huydhn, https://github.com/r-barnes, https://github.com/atalman
1 parent 5107d24 commit a2ac96c

File tree

3 files changed

+6
-81
lines changed

3 files changed

+6
-81
lines changed

setup.py

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
import setuptools.command.sdist
257257
from setuptools import Extension, find_packages, setup
258258
from setuptools.dist import Distribution
259-
from tools.build_pytorch_libs import build_caffe2
259+
from tools.build_pytorch_libs import build_pytorch
260260
from tools.generate_torch_version import get_torch_version
261261
from tools.setup_helpers.cmake import CMake
262262
from tools.setup_helpers.env import build_type, IS_DARWIN, IS_LINUX, IS_WINDOWS
@@ -339,7 +339,6 @@ def report(*args):
339339
cwd = os.path.dirname(os.path.abspath(__file__))
340340
lib_path = os.path.join(cwd, "torch", "lib")
341341
third_party_path = os.path.join(cwd, "third_party")
342-
caffe2_build_dir = os.path.join(cwd, "build")
343342

344343
# CMAKE: full path to python library
345344
if IS_WINDOWS:
@@ -484,7 +483,7 @@ def build_deps():
484483
check_submodules()
485484
check_pydep("yaml", "pyyaml")
486485
build_python = not BUILD_LIBTORCH_WHL
487-
build_caffe2(
486+
build_pytorch(
488487
version=version,
489488
cmake_python_library=cmake_python_library,
490489
build_python=build_python,
@@ -730,47 +729,6 @@ def run(self):
730729

731730
def build_extensions(self):
732731
self.create_compile_commands()
733-
# The caffe2 extensions are created in
734-
# tmp_install/lib/pythonM.m/site-packages/caffe2/python/
735-
# and need to be copied to build/lib.linux.... , which will be a
736-
# platform dependent build folder created by the "build" command of
737-
# setuptools. Only the contents of this folder are installed in the
738-
# "install" command by default.
739-
# We only make this copy for Caffe2's pybind extensions
740-
caffe2_pybind_exts = [
741-
"caffe2.python.caffe2_pybind11_state",
742-
"caffe2.python.caffe2_pybind11_state_gpu",
743-
"caffe2.python.caffe2_pybind11_state_hip",
744-
]
745-
if BUILD_LIBTORCH_WHL:
746-
caffe2_pybind_exts = []
747-
i = 0
748-
while i < len(self.extensions):
749-
ext = self.extensions[i]
750-
if ext.name not in caffe2_pybind_exts:
751-
i += 1
752-
continue
753-
fullname = self.get_ext_fullname(ext.name)
754-
filename = self.get_ext_filename(fullname)
755-
report(f"\nCopying extension {ext.name}")
756-
757-
relative_site_packages = (
758-
sysconfig.get_path("purelib")
759-
.replace(sysconfig.get_path("data"), "")
760-
.lstrip(os.path.sep)
761-
)
762-
src = os.path.join("torch", relative_site_packages, filename)
763-
if not os.path.exists(src):
764-
report(f"{src} does not exist")
765-
del self.extensions[i]
766-
else:
767-
dst = os.path.join(os.path.realpath(self.build_lib), filename)
768-
report(f"Copying {ext.name} from {src} to {dst}")
769-
dst_dir = os.path.dirname(dst)
770-
if not os.path.exists(dst_dir):
771-
os.makedirs(dst_dir)
772-
self.copy_file(src, dst)
773-
i += 1
774732

775733
# Copy functorch extension
776734
for i, ext in enumerate(self.extensions):
@@ -1060,9 +1018,7 @@ def make_relative_rpath_args(path):
10601018
################################################################################
10611019

10621020
extensions = []
1063-
excludes = ["tools", "tools.*"]
1064-
if not cmake_cache_vars["BUILD_CAFFE2"]:
1065-
excludes.extend(["caffe2", "caffe2.*"])
1021+
excludes = ["tools", "tools.*", "caffe2", "caffe2.*"]
10661022
if not cmake_cache_vars["BUILD_FUNCTORCH"]:
10671023
excludes.extend(["functorch", "functorch.*"])
10681024
packages = find_packages(exclude=excludes)
@@ -1082,18 +1038,6 @@ def make_relative_rpath_args(path):
10821038

10831039
# These extensions are built by cmake and copied manually in build_extensions()
10841040
# inside the build_ext implementation
1085-
if cmake_cache_vars["BUILD_CAFFE2"]:
1086-
extensions.append(
1087-
Extension(name="caffe2.python.caffe2_pybind11_state", sources=[]),
1088-
)
1089-
if cmake_cache_vars["USE_CUDA"]:
1090-
extensions.append(
1091-
Extension(name="caffe2.python.caffe2_pybind11_state_gpu", sources=[]),
1092-
)
1093-
if cmake_cache_vars["USE_ROCM"]:
1094-
extensions.append(
1095-
Extension(name="caffe2.python.caffe2_pybind11_state_hip", sources=[]),
1096-
)
10971041
if cmake_cache_vars["BUILD_FUNCTORCH"]:
10981042
extensions.append(
10991043
Extension(name="functorch._C", sources=[]),
@@ -1109,8 +1053,6 @@ def make_relative_rpath_args(path):
11091053

11101054
entry_points = {
11111055
"console_scripts": [
1112-
"convert-caffe2-to-onnx = caffe2.python.onnx.bin.conversion:caffe2_to_onnx",
1113-
"convert-onnx-to-caffe2 = caffe2.python.onnx.bin.conversion:onnx_to_caffe2",
11141056
"torchrun = torch.distributed.run:main",
11151057
],
11161058
"torchrun.logs_specs": [
@@ -1429,14 +1371,6 @@ def main():
14291371
"lib/*.lib",
14301372
]
14311373
)
1432-
if get_cmake_cache_vars()["BUILD_CAFFE2"]:
1433-
torch_package_data.extend(
1434-
[
1435-
"include/caffe2/**/*.h",
1436-
"include/caffe2/utils/*.h",
1437-
"include/caffe2/utils/**/*.h",
1438-
]
1439-
)
14401374
if get_cmake_cache_vars()["USE_TENSORPIPE"]:
14411375
torch_package_data.extend(
14421376
[
@@ -1477,9 +1411,6 @@ def main():
14771411

14781412
if not BUILD_LIBTORCH_WHL:
14791413
package_data["torchgen"] = torchgen_package_data
1480-
package_data["caffe2"] = [
1481-
"python/serialized_test/data/operator_test/*.zip",
1482-
]
14831414
else:
14841415
# no extensions in BUILD_LIBTORCH_WHL mode
14851416
extensions = []

tools/build_libtorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
pytorch_root = dirname(dirname(abspath(__file__)))
1010
sys.path.append(pytorch_root)
1111

12-
from tools.build_pytorch_libs import build_caffe2
12+
from tools.build_pytorch_libs import build_pytorch
1313
from tools.setup_helpers.cmake import CMake
1414

1515

@@ -24,7 +24,7 @@
2424
)
2525
options = parser.parse_args()
2626

27-
build_caffe2(
27+
build_pytorch(
2828
version=None,
2929
cmake_python_library=None,
3030
build_python=False,

tools/build_pytorch_libs.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import platform
5-
import shutil
65
from glob import glob
76

87
from setuptools import distutils # type: ignore[import]
@@ -71,7 +70,7 @@ def _create_build_env() -> dict[str, str]:
7170
return my_env
7271

7372

74-
def build_caffe2(
73+
def build_pytorch(
7574
version: str | None,
7675
cmake_python_library: str | None,
7776
build_python: bool,
@@ -87,8 +86,3 @@ def build_caffe2(
8786
if cmake_only:
8887
return
8988
cmake.build(my_env)
90-
if build_python:
91-
caffe2_proto_dir = os.path.join(cmake.build_dir, "caffe2", "proto")
92-
for proto_file in glob(os.path.join(caffe2_proto_dir, "*.py")):
93-
if proto_file != os.path.join(caffe2_proto_dir, "__init__.py"):
94-
shutil.copy(proto_file, os.path.join("caffe2", "proto"))

0 commit comments

Comments
 (0)