Skip to content

Commit 9922857

Browse files
Alexknakad
authored andcommitted
change: remove instance_pools parameter from tuner
this change is to remove the concept of instance_pools from multi- algorithm hyperparameter tuning as an input configuration.
1 parent ed43726 commit 9922857

File tree

8 files changed

+2
-90
lines changed

8 files changed

+2
-90
lines changed

src/sagemaker/session.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ def _map_tuning_config(
788788
objective_type=None,
789789
objective_metric_name=None,
790790
parameter_ranges=None,
791-
training_instance_pools=None,
792791
):
793792
"""
794793
Construct tuning job configuration dictionary.
@@ -807,10 +806,6 @@ def _map_tuning_config(
807806
objective_metric_name (str): Name of the metric for evaluating training jobs.
808807
parameter_ranges (dict): Dictionary of parameter ranges. These parameter ranges can
809808
be one of three types: Continuous, Integer, or Categorical.
810-
training_instance_pools (dict[str, int]): Dictionary to specify how many ML instances
811-
of different types to be reserved before starting the hyperparameter tuning job.
812-
The keys are the ML instance types, and the values are the numbers of the
813-
instances to be reserved.
814809
815810
Returns:
816811
A dictionary of tuning job configuration. For format details, please refer to
@@ -834,12 +829,6 @@ def _map_tuning_config(
834829
if parameter_ranges is not None:
835830
tuning_config["ParameterRanges"] = parameter_ranges
836831

837-
if training_instance_pools is not None:
838-
tuning_config["TrainingJobInstancePools"] = [
839-
{"InstanceType": instance_type, "PoolSize": training_instance_pools[instance_type]}
840-
for instance_type in sorted(training_instance_pools.keys())
841-
]
842-
843832
return tuning_config
844833

845834
@classmethod

src/sagemaker/tuner.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ def __init__(
206206
warm_start_config=None,
207207
early_stopping_type="Off",
208208
estimator_name=None,
209-
training_instance_pools=None,
210209
):
211210
"""Initialize a ``HyperparameterTuner``. It takes an estimator to obtain
212211
configuration information for training jobs that are created as the
@@ -260,19 +259,6 @@ def __init__(
260259
estimator_name (str): A unique name to identify an estimator within the
261260
hyperparameter tuning job, when more than one estimator is used with
262261
the same tuning job (default: None).
263-
training_instance_pools (dict[str, str]): Dictionary to specify how many
264-
ML instances of different types to be reserved before starting the
265-
hyperparameter tuning job (default: None). The keys are the ML instance
266-
types, and the values are the numbers of the instances to be reserved.
267-
The following example specifies two instance pools. One pool has
268-
10 ml.m4.4xlarge instances, while the other has 2 ml.p2.8xlarge
269-
instances.
270-
>>> {
271-
>>> 'ml.m4.4xlarge': 10,
272-
>>> 'ml.p2.8xlarge': 2
273-
>>> }
274-
For more details, see
275-
https://botocore.readthedocs.io/en/latest/reference/services/sagemaker.html#SageMaker.Client.create_hyper_parameter_tuning_job
276262
"""
277263
if hyperparameter_ranges is None or len(hyperparameter_ranges) == 0:
278264
raise ValueError("Need to specify hyperparameter ranges")
@@ -313,7 +299,6 @@ def __init__(
313299
self.latest_tuning_job = None
314300
self.warm_start_config = warm_start_config
315301
self.early_stopping_type = early_stopping_type
316-
self.training_instance_pools = training_instance_pools
317302

318303
def _prepare_for_tuning(self, job_name=None, include_cls_metadata=False):
319304
"""Prepare the tuner instance for tuning (fit)"""
@@ -952,12 +937,6 @@ def _prepare_init_params_from_job_description(cls, job_details):
952937
tuning_config["ParameterRanges"]
953938
)
954939

955-
if "TrainingJobInstancePools" in tuning_config:
956-
params["training_instance_pools"] = {
957-
instance_pool["InstanceType"]: instance_pool["PoolSize"]
958-
for instance_pool in tuning_config["TrainingJobInstancePools"]
959-
}
960-
961940
if "TrainingJobDefinition" in job_details:
962941
params["metric_definitions"] = job_details["TrainingJobDefinition"][
963942
"AlgorithmSpecification"
@@ -1230,7 +1209,6 @@ def _create_warm_start_tuner(self, additional_parents, warm_start_type, estimato
12301209
max_jobs=self.max_jobs,
12311210
max_parallel_jobs=self.max_parallel_jobs,
12321211
warm_start_config=WarmStartConfig(warm_start_type=warm_start_type, parents=all_parents),
1233-
training_instance_pools=self.training_instance_pools,
12341212
early_stopping_type=self.early_stopping_type,
12351213
)
12361214

@@ -1241,7 +1219,6 @@ def create(
12411219
objective_metric_name_dict,
12421220
hyperparameter_ranges_dict,
12431221
metric_definitions_dict=None,
1244-
training_instance_pools=None,
12451222
base_tuning_job_name=None,
12461223
strategy="Bayesian",
12471224
objective_type="Maximize",
@@ -1284,10 +1261,6 @@ def create(
12841261
name of the metric, and 'Regex' for the regular expression used to extract the
12851262
metric from the logs. This should be defined only for hyperparameter tuning jobs
12861263
that don't use an Amazon algorithm.
1287-
training_instance_pools (dict[str, str]): Dictionary to specify how many ML instances
1288-
of different types to be reserved before starting the hyperparameter tuning job.
1289-
The keys are the ML instance types, and the values are the numbers of the instances
1290-
to be reserved.
12911264
base_tuning_job_name (str): Prefix for the hyperparameter tuning job name when the
12921265
:meth:`~sagemaker.tuner.HyperparameterTuner.fit` method launches. If not specified,
12931266
a default job name is generated, based on the training image name and current
@@ -1344,7 +1317,6 @@ def create(
13441317
max_jobs=max_jobs,
13451318
max_parallel_jobs=max_parallel_jobs,
13461319
tags=tags,
1347-
training_instance_pools=training_instance_pools,
13481320
warm_start_config=warm_start_config,
13491321
early_stopping_type=early_stopping_type,
13501322
)
@@ -1484,9 +1456,6 @@ def start_new(cls, tuner, inputs):
14841456
if parameter_ranges is not None:
14851457
tuning_config["parameter_ranges"] = parameter_ranges
14861458

1487-
if tuner.training_instance_pools is not None:
1488-
tuning_config["training_instance_pools"] = tuner.training_instance_pools
1489-
14901459
tuner_args = {
14911460
"job_name": tuner._current_job_name,
14921461
"tuning_config": tuning_config,

src/sagemaker/workflow/airflow.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,6 @@ def _extract_tuning_job_config(tuner):
357357
if parameter_ranges:
358358
tuning_job_config["ParameterRanges"] = parameter_ranges
359359

360-
if tuner.training_instance_pools:
361-
tuning_job_config["TrainingJobInstancePools"] = [
362-
{
363-
"InstanceType": instance_type,
364-
"PoolSize": tuner.training_instance_pools[instance_type],
365-
}
366-
for instance_type in sorted(tuner.training_instance_pools.keys())
367-
]
368-
369360
return tuning_job_config
370361

371362

tests/integ/test_tuner_multi_algo.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ def data_set():
6868
return data_set
6969

7070

71-
@pytest.fixture(scope="module")
72-
def training_instance_pools(cpu_instance_type):
73-
return {cpu_instance_type: 2}
74-
75-
7671
@pytest.fixture(scope="function")
7772
def estimator_fm(sagemaker_session, cpu_instance_type):
7873
fm_image = get_image_uri(
@@ -114,12 +109,7 @@ def estimator_knn(sagemaker_session, cpu_instance_type):
114109

115110
@pytest.mark.canary_quick
116111
def test_multi_estimator_tuning(
117-
sagemaker_session,
118-
estimator_fm,
119-
estimator_knn,
120-
training_instance_pools,
121-
data_set,
122-
cpu_instance_type,
112+
sagemaker_session, estimator_fm, estimator_knn, data_set, cpu_instance_type
123113
):
124114
tuner = HyperparameterTuner.create(
125115
base_tuning_job_name=BASE_TUNING_JOB_NAME,
@@ -136,7 +126,6 @@ def test_multi_estimator_tuning(
136126
objective_type=OBJECTIVE_TYPE,
137127
max_jobs=MAX_JOBS,
138128
max_parallel_jobs=MAX_PARALLEL_JOBS,
139-
training_instance_pools=training_instance_pools,
140129
tags=TAGS,
141130
)
142131

tests/unit/test_airflow.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ def test_multi_estimator_tuning_config(sagemaker_session):
671671
max_parallel_jobs="{{ max_parallel_job }}",
672672
tags=[{"{{ key }}": "{{ value }}"}],
673673
base_tuning_job_name="{{ base_job_name }}",
674-
training_instance_pools={"ml.m4.xlarge": 4, "ml.c4.2xlarge": 10},
675674
)
676675

677676
data = {
@@ -690,10 +689,6 @@ def test_multi_estimator_tuning_config(sagemaker_session):
690689
"MaxParallelTrainingJobs": "{{ max_parallel_job }}",
691690
},
692691
"TrainingJobEarlyStoppingType": "Off",
693-
"TrainingJobInstancePools": [
694-
{"InstanceType": "ml.c4.2xlarge", "PoolSize": 10},
695-
{"InstanceType": "ml.m4.xlarge", "PoolSize": 4},
696-
],
697692
},
698693
"TrainingJobDefinitions": [
699694
{

tests/unit/test_session.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,6 @@ def test_train_pack_to_request(sagemaker_session):
807807
"Strategy": "Bayesian",
808808
"ResourceLimits": {"MaxNumberOfTrainingJobs": 100, "MaxParallelTrainingJobs": 5},
809809
"TrainingJobEarlyStoppingType": "Off",
810-
"TrainingJobInstancePools": [
811-
{"InstanceType": "ml.m4.4xlarge", "PoolSize": 3},
812-
{"InstanceType": "ml.p2.xlarge", "PoolSize": 1},
813-
],
814810
},
815811
"TrainingJobDefinitions": [
816812
{
@@ -1001,12 +997,7 @@ def assert_create_tuning_job_request(**kwrags):
1001997
)
1002998
sagemaker_session.create_tuning_job(
1003999
job_name="dummy-tuning-1",
1004-
tuning_config={
1005-
"strategy": "Bayesian",
1006-
"max_jobs": 100,
1007-
"max_parallel_jobs": 5,
1008-
"training_instance_pools": {"ml.m4.4xlarge": 3, "ml.p2.xlarge": 1},
1009-
},
1000+
tuning_config={"strategy": "Bayesian", "max_jobs": 100, "max_parallel_jobs": 5},
10101001
training_config_list=[
10111002
{
10121003
"static_hyperparameters": STATIC_HPs,

tests/unit/test_tuner.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ def test_fit_multi_estimators(sagemaker_session):
376376
assert tune_kwargs["tuning_config"]["max_jobs"] == MAX_JOBS
377377
assert tune_kwargs["tuning_config"]["max_parallel_jobs"] == MAX_PARALLEL_JOBS
378378
assert tune_kwargs["tuning_config"]["early_stopping_type"] == EARLY_STOPPING_TYPE
379-
assert tune_kwargs["tuning_config"]["training_instance_pools"] == TRAINING_INSTANCE_POOLS
380379

381380
assert "tuning_objective" not in tune_kwargs["tuning_config"]
382381
assert "parameter_ranges" not in tune_kwargs["tuning_config"]
@@ -455,7 +454,6 @@ def _create_multi_estimator_tuner(sagemaker_session):
455454
ESTIMATOR_NAME_TWO: HYPERPARAMETER_RANGES_TWO,
456455
},
457456
metric_definitions_dict={ESTIMATOR_NAME: METRIC_DEFINITIONS},
458-
training_instance_pools=TRAINING_INSTANCE_POOLS,
459457
strategy=STRATEGY,
460458
objective_type=OBJECTIVE_TYPE,
461459
max_jobs=MAX_JOBS,
@@ -613,8 +611,6 @@ def test_attach_tuning_job_with_multi_estimators(sagemaker_session):
613611
assert tuner.early_stopping_type == "Off"
614612
assert tuner.warm_start_config is None
615613

616-
assert tuner.training_instance_pools == TRAINING_INSTANCE_POOLS
617-
618614
assert tuner.estimator is None
619615
assert tuner.objective_metric_name is None
620616
assert tuner._hyperparameter_ranges is None
@@ -1001,7 +997,6 @@ def test_create_tuner(estimator_dict, obj_metric_name_dict, param_ranges_dict, m
1001997
objective_metric_name_dict=obj_metric_name_dict,
1002998
hyperparameter_ranges_dict=param_ranges_dict,
1003999
metric_definitions_dict=metric_def_dict,
1004-
training_instance_pools=TRAINING_INSTANCE_POOLS,
10051000
strategy="Bayesian",
10061001
objective_type="Minimize",
10071002
max_jobs=MAX_JOBS,
@@ -1019,7 +1014,6 @@ def test_create_tuner(estimator_dict, obj_metric_name_dict, param_ranges_dict, m
10191014
assert tuner.metric_definitions_dict == metric_def_dict
10201015

10211016
assert tuner.base_tuning_job_name == BASE_JOB_NAME
1022-
assert tuner.training_instance_pools == TRAINING_INSTANCE_POOLS
10231017
assert tuner.strategy == "Bayesian"
10241018
assert tuner.objective_type == "Minimize"
10251019
assert tuner.max_jobs == MAX_JOBS
@@ -1103,7 +1097,6 @@ def test_create_tuner_negative(
11031097
objective_metric_name_dict=obj_metric_name_dict,
11041098
hyperparameter_ranges_dict=param_ranges_dict,
11051099
metric_definitions_dict=metric_def_dict,
1106-
training_instance_pools=TRAINING_INSTANCE_POOLS,
11071100
strategy="Bayesian",
11081101
objective_type="Minimize",
11091102
max_jobs=MAX_JOBS,

tests/unit/tuner_test_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959

6060
METRIC_DEFINITIONS = "mock_metric_definitions"
6161

62-
TRAINING_INSTANCE_POOLS = {"ml.m4.4xlarge": 5, "ml.p2.8xlarge": 2}
6362
MAX_JOBS = 10
6463
MAX_PARALLEL_JOBS = 5
6564
TAGS = [{"key1": "value1"}]
@@ -165,10 +164,6 @@
165164
"ResourceLimits": {"MaxParallelTrainingJobs": 2, "MaxNumberOfTrainingJobs": 4},
166165
"Strategy": "Bayesian",
167166
"TrainingJobEarlyStoppingType": "Off",
168-
"TrainingJobInstancePools": [
169-
{"InstanceType": instance_type, "PoolSize": pool_size}
170-
for (instance_type, pool_size) in TRAINING_INSTANCE_POOLS.items()
171-
],
172167
},
173168
"HyperParameterTuningJobName": JOB_NAME,
174169
"TrainingJobDefinitions": [

0 commit comments

Comments
 (0)