Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytorch 2.4.1 #184012

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 32 additions & 69 deletions Formula/p/pytorch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ class Pytorch < Formula

desc "Tensors and dynamic neural networks"
homepage "https://pytorch.org/"
url "https://github.com/pytorch/pytorch/releases/download/v2.2.0/pytorch-v2.2.0.tar.gz"
sha256 "e12d18c3dbb12d7ae2f61f5ab9a21023e3dd179d67ed87279ef96600b9ac08c5"
url "https://github.com/pytorch/pytorch/releases/download/v2.4.1/pytorch-v2.4.1.tar.gz"
sha256 "39666a43c0c10f5fd46c1a7ca95dc74d3bc39de2678b70066481cbf02e58384f"
license "BSD-3-Clause"
revision 11

livecheck do
url :stable
Expand Down Expand Up @@ -42,18 +41,18 @@ class Pytorch < Formula
end

resource "filelock" do
url "https://files.pythonhosted.org/packages/70/70/41905c80dcfe71b22fb06827b8eae65781783d4a14194bce79d16a013263/filelock-3.13.1.tar.gz"
sha256 "521f5f56c50f8426f5e03ad3b281b490a87ef15bc6c526f168290f0c7148d44e"
url "https://files.pythonhosted.org/packages/9d/db/3ef5bb276dae18d6ec2124224403d1d67bccdbefc17af4cc8f553e341ab1/filelock-3.16.1.tar.gz"
sha256 "c249fbfcd5db47e5e2d6d62198e565475ee65e4831e2561c8e313fa7eb961435"
end

resource "fsspec" do
url "https://files.pythonhosted.org/packages/28/d3/c2e0403c735548abf991bba3f45ba39194dff4569f76a99fbe77078ba7c5/fsspec-2024.2.0.tar.gz"
sha256 "b6ad1a679f760dda52b1168c859d01b7b80648ea6f7f7c7f5a8a91dc3f3ecb84"
url "https://files.pythonhosted.org/packages/62/7c/12b0943011daaaa9c35c2a2e22e5eb929ac90002f08f1259d69aedad84de/fsspec-2024.9.0.tar.gz"
sha256 "4b0afb90c2f21832df142f292649035d80b421f60a9e1c027802e5a0da2b04e8"
end

resource "jinja2" do
url "https://files.pythonhosted.org/packages/b2/5e/3a21abf3cd467d7876045335e681d276ac32492febe6d98ad89562d1a7e1/Jinja2-3.1.3.tar.gz"
sha256 "ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90"
url "https://files.pythonhosted.org/packages/ed/55/39036716d19cab0747a5020fc7e907f362fbf48c984b14e62127f7e68e5d/jinja2-3.1.4.tar.gz"
sha256 "4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369"
end

resource "markupsafe" do
Expand All @@ -67,8 +66,8 @@ class Pytorch < Formula
end

resource "networkx" do
url "https://files.pythonhosted.org/packages/c4/80/a84676339aaae2f1cfdf9f418701dd634aef9cc76f708ef55c36ff39c3ca/networkx-3.2.1.tar.gz"
sha256 "9f1bb5cf3409bf324e0a722c20bdb4c20ee39bf1c30ce8ae499c8502b0b5e0c6"
url "https://files.pythonhosted.org/packages/04/e6/b164f94c869d6b2c605b5128b7b0cfe912795a87fc90e78533920001f3ec/networkx-3.3.tar.gz"
sha256 "0c127d8b2f4865f59ae9cb8aafcd60b5c70f3241ebd66f7defad7c4ab90126c9"
end

resource "opt-einsum" do
Expand All @@ -83,47 +82,42 @@ class Pytorch < Formula
end

resource "pyyaml" do
url "https://files.pythonhosted.org/packages/cd/e5/af35f7ea75cf72f2cd079c95ee16797de7cd71f29ea7c68ae5ce7be1eda0/PyYAML-6.0.1.tar.gz"
sha256 "bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"
url "https://files.pythonhosted.org/packages/54/ed/79a089b6be93607fa5cdaedf301d7dfb23af5f25c398d5ead2525b063e17/pyyaml-6.0.2.tar.gz"
sha256 "d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e"
end

resource "setuptools" do
url "https://files.pythonhosted.org/packages/c8/1f/e026746e5885a83e1af99002ae63650b7c577af5c424d4c27edcf729ab44/setuptools-69.1.1.tar.gz"
sha256 "5c0806c7d9af348e6dd3777b4f4dbb42c7ad85b190104837488eab9a7c945cf8"
url "https://files.pythonhosted.org/packages/27/b8/f21073fde99492b33ca357876430822e4800cdf522011f18041351dfa74b/setuptools-75.1.0.tar.gz"
sha256 "d59a21b17a275fb872a9c3dae73963160ae079f1049ed956880cd7c09b120538"
end

