Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTX] consider multi GPU when setting drop last #1520

Merged
merged 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion otx/algorithms/classification/tasks/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Optional

import numpy as np
import torch.distributed as dist
from mmcv.utils import ConfigDict

from otx.algorithms.classification.configs import ClassificationConfig
Expand Down Expand Up @@ -454,7 +455,11 @@ def patch_color_conversion(pipeline):
# In train dataset, when sample size is smaller than batch size
if subset == "train" and self._data_cfg:
train_data_cfg = Stage.get_data_cfg(self._data_cfg, "train")
if len(train_data_cfg.get("otx_dataset", [])) < self._recipe_cfg.data.get("samples_per_gpu", 2):
num_worlds = dist.get_world_size() if dist.is_initialized() else 1
if (
len(train_data_cfg.get("otx_dataset", []))
< self._recipe_cfg.data.get("samples_per_gpu", 2) * num_worlds
):
cfg.drop_last = False

cfg.domain = domain
Expand Down
7 changes: 6 additions & 1 deletion otx/mpa/cls/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import warnings

import mmcv
import torch.distributed as dist
from mmcls import __version__
from mmcls.core import DistOptimizerHook
from mmcls.datasets import build_dataloader, build_dataset
Expand Down Expand Up @@ -105,7 +106,11 @@ def run(self, model_cfg, model_ckpt, data_cfg, **kwargs):
drop_last = False
dataset_len = len(otx_dataset) if otx_dataset else 0
# if task == h-label & dataset size is bigger than batch size
if train_data_cfg.get("hierarchical_info", None) and dataset_len > cfg.data.get("samples_per_gpu", 2):
num_worlds = dist.get_world_size() if self.distributed else 1
if (
train_data_cfg.get("hierarchical_info", None)
and dataset_len > cfg.data.get("samples_per_gpu", 2) * num_worlds
):
drop_last = True
# updated to adapt list of dataset for the 'train'
data_loaders = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_otx_multi_gpu_train(self, template, tmp_dir_path):
"--learning_parameters.num_iters",
"2",
"--learning_parameters.batch_size",
"2",
"4",
],
}

Expand Down