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


热门话题
java后台通知:安卓   java Resultset未返回具有特殊字符/,   等待加载主帧时的java JxBrowser TimeoutException(invokeAndWaitFinishLoadingMainFrame)   java EclipseLink级联持久化异常   JavaMail 1.5.0漏洞还是gmail奇怪的问题?   java循环和IFT语句的装箱   java API不起作用,progressBar一直在旋转   java httpget在“执行”之后不工作   用户界面Java basic GUI程序错误   捕获异常后java代码失败   noclassdeffounderror在一个简单的网络程序中。我正在使用EclipseIDE运行java程序   安卓:java。朗,反思一下。InvocationTargetException有什么建议吗?   java Spring引导未创建数据源   ID为的java RichFaces 4.5 commandLink执行表单   java Struts2:JSP页面无法从数据库获取值   java缓存修改通知?   在java/spring中审计方法变量的最佳方法是什么?