misc/pytorch: Tensors and dynamic neural networks in Python (C++ library)
This commit is contained in:
parent
6946da3134
commit
639e0f24c6
@ -445,6 +445,7 @@
|
||||
SUBDIR += py-wurlitzer
|
||||
SUBDIR += py-xgboost
|
||||
SUBDIR += pyobd
|
||||
SUBDIR += pytorch
|
||||
SUBDIR += qbrew
|
||||
SUBDIR += qlas
|
||||
SUBDIR += qt5-doc
|
||||
|
63
misc/pytorch/Makefile
Normal file
63
misc/pytorch/Makefile
Normal file
@ -0,0 +1,63 @@
|
||||
PORTNAME= pytorch
|
||||
DISTVERSIONPREFIX= v
|
||||
DISTVERSION= 1.13.1
|
||||
CATEGORIES= misc # machine-learning
|
||||
MASTER_SITES= https://github.com/pytorch/pytorch/releases/download/v1.13.1/
|
||||
DIST_SUBDIR= ${PORTNAME}
|
||||
|
||||
MAINTAINER= yuri@FreeBSD.org
|
||||
COMMENT= Tensors and dynamic neural networks in Python (C++ library)
|
||||
WWW= https://pytorch.org/
|
||||
|
||||
LICENSE= BSD3CLAUSE
|
||||
|
||||
BUILD_DEPENDS= gmake:devel/gmake \
|
||||
${LOCALBASE}/include/fxdiv.h:devel/fxdiv
|
||||
LIB_DEPENDS= libopenblas.so:math/openblas \
|
||||
libmpi.so:net/openmpi \
|
||||
libpthreadpool.so:devel/pthreadpool \
|
||||
libonnx.so:misc/onnx \
|
||||
libprotobuf.so:devel/protobuf \
|
||||
libsleef.so:math/sleef
|
||||
|
||||
USES= compiler:c++14-lang cmake localbase:ldflags python # requires python even with PYTHON=off
|
||||
|
||||
CMAKE_OFF= BUILD_CUSTOM_PROTOBUF USE_CUDA USE_ROCM USE_NNPACK USE_QNNPACK USE_PYTORCH_QNNPACK \
|
||||
USE_FBGEMM # workaround recommended by the upstream here: https://github.com/pytorch/pytorch/issues/28337
|
||||
CMAKE_ON= USE_SYSTEM_PYBIND11 \
|
||||
USE_SYSTEM_SLEEF \
|
||||
USE_SYSTEM_ONNX # see other USE_SYSTEM_xx in CMakeLists.txt
|
||||
CMAKE_ARGS= -DPSIMD_SOURCE_DIR=${WRKSRC}/third_party/psimd \
|
||||
-DFREEBSD_PYTHON_VER=${PYTHON_VER} \
|
||||
-DPYTHON_EXECUTABLE:STRING=${PYTHON_CMD}
|
||||
|
||||
MAKE_ENV= USE_NINJA=no # ninja breaks for some reason
|
||||
LDFLAGS+= -lexecinfo
|
||||
|
||||
BINARY_ALIAS= make=${GMAKE} git=true
|
||||
|
||||
OPTIONS_DEFINE= PYTHON # PYTHON only provides python support for the py-PyTorch port - it's not a python binding
|
||||
OPTIONS_DEFAULT= PYTHON
|
||||
OPTIONS_SUB= yes
|
||||
|
||||
PYTHON_CMAKE_BOOL= BUILD_PYTHON
|
||||
PYTHON_PY_DEPENDS= ${PYNUMPY} \
|
||||
${PYTHON_PKGNAMEPREFIX}typing-extensions>0:devel/py-typing-extensions@${PY_FLAVOR} \
|
||||
${PYTHON_PKGNAMEPREFIX}yaml>0:devel/py-yaml@${PY_FLAVOR}
|
||||
PYTHON_BUILD_DEPENDS= ${PYTHON_PY_DEPENDS} \
|
||||
pybind11>0:devel/pybind11
|
||||
PYTHON_RUN_DEPENDS= ${PYTHON_PY_DEPENDS}
|
||||
|
||||
post-patch:
|
||||
# replace malloc.h -> stdlib.h in many places
|
||||
@cd ${WRKSRC} && for f in $$(${GREP} -rl "include <malloc\.h>" * | ${GREP} -E "\.(c|cpp|h|hpp)$$"); do \
|
||||
${REINPLACE_CMD} -i'' -E "s|include <malloc\.h>|include <stdlib.h>|" $$f; \
|
||||
done
|
||||
|
||||
post-install:
|
||||
# functorch.so is installed back into the source directory, see https://github.com/pytorch/pytorch/issues/91524
|
||||
@${RM} $$(${FIND} ${STAGEDIR} -name functorch.so)
|
||||
# https://github.com/pytorch/pytorch/issues/24417
|
||||
@${FIND} ${STAGEDIR} -type d -empty -delete
|
||||
|
||||
.include <bsd.port.mk>
|
3
misc/pytorch/distinfo
Normal file
3
misc/pytorch/distinfo
Normal file
@ -0,0 +1,3 @@
|
||||
TIMESTAMP = 1672353185
|
||||
SHA256 (pytorch/pytorch-v1.13.1.tar.gz) = dbc229ee9750b02b514937d017744443a269ea0241ed3f32b9af0703589d25d4
|
||||
SIZE (pytorch/pytorch-v1.13.1.tar.gz) = 234057741
|
11
misc/pytorch/files/patch-aten_src_ATen_native_SoftMax.cpp
Normal file
11
misc/pytorch/files/patch-aten_src_ATen_native_SoftMax.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
--- aten/src/ATen/native/SoftMax.cpp.orig 2022-12-29 23:05:30 UTC
|
||||
+++ aten/src/ATen/native/SoftMax.cpp
|
||||
@@ -132,7 +132,7 @@ void host_softmax(
|
||||
const Tensor& input,
|
||||
const int64_t dim,
|
||||
bool* mask = nullptr,
|
||||
- const c10::optional<int64_t> mask_type_ = NULL) {
|
||||
+ const c10::optional<int64_t> mask_type_ = 0) {
|
||||
|
||||
if (MaskedSoftMax) {
|
||||
TORCH_CHECK(mask_type_.has_value(), "Mask Type should be defined");
|
@ -0,0 +1,80 @@
|
||||
--- aten/src/ATen/native/sparse/ValidateCompressedIndicesCommon.h.orig 2022-12-29 23:09:42 UTC
|
||||
+++ aten/src/ATen/native/sparse/ValidateCompressedIndicesCommon.h
|
||||
@@ -38,7 +38,7 @@ namespace {
|
||||
// respectively.
|
||||
|
||||
INVARIANT_CHECK_FUNC_API
|
||||
-_assert(const bool cond, const char* const message) {
|
||||
+__assert__(const bool cond, const char* const message) {
|
||||
#ifdef GPUCC
|
||||
CUDA_KERNEL_ASSERT(cond && message);
|
||||
#else
|
||||
@@ -58,10 +58,10 @@ INVARIANT_CHECK_FUNC_API
|
||||
_check_first_cidx_is_zero(const index_t& cidx, const index_t& zero) {
|
||||
const bool invariant = cidx == zero;
|
||||
if (cdim_name == CDimName::CRow) {
|
||||
- _assert(invariant, "`crow_indices[..., 0] == 0` is not satisfied.");
|
||||
+ __assert__(invariant, "`crow_indices[..., 0] == 0` is not satisfied.");
|
||||
}
|
||||
else {
|
||||
- _assert(invariant, "`ccol_indices[..., 0] == 0` is not satisfied.");
|
||||
+ __assert__(invariant, "`ccol_indices[..., 0] == 0` is not satisfied.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ INVARIANT_CHECK_FUNC_API
|
||||
_check_last_cidx_is_nnz(const index_t& cidx, const index_t& nnz) {
|
||||
const bool invariant = cidx == nnz;
|
||||
if (cdim_name == CDimName::CRow) {
|
||||
- _assert(invariant, "`crow_indices[..., -1] == nnz` is not satisfied.");
|
||||
+ __assert__(invariant, "`crow_indices[..., -1] == nnz` is not satisfied.");
|
||||
}
|
||||
else {
|
||||
- _assert(invariant, "`ccol_indices[..., -1] == nnz` is not satisfied.");
|
||||
+ __assert__(invariant, "`ccol_indices[..., -1] == nnz` is not satisfied.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ _check_cidx_nondecreasing_locally_bounded_sequence(
|
||||
const auto s_cidx = cidx_next - cidx;
|
||||
const bool invariant = zero <= s_cidx && s_cidx <= dim;
|
||||
if (cdim_name == CDimName::CRow) {
|
||||
- _assert(invariant,
|
||||
+ __assert__(invariant,
|
||||
"`0 <= crow_indices[..., 1:] - crow_indices[..., :-1] <= ncols` is not satisfied.");
|
||||
}
|
||||
else {
|
||||
- _assert(invariant,
|
||||
+ __assert__(invariant,
|
||||
"`0 <= ccol_indices[..., 1:] - ccol_indices[..., :-1] <= nrows` is not satisfied.");
|
||||
}
|
||||
}
|
||||
@@ -110,10 +110,10 @@ _check_idx_bounds(
|
||||
const index_t& dim) {
|
||||
const bool invariant = zero <= idx && idx < dim;
|
||||
if (cdim_name == CDimName::CRow) {
|
||||
- _assert(invariant, "`0 <= col_indices < ncols` is not satisfied.");
|
||||
+ __assert__(invariant, "`0 <= col_indices < ncols` is not satisfied.");
|
||||
}
|
||||
else {
|
||||
- _assert(invariant, "`0 <= row_indices < nrows` is not satisfied.");
|
||||
+ __assert__(invariant, "`0 <= row_indices < nrows` is not satisfied.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,13 +133,13 @@ _check_idx_sorted_distinct_vals_slices_with_cidx(
|
||||
for (auto* RESTRICT curr = slice_begin + 1; curr < slice_end; ++curr) {
|
||||
const auto invariant = *(curr - 1) < *curr;
|
||||
if (cdim_name == CDimName::CRow) {
|
||||
- _assert(invariant, "`col_indices[..., crow_indices[..., i - 1]:crow_indices[..., i]] "
|
||||
+ __assert__(invariant, "`col_indices[..., crow_indices[..., i - 1]:crow_indices[..., i]] "
|
||||
"for all i = 1, ..., nrows "
|
||||
"are sorted and distinct along the last dimension values` "
|
||||
"is not satisfied.");
|
||||
}
|
||||
else {
|
||||
- _assert(invariant, "`row_indices[..., ccol_indices[..., i - 1]:ccol_indices[..., i]] "
|
||||
+ __assert__(invariant, "`row_indices[..., ccol_indices[..., i - 1]:ccol_indices[..., i]] "
|
||||
"for all i = 1, ..., ncols "
|
||||
"are sorted and distinct along the last dimension values` "
|
||||
"is not satisfied.");
|
@ -0,0 +1,11 @@
|
||||
--- aten/src/ATen/native/transformers/attention.cpp.orig 2022-12-29 23:18:12 UTC
|
||||
+++ aten/src/ATen/native/transformers/attention.cpp
|
||||
@@ -118,7 +118,7 @@ Tensor masked_softmax(
|
||||
Tensor& attn_scores,
|
||||
c10::optional<Tensor> attn_mask,
|
||||
const Tensor& query,
|
||||
- c10::optional<int64_t> mask_type = NULL) {
|
||||
+ c10::optional<int64_t> mask_type = 0) {
|
||||
if (query.is_nested() && !attn_mask) {
|
||||
return at::_nested_tensor_softmax_with_shape(attn_scores, query);
|
||||
}
|
11
misc/pytorch/files/patch-cmake_Dependencies.cmake
Normal file
11
misc/pytorch/files/patch-cmake_Dependencies.cmake
Normal file
@ -0,0 +1,11 @@
|
||||
--- cmake/Dependencies.cmake.orig 2022-12-16 00:23:46 UTC
|
||||
+++ cmake/Dependencies.cmake
|
||||
@@ -339,7 +339,7 @@ if(USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR
|
||||
set(DISABLE_NNPACK_AND_FAMILY ON)
|
||||
endif()
|
||||
else()
|
||||
- if(NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|Darwin|Windows)$"))
|
||||
+ if(NOT IOS AND NOT (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux|FreeBSD|Darwin|Windows)$"))
|
||||
message(WARNING
|
||||
"Target platform \"${CMAKE_SYSTEM_NAME}\" is not supported in {Q/X}NNPACK. "
|
||||
"Supported platforms are Android, iOS, Linux, and macOS. "
|
11
misc/pytorch/files/patch-cmake_public_mkldnn.cmake
Normal file
11
misc/pytorch/files/patch-cmake_public_mkldnn.cmake
Normal file
@ -0,0 +1,11 @@
|
||||
--- cmake/public/mkldnn.cmake.orig 2022-12-16 00:23:46 UTC
|
||||
+++ cmake/public/mkldnn.cmake
|
||||
@@ -4,7 +4,7 @@ if(CPU_AARCH64)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/ComputeLibrary.cmake)
|
||||
endif()
|
||||
|
||||
-find_package(MKLDNN QUIET)
|
||||
+find_package(MKLDNN REQUIRED)
|
||||
|
||||
if(NOT TARGET caffe2::mkldnn)
|
||||
add_library(caffe2::mkldnn INTERFACE IMPORTED)
|
11
misc/pytorch/files/patch-third__party_cpuinfo_CMakeLists.txt
Normal file
11
misc/pytorch/files/patch-third__party_cpuinfo_CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
--- third_party/cpuinfo/CMakeLists.txt.orig 2022-12-16 00:23:47 UTC
|
||||
+++ third_party/cpuinfo/CMakeLists.txt
|
||||
@@ -77,7 +77,7 @@ IF(NOT CMAKE_SYSTEM_NAME)
|
||||
"Target operating system is not specified. "
|
||||
"cpuinfo will compile, but cpuinfo_initialize() will always fail.")
|
||||
SET(CPUINFO_SUPPORTED_PLATFORM FALSE)
|
||||
-ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS|Darwin|Linux|Android)$")
|
||||
+ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS|Darwin|Linux|FreeBSD|Android)$")
|
||||
IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||
MESSAGE(WARNING
|
||||
"Target operating system \"${CMAKE_SYSTEM_NAME}\" is not supported in cpuinfo. "
|
@ -0,0 +1,10 @@
|
||||
--- third_party/fbgemm/third_party/asmjit/src/asmjit/core/virtmem.cpp.orig 2022-12-16 00:23:48 UTC
|
||||
+++ third_party/fbgemm/third_party/asmjit/src/asmjit/core/virtmem.cpp
|
||||
@@ -45,6 +45,7 @@
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
+#include <sys/stat.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__BIONIC__)
|
||||
#define ASMJIT_VM_SHM_DETECT 0
|
@ -0,0 +1,11 @@
|
||||
--- third_party/kineto/libkineto/src/ThreadUtil.cpp.orig 2022-12-29 22:41:51 UTC
|
||||
+++ third_party/kineto/libkineto/src/ThreadUtil.cpp
|
||||
@@ -49,7 +49,7 @@ int32_t systemThreadId() {
|
||||
#elif defined _MSC_VER
|
||||
_sysTid = (int32_t)GetCurrentThreadId();
|
||||
#else
|
||||
- _sysTid = (int32_t)syscall(SYS_gettid);
|
||||
+ _sysTid = (int32_t)syscall(SYS_getpid);
|
||||
#endif
|
||||
}
|
||||
return _sysTid;
|
3
misc/pytorch/pkg-descr
Normal file
3
misc/pytorch/pkg-descr
Normal file
@ -0,0 +1,3 @@
|
||||
PyTorch is a Python package that provides two high-level features:
|
||||
* Tensor computation (like NumPy) with strong GPU acceleration
|
||||
* Deep neural networks built on a tape-based autograd system
|
8950
misc/pytorch/pkg-plist
Normal file
8950
misc/pytorch/pkg-plist
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user