We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`reduction` for `ContrastiveLoss`
**Describe the bug**
the error messages and docstring should be consistent
https://github.com/Project-MONAI/MONAI/blob/a7bc4a3cbaeaa3c505a25ca2ddf6922bda8ea7dc/monai/losses/contrastive.py#L89-L91

https://github.com/Project-MONAI/MONAI/blob/a7bc4a3cbaeaa3c505a25ca2ddf6922bda8ea7dc/monai/losses/contrastive.py#L58

**Expected behavior**
implementing the option `reduction="none"`?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `monai/losses/contrastive.py`
Content:
```
1 # Copyright 2020 - 2021 MONAI Consortium
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #     http://www.apache.org/licenses/LICENSE-2.0
6 # Unless required by applicable law or agreed to in writing, software
7 # distributed under the License is distributed on an "AS IS" BASIS,
8 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 # See the License for the specific language governing permissions and
10 # limitations under the License.
11 
12 from typing import Union
13 
14 import torch
15 from torch.nn import functional as F
16 from torch.nn.modules.loss import _Loss
17 
18 from monai.utils import LossReduction
19 
20 
21 class ContrastiveLoss(_Loss):
22 
23     """
24     Compute the Contrastive loss defined in:
25 
26         Chen, Ting, et al. "A simple framework for contrastive learning of visual representations." International
27         conference on machine learning. PMLR, 2020. (http://proceedings.mlr.press/v119/chen20j.html)
28 
29     Adapted from:
30         https://github.com/Sara-Ahmed/SiT/blob/1aacd6adcd39b71efc903d16b4e9095b97dda76f/losses.py#L5
31 
32     """
33 
34     def __init__(
35         self, temperature: float = 0.5, batch_size: int = 1, reduction: Union[LossReduction, str] = LossReduction.SUM
36     ) -> None:
37         """
38         Args:
39             temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.
40 
41         Raises:
42             AssertionError: When an input of dimension length > 2 is passed
43             AssertionError: When input and target are of different shapes
44 
45         """
46         super().__init__(reduction=LossReduction(reduction).value)
47 
48         self.batch_size = batch_size
49         self.temperature = temperature
50 
51     def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
52         """
53         Args:
54             input: the shape should be B[F].
55             target: the shape should be B[F].
56 
57         Raises:
58             ValueError: When ``self.reduction`` is not one of ["sum", "none"].
59         """
60         if len(target.shape) > 2 or len(input.shape) > 2:
61             raise AssertionError(
62                 f"Either target or input has dimensions greater than 2 where target "
63                 f"shape is ({target.shape}) and input shape is ({input.shape})"
64             )
65 
66         if target.shape != input.shape:
67             raise AssertionError(f"ground truth has differing shape ({target.shape}) from input ({input.shape})")
68 
69         temperature_tensor = torch.tensor(self.temperature).to(input.device)
70 
71         norm_i = F.normalize(input, dim=1)
72         norm_j = F.normalize(target, dim=1)
73 
74         negatives_mask = ~torch.eye(self.batch_size * 2, self.batch_size * 2, dtype=torch.bool)
75         negatives_mask = torch.tensor(negatives_mask, dtype=torch.float)
76         negatives_mask = torch.clone(torch.as_tensor(negatives_mask)).to(input.device)
77 
78         repr = torch.cat([norm_i, norm_j], dim=0)
79         sim_matrix = F.cosine_similarity(repr.unsqueeze(1), repr.unsqueeze(0), dim=2)
80         sim_ij = torch.diag(sim_matrix, self.batch_size)
81         sim_ji = torch.diag(sim_matrix, -self.batch_size)
82 
83         positives = torch.cat([sim_ij, sim_ji], dim=0)
84         nominator = torch.exp(positives / temperature_tensor)
85         denominator = negatives_mask * torch.exp(sim_matrix / temperature_tensor)
86 
87         loss_partial = -torch.log(nominator / torch.sum(denominator, dim=1))
88 
89         if self.reduction == LossReduction.SUM.value:
90             return torch.sum(loss_partial) / (2 * self.batch_size)
91         raise ValueError(f"Unsupported reduction: {self.reduction}, " f'available options are ["mean", "sum", "none"].')
92
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/monai/losses/contrastive.py b/monai/losses/contrastive.py
--- a/monai/losses/contrastive.py
+++ b/monai/losses/contrastive.py
@@ -9,13 +9,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from typing import Union
-
 import torch
 from torch.nn import functional as F
 from torch.nn.modules.loss import _Loss
 
-from monai.utils import LossReduction
+from monai.utils import deprecated_arg
 
 
 class ContrastiveLoss(_Loss):
@@ -31,19 +29,23 @@
 
     """
 
-    def __init__(
-        self, temperature: float = 0.5, batch_size: int = 1, reduction: Union[LossReduction, str] = LossReduction.SUM
-    ) -> None:
+    @deprecated_arg(name="reduction", since="0.8", msg_suffix="`reduction` is no longer supported.")
+    def __init__(self, temperature: float = 0.5, batch_size: int = 1, reduction="sum") -> None:
         """
         Args:
             temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.
+            batch_size: The number of samples.
 
         Raises:
-            AssertionError: When an input of dimension length > 2 is passed
-            AssertionError: When input and target are of different shapes
+            ValueError: When an input of dimension length > 2 is passed
+            ValueError: When input and target are of different shapes
+
+        .. deprecated:: 0.8.0
+
+            `reduction` is no longer supported.
 
         """
-        super().__init__(reduction=LossReduction(reduction).value)
+        super().__init__()
 
         self.batch_size = batch_size
         self.temperature = temperature
@@ -53,18 +55,15 @@
         Args:
             input: the shape should be B[F].
             target: the shape should be B[F].
-
-        Raises:
-            ValueError: When ``self.reduction`` is not one of ["sum", "none"].
         """
         if len(target.shape) > 2 or len(input.shape) > 2:
-            raise AssertionError(
+            raise ValueError(
                 f"Either target or input has dimensions greater than 2 where target "
                 f"shape is ({target.shape}) and input shape is ({input.shape})"
             )
 
         if target.shape != input.shape:
-            raise AssertionError(f"ground truth has differing shape ({target.shape}) from input ({input.shape})")
+            raise ValueError(f"ground truth has differing shape ({target.shape}) from input ({input.shape})")
 
         temperature_tensor = torch.tensor(self.temperature).to(input.device)
 
@@ -86,6 +85,4 @@
 
         loss_partial = -torch.log(nominator / torch.sum(denominator, dim=1))
 
-        if self.reduction == LossReduction.SUM.value:
-            return torch.sum(loss_partial) / (2 * self.batch_size)
-        raise ValueError(f"Unsupported reduction: {self.reduction}, " f'available options are ["mean", "sum", "none"].')
+        return torch.sum(loss_partial) / (2 * self.batch_size)

{"golden_diff": "diff --git a/monai/losses/contrastive.py b/monai/losses/contrastive.py\n--- a/monai/losses/contrastive.py\n+++ b/monai/losses/contrastive.py\n@@ -9,13 +9,11 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \n-from typing import Union\n-\n import torch\n from torch.nn import functional as F\n from torch.nn.modules.loss import _Loss\n \n-from monai.utils import LossReduction\n+from monai.utils import deprecated_arg\n \n \n class ContrastiveLoss(_Loss):\n@@ -31,19 +29,23 @@\n \n     \"\"\"\n \n-    def __init__(\n-        self, temperature: float = 0.5, batch_size: int = 1, reduction: Union[LossReduction, str] = LossReduction.SUM\n-    ) -> None:\n+    @deprecated_arg(name=\"reduction\", since=\"0.8\", msg_suffix=\"`reduction` is no longer supported.\")\n+    def __init__(self, temperature: float = 0.5, batch_size: int = 1, reduction=\"sum\") -> None:\n         \"\"\"\n         Args:\n             temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.\n+            batch_size: The number of samples.\n \n         Raises:\n-            AssertionError: When an input of dimension length > 2 is passed\n-            AssertionError: When input and target are of different shapes\n+            ValueError: When an input of dimension length > 2 is passed\n+            ValueError: When input and target are of different shapes\n+\n+        .. deprecated:: 0.8.0\n+\n+            `reduction` is no longer supported.\n \n         \"\"\"\n-        super().__init__(reduction=LossReduction(reduction).value)\n+        super().__init__()\n \n         self.batch_size = batch_size\n         self.temperature = temperature\n@@ -53,18 +55,15 @@\n         Args:\n             input: the shape should be B[F].\n             target: the shape should be B[F].\n-\n-        Raises:\n-            ValueError: When ``self.reduction`` is not one of [\"sum\", \"none\"].\n         \"\"\"\n         if len(target.shape) > 2 or len(input.shape) > 2:\n-            raise AssertionError(\n+            raise ValueError(\n                 f\"Either target or input has dimensions greater than 2 where target \"\n                 f\"shape is ({target.shape}) and input shape is ({input.shape})\"\n             )\n \n         if target.shape != input.shape:\n-            raise AssertionError(f\"ground truth has differing shape ({target.shape}) from input ({input.shape})\")\n+            raise ValueError(f\"ground truth has differing shape ({target.shape}) from input ({input.shape})\")\n \n         temperature_tensor = torch.tensor(self.temperature).to(input.device)\n \n@@ -86,6 +85,4 @@\n \n         loss_partial = -torch.log(nominator / torch.sum(denominator, dim=1))\n \n-        if self.reduction == LossReduction.SUM.value:\n-            return torch.sum(loss_partial) / (2 * self.batch_size)\n-        raise ValueError(f\"Unsupported reduction: {self.reduction}, \" f'available options are [\"mean\", \"sum\", \"none\"].')\n+        return torch.sum(loss_partial) / (2 * self.batch_size)\n", "issue": "`reduction` for `ContrastiveLoss`\n**Describe the bug**\r\nthe error messages and docstring should be consistent\r\nhttps://github.com/Project-MONAI/MONAI/blob/a7bc4a3cbaeaa3c505a25ca2ddf6922bda8ea7dc/monai/losses/contrastive.py#L89-L91\r\n\r\nhttps://github.com/Project-MONAI/MONAI/blob/a7bc4a3cbaeaa3c505a25ca2ddf6922bda8ea7dc/monai/losses/contrastive.py#L58\r\n\r\n**Expected behavior**\r\nimplementing the option `reduction=\"none\"`?\r\n\n", "before_files": [{"content": "# Copyright 2020 - 2021 MONAI Consortium\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#     http://www.apache.org/licenses/LICENSE-2.0\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import Union\n\nimport torch\nfrom torch.nn import functional as F\nfrom torch.nn.modules.loss import _Loss\n\nfrom monai.utils import LossReduction\n\n\nclass ContrastiveLoss(_Loss):\n\n    \"\"\"\n    Compute the Contrastive loss defined in:\n\n        Chen, Ting, et al. \"A simple framework for contrastive learning of visual representations.\" International\n        conference on machine learning. PMLR, 2020. (http://proceedings.mlr.press/v119/chen20j.html)\n\n    Adapted from:\n        https://github.com/Sara-Ahmed/SiT/blob/1aacd6adcd39b71efc903d16b4e9095b97dda76f/losses.py#L5\n\n    \"\"\"\n\n    def __init__(\n        self, temperature: float = 0.5, batch_size: int = 1, reduction: Union[LossReduction, str] = LossReduction.SUM\n    ) -> None:\n        \"\"\"\n        Args:\n            temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.\n\n        Raises:\n            AssertionError: When an input of dimension length > 2 is passed\n            AssertionError: When input and target are of different shapes\n\n        \"\"\"\n        super().__init__(reduction=LossReduction(reduction).value)\n\n        self.batch_size = batch_size\n        self.temperature = temperature\n\n    def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:\n        \"\"\"\n        Args:\n            input: the shape should be B[F].\n            target: the shape should be B[F].\n\n        Raises:\n            ValueError: When ``self.reduction`` is not one of [\"sum\", \"none\"].\n        \"\"\"\n        if len(target.shape) > 2 or len(input.shape) > 2:\n            raise AssertionError(\n                f\"Either target or input has dimensions greater than 2 where target \"\n                f\"shape is ({target.shape}) and input shape is ({input.shape})\"\n            )\n\n        if target.shape != input.shape:\n            raise AssertionError(f\"ground truth has differing shape ({target.shape}) from input ({input.shape})\")\n\n        temperature_tensor = torch.tensor(self.temperature).to(input.device)\n\n        norm_i = F.normalize(input, dim=1)\n        norm_j = F.normalize(target, dim=1)\n\n        negatives_mask = ~torch.eye(self.batch_size * 2, self.batch_size * 2, dtype=torch.bool)\n        negatives_mask = torch.tensor(negatives_mask, dtype=torch.float)\n        negatives_mask = torch.clone(torch.as_tensor(negatives_mask)).to(input.device)\n\n        repr = torch.cat([norm_i, norm_j], dim=0)\n        sim_matrix = F.cosine_similarity(repr.unsqueeze(1), repr.unsqueeze(0), dim=2)\n        sim_ij = torch.diag(sim_matrix, self.batch_size)\n        sim_ji = torch.diag(sim_matrix, -self.batch_size)\n\n        positives = torch.cat([sim_ij, sim_ji], dim=0)\n        nominator = torch.exp(positives / temperature_tensor)\n        denominator = negatives_mask * torch.exp(sim_matrix / temperature_tensor)\n\n        loss_partial = -torch.log(nominator / torch.sum(denominator, dim=1))\n\n        if self.reduction == LossReduction.SUM.value:\n            return torch.sum(loss_partial) / (2 * self.batch_size)\n        raise ValueError(f\"Unsupported reduction: {self.reduction}, \" f'available options are [\"mean\", \"sum\", \"none\"].')\n", "path": "monai/losses/contrastive.py"}], "after_files": [{"content": "# Copyright 2020 - 2021 MONAI Consortium\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#     http://www.apache.org/licenses/LICENSE-2.0\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport torch\nfrom torch.nn import functional as F\nfrom torch.nn.modules.loss import _Loss\n\nfrom monai.utils import deprecated_arg\n\n\nclass ContrastiveLoss(_Loss):\n\n    \"\"\"\n    Compute the Contrastive loss defined in:\n\n        Chen, Ting, et al. \"A simple framework for contrastive learning of visual representations.\" International\n        conference on machine learning. PMLR, 2020. (http://proceedings.mlr.press/v119/chen20j.html)\n\n    Adapted from:\n        https://github.com/Sara-Ahmed/SiT/blob/1aacd6adcd39b71efc903d16b4e9095b97dda76f/losses.py#L5\n\n    \"\"\"\n\n    @deprecated_arg(name=\"reduction\", since=\"0.8\", msg_suffix=\"`reduction` is no longer supported.\")\n    def __init__(self, temperature: float = 0.5, batch_size: int = 1, reduction=\"sum\") -> None:\n        \"\"\"\n        Args:\n            temperature: Can be scaled between 0 and 1 for learning from negative samples, ideally set to 0.5.\n            batch_size: The number of samples.\n\n        Raises:\n            ValueError: When an input of dimension length > 2 is passed\n            ValueError: When input and target are of different shapes\n\n        .. deprecated:: 0.8.0\n\n            `reduction` is no longer supported.\n\n        \"\"\"\n        super().__init__()\n\n        self.batch_size = batch_size\n        self.temperature = temperature\n\n    def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:\n        \"\"\"\n        Args:\n            input: the shape should be B[F].\n            target: the shape should be B[F].\n        \"\"\"\n        if len(target.shape) > 2 or len(input.shape) > 2:\n            raise ValueError(\n                f\"Either target or input has dimensions greater than 2 where target \"\n                f\"shape is ({target.shape}) and input shape is ({input.shape})\"\n            )\n\n        if target.shape != input.shape:\n            raise ValueError(f\"ground truth has differing shape ({target.shape}) from input ({input.shape})\")\n\n        temperature_tensor = torch.tensor(self.temperature).to(input.device)\n\n        norm_i = F.normalize(input, dim=1)\n        norm_j = F.normalize(target, dim=1)\n\n        negatives_mask = ~torch.eye(self.batch_size * 2, self.batch_size * 2, dtype=torch.bool)\n        negatives_mask = torch.tensor(negatives_mask, dtype=torch.float)\n        negatives_mask = torch.clone(torch.as_tensor(negatives_mask)).to(input.device)\n\n        repr = torch.cat([norm_i, norm_j], dim=0)\n        sim_matrix = F.cosine_similarity(repr.unsqueeze(1), repr.unsqueeze(0), dim=2)\n        sim_ij = torch.diag(sim_matrix, self.batch_size)\n        sim_ji = torch.diag(sim_matrix, -self.batch_size)\n\n        positives = torch.cat([sim_ij, sim_ji], dim=0)\n        nominator = torch.exp(positives / temperature_tensor)\n        denominator = negatives_mask * torch.exp(sim_matrix / temperature_tensor)\n\n        loss_partial = -torch.log(nominator / torch.sum(denominator, dim=1))\n\n        return torch.sum(loss_partial) / (2 * self.batch_size)\n", "path": "monai/losses/contrastive.py"}]}