From 8d17af7e32ac3b536bdcced7b7705ce688ae6d94 Mon Sep 17 00:00:00 2001 From: IMhx233 <76209259+IMhx233@users.noreply.github.com> Date: Tue, 14 May 2024 01:28:57 +0800 Subject: [PATCH] `ultralytics 8.2.15` get_latest_opset() compat for `torch<1.13.0` (#12652) Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- ultralytics/__init__.py | 2 +- ultralytics/utils/torch_utils.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index 0bb5c41e..5e1364da 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.14" +__version__ = "8.2.15" from ultralytics.data.explorer.explorer import Explorer from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld diff --git a/ultralytics/utils/torch_utils.py b/ultralytics/utils/torch_utils.py index f859cd5f..919fee07 100644 --- a/ultralytics/utils/torch_utils.py +++ b/ultralytics/utils/torch_utils.py @@ -399,8 +399,13 @@ def copy_attr(a, b, include=(), exclude=()): def get_latest_opset(): - """Return second-most (for maturity) recently supported ONNX opset by this version of torch.""" - return max(int(k[14:]) for k in vars(torch.onnx) if "symbolic_opset" in k) - 1 # opset + """Return the second-most recent ONNX opset version supported by this version of PyTorch, adjusted for maturity.""" + if TORCH_1_13: + # If the PyTorch>=1.13, dynamically compute the latest opset minus one using 'symbolic_opset' + return max(int(k[14:]) for k in vars(torch.onnx) if "symbolic_opset" in k) - 1 + # Otherwise for PyTorch<=1.12 return the corresponding predefined opset + version = torch.onnx.producer_version.rsplit(".", 1)[0] # i.e. '2.3' + return {"1.12": 15, "1.11": 14, "1.10": 13, "1.9": 12, "1.8": 12}.get(version, 12) def intersect_dicts(da, db, exclude=()):