From 6282f2c2d96f8b8e5578aa584d99ba26a74cd4bc Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Tue, 12 Nov 2024 13:15:46 +0000 Subject: [PATCH 01/10] Reapply "Fix memory leak in decode_webp (#8712)" (#8723) This reverts commit 7d077f131217dc03813d97d7524ea3aeba7dd7e1. --- torchvision/csrc/io/image/cpu/decode_webp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torchvision/csrc/io/image/cpu/decode_webp.cpp b/torchvision/csrc/io/image/cpu/decode_webp.cpp index b202473c039..0a9ff9ddbce 100644 --- a/torchvision/csrc/io/image/cpu/decode_webp.cpp +++ b/torchvision/csrc/io/image/cpu/decode_webp.cpp @@ -44,10 +44,12 @@ torch::Tensor decode_webp( auto decoded_data = decoding_func(encoded_data_p, encoded_data_size, &width, &height); + TORCH_CHECK(decoded_data != nullptr, "WebPDecodeRGB[A] failed."); + auto deleter = [decoded_data](void*) { WebPFree(decoded_data); }; auto out = torch::from_blob( - decoded_data, {height, width, num_channels}, torch::kUInt8); + decoded_data, {height, width, num_channels}, deleter, torch::kUInt8); return out.permute({2, 0, 1}); } From cb3bd780589c2835e0d1277faf15806eb40b38de Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 27 Nov 2024 14:23:34 +0000 Subject: [PATCH 02/10] Don't build webp support on rocm --- setup.py | 7 ++++++- test/test_image.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c2be57e9775..a5234288458 100644 --- a/setup.py +++ b/setup.py @@ -320,7 +320,12 @@ def make_image_extension(): else: warnings.warn("Building torchvision without JPEG support") - if USE_WEBP: + if USE_WEBP and IS_ROCM: + warnings.warn( + "Cannot enable webp support on rocm. " + "See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558." + ) + elif USE_WEBP: webp_found, webp_include_dir, webp_library_dir = find_library(header="webp/decode.h") if webp_found: print("Building torchvision with WEBP support") diff --git a/test/test_image.py b/test/test_image.py index f3c2984b348..6129abe8895 100644 --- a/test/test_image.py +++ b/test/test_image.py @@ -45,6 +45,9 @@ IS_MACOS = sys.platform == "darwin" PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split(".")) WEBP_TEST_IMAGES_DIR = os.environ.get("WEBP_TEST_IMAGES_DIR", "") +IS_ROCM = torch.version.hip is not None +# See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558 +ROCM_WEBP_MESSAGE = "ROCM not built with webp support." # Hacky way of figuring out whether we compiled with libavif/libheif (those are # currenlty disabled by default) @@ -869,6 +872,7 @@ def test_decode_gif(tmpdir, name, scripted): (decode_jpeg, "Not a JPEG file"), (decode_gif, re.escape("DGifOpenFileName() failed - 103")), (decode_webp, "WebPGetFeatures failed."), + pytest.param(decode_webp, "WebPGetFeatures failed.", marks=pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE)), ] if DECODE_AVIF_ENABLED: decode_fun_and_match.append((_decode_avif, "BMFF parsing failed")) @@ -889,6 +893,7 @@ def test_decode_bad_encoded_data(decode_fun, match): decode_fun(encoded_data) +@pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE) @pytest.mark.parametrize("decode_fun", (decode_webp, decode_image)) @pytest.mark.parametrize("scripted", (False, True)) def test_decode_webp(decode_fun, scripted): @@ -905,6 +910,7 @@ def test_decode_webp(decode_fun, scripted): # including within the repo. The test images were downloaded manually from the # different pages of https://developers.google.com/speed/webp/gallery @pytest.mark.skipif(not WEBP_TEST_IMAGES_DIR, reason="WEBP_TEST_IMAGES_DIR is not set") +@pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE) @pytest.mark.parametrize("decode_fun", (decode_webp, decode_image)) @pytest.mark.parametrize("scripted", (False, True)) @pytest.mark.parametrize( From a4e53ebe931da7cfa1e7a81e71922dc3d3c1a9af Mon Sep 17 00:00:00 2001 From: atalman Date: Wed, 27 Nov 2024 10:28:14 -0800 Subject: [PATCH 03/10] Switch unit test back to Manylinux2014 --- .github/workflows/prototype-tests-linux-gpu.yml | 2 +- .github/workflows/tests.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/prototype-tests-linux-gpu.yml b/.github/workflows/prototype-tests-linux-gpu.yml index e1d6498761b..ffa2dd650fe 100644 --- a/.github/workflows/prototype-tests-linux-gpu.yml +++ b/.github/workflows/prototype-tests-linux-gpu.yml @@ -23,7 +23,7 @@ jobs: gpu-arch-type: cuda gpu-arch-version: "11.8" fail-fast: false - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main with: repository: pytorch/vision runner: ${{ matrix.runner }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b4a74733967..6f03b0a59eb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: gpu-arch-type: cuda gpu-arch-version: "11.8" fail-fast: false - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main with: repository: pytorch/vision runner: ${{ matrix.runner }} @@ -104,7 +104,7 @@ jobs: ./.github/scripts/unittest.sh onnx: - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main with: repository: pytorch/vision test-infra-ref: main @@ -135,7 +135,7 @@ jobs: echo '::endgroup::' unittests-extended: - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main if: contains(github.event.pull_request.labels.*.name, 'run-extended') with: repository: pytorch/vision From d343a0fdea194693d731a740cba0ef1866b8280b Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Fri, 29 Nov 2024 15:03:36 +0000 Subject: [PATCH 04/10] only test images --- .github/scripts/unittest.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/unittest.sh b/.github/scripts/unittest.sh index da8a06928ea..3e2fe57f6c8 100755 --- a/.github/scripts/unittest.sh +++ b/.github/scripts/unittest.sh @@ -15,4 +15,5 @@ echo '::endgroup::' python test/smoke_test.py # We explicitly ignore the video tests until we resolve https://github.com/pytorch/vision/issues/8162 -pytest --ignore-glob="*test_video*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 +# TODO REMOVE test/test_image.py +pytest --ignore-glob="*test_video*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_image.py From a4bb341fc8dd3a1c35ccf502d8cfa9ea86ceb874 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 11:01:47 +0000 Subject: [PATCH 05/10] include types.h??? --- torchvision/csrc/io/image/cpu/decode_webp.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/torchvision/csrc/io/image/cpu/decode_webp.cpp b/torchvision/csrc/io/image/cpu/decode_webp.cpp index 0a9ff9ddbce..4c13c5c2b1a 100644 --- a/torchvision/csrc/io/image/cpu/decode_webp.cpp +++ b/torchvision/csrc/io/image/cpu/decode_webp.cpp @@ -3,6 +3,7 @@ #if WEBP_FOUND #include "webp/decode.h" +#include "webp/types.h" #endif // WEBP_FOUND namespace vision { From 7e4351ac01ee6d4eacd8735de8bedaa1f1429b0b Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 11:17:53 +0000 Subject: [PATCH 06/10] Try different way to install libwebp???? --- .github/workflows/build-wheels-linux.yml | 5 ++++- packaging/pre_build_script.sh | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-wheels-linux.yml b/.github/workflows/build-wheels-linux.yml index 818f32c102b..b836706336f 100644 --- a/.github/workflows/build-wheels-linux.yml +++ b/.github/workflows/build-wheels-linux.yml @@ -25,7 +25,10 @@ jobs: os: linux test-infra-repository: pytorch/test-infra test-infra-ref: main - with-xpu: enable + with-xpu: disable + with-rocm: disable + with-cuda: disable + build: needs: generate-matrix strategy: diff --git a/packaging/pre_build_script.sh b/packaging/pre_build_script.sh index 9b1f93b5abe..018a6b76384 100644 --- a/packaging/pre_build_script.sh +++ b/packaging/pre_build_script.sh @@ -32,7 +32,8 @@ else conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly fi - yum install -y libjpeg-turbo-devel libwebp-devel freetype gnutls + conda install libwebp -yq + yum install -y libjpeg-turbo-devel freetype gnutls pip install auditwheel fi From 4f074a329a03d874e12de51daa5d83d9a0940d45 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 11:25:14 +0000 Subject: [PATCH 07/10] aefaef --- packaging/pre_build_script.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packaging/pre_build_script.sh b/packaging/pre_build_script.sh index 018a6b76384..9224e38428f 100644 --- a/packaging/pre_build_script.sh +++ b/packaging/pre_build_script.sh @@ -32,8 +32,9 @@ else conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly fi + conda install libjpeg-turbo -yq conda install libwebp -yq - yum install -y libjpeg-turbo-devel freetype gnutls + yum install -y freetype gnutls pip install auditwheel fi From 1af8d4bdaa8d2b396880bebfba187f65d1daba53 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 11:46:35 +0000 Subject: [PATCH 08/10] AAAAAAAAAAAAAAAAH --- packaging/pre_build_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/pre_build_script.sh b/packaging/pre_build_script.sh index 9224e38428f..6bc3cdc703f 100644 --- a/packaging/pre_build_script.sh +++ b/packaging/pre_build_script.sh @@ -32,8 +32,8 @@ else conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch-nightly fi - conda install libjpeg-turbo -yq conda install libwebp -yq + conda install libjpeg-turbo -c pytorch yum install -y freetype gnutls pip install auditwheel fi From 77f2e23350623a88f5bafef88a779b7b25632818 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 12:33:48 +0000 Subject: [PATCH 09/10] aelfnjljnaef --- .github/scripts/unittest.sh | 3 +-- .github/workflows/build-wheels-linux.yml | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/scripts/unittest.sh b/.github/scripts/unittest.sh index 3e2fe57f6c8..da8a06928ea 100755 --- a/.github/scripts/unittest.sh +++ b/.github/scripts/unittest.sh @@ -15,5 +15,4 @@ echo '::endgroup::' python test/smoke_test.py # We explicitly ignore the video tests until we resolve https://github.com/pytorch/vision/issues/8162 -# TODO REMOVE test/test_image.py -pytest --ignore-glob="*test_video*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 test/test_image.py +pytest --ignore-glob="*test_video*" --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25 diff --git a/.github/workflows/build-wheels-linux.yml b/.github/workflows/build-wheels-linux.yml index b836706336f..818f32c102b 100644 --- a/.github/workflows/build-wheels-linux.yml +++ b/.github/workflows/build-wheels-linux.yml @@ -25,10 +25,7 @@ jobs: os: linux test-infra-repository: pytorch/test-infra test-infra-ref: main - with-xpu: disable - with-rocm: disable - with-cuda: disable - + with-xpu: enable build: needs: generate-matrix strategy: From 1e3822cf672be77d565fc43c6587f3ec901f167a Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 2 Dec 2024 12:56:13 +0000 Subject: [PATCH 10/10] Remove ROCM-specific stuff? --- setup.py | 7 +------ test/test_image.py | 4 ---- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/setup.py b/setup.py index a5234288458..c2be57e9775 100644 --- a/setup.py +++ b/setup.py @@ -320,12 +320,7 @@ def make_image_extension(): else: warnings.warn("Building torchvision without JPEG support") - if USE_WEBP and IS_ROCM: - warnings.warn( - "Cannot enable webp support on rocm. " - "See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558." - ) - elif USE_WEBP: + if USE_WEBP: webp_found, webp_include_dir, webp_library_dir = find_library(header="webp/decode.h") if webp_found: print("Building torchvision with WEBP support") diff --git a/test/test_image.py b/test/test_image.py index 6129abe8895..4146d54ac78 100644 --- a/test/test_image.py +++ b/test/test_image.py @@ -45,7 +45,6 @@ IS_MACOS = sys.platform == "darwin" PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split(".")) WEBP_TEST_IMAGES_DIR = os.environ.get("WEBP_TEST_IMAGES_DIR", "") -IS_ROCM = torch.version.hip is not None # See https://github.com/pytorch/vision/pull/8724#issuecomment-2503964558 ROCM_WEBP_MESSAGE = "ROCM not built with webp support." @@ -872,7 +871,6 @@ def test_decode_gif(tmpdir, name, scripted): (decode_jpeg, "Not a JPEG file"), (decode_gif, re.escape("DGifOpenFileName() failed - 103")), (decode_webp, "WebPGetFeatures failed."), - pytest.param(decode_webp, "WebPGetFeatures failed.", marks=pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE)), ] if DECODE_AVIF_ENABLED: decode_fun_and_match.append((_decode_avif, "BMFF parsing failed")) @@ -893,7 +891,6 @@ def test_decode_bad_encoded_data(decode_fun, match): decode_fun(encoded_data) -@pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE) @pytest.mark.parametrize("decode_fun", (decode_webp, decode_image)) @pytest.mark.parametrize("scripted", (False, True)) def test_decode_webp(decode_fun, scripted): @@ -910,7 +907,6 @@ def test_decode_webp(decode_fun, scripted): # including within the repo. The test images were downloaded manually from the # different pages of https://developers.google.com/speed/webp/gallery @pytest.mark.skipif(not WEBP_TEST_IMAGES_DIR, reason="WEBP_TEST_IMAGES_DIR is not set") -@pytest.mark.skipif(IS_ROCM, reason=ROCM_WEBP_MESSAGE) @pytest.mark.parametrize("decode_fun", (decode_webp, decode_image)) @pytest.mark.parametrize("scripted", (False, True)) @pytest.mark.parametrize(