wx-ai training create

Creates a watsonx.ai™ training in a project or a space.

Syntax

cpdctl wx-ai training create \
[--auto-update-model AUTO-UPDATE-MODEL] \
[--custom CUSTOM] \
[--description DESCRIPTION] \
--name NAME \
[--project-id PROJECT-ID] \
[--prompt-tuning PROMPT-TUNING | --prompt-tuning-base-model PROMPT-TUNING-BASE-MODEL] \
--prompt-tuning-accumulate-steps PROMPT-TUNING-ACCUMULATE-STEPS \
--prompt-tuning-batch-size PROMPT-TUNING-BATCH-SIZE \
--prompt-tuning-init-method PROMPT-TUNING-INIT-METHOD \
[-prompt-tuning-init-text PROMPT-TUNING-INIT-TEXT] \
--prompt-tuning-learning-rate PROMPT-TUNING-LEARNING-RATE \
--prompt-tuning-max-input-tokens PROMPT-TUNING-MAX-INPUT-TOKENS \
--prompt-tuning-max-output-tokens PROMPT-TUNING-MAX-OUTPUT-TOKENS \
--prompt-tuning-num-epochs PROMPT-TUNING-NUM-EPOCHS \
--prompt-tuning-task-id PROMPT-TUNING-TASK-ID \
--prompt-tuning-tuning-type PROMPT-TUNING-TUNING-TYPE \
--prompt-tuning-verbalizer PROMPT-TUNING-VERBALIZER \
[--results-reference RESULTS-REFERENCE | --results-reference-id RESULTS-REFERENCE-ID] \
--results-reference-connection RESULTS-REFERENCE-CONNECTION \
[--results-reference-location RESULTS-REFERENCE-LOCATION] \
--results-reference-type RESULTS-REFERENCE-TYPE \
[--space-id SPACE-ID] \
[--tags TAGS] \
[--training-data-references TRAINING-DATA-REFERENCES]

Extended description

To deploy the tuned model, follow these steps:

  1. Provide the details of the base model and parameters for the training in the prompt_tuning object.
  2. Create a WML model asset, in a space or a project, by providing a request.json that is similar to the following example.
    curl -X POST "https://{cpd_cluster}/ml/v4/models?version=2024-01-29" \
      -H "Authorization: Bearer <replace with your token>" \
      -H "content-type: application/json" \
      --data '{
         "name": "replace_with_a_meaningful_name",
         "space_id": "replace_with_your_space_id",
         "type": "prompt_tune_1.0",
         "software_spec": {
           "name": "watsonx-textgen-fm-1.0"
         },
         "metrics": [ from the training job ],
         "training": {
           "id": "05859469-b25b-420e-aefe-4a5cb6b595eb",
           "base_model": {
             "model_id": "google/flan-t5-xl"
           },
           "task_id": "generation",
           "verbalizer": "Input: {{input}} Output:"
         },
         "training_data_references": [
           {
             "connection": {
               "id": "20933468-7e8a-4706-bc90-f0a09332b263"
             },
             "id": "file_to_tune1.json",
             "location": {
               "bucket": "wxproject-donotdelete-pr-xeyivy0rx3vrbl",
               "path": "file_to_tune1.json"
             },
             "type": "connection_asset"
           }
         ]
       }'
    Note:
    • If you used the training request field auto_update_model: true, then you can skip this step because the model was saved at the end of the training job.
    • You can use the generated request.json that was stored in the results_reference field, instead of creating the payload for the model. Look for the path in the field entity.results_reference.location.model_request_path.
    • The model type must be prompt_tune_1.0.
    • The software spec name must be watsonx-textgen-fm-1.0.
  3. Create a tuned model deployment as described in wx-ai deployment create.

Options

Table 1: Command options
Option Description
--auto-update-model (Boolean)

If this option is set to true, the result of the training is uploaded to the repository as a model if it is successful.

The default value is false.

--custom (generic map)

User-defined properties that are specified as key-value pairs.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @. For example, --custom=@path/to/file.json.

--description (string)

A description of the training.

--name (string)

The name of the training. Required.

--project-id (string)

The project that contains the resource. Either space_id or project_id must be given.

The maximum length is 36 characters. The minimum length is 36 characters. The value must match the regular expression /[a-zA-Z0-9-]*/.

--prompt-tuning

