Skip to content

Commit 11fe3d9

Browse files
committed
Enable training on XPU using SingleXPUStrategy
Setting the SingleXPUStrategy fixes the error message, ``` Failed to train pending training job: Device should be xpu, got cpu instead ``` After this another error would show up, ``` Cannot re-initialize XPU in forked subproces. To use XPU with multiprocessing you must use the `spawn` method ``` This requires us to set the start method of our `main.py` file. Signed-off-by: Mark Redeman <[email protected]>
1 parent c0af0a0 commit 11fe3d9

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

application/backend/src/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4+
import multiprocessing as mp
5+
6+
if mp.get_start_method(allow_none=True) != "spawn":
7+
mp.set_start_method("spawn", force=True)
8+
49
import os
510

611
import uvicorn

application/backend/src/services/training_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from anomalib.data.utils import ValSplitMode
1010
from anomalib.deploy import ExportType
1111
from anomalib.engine import Engine
12+
from anomalib.engine.strategy.xpu_single import SingleXPUStrategy
1213
from anomalib.loggers import AnomalibTensorBoardLogger
1314
from anomalib.models import get_model
1415
from loguru import logger
@@ -214,6 +215,7 @@ def _train_model(
214215
max_epochs=max_epochs,
215216
callbacks=[GetiInspectProgressCallback(synchronization_parameters)],
216217
accelerator=training_device,
218+
**({"strategy": SingleXPUStrategy()} if training_device == "xpu" else {}),
217219
)
218220

219221
# Execute training and export

0 commit comments

Comments
 (0)