resource "sympy" do
url "https://files.pythonhosted.org/packages/e5/57/3485a1a3dff51bfd691962768b14310dae452431754bfc091250be50dd29/sympy-1.12.tar.gz"
sha256 "ebf595c8dac3e0fdc4152c51878b498396ec7f30e7a914d6071e674d49420fb8"
url "https://files.pythonhosted.org/packages/11/8a/5a7fd6284fa8caac23a26c9ddf9c30485a48169344b4bd3b0f02fef1890f/sympy-1.13.3.tar.gz"
sha256 "b27fd2c6530e0ab39e275fc9b683895367e51d5da91baa8d3d64db2565fec4d9"
end

resource "typing-extensions" do
url "https://files.pythonhosted.org/packages/0c/1d/eb26f5e75100d531d7399ae800814b069bc2ed2a7410834d57374d010d96/typing_extensions-4.9.0.tar.gz"
sha256 "23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"
url "https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec321ba8bce9420de607a1d37f8342eee1863174c69557/typing_extensions-4.12.2.tar.gz"
sha256 "1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"
end

# Support numpy 2.0: https://github.com/pytorch/pytorch/pull/121880
patch do
url "https://github.com/pytorch/pytorch/commit/38d9bb5abcc31ba97927a5399b88afe2cf60bf64.patch?full_index=1"
sha256 "c9bf84d154e5f3f9b67a68d25765f32a08b9deb3127254971ed6351231eba228"
end

# Backport usage of SLEEF_CONST from upstream commit
# Ref: https://github.com/pytorch/pytorch/commit/2b060983809e5fe8706acd085fff67b6a27bfb5f
patch :DATA

def install
python3 = "python3.12"

