From 87c6cc241aa24a6d4bad07fb80b6f3991feb69c2 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 7 Jun 2024 12:46:30 -0700 Subject: [PATCH 01/10] Revert "Remove broken MPS build (#8472)" This reverts commit 4393f7df07e48f62e5001b2514ce178c34c0fda1. --- setup.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 753a50ffeed..fedbc370f72 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ import shutil import subprocess import sys -import warnings import torch from pkg_resources import DistributionNotFound, get_distribution, parse_version @@ -139,6 +138,7 @@ def get_extensions(): + glob.glob(os.path.join(extensions_dir, "ops", "cpu", "*.cpp")) + glob.glob(os.path.join(extensions_dir, "ops", "quantized", "cpu", "*.cpp")) ) + source_mps = glob.glob(os.path.join(extensions_dir, "ops", "mps", "*.mm")) print("Compiling extensions with following flags:") force_cuda = os.getenv("FORCE_CUDA", "0") == "1" @@ -204,15 +204,8 @@ def get_extensions(): define_macros += [("WITH_HIP", None)] nvcc_flags = [] extra_compile_args["nvcc"] = nvcc_flags - - # FIXME: MPS build breaks custom ops registration, so it was disabled. - # See https://github.com/pytorch/vision/issues/8456. - # TODO: Fix MPS build, remove warning below, and put back commented-out elif block.V - if force_mps: - warnings.warn("MPS build is temporarily disabled!!!!") - # elif torch.backends.mps.is_available() or force_mps: - # source_mps = glob.glob(os.path.join(extensions_dir, "ops", "mps", "*.mm")) - # sources += source_mps + elif torch.backends.mps.is_available() or force_mps: + sources += source_mps if sys.platform == "win32": define_macros += [("torchvision_EXPORTS", None)] From c57c54bc9cb4ecec58674a5f556b04ad1663e122 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 7 Jun 2024 19:51:22 -0700 Subject: [PATCH 02/10] Debug vision mps failure --- .github/workflows/build-wheels-m1.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-wheels-m1.yml b/.github/workflows/build-wheels-m1.yml index 76709b755e8..1f658b95242 100644 --- a/.github/workflows/build-wheels-m1.yml +++ b/.github/workflows/build-wheels-m1.yml @@ -32,6 +32,7 @@ jobs: matrix: include: - repository: pytorch/vision + env-var-script: packaging/env_var_script.sh pre-script: packaging/pre_build_script.sh post-script: packaging/post_build_script.sh smoke-test-script: test/smoke_test.py @@ -44,6 +45,7 @@ jobs: test-infra-repository: pytorch/test-infra test-infra-ref: main build-matrix: ${{ needs.generate-matrix.outputs.matrix }} + env-var-script: ${{ matrix.env-var-script }} pre-script: ${{ matrix.pre-script }} post-script: ${{ matrix.post-script }} package-name: ${{ matrix.package-name }} From 7c06376735696dae36406abefc640c5f74709b1f Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 7 Jun 2024 20:13:27 -0700 Subject: [PATCH 03/10] Debug --- .github/workflows/tests.yml | 2 +- packaging/env_var_script.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packaging/env_var_script.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ad327129912..bf5f8c108fb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -53,7 +53,7 @@ jobs: - "3.10" - "3.11" - "3.12" - runner: ["macos-m1-stable"] + runner: ["macos-m1-13"] fail-fast: false uses: pytorch/test-infra/.github/workflows/macos_job.yml@main with: diff --git a/packaging/env_var_script.sh b/packaging/env_var_script.sh new file mode 100644 index 00000000000..25eeb9f0db9 --- /dev/null +++ b/packaging/env_var_script.sh @@ -0,0 +1,6 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. +MACOSX_DEPLOYMENT_TARGET=11.0 From a0be9d6210d0e2385575c438b21cbc8fab0f8583 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 7 Jun 2024 20:46:16 -0700 Subject: [PATCH 04/10] Debug --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bf5f8c108fb..533a44a9e84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -53,7 +53,7 @@ jobs: - "3.10" - "3.11" - "3.12" - runner: ["macos-m1-13"] + runner: ["macos-m1-stable"] fail-fast: false uses: pytorch/test-infra/.github/workflows/macos_job.yml@main with: @@ -68,7 +68,7 @@ jobs: export GPU_ARCH_TYPE=cpu export GPU_ARCH_VERSION='' - ./.github/scripts/unittest.sh + ${CONDA_RUN} ./.github/scripts/unittest.sh unittests-windows: strategy: From fbefdccfe942960d2b99159cffbfbcb68ad4b95f Mon Sep 17 00:00:00 2001 From: Huy Do Date: Fri, 7 Jun 2024 20:57:37 -0700 Subject: [PATCH 05/10] Revert "Update usages of torch.library APIs (#8384)" This reverts commit a4713054873b0b695246a6d7fc5d5edc2c48052a. --- torchvision/_meta_registrations.py | 2 +- torchvision/csrc/ops/nms.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/torchvision/_meta_registrations.py b/torchvision/_meta_registrations.py index f75bfb77a7f..4ff55280e89 100644 --- a/torchvision/_meta_registrations.py +++ b/torchvision/_meta_registrations.py @@ -160,7 +160,7 @@ def meta_ps_roi_pool_backward( return grad.new_empty((batch_size, channels, height, width)) -@torch.library.register_fake("torchvision::nms") +@torch._custom_ops.impl_abstract("torchvision::nms") def meta_nms(dets, scores, iou_threshold): torch._check(dets.dim() == 2, lambda: f"boxes should be a 2d tensor, got {dets.dim()}D") torch._check(dets.size(1) == 4, lambda: f"boxes should have 4 elements in dimension 1, got {dets.size(1)}") diff --git a/torchvision/csrc/ops/nms.cpp b/torchvision/csrc/ops/nms.cpp index 5ecf8812f1b..07a934bce5a 100644 --- a/torchvision/csrc/ops/nms.cpp +++ b/torchvision/csrc/ops/nms.cpp @@ -19,7 +19,6 @@ at::Tensor nms( } TORCH_LIBRARY_FRAGMENT(torchvision, m) { - m.set_python_module("torchvision._meta_registrations"); m.def(TORCH_SELECTIVE_SCHEMA( "torchvision::nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor")); } From aacf17b04ee2f87881378c9e1fb4d32ab85997e5 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Sun, 9 Jun 2024 02:07:41 -0700 Subject: [PATCH 06/10] Revert "Revert "Update usages of torch.library APIs (#8384)"" This reverts commit fbefdccfe942960d2b99159cffbfbcb68ad4b95f. --- torchvision/_meta_registrations.py | 2 +- torchvision/csrc/ops/nms.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/torchvision/_meta_registrations.py b/torchvision/_meta_registrations.py index 4ff55280e89..f75bfb77a7f 100644 --- a/torchvision/_meta_registrations.py +++ b/torchvision/_meta_registrations.py @@ -160,7 +160,7 @@ def meta_ps_roi_pool_backward( return grad.new_empty((batch_size, channels, height, width)) -@torch._custom_ops.impl_abstract("torchvision::nms") +@torch.library.register_fake("torchvision::nms") def meta_nms(dets, scores, iou_threshold): torch._check(dets.dim() == 2, lambda: f"boxes should be a 2d tensor, got {dets.dim()}D") torch._check(dets.size(1) == 4, lambda: f"boxes should have 4 elements in dimension 1, got {dets.size(1)}") diff --git a/torchvision/csrc/ops/nms.cpp b/torchvision/csrc/ops/nms.cpp index 07a934bce5a..5ecf8812f1b 100644 --- a/torchvision/csrc/ops/nms.cpp +++ b/torchvision/csrc/ops/nms.cpp @@ -19,6 +19,7 @@ at::Tensor nms( } TORCH_LIBRARY_FRAGMENT(torchvision, m) { + m.set_python_module("torchvision._meta_registrations"); m.def(TORCH_SELECTIVE_SCHEMA( "torchvision::nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor")); } From 70a4ea842b0bf4e04f16e0fb4c40fbf38ed45a42 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Sun, 9 Jun 2024 02:08:19 -0700 Subject: [PATCH 07/10] Re-enable vision MPS builds --- .github/workflows/build-wheels-m1.yml | 2 -- packaging/env_var_script.sh | 6 ------ 2 files changed, 8 deletions(-) delete mode 100644 packaging/env_var_script.sh diff --git a/.github/workflows/build-wheels-m1.yml b/.github/workflows/build-wheels-m1.yml index 1f658b95242..76709b755e8 100644 --- a/.github/workflows/build-wheels-m1.yml +++ b/.github/workflows/build-wheels-m1.yml @@ -32,7 +32,6 @@ jobs: matrix: include: - repository: pytorch/vision - env-var-script: packaging/env_var_script.sh pre-script: packaging/pre_build_script.sh post-script: packaging/post_build_script.sh smoke-test-script: test/smoke_test.py @@ -45,7 +44,6 @@ jobs: test-infra-repository: pytorch/test-infra test-infra-ref: main build-matrix: ${{ needs.generate-matrix.outputs.matrix }} - env-var-script: ${{ matrix.env-var-script }} pre-script: ${{ matrix.pre-script }} post-script: ${{ matrix.post-script }} package-name: ${{ matrix.package-name }} diff --git a/packaging/env_var_script.sh b/packaging/env_var_script.sh deleted file mode 100644 index 25eeb9f0db9..00000000000 --- a/packaging/env_var_script.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. -# All rights reserved. -# -# This source code is licensed under the BSD-style license found in the -# LICENSE file in the root directory of this source tree. -MACOSX_DEPLOYMENT_TARGET=11.0 From d0220926605e901f590480b27fa1c7fe7aa9f494 Mon Sep 17 00:00:00 2001 From: Huy Do Date: Sun, 9 Jun 2024 02:16:32 -0700 Subject: [PATCH 08/10] Another $CONDA_RUN --- .github/workflows/build-cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-cmake.yml b/.github/workflows/build-cmake.yml index 1dce7b8446a..1ab20669f0b 100644 --- a/.github/workflows/build-cmake.yml +++ b/.github/workflows/build-cmake.yml @@ -54,7 +54,7 @@ jobs: export GPU_ARCH_TYPE=cpu export GPU_ARCH_VERSION='' - ./.github/scripts/cmake.sh + ${CONDA_RUN} ./.github/scripts/cmake.sh windows: strategy: From e2809de2f8284f6a5794dca811c642f68c852158 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 10 Jun 2024 10:04:46 +0100 Subject: [PATCH 09/10] Put back MPS tests as well --- test/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 89b4946e612..a9768598ded 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -49,8 +49,7 @@ def pytest_collection_modifyitems(items): # There are special cases though, see below item.add_marker(pytest.mark.skip(reason=CUDA_NOT_AVAILABLE_MSG)) - # TODO: uncoment when MPS works again - see FIXME in setup.py - if needs_mps: # and not torch.backends.mps.is_available(): + if needs_mps and not torch.backends.mps.is_available(): item.add_marker(pytest.mark.skip(reason=MPS_NOT_AVAILABLE_MSG)) if IN_FBCODE: From 8c6084c77dc3302bcc05454d88d2ff8cf10bef81 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 10 Jun 2024 13:51:37 +0100 Subject: [PATCH 10/10] empty