Skip to content

Commit deeae84

Browse files
authored
Merge pull request #326 from Anhforth/merge_aquila
Merge aquila
2 parents 46127c9 + dd72e8a commit deeae84

24 files changed

+691
-231
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FlagAI (Fast LArge-scale General AI models) is a fast, easy-to-use and extensibl
1919

2020
FlagAI provides an API that allows you to quickly download pre-trained models and fine-tune them on a wide range of datasets collected from [SuperGLUE](https://super.gluebenchmark.com/) and [CLUE](https://github.com/CLUEbenchmark/CLUE) benchmarks for both Chinese and English text.
2121

22-
FlagAI now supports over 30 mainstream models, including multilingual text and image representation model [**AltCLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltCLIP), text-to-image generation model [**AltDiffusion**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion) [![Huggingface space](https://img.shields.io/badge/🤗-Huggingface%20Space-cyan.svg)](https://huggingface.co/spaces/BAAI/bilingual_stable_diffusion), [**WuDao GLM**](/docs/GLM.md) (with a maximum of 10 billion parameters), [**EVA-CLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/EVA_CLIP), **OPT**, **BERT**, **RoBERTa**, **GPT2**, **T5**, **ALM**, and models from **Huggingface Transformers**, etc.
22+
FlagAI now supports over 30 mainstream models, including Language Model [**Aquila**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/Aquila), multilingual text and image representation model [**AltCLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltCLIP), text-to-image generation model [**AltDiffusion**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion) [![Huggingface space](https://img.shields.io/badge/🤗-Huggingface%20Space-cyan.svg)](https://huggingface.co/spaces/BAAI/bilingual_stable_diffusion), [**WuDao GLM**](/docs/GLM.md) (with a maximum of 10 billion parameters), [**EVA-CLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/EVA_CLIP), **OPT**, **BERT**, **RoBERTa**, **GPT2**, **T5**, **ALM**, and models from **Huggingface Transformers**, etc.
2323

2424

2525
2. **Parallel train with fewer than 10 lines of code**
@@ -56,6 +56,7 @@ FlagAI (Fast LArge-scale General AI models) is a fast, easy-to-use and extensibl
5656

5757
| Model | Task | Train | Finetune | Inference/Generate | Examples |
5858
| :---------------- | :------- | :-- |:-- | :-- | :--------------------------------------------- |
59+
| Aquila | Natural Language Processing | ✅ | ✅ | ✅ | [README.md](examples/Aquila/README.md)
5960
| ALM | Arabic Text Generation |||| [README.md](/examples/ALM/README.md) |
6061
| AltCLIP | Image-Text Matching |||| [README.md](/examples/AltCLIP/README.md) |
6162
| AltCLIP-m18 | Image-Text Matching |||| [README.md](examples/AltCLIP-m18/README.md) |

README_zh.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
提供 API 方便你快速下载模型,并在给定(中/英文)文本上使用这些预训练模型,在从[SuperGLUE](https://super.gluebenchmark.com/)[CLUE](https://github.com/CLUEbenchmark/CLUE) benchmarks收集的广泛使用的数据集上对它们进行微调。
2828

29-
FlagAI 现已支持 30+ 主流模型,包括多模态模型 [**AltCLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltCLIP) 、文生图模型 [**AltDiffusion**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion) [![Huggingface space](https://img.shields.io/badge/🤗-Huggingface%20Space-cyan.svg)](https://huggingface.co/spaces/BAAI/bilingual_stable_diffusion)、最高百亿参数的 **[悟道GLM](/doc_zh/GLM.md)**[**EVA-CLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/EVA_CLIP)**[Galactica](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/galactica)****OPT****BERT****RoBERTa****GPT2****T5****ALM****Huggingface Transformers** 等。
29+
FlagAI 现已支持 30+ 主流模型,包括语言模型[**Aquila**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/Aquila), 多模态模型 [**AltCLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltCLIP) 、文生图模型 [**AltDiffusion**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/AltDiffusion) [![Huggingface space](https://img.shields.io/badge/🤗-Huggingface%20Space-cyan.svg)](https://huggingface.co/spaces/BAAI/bilingual_stable_diffusion)、最高百亿参数的 **[悟道GLM](/doc_zh/GLM.md)**[**EVA-CLIP**](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/EVA_CLIP)**[Galactica](https://github.com/FlagAI-Open/FlagAI/tree/master/examples/galactica)****OPT****BERT****RoBERTa****GPT2****T5****ALM****Huggingface Transformers** 等。
3030

3131
2. **仅用十行代码即可进行并行训练**
3232

@@ -59,6 +59,7 @@
5959

6060
| 模型名称 | 任务 | 训练 | 微调 | 推理 | 样例 |
6161
| :---------------- | :------- | :-- |:-- | :-- | :--------------------------------------------- |
62+
| Aquila | 自然语言处理 | ✅ | ✅ | ✅ | [README.md](examples/Aquila/README.md)
6263
| ALM | 阿拉伯语文本生成 |||| [README.md](/examples/ALM/README.md) |
6364
| AltCLIP | 文图匹配 |||| [README.md](/examples/AltCLIP/README.md) |
6465
| AltCLIP-m18 | 文图匹配 |||| [README.md](examples/AltCLIP-m18/README.md) |

examples/Aquila/Aquila-sft/aquila_sft.py examples/Aquila/Aquila-chat/aquila_chat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from flagai.env_trainer_v1 import EnvTrainer
1414
import jsonlines
1515
import numpy as np
16-
from examples.Aquila import cyg_conversation as conversation_lib
16+
import cyg_conversation as conversation_lib
1717
from flagai.model.tools.lora.prepare_lora import lora_transfer
1818
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
1919

examples/Aquila/Aquila-sft/generate_sft.py examples/Aquila/Aquila-chat/generate_chat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def convo_tokenize(convo_obj, tokenizer):
9292
print('-'*80)
9393
print(f"text is {text}")
9494

95-
from examples.Aquila.cyg_conversation import default_conversation
95+
from cyg_conversation import default_conversation
9696

9797
conv = default_conversation.copy()
9898
conv.append_message(conv.roles[0], text)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import os
2+
import torch
3+
from flagai.auto_model.auto_loader import AutoLoader
4+
from flagai.model.predictor.predictor import Predictor
5+
from flagai.model.predictor.aquila import aquila_generate
6+
from flagai.data.tokenizer import Tokenizer
7+
import bminf
8+
9+
state_dict = "/data2/yzd/checkpoints/converted_models_ldwang"
10+
model_name = 'aquilachat-7b'
11+
12+
loader = AutoLoader(
13+
"lm",
14+
model_dir=state_dict,
15+
model_name=model_name,
16+
use_cache=True)
17+
model = loader.get_model()
18+
tokenizer = loader.get_tokenizer()
19+
cache_dir = os.path.join(state_dict, model_name)
20+
21+
model.eval()
22+
model.half()
23+
24+
with torch.cuda.device(0):
25+
model = bminf.wrapper(model, quantization=False, memory_limit=2 << 30)
26+
27+
predictor = Predictor(model, tokenizer)
28+
29+
texts = [
30+
"北京为什么是中国的首都?",
31+
"1+1=",
32+
"为什么湘菜那么甜?",
33+
"东三省和海南岛的区别?",
34+
]
35+
##
36+
def pack_obj(text):
37+
obj = dict()
38+
obj['id'] = 'demo'
39+
40+
obj['conversations'] = []
41+
human = dict()
42+
human['from'] = 'human'
43+
human['value'] = text
44+
obj['conversations'].append(human)
45+
# dummy bot
46+
bot = dict()
47+
bot['from'] = 'gpt'
48+
bot['value'] = ''
49+
obj['conversations'].append(bot)
50+
51+
obj['instruction'] = ''
52+
53+
return obj
54+
55+
def delete_last_bot_end_singal(convo_obj):
56+
conversations = convo_obj['conversations']
57+
assert len(conversations) > 0 and len(conversations) % 2 == 0
58+
assert conversations[0]['from'] == 'human'
59+
60+
last_bot = conversations[len(conversations)-1]
61+
assert last_bot['from'] == 'gpt'
62+
63+
## from _add_speaker_and_signal
64+
END_SIGNAL = "\n"
65+
len_end_singal = len(END_SIGNAL)
66+
len_last_bot_value = len(last_bot['value'])
67+
last_bot['value'] = last_bot['value'][:len_last_bot_value-len_end_singal]
68+
return
69+
70+
def convo_tokenize(convo_obj, tokenizer):
71+
chat_desc = convo_obj['chat_desc']
72+
instruction = convo_obj['instruction']
73+
conversations = convo_obj['conversations']
74+
75+
# chat_desc
76+
example = tokenizer.encode_plus(f"{chat_desc}", None, max_length=None)['input_ids']
77+
EOS_TOKEN = example[-1]
78+
example = example[:-1] # remove eos
79+
# instruction
80+
instruction = tokenizer.encode_plus(f"{instruction}", None, max_length=None)['input_ids']
81+
instruction = instruction[1:-1] # remove bos & eos
82+
example += instruction
83+
84+
for conversation in conversations:
85+
role = conversation['from']
86+
content = conversation['value']
87+
print(f"role {role}, raw content {content}")
88+
content = tokenizer.encode_plus(f"{content}", None, max_length=None)['input_ids']
89+
content = content[1:-1] # remove bos & eos
90+
print(f"role {role}, content {content}")
91+
example += content
92+
return example
93+
94+
for text in texts:
95+
print('-'*80)
96+
print(f"text is {text}")
97+
98+
from cyg_conversation import default_conversation
99+
100+
conv = default_conversation.copy()
101+
conv.append_message(conv.roles[0], text)
102+
conv.append_message(conv.roles[1], None)
103+
104+
tokens = tokenizer.encode_plus(f"{conv.get_prompt()}", None, max_length=None)['input_ids']
105+
tokens = tokens[1:-1]
106+
107+
with torch.no_grad():
108+
out = aquila_generate(tokenizer, model, [text], max_gen_len:=200, top_p=0.95, prompts_tokens=[tokens])
109+
print(f"pred is {out}")
File renamed without changes.

examples/Aquila/Aquila-code/README_AquilaCode.md examples/Aquila/Aquila-code/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bash dist_trigger_docker.sh hostfile Aquila-sft.yaml [aquilacode-7b-nv/aquilacod
148148

149149
## 证书/License
150150

151-
AquilaCode-7B-NV开源模型使用 [智源Aquila系列模型许可协议](https://huggingface.co/BAAI/AquilaCode-7B-NV/resolve/main/BAAI%20Aquila%20Model%20License%20Agreement.pdf), 原始代码基于[Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0)
151+
AquilaCode-7B-NV和AquilaCode-7B-TS开源模型使用 [智源Aquila系列模型许可协议](https://huggingface.co/BAAI/AquilaCode-7B-NV/resolve/main/BAAI%20Aquila%20Model%20License%20Agreement.pdf), 原始代码基于[Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0)
152152

153153

154-
AquilaCode-7B-NV open-source model is licensed under [ BAAI Aquila Model Licence Agreement](https://huggingface.co/BAAI/AquilaCode-7B-NV/resolve/main/BAAI%20Aquila%20Model%20License%20Agreement.pdf). The source code is under [Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0).
154+
AquilaCode-7B-NV and AquilaCode-7B-TSopen-source model is licensed under [ BAAI Aquila Model Licence Agreement](https://huggingface.co/BAAI/AquilaCode-7B-NV/resolve/main/BAAI%20Aquila%20Model%20License%20Agreement.pdf). The source code is under [Apache Licence 2.0](https://www.apache.org/licenses/LICENSE-2.0).

examples/Aquila/Aquila-code/aquila_code.py

-223
This file was deleted.

0 commit comments

Comments
 (0)