0 / 0
Decision Optimization REST API changing Python version in deployed model

Changing Python version for an existing deployed model with the REST API

You can update an existing Decision Optimization model using the Watson Machine Learning REST API. This can be useful, for example, if in your model you have explicitly specified a Python version that has now become deprecated.

Before you begin

You will need your SPACE-ID, MODEL-ID and DEPLOYMENT-ID to make this change. See REST API example for more details.

About this task

The following steps show you how to update an existing Decision Optimization deployed model using the Watson Machine Learning REST API. The REST API example uses curl, a command line tool and library for transferring data with URL syntax. You can download curl and read more about it at http://curl.haxx.se.

For Windows users, use ^ instead of \ for the multi-line separator and double quotation marks " throughout these code examples. Windows users also need to use indentation of at least one character space in the header lines.

For clarity, some code examples in this procedure have been placed in a json file to make the commands more readable and easier to use.

Procedure

To change Python version for an existing deployed model:

  1. Create a revision to your Decision Optimization model

    All API requests require a version parameter that takes a date in the format version=YYYY-MM-DD. This code example posts a model that uses the file update_model.json. The URL will vary according to the chosen region/location for your machine learning service.

    curl --location --request POST \
      "https://us-south.ml.cloud.ibm.com/ml/v4/models/MODEL-ID-HERE/revisions?version=2021-12-01" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @revise_model.json
    The revise_model.json file contains the following code:
    {
      "commit_message": "Save current model",
      "space_id": "SPACE-ID-HERE"
    }
    Note the model revision number "rev" that is provided in the output for use in the next step.
  2. Update an existing deployment so that current jobs will not be impacted:
    curl --location --request PATCH \
      "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2021-12-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @revise_deploy.json
    The revise_deploy.json file contains the following code:
    [
      {
      "op": "add",
      "path": "/asset",
      "value": {
        "id":"MODEL-ID-HERE",
        "rev":"MODEL-REVISION-NUMBER-HERE"
       }
      }
    ]
  3. Patch an existing model to explicitly specify Python version 3.11
    curl --location --request PATCH \
      "https://us-south.ml.cloud.ibm.com/ml/v4/models/MODEL-ID-HERE?rev=MODEL-REVISION-NUMBER-HERE&version=2021-12-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @update_model.json
    The update_model.json file, with the default Python version stated explicitly, contains the following code:
    [
     {
     "op": "add",
     "path": "/custom",
     "value": {
       "decision_optimization":{
          "oaas.docplex.python": "3.11"
         }
       }
     }
    ]
    Alternatively, to remove any explicit mention of a Python version so that the default version will always be used:
    [
     {
     "op": "remove",
     "path": "/custom/decision_optimization"
     }
    ]
  4. Patch the deployment to use the model that was created for Python to use version 3.11
    curl --location --request PATCH \
      "https://us-south.ml.cloud.ibm.com/ml/v4/deployments/DEPLOYMENT-ID-HERE?version=2021-12-01&space_id=SPACE-ID-HERE" \
      -H "Authorization: bearer TOKEN-HERE" \
      -H "Content-Type: application/json" \
      -d @update_deploy.json
    The update_deploy.json file contains the following code:
    [
     {
       "op": "add",
       "path": "/asset",
       "value": { "id":"MODEL-ID-HERE"}
     }
    ]

Results

You can post new jobs using the DEPLOYMENT-ID without having to redeploy your model.

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more