Properties to control the prompt tuning. This JSON option can instead be provided by setting individual fields with other options. It is mutually exclusive with those options.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --prompt-tuning=@path/to/file.json.

--prompt-tuning-accumulate-steps (int64)

Number of steps to be used for gradient accumulation. Gradient accumulation refers to a method of collecting gradient for configured number of steps instead of updating the model variables at every step and then applying the update to model variables. Use this option to overcome smaller batch size limitations. Often also referred with "effective batch size". This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 16. The maximum value is 128. The minimum value is 1.

--prompt-tuning-base-model

The model ID of the base model for this prompt tuning. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --prompt-tuning-base-model=@path/to/file.json.

--prompt-tuning-batch-size (int64)

The batch size is a number of samples that are processed before the model is updated. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 16. The maximum value is 16. The minimum value is 1.

--prompt-tuning-init-method (string)

The text method requires init_text to be set. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is random. Allowable values are random, text.

--prompt-tuning-init-text (string)

Initialization text to use if init_method is set to text. Otherwise, this option is ignored. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

--prompt-tuning-learning-rate (float64)

Learning rate to be used while tuning prompt vectors. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 0.3. The maximum value is 0.5. The minimum value is 0.01.

--prompt-tuning-max-input-tokens (int64)

The maximum length of input tokens that is considered. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 256. The maximum value is 256. The minimum value is 1.

--prompt-tuning-max-output-tokens (int64)

The maximum length of output tokens that are predicted. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 128. The maximum value is 128. The minimum value is 1.

--prompt-tuning-num-epochs (int64)

The number of epochs to tune the prompt vectors, which affect the quality of the trained model. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is 20. The maximum value is 50. The minimum value is 1.

--prompt-tuning-task-id (string)

The task that is targeted for this model. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

--prompt-tuning-tuning-type (string)

Type of Peft (Parameter-Efficient Fine-Tuning) config to build. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is prompt_tuning. Allowable values are prompt_tuning.

--prompt-tuning-verbalizer (string)

A verbalizer template to be used for formatting data at train and inference time. This template can use brackets to indicate where fields from the data model must be rendered. This option provides a value for a sub-field of the JSON option 'prompt-tuning'. It is mutually exclusive with that option.

The default value is Input: {{input}} Output:.

--results-reference

The training results. This option is specified as type=container, which means that it is stored in the space or project. This JSON option can instead be provided by setting individual fields with other options. It is mutually exclusive with those options.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --results-reference=@path/to/file.json.

--results-reference-connection

This option contains a set of fields specific to each connection. This option provides a value for a sub-field of the JSON option 'results-reference'. It is mutually exclusive with that option.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --results-reference-connection=@path/to/file.json.

--results-reference-id (string)

Item identification inside a collection. This option provides a value for a sub-field of the JSON option 'results-reference'. It is mutually exclusive with that option.

--results-reference-location (string)

This option contains a set of fields that describe the location of the data for the connection. This option provides a value for a sub-field of the JSON option 'results-reference'. It is mutually exclusive with that option.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --results-reference-location=@path/to/file.json.

--results-reference-type (string)

The data source type like connection_asset or data_asset. This option provides a value for a sub-field of the JSON option 'results-reference'. It is mutually exclusive with that option.

Allowable values are connection_asset, data_asset, container, url.

--space-id (string)

The space that contains the resource. Either space_id or project_id must be given.

The maximum length is 36 characters. The minimum length is 36 characters. The value must match the regular expression /[a-zA-Z0-9-]*/.

--tags (string)

A list of tags for this resource.

--training-data-references

Training datasets.

Provide a JSON string option or specify a JSON file to read from by providing a file path option that begins with a @, for example --training-data-references=@path/to/file.json.


[ {
  "id" : "tune1_data.json",
  "type" : "container",
  "connection" : { },
  "location" : { },
  "schema" : {
    "id" : "t1",
    "name" : "Tasks",
    "fields" : [ {
      "anyKey" : "anyValue"
    }, {
      "anotherAnyKey" : "anotherAnyValue"
    } ],
    "type" : "struct"
  }
} ]
s

Examples

cpdctl wx-ai training create \
    --name my-prompt-tune-training \
    --results-reference '{"id": "exampleString", "type": "container", "connection": {}, "location": {}}' \
    --space-id exampleString \
    --project-id 12ac4cf1-252f-424b-b52d-5cdd9814987f \
    --description exampleString \
    --tags exampleString,anotherTestString \
    --prompt-tuning '{"base_model": {"model_id": "google/flan-t5-xl"}, "task_id": "classification", "tuning_type": "prompt_tuning", "num_epochs": 30, "learning_rate": 0.4, "accumulate_steps": 3, "verbalizer": "rte { 0 : entailment, 1 : not entailment } {{input}}", "batch_size": 10, "max_input_tokens": 100, "max_output_tokens": 100, "init_method": "text", "init_text": "exampleString"}' \
    --training-data-references '[{"id": "tune1_data.json", "type": "container", "connection": {}, "location": {}, "schema": {"id": "t1", "name": "Tasks", "fields": [{"anyKey": "anyValue"},{"anotherAnyKey": "anotherAnyValue"}], "type": "struct"}}]' \
    --custom '{"anyKey": "anyValue"}' \
    --auto-update-model true

Alternatively, granular options are available for the sub-fields of JSON string options.

cpdctl wx-ai training create \
    --name my-prompt-tune-training \
    --space-id exampleString \
    --project-id 12ac4cf1-252f-424b-b52d-5cdd9814987f \
    --description exampleString \
    --tags exampleString,anotherTestString \
    --training-data-references '[dataConnectionReference]' \
    --custom '{"anyKey": "anyValue"}' \
    --auto-update-model true \
    --results-reference-id exampleString \
    --results-reference-type connection_asset \
    --results-reference-connection dataConnection \
    --results-reference-location '{}' \
    --prompt-tuning-base-model baseModel \
    --prompt-tuning-task-id summarization \
    --prompt-tuning-tuning-type prompt_tuning \
    --prompt-tuning-num-epochs 30 \
    --prompt-tuning-learning-rate 0.4 \
    --prompt-tuning-accumulate-steps 32 \
    --prompt-tuning-verbalizer 'rte { 0 : entailment, 1 : not entailment } {{input}}' \
    --prompt-tuning-batch-size 10 \
    --prompt-tuning-max-input-tokens 100 \
    --prompt-tuning-max-output-tokens 100 \
    --prompt-tuning-init-method text \
    --prompt-tuning-init-text exampleString

Example output

{
  "metadata" : {
    "id" : "6213cf1-252f-424b-b52d-5cdd9814956c",
    "name" : "my-prompt-training",
    "project_id" : "12ac4cf1-252f-424b-b52d-5cdd9814987f",
    "created_at" : "2023-08-04T13:22:47.000Z"
  },
  "entity" : {
    "prompt_tuning" : {
      "base_model" : {
        "model_id" : "google/flan-t5-xl"
      },
      "task_id" : "classification"
    },
    "training_data_references" : [ {
      "id" : "tune1_data.json",
      "location" : {
        "path" : "tune1_data.json"
      },
      "type" : "container"
    } ],
    "auto_update_model" : true,
    "results_reference" : {
      "location" : {
        "path" : "tune1/results",
        "training" : "tune1/results/360c40f7-ac0c-43ca-a95f-1a5421f93b82",
        "training_status" : "tune1/results/360c40f7-ac0c-43ca-a95f-1a5421f93b82/training-status.json",
        "assets_path" : "tune1/results/360c40f7-ac0c-43ca-a95f-1a5421f93b82/assets",
        "model_request_path" : "tune1/results/360c40f7-ac0c-43ca-a95f-1a5421f93b82/assets/c29e7544-dfd0-4427-bc66-20fa6023e2e0/resources/wml_model/request.json"
      },
      "type" : "container"
    },
    "status" : {
      "state" : "completed",
      "running_at" : "2023-08-04T13:22:48.000Z",
      "completed_at" : "2023-08-04T13:22:55.289Z",
      "metrics" : [ {
        "iteration" : 0,
        "ml_metrics" : {
          "loss" : 4.49988
        },
        "timestamp" : "2023-09-22T02:52:03.324Z"
      }, {
        "iteration" : 1,
        "ml_metrics" : {
          "loss" : 3.86884
        },
        "timestamp" : "2023-09-22T02:52:03.689Z"
      }, {
        "iteration" : 2,
        "ml_metrics" : {
          "loss" : 4.05115
        },
        "timestamp" : "2023-09-22T02:52:04.053Z"
      } ]
    }
  }
}