Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/releases/2.0.0' into test/benc…
Browse files Browse the repository at this point in the history
…hmark-history
  • Loading branch information
goodsong81 committed Apr 12, 2024
2 parents 1222efc + 3dea944 commit ac640de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/otx/algo/strategies/xpu_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ def is_distributed(self) -> bool:
def setup_optimizers(self, trainer: pl.Trainer) -> None:
"""Sets up optimizers."""
super().setup_optimizers(trainer)
if len(self.optimizers) != 1: # type: ignore[has-type]
if len(self.optimizers) > 1: # type: ignore[has-type]
msg = "XPU strategy doesn't support multiple optimizers"
raise RuntimeError(msg)
if trainer.task != "SEMANTIC_SEGMENTATION":
model, optimizer = torch.xpu.optimize(trainer.model, optimizer=self.optimizers[0]) # type: ignore[has-type]
self.optimizers = [optimizer]
self.model = model
if len(self.optimizers) == 1: # type: ignore[has-type]
model, optimizer = torch.xpu.optimize(trainer.model, optimizer=self.optimizers[0]) # type: ignore[has-type]
self.optimizers = [optimizer]
self.model = model
else: # for inference
trainer.model.eval()
self.model = torch.xpu.optimize(trainer.model)


StrategyRegistry.register(
Expand Down
2 changes: 1 addition & 1 deletion src/otx/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def _build_trainer(self, **kwargs) -> None:
if self._device.accelerator == DeviceType.xpu:
self._cache.update(strategy="xpu_single")
# add plugin for Automatic Mixed Precision on XPU
if self._cache.args["precision"] == 16:
if self._cache.args.get("precision", 32) == 16:
self._cache.update(plugins=[MixedPrecisionXPUPlugin()])
self._cache.args["precision"] = None

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def fxt_target_dataset_per_task(fxt_ci_data_root) -> dict:
"zero_shot_visual_prompting": Path(
fxt_ci_data_root / "v2/zero_shot_visual_prompting/coco_car_person_medium",
),
"anomaly_classification": Path(fxt_ci_data_root / "v2/anomaly/mvtec/bottle_small/1"),
"anomaly_classification": Path(fxt_ci_data_root / "v2/anomaly/mvtec/hazelnut_large"),
"anomaly_detection": Path(fxt_ci_data_root / "v2/anomaly/mvtec/hazelnut_large"),
"anomaly_segmentation": Path(fxt_ci_data_root / "v2/anomaly/mvtec/hazelnut_large"),
}
Expand Down

0 comments on commit ac640de

Please sign in to comment.