diff --git a/misc/py-pytorch/Makefile b/misc/py-pytorch/Makefile index 4b20c667b5c1..19d73b755f1a 100644 --- a/misc/py-pytorch/Makefile +++ b/misc/py-pytorch/Makefile @@ -1,98 +1,99 @@ PORTNAME= pytorch DISTVERSIONPREFIX= v DISTVERSION= 2.7.1 -PORTREVISION= 1 +PORTREVISION= 2 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 \ gmake:devel/gmake \ pybind11>0:devel/pybind11 \ ${PYNUMPY} \ ${LOCALBASE}/include/fxdiv.h:devel/fxdiv \ ${PYTHON_PKGNAMEPREFIX}typing-extensions>0:devel/py-typing-extensions@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}pyyaml>=0:devel/py-pyyaml@${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}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_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 .include .if ${OPSYS} == FreeBSD USES+= llvm:max=15 .endif post-patch: @cd ${WRKSRC} && \ ${RM} -r third_party/cpuinfo third_party/fbgemm/third_party/cpuinfo && \ ${CP} -r cpuinfo-with-freebsd-support third_party/cpuinfo && \ ${CP} -r cpuinfo-with-freebsd-support third_party/fbgemm/third_party/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 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/files/patch-third__party_tensorpipe_tensorpipe_common_system.cc b/misc/py-pytorch/files/patch-third__party_tensorpipe_tensorpipe_common_system.cc new file mode 100644 index 000000000000..cc052f650cfa --- /dev/null +++ b/misc/py-pytorch/files/patch-third__party_tensorpipe_tensorpipe_common_system.cc @@ -0,0 +1,30 @@ +--- third_party/tensorpipe/tensorpipe/common/system.cc.orig 2025-06-04 18:15:56 UTC ++++ third_party/tensorpipe/tensorpipe/common/system.cc +@@ -102,6 +102,27 @@ std::string getPathForLinuxNamespace(LinuxNamespace ns + return oss.str(); + } + ++#elif defined(__FreeBSD__) ++ ++#include ++#include ++#include ++#include ++ ++optional getBootIDInternal() { ++ char hostname[256]; ++ (void)::gethostname(hostname, sizeof(hostname)); ++ ++ struct timeval boottime; ++ size_t size = sizeof(boottime); ++ (void)sysctlbyname("kern.boottime", &boottime, &size, nullptr, 0); ++ ++ char buf[512]; ++ ::sprintf(buf, "%s-%ld-%ld", hostname, boottime.tv_sec, boottime.tv_usec); ++ ++ return std::string(buf); ++} ++ + #endif + + } // namespace 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 new file mode 100644 index 000000000000..7977852226dd --- /dev/null +++ b/misc/py-pytorch/files/patch-torch_csrc_distributed_c10d_ProcessGroupGloo.cpp @@ -0,0 +1,22 @@ +--- torch/csrc/distributed/c10d/ProcessGroupGloo.cpp.orig 2025-06-04 18:15:57 UTC ++++ torch/csrc/distributed/c10d/ProcessGroupGloo.cpp +@@ -111,6 +111,10 @@ + } + #endif + ++#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); + } + +-#if defined(__linux__) || defined(_WIN32) ++#if defined(__linux__) || defined(__FreeBSD__) || defined(_WIN32) + std::shared_ptr<::gloo::transport::Device> ProcessGroupGloo:: + createDefaultDevice() { + // Use the hostname to resolve the network address to