Example #1
0
def test_jumpstart_cache_get_specs():
    cache = JumpStartModelsCache(s3_bucket_name="some_bucket")

    model_id, version = "tensorflow-ic-imagenet-inception-v3-classification-4", "2.0.0"
    assert get_spec_from_base_spec(model_id=model_id, version=version) == cache.get_specs(
        model_id=model_id, semantic_version_str=version
    )

    model_id = "tensorflow-ic-imagenet-inception-v3-classification-4"
    assert get_spec_from_base_spec(model_id=model_id, version="2.0.0") == cache.get_specs(
        model_id=model_id, semantic_version_str="2.0.*"
    )

    model_id, version = "tensorflow-ic-imagenet-inception-v3-classification-4", "1.0.0"
    assert get_spec_from_base_spec(model_id=model_id, version=version) == cache.get_specs(
        model_id=model_id, semantic_version_str=version
    )

    model_id = "pytorch-ic-imagenet-inception-v3-classification-4"
    assert get_spec_from_base_spec(model_id=model_id, version="1.0.0") == cache.get_specs(
        model_id=model_id, semantic_version_str="1.*"
    )

    model_id = "pytorch-ic-imagenet-inception-v3-classification-4"
    assert get_spec_from_base_spec(model_id=model_id, version="1.0.0") == cache.get_specs(
        model_id=model_id, semantic_version_str="1.0.*"
    )

    with pytest.raises(KeyError):
        cache.get_specs(model_id=model_id + "bak", semantic_version_str="*")

    with pytest.raises(KeyError):
        cache.get_specs(model_id=model_id, semantic_version_str="9.*")

    with pytest.raises(KeyError):
        cache.get_specs(model_id=model_id, semantic_version_str="BAD")

    with pytest.raises(KeyError):
        cache.get_specs(
            model_id=model_id,
            semantic_version_str="2.1.*",
        )

    with pytest.raises(KeyError):
        cache.get_specs(
            model_id=model_id,
            semantic_version_str="3.9.*",
        )

    with pytest.raises(KeyError):
        cache.get_specs(
            model_id=model_id,
            semantic_version_str="5.*",
        )
 def add_options_to_hyperparameter(*largs, **kwargs):
     spec = get_spec_from_base_spec(*largs, **kwargs)
     spec.hyperparameters.append(
         JumpStartHyperparameter({
             "name":
             "penalty",
             "type":
             "text",
             "default":
             "l2",
             "options": ["l1", "l2", "elasticnet", "none"],
             "scope":
             "algorithm",
         }))
     return spec
def test_jumpstart_models_cache_get_fxs():

    assert get_header_from_base_header(
        region="us-west-2", model_id="pytorch-ic-mobilenet-v2",
        version="*") == accessors.JumpStartModelsAccessor.get_model_header(
            region="us-west-2",
            model_id="pytorch-ic-mobilenet-v2",
            version="*")
    assert get_spec_from_base_spec(
        region="us-west-2", model_id="pytorch-ic-mobilenet-v2",
        version="*") == accessors.JumpStartModelsAccessor.get_model_specs(
            region="us-west-2",
            model_id="pytorch-ic-mobilenet-v2",
            version="*")

    # necessary because accessors is a static module
    reload(accessors)
 def add_options_to_hyperparameter(*largs, **kwargs):
     spec = get_spec_from_base_spec(*largs, **kwargs)
     spec.hyperparameters.extend([
         JumpStartHyperparameter({
             "name":
             "penalty",
             "type":
             "text",
             "default":
             "l2",
             "options": ["l1", "l2", "elasticnet", "none"],
             "scope":
             "algorithm",
         }),
         JumpStartHyperparameter({
             "name": "test_bool_param",
             "type": "bool",
             "default": True,
             "scope": "algorithm",
         }),
         JumpStartHyperparameter({
             "name": "test_exclusive_min_param",
             "type": "float",
             "default": 4,
             "scope": "algorithm",
             "exclusive_min": 1,
         }),
         JumpStartHyperparameter({
             "name": "test_exclusive_max_param",
             "type": "int",
             "default": -4,
             "scope": "algorithm",
             "exclusive_max": 4,
         }),
         JumpStartHyperparameter({
             "name": "test_exclusive_min_param_text",
             "type": "text",
             "default": "hello",
             "scope": "algorithm",
             "exclusive_min": 1,
         }),
         JumpStartHyperparameter({
             "name": "test_exclusive_max_param_text",
             "type": "text",
             "default": "hello",
             "scope": "algorithm",
             "exclusive_max": 6,
         }),
         JumpStartHyperparameter({
             "name": "test_min_param_text",
             "type": "text",
             "default": "hello",
             "scope": "algorithm",
             "min": 1,
         }),
         JumpStartHyperparameter({
             "name": "test_max_param_text",
             "type": "text",
             "default": "hello",
             "scope": "algorithm",
             "max": 6,
         }),
     ])
     return spec
Example #5
0
 def make_deprecated_spec(*largs, **kwargs):
     spec = get_spec_from_base_spec(*largs, **kwargs)
     spec.deprecated = True
     return spec
Example #6
0
 def make_vulnerable_training_spec(*largs, **kwargs):
     spec = get_spec_from_base_spec(*largs, **kwargs)
     spec.training_vulnerable = True
     spec.training_vulnerabilities = ["some", "vulnerability"]
     return spec
Example #7
0
 def make_vulnerable_inference_spec(*largs, **kwargs):
     spec = get_spec_from_base_spec(*largs, **kwargs)
     spec.inference_vulnerable = True
     spec.inference_vulnerabilities = ["some", "vulnerability"]
     return spec