From efe74209ff0479ef35404be46b121ded103bfb2c Mon Sep 17 00:00:00 2001 From: rahul-tuli Date: Wed, 31 May 2023 18:34:59 -0400 Subject: [PATCH 1/2] Add trainer to validator when calling w/o recipe --- src/sparseml/yolov8/trainers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sparseml/yolov8/trainers.py b/src/sparseml/yolov8/trainers.py index 18c0ef1888d..c9ac15de9a7 100644 --- a/src/sparseml/yolov8/trainers.py +++ b/src/sparseml/yolov8/trainers.py @@ -20,6 +20,7 @@ import warnings from copy import copy, deepcopy from datetime import datetime, timedelta +from functools import partial from pathlib import Path from typing import List, Optional @@ -487,6 +488,10 @@ def save_model(self): def final_eval(self): # skip final eval if we are using a recipe if self.manager is None and self.checkpoint_manager is None: + # need access to trainer in validator when recipe is not used + # but we can't touch original ultralytics code that makes this call + # without the trainer, so we create a partial with the trainer set + self.validator = partial(self.validator, trainer=self) return super().final_eval() def callback_teardown(self): From 155e1a3c452b9ddf7e48a3b042c3aff0e6a44b9a Mon Sep 17 00:00:00 2001 From: rahul-tuli Date: Thu, 1 Jun 2023 10:05:33 -0400 Subject: [PATCH 2/2] Re-work comment message to better describe what was done --- src/sparseml/yolov8/trainers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sparseml/yolov8/trainers.py b/src/sparseml/yolov8/trainers.py index c9ac15de9a7..5af0f97f22d 100644 --- a/src/sparseml/yolov8/trainers.py +++ b/src/sparseml/yolov8/trainers.py @@ -488,9 +488,11 @@ def save_model(self): def final_eval(self): # skip final eval if we are using a recipe if self.manager is None and self.checkpoint_manager is None: - # need access to trainer in validator when recipe is not used - # but we can't touch original ultralytics code that makes this call - # without the trainer, so we create a partial with the trainer set + # patch the validator, so it always has access to the + # trainer object, which is needed to circumvent original ultralytics + # call that ignores the trainer object + # https://github.com/ultralytics/ultralytics/blob/ + # 6c65934b555e64bf26edd699865754b5ff651d0c/ultralytics/yolo/engine/trainer.py#L551 self.validator = partial(self.validator, trainer=self) return super().final_eval()