def test_get_expected_model_with_framework_estimator(tensorflow_estimator): training_step = TrainingStep('Training', estimator=tensorflow_estimator, data={'train': 's3://sagemaker/train'}, job_name='tensorflow-job', mini_batch_size=1024) expected_model = training_step.get_expected_model() expected_model.entry_point = 'tf_train.py' model_step = ModelStep('Create model', model=expected_model, model_name='tf-model') assert model_step.to_dict() == { 'Type': 'Task', 'Parameters': { 'ExecutionRoleArn': EXECUTION_ROLE, 'ModelName': 'tf-model', 'PrimaryContainer': { 'Environment': { 'SAGEMAKER_PROGRAM': 'tf_train.py', 'SAGEMAKER_SUBMIT_DIRECTORY': 's3://sagemaker/tensorflow-job/source/sourcedir.tar.gz', 'SAGEMAKER_CONTAINER_LOG_LEVEL': '20', 'SAGEMAKER_REGION': 'us-east-1', }, 'Image': expected_model.image_uri, 'ModelDataUrl.$': "$['ModelArtifacts']['S3ModelArtifacts']" } }, 'Resource': 'arn:aws:states:::sagemaker:createModel', 'End': True }
def test_training_step_creation_with_model(pca_estimator): training_step = TrainingStep('Training', estimator=pca_estimator, job_name='TrainingJob') model_step = ModelStep( 'Training - Save Model', training_step.get_expected_model( model_name=training_step.output()['TrainingJobName'])) training_step.next(model_step) assert training_step.to_dict() == { 'Type': 'Task', 'Parameters': { 'AlgorithmSpecification': { 'TrainingImage': PCA_IMAGE, 'TrainingInputMode': 'File' }, 'OutputDataConfig': { 'S3OutputPath': 's3://sagemaker/models' }, 'StoppingCondition': { 'MaxRuntimeInSeconds': 86400 }, 'ResourceConfig': { 'InstanceCount': 1, 'InstanceType': 'ml.c4.xlarge', 'VolumeSizeInGB': 30 }, 'RoleArn': EXECUTION_ROLE, 'HyperParameters': { 'feature_dim': '50000', 'num_components': '10', 'subtract_mean': 'True', 'algorithm_mode': 'randomized', 'mini_batch_size': '200' }, 'TrainingJobName': 'TrainingJob' }, 'Resource': 'arn:aws:states:::sagemaker:createTrainingJob.sync', 'Next': 'Training - Save Model' } assert model_step.to_dict() == { 'Type': 'Task', 'Resource': 'arn:aws:states:::sagemaker:createModel', 'Parameters': { 'ExecutionRoleArn': EXECUTION_ROLE, 'ModelName.$': "$['TrainingJobName']", 'PrimaryContainer': { 'Environment': {}, 'Image': PCA_IMAGE, 'ModelDataUrl.$': "$['ModelArtifacts']['S3ModelArtifacts']" } }, 'End': True }
def test_model_step_creation(pca_model): step = ModelStep('Create model', model=pca_model, model_name='pca-model') assert step.to_dict() == { 'Type': 'Task', 'Parameters': { 'ExecutionRoleArn': EXECUTION_ROLE, 'ModelName': 'pca-model', 'PrimaryContainer': { 'Environment': {}, 'Image': pca_model.image, 'ModelDataUrl': pca_model.model_data } }, 'Resource': 'arn:aws:states:::sagemaker:createModel', 'End': True }
def test_get_expected_model(pca_estimator): training_step = TrainingStep('Training', estimator=pca_estimator, job_name='TrainingJob') expected_model = training_step.get_expected_model() model_step = ModelStep('Create model', model=expected_model, model_name='pca-model') assert model_step.to_dict() == { 'Type': 'Task', 'Parameters': { 'ExecutionRoleArn': EXECUTION_ROLE, 'ModelName': 'pca-model', 'PrimaryContainer': { 'Environment': {}, 'Image': expected_model.image, 'ModelDataUrl.$': "$['ModelArtifacts']['S3ModelArtifacts']" } }, 'Resource': 'arn:aws:states:::sagemaker:createModel', 'End': True }