Пример #1
0
def test_cartpole(docker_image, sagemaker_local_session, processor, tmpdir):
    source_dir = os.path.join(RESOURCE_PATH, 'coach_cartpole')
    dependencies = [os.path.join(RESOURCE_PATH, 'sagemaker_rl')]
    cartpole = 'train_coach.py'

    instance_type = 'local' if processor == 'cpu' else 'local_gpu'

    estimator = RLEstimator(entry_point=cartpole,
                            source_dir=source_dir,
                            role='SageMakerRole',
                            instance_count=1,
                            instance_type=instance_type,
                            sagemaker_session=sagemaker_local_session,
                            image_uri=docker_image,
                            output_path='file://{}'.format(tmpdir),
                            dependencies=dependencies,
                            hyperparameters={
                                "save_model": 1,
                                "RLCOACH_PRESET": "preset_cartpole_clippedppo",
                                "rl.agent_params.algorithm.discount": 0.9,
                                "rl.evaluation_steps:EnvironmentEpisodes": 1,
                            })
    estimator.fit()

    local_mode_utils.assert_output_files_exist(str(tmpdir), 'output',
                                               ['success'])
    assert os.path.exists(os.path.join(str(tmpdir),
                                       'model.tar.gz')), 'model file not found'
def test_linear_regression(docker_image, sagemaker_local_session,
                           local_instance_type, framework_version, tmpdir):
    lr_path = os.path.join(RESOURCE_PATH, 'linear_regression')

    mx = MXNet(entry_point=os.path.join(lr_path, 'linear_regression.py'),
               role='SageMakerRole',
               train_instance_count=1,
               train_instance_type=local_instance_type,
               sagemaker_session=sagemaker_local_session,
               image_name=docker_image,
               framework_version=framework_version,
               output_path='file://{}'.format(tmpdir))

    data_path = os.path.join(lr_path, 'data')
    s3_prefix = 'integ-test-data/mxnet-linear-regression'
    train_input = sagemaker_local_session.upload_data(path=os.path.join(
        data_path, 'training'),
                                                      key_prefix=s3_prefix)
    eval_input = sagemaker_local_session.upload_data(path=os.path.join(
        data_path, 'evaluation'),
                                                     key_prefix=s3_prefix)

    mx.fit({'training': train_input, 'evaluation': eval_input})

    for directory, files in MODEL_SUCCESS_FILES.items():
        local_mode_utils.assert_output_files_exist(str(tmpdir), directory,
                                                   files)
def test_onnx_export(docker_image, sagemaker_local_session, local_instance_type, framework_version,
                     tmpdir):
    mx = MXNet(entry_point=SCRIPT_PATH, role='SageMakerRole', train_instance_count=1,
               train_instance_type=local_instance_type, sagemaker_session=sagemaker_local_session,
               image_name=docker_image, framework_version=framework_version,
               output_path='file://{}'.format(tmpdir))

    input_path = 'file://{}'.format(os.path.join(ONNX_PATH, 'mxnet_module'))
    mx.fit({'train': input_path})

    local_mode_utils.assert_output_files_exist(str(tmpdir), 'model', ['model.onnx'])
Пример #4
0
def test_keras_training(docker_image, sagemaker_local_session, local_instance_type,
                        framework_version, tmpdir):
    keras_path = os.path.join(RESOURCE_PATH, 'keras')
    script_path = os.path.join(keras_path, 'keras_mnist.py')

    mx = MXNet(entry_point=script_path, role='SageMakerRole', train_instance_count=1,
               train_instance_type=local_instance_type, sagemaker_session=sagemaker_local_session,
               image_name=docker_image, framework_version=framework_version,
               output_path='file://{}'.format(tmpdir))

    train = 'file://{}'.format(os.path.join(keras_path, 'data'))
    mx.fit({'train': train})

    for directory, files in MODEL_SUCCESS_FILES.items():
        local_mode_utils.assert_output_files_exist(str(tmpdir), directory, files)
Пример #5
0
def test_vw_cb_explore(local_instance_type, sagemaker_local_session, docker_image,
                       tmpdir, training_data_bandits, role):
    source_path = os.path.join(RESOURCE_PATH, 'vw')
    estimator = RLEstimator(entry_point="train_cb_explore.py",
                            source_dir=source_path,
                            role=role,
                            train_instance_count=1,
                            hyperparameters={"num_arms": 7},
                            train_instance_type=local_instance_type,
                            sagemaker_session=sagemaker_local_session,
                            output_path='file://{}'.format(tmpdir),
                            image_name=docker_image)
    estimator.fit(inputs=training_data_bandits)

    local_mode_utils.assert_output_files_exist(str(tmpdir), 'output', ['success'])
    local_mode_utils.assert_output_files_exist(str(tmpdir), 'model', ['vw.model', 'vw.metadata'])    
    assert os.path.exists(os.path.join(str(tmpdir), 'model.tar.gz')), 'model file not found'
Пример #6
0
def test_gym(local_instance_type, sagemaker_local_session, docker_image,
             tmpdir, framework):
    source_path = os.path.join(RESOURCE_PATH, 'gym')
    gym_script = 'launcher.sh' if framework == 'tensorflow' else 'gym_envs.py'
    estimator = RLEstimator(entry_point=gym_script,
                            source_dir=source_path,
                            role='SageMakerRole',
                            train_instance_count=1,
                            train_instance_type=local_instance_type,
                            sagemaker_session=sagemaker_local_session,
                            output_path='file://{}'.format(tmpdir),
                            image_name=docker_image)
    estimator.fit()

    local_mode_utils.assert_output_files_exist(str(tmpdir), 'output',
                                               ['success'])
    assert os.path.exists(os.path.join(str(tmpdir),
                                       'model.tar.gz')), 'model file not found'
Пример #7
0
def test_ray_tf(local_instance_type, sagemaker_local_session, docker_image,
                tmpdir):
    source_dir = os.path.join(RESOURCE_PATH, 'ray_cartpole')
    cartpole = 'train_ray.py'

    estimator = RLEstimator(entry_point=cartpole,
                            source_dir=source_dir,
                            role='SageMakerRole',
                            train_instance_count=1,
                            train_instance_type=local_instance_type,
                            sagemaker_session=sagemaker_local_session,
                            output_path='file://{}'.format(tmpdir),
                            image_name=docker_image)

    estimator.fit()

    local_mode_utils.assert_output_files_exist(str(tmpdir), 'output',
                                               ['success'])
    assert os.path.exists(os.path.join(str(tmpdir),
                                       'model.tar.gz')), 'model file not found'
Пример #8
0
def _train_and_assert_success(estimator, output_path):
    estimator.fit({'train': TRAIN_INPUT, 'test': TEST_INPUT})

    for directory, files in MODEL_SUCCESS_FILES.items():
        local_mode_utils.assert_output_files_exist(output_path, directory, files)