def test_init_required_named(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session, **ALL_REQ_ARGS)

    assert ipinsights.role == COMMON_TRAIN_ARGS["role"]
    assert ipinsights.instance_count == INSTANCE_COUNT
    assert ipinsights.instance_type == COMMON_TRAIN_ARGS["instance_type"]
    assert ipinsights.num_entity_vectors == NUM_ENTITY_VECTORS
    assert ipinsights.vector_dim == VECTOR_DIM
Ejemplo n.º 2
0
def test_call_fit_none_mini_batch_size(sagemaker_session):
    ipinsights = IPInsights(base_job_name="ipinsights",
                            sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)

    data = RecordSet("s3://{}/{}".format(BUCKET_NAME, PREFIX),
                     num_records=1,
                     feature_dim=FEATURE_DIM,
                     channel='train')
    ipinsights.fit(data)
Ejemplo n.º 3
0
def test_model_image(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)
    data = RecordSet("s3://{}/{}".format(BUCKET_NAME, PREFIX),
                     num_records=1,
                     feature_dim=FEATURE_DIM,
                     channel='train')
    ipinsights.fit(data, MINI_BATCH_SIZE)

    model = ipinsights.create_model()
    assert model.image == registry(REGION, "ipinsights") + '/ipinsights:1'
def test_model_image(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session, **ALL_REQ_ARGS)
    data = RecordSet(
        "s3://{}/{}".format(BUCKET_NAME, PREFIX),
        num_records=1,
        feature_dim=FEATURE_DIM,
        channel="train",
    )
    ipinsights.fit(data, MINI_BATCH_SIZE)

    model = ipinsights.create_model()
    assert image_uris.retrieve("ipinsights", REGION) == model.image_uri
Ejemplo n.º 5
0
def test_init_required_positional(sagemaker_session):
    ipinsights = IPInsights(ROLE,
                            TRAIN_INSTANCE_COUNT,
                            TRAIN_INSTANCE_TYPE,
                            NUM_ENTITY_VECTORS,
                            VECTOR_DIM,
                            sagemaker_session=sagemaker_session)
    assert ipinsights.role == ROLE
    assert ipinsights.train_instance_count == TRAIN_INSTANCE_COUNT
    assert ipinsights.train_instance_type == TRAIN_INSTANCE_TYPE
    assert ipinsights.num_entity_vectors == NUM_ENTITY_VECTORS
    assert ipinsights.vector_dim == VECTOR_DIM
Ejemplo n.º 6
0
def test_predictor_type(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)
    data = RecordSet("s3://{}/{}".format(BUCKET_NAME, PREFIX),
                     num_records=1,
                     feature_dim=FEATURE_DIM,
                     channel='train')
    ipinsights.fit(data, MINI_BATCH_SIZE)
    model = ipinsights.create_model()
    predictor = model.deploy(1, TRAIN_INSTANCE_TYPE)

    assert isinstance(predictor, IPInsightsPredictor)
Ejemplo n.º 7
0
def test_prepare_for_training_wrong_value_upper_mini_batch_size(
        sagemaker_session):
    ipinsights = IPInsights(base_job_name="ipinsights",
                            sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)

    data = RecordSet("s3://{}/{}".format(BUCKET_NAME, PREFIX),
                     num_records=1,
                     feature_dim=FEATURE_DIM,
                     channel='train')
    with pytest.raises(ValueError):
        ipinsights._prepare_for_training(data, 500001)
Ejemplo n.º 8
0
def test_call_fit(base_fit, sagemaker_session):
    ipinsights = IPInsights(base_job_name="ipinsights",
                            sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)

    data = RecordSet("s3://{}/{}".format(BUCKET_NAME, PREFIX),
                     num_records=1,
                     feature_dim=FEATURE_DIM,
                     channel='train')

    ipinsights.fit(data, MINI_BATCH_SIZE)

    base_fit.assert_called_once()
    assert len(base_fit.call_args[0]) == 2
    assert base_fit.call_args[0][0] == data
    assert base_fit.call_args[0][1] == MINI_BATCH_SIZE
Ejemplo n.º 9
0
def test_all_hyperparameters(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session,
                            batch_metrics_publish_interval=100,
                            epochs=10,
                            learning_rate=0.001,
                            num_ip_encoder_layers=3,
                            random_negative_sampling_rate=5,
                            shuffled_negative_sampling_rate=5,
                            weight_decay=5.0,
                            **ALL_REQ_ARGS)
    assert ipinsights.hyperparameters() == dict(
        num_entity_vectors=str(ALL_REQ_ARGS['num_entity_vectors']),
        vector_dim=str(ALL_REQ_ARGS['vector_dim']),
        batch_metrics_publish_interval='100',
        epochs='10',
        learning_rate='0.001',
        num_ip_encoder_layers='3',
        random_negative_sampling_rate='5',
        shuffled_negative_sampling_rate='5',
        weight_decay='5.0')
Ejemplo n.º 10
0
def test_all_hyperparameters(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session,
                            batch_metrics_publish_interval=100,
                            epochs=10,
                            learning_rate=0.001,
                            num_ip_encoder_layers=3,
                            random_negative_sampling_rate=5,
                            shuffled_negative_sampling_rate=5,
                            weight_decay=5.0,
                            **ALL_REQ_ARGS)
    assert ipinsights.hyperparameters() == dict(
        num_entity_vectors=str(ALL_REQ_ARGS["num_entity_vectors"]),
        vector_dim=str(ALL_REQ_ARGS["vector_dim"]),
        batch_metrics_publish_interval="100",
        epochs="10",
        learning_rate="0.001",
        num_ip_encoder_layers="3",
        random_negative_sampling_rate="5",
        shuffled_negative_sampling_rate="5",
        weight_decay="5.0",
    )
def test_predictor_custom_serialization(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session, **ALL_REQ_ARGS)
    data = RecordSet(
        "s3://{}/{}".format(BUCKET_NAME, PREFIX),
        num_records=1,
        feature_dim=FEATURE_DIM,
        channel="train",
    )
    ipinsights.fit(data, MINI_BATCH_SIZE)
    model = ipinsights.create_model()
    custom_serializer = Mock()
    custom_deserializer = Mock()
    predictor = model.deploy(
        1,
        INSTANCE_TYPE,
        serializer=custom_serializer,
        deserializer=custom_deserializer,
    )

    assert isinstance(predictor, IPInsightsPredictor)
    assert predictor.serializer is custom_serializer
    assert predictor.deserializer is custom_deserializer
def test_optional_hyper_parameters_value(sagemaker_session, optional_hyper_parameters, value):
    with pytest.raises(ValueError):
        test_params = ALL_REQ_ARGS.copy()
        test_params.update({optional_hyper_parameters: value})
        IPInsights(sagemaker_session=sagemaker_session, **test_params)
def test_required_hyper_parameters_value(sagemaker_session, required_hyper_parameters, value):
    with pytest.raises(ValueError):
        test_params = ALL_REQ_ARGS.copy()
        test_params[required_hyper_parameters] = value
        IPInsights(sagemaker_session=sagemaker_session, **test_params)
def test_image(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session, **ALL_REQ_ARGS)
    assert image_uris.retrieve("ipinsights", REGION) == ipinsights.training_image_uri()
Ejemplo n.º 15
0
def test_image(sagemaker_session):
    ipinsights = IPInsights(sagemaker_session=sagemaker_session,
                            **ALL_REQ_ARGS)
    assert ipinsights.train_image() == registry(REGION,
                                                "ipinsights") + '/ipinsights:1'