Skip to content

Commit 5342680

Browse files
heyufan1995pre-commit-ci[bot]wylimonai-bot
authored
Fix infer files < world size bug (#6530)
Fixes # . ### Description Fix the ensembler bug where infer_files are empty or smaller than GPU number ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: heyufan1995 <heyufan1995@gmail.com> Signed-off-by: monai-bot <monai.miccai2019@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li <831580+wyli@users.noreply.github.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
1 parent ab28132 commit 5342680

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

monai/apps/auto3dseg/ensemble_builder.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def set_infer_files(self, dataroot: str, data_list_or_path: str | list, data_key
9595
datalist = ConfigParser.load_config_file(data_list_or_path)
9696
if data_key in datalist:
9797
self.infer_files, _ = datafold_read(datalist=datalist, basedir=dataroot, fold=-1, key=data_key)
98-
elif hasattr(self, "rank") and self.rank == 0:
98+
elif not hasattr(self, "rank") or self.rank == 0:
9999
logger.info(f"Datalist file has no testing key - {data_key}. No data for inference is specified")
100100

101101
else:
@@ -582,9 +582,20 @@ def ensemble(self):
582582
builder.set_ensemble_method(self.ensemble_method)
583583
self.ensembler = builder.get_ensemble()
584584
infer_files = self.ensembler.infer_files
585-
infer_files = partition_dataset(
586-
data=infer_files, shuffle=False, num_partitions=self.world_size, even_divisible=True
587-
)[self.rank]
585+
if len(infer_files) < self.world_size:
586+
if len(infer_files) == 0:
587+
logger.info("No testing files for inference is provided. Ensembler ending.")
588+
return
589+
infer_files = (
590+
partition_dataset(data=infer_files, shuffle=False, num_partitions=len(infer_files))[self.rank]
591+
if self.rank < len(infer_files)
592+
else []
593+
)
594+
else:
595+
infer_files = partition_dataset(
596+
data=infer_files, shuffle=False, num_partitions=self.world_size, even_divisible=True
597+
)[self.rank]
598+
588599
# TO DO: Add some function in ensembler for infer_files update?
589600
self.ensembler.infer_files = infer_files
590601
# add rank to pred_params

0 commit comments

Comments
 (0)