@@ -207,8 +207,24 @@ HyperParameterOptimizerLearner::TrainWithStatusImpl(
207207 const dataset::VerticalDataset& train_dataset,
208208 std::optional<std::reference_wrapper<const dataset::VerticalDataset>>
209209 valid_dataset) const {
210+ // The effective configuration is the user configuration + the default value +
211+ // the automatic configuration (if enabled) + the copy of the non-specified
212+ // training configuration field from the learner to the sub-learner (e.g. copy
213+ // of the label name).
214+ model::proto::TrainingConfig effective_config;
215+ model::proto::TrainingConfigLinking config_link;
216+ RETURN_IF_ERROR (GetEffectiveConfiguration (train_dataset.data_spec (),
217+ &effective_config, &config_link));
218+ const proto::HyperParametersOptimizerLearnerTrainingConfig& spe_config =
219+ effective_config.GetExtension (proto::hyperparameters_optimizer_config);
220+
210221 if (deployment ().execution_case () ==
211222 model::proto::DeploymentConfig::ExecutionCase::kDistribute ) {
223+ if (spe_config.evaluation ().has_cross_validation ()) {
224+ return absl::InvalidArgumentError (
225+ " The cross-validation evaluation of the hyper-parameter candidates "
226+ " is not supported with distributed training" );
227+ }
212228 // Export the dataset to file and run the training on file.
213229 return TrainFromFileOnMemoryDataset (train_dataset, valid_dataset);
214230 }
@@ -222,17 +238,6 @@ HyperParameterOptimizerLearner::TrainWithStatusImpl(
222238 " deployment configs." );
223239 }
224240
225- // The effective configuration is the user configuration + the default value +
226- // the automatic configuration (if enabled) + the copy of the non-specified
227- // training configuration field from the learner to the sub-learner (e.g. copy
228- // of the label name).
229- model::proto::TrainingConfig effective_config;
230- model::proto::TrainingConfigLinking config_link;
231- RETURN_IF_ERROR (GetEffectiveConfiguration (train_dataset.data_spec (),
232- &effective_config, &config_link));
233- const proto::HyperParametersOptimizerLearnerTrainingConfig& spe_config =
234- effective_config.GetExtension (proto::hyperparameters_optimizer_config);
235-
236241 // Initialize the learner with the base hyperparameters.
237242 ASSIGN_OR_RETURN (auto base_learner,
238243 BuildBaseLearner (spe_config, /* for_tuning=*/ true ));
@@ -345,6 +350,12 @@ HyperParameterOptimizerLearner::TrainWithStatusImpl(
345350 const proto::HyperParametersOptimizerLearnerTrainingConfig& spe_config =
346351 effective_config.GetExtension (proto::hyperparameters_optimizer_config);
347352
353+ if (spe_config.evaluation ().has_cross_validation ()) {
354+ return absl::InvalidArgumentError (
355+ " The cross-validation evaluation of the hyper-parameter candidates "
356+ " is not supported with distributed training" );
357+ }
358+
348359 // Initialize the remote workers.
349360 ASSIGN_OR_RETURN (auto manager, CreateDistributeManager (spe_config));
350361
@@ -652,7 +663,8 @@ HyperParameterOptimizerLearner::SearchBestHyperparameterInProcess(
652663
653664 LOG (INFO ) << " Start local tuner with "
654665 << spe_config.optimizer ().parallel_trials ()
655- << " parallel trial(s), each with " << deployment ().num_threads ()
666+ << " parallel trial(s), each with "
667+ << spe_config.base_learner_deployment ().num_threads ()
656668 << " thread(s)" ;
657669 async_evaluator.StartWorkers ();
658670
@@ -822,7 +834,12 @@ absl::StatusOr<double> HyperParameterOptimizerLearner::EvaluateCandidateLocally(
822834 *base_learner, train_dataset,
823835 fold_generator, evaluation_options,
824836 spe_config.base_learner_deployment ()));
837+ break ;
825838 }
839+ default :
840+ return absl::InvalidArgumentError (absl::StrCat (
841+ " Unsupported evaluation source: " ,
842+ static_cast <int >(spe_config.evaluation ().source_case ())));
826843 }
827844
828845 ASSIGN_OR_RETURN (const auto score, EvaluationToScore (spe_config, evaluation));
0 commit comments