# Avoid building AVX512 code
inreplace "cmake/Modules/FindAVX.cmake", /^CHECK_SSE\(CXX "AVX512"/, "#\\0"

ENV["ATEN_NO_TEST"] = "ON"
ENV["BLAS"] = "OpenBLAS"
ENV["BUILD_CUSTOM_PROTOBUF"] = "OFF"
ENV["BUILD_PYTHON"] = "ON"
ENV["BUILD_TEST"] = "OFF"
ENV["PYTHON_EXECUTABLE"] = which(python3)
ENV["PYTORCH_BUILD_VERSION"] = version.to_s
ENV["PYTORCH_BUILD_NUMBER"] = "1"
ENV["USE_CCACHE"] = "OFF"
ENV["USE_CUDA"] = "OFF"
ENV["USE_DISTRIBUTED"] = "ON"
ENV["USE_METAL"] = "OFF"
ENV["USE_MKLDNN"] = "OFF"
ENV["USE_NNPACK"] = "OFF"
ENV["USE_OPENMP"] = "ON"
Expand All @@ -134,7 +128,7 @@ def install

# Work around superenv removing `-Werror=` but leaving `-Wno-error=` breaking flag detection
if ENV.compiler.to_s.start_with?("gcc")
inreplace "CMakeLists.txt", 'append_cxx_flag_if_supported("-Wno-error=inconsistent-missing-', "# \\0"
inreplace "CMakeLists.txt", /^\s*append_cxx_flag_if_supported\(\s*"-Wno-error=inconsistent-missing-[^)]*\)/, ""
end

# Avoid references to Homebrew shims
Expand All @@ -145,7 +139,7 @@ def install
venv.pip_install_and_link(buildpath, build_isolation: false)

# Expose C++ API
torch = libexec/Language::Python.site_packages(python3)/"torch"
torch = venv.site_packages/"torch"
include.install_symlink (torch/"include").children
lib.install_symlink (torch/"lib").children
(share/"cmake").install_symlink (torch/"share/cmake").children
Expand Down Expand Up @@ -174,43 +168,12 @@ def install
assert isinstance(t, torch.Tensor), "not a tensor"
assert torch.distributed.is_available(), "torch.distributed is unavailable"
EOS
return unless OS.mac?

if OS.mac?
# test that we have the MPS backend
system libexec/"bin/python", "-c", <<~EOS
import torch
assert torch.backends.mps.is_built(), "MPS backend is not built"
EOS
end
# test that we have the MPS backend
system libexec/"bin/python", "-c", <<~EOS
import torch
assert torch.backends.mps.is_built(), "MPS backend is not built"
EOS
end
end

__END__
diff --git a/aten/src/ATen/cpu/vec/vec256/vec256_bfloat16.h b/aten/src/ATen/cpu/vec/vec256/vec256_bfloat16.h
index 3e26213d6d26609b2cda7bde2d026fc92c626db2..edda0210746530bb60765939e90899083f8be595 100644
--- a/aten/src/ATen/cpu/vec/vec256/vec256_bfloat16.h
+++ b/aten/src/ATen/cpu/vec/vec256/vec256_bfloat16.h
@@ -265,7 +266,8 @@ static_assert(
}
return b;
}
- Vectorized<T> map(const __m256 (*const vop)(__m256)) const {
+
+ Vectorized<T> map(SLEEF_CONST __m256 (*vop)(__m256)) const {
__m256 lo, hi;
cvt_to_fp32<T>(values, lo, hi);
const auto o1 = vop(lo);
diff --git a/aten/src/ATen/cpu/vec/vec512/vec512_bfloat16.h b/aten/src/ATen/cpu/vec/vec512/vec512_bfloat16.h
index f9fc92d52bfe0c8ea594384beecf4da47961faa0..6513455283e2be3e588fd15131c5d48a17e107bb 100644
--- a/aten/src/ATen/cpu/vec/vec512/vec512_bfloat16.h
+++ b/aten/src/ATen/cpu/vec/vec512/vec512_bfloat16.h
@@ -362,7 +363,8 @@ static_assert(
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-qualifiers"
- Vectorized<T> map(const __m512 (*const vop)(__m512)) const {
+
+ Vectorized<T> map(SLEEF_CONST __m512 (*vop)(__m512)) const {
__m512 lo, hi;
cvt_to_fp32<T>(values, lo, hi);
const auto o1 = vop(lo);
30 changes: 5 additions & 25 deletions Formula/t/torchvision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ class Torchvision < Formula

desc "Datasets, transforms, and models for computer vision"
homepage "https://github.com/pytorch/vision"
url "https://github.com/pytorch/vision/archive/refs/tags/v0.17.0.tar.gz"
sha256 "55e395d5c7d9bf7658c82ac633cac2224aa168e1bfe8bb5b2b2a296c792a3500"
url "https://github.com/pytorch/vision/archive/refs/tags/v0.19.1.tar.gz"
sha256 "083e75c467285595ec3eb3c7aa8493c19e53d7eb42f13046fb56a07c8897e5a8"
license "BSD-3-Clause"
revision 11

livecheck do
url :stable
Expand Down Expand Up @@ -38,26 +37,6 @@ class Torchvision < Formula
depends_on "libomp"
end

resource "charset-normalizer" do
url "https://files.pythonhosted.org/packages/63/09/c1bc53dab74b1816a00d8d030de5bf98f724c52c1635e07681d312f20be8/charset-normalizer-3.3.2.tar.gz"
sha256 "f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"
end

resource "idna" do
url "https://files.pythonhosted.org/packages/e8/ac/e349c5e6d4543326c6883ee9491e3921e0d07b55fdf3cce184b40d63e72a/idna-3.8.tar.gz"
sha256 "d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603"
end

resource "requests" do
url "https://files.pythonhosted.org/packages/63/70/2bf7780ad2d390a8d301ad0b550f1581eadbd9a20f896afe06353c2a2913/requests-2.32.3.tar.gz"
sha256 "55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"
end

resource "urllib3" do
url "https://files.pythonhosted.org/packages/43/6d/fa469ae21497ddc8bc93e5877702dca7cb8f911e337aca7452b5724f1bb6/urllib3-2.2.2.tar.gz"
sha256 "dd505485549a7a552833da5e6063639d0d177c04f23bc3864e41e5dc5f612168"
end

def install
system "cmake", "-S", ".", "-B", "build", *std_cmake_args
system "cmake", "--build", "build"
Expand All @@ -74,9 +53,10 @@ def install

# We depend on pytorch, but that's a separate formula, so install a `.pth` file to link them.
# This needs to happen _before_ we try to install torchvision.
# NOTE: This is an exception to our usual policy as building `pytorch` is complicated
site_packages = Language::Python.site_packages(python3)
pytorch = Formula["pytorch"].opt_libexec
(libexec/site_packages/"homebrew-pytorch.pth").write pytorch/site_packages
pth_contents = "import site; site.addsitedir('#{Formula["pytorch"].opt_libexec/site_packages}')\n"
(venv.site_packages/"homebrew-pytorch.pth").write pth_contents

venv.pip_install_and_link(buildpath, build_isolation: false)

Expand Down
5 changes: 5 additions & 0 deletions pypi_formula_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@
"pythran": {
"exclude_packages": ["numpy"]
},
"pytorch": {
"package_name": "torch[opt-einsum]",
"extra_packages": ["pyyaml"],
"exclude_packages": ["numpy"]
},
"raven": {
"exclude_packages": ["certifi"]
},
Expand Down
Loading