From 3e50f0adecc76afdae585676fd672fa384f22ddb Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Fri, 30 Jan 2026 01:56:55 +0800 Subject: [PATCH] Fix training with `compile` (#23479) Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> --- tests/test_cuda.py | 2 +- ultralytics/models/yolo/detect/train.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cuda.py b/tests/test_cuda.py index 918b4d83..92afb456 100644 --- a/tests/test_cuda.py +++ b/tests/test_cuda.py @@ -120,7 +120,7 @@ def test_train(): device = tuple(DEVICES) if len(DEVICES) > 1 else DEVICES[0] # NVIDIA Jetson only has one GPU and therefore skipping checks if not IS_JETSON: - results = YOLO(MODEL).train(data="coco8.yaml", imgsz=64, epochs=1, device=device, batch=15) + results = YOLO(MODEL).train(data="coco8.yaml", imgsz=64, epochs=1, device=device, batch=15, compile=True) results = YOLO(MODEL).train(data="coco128.yaml", imgsz=64, epochs=1, device=device, batch=15, val=False) visible = eval(os.environ["CUDA_VISIBLE_DEVICES"]) assert visible == device, f"Passed GPUs '{device}', but used GPUs '{visible}'" diff --git a/ultralytics/models/yolo/detect/train.py b/ultralytics/models/yolo/detect/train.py index 56aaf760..8d8449c0 100644 --- a/ultralytics/models/yolo/detect/train.py +++ b/ultralytics/models/yolo/detect/train.py @@ -73,7 +73,7 @@ class DetectionTrainer(BaseTrainer): Returns: (Dataset): YOLO dataset object configured for the specified mode. """ - gs = max(int(unwrap_model(self.model).stride.max() if self.model else 0), 32) + gs = max(int(unwrap_model(self.model).stride.max()), 32) return build_yolo_dataset(self.args, img_path, batch, self.data, mode=mode, rect=mode == "val", stride=gs) def get_dataloader(self, dataset_path: str, batch_size: int = 16, rank: int = 0, mode: str = "train"):