git: 529b43a76591 - main - misc/py-pytorch: Enable distributed mode during build

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Tue, 19 Aug 2025 06:45:16 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=529b43a7659157f72e7f03838e42316bfbe62c20

commit 529b43a7659157f72e7f03838e42316bfbe62c20
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2025-08-19 05:41:32 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2025-08-19 06:45:13 +0000

    misc/py-pytorch: Enable distributed mode during build
    
    USE_DISTRIBUTED=1 enables it.
    
    Some users require this mode.
---
 misc/py-pytorch/Makefile                           |  3 ++-
 ...d__party_tensorpipe_tensorpipe_common_system.cc | 30 ++++++++++++++++++++++
 ...orch_csrc_distributed_c10d_ProcessGroupGloo.cpp | 22 ++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

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,7 +1,7 @@
 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}
@@ -60,6 +60,7 @@ MAKE_ENV+=	USE_MKLDNN=0 # disable MKLDNN that doesn't exist, see https://github.
 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
 
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 <unistd.h>
++#include <stdio.h>
++#include <sys/sysctl.h>
++#include <time.h>
++
++optional<std::string> 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