From a9f13b189b9d2edb7ea54b55d88b701ead34af6a Mon Sep 17 00:00:00 2001 From: elisim7 Date: Wed, 17 Jul 2024 18:18:35 +0300 Subject: [PATCH 01/10] rename `emb` to `embeddings` --- src/pytorch_metric_learning/utils/distributed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytorch_metric_learning/utils/distributed.py b/src/pytorch_metric_learning/utils/distributed.py index 93946eed..d301b934 100644 --- a/src/pytorch_metric_learning/utils/distributed.py +++ b/src/pytorch_metric_learning/utils/distributed.py @@ -93,7 +93,7 @@ def __init__(self, loss, efficient=False): def forward( self, - emb, + embeddings, labels=None, indices_tuple=None, ref_emb=None, @@ -101,7 +101,7 @@ def forward( enqueue_mask=None, ): world_size = torch.distributed.get_world_size() - common_args = [emb, labels, indices_tuple, ref_emb, ref_labels, world_size] + common_args = [embeddings, labels, indices_tuple, ref_emb, ref_labels, world_size] if isinstance(self.loss, CrossBatchMemory): return self.forward_cross_batch(*common_args, enqueue_mask) return self.forward_regular_loss(*common_args) From 946eeb8fd336576ba7485257d9f6bb3b8916ff71 Mon Sep 17 00:00:00 2001 From: elisim7 Date: Wed, 17 Jul 2024 18:22:23 +0300 Subject: [PATCH 02/10] warn in non-distributed setting --- src/pytorch_metric_learning/utils/distributed.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pytorch_metric_learning/utils/distributed.py b/src/pytorch_metric_learning/utils/distributed.py index d301b934..ab205f41 100644 --- a/src/pytorch_metric_learning/utils/distributed.py +++ b/src/pytorch_metric_learning/utils/distributed.py @@ -1,3 +1,5 @@ +import warnings + import torch from ..losses import BaseMetricLossFunction, CrossBatchMemory @@ -100,6 +102,12 @@ def forward( ref_labels=None, enqueue_mask=None, ): + if not is_distributed(): + warnings.warn( + "DistributedLossWrapper is being used in a non-distributed setting. Returning the loss as is." + ) + return self.loss(embeddings, labels, indices_tuple, ref_emb, ref_labels) + world_size = torch.distributed.get_world_size() common_args = [embeddings, labels, indices_tuple, ref_emb, ref_labels, world_size] if isinstance(self.loss, CrossBatchMemory): From 7ec404fef590d8b4441ad6beba8c5048c1be4508 Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Thu, 18 Jul 2024 16:22:34 -0400 Subject: [PATCH 03/10] Remove numpy from setup.py --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 66326d46..f63dee62 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,6 @@ ], python_requires=">=3.0", install_requires=[ - "numpy", "scikit-learn", "tqdm", "torch >= 1.6.0", From df3e1f91ed34c4f30f7fbff544b86b373cc66ff9 Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Thu, 18 Jul 2024 17:18:40 -0400 Subject: [PATCH 04/10] Update base_test_workflow.yml --- .github/workflows/base_test_workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/base_test_workflow.yml b/.github/workflows/base_test_workflow.yml index 52fd4429..f81bf485 100644 --- a/.github/workflows/base_test_workflow.yml +++ b/.github/workflows/base_test_workflow.yml @@ -18,8 +18,8 @@ jobs: pytorch-version: 1.6 torchvision-version: 0.7 - python-version: 3.9 - pytorch-version: 2.1 - torchvision-version: 0.16 + pytorch-version: 2.3 + torchvision-version: 0.18 steps: - uses: actions/checkout@v2 From 3cc2f6acc733c91ed4067beaab99d199c3328bef Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Thu, 18 Jul 2024 17:22:14 -0400 Subject: [PATCH 05/10] Update setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index f63dee62..2e8a8dee 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ ], python_requires=">=3.0", install_requires=[ + "numpy < 2.0", "scikit-learn", "tqdm", "torch >= 1.6.0", From e3a31a72938b5dec619e47964756c14f672dbb4a Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Tue, 23 Jul 2024 15:27:22 +0200 Subject: [PATCH 06/10] Update base_test_workflow.yml --- .github/workflows/base_test_workflow.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/base_test_workflow.yml b/.github/workflows/base_test_workflow.yml index f81bf485..c8774f40 100644 --- a/.github/workflows/base_test_workflow.yml +++ b/.github/workflows/base_test_workflow.yml @@ -31,6 +31,7 @@ jobs: run: | pip install .[with-hooks-cpu] pip install torch==${{ matrix.pytorch-version }} torchvision==${{ matrix.torchvision-version }} --force-reinstall + pip install numpy<2.0 --force-reinstall pip install --upgrade protobuf==3.20.1 pip install six pip install packaging From d6c55facca777176b674ed2725bc13e332161468 Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Tue, 23 Jul 2024 15:36:56 +0200 Subject: [PATCH 07/10] Update base_test_workflow.yml --- .github/workflows/base_test_workflow.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/base_test_workflow.yml b/.github/workflows/base_test_workflow.yml index c8774f40..b3ac9c21 100644 --- a/.github/workflows/base_test_workflow.yml +++ b/.github/workflows/base_test_workflow.yml @@ -30,8 +30,7 @@ jobs: - name: Install dependencies run: | pip install .[with-hooks-cpu] - pip install torch==${{ matrix.pytorch-version }} torchvision==${{ matrix.torchvision-version }} --force-reinstall - pip install numpy<2.0 --force-reinstall + pip install numpy<2.0 torch==${{ matrix.pytorch-version }} torchvision==${{ matrix.torchvision-version }} --force-reinstall pip install --upgrade protobuf==3.20.1 pip install six pip install packaging From 9ed1d0d67e46e325245fefba5c889a989775254c Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Tue, 23 Jul 2024 15:40:45 +0200 Subject: [PATCH 08/10] Update base_test_workflow.yml --- .github/workflows/base_test_workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/base_test_workflow.yml b/.github/workflows/base_test_workflow.yml index b3ac9c21..02367536 100644 --- a/.github/workflows/base_test_workflow.yml +++ b/.github/workflows/base_test_workflow.yml @@ -30,7 +30,7 @@ jobs: - name: Install dependencies run: | pip install .[with-hooks-cpu] - pip install numpy<2.0 torch==${{ matrix.pytorch-version }} torchvision==${{ matrix.torchvision-version }} --force-reinstall + pip install "numpy<2.0" torch==${{ matrix.pytorch-version }} torchvision==${{ matrix.torchvision-version }} --force-reinstall pip install --upgrade protobuf==3.20.1 pip install six pip install packaging From ed2c1e295d91977cebdded9f625bb8afc3ded786 Mon Sep 17 00:00:00 2001 From: Kevin Musgrave Date: Tue, 23 Jul 2024 15:56:19 +0200 Subject: [PATCH 09/10] Update __init__.py --- src/pytorch_metric_learning/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytorch_metric_learning/__init__.py b/src/pytorch_metric_learning/__init__.py index 50062f87..e5e59e38 100644 --- a/src/pytorch_metric_learning/__init__.py +++ b/src/pytorch_metric_learning/__init__.py @@ -1 +1 @@ -__version__ = "2.5.0" +__version__ = "2.6.0" From ef1bd0627633ab2fb3c8a2a1e58938de866f5b2c Mon Sep 17 00:00:00 2001 From: KevinMusgrave Date: Wed, 24 Jul 2024 11:43:27 +0000 Subject: [PATCH 10/10] formatted code --- src/pytorch_metric_learning/utils/distributed.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pytorch_metric_learning/utils/distributed.py b/src/pytorch_metric_learning/utils/distributed.py index ab205f41..40dddf90 100644 --- a/src/pytorch_metric_learning/utils/distributed.py +++ b/src/pytorch_metric_learning/utils/distributed.py @@ -109,7 +109,14 @@ def forward( return self.loss(embeddings, labels, indices_tuple, ref_emb, ref_labels) world_size = torch.distributed.get_world_size() - common_args = [embeddings, labels, indices_tuple, ref_emb, ref_labels, world_size] + common_args = [ + embeddings, + labels, + indices_tuple, + ref_emb, + ref_labels, + world_size, + ] if isinstance(self.loss, CrossBatchMemory): return self.forward_cross_batch(*common_args, enqueue_mask) return self.forward_regular_loss(*common_args)