# PAI Python SDK
[English](./README_CN.md) \| 简体中文
PAI Python SDK是阿里云 [机器学习平台 PAI(Platform for Artificial Intelligence)](https://www.aliyun.com/product/bigdata/learn) 提供的Python SDK,提供了更易用的HighLevel API,支持机器学习工程师简单地使用Python在PAI完成模型训练和部署,串联机器学习的流程。
## 🔧 安装
使用以下命令安装PAI Python SDK(支持Python版本 \>= 3.8):
```shell
python -m pip install pai
```
## 📖 文档
请通过访问 [PAI Python SDK文档](https://pai.readthedocs.io/) 或是查看 [docs](./docs) 目录下的文件获取SDK的详细文档,包括用户指南和API文档。
## 🛠 使用示例
- 提交自定义训练任务
以下代码演示了如何通过SDK提交一个自定义的训练作业:
```python
from pai.estimator import Estimator
from pai.image import retrieve
est = Estimator(
# 获取PAI提供的最新PyTorch镜像
image_uri=retrieve(
framework_name="PyTorch", framework_version="latest"
).image_uri,
command="echo hello",
# 可选,指定source_dir上传你的训练代码:
# source_dir="./train_src",
instance_type="ecs.c6.large",
)
# 提交训练任务
est.fit()
print(est.model_data())
```
- 部署大语言模型
PAI提供了大量预训练模型,可以使用PAI Python SDK轻松部署:
```python
from pai.model import RegisteredModel
# 获取PAI提供的QWen1.5-7b模型
qwen_model = RegisteredModel("qwen1.5-7b-chat", model_provider="pai")
# 部署模型
p = qwen_model.deploy(service_name="qwen_service")
# 调用服务
p.predict(
data={
"prompt": "What is the purpose of life?",
"system_prompt": "You are helpful assistant.",
"temperature": 0.8,
}
)
# PAI提供的大语言模型支持OpenAI API,可以通过openai SDK调用
openai_client = p.openai()
res = openai_client.chat.completions.create(
model="default",
max_tokens=1024,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the purpose of life?"}
]
)
print(res.choices[0].message.content)
```
更多功能介绍,请参阅 [PAI Python SDK文档](https://alipai.readthedocs.io/) 。
## 🤝 贡献代码
我们欢迎为PAI Python SDK贡献代码。请阅读 [CONTRIBUTING](./CONTRIBUTING.md) 文件了解如何为本项目贡献代码。
## 📝 许可证
PAI Python SDK是由阿里云开发,并根据Apache许可证(版本2.0)授权使用。
## 📬 联系方式
如需支持或咨询,请在GitHub仓库中提交issue,或通过钉钉群联系我们:
<img src="./assets/dingtalk-group.png" alt="DingTalkGroup" width="500"/>
Raw data
{
"_id": null,
"home_page": "https://www.aliyun.com/product/bigdata/product/learn",
"name": "pai",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "ML Alibaba Cloud PAI Training Inference Pipeline",
"author": "Alibaba PAI team",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/5e/06/b9d275c97582ea399eafa4559eb27da64effb052dbd4ca8fc1ba6487fa8b/pai-0.4.9.post0.tar.gz",
"platform": null,
"description": "# PAI Python SDK\n\n[English](./README_CN.md) \\| \u7b80\u4f53\u4e2d\u6587\n\nPAI Python SDK\u662f\u963f\u91cc\u4e91 [\u673a\u5668\u5b66\u4e60\u5e73\u53f0 PAI(Platform for Artificial Intelligence)](https://www.aliyun.com/product/bigdata/learn) \u63d0\u4f9b\u7684Python SDK\uff0c\u63d0\u4f9b\u4e86\u66f4\u6613\u7528\u7684HighLevel API\uff0c\u652f\u6301\u673a\u5668\u5b66\u4e60\u5de5\u7a0b\u5e08\u7b80\u5355\u5730\u4f7f\u7528Python\u5728PAI\u5b8c\u6210\u6a21\u578b\u8bad\u7ec3\u548c\u90e8\u7f72\uff0c\u4e32\u8054\u673a\u5668\u5b66\u4e60\u7684\u6d41\u7a0b\u3002\n\n## \ud83d\udd27 \u5b89\u88c5\n\n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PAI Python SDK\uff08\u652f\u6301Python\u7248\u672c \\>= 3.8\uff09\uff1a\n\n```shell\npython -m pip install pai\n```\n\n## \ud83d\udcd6 \u6587\u6863\n\n\u8bf7\u901a\u8fc7\u8bbf\u95ee [PAI Python SDK\u6587\u6863](https://pai.readthedocs.io/) \u6216\u662f\u67e5\u770b [docs](./docs) \u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u83b7\u53d6SDK\u7684\u8be6\u7ec6\u6587\u6863\uff0c\u5305\u62ec\u7528\u6237\u6307\u5357\u548cAPI\u6587\u6863\u3002\n\n## \ud83d\udee0 \u4f7f\u7528\u793a\u4f8b\n\n- \u63d0\u4ea4\u81ea\u5b9a\u4e49\u8bad\u7ec3\u4efb\u52a1\n\n\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u901a\u8fc7SDK\u63d0\u4ea4\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u8bad\u7ec3\u4f5c\u4e1a:\n\n```python\nfrom pai.estimator import Estimator\nfrom pai.image import retrieve\n\nest = Estimator(\n # \u83b7\u53d6PAI\u63d0\u4f9b\u7684\u6700\u65b0PyTorch\u955c\u50cf\n image_uri=retrieve(\n framework_name=\"PyTorch\", framework_version=\"latest\"\n ).image_uri,\n command=\"echo hello\",\n # \u53ef\u9009\uff0c\u6307\u5b9asource_dir\u4e0a\u4f20\u4f60\u7684\u8bad\u7ec3\u4ee3\u7801\uff1a\n # source_dir=\"./train_src\",\n instance_type=\"ecs.c6.large\",\n)\n# \u63d0\u4ea4\u8bad\u7ec3\u4efb\u52a1\nest.fit()\nprint(est.model_data())\n\n```\n\n- \u90e8\u7f72\u5927\u8bed\u8a00\u6a21\u578b\n\nPAI\u63d0\u4f9b\u4e86\u5927\u91cf\u9884\u8bad\u7ec3\u6a21\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528PAI Python SDK\u8f7b\u677e\u90e8\u7f72\uff1a\n\n```python\nfrom pai.model import RegisteredModel\n\n# \u83b7\u53d6PAI\u63d0\u4f9b\u7684QWen1.5-7b\u6a21\u578b\nqwen_model = RegisteredModel(\"qwen1.5-7b-chat\", model_provider=\"pai\")\n\n# \u90e8\u7f72\u6a21\u578b\np = qwen_model.deploy(service_name=\"qwen_service\")\n\n# \u8c03\u7528\u670d\u52a1\np.predict(\n data={\n \"prompt\": \"What is the purpose of life?\",\n \"system_prompt\": \"You are helpful assistant.\",\n \"temperature\": 0.8,\n }\n)\n\n# PAI\u63d0\u4f9b\u7684\u5927\u8bed\u8a00\u6a21\u578b\u652f\u6301OpenAI API\uff0c\u53ef\u4ee5\u901a\u8fc7openai SDK\u8c03\u7528\nopenai_client = p.openai()\nres = openai_client.chat.completions.create(\n model=\"default\",\n max_tokens=1024,\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n {\"role\": \"user\", \"content\": \"What is the purpose of life?\"}\n ]\n)\nprint(res.choices[0].message.content)\n\n```\n\n\u66f4\u591a\u529f\u80fd\u4ecb\u7ecd\uff0c\u8bf7\u53c2\u9605 [PAI Python SDK\u6587\u6863](https://alipai.readthedocs.io/) \u3002\n\n## \ud83e\udd1d \u8d21\u732e\u4ee3\u7801\n\n\u6211\u4eec\u6b22\u8fce\u4e3aPAI Python SDK\u8d21\u732e\u4ee3\u7801\u3002\u8bf7\u9605\u8bfb [CONTRIBUTING](./CONTRIBUTING.md) \u6587\u4ef6\u4e86\u89e3\u5982\u4f55\u4e3a\u672c\u9879\u76ee\u8d21\u732e\u4ee3\u7801\u3002\n\n## \ud83d\udcdd \u8bb8\u53ef\u8bc1\n\nPAI Python SDK\u662f\u7531\u963f\u91cc\u4e91\u5f00\u53d1\uff0c\u5e76\u6839\u636eApache\u8bb8\u53ef\u8bc1\uff08\u7248\u672c2.0\uff09\u6388\u6743\u4f7f\u7528\u3002\n\n## \ud83d\udcec \u8054\u7cfb\u65b9\u5f0f\n\n\u5982\u9700\u652f\u6301\u6216\u54a8\u8be2\uff0c\u8bf7\u5728GitHub\u4ed3\u5e93\u4e2d\u63d0\u4ea4issue\uff0c\u6216\u901a\u8fc7\u9489\u9489\u7fa4\u8054\u7cfb\u6211\u4eec\uff1a\n\n<img src=\"./assets/dingtalk-group.png\" alt=\"DingTalkGroup\" width=\"500\"/>\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Alibaba Cloud PAI Python SDK",
"version": "0.4.9.post0",
"project_urls": {
"Homepage": "https://www.aliyun.com/product/bigdata/product/learn"
},
"split_keywords": [
"ml",
"alibaba",
"cloud",
"pai",
"training",
"inference",
"pipeline"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "88f5ac3102f3de8e951bd66c6339bcb1ad1729afa111d371d3525ae8f24d954f",
"md5": "b5561f45c73176694b074f1a79abf8d7",
"sha256": "5151ce83e8d4f14b52aa756b23fd92a863e91ae1d7ef0156f8c27edc3f38530d"
},
"downloads": -1,
"filename": "pai-0.4.9.post0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b5561f45c73176694b074f1a79abf8d7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 406956,
"upload_time": "2024-07-18T01:26:30",
"upload_time_iso_8601": "2024-07-18T01:26:30.508849Z",
"url": "https://files.pythonhosted.org/packages/88/f5/ac3102f3de8e951bd66c6339bcb1ad1729afa111d371d3525ae8f24d954f/pai-0.4.9.post0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5e06b9d275c97582ea399eafa4559eb27da64effb052dbd4ca8fc1ba6487fa8b",
"md5": "d414e321f761951197deb9785d11874c",
"sha256": "bfd2c5539cd97266cd3f75cfdbb9a11d066af8cd086de1d538b9ce4766a2144d"
},
"downloads": -1,
"filename": "pai-0.4.9.post0.tar.gz",
"has_sig": false,
"md5_digest": "d414e321f761951197deb9785d11874c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11379760,
"upload_time": "2024-07-18T01:26:32",
"upload_time_iso_8601": "2024-07-18T01:26:32.388623Z",
"url": "https://files.pythonhosted.org/packages/5e/06/b9d275c97582ea399eafa4559eb27da64effb052dbd4ca8fc1ba6487fa8b/pai-0.4.9.post0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-18 01:26:32",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pai"
}