From faa10a420eb7b16c5256b763214ac4ada4733458 Mon Sep 17 00:00:00 2001 From: Sadra Barikbin Date: Wed, 4 Sep 2024 13:15:36 +0330 Subject: [PATCH] Resolve MPS's lack of cummax --- .../vision/object_detection_average_precision_recall.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ignite/metrics/vision/object_detection_average_precision_recall.py b/ignite/metrics/vision/object_detection_average_precision_recall.py index a56a18c164f..09a5046faa0 100644 --- a/ignite/metrics/vision/object_detection_average_precision_recall.py +++ b/ignite/metrics/vision/object_detection_average_precision_recall.py @@ -1,3 +1,4 @@ +import os from typing import Callable, cast, Dict, List, Optional, Sequence, Tuple, Union import torch @@ -234,7 +235,9 @@ def _compute_average_precision(self, recall: torch.Tensor, precision: torch.Tens Returns: average_precision: (n-1)-dimensional tensor containing the average precision for mean dimensions. """ + os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = True precision_integrand = precision.flip(-1).cummax(dim=-1).values.flip(-1) + os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = False rec_thresholds = cast(torch.Tensor, self.rec_thresholds).repeat((*recall.shape[:-1], 1)) rec_thresh_indices = ( torch.searchsorted(recall, rec_thresholds)