阿里云派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第三方库


热门话题
如何使用SeleniumWebDriver捕获特定元素的屏幕截图而不是整个页面?   WAS 8.5中的java JAXWS异步IO异常   java Android Studio无法解析数组适配器中的符号项   swing Java在运行时添加和删除按钮   java Spring Boot 2.0。x禁用特定配置文件的安全性   java这是我的最后一个代码,我在“if(Users[B].substring(0,1)==“1”){//Find String Cut Char Function”上遇到错误   单击菜单选项后打开“活动”时发生java错误   java Tic Tac Toe NullPointerException   java如何做数学题。随机进入for循环   java Http状态404错误处理spring mvc   java循环依赖双向@OneToMany JPA关系   java我可以在不重新启动项目的情况下添加servlet吗   java在蓝色/绿色部署中如何管理共享数据库?   这是一个系统。currentTimeMillis()是Java中时间性能的最佳度量?