阿里云派Python SDK

alipai的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第三方库


热门话题
maven字段#getGenericType()抛出java。lang.TypeNotPresentException   用java绘制三角形的几何图形   java无法下载主题和发件人地址(rediff)   java如何使代码线程安全   java在尝试转换FileInputStream中的文件时,我遇到了一个FileNotFound异常   java Moxy和Jackson如何将Json映射到Pojo   在foreach循环中使用BufferedWriter生成新行的java问题   java为什么我的测试在单次执行中运行时间小于1秒,而在maven构建中运行时间大于20秒?   java如何显示下载附件的进度条   了解java rmi的良好实践   .net可以将Java portlet嵌入ASP。网页?   循环如何多次执行Java方法?   java如何确保用户输入在给定的有效范围内?   java单元测试定理   java如何在IntelliJ上运行外部构建项目?   JAVA:试图编写一个检查字符串是否为数字的方法。总是返回错误   javahadoop将特定键的所有map方法生成的所有值都发送到一个reduce方法,对吗?   在java中读取和使用文件