Installation and configuration

Updated at:

Install PAI SDK for Python and configure workspace credentials and region settings to train and deploy models.

PAI SDK for Python is used for model training and deployment and does not support cluster-level resource management, such as starting and stopping instances, quota management, or workspace management. Use the Alibaba Cloud Management Console to manage these resources.

Prerequisites

Installation

Run the following command to install PAI SDK for Python:

pip install "alipai>=0.4.0"

Configuration

Run the following command to launch the configuration wizard:

# Run after SDK installation.
python -m pai.toolkit.config

Configuration example:

$ python -m pai.toolkit.config
Please enter your Alibaba Cloud AccessKeyId: LTAxxx
Please enter your Alibaba Cloud AccessKeySecret: ********************************
Currently configured credentials and region:
AccessKeyId: LTAIxxx
AccessKeySecret: nS0c********************PVLe
RegionId: cn-hangzhou
IdentityType: Account
Cloud service dependency check:
AliyunODPSPAIDefaultRole Authorized
AliyunPAIAccessingOSSRole Authorized
AliyunPAIDLCAccessingOSSRole Authorized
AliyunPAIDLCDefaultRole Authorized
Currently selected workspace information:
WorkspaceName: xxx
WorkspaceId: xxx
Roles: PAI.WorkspaceOwner, PAI.WorkspaceAdmin
Please configure the OSS Bucket to use:
Do you want to use the default OSS Bucket of the current workspace (oss://xxx)? (y/n)

After the configuration succeeds, the following message is displayed: Configuration saved successfully: <Path to which the configurations are saved>.

Configuration parameters

The wizard prompts you to specify the following parameters:

ParameterDescriptionExampleworkspace_idThe ID of your PAI workspace. You can find it on the PAI console.12345region_idThe Alibaba Cloud region where your workspace or Elastic Algorithm Service (EAS) is deployed. Required for cross-region access.us-southeast-1oss_bucket_nameThe name of the OSS bucket used to store code and models.my-pai-bucket

Available regions

The following table lists the supported values for the region_id parameter:

RegionRegion IDChina (Hangzhou)cn-hangzhouChina (Shanghai)cn-shanghaiChina (Beijing)cn-beijingChina (Shenzhen)cn-shenzhenChina (Zhangjiakou)cn-zhangjiakouChina (Hong Kong)cn-hongkongSingaporeap-southeast-1Indonesia (Jakarta)ap-southeast-5US (Silicon Valley)us-west-1US (Virginia)us-east-1US (Atlanta)us-southeast-1Germany (Frankfurt)eu-central-1UK (London)eu-west-1Japan (Tokyo)ap-northeast-1

Cross-region configuration

To deploy EAS services in a region different from your workspace, configure the session programmatically:

from pai.session import Session

# Initialize session with US region
session = Session(
    workspace_id="12345",
    region_id="us-southeast-1",  # EAS service deployed in US region
    oss_bucket_name="my-pai-bucket"
)

# Deploy model to EAS service in us-southeast-1
from pai.model import Model

model = Model(
    model_data="oss://my-pai-bucket/models/my_model/",
    session=session
)

# Deploy with region-specific configuration
predictor = model.deploy(
    service_name="my-service",
    instance_type="ecs.g6.xlarge",
    options={
        "metadata.region": "us-southeast-1"  # Explicit region specification
    }
)

Note: For optimal performance, place your OSS bucket and EAS service in the same region. Cross-region data transfer may incur additional latency and costs.

Next steps

After you complete the configuration, you can start submitting training jobs. For more information, see Submit a training job.