Exemplo n.º 1
0
def deploy_model(action, model_name, default_model_uri, canary_model_uri, canary_model_traffic, namespace, framework, default_custom_model_spec, canary_custom_model_spec, autoscaling_target=0):
    if int(autoscaling_target) != 0:
        annotations = {"autoscaling.knative.dev/target": str(autoscaling_target)}
    else:
        annotations = None
    metadata = client.V1ObjectMeta(name=model_name, namespace=namespace, annotations=annotations)
    if framework != 'custom':
        default_model_spec = ModelSpec(framework, default_model_uri)
    else:
        default_model_spec = customModelSpec(default_custom_model_spec)
    # Create Canary deployment if canary model uri is provided.
    if framework != 'custom' and canary_model_uri:
        canary_model_spec = ModelSpec(framework, canary_model_uri)
        kfsvc = kfserving_deployment(metadata, default_model_spec, canary_model_spec, canary_model_traffic)
    elif framework == 'custom' and canary_custom_model_spec:
        canary_model_spec = customModelSpec(canary_custom_model_spec)
        kfsvc = kfserving_deployment(metadata, default_model_spec, canary_model_spec, canary_model_traffic)
    else:
        kfsvc = kfserving_deployment(metadata, default_model_spec)

    KFServing = KFServingClient()

    if action == 'create':
        KFServing.create(kfsvc)
    elif action == 'update':
        KFServing.patch(model_name, kfsvc)
    elif action == 'delete':
        KFServing.delete(model_name, namespace=namespace)
    else:
        raise("Error: No matching action: " + action)

    model_status = KFServing.get(model_name, namespace=namespace)
    return model_status
Exemplo n.º 2
0
def deploy_model(action,
                 model_name,
                 default_model_uri,
                 canary_model_uri,
                 canary_model_traffic,
                 namespace,
                 framework,
                 default_custom_model_spec,
                 canary_custom_model_spec,
                 autoscaling_target=0):
    if int(autoscaling_target) != 0:
        annotations = {
            "autoscaling.knative.dev/target": str(autoscaling_target)
        }
    else:
        annotations = None
    metadata = client.V1ObjectMeta(name=model_name,
                                   namespace=namespace,
                                   annotations=annotations)

    # Create Default deployment if default model uri is provided.
    if framework != 'custom' and default_model_uri:
        default_model_spec = EndpointSpec(framework, default_model_uri)
    elif framework == 'custom' and default_custom_model_spec:
        default_model_spec = customEndpointSpec(default_custom_model_spec)

    # Create Canary deployment if canary model uri is provided.
    if framework != 'custom' and canary_model_uri:
        canary_model_spec = EndpointSpec(framework, canary_model_uri)
        kfsvc = InferenceService(metadata, default_model_spec,
                                 canary_model_spec, canary_model_traffic)
    elif framework == 'custom' and canary_custom_model_spec:
        canary_model_spec = customEndpointSpec(canary_custom_model_spec)
        kfsvc = InferenceService(metadata, default_model_spec,
                                 canary_model_spec, canary_model_traffic)
    else:
        kfsvc = InferenceService(metadata, default_model_spec)

    KFServing = KFServingClient()

    if action == 'create':
        KFServing.create(kfsvc, watch=True, timeout_seconds=120)
    elif action == 'update':
        KFServing.patch(model_name, kfsvc)
    elif action == 'rollout':
        KFServing.rollout_canary(model_name,
                                 canary=canary_model_spec,
                                 percent=canary_model_traffic,
                                 namespace=namespace,
                                 watch=True,
                                 timeout_seconds=120)
    elif action == 'promote':
        KFServing.promote(model_name,
                          namespace=namespace,
                          watch=True,
                          timeout_seconds=120)
    elif action == 'delete':
        KFServing.delete(model_name, namespace=namespace)
    else:
        raise ("Error: No matching action: " + action)

    model_status = KFServing.get(model_name, namespace=namespace)
    return model_status
Exemplo n.º 3
0
    # Create Canary deployment if canary model uri is provided.
    if framework != 'custom' and canary_model_uri:
        canary_model_spec = ModelSpec(framework, canary_model_uri)
        kfsvc = kfserving_deployment(metadata, default_model_spec,
                                     canary_model_spec, canary_model_traffic)
    elif framework == 'custom' and canary_custom_model_spec:
        canary_model_spec = customModelSpec(canary_custom_model_spec)
        kfsvc = kfserving_deployment(metadata, default_model_spec,
                                     canary_model_spec, canary_model_traffic)
    else:
        kfsvc = kfserving_deployment(metadata, default_model_spec)

    KFServing = KFServingClient()

    if action == 'create':
        KFServing.create(kfsvc)
    elif action == 'update':
        KFServing.patch(model_name, kfsvc)
    elif action == 'delete':
        KFServing.delete(model_name, namespace=namespace)
    else:
        raise ("Error: No matching action: " + action)

    model_status = KFServing.get(model_name, namespace=namespace)
    print(model_status)

    if not os.path.exists(os.path.dirname(output_path)):
        os.makedirs(os.path.dirname(output_path))
    with open(output_path, "w") as report:
        report.write(json.dumps(model_status))