diff --git a/misc/py-pytorch/Makefile b/misc/py-pytorch/Makefile index 9e4d09be2c50..67bdf831cb8e 100644 --- a/misc/py-pytorch/Makefile +++ b/misc/py-pytorch/Makefile @@ -1,108 +1,134 @@ PORTNAME= pytorch DISTVERSIONPREFIX= v -DISTVERSION= 2.8.0 -PORTREVISION= 4 +DISTVERSION= 2.10.0 CATEGORIES= misc # machine-learning MASTER_SITES= https://github.com/pytorch/pytorch/releases/download/v${DISTVERSION}/ PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} DISTFILES= ${PORTNAME}-${DISTVERSIONFULL}${EXTRACT_SUFX} # the main tarball disappears when GH_xx tags are added w/out this line DIST_SUBDIR= ${PORTNAME} MAINTAINER= yuri@FreeBSD.org COMMENT= PyTorch: Tensors and dynamic neural networks in Python WWW= https://pytorch.org/ \ https://github.com/pytorch/pytorch LICENSE= BSD3CLAUSE LICENSE_FILE= ${WRKSRC}/LICENSE BROKEN_aarch64= build fails: CMake Error at third_party/QNNPACK/CMakeLists.txt:47 (MESSAGE): Unrecognized CMAKE_SYSTEM_NAME = FreeBSD, see https://github.com/pytorch/pytorch/issues/144608 BROKEN_armv7= build fails: CMake Error at third_party/QNNPACK/CMakeLists.txt:47 (MESSAGE): Unrecognized CMAKE_SYSTEM_NAME = FreeBSD, see https://github.com/pytorch/pytorch/issues/144608 BROKEN_i386= build fails: DispatchStub.cpp:162:29: [0m[0;1;31merror: [0m[1muse of undeclared identifier 'AVX2'[0m -BUILD_DEPENDS= cmake:devel/cmake-core \ +BUILD_DEPENDS= ${PY_SETUPTOOLS} \ + cmake:devel/cmake-core \ gmake:devel/gmake \ pybind11>0:devel/pybind11 \ ${PYNUMPY} \ ${LOCALBASE}/include/fxdiv.h:devel/fxdiv \ + ${PYTHON_PKGNAMEPREFIX}filelock>0:sysutils/py-filelock@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}fsspec>0:filesystems/py-fsspec@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}hypothesis>0:devel/py-hypothesis@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}Jinja2>0:devel/py-Jinja2@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}optree>0:devel/py-optree@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}psutil>0:sysutils/py-psutil@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}pyyaml>0:devel/py-pyyaml@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}requests>0:www/py-requests@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}six>0:devel/py-six@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}sympy>=1.13.3:math/py-sympy@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}typing-extensions>0:devel/py-typing-extensions@${PY_FLAVOR} \ - ${PYTHON_PKGNAMEPREFIX}pyyaml>=0:devel/py-pyyaml@${PY_FLAVOR} + ${PYTHON_PKGNAMEPREFIX}wheel>0:devel/py-wheel@${PY_FLAVOR} LIB_DEPENDS= libabsl_base.so:devel/abseil \ libblis.so:math/blis \ libmpi_cxx.so:net/openmpi4 \ libonnx.so:misc/onnx \ libopenblas.so:math/openblas \ libpthreadpool.so:devel/pthreadpool \ libprotobuf.so:devel/protobuf \ libsleef.so:math/sleef RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}filelock>0:sysutils/py-filelock@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}fsspec>0:filesystems/py-fsspec@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}Jinja2>0:devel/py-Jinja2@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}networkx>0:math/py-networkx@${PY_FLAVOR} \ ${PYNUMPY} \ - ${PYTHON_PKGNAMEPREFIX}sympy>=1.13.1:math/py-sympy@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}sympy>=1.13.3:math/py-sympy@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}typing-extensions>=4.10.0:devel/py-typing-extensions@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}pyyaml>0:devel/py-pyyaml@${PY_FLAVOR} RUN_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}astunparse>0:devel/py-astunparse@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}dill>0:devel/py-dill@${PY_FLAVOR} \ - ${PYTHON_PKGNAMEPREFIX}networkx>0:math/py-networkx@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}protobuf>0:devel/py-protobuf@${PY_FLAVOR} # optional dependencies USES= compiler:c++17-lang localbase:ldflags python -USE_PYTHON= distutils autoplist +USE_PYTHON= pep517 autoplist USE_LDCONFIG= ${PYTHON_SITELIBDIR}/torch/lib +# The Python package is named "torch" not "pytorch" +PYDISTUTILS_PKGNAME= torch +PEP517_INSTALL_CMD= ${PYTHON_CMD} -m installer --destdir ${STAGEDIR} --prefix ${PREFIX} ${BUILD_WRKSRC}/dist/torch-${DISTVERSION}*.whl + USE_GITHUB= nodefault GH_TUPLE= pytorch:cpuinfo:1e83a2f:cpuinfo/cpuinfo-with-freebsd-support # https://github.com/pytorch/cpuinfo/pull/230/commits MAKE_ENV= USE_NINJA=no # ninja breaks for some reason MAKE_ENV+= BUILD_TEST=0 # ninja breaks for some reason MAKE_ENV+= USE_MKLDNN=0 # disable MKLDNN that doesn't exist, see https://github.com/pytorch/pytorch/issues/100957 MAKE_ENV+= USE_CUDNN=0 MAKE_ENV+= USE_LAPACK=1 # needed on FreeBSD to run w/out GPU MAKE_ENV+= USE_QNNPACK=0 MAKE_ENV+= USE_DISTRIBUTED=1 LDFLAGS+= -lexecinfo LDFLAGS_powerpc64le= -pthread BINARY_ALIAS= make=${GMAKE} POST_PLIST= fix-plist TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} TEST_WRKSRC= ${WRKSRC}/test OPTIONS_DEFINE= VULKAN OPTIONS_DEFAULT= VULKAN # VULKAN is experimental in PyTorch and only simple computations work VULKAN_MAKE_ENV= USE_VULKAN=1 USE_VULKAN_SHADERC_RUNTIME=1 USE_VULKAN_WRAPPER=0 # see https://docs.pytorch.org/tutorials/unstable/vulkan_workflow.html VULKAN_BUILD_DEPENDS= glslc:graphics/shaderc \ vulkan-headers>0:graphics/vulkan-headers VULKAN_LIB_DEPENDS= libvulkan.so:graphics/vulkan-loader .include .if ${OPSYS} == FreeBSD USES+= llvm:max=15 .endif post-patch: @cd ${WRKSRC} && \ ${RM} -r third_party/cpuinfo third_party/fbgemm/external/cpuinfo && \ ${CP} -r cpuinfo-with-freebsd-support third_party/cpuinfo && \ ${CP} -r cpuinfo-with-freebsd-support third_party/fbgemm/external/cpuinfo -post-install: # strip binaries - @${STRIP_CMD} \ - ${STAGEDIR}${PYTHON_SITELIBDIR}/torch/bin/torch_shm_manager \ - ${STAGEDIR}${PYTHON_SITELIBDIR}/torch/_C${PYTHON_TAG}.so \ - ${STAGEDIR}${PYTHON_SITELIBDIR}/functorch/_C${PYTHON_TAG}.so \ - ${STAGEDIR}${PYTHON_SITELIBDIR}/torch/lib/lib*.so +do-install: # port should be moved to 'torch', but keep this for now with the hardcoded 'torch' name + @${MKDIR} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} + @cd ${INSTALL_WRKSRC} && ${SETENVI} ${WRK_ENV} ${MAKE_ENV} ${PEP517_INSTALL_CMD} + @${PYTHON_CMD} -B ${PORTSDIR}/Mk/Scripts/strip_RECORD.py \ + ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/torch-${DISTVERSION}*.dist-info/RECORD >> ${_PYTHONPKGLIST} + @${REINPLACE_CMD} \ + -e '/\.pyc$$/d' \ + -e 's|^|${PYTHONPREFIX_SITELIBDIR}/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../etc/|etc/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../bin/|bin/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../include/|include/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../lib/|lib/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../libdata/|libdata/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../libexec/|libexec/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../man/|man/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../sbin/|sbin/|' \ + -e 's|^${PYTHONPREFIX_SITELIBDIR}/../../../share/|share/|' \ + ${_PYTHONPKGLIST} + @cd ${STAGEDIR}${PREFIX} && ${FIND} lib -name '*.pyc' >> ${_PYTHONPKGLIST} fix-plist: # remove the stray %%PYTHON_SITELIBDIR%%/caffe2 file @${REINPLACE_CMD} -e "s|.*/caffe2$$||" ${TMPPLIST} do-test: cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} run_test.py .include diff --git a/misc/py-pytorch/distinfo b/misc/py-pytorch/distinfo index 83e007ea33e1..3a750c8759a0 100644 --- a/misc/py-pytorch/distinfo +++ b/misc/py-pytorch/distinfo @@ -1,5 +1,5 @@ -TIMESTAMP = 1755586021 -SHA256 (pytorch/pytorch-v2.8.0.tar.gz) = c70a2c9488f6f6e8af5982a10d1cc2c37b7df5e6506d839daa5d5e250953d7b5 -SIZE (pytorch/pytorch-v2.8.0.tar.gz) = 330943132 +TIMESTAMP = 1769236907 +SHA256 (pytorch/pytorch-v2.10.0.tar.gz) = fa8ccbe87f83f48735505371c1c313b4aa6db400b0ae4f8a02844d1e150c695f +SIZE (pytorch/pytorch-v2.10.0.tar.gz) = 372567293 SHA256 (pytorch/pytorch-cpuinfo-1e83a2f_GH0.tar.gz) = b8945cf45d4f13054d7f52e8bd9314690ea840d4d0ff21febd95ff04de3c613e SIZE (pytorch/pytorch-cpuinfo-1e83a2f_GH0.tar.gz) = 3541839 diff --git a/misc/py-pytorch/files/patch-CMakeLists.txt b/misc/py-pytorch/files/patch-CMakeLists.txt index f7b4af5cd8d0..4493ea8e5155 100644 --- a/misc/py-pytorch/files/patch-CMakeLists.txt +++ b/misc/py-pytorch/files/patch-CMakeLists.txt @@ -1,48 +1,48 @@ ---- CMakeLists.txt.orig 2025-08-06 17:08:00 UTC +--- CMakeLists.txt.orig 2026-01-21 17:08:59 UTC +++ CMakeLists.txt -@@ -173,7 +173,7 @@ set(CPU_POWER OFF) - set(CPU_INTEL OFF) +@@ -173,7 +173,7 @@ set(CPU_RISCV OFF) set(CPU_POWER OFF) + set(CPU_RISCV OFF) -if(CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|x86_64)") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64|x86_64)") set(CPU_INTEL ON) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)") set(CPU_AARCH64 ON) -@@ -203,7 +203,7 @@ option(BUILD_CUSTOM_PROTOBUF +@@ -205,7 +205,7 @@ option(BUILD_CUSTOM_PROTOBUF option(ATEN_NO_TEST "Do not build ATen test binaries" OFF) option(BUILD_BINARY "Build C++ binaries" OFF) option(BUILD_CUSTOM_PROTOBUF - "Build and use Caffe2's own protobuf under third_party" ON) + "Build and use Caffe2's own protobuf under third_party" OFF) option(BUILD_PYTHON "Build Python binaries" ON) option(BUILD_LITE_INTERPRETER "Master flag to build Lite Interpreter" OFF) option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON) -@@ -254,7 +254,7 @@ option(USE_GLOG "Use GLOG" OFF) - option(USE_FAKELOWP "Use FakeLowp operators" OFF) +@@ -268,7 +268,7 @@ option(USE_GLOG "Use GLOG" OFF) + option(USE_CUPTI_SO "Use CUPTI as a shared library" ON) option(USE_GFLAGS "Use GFLAGS" OFF) option(USE_GLOG "Use GLOG" OFF) -option(USE_LITE_PROTO "Use lite protobuf instead of full." OFF) +option(USE_LITE_PROTO "Use lite protobuf instead of full." ON) option(USE_MAGMA "Use MAGMA" ON) option(USE_PYTORCH_METAL "Use Metal for PyTorch iOS build" OFF) option(USE_PYTORCH_METAL_EXPORT "Export Metal models on MacOSX desktop" OFF) -@@ -451,15 +451,15 @@ option(USE_SYSTEM_CPUINFO "Use system-provided cpuinfo +@@ -476,15 +476,15 @@ option(USE_SYSTEM_CPUINFO "Use system-provided cpuinfo # USE_SYSTEM_LIBS being "OFF". option(USE_SYSTEM_LIBS "Use all available system-provided libraries." OFF) option(USE_SYSTEM_CPUINFO "Use system-provided cpuinfo." OFF) -option(USE_SYSTEM_SLEEF "Use system-provided sleef." OFF) +option(USE_SYSTEM_SLEEF "Use system-provided sleef." ON) option(USE_SYSTEM_GLOO "Use system-provided gloo." OFF) option(USE_SYSTEM_FP16 "Use system-provided fp16." OFF) -option(USE_SYSTEM_PYBIND11 "Use system-provided PyBind11." OFF) +option(USE_SYSTEM_PYBIND11 "Use system-provided PyBind11." ON) option(USE_SYSTEM_PTHREADPOOL "Use system-provided pthreadpool." OFF) option(USE_SYSTEM_PSIMD "Use system-provided psimd." OFF) option(USE_SYSTEM_FXDIV "Use system-provided fxdiv." OFF) option(USE_SYSTEM_BENCHMARK "Use system-provided google benchmark." OFF) -option(USE_SYSTEM_ONNX "Use system-provided onnx." OFF) +option(USE_SYSTEM_ONNX "Use system-provided onnx." ON) option(USE_SYSTEM_XNNPACK "Use system-provided xnnpack." OFF) option(USE_SYSTEM_NVTX "Use system-provided nvtx." OFF) option(USE_GOLD_LINKER "Use ld.gold to link" OFF) diff --git a/misc/py-pytorch/files/patch-pyproject.toml b/misc/py-pytorch/files/patch-pyproject.toml new file mode 100644 index 000000000000..b22842375119 --- /dev/null +++ b/misc/py-pytorch/files/patch-pyproject.toml @@ -0,0 +1,32 @@ +--- pyproject.toml.orig 2026-01-24 08:31:03 UTC ++++ pyproject.toml +@@ -4,9 +4,11 @@ requires = [ + requires = [ + # 70.1.0: min version for integrated bdist_wheel command from wheel package + # 77.0.0: min version for SPDX expression support for project.license +- "setuptools>=70.1.0", +- "cmake>=3.27", +- "ninja", ++ # FreeBSD: patched to work with setuptools-63.1.0 ++ "setuptools>=63.1.0", ++ # FreeBSD: cmake and ninja are provided as BUILD_DEPENDS ++ # "cmake>=3.27", ++ # "ninja", + "numpy", + "packaging", + "pyyaml", +@@ -22,9 +24,11 @@ dev = [ + # in PyTorch root until the project fully migrates to pyproject.toml + # after which this can be removed as it is already specified in the + # [build-system] section +- "setuptools>=70.1.0,<80.0", # setuptools develop deprecated on 80.0 +- "cmake>=3.27", +- "ninja", ++ # FreeBSD: patched to work with setuptools-63.1.0 ++ "setuptools>=63.1.0,<80.0", # setuptools develop deprecated on 80.0 ++ # FreeBSD: cmake and ninja are provided as BUILD_DEPENDS ++ # "cmake>=3.27", ++ # "ninja", + "numpy", + "packaging", + "pyyaml", diff --git a/misc/py-pytorch/files/patch-requirements-build.txt b/misc/py-pytorch/files/patch-requirements-build.txt new file mode 100644 index 000000000000..580e6e40d6af --- /dev/null +++ b/misc/py-pytorch/files/patch-requirements-build.txt @@ -0,0 +1,15 @@ +--- requirements-build.txt.orig 2026-01-24 08:31:03 UTC ++++ requirements-build.txt +@@ -1,7 +1,9 @@ + # Build System requirements +-setuptools>=70.1.0 +-cmake>=3.27 +-ninja ++# FreeBSD: patched to work with setuptools-63.1.0 ++setuptools>=63.1.0 ++# FreeBSD: cmake and ninja are provided as BUILD_DEPENDS ++# cmake>=3.27 ++# ninja + numpy + packaging + pyyaml diff --git a/misc/py-pytorch/files/patch-setup.py b/misc/py-pytorch/files/patch-setup.py new file mode 100644 index 000000000000..47ad8e6a118b --- /dev/null +++ b/misc/py-pytorch/files/patch-setup.py @@ -0,0 +1,83 @@ +--- setup.py.orig 2026-01-24 08:17:11 UTC ++++ setup.py +@@ -286,7 +286,7 @@ from typing import Any, ClassVar, IO + from pathlib import Path + from typing import Any, ClassVar, IO + +-import setuptools.command.bdist_wheel ++# import setuptools.command.bdist_wheel + import setuptools.command.build_ext + import setuptools.command.sdist + import setuptools.errors +@@ -1429,29 +1429,37 @@ class concat_license_files: + self.f1.write_text(self.bsd_text, encoding="utf-8") + + +-# Need to create the proper LICENSE.txt for the wheel +-class bdist_wheel(setuptools.command.bdist_wheel.bdist_wheel): +- def run(self) -> None: +- with concat_license_files(include_files=True): +- super().run() ++try: ++ from wheel.bdist_wheel import bdist_wheel as _bdist_wheel ++except ImportError: ++ # This is useful when wheel is not installed and bdist_wheel is not ++ # specified on the command line. If it _is_ specified, parsing the command ++ # line will fail before bdist_wheel is needed ++ bdist_wheel = None ++else: ++ # Need to create the proper LICENSE.txt for the wheel ++ class bdist_wheel(_bdist_wheel): ++ def run(self) -> None: ++ with concat_license_files(include_files=True): ++ super().run() + +- def write_wheelfile(self, *args: Any, **kwargs: Any) -> None: +- super().write_wheelfile(*args, **kwargs) ++ def write_wheelfile(self, *args: Any, **kwargs: Any) -> None: ++ super().write_wheelfile(*args, **kwargs) + +- if BUILD_LIBTORCH_WHL: +- assert self.bdist_dir is not None +- bdist_dir = Path(self.bdist_dir) +- # Remove extraneneous files in the libtorch wheel +- for file in itertools.chain( +- bdist_dir.rglob("*.a"), +- bdist_dir.rglob("*.so"), +- ): +- if (bdist_dir / file.name).is_file(): ++ if BUILD_LIBTORCH_WHL: ++ assert self.bdist_dir is not None ++ bdist_dir = Path(self.bdist_dir) ++ # Remove extraneneous files in the libtorch wheel ++ for file in itertools.chain( ++ bdist_dir.rglob("*.a"), ++ bdist_dir.rglob("*.so"), ++ ): ++ if (bdist_dir / file.name).is_file(): ++ file.unlink() ++ for file in bdist_dir.rglob("*.py"): + file.unlink() +- for file in bdist_dir.rglob("*.py"): +- file.unlink() +- # need an __init__.py file otherwise we wouldn't have a package +- (bdist_dir / "torch" / "__init__.py").touch() ++ # need an __init__.py file otherwise we wouldn't have a package ++ (bdist_dir / "torch" / "__init__.py").touch() + + + class clean(Command): +@@ -1640,11 +1648,12 @@ def configure_extension_build() -> tuple[ + ext_modules.append(C) + + cmdclass = { +- "bdist_wheel": bdist_wheel, + "build_ext": build_ext, + "clean": clean, + "sdist": sdist, + } ++ if bdist_wheel is not None: ++ cmdclass["bdist_wheel"] = bdist_wheel + + entry_points = { + "console_scripts": [ diff --git a/misc/py-pytorch/files/patch-torch_csrc_distributed_c10d_ProcessGroupGloo.cpp b/misc/py-pytorch/files/patch-torch_csrc_distributed_c10d_ProcessGroupGloo.cpp index 7977852226dd..88578933f045 100644 --- a/misc/py-pytorch/files/patch-torch_csrc_distributed_c10d_ProcessGroupGloo.cpp +++ b/misc/py-pytorch/files/patch-torch_csrc_distributed_c10d_ProcessGroupGloo.cpp @@ -1,22 +1,22 @@ ---- torch/csrc/distributed/c10d/ProcessGroupGloo.cpp.orig 2025-06-04 18:15:57 UTC +--- torch/csrc/distributed/c10d/ProcessGroupGloo.cpp.orig 2026-01-21 17:09:02 UTC +++ torch/csrc/distributed/c10d/ProcessGroupGloo.cpp -@@ -111,6 +111,10 @@ - } - #endif +@@ -32,6 +32,10 @@ + #include + #include +#if defined(__FreeBSD__) +#define HOST_NAME_MAX 256 +#endif + namespace c10d { namespace { -@@ -705,7 +709,7 @@ std::shared_ptr<::gloo::transport::Device> ProcessGrou - return ::c10d::GlooDeviceFactory::makeDeviceForHostname(hostname); +@@ -488,7 +492,7 @@ std::shared_ptr<::gloo::transport::Device> ProcessGrou + return ::c10d::GlooDeviceFactory::makeDeviceForHostname(hostname, lazyInit); } -#if defined(__linux__) || defined(_WIN32) +#if defined(__linux__) || defined(__FreeBSD__) || defined(_WIN32) std::shared_ptr<::gloo::transport::Device> ProcessGroupGloo:: - createDefaultDevice() { + createDefaultDevice(bool lazyInit) { // Use the hostname to resolve the network address to