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
You have Create an AccessKey.
You have Create and manage workspaces.
You have Console quick start.
Python 3.8 or later.
RAM users must have the following permissions on the workspace and Object Storage Service (OSS) buckets:
Assign the developer or administrator role to the RAM user for submitting training jobs. For more information, see Manage members of the workspace.
Grant read and write permissions to store code and models in OSS buckets. For more information, see "Grant your RAM user or RAM role the permissions to access OSS" in Grant the permissions that are required to use Machine Learning Designer.
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.configConfiguration example:
$ python -m pai.toolkit.config
请输入您的阿里云账号AccessKeyId: LTAxxx
请输入您的阿里云账号AccessKeySecret: ********************************
当前配置的访问密钥和地域:
AccessKeyId: LTAIxxx
AccessKeySecret: nS0c********************PVLe
RegionId: cn-hangzhou
IdentityType: Account
云产品依赖检查:
AliyunODPSPAIDefaultRole Authorized
AliyunPAIAccessingOSSRole Authorized
AliyunPAIDLCAccessingOSSRole Authorized
AliyunPAIDLCDefaultRole Authorized
当前选择的工作空间信息:
WorkspaceName: xxx
WorkspaceId: xxx
Roles: PAI.WorkspaceOwner, PAI.WorkspaceAdmin
请配置使用的OSS Bucket
是否使用当前工作空间的默认OSS Bucket (oss://xxx) ? (y/nAfter 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.