You can create a custom algorithm component for specific scenarios. After you create a custom component, you can use the component in Machine Learning Designer of Platform for AI (PAI) to train models. This topic describes how to create and use a PyTorch-based component in Machine Learning Designer. The code directory of the PyTorch-based component is in an Object Storage Service (OSS) bucket.
Limits
You can run custom components only by using the public resource group of general computing resources in Machine Learning Designer.
Prerequisites
The execution code is uploaded to an OSS bucket. For more information, see Upload objects. In this example, the following sample code is used: main.py and requirements.txt.
Procedure
Create a custom PyTorch-based component.
On the Create Component page, create a PyTorch-based component. For more information, see Create a custom component.
Execution Configuration
Parameter
Description
Job Type
Select PyTorch.
Image
Select Community Image and then select the
pytorch-training:1.12-cpu-py39-ubuntu20.04
image from the drop-down list.Code
Select Mount OSS Path and enter the path of the OSS bucket in which the main.py and requirements.txt files are stored.
Command
Set the command to
python main.py $PAI_USER_ARGS --train $PAI_INPUT_TRAIN --test $PAI_INPUT_TEST --model $PAI_OUTPUT_MODEL --checkpoints $PAI_OUTPUT_CHECKPOINTS && echo "job finished"
.Pipeline and Parameter
Parameter
Description
Input
Click the icon to configure the following input pipelines:
Name: train and test
Source: OSS
Required: Yes and No
Description: training data and test data.
Output
Click the icon to configure the following output pipelines:
Name: model and checkpoints
Storage: OSS
Required: Yes
Description: model data and algorithm checkpoints
Parameter
Click the icon to configure the following parameters:
Parameter Name: param1, param2, param3, param4, and param5
Type: Int, Float, String, Bool, and Int
Default Value: 6, 0.3, test1, true, and 2
Constraint: Click Constraint on the right of the Default Value parameter to configure constraints based on on-screen instructions for each parameter.
Required: Yes, Yes, Yes, No, and No
Constraints
Parameter
Description
Enable Constraints
Turn on Enable Constraints.
Instance Type
Select CPU and GPU.
Multiple Instances
Select Supported.
Multiple GPUs
Select Not Supported.
Create a blank pipeline and go to the pipeline page. For more information, see Create a blank pipeline.
In this example, the component name component is used. You can drag the component from the left-side component list to the canvas and use the component in the same manner as you use the built-in components in Machine Learning Designer.
After you create a custom component, the component is displayed in the algorithm tree in Machine Learning Designer of the current workspace.
The input and output pipelines that you configured for the custom component are used as the input and output ports of the component.
The parameters that you configured for the custom component are used as the parameters of the component and are displayed in the right-side configuration pane.
You can select an OSS path as the output path for each output port.
The constraints that you configured for the custom component are used as parameters on the Tuning tab of the configuration pane.
If the custom component does not meet your business requirements, you can update the configuration of the custom component or add a component version on the Custom Components page. For more information, see Manage custom components.