All Products
Search
Document Center

Platform For AI:Advanced feature: global variable

Last Updated:Feb 08, 2024

When you configure components in Machine Learning Platform for AI (PAI), you can use global variables to reduce the workload of repeat parameter configurations. You can create and delete global variables. You can also use the configuration copy feature to obtain the reference methods of global variables. This topic describes how to configure and use global variables.

Scenarios

Prerequisites

A pipeline is created. For more information, see Overview.

Go to the global variable configuration page

  1. Go to the Visualized Modeling (Designer) page.

    1. Log on to the PAI console.

    2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace in which you want to configure global variables.

    3. In the left-side navigation pane, choose Model Training > Visualized Modeling (Designer) to go to the Visualized Modeling (Designer) page.

  2. On the Pipelines tab, double-click the created pipeline. The configuration tab of the pipeline appears.

  3. On the Global Variables tab in the right-side pane of the canvas, click Add Global Variable and add global variables in sequence. You must specify the name and value for each global variable. Global variables

Example 1: Configure the parameters that are used by all the components in a pipeline

The Heart Disease Prediction pipeline is used in this example. You can use global variables to replace parameter settings when you configure parameters. Global variables can also be used for the components that use the same parameters.

  1. Configure a global variable.

    1. Go to the global variable configuration page.

    2. Set the Variable Name and Variable Value parameters.

      In this example, Variable Name is set to param, and Variable Value is set to cp,fbs. Then, the system automatically generates the ${param} reference method. If you replace a parameter with ${param}, you can reference this variable. Global variable

  2. Use the global variable.

    Replace a parameter with the reference method of the variable to use the variable. The reference method is generated based on the value of the Variable Name parameter for this variable. Use the global variable

  3. Check whether the parameter value is automatically replaced with the value of the variable. Run test

Example 2: Replace scheduling parameters

Global variables can also be used to schedule pipelines associated with dates. In a PAI pipeline, the configured values for global variables can only be used to run the pipeline online. If scheduling is performed offline, the parameter values that you configured for scheduling are used. In this example, the source data of the pipeline contains the data of two partitions. Pipeline

  1. Prepare source data. Prepare source data

  2. Configure a global variable.

    For more information, see Example 1: Configure the parameters that are used by all the components in a pipeline. In this example, Variable Name is set to date, and Variable Value is set to 20190520. Global variable 2

  3. Use the global variable in the SQL Script component. Use a variable

  4. Run the pipeline online to obtain the generated results. Online experiment results

  5. Use the global variable to configure offline scheduling.

    1. Go to the offline scheduling page.

      When you go to the offline scheduling page, you are asked to configure a parameter that has the same name as the global variable that you want to use. Go to the offline scheduling page

    2. Use the global variable in an offline scheduling task. Use the global variable

    3. Run the scheduling task and view the results.

      The scheduling results show that the scheduling task replaces the parameter value with 20190519. Run the scheduling task