diff --git a/math/dgl/Makefile b/math/dgl/Makefile index fc23867ff0b8..a2cb34684cc4 100644 --- a/math/dgl/Makefile +++ b/math/dgl/Makefile @@ -1,66 +1,69 @@ PORTNAME= dgl DISTVERSIONPREFIX= v DISTVERSION= 2.4.0 CATEGORIES= math # machine-learning MAINTAINER= yuri@FreeBSD.org COMMENT= Deep Graph Library -WWW= https://www.dgl.ai/ +WWW= https://www.dgl.ai/ \ + https://github.com/dmlc/dgl/ LICENSE= APACHE20 LICENSE_FILE= ${WRKSRC}/LICENSE +BROKEN= not compatible with pytorch-2.14.0, see https://github.com/dmlc/dgl/issues/7934 + BUILD_DEPENDS= ${BACKEND_DEPENDS} \ bash:shells/bash \ gmake:devel/gmake USES= cmake:testing compiler:c++17-lang localbase:ldflags python:build shebangfix USE_LDCONFIG= yes USE_GITHUB= yes GH_ACCOUNT= dmlc GH_TUPLE= axboe:liburing:f7dcc1ea60819475dffd3a45059e16f04381bee7:liburing/third_party/liburing \ dmlc:dlpack:e2bdd3bee8cb6501558042633fa59144cc8b7f5f:dlpack/third_party/dlpack \ dmlc:dmlc-core:bfad207b448480783a1f428ae3d93d87032d8349:dmlc_core/third_party/dmlc-core \ google:googletest:f8d7d77c06936315286eb55f8de22cd23c188571:googletest/third_party/googletest \ hfp:libxsmm:80090603e43f6ddc870cc42e1403dd0af07744cc:libxsmm/third_party/libxsmm \ imneme:pcg-cpp:428802d1a5634f96bcd0705fab379ff0113bcf13:pcg/third_party/pcg \ jlblancoc:nanoflann:4c47ca200209550c5628c89803591f8a753c8181:nanoflann/third_party/nanoflann \ KarypisLab:GKlib:8bd6bad750b2b0d90800c632cf18e8ee93ad72d7:gklib/third_party/GKlib \ KarypisLab:METIS:e0f1b88b8efcb24ffa0ec55eabb78fbe61e58ae7:metis/third_party/METIS \ NVIDIA:cccl:c67b1c3257be5115253f06d45a2d607b54234db4:cccl/third_party/cccl \ NVIDIA:cuCollections:6c0d7ee190a167c6976af0f7c628a43d13b78f38:cuco/third_party/cuco \ taskflow:taskflow:7d9e85b6b2e9bf501021f857f2f3cbe43bc37c85:taskflow/third_party/taskflow \ Tessil:robin-map:1115dad3ffa0994e3f43b693d9b9cc99944c64c1:tsl_robin_map/third_party/tsl_robin_map SHEBANG_GLOB= *.sh MAKE_ENV= PYTHON=${PYTHON_CMD} CMAKE_ON= BUILD_SHARED_LIBS CMAKE_OFF= BUILD_GRAPHBOLT \ BUILD_CPP_TEST \ USE_LIBXSMM BINARY_ALIAS= make=${GMAKE} python3=${PYTHON_CMD} PLIST_FILES= lib/libGKlib.so \ lib/libdgl_metis.so # workaround for https://github.com/dmlc/dgl/issues/5666 OPTIONS_RADIO= BACKEND OPTIONS_RADIO_BACKEND= PYTORCH TENSORFLOW OPTIONS_DEFAULT= PYTORCH PYTORCH_DESC= Use PyTorch backend PYTORCH_VARS= BACKEND_DEPENDS=${PYTHON_PKGNAMEPREFIX}pytorch>0:misc/py-pytorch@${PY_FLAVOR} PYTORCH_MAKE_ENV= DGLBACKEND=pytorch TENSORFLOW_DESC= Use TensorFlow backend TENSORFLOW_VARS= BACKEND_DEPENDS=${PYTHON_PKGNAMEPREFIX}tensorflow>0:science/py-tensorflow@${PY_FLAVOR} TENSORFLOW_MAKE_ENV= DGLBACKEND=tensorflow TENSORFLOW_CMAKE_ON= -DBUILD_SPARSE=OFF post-install: # workaround for https://github.com/dmlc/dgl/issues/5666 ${INSTALL_LIB} ${BUILD_WRKSRC}/libGKlib.so ${STAGEDIR}${PREFIX}/lib ${INSTALL_LIB} ${BUILD_WRKSRC}/third_party/METIS/libmetis/libdgl_metis.so ${STAGEDIR}${PREFIX}/lib .include diff --git a/misc/py-pytorch/Makefile b/misc/py-pytorch/Makefile index 8c897546999c..20a580d0a863 100644 --- a/misc/py-pytorch/Makefile +++ b/misc/py-pytorch/Makefile @@ -1,129 +1,149 @@ PORTNAME= pytorch DISTVERSIONPREFIX= v -DISTVERSION= 2.13.0 +DISTVERSION= 2.14.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= ${PY_SETUPTOOLS} \ - cmake:devel/cmake-core \ +BUILD_DEPENDS= cmake:devel/cmake-core \ gmake:devel/gmake \ pybind11>0:devel/pybind11 \ ${PYTHON_PKGNAMEPREFIX}numpy>=1.16:math/py-numpy@${PY_FLAVOR} \ ${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}packaging>0:devel/py-packaging@${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}scikit-build-core>=1.0:devel/py-scikit-build-core@${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}wheel>0:devel/py-wheel@${PY_FLAVOR} LIB_DEPENDS= libabsl_base.so:devel/abseil \ libonnx.so:misc/onnx \ libopenblas.so:math/openblas \ 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} \ ${PYTHON_PKGNAMEPREFIX}numpy>=1.16:math/py-numpy@${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}protobuf>0:devel/py-protobuf@${PY_FLAVOR} # optional dependencies -TEST_DEPENDS= ${PYTHON_PKGNAMEPREFIX}pytest-rerunfailures>0:devel/py-pytest-rerunfailures@${PY_FLAVOR} \ +TEST_DEPENDS= ${PYTHON_PKGNAMEPREFIX}expecttest>0:devel/py-expecttest@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}pytest-rerunfailures>0:devel/py-pytest-rerunfailures@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}pytest-xdist>0:devel/py-pytest-xdist@${PY_FLAVOR} -USES= compiler:c++17-lang localbase:ldflags mpi:openmpi python +USES= compiler:c++17-lang localbase:ldflags mpi:openmpi python shebangfix USE_PYTHON= pep517 autoplist + +SHEBANG_FILES= torch/utils/hipify/hipify_python.py # installed executable, unlike with the pre-2.14 setuptools build 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:bc3c01e: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 +# point FindMPI at the openmpi requested by USES=mpi, otherwise it picks up the +# mpicc/mpicxx wrappers that net/mpich installs into LOCALBASE/bin, which link +# libmpi/libmpicxx from mpich and drag in lang/gcc14 via the wrapper's -rpath +MAKE_ENV+= CMAKE_ARGS="-DMPI_C_COMPILER=${MPI_HOME}/bin/mpicc -DMPI_CXX_COMPILER=${MPI_HOME}/bin/mpicxx" \ + MAX_JOBS=${MAKE_JOBS_NUMBER} LDFLAGS+= -lexecinfo LDFLAGS_powerpc64le= -pthread BINARY_ALIAS= make=${GMAKE} TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} \ TORCHINDUCTOR_CACHE_DIR=${WRKDIR}/torchinductor_cache 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 +CONFLICTS_BUILD= mpich # binaries are still linked with mpich when it is present + .include +post-extract: + # upstream ships a stray *.orig file that 'make makepatch' would otherwise + # mistake for a patch baseline and turn into a bogus binary patch + @${RM} ${WRKSRC}/third_party/aiter/hsa/gfx950/pa/pa_bf16_noquant_gqa8_1tg_4w.co.orig + 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 # change hardcoded compiler in torch/_inductor/config.py @${REINPLACE_CMD} -e 's|"g++"|"${CXX}"|' \ ${WRKSRC}/torch/_inductor/config.py 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} do-test: @cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} run_test.py +test-quick: + @cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${FILESDIR}/example.py + +# tests as of 2.14.0: 231 passed 6 skipped + .include diff --git a/misc/py-pytorch/distinfo b/misc/py-pytorch/distinfo index d51bf5ed6c82..159be4c30252 100644 --- a/misc/py-pytorch/distinfo +++ b/misc/py-pytorch/distinfo @@ -1,5 +1,5 @@ -TIMESTAMP = 1784075507 -SHA256 (pytorch/pytorch-v2.13.0.tar.gz) = 66614a19060f69cfd63cd0295f65a1241bd15df2fa65c60ae51066c11c2ce812 -SIZE (pytorch/pytorch-v2.13.0.tar.gz) = 485291648 +TIMESTAMP = 1789232118 +SHA256 (pytorch/pytorch-v2.14.0.tar.gz) = e4bc64b802db095a8a53e216e5aba168eba629b99dd397cfa44e72d9c84e7657 +SIZE (pytorch/pytorch-v2.14.0.tar.gz) = 797590021 SHA256 (pytorch/pytorch-cpuinfo-bc3c01e_GH0.tar.gz) = 09459e830a588fee730feb19d8a32fedf2d36d48db7bd9b18c3159c7e74ea0ce SIZE (pytorch/pytorch-cpuinfo-bc3c01e_GH0.tar.gz) = 3547453 diff --git a/misc/py-pytorch/files/example.py b/misc/py-pytorch/files/example.py new file mode 100644 index 000000000000..0c8046ca603e --- /dev/null +++ b/misc/py-pytorch/files/example.py @@ -0,0 +1,132 @@ +import torch +import torch.nn as nn +import torch.optim as optim +import numpy as np + +# Set random seed for reproducibility +torch.manual_seed(42) +np.random.seed(42) + +# Define the target mathematical function +def target_function(a, b, c): + return 18*a*b*c - 4*(a**3)*c + (a**2)*(b**2) - 4*(b**3) - 27*(c**2) + +# ========================================== +# (1) Define Neural Network and Train +# ========================================== + +# A deep network with architectural modifications to easily map polynomial boundaries +class DiscriminantNN(nn.Module): + def __init__(self): + super(DiscriminantNN, self).__init__() + self.net = nn.Sequential( + nn.Linear(3, 128), + nn.GELU(), + nn.Linear(128, 128), + nn.GELU(), + nn.Linear(128, 128), + nn.GELU(), + nn.Linear(128, 64), + nn.GELU(), + nn.Linear(64, 1) + ) + + def forward(self, x): + return self.net(x) + +# Generate dense grid data for the 0..1 interval with 0.05 step to cover the domain topology +grid_steps = np.linspace(0.0, 1.0, 21) +a_grid, b_grid, c_grid = np.meshgrid(grid_steps, grid_steps, grid_steps) +X_train_np = np.stack([a_grid.ravel(), b_grid.ravel(), c_grid.ravel()], axis=1) +y_train_np = target_function(X_train_np[:, 0], X_train_np[:, 1], X_train_np[:, 2]).reshape(-1, 1) + +X_train = torch.tensor(X_train_np, dtype=torch.float32) +y_train = torch.tensor(y_train_np, dtype=torch.float32) + +# Model initialization +model = DiscriminantNN() +criterion = nn.MSELoss() +optimizer = optim.AdamW(model.parameters(), lr=0.005, weight_decay=1e-5) +scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode='min', factor=0.5, patience=100) + +print("Training started...") +epoch = 0 +max_epochs = 300000 + +while epoch < max_epochs: + #print(f"Epoch {epoch:04d} | Learning Rate: {optimizer.param_groups[0]['lr']:.6f}") + model.train() + optimizer.zero_grad() + predictions = model(X_train) + loss = criterion(predictions, y_train) + loss.backward() + optimizer.step() + + # Calculate absolute errors on the training set + with torch.no_grad(): + abs_errors = torch.abs(predictions - y_train) + max_error = torch.max(abs_errors).item() + mean_error = torch.mean(abs_errors).item() + scheduler.step(loss) + + if epoch % 500 == 0 or max_error < 0.001: + print(f"Epoch {epoch:04d} | Loss: {loss.item():.2e} | Max Abs Error: {max_error:.5f} | Mean Abs Error: {mean_error:.5f}") + + # Stop explicitly once the entire domain satisfies the 0.001 precision threshold + if max_error < 0.001: + print(f"\nTarget precision of 0.001 achieved globally across training domain at epoch {epoch}!") + break + + epoch += 1 + +# ========================================== +# (2) Evaluate within the 0..1 range +# ========================================== +print("\n--- Evaluation Inside [0, 1]^3 Domain ---") +model.eval() + +# Generate 10,000 completely random uniform points inside the unit cube +X_inside_np = np.random.uniform(0.0, 1.0, (10000, 3)) +y_inside_exact = target_function(X_inside_np[:, 0], X_inside_np[:, 1], X_inside_np[:, 2]).reshape(-1, 1) + +X_inside = torch.tensor(X_inside_np, dtype=torch.float32) +y_inside_exact = torch.tensor(y_inside_exact, dtype=torch.float32) + +with torch.no_grad(): + y_inside_pred = model(X_inside) + errors_inside = torch.abs(y_inside_pred - y_inside_exact) + within_precision_inside = torch.sum(errors_inside <= 0.001).item() + +print(f"Total validation points evaluated: {len(X_inside_np)}") +print(f"Points within 0.001 precision: {within_precision_inside} / 10,000 ({within_precision_inside/100:.2f}%)") + +# ========================================== +# (3) Evaluate Outside the 0..1 Range +# ========================================== +print("\n--- Evaluation Outside [0, 1]^3 Domain (Extrapolation) ---") + +X_outside_list = [] +# Rejection sampling loop to get 10,000 points strictly within [-0.5, 1.5] but outside [0, 1] +while len(X_outside_list) < 10000: + candidates = np.random.uniform(-0.5, 1.5, (20000, 3)) + # A point is outside if any coordinate falls outside [0, 1] + is_outside = np.any((candidates < 0.0) | (candidates > 1.0), axis=1) + filtered = candidates[is_outside] + X_outside_list.extend(filtered) + +X_outside_np = np.array(X_outside_list[:10000]) +y_outside_exact = target_function(X_outside_np[:, 0], X_outside_np[:, 1], X_outside_np[:, 2]).reshape(-1, 1) + +X_outside = torch.tensor(X_outside_np, dtype=torch.float32) +y_outside_exact = torch.tensor(y_outside_exact, dtype=torch.float32) + +with torch.no_grad(): + y_outside_pred = model(X_outside) + errors_outside = torch.abs(y_outside_pred - y_outside_exact) + within_precision_outside = torch.sum(errors_outside <= 0.001).item() + failed_precision_outside = 10000 - within_precision_outside + +print(f"Total extrapolation points evaluated: {len(X_outside_np)}") +print(f"Points within 0.001 precision: {within_precision_outside}") +print(f"Points outside 0.001 precision: {failed_precision_outside}") + diff --git a/misc/py-pytorch/files/patch-CMakeLists.txt b/misc/py-pytorch/files/patch-CMakeLists.txt index 28c06933b2eb..e85dec48b683 100644 --- a/misc/py-pytorch/files/patch-CMakeLists.txt +++ b/misc/py-pytorch/files/patch-CMakeLists.txt @@ -1,48 +1,48 @@ ---- CMakeLists.txt.orig 2026-07-08 17:44:27 UTC +--- CMakeLists.txt.orig 2026-09-02 17:43:46 UTC +++ CMakeLists.txt -@@ -185,7 +185,7 @@ set(CPU_RISCV OFF) +@@ -216,7 +216,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) -@@ -217,7 +217,7 @@ option(BUILD_CUSTOM_PROTOBUF + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)") + # Linux reports "aarch64", macOS "arm64", and native Windows on Arm "ARM64". +@@ -250,7 +250,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) -@@ -283,7 +283,7 @@ option(USE_GLOG "Use GLOG" OFF) +@@ -323,7 +323,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) -@@ -498,15 +498,15 @@ option(USE_SYSTEM_CPUINFO "Use system-provided cpuinfo +@@ -533,15 +533,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 index 8abe8b9877eb..8f1cc4f133e8 100644 --- a/misc/py-pytorch/files/patch-pyproject.toml +++ b/misc/py-pytorch/files/patch-pyproject.toml @@ -1,39 +1,28 @@ ---- pyproject.toml.orig 2026-07-08 17:44:27 UTC +--- pyproject.toml.orig 2026-09-02 17:43:46 UTC +++ pyproject.toml -@@ -2,9 +2,7 @@ requires = [ - - [build-system] - requires = [ -- "setuptools>=77.0.0,<82", # 77.0 is the first release with PEP 639 license-files support -- "cmake>=3.27", -- "ninja", -+ "setuptools", # 77.0 is the first release with PEP 639 license-files support - "numpy", - "packaging>=24.2", # required by setuptools>=77 to validate PEP 639 license expressions - "pyyaml", -@@ -20,9 +18,7 @@ dev = [ - # in PyTorch root until the project fully migrates to pyproject.toml +@@ -312,10 +312,8 @@ dev = [ # after which this can be removed as it is already specified in the # [build-system] section + "scikit-build-core>=1.0", - "setuptools>=77.0.0,<82", # 77.0 is the first release with PEP 639 license-files support ++ "setuptools", # 77.0 is the first release with PEP 639 license-files support + "spin", - "cmake>=3.27", - "ninja", -+ "setuptools", # 77.0 is the first release with PEP 639 license-files support "numpy", "packaging>=24.2", # required by setuptools>=77 to validate PEP 639 license expressions "pyyaml", -@@ -55,14 +51,6 @@ requires-python = ">=3.10" +@@ -349,13 +347,6 @@ requires-python = ">=3.10" # License info: # - The main Pytorch project license is BSD-3-Clause. # - The SPDX license expression below reflects installed pytorch packages. -license = "Apache-2.0 AND Apache-2.0 WITH LLVM-exception AND BSD-2-Clause AND BSD-3-Clause AND BSL-1.0 AND MIT" -license-files = [ - "LICENSE", - "third_party/**/LICENSE", - "third_party/**/LICENSE.txt", - "third_party/**/LICENSE.rst", -- "third_party/**/COPYING.BSD", -] authors = [{ name = "PyTorch Team", email = "packages@pytorch.org" }] keywords = ["pytorch", "machine learning"] classifiers = [ diff --git a/misc/py-pytorch/files/patch-requirements-build.txt b/misc/py-pytorch/files/patch-requirements-build.txt index 18fc1118b990..f6da96af1e8b 100644 --- a/misc/py-pytorch/files/patch-requirements-build.txt +++ b/misc/py-pytorch/files/patch-requirements-build.txt @@ -1,11 +1,14 @@ ---- requirements-build.txt.orig 2026-07-08 17:44:27 UTC +--- requirements-build.txt.orig 2026-09-02 17:43:46 UTC +++ requirements-build.txt -@@ -1,7 +1,5 @@ - # Build System requirements +@@ -2,10 +2,8 @@ scikit-build-core>=1.0 + # 1.0 is required for [[tool.dynamic-metadata]] and the env table; see + # pyproject.toml for the rationale on this lower bound. + scikit-build-core>=1.0 -setuptools>=77.0.0,<82 # 77.0 is the first release with PEP 639 license-files support ++setuptools # 77.0 is the first release with PEP 639 license-files support + spin -cmake>=3.27 -ninja -+setuptools # 77.0 is the first release with PEP 639 license-files support numpy packaging>=24.2 # required by setuptools>=77 to validate PEP 639 license expressions pyyaml diff --git a/misc/py-pytorch/files/patch-setup.py b/misc/py-pytorch/files/patch-setup.py deleted file mode 100644 index 55d07b9aadf3..000000000000 --- a/misc/py-pytorch/files/patch-setup.py +++ /dev/null @@ -1,83 +0,0 @@ --- Avoid dependency on the setuptools.command.bdist_wheel module if wheel is not installed. --- This ensures setup.py runs correctly during build when wheel is not present. ---- setup.py.orig 2026-07-08 17:44:27 UTC -+++ setup.py -@@ -282,7 +282,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.errors - from setuptools import Command, Extension, find_packages, setup -@@ -980,25 +980,30 @@ class build_ext(setuptools.command.build_ext.build_ext - return outputs - - --class bdist_wheel(setuptools.command.bdist_wheel.bdist_wheel): -- def write_wheelfile(self, *args: Any, **kwargs: Any) -> None: -- super().write_wheelfile(*args, **kwargs) -+try: -+ from wheel.bdist_wheel import bdist_wheel as _bdist_wheel -+except ImportError: -+ bdist_wheel = None -+else: -+ class bdist_wheel(_bdist_wheel): -+ def write_wheelfile(self, *args: Any, **kwargs: Any) -> None: -+ super().write_wheelfile(*args, **kwargs) - -- if BUILD_LIBTORCH_WHL: -- if self.bdist_dir is None: -- raise AssertionError("self.bdist_dir must not be 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: -+ if self.bdist_dir is None: -+ raise AssertionError("self.bdist_dir must not be 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): -@@ -1082,10 +1087,11 @@ def configure_extension_build() -> tuple[ - packages = find_packages(include=includes, exclude=excludes) - - cmdclass = { -- "bdist_wheel": bdist_wheel, - "build_ext": build_ext, - "clean": clean, - } -+ if bdist_wheel is not None: -+ cmdclass["bdist_wheel"] = bdist_wheel - - entry_points = { - "console_scripts": [ -@@ -1137,7 +1143,7 @@ def main() -> None: - install_requires = [ - "filelock", - "typing-extensions>=4.10.0", -- "setuptools>=77.0.3", -+ "setuptools", - "sympy>=1.13.3", - "networkx>=2.5.1", - "jinja2", diff --git a/misc/py-pytorch/files/patch-test_dynamo_test__aot__autograd.py b/misc/py-pytorch/files/patch-test_dynamo_test__aot__autograd.py index 3206709a1e5a..01b4fa9150e6 100644 --- a/misc/py-pytorch/files/patch-test_dynamo_test__aot__autograd.py +++ b/misc/py-pytorch/files/patch-test_dynamo_test__aot__autograd.py @@ -1,18 +1,18 @@ ---- test/dynamo/test_aot_autograd.py.orig 2026-05-13 17:40:38 UTC +--- test/dynamo/test_aot_autograd.py.orig 2026-09-02 17:43:46 UTC +++ test/dynamo/test_aot_autograd.py -@@ -1,6 +1,7 @@ import re - # Owner(s): ["module: dynamo"] +@@ -2,6 +2,7 @@ import re import copy + import operator import re +import sys import unittest from textwrap import dedent from unittest.mock import patch -@@ -1006,6 +1007,7 @@ SeqNr|OrigAten|SrcFn|FwdSrcFn +@@ -1018,6 +1019,7 @@ SeqNr|OrigAten|SrcFn|FwdSrcFn # set donated_buffer=False due to create_graph=True @torch._functorch.config.patch("donated_buffer", False) + @unittest.skipIf(sys.platform.startswith("freebsd"), "Kineto causes SIGABRT on FreeBSD") def test_eager_sequence_nr(self): class Model(torch.nn.Module): def __init__(self) -> None: diff --git a/misc/py-pytorch/files/patch-test_dynamo_test__guard__serialization.py b/misc/py-pytorch/files/patch-test_dynamo_test__guard__serialization.py index 009b5ad23daf..3070b6f46ecb 100644 --- a/misc/py-pytorch/files/patch-test_dynamo_test__guard__serialization.py +++ b/misc/py-pytorch/files/patch-test_dynamo_test__guard__serialization.py @@ -1,26 +1,26 @@ ---- test/dynamo/test_guard_serialization.py.orig 2026-07-08 17:44:27 UTC +--- test/dynamo/test_guard_serialization.py.orig 2026-09-02 17:43:46 UTC +++ test/dynamo/test_guard_serialization.py -@@ -1526,6 +1526,7 @@ class TestGuardSerialization(TestGuardSerializationBas +@@ -1582,6 +1582,7 @@ class TestGuardSerialization(TestGuardSerializationBas + True, ) - @torch._dynamo.config.patch(nested_graph_breaks=False) + @unittest.skipIf(sys.platform.startswith("freebsd"), "Gloo does not support FreeBSD") def test_ddp_module(self): import torch.distributed as dist -@@ -1578,6 +1579,7 @@ class TestGuardSerialization(TestGuardSerializationBas +@@ -1636,6 +1637,7 @@ class TestGuardSerialization(TestGuardSerializationBas True, ) + @unittest.skipIf(sys.platform.startswith("freebsd"), "Gloo does not support FreeBSD") def test_unserializable_sharded_tensor(self): import torch.distributed as dist -@@ -1693,6 +1695,7 @@ class TestGuardSerialization(TestGuardSerializationBas +@@ -1751,6 +1753,7 @@ class TestGuardSerialization(TestGuardSerializationBas ) self._test_check_fn(ref, loaded, {"inputs": Inputs(x, torch.Stream())}, True) + @unittest.skipIf(sys.platform.startswith("freebsd"), "Gloo does not support FreeBSD") def test_unused_process_group(self): import torch.distributed as dist diff --git a/misc/py-pytorch/files/patch-test_dynamo_test__repros.py b/misc/py-pytorch/files/patch-test_dynamo_test__repros.py index 5c27ec8fe60b..d78019bed4e6 100644 --- a/misc/py-pytorch/files/patch-test_dynamo_test__repros.py +++ b/misc/py-pytorch/files/patch-test_dynamo_test__repros.py @@ -1,10 +1,10 @@ ---- test/dynamo/test_repros.py.orig 2026-07-08 17:44:27 UTC +--- test/dynamo/test_repros.py.orig 2026-09-02 17:43:46 UTC +++ test/dynamo/test_repros.py -@@ -6272,6 +6272,7 @@ def forward(self, s77 : torch.SymInt, s27 : torch.SymI +@@ -6457,6 +6457,7 @@ def forward(self, L_x_ : torch.Tensor, s77 : torch.Sym graph_code = backend.graphs[0].print_readable(print_output=False) self.assertIn("torch._C._nn.linear", graph_code) + @unittest.skipIf(sys.platform.startswith("freebsd"), "Kineto causes SIGABRT on FreeBSD") def test_aot_autograd_runtime_wrapper_prologue_profiled(self): # Names for prologue profiling event prologue_name = "AOTDispatcher Runtime Wrapper Prologue" diff --git a/misc/py-pytorch/files/patch-third__party_fmt_include_fmt_format.h b/misc/py-pytorch/files/patch-third__party_fmt_include_fmt_format.h deleted file mode 100644 index 28246dbb90da..000000000000 --- a/misc/py-pytorch/files/patch-third__party_fmt_include_fmt_format.h +++ /dev/null @@ -1,10 +0,0 @@ ---- third_party/fmt/include/fmt/format.h.orig 2026-03-23 18:40:46 UTC -+++ third_party/fmt/include/fmt/format.h -@@ -52,6 +52,7 @@ - # include // std::signbit - # include // std::byte - # include // uint32_t -+# include // malloc/free - # include // std::memcpy - # include // std::numeric_limits - # include // std::bad_alloc diff --git a/misc/py-pytorch/files/patch-tools_metadata_dependencies.py b/misc/py-pytorch/files/patch-tools_metadata_dependencies.py new file mode 100644 index 000000000000..869602e003cd --- /dev/null +++ b/misc/py-pytorch/files/patch-tools_metadata_dependencies.py @@ -0,0 +1,20 @@ +-- Relax the setuptools>=77.0.3 lower bound in the wheel's runtime dependency metadata. +-- FreeBSD's devel/py-setuptools is currently 63.1.0, so the upstream bound would make +-- the installed torch package declare a Requires-Dist that no port can satisfy. +-- The bound only exists upstream for PEP 639 license-expression validation, which the +-- port does not rely on (see files/patch-pyproject.toml, which drops the license-files key). +-- This replaces the old files/patch-setup.py: as of 2.14.0 PyTorch builds via +-- scikit-build-core and setup.py is a pip-forwarding shim, so the install_requires list +-- it used to patch now lives here. +-- see https://github.com/pytorch/pytorch/issues/152276 for the build-system migration +--- tools/metadata/dependencies.py.orig 2026-09-02 17:44:01 UTC ++++ tools/metadata/dependencies.py +@@ -27,7 +27,7 @@ BASE_DEPENDENCIES = [ + BASE_DEPENDENCIES = [ + "filelock", + "typing-extensions>=4.10.0", +- "setuptools>=77.0.3", ++ "setuptools", + "sympy>=1.13.3", + "networkx>=2.5.1", + "jinja2", diff --git a/misc/py-pytorch/files/patch-torch___inductor_compile__worker_____main____.py b/misc/py-pytorch/files/patch-torch___inductor_compile__worker_____main____.py index 115e1cf1fd23..2b692e94caa0 100644 --- a/misc/py-pytorch/files/patch-torch___inductor_compile__worker_____main____.py +++ b/misc/py-pytorch/files/patch-torch___inductor_compile__worker_____main____.py @@ -1,11 +1,11 @@ ---- torch/_inductor/compile_worker/__main__.py.orig 2026-04-19 02:49:11 UTC +--- torch/_inductor/compile_worker/__main__.py.orig 2026-09-02 17:44:01 UTC +++ torch/_inductor/compile_worker/__main__.py -@@ -30,7 +30,7 @@ try: - import triton +@@ -31,7 +31,7 @@ try: - assert triton is not None # preload in parent + if triton is None: + raise AssertionError("triton failed to preload in parent") -except ImportError: +except (ImportError, AttributeError): pass