@@ -2189,7 +2189,9 @@ def tune( # noqa: C901
2189
2189
stop_condition ,
2190
2190
tags ,
2191
2191
warm_start_config ,
2192
+ max_runtime_in_seconds = None ,
2192
2193
strategy_config = None ,
2194
+ completion_criteria_config = None ,
2193
2195
enable_network_isolation = False ,
2194
2196
image_uri = None ,
2195
2197
algorithm_arn = None ,
@@ -2256,6 +2258,10 @@ def tune( # noqa: C901
2256
2258
https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html.
2257
2259
warm_start_config (dict): Configuration defining the type of warm start and
2258
2260
other required configurations.
2261
+ max_runtime_in_seconds (int or PipelineVariable): The maximum time in seconds
2262
+ that a training job launched by a hyperparameter tuning job can run.
2263
+ completion_criteria_config (sagemaker.tuner.TuningJobCompletionCriteriaConfig): A
2264
+ configuration for the completion criteria.
2259
2265
early_stopping_type (str): Specifies whether early stopping is enabled for the job.
2260
2266
Can be either 'Auto' or 'Off'. If set to 'Off', early stopping will not be
2261
2267
attempted. If set to 'Auto', early stopping of some training jobs may happen, but
@@ -2311,12 +2317,14 @@ def tune( # noqa: C901
2311
2317
strategy = strategy ,
2312
2318
max_jobs = max_jobs ,
2313
2319
max_parallel_jobs = max_parallel_jobs ,
2320
+ max_runtime_in_seconds = max_runtime_in_seconds ,
2314
2321
objective_type = objective_type ,
2315
2322
objective_metric_name = objective_metric_name ,
2316
2323
parameter_ranges = parameter_ranges ,
2317
2324
early_stopping_type = early_stopping_type ,
2318
2325
random_seed = random_seed ,
2319
2326
strategy_config = strategy_config ,
2327
+ completion_criteria_config = completion_criteria_config ,
2320
2328
),
2321
2329
"TrainingJobDefinition" : self ._map_training_config (
2322
2330
static_hyperparameters = static_hyperparameters ,
@@ -2470,12 +2478,14 @@ def _map_tuning_config(
2470
2478
strategy ,
2471
2479
max_jobs ,
2472
2480
max_parallel_jobs ,
2481
+ max_runtime_in_seconds = None ,
2473
2482
early_stopping_type = "Off" ,
2474
2483
objective_type = None ,
2475
2484
objective_metric_name = None ,
2476
2485
parameter_ranges = None ,
2477
2486
random_seed = None ,
2478
2487
strategy_config = None ,
2488
+ completion_criteria_config = None ,
2479
2489
):
2480
2490
"""Construct tuning job configuration dictionary.
2481
2491
@@ -2484,6 +2494,8 @@ def _map_tuning_config(
2484
2494
max_jobs (int): Maximum total number of training jobs to start for the hyperparameter
2485
2495
tuning job.
2486
2496
max_parallel_jobs (int): Maximum number of parallel training jobs to start.
2497
+ max_runtime_in_seconds (int or PipelineVariable): The maximum time in seconds
2498
+ that a training job launched by a hyperparameter tuning job can run.
2487
2499
early_stopping_type (str): Specifies whether early stopping is enabled for the job.
2488
2500
Can be either 'Auto' or 'Off'. If set to 'Off', early stopping will not be
2489
2501
attempted. If set to 'Auto', early stopping of some training jobs may happen,
@@ -2498,6 +2510,8 @@ def _map_tuning_config(
2498
2510
produce more consistent configurations for the same tuning job.
2499
2511
strategy_config (dict): A configuration for the hyperparameter tuning job optimisation
2500
2512
strategy.
2513
+ completion_criteria_config (dict): A configuration
2514
+ for the completion criteria.
2501
2515
2502
2516
Returns:
2503
2517
A dictionary of tuning job configuration. For format details, please refer to
@@ -2514,6 +2528,9 @@ def _map_tuning_config(
2514
2528
"TrainingJobEarlyStoppingType" : early_stopping_type ,
2515
2529
}
2516
2530
2531
+ if max_runtime_in_seconds is not None :
2532
+ tuning_config ["ResourceLimits" ]["MaxRuntimeInSeconds" ] = max_runtime_in_seconds
2533
+
2517
2534
if random_seed is not None :
2518
2535
tuning_config ["RandomSeed" ] = random_seed
2519
2536
@@ -2526,6 +2543,9 @@ def _map_tuning_config(
2526
2543
2527
2544
if strategy_config is not None :
2528
2545
tuning_config ["StrategyConfig" ] = strategy_config
2546
+
2547
+ if completion_criteria_config is not None :
2548
+ tuning_config ["TuningJobCompletionCriteria" ] = completion_criteria_config
2529
2549
return tuning_config
2530
2550
2531
2551
@classmethod
0 commit comments