Skip to content

Commit f76291b

Browse files
📝
1 parent 3a8c2e9 commit f76291b

File tree

6 files changed

+156
-48
lines changed

6 files changed

+156
-48
lines changed

docs/docs/机器学习/大语言模型部署/Agent智能体.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 3
2+
sidebar_position: 6
33
title: 🚧Agent智能体
44
---
55

docs/docs/机器学习/大语言模型部署/大语言模型获取.md

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
sidebar_position: 3
3+
title: 🚧提示词工程
4+
---
5+
6+
7+
## 提示词工程
8+
9+
提示工程(Prompt Engineering)是一门较新的学科,关注提示词开发和优化,帮助用户将大语言模型(Large Language Model, LLM)用于各场景和研究领域。 掌握了提示工程相关技能将有助于用户更好地了解大型语言模型的能力和局限性。
10+
11+
推荐文档:[https://www.promptingguide.ai/zh](https://www.promptingguide.ai/zh)
12+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
sidebar_position: 4
3+
title: 🚧模型微调
4+
---
5+
6+
7+
模型微调(Fine-Tuning) 是指在一个预训练的基础模型上,使用特定领域或特定任务的数据进行进一步训练,以使模型能够在特定任务上表现得更好。例如对计算机科学的名词翻译进行微调,可以提高翻译的准确性。
8+
9+
## LLaMA-Factory
10+
11+
项目地址:[https://github.com/hiyouga/LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory)
12+
13+
安装
14+
15+
```bash
16+
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
17+
cd LLaMA-Factory
18+
pip install -e ".[torch,metrics]"
19+
```
20+
21+
启动WebUI
22+
23+
```bash
24+
llamafactory-cli webui
25+
```
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
sidebar_position: 1
3+
title: 🚧模型获取
4+
---
5+
6+
## 开源社区
7+
8+
大模型社区是指围绕大型深度学习模型(如 GPT 系列、BERT、T5 等)构建的开放协作平台和生态系统。这些社区由研究人员、开发者、数据科学家、工程师及爱好者组成,他们共同致力于大模型的研究、开发、优化和应用。
9+
10+
现在模型非常多,各有千秋,且更新迭代非常快。下面的表格列出了部分公司及其z主要大模型代号:
11+
12+
| **公司名称** | **大模型代号** |
13+
| ----------------------------- | ------------------- |
14+
| **OpenAI** | GPT |
15+
| **Meta** | Llama |
16+
| **Anthropic(前 OpenAI 成员)** | Claude |
17+
| **X** | Grok |
18+
| **谷歌** | Gemini |
19+
| **微软** | Phi |
20+
| **百度** | 文心大模型 (Ernie) |
21+
| **阿里巴巴** | 通义千问 (Qwen), M6 |
22+
| **腾讯** | 混元 (Hunyuan) |
23+
| **字节跳动** | 豆包 |
24+
| **华为** | 盘古大模型 (Pangu) |
25+
26+
社区具有明显的马太效应,即头部效应明显,头部模型拥有最多的资源,最新的技术,最多的用户。这里列举两个在国内外有一定影响力的社区。
27+
28+
### Hugging Face
29+
30+
社区地址:[https://huggingface.co/](https://huggingface.co/)
31+
32+
以 Qwen 模型为例,下面展示如何使用 Hugging Face 的 transformers 库进行推理。其中`model_name`为模型地址
33+
34+
```python showLineNumbers
35+
from transformers import AutoModelForCausalLM, AutoTokenizer
36+
37+
model_size = "3B" # 3B 7B 14B 32B
38+
model_name = f"Qwen/Qwen2.5-{model_size}-Instruct"
39+
40+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
41+
tokenizer = AutoTokenizer.from_pretrained(model_name)
42+
43+
while True:
44+
prompt = input("输入你的问题: ")
45+
if prompt == "退出":
46+
break
47+
48+
messages = [
49+
{
50+
"role": "system",
51+
"content": "你是一个AI助手,由阿里巴巴云创建。你是一个乐于助人的助手。你总是以中文回答问题。",
52+
},
53+
{"role": "user", "content": prompt},
54+
]
55+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
56+
model_input = tokenizer([text], return_tensors="pt").to(model.device)
57+
58+
generated_ids = model.generate(**model_input, max_new_tokens=512)
59+
generated_ids = [output[len(input_ids):] for input_ids, output in zip(model_input.input_ids, generated_ids)]
60+
61+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
62+
print(response)
63+
```
64+
65+
### 魔搭社区(阿里达摩院)
66+
67+
社区地址:[https://www.modelscope.cn/](https://www.modelscope.cn/)
68+
69+
除了 Hugging Face 的 transformers 库,魔搭社区还提供了 modelscope 库,基于中国网络环境,可以方便地进行推理。代码基本与 Hugging Face 一致。
70+
71+
```python showLineNumbers
72+
from modelscope import AutoModelForCausalLM, AutoTokenizer
73+
74+
model_size = "0.5B" # 3B 7B 14B 32B
75+
model_name = f"Qwen/Qwen2.5-{model_size}-Instruct"
76+
77+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto", device_map="auto")
78+
tokenizer = AutoTokenizer.from_pretrained(model_name)
79+
80+
while True:
81+
prompt = input("输入你的问题: ")
82+
if prompt == "退出":
83+
break
84+
85+
messages = [
86+
{
87+
"role": "system",
88+
"content": "你是一个AI助手,由阿里巴巴云创建。你是一个乐于助人的助手。你总是以中文回答问题。",
89+
},
90+
{"role": "user", "content": prompt},
91+
]
92+
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
93+
model_input = tokenizer([text], return_tensors="pt").to(model.device)
94+
95+
generated_ids = model.generate(**model_input, max_new_tokens=512)
96+
generated_ids = [output[len(input_ids):] for input_ids, output in zip(model_input.input_ids, generated_ids)]
97+
98+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
99+
print(response)
100+
```
101+
102+
## 商用接口
103+
104+
接口大同小异,这里列举一个国内的接口与一个国外的接口用作示例。
105+
106+
### OpenAI
107+
108+
地址:[https://openai.com/](https://openai.com/)
109+
110+
### 百度
111+
112+
地址:[https://cloud.baidu.com/](https://cloud.baidu.com/)
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
---
2-
sidebar_position: 1
3-
title: 🚧模型微调与部署
2+
sidebar_position: 5
3+
title: 🚧模型部署
44
---
55

6-
## 模型微调
7-
8-
### LLaMA-Factory
9-
10-
## 提示词工程
11-
12-
### Prompt Engineering Guide
13-
14-
[https://www.promptingguide.ai/zh](https://www.promptingguide.ai/zh)
15-
16-
## 模型部署
176

7+
模型部署主要有如下几个需求:并发高、延迟低、占用小。解决方案对应Ollama、VLLM、Llama-Cpp-Python。
188

199
| 维度 | Ollama | VLLM | Llama-Cpp-Python |
2010
|------------------------|---------------------------------------------------|------------------------------------------------|------------------------------------------------|
@@ -35,17 +25,17 @@ title: 🚧模型微调与部署
3525
| **成熟度** | 新兴工具,功能逐步完善 | 工业级项目,专注高性能推理 | 成熟项目,广泛使用于轻量化 LLM 应用 |
3626

3727

38-
### ollma
28+
## ollma
3929

4030
github地址:https://github.com/ollama/ollama
4131

4232
官网:https://ollama.com/
4333

44-
### vllma
34+
## vllma
4535

4636

4737
官网:https://docs.vllm.ai/en/latest/getting_started/quickstart.html
4838

4939

50-
### llama-cpp-python
40+
## llama-cpp-python
5141

0 commit comments

Comments
 (0)