def test_stop_tuning_job(sagemaker_session): feature_num = 14 train_input = np.random.rand(1000, feature_num) rcf = RandomCutForest(role='SageMakerRole', train_instance_count=1, train_instance_type='ml.c4.xlarge', num_trees=50, num_samples_per_tree=20, sagemaker_session=sagemaker_session, base_job_name='test-randomcutforest') records = rcf.record_set(train_input) records.distribution = 'FullyReplicated' test_records = rcf.record_set(train_input, channel='test') test_records.distribution = 'FullyReplicated' hyperparameter_ranges = {'num_trees': IntegerParameter(50, 100), 'num_samples_per_tree': IntegerParameter(1, 2)} objective_metric_name = 'test:f1' tuner = HyperparameterTuner(estimator=rcf, objective_metric_name=objective_metric_name, hyperparameter_ranges=hyperparameter_ranges, objective_type='Maximize', max_jobs=2, max_parallel_jobs=2) tuner.fit([records, test_records]) time.sleep(15) latest_tuning_job_name = tuner.latest_tuning_job.name print('Attempting to stop {}'.format(latest_tuning_job_name)) tuner.stop_tuning_job() desc = tuner.latest_tuning_job.sagemaker_session.sagemaker_client\ .describe_hyper_parameter_tuning_job(HyperParameterTuningJobName=latest_tuning_job_name) assert desc['HyperParameterTuningJobStatus'] == 'Stopping'
def test_stop_tuning_job(sagemaker_session, cpu_instance_type): feature_num = 14 train_input = np.random.rand(1000, feature_num) rcf = RandomCutForest( role="SageMakerRole", instance_count=1, instance_type=cpu_instance_type, num_trees=50, num_samples_per_tree=20, sagemaker_session=sagemaker_session, ) records = rcf.record_set(train_input) records.distribution = "FullyReplicated" test_records = rcf.record_set(train_input, channel="test") test_records.distribution = "FullyReplicated" hyperparameter_ranges = { "num_trees": IntegerParameter(50, 100), "num_samples_per_tree": IntegerParameter(1, 2), } objective_metric_name = "test:f1" tuner = HyperparameterTuner( estimator=rcf, objective_metric_name=objective_metric_name, hyperparameter_ranges=hyperparameter_ranges, objective_type="Maximize", max_jobs=2, max_parallel_jobs=2, ) tuning_job_name = unique_name_from_base("test-randomcutforest", max_length=32) tuner.fit([records, test_records], tuning_job_name, wait=False) time.sleep(15) latest_tuning_job_name = tuner.latest_tuning_job.name print("Attempting to stop {}".format(latest_tuning_job_name)) tuner.stop_tuning_job() desc = tuner.latest_tuning_job.sagemaker_session.sagemaker_client.describe_hyper_parameter_tuning_job( HyperParameterTuningJobName=latest_tuning_job_name) assert desc["HyperParameterTuningJobStatus"] == "Stopping"