All Products
Search
Document Center

Platform For AI:Notebook

Last Updated:Apr 02, 2026

The Notebook component in Machine Learning Designer lets you write, debug, and run code directly inside a pipeline without interrupting the pipeline's context or state. It integrates with Data Science Workshop (DSW) instances for interactive development, and converts Notebook files into Deep Learning Containers (DLC) jobs for production runs.

How it works

The Notebook component supports two modes:

Mode When to use Resource charged
Development Interactively write and debug code in a DSW instance attached to the pipeline DSW instance running duration
Running Execute the Notebook as part of a pipeline run or scheduled job DLC job running duration

In Development mode, start a DSW instance from the Notebook node. The instance automatically loads output data and state from upstream components, so you can inspect upstream results, develop logic, and pass results downstream — all without leaving the pipeline canvas.

In Running mode, triggering the pipeline (manually or via a DataWorks schedule) starts a DLC job that runs the Notebook file converted by Jupyter nbconvert.

Important

If you use a pay-as-you-go resource group, charges apply based on running duration. See Billing of DSW and Billing of DLC.

Component description

The Notebook component has four input ports and four output ports:

Port Direction Storage type Names
Input In OSS or MaxCompute table input1, input2, input3, input4
Output (OSS) Out OSS output1, output2
Output (MaxCompute) Out MaxCompute table output3, output4

Use the pai-notebook-utils package to access port configurations and custom parameters from within the Notebook.

Install pai-notebook-utils

Run the following command in your Notebook or Init Command:

pip install --upgrade https://pai-sdk.oss-cn-shanghai.aliyuncs.com/pai_notebook_utils/dist/pai_notebook_utils-0.0.1-py2.py3-none-any.whl

Access ports and parameters

All three functions are available through the NotebookUtils class:

from pai_notebook.utils.notebook_utils import NotebookUtils

node_inputs = NotebookUtils.get_inputs()      # list of input port configs
node_outputs = NotebookUtils.get_outputs()    # list of output port configs
custom_params = NotebookUtils.get_custom_params()  # dict of custom parameters

Input ports

get_inputs() returns a list. Each item contains:

Field Description
name Port name: input1, input2, input3, or input4
type Port type, such as DataSet or Model
location_type Storage type: MaxComputeTable or OSS
value Port configuration as a MAP

MaxCompute table inputlocation_type is MaxComputeTable; value contains project, table, and endpoint:

from pai_notebook.utils.notebook_utils import NotebookUtils

node_inputs = NotebookUtils.get_inputs()

for node_input in node_inputs:
    if node_input.location_type == "MaxComputeTable":
        input_name = node_input.name
        table_name = node_input.value["table"]
        project = node_input.value["project"]
        endpoint = node_input.value["endpoint"]
        print(f"input_name: {input_name}, project: {project}, table_name: {table_name}, endpoint: {endpoint}")

OSS inputlocation_type is OSS; the OSS path is mounted to a local path. value contains key, bucket, endpoint, and mountPath:

from pai_notebook.utils.notebook_utils import NotebookUtils

node_inputs = NotebookUtils.get_inputs()

for node_input in node_inputs:
    if node_input.location_type == "OSS":
        input_name = node_input.name
        key = node_input.value["key"]
        bucket = node_input.value["bucket"]
        endpoint = node_input.value["endpoint"]
        mount_path = node_input.value["mountPath"]
        print(f"input_name: {input_name}, bucket: {bucket}, key: {key}, endpoint: {endpoint}, mount path: {mount_path}")
Important

If the OSS path changes after the DSW instance starts, mountPath becomes unavailable. Restart the DSW instance to remount the new path.

Output ports

get_outputs() returns a list. Each item contains:

Field Description
name Port name: output1, output2, output3, or output4
location_type Storage type: MaxComputeTable or OSS
value Port configuration as a MAP (same field structure as input ports)
  • OSS outputs (output1, output2): data is written to the configured OSS path. If Job Output Path is not set, the path is auto-generated from the global default path. The OSS directory is mounted to /ml/output/ in the job container: output1 maps to /ml/output/output1/, and output2 maps to /ml/output/output2/. The Notebook run result (HTML) is saved to /ml/output/result/.

  • MaxCompute outputs (output3, output4): the workspace must be associated with a MaxCompute compute engine.

from pai_notebook.utils.notebook_utils import NotebookUtils

node_outputs = NotebookUtils.get_outputs()

for node_output in node_outputs:
    output_name = node_output.name
    if node_output.location_type == "MaxComputeTable":
        table_name = node_output.value["table"]
        project = node_output.value["project"]
        endpoint = node_output.value["endpoint"]
        print(f"output_name: {output_name}, project: {project}, table_name: {table_name}, endpoint: {endpoint}")
    elif node_output.location_type == "OSS":
        key = node_output.value["key"]
        bucket = node_output.value["bucket"]
        endpoint = node_output.value["endpoint"]
        mount_path = node_output.value["mountPath"]
        print(f"output_name: {output_name}, bucket: {bucket}, key: {key}, endpoint: {endpoint}, mount path: {mount_path}")
    else:
        print(json.dumps(node_output.value, indent=4))

Custom parameters

Configure custom parameters as key-value pairs in the Notebook node. Reference global variables using the ${globalParamName} format. For example, set a parameter key to modelVersion and its value to ${globalModelVersion}. At runtime, get_custom_params() returns the resolved value:

from pai_notebook.utils.notebook_utils import NotebookUtils

custom_params = NotebookUtils.get_custom_params()
print(custom_params)
# Example output: {'modelVersion': '2.1.0', 'batchSize': '32'}

Custom parameters are in the key-value pair format and can be shared by a pipeline and a DSW instance, which facilitates parameter modification.

Notebook configuration

Add the Notebook component to a pipeline in Machine Learning Designer, then configure the following parameters in the right panel.

Important

Before starting a DSW instance, configure the Pipeline Data Path when creating the pipeline. The Notebook File path is generated from this setting.

Category Parameter Required Description Default
Notebook Config DSW Instance No Status and start control for the DSW instance attached to this node Not Running
Notebook File Yes Path to the Notebook file, in the format <pipeline data path>/notebook/${pipeline ID}/${node ID}/main.ipynb. Find the pipeline ID on the Pipeline Attributes tab; the node ID is system-generated. <pipeline data path>/notebook/${pipeline ID}/${node ID}/main.ipynb
Job Output Path No OSS directory mounted to /ml/output/ in the job container. Output ports write to subdirectories (output1/, output2/); run results are saved to result/ in HTML. Pipeline data path
Custom Parameters No Key-value pairs shared by the pipeline and DSW instance. Reference global variables using ${globalParamName}. None
Init Command No Shell command to run before executing the Notebook, such as pip install pandas. None
Automatic shutdown time No DSW instance shuts down automatically after this duration to prevent runaway charges. 1 hour
Run Config Select Resource Group Public Resource Group No Configure Node Type (CPU/GPU), VPC Settings, Security Group, vSwitch, Internet Access Gateway, and Node Image. Default ECS type: ecs.c6.large.
Dedicated resource group No Configure vCPUs, memory, shared memory, GPUs, and number of instances. None
Node Image No Official image, custom image, or a public image address. Official

What's next