|
26 | 26 | from botocore.exceptions import WaiterError
|
27 | 27 |
|
28 | 28 | import tests
|
29 |
| -from sagemaker.parameter import IntegerParameter |
30 | 29 | from sagemaker.tensorflow import TensorFlow, TensorFlowModel
|
31 |
| -from sagemaker.tuner import HyperparameterTuner |
32 | 30 | from tests.integ.retry import retries
|
33 | 31 | from sagemaker.drift_check_baselines import DriftCheckBaselines
|
34 | 32 | from sagemaker import (
|
|
50 | 48 | from sagemaker.workflow.parameters import ParameterInteger, ParameterString
|
51 | 49 | from sagemaker.workflow.pipeline import Pipeline
|
52 | 50 | from sagemaker.workflow.step_collections import RegisterModel
|
53 |
| -from sagemaker.workflow.steps import CreateModelStep, ProcessingStep, TrainingStep, TuningStep |
| 51 | +from sagemaker.workflow.steps import CreateModelStep, ProcessingStep, TrainingStep |
54 | 52 | from sagemaker.xgboost import XGBoostModel
|
55 | 53 | from sagemaker.xgboost import XGBoost
|
56 | 54 | from sagemaker.workflow.conditions import (
|
@@ -848,124 +846,3 @@ def test_model_registration_with_tensorflow_model_with_pipeline_model(
|
848 | 846 | pipeline.delete()
|
849 | 847 | except Exception as error:
|
850 | 848 | logging.error(error)
|
851 |
| - |
852 |
| - |
853 |
| -def test_tuning_single_algo_with_create_model( |
854 |
| - sagemaker_session, |
855 |
| - role, |
856 |
| - cpu_instance_type, |
857 |
| - pipeline_name, |
858 |
| - region_name, |
859 |
| -): |
860 |
| - base_dir = os.path.join(DATA_DIR, "pytorch_mnist") |
861 |
| - entry_point = os.path.join(base_dir, "mnist.py") |
862 |
| - input_path = sagemaker_session.upload_data( |
863 |
| - path=os.path.join(base_dir, "training"), |
864 |
| - key_prefix="integ-test-data/pytorch_mnist/training", |
865 |
| - ) |
866 |
| - inputs = TrainingInput(s3_data=input_path) |
867 |
| - |
868 |
| - instance_count = ParameterInteger(name="InstanceCount", default_value=1) |
869 |
| - instance_type = ParameterString(name="InstanceType", default_value="ml.m5.xlarge") |
870 |
| - |
871 |
| - pytorch_estimator = PyTorch( |
872 |
| - entry_point=entry_point, |
873 |
| - role=role, |
874 |
| - framework_version="1.5.0", |
875 |
| - py_version="py3", |
876 |
| - instance_count=instance_count, |
877 |
| - instance_type=instance_type, |
878 |
| - sagemaker_session=sagemaker_session, |
879 |
| - enable_sagemaker_metrics=True, |
880 |
| - max_retry_attempts=3, |
881 |
| - ) |
882 |
| - |
883 |
| - min_batch_size = ParameterInteger(name="MinBatchSize", default_value=64) |
884 |
| - max_batch_size = ParameterInteger(name="MaxBatchSize", default_value=128) |
885 |
| - hyperparameter_ranges = { |
886 |
| - "batch-size": IntegerParameter(min_batch_size, max_batch_size), |
887 |
| - } |
888 |
| - tuner = HyperparameterTuner( |
889 |
| - estimator=pytorch_estimator, |
890 |
| - objective_metric_name="test:acc", |
891 |
| - objective_type="Maximize", |
892 |
| - hyperparameter_ranges=hyperparameter_ranges, |
893 |
| - metric_definitions=[{"Name": "test:acc", "Regex": "Overall test accuracy: (.*?);"}], |
894 |
| - max_jobs=2, |
895 |
| - max_parallel_jobs=2, |
896 |
| - ) |
897 |
| - step_tune = TuningStep( |
898 |
| - name="my-tuning-step", |
899 |
| - tuner=tuner, |
900 |
| - inputs=inputs, |
901 |
| - ) |
902 |
| - best_model = Model( |
903 |
| - image_uri=pytorch_estimator.training_image_uri(), |
904 |
| - model_data=step_tune.get_top_model_s3_uri( |
905 |
| - top_k=0, |
906 |
| - s3_bucket=sagemaker_session.default_bucket(), |
907 |
| - ), |
908 |
| - sagemaker_session=sagemaker_session, |
909 |
| - role=role, |
910 |
| - ) |
911 |
| - model_inputs = CreateModelInput( |
912 |
| - instance_type="ml.m5.large", |
913 |
| - accelerator_type="ml.eia1.medium", |
914 |
| - ) |
915 |
| - step_best_model = CreateModelStep( |
916 |
| - name="1st-model", |
917 |
| - model=best_model, |
918 |
| - inputs=model_inputs, |
919 |
| - ) |
920 |
| - |
921 |
| - second_best_model = Model( |
922 |
| - image_uri=pytorch_estimator.training_image_uri(), |
923 |
| - model_data=step_tune.get_top_model_s3_uri( |
924 |
| - top_k=1, |
925 |
| - s3_bucket=sagemaker_session.default_bucket(), |
926 |
| - ), |
927 |
| - sagemaker_session=sagemaker_session, |
928 |
| - role=role, |
929 |
| - entry_point=entry_point, |
930 |
| - source_dir=base_dir, |
931 |
| - ) |
932 |
| - step_second_best_model = CreateModelStep( |
933 |
| - name="2nd-best-model", |
934 |
| - model=second_best_model, |
935 |
| - inputs=model_inputs, |
936 |
| - ) |
937 |
| - pipeline = Pipeline( |
938 |
| - name=pipeline_name, |
939 |
| - parameters=[instance_count, instance_type, min_batch_size, max_batch_size], |
940 |
| - steps=[step_tune, step_best_model, step_second_best_model], |
941 |
| - sagemaker_session=sagemaker_session, |
942 |
| - ) |
943 |
| - |
944 |
| - try: |
945 |
| - response = pipeline.create(role) |
946 |
| - create_arn = response["PipelineArn"] |
947 |
| - assert re.match( |
948 |
| - rf"arn:aws:sagemaker:{region_name}:\d{{12}}:pipeline/{pipeline_name}", |
949 |
| - create_arn, |
950 |
| - ) |
951 |
| - |
952 |
| - execution = pipeline.start(parameters={}) |
953 |
| - assert re.match( |
954 |
| - rf"arn:aws:sagemaker:{region_name}:\d{{12}}:pipeline/{pipeline_name}/execution/", |
955 |
| - execution.arn, |
956 |
| - ) |
957 |
| - try: |
958 |
| - execution.wait(delay=30, max_attempts=60) |
959 |
| - except WaiterError: |
960 |
| - pass |
961 |
| - execution_steps = execution.list_steps() |
962 |
| - |
963 |
| - for step in execution_steps: |
964 |
| - assert not step.get("FailureReason", None) |
965 |
| - assert step["StepStatus"] == "Succeeded" |
966 |
| - assert len(execution_steps) == 3 |
967 |
| - finally: |
968 |
| - try: |
969 |
| - pipeline.delete() |
970 |
| - except Exception: |
971 |
| - pass |
0 commit comments