Repository: Project-MONAI/MONAI
File: monai/apps/auto3dseg/auto_runner.py (Python)

Code before:
                    self.work_dir,
                    num_fold=self.num_fold,
                    gpu_customization=self.gpu_customization,
                    gpu_customization_specs=self.gpu_customization_specs,
                )
            else:
                bundle_generator.generate(self.work_dir, num_fold=self.num_fold)
            history = bundle_generator.get_history()
            export_bundle_algo_history(history)
            self.export_cache(algo_gen=True)
        else:
            logger.info("Skipping algorithm generation...")

        # step 3: algo training
        auto_train_choice = self.train is None
        if self.train or (auto_train_choice and not self.cache["train"]):
            history = import_bundle_algo_history(self.work_dir, only_trained=False)

            if len(history) == 0:
                raise ValueError(
                    f"Could not find training scripts in {self.work_dir}. "
                    "Possibly the required algorithms generation step was not completed."
                )

            if auto_train_choice:
                history = [h for h in history if not h["is_trained"]]  # skip trained

            if len(history) > 0:
                if not self.hpo:
                    self._train_algo_in_sequence(history)
                else:
                    self._train_algo_in_nni(history)

            self.export_cache(train=True)
        else:
            logger.info("Skipping algorithm training...")

        # step 4: model ensemble and write the prediction to disks.
        if self.ensemble:
            history = import_bundle_algo_history(self.work_dir, only_trained=False)

            history_untrained = [h for h in history if not h["is_trained"]]
            if len(history_untrained) > 0:
                warnings.warn(
                    f"Ensembling step will skip {[h['name'] for h in history_untrained]} untrained algos"
                    "Generally it means these algos did not complete training"
                )
                history = [h for h in history if h["is_trained"]]

            if len(history) == 0:
                raise ValueError(

Review comment (bug):
Shall we have a logging at the debug level for the algorithms picked for training, or the algorithms skipped because `is_trained` is true?

Code after:
                    self.work_dir,
                    num_fold=self.num_fold,
                    gpu_customization=self.gpu_customization,
                    gpu_customization_specs=self.gpu_customization_specs,
                )
            else:
                bundle_generator.generate(self.work_dir, num_fold=self.num_fold)
            history = bundle_generator.get_history()
            export_bundle_algo_history(history)
            self.export_cache(algo_gen=True)
        else:
            logger.info("Skipping algorithm generation...")

        # step 3: algo training
        auto_train_choice = self.train is None
        if self.train or (auto_train_choice and not self.cache["train"]):
            history = import_bundle_algo_history(self.work_dir, only_trained=False)

            if len(history) == 0:
                raise ValueError(
                    f"Could not find training scripts in {self.work_dir}. "
                    "Possibly the required algorithms generation step was not completed."
                )

            if auto_train_choice:
                skip_algos = [h[AlgoEnsembleKeys.ID] for h in history if h["is_trained"]]
                if len(skip_algos) > 0:
                    logger.info(
                        f"Skipping already trained algos {skip_algos}."
                        "Set option train=True to always retrain all algos."
                    )
                    history = [h for h in history if not h["is_trained"]]

            if len(history) > 0:
                if not self.hpo:
                    self._train_algo_in_sequence(history)
                else:
                    self._train_algo_in_nni(history)

            self.export_cache(train=True)
        else:
            logger.info("Skipping algorithm training...")

        # step 4: model ensemble and write the prediction to disks.
        if self.ensemble:
            history = import_bundle_algo_history(self.work_dir, only_trained=False)

            history_untrained = [h for h in history if not h["is_trained"]]
            if len(history_untrained) > 0:
                warnings.warn(
                    f"Ensembling step will skip {[h['name'] for h in history_untrained]} untrained algos."