阿里云派Python SDK

alibaba-pai的Python项目详细描述


阿里巴巴派Python SDK

阿里派Python SDK由阿里计算平台PAI团队提供。它为用户访问PAI service in Alibaba Cloud提供了方便。在

目前,PAI-SDK支持PAIFlow(PAI的ML-Pipeline-Service)服务,其他PAI服务,如EAS(弹性算法服务)和Blade也将很快加入进来。在

安装

要安装PAI-sdk,请在终端中使用以下命令。在

python -m pip install alipai

使用

设置默认PAI会话

在通过SDK使用PAI服务之前,开发者应该通过提供服务的凭证和region_id来初始化默认的PAI会话。在

Pipeline service of PAI is currently provided in cn-shanghai region only.

^{pr2}$

接入管道服务

使用管道模板

PipelineTemplate实例包含PAI管道服务中使用的“工作流”定义。它可以从远程PAI服务获取,也可以从本地管道/组件构建。在

保存的管道模板具有唯一的pipeline_id,该模板由管道服务生成。可以使用标识符提供程序版本或管道\u id获取远程管道模板

PAI提供了一个公共管道模板的列表,这些模板可以用作运行或构建管道的工作流模板。这些模板可由PipelineTemplate.list中的特定提供者pai.common.ProviderAlibabaPAI访问。在

frompai.pipelineimportPipelineTemplatefrompai.commonimportProviderAlibabaPAI# search PipelineTemplate which provide by `PAI` and include `xflow` in identifier.template=next(PipelineTemplate.list(identifie="xflow",provider=ProviderAlibabaPAI))# view template inputs/outputs.templatetemplate.inputstemplate.outputs

提交运行作业后,用户可以通过访问控制台中打印的作业详细信息URL来查看详细的工作流DAG、执行日志和管道的输出。在

frompai.commonimportProviderAlibabaPAIfrompai.pipelineimportPipelineTemplate# Get specific template by Identifier-Provider-Versiontemplate=PipelineTemplate.get_by_identifier(identifier="split-xflow-maxCompute",provider=ProviderAlibabaPAI,version="v1")xflow_execution={"odpsInfoFile":"/share/base/odpsInfo.ini","endpoint":"http://service.cn-shanghai.maxcompute.aliyun.com/api","logViewHost":"http://logview.odps.aliyun.com","odpsProject":"your_odps_project",}# run pipeline use provide arguments.job=template.run(job_name="demo-split-job",arguments={"inputArtifact":"odps://pai_online_project/tables/mnist_data","execution":xflow_execution,"fraction":0.7},wait=True)job.get_outputs()

构建可运行和可重用的管道

PAI管道服务支持嵌套的用户定义工作流。通过提供所需的参数,可以运行复合管道。保存的管道模板可用作生成新管道的步骤。在

defcreate_composite_pipeline():# Definite the inputs parameters in pipelineexecution_input=PipelineParameter(name="execution",typ=dict)cols_to_double_input=PipelineParameter(name="cols_to_double")table_input=PipelineArtifact(name="data_source",metadata=ArtifactMetadata(data_type=ArtifactDataType.DataSet,location_type=ArtifactLocationType.MaxComputeTable))# Pipeline step from remote PAI service.type_transform_step=PipelineStep(identifier="type-transform-xflow-maxCompute",provider=ProviderAlibabaPAI,version="v1",name="typeTransform",inputs={"inputArtifact":table_input,"execution":execution_input,"outputTable":gen_temp_table(),"cols_to_double":cols_to_double_input,})split_template=PipelineTemplate.get_by_identifier(identifier="split-xflow-maxCompute",provider=ProviderAlibabaPAI,version="v1")split_step=split_template.as_step(inputs={"inputArtifact":type_transform_step.outputs[0],"execution":execution_input,"output1TableName":gen_temp_table(),"fraction":0.5,"output2TableName":gen_temp_table(),})# Initialize the pipeline instance by specific the steps and outputs.   p=Pipeline(steps=[split_step],outputs=split_step.outputs[:2],)returnpp=create_composite_pipeline()# Run pipeline with required arguments.pipeline_run=p.run(job_name="demo-composite-pipeline-run",arguments={"execution":xflow_execution,"cols_to_double":"time,hour,pm2,pm10,so2,co,no2","data_source":"odps://pai_online_project/tables/wumai_data",},wait=True)# Save Pipelinep.save(identifier="demo-composite-pipeline",version="v1")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用MVC设计模式观察嵌套对象   java将多个客户端连接到服务器   合并Java Web应用程序   Spring Security中未捕获java AuthenticationSuccessEvent   java Firebase JSON到Arraylist内部的Arraylist,存在对象问题   在Java15的sealedclasses特性中,final类和非密封类之间有什么区别?   java我可以使用数组。copyOf制作二维数组的防御副本?   java球不会在屏幕上移动   Java类如何在同一个文件中包含两个类?   java使用“Character.isWhiteSpace”删除所有空白   java阻止在RealmList中保存时创建领域对象   如何仅在ConnectionFactory上使用Java JMS身份验证   spring可以强制java对象在运行时实现接口吗?   socket无法在JAVA中使用TCP启用双工模式通信