"...llm/count/git@developer.sourcefind.cn:OpenDAS/dynamo.git" did not exist on "a720fa126b61e02b23afcb47c993c440c08aacd8"
Commit 7c2a90f3 authored by Rayyyyy's avatar Rayyyyy
Browse files

First add

parents
Pipeline #1441 failed with stages
in 0 seconds
# Contributors
This file contains the list of everyone who contributed to the repository
<br>
<table>
<th>Contributors1</th><th>Contributors2</th> <tr>
<td><img src="xxx1">
<br>
<a href="xxx1">xxx1</a></td>
<td><img src="xxx2">
<br>
<a href="xxx2">xxx2</a></td>
</tr>
</table>
<br>
### Thanks to everyone who helped in building this Repository :)
Microsoft.
Copyright (c) Microsoft Corporation.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
# Phi-3
## 论文
`Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phone`
- https://arxiv.org/abs/2404.14219
## 模型结构
基于transformer结构
<div align=center>
<img src="./doc/transformers.jpg" witdh=300 height=400/>
</div>
## 算法原理
Phi-3 模型是目前功能最强大、性价比最高的小型语言模型 (SLM),在各种语言、推理、编码和数学基准测试中,其表现优于同等规模和下一个规模的模型。此版本扩大了客户的高质量模型选择范围,为他们编写和构建生成式 AI 应用程序提供了更多实用选择。
## 环境配置
-v 路径、docker_name和imageID根据实际情况修改
### Docker(方法一)
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
docker run -it --network=host --privileged=true --name=docker_name --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=32G --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro imageID /bin/bash
cd /your_code_path/phi-3_pytorch
pip install -r requirements.txt
```
### Dockerfile(方法二)
```
cd ./docker
docker build --no-cache -t phi-3:latest .
docker run -it --network=host --privileged=true --name=docker_name --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=32G --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro imageID /bin/bash
cd /your_code_path/phi-3_pytorch
pip install -r requirements.txt
```
### Anaconda(方法三)
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
```
DTK驱动:dtk24.04.1
python:3.10
torch:2.1
vllm: 0.3.3
```
`Tips:以上dtk驱动、python等DCU相关工具版本需要严格一一对应`
其它非深度学习库参照requirements.txt安装:
```
pip install -r requirements.txt
```
## 数据集
暂无
## 训练
暂无
## 推理
```bash
# 指定显卡
export HIP_VISIBLE_DEVICE=0
python inference.py --model_path /path/of/model
```
## result
<div align=center>
<img src="./doc/result.png"/>
</div>
### 精度
暂无
## 应用场景
### 算法类别
多轮对话
### 热点应用行业
家居,教育,科研
## 预训练权重
- [Phi-3-mini-4k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-mini-4k-instruct)
- [Phi-3-mini-128k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-mini-128k-instruct)
- [Phi-3-small-8k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-small-8k-instruct)
- [Phi-3-small-128k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-small-128k-instruct)
- [Phi-3-medium-4k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-medium-4k-instruct)
- [Phi-3-medium-128k-instruct](http://113.200.138.88:18080/aimodels/Phi-3-medium-128k-instruct)
## 源码仓库及问题反馈
- https://developer.hpccube.com/codes/modelzoo/phi-3_pytorch
## 参考资料
- https://huggingface.co/collections/microsoft/phi-3-6626e15e9585a200d2d761e3
- https://azure.microsoft.com/en-us/blog/introducing-phi-3-redefining-whats-possible-with-slms/
FROM image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
\ No newline at end of file
icon.png

53.8 KB

import time
import argparse
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
torch.random.manual_seed(0)
def infer_hf(model_path, messages):
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_path)
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 600,
"return_full_text": False,
"temperature": 0.3,
"do_sample": False,
}
start_time = time.time()
output = pipe(messages, **generation_args)
print("total infer time", time.time() - start_time)
print("output", output[0]['generated_text'])
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--model_path', default="/home/checkpoints/Phi-3-mini-128k-instruct/")
args = parser.parse_args()
return args
if __name__ == "__main__":
args = parse_args()
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
]
infer_hf(args.model_path, messages)
# 模型唯一标识
modelCode=834
# 模型名称
modelName=phi-3_pytorch
# 模型描述
modelDescription=Phi-3模型是目前功能最强大、性价比最高的小型语言模型(SLM),在各种语言、推理、编码和数学基准测试中,其表现优于同等规模和下一个规模的模型。
# 应用场景
appScenario=推理,多轮对话,家居,教育,科研
# 框架类型
frameType=pytorch
transformers==4.40.0
accelerate
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment