Repository: Lightning-AI/torchmetrics

Issue:
JIT RuntimeError for property `is_differentiable`
## 🐛 Bug

```
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/opt/conda/lib/python3.8/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/__w/2/s/tests/helpers/testers.py", line 131, in _class_test
    torch.jit.script(metric)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_script.py", line 897, in script
    return torch.jit._recursive.create_script_module(
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py", line 352, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py", line 410, in create_script_module_impl
    create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py", line 304, in create_methods_and_properties_from_stubs
    concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
RuntimeError: Can't redefine method: __is_differentiable_getter on class: __torch__.torchmetrics.retrieval.retrieval_precision.___torch_mangle_12.RetrievalPrecision

```

### To Reproduce

see tests on master for PT>=1.7
https://github.com/PyTorchLightning/metrics/actions/runs/904368314

### Additional context

<!-- Add any other context about the problem here. -->



Discussion:

Resolving patch:
diff --git a/torchmetrics/metric.py b/torchmetrics/metric.py
--- a/torchmetrics/metric.py
+++ b/torchmetrics/metric.py
@@ -137,7 +137,7 @@ def add_state(
             ValueError:
                 If ``dist_reduce_fx`` is not callable or one of ``"mean"``, ``"sum"``, ``"cat"``, ``None``.
         """
-        if (not isinstance(default, (Tensor, list)) or (isinstance(default, list) and default)):
+        if not isinstance(default, (Tensor, list)) or (isinstance(default, list) and default):
             raise ValueError("state variable must be a tensor or any empty list (where you can append tensors)")
 
         if dist_reduce_fx == "sum":
@@ -505,7 +505,7 @@ def __getitem__(self, idx):
         return CompositionalMetric(lambda x: x[idx], self, None)
 
     @property
-    def is_differentiable(self) -> bool:
+    def is_differentiable(self):
         # There is a bug in PyTorch that leads to properties being executed during scripting
         # To make the metric scriptable, we add property to ignore list and switch to return None here
         return None


Test patch:
diff --git a/tests/classification/test_binned_precision_recall.py b/tests/classification/test_binned_precision_recall.py
--- a/tests/classification/test_binned_precision_recall.py
+++ b/tests/classification/test_binned_precision_recall.py
@@ -109,7 +109,6 @@ def test_binned_pr(self, preds, target, sk_metric, num_classes, ddp, dist_sync_o
     ],
 )
 class TestBinnedAveragePrecision(MetricTester):
-    atol = 0.02
 
     @pytest.mark.parametrize("ddp", [True, False])
     @pytest.mark.parametrize("dist_sync_on_step", [True, False])