Skip to content

Commit

Permalink
[Cherry Pick]Add trainer to validator when calling w/o recipe (#1600)
Browse files Browse the repository at this point in the history
* Add trainer to validator when calling w/o recipe

* Re-work comment message to better describe what was done

---------

Co-authored-by: Konstantin Gulin <66528950+KSGulin@users.noreply.github.com>
Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 1, 2023
1 parent ca1ead8 commit 8422758
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sparseml/yolov8/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -487,6 +488,12 @@ 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:
# 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()

def callback_teardown(self):
Expand Down

0 comments on commit 8422758

Please sign in to comment.