Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: haoranxu/ALMA-7B
|
3 |
+
inference: false
|
4 |
+
license: mit
|
5 |
+
model_creator: Haoran Xu
|
6 |
+
model_name: ALMA 7B
|
7 |
+
model_type: llama
|
8 |
+
prompt_template: 'Translate this from Chinese to English:
|
9 |
+
|
10 |
+
Chinese: {prompt}
|
11 |
+
|
12 |
+
English:
|
13 |
+
|
14 |
+
'
|
15 |
+
quantized_by: TheBloke
|
16 |
+
---
|
17 |
+
|
18 |
+
<!-- header start -->
|
19 |
+
<!-- 200823 -->
|
20 |
+
<div style="width: auto; margin-left: auto; margin-right: auto">
|
21 |
+
<img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
|
22 |
+
</div>
|
23 |
+
<div style="display: flex; justify-content: space-between; width: 100%;">
|
24 |
+
<div style="display: flex; flex-direction: column; align-items: flex-start;">
|
25 |
+
<p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
|
26 |
+
</div>
|
27 |
+
<div style="display: flex; flex-direction: column; align-items: flex-end;">
|
28 |
+
<p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
|
29 |
+
</div>
|
30 |
+
</div>
|
31 |
+
<div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
|
32 |
+
<hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
|
33 |
+
<!-- header end -->
|
34 |
+
|
35 |
+
# ALMA 7B - AWQ
|
36 |
+
- Model creator: [Haoran Xu](https://huggingface.co/haoranxu)
|
37 |
+
- Original model: [ALMA 7B](https://huggingface.co/haoranxu/ALMA-7B)
|
38 |
+
|
39 |
+
<!-- description start -->
|
40 |
+
## Description
|
41 |
+
|
42 |
+
This repo contains AWQ model files for [Haoran Xu's ALMA 7B](https://huggingface.co/haoranxu/ALMA-7B).
|
43 |
+
|
44 |
+
|
45 |
+
### About AWQ
|
46 |
+
|
47 |
+
AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference.
|
48 |
+
|
49 |
+
It is also now supported by continuous batching server [vLLM](https://github.com/vllm-project/vllm), allowing use of Llama AWQ models for high-throughput concurrent inference in multi-user server scenarios.
|
50 |
+
|
51 |
+
As of September 25th 2023, preliminary Llama-only AWQ support has also been added to [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference).
|
52 |
+
|
53 |
+
Note that, at the time of writing, overall throughput is still lower than running vLLM or TGI with unquantised models, however using AWQ enables using much smaller GPUs which can lead to easier deployment and overall cost savings. For example, a 70B model can be run on 1 x 48GB GPU instead of 2 x 80GB.
|
54 |
+
<!-- description end -->
|
55 |
+
<!-- repositories-available start -->
|
56 |
+
## Repositories available
|
57 |
+
|
58 |
+
* [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/ALMA-7B-AWQ)
|
59 |
+
* [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/ALMA-7B-GPTQ)
|
60 |
+
* [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/ALMA-7B-GGUF)
|
61 |
+
* [Haoran Xu's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/haoranxu/ALMA-7B)
|
62 |
+
<!-- repositories-available end -->
|
63 |
+
|
64 |
+
<!-- prompt-template start -->
|
65 |
+
## Prompt template: ALMA
|
66 |
+
|
67 |
+
```
|
68 |
+
Translate this from Chinese to English:
|
69 |
+
Chinese: {prompt}
|
70 |
+
English:
|
71 |
+
|
72 |
+
```
|
73 |
+
|
74 |
+
<!-- prompt-template end -->
|
75 |
+
<!-- licensing start -->
|
76 |
+
## Licensing
|
77 |
+
|
78 |
+
The creator of the source model has listed its license as `mit`, and this quantization has therefore used that same license.
|
79 |
+
|
80 |
+
As this model is based on Llama 2, it is also subject to the Meta Llama 2 license terms, and the license files for that are additionally included. It should therefore be considered as being claimed to be licensed under both licenses. I contacted Hugging Face for clarification on dual licensing but they do not yet have an official position. Should this change, or should Meta provide any feedback on this situation, I will update this section accordingly.
|
81 |
+
|
82 |
+
In the meantime, any questions regarding licensing, and in particular how these two licenses might interact, should be directed to the original model repository: [Haoran Xu's ALMA 7B](https://huggingface.co/haoranxu/ALMA-7B).
|
83 |
+
<!-- licensing end -->
|
84 |
+
<!-- README_AWQ.md-provided-files start -->
|
85 |
+
## Provided files, and AWQ parameters
|
86 |
+
|
87 |
+
For my first release of AWQ models, I am releasing 128g models only. I will consider adding 32g as well if there is interest, and once I have done perplexity and evaluation comparisons, but at this time 32g models are still not fully tested with AutoAWQ and vLLM.
|
88 |
+
|
89 |
+
Models are released as sharded safetensors files.
|
90 |
+
|
91 |
+
| Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
|
92 |
+
| ------ | ---- | -- | ----------- | ------- | ---- |
|
93 |
+
| [main](https://huggingface.co/TheBloke/ALMA-7B-AWQ/tree/main) | 4 | 128 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 3.89 GB
|
94 |
+
|
95 |
+
<!-- README_AWQ.md-provided-files end -->
|
96 |
+
|
97 |
+
<!-- README_AWQ.md-use-from-vllm start -->
|
98 |
+
## Serving this model from vLLM
|
99 |
+
|
100 |
+
Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
|
101 |
+
|
102 |
+
Note: at the time of writing, vLLM has not yet done a new release with AWQ support.
|
103 |
+
|
104 |
+
If you try the vLLM examples below and get an error about `quantization` being unrecognised, or other AWQ-related issues, please install vLLM from Github source.
|
105 |
+
|
106 |
+
- When using vLLM as a server, pass the `--quantization awq` parameter, for example:
|
107 |
+
|
108 |
+
```shell
|
109 |
+
python3 python -m vllm.entrypoints.api_server --model TheBloke/ALMA-7B-AWQ --quantization awq --dtype half
|
110 |
+
```
|
111 |
+
|
112 |
+
When using vLLM from Python code, pass the `quantization=awq` parameter, for example:
|
113 |
+
|
114 |
+
```python
|
115 |
+
from vllm import LLM, SamplingParams
|
116 |
+
|
117 |
+
prompts = [
|
118 |
+
"Hello, my name is",
|
119 |
+
"The president of the United States is",
|
120 |
+
"The capital of France is",
|
121 |
+
"The future of AI is",
|
122 |
+
]
|
123 |
+
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
124 |
+
|
125 |
+
llm = LLM(model="TheBloke/ALMA-7B-AWQ", quantization="awq", dtype="half")
|
126 |
+
|
127 |
+
outputs = llm.generate(prompts, sampling_params)
|
128 |
+
|
129 |
+
# Print the outputs.
|
130 |
+
for output in outputs:
|
131 |
+
prompt = output.prompt
|
132 |
+
generated_text = output.outputs[0].text
|
133 |
+
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
|
134 |
+
```
|
135 |
+
<!-- README_AWQ.md-use-from-vllm start -->
|
136 |
+
|
137 |
+
<!-- README_AWQ.md-use-from-tgi start -->
|
138 |
+
## Serving this model from Text Generation Inference (TGI)
|
139 |
+
|
140 |
+
Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
|
141 |
+
|
142 |
+
Example Docker parameters:
|
143 |
+
|
144 |
+
```shell
|
145 |
+
--model-id TheBloke/ALMA-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
|
146 |
+
```
|
147 |
+
|
148 |
+
Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
|
149 |
+
|
150 |
+
```shell
|
151 |
+
pip3 install huggingface-hub
|
152 |
+
```
|
153 |
+
|
154 |
+
```python
|
155 |
+
from huggingface_hub import InferenceClient
|
156 |
+
|
157 |
+
endpoint_url = "https://your-endpoint-url-here"
|
158 |
+
|
159 |
+
prompt = "Tell me about AI"
|
160 |
+
prompt_template=f'''Translate this from Chinese to English:
|
161 |
+
Chinese: {prompt}
|
162 |
+
English:
|
163 |
+
|
164 |
+
'''
|
165 |
+
|
166 |
+
client = InferenceClient(endpoint_url)
|
167 |
+
response = client.text_generation(prompt,
|
168 |
+
max_new_tokens=128,
|
169 |
+
do_sample=True,
|
170 |
+
temperature=0.7,
|
171 |
+
top_p=0.95,
|
172 |
+
top_k=40,
|
173 |
+
repetition_penalty=1.1)
|
174 |
+
|
175 |
+
print(f"Model output: {response}")
|
176 |
+
```
|
177 |
+
<!-- README_AWQ.md-use-from-tgi end -->
|
178 |
+
|
179 |
+
<!-- README_AWQ.md-use-from-python start -->
|
180 |
+
## How to use this AWQ model from Python code
|
181 |
+
|
182 |
+
### Install the necessary packages
|
183 |
+
|
184 |
+
Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.1 or later
|
185 |
+
|
186 |
+
```shell
|
187 |
+
pip3 install autoawq
|
188 |
+
```
|
189 |
+
|
190 |
+
If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
|
191 |
+
|
192 |
+
```shell
|
193 |
+
pip3 uninstall -y autoawq
|
194 |
+
git clone https://github.com/casper-hansen/AutoAWQ
|
195 |
+
cd AutoAWQ
|
196 |
+
pip3 install .
|
197 |
+
```
|
198 |
+
|
199 |
+
### You can then try the following example code
|
200 |
+
|
201 |
+
```python
|
202 |
+
from awq import AutoAWQForCausalLM
|
203 |
+
from transformers import AutoTokenizer
|
204 |
+
|
205 |
+
model_name_or_path = "TheBloke/ALMA-7B-AWQ"
|
206 |
+
|
207 |
+
# Load model
|
208 |
+
model = AutoAWQForCausalLM.from_quantized(model_name_or_path, fuse_layers=True,
|
209 |
+
trust_remote_code=False, safetensors=True)
|
210 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=False)
|
211 |
+
|
212 |
+
prompt = "Tell me about AI"
|
213 |
+
prompt_template=f'''Translate this from Chinese to English:
|
214 |
+
Chinese: {prompt}
|
215 |
+
English:
|
216 |
+
|
217 |
+
'''
|
218 |
+
|
219 |
+
print("\n\n*** Generate:")
|
220 |
+
|
221 |
+
tokens = tokenizer(
|
222 |
+
prompt_template,
|
223 |
+
return_tensors='pt'
|
224 |
+
).input_ids.cuda()
|
225 |
+
|
226 |
+
# Generate output
|
227 |
+
generation_output = model.generate(
|
228 |
+
tokens,
|
229 |
+
do_sample=True,
|
230 |
+
temperature=0.7,
|
231 |
+
top_p=0.95,
|
232 |
+
top_k=40,
|
233 |
+
max_new_tokens=512
|
234 |
+
)
|
235 |
+
|
236 |
+
print("Output: ", tokenizer.decode(generation_output[0]))
|
237 |
+
|
238 |
+
"""
|
239 |
+
# Inference should be possible with transformers pipeline as well in future
|
240 |
+
# But currently this is not yet supported by AutoAWQ (correct as of September 25th 2023)
|
241 |
+
from transformers import pipeline
|
242 |
+
|
243 |
+
print("*** Pipeline:")
|
244 |
+
pipe = pipeline(
|
245 |
+
"text-generation",
|
246 |
+
model=model,
|
247 |
+
tokenizer=tokenizer,
|
248 |
+
max_new_tokens=512,
|
249 |
+
do_sample=True,
|
250 |
+
temperature=0.7,
|
251 |
+
top_p=0.95,
|
252 |
+
top_k=40,
|
253 |
+
repetition_penalty=1.1
|
254 |
+
)
|
255 |
+
|
256 |
+
print(pipe(prompt_template)[0]['generated_text'])
|
257 |
+
"""
|
258 |
+
```
|
259 |
+
<!-- README_AWQ.md-use-from-python end -->
|
260 |
+
|
261 |
+
<!-- README_AWQ.md-compatibility start -->
|
262 |
+
## Compatibility
|
263 |
+
|
264 |
+
The files provided are tested to work with:
|
265 |
+
|
266 |
+
- [AutoAWQ](https://github.com/casper-hansen/AutoAWQ)
|
267 |
+
- [vLLM](https://github.com/vllm-project/vllm)
|
268 |
+
- [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
|
269 |
+
|
270 |
+
TGI merged AWQ support on September 25th, 2023: [TGI PR #1054](https://github.com/huggingface/text-generation-inference/pull/1054). Use the `:latest` Docker container until the next TGI release is made.
|
271 |
+
|
272 |
+
<!-- README_AWQ.md-compatibility end -->
|
273 |
+
|
274 |
+
<!-- footer start -->
|
275 |
+
<!-- 200823 -->
|
276 |
+
## Discord
|
277 |
+
|
278 |
+
For further support, and discussions on these models and AI in general, join us at:
|
279 |
+
|
280 |
+
[TheBloke AI's Discord server](https://discord.gg/theblokeai)
|
281 |
+
|
282 |
+
## Thanks, and how to contribute
|
283 |
+
|
284 |
+
Thanks to the [chirper.ai](https://chirper.ai) team!
|
285 |
+
|
286 |
+
Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
|
287 |
+
|
288 |
+
I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
|
289 |
+
|
290 |
+
If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
|
291 |
+
|
292 |
+
Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
|
293 |
+
|
294 |
+
* Patreon: https://patreon.com/TheBlokeAI
|
295 |
+
* Ko-Fi: https://ko-fi.com/TheBlokeAI
|
296 |
+
|
297 |
+
**Special thanks to**: Aemon Algiz.
|
298 |
+
|
299 |
+
**Patreon special mentions**: Pierre Kircher, Stanislav Ovsiannikov, Michael Levine, Eugene Pentland, Andrey, 준교 김, Randy H, Fred von Graf, Artur Olbinski, Caitlyn Gatomon, terasurfer, Jeff Scroggin, James Bentley, Vadim, Gabriel Puliatti, Harry Royden McLaughlin, Sean Connelly, Dan Guido, Edmond Seymore, Alicia Loh, subjectnull, AzureBlack, Manuel Alberto Morcote, Thomas Belote, Lone Striker, Chris Smitley, Vitor Caleffi, Johann-Peter Hartmann, Clay Pascal, biorpg, Brandon Frisco, sidney chen, transmissions 11, Pedro Madruga, jinyuan sun, Ajan Kanaga, Emad Mostaque, Trenton Dambrowitz, Jonathan Leane, Iucharbius, usrbinkat, vamX, George Stoitzev, Luke Pendergrass, theTransient, Olakabola, Swaroop Kallakuri, Cap'n Zoog, Brandon Phillips, Michael Dempsey, Nikolai Manek, danny, Matthew Berman, Gabriel Tamborski, alfie_i, Raymond Fosdick, Tom X Nguyen, Raven Klaugh, LangChain4j, Magnesian, Illia Dulskyi, David Ziegler, Mano Prime, Luis Javier Navarrete Lozano, Erik Bjäreholt, 阿明, Nathan Dryer, Alex, Rainer Wilmers, zynix, TL, Joseph William Delisle, John Villwock, Nathan LeClaire, Willem Michiel, Joguhyik, GodLy, OG, Alps Aficionado, Jeffrey Morgan, ReadyPlayerEmma, Tiffany J. Kim, Sebastain Graf, Spencer Kim, Michael Davis, webtim, Talal Aujan, knownsqashed, John Detwiler, Imad Khwaja, Deo Leter, Jerry Meng, Elijah Stavena, Rooh Singh, Pieter, SuperWojo, Alexandros Triantafyllidis, Stephen Murray, Ai Maven, ya boyyy, Enrico Ros, Ken Nordquist, Deep Realms, Nicholas, Spiking Neurons AB, Elle, Will Dee, Jack West, RoA, Luke @flexchar, Viktor Bowallius, Derek Yates, Subspace Studios, jjj, Toran Billups, Asp the Wyvern, Fen Risland, Ilya, NimbleBox.ai, Chadd, Nitin Borwankar, Emre, Mandus, Leonard Tan, Kalila, K, Trailburnt, S_X, Cory Kujawski
|
300 |
+
|
301 |
+
|
302 |
+
Thank you to all my generous patrons and donaters!
|
303 |
+
|
304 |
+
And thank you again to a16z for their generous grant.
|
305 |
+
|
306 |
+
<!-- footer end -->
|
307 |
+
|
308 |
+
# Original model card: Haoran Xu's ALMA 7B
|
309 |
+
|
310 |
+
**ALMA** (**A**dvanced **L**anguage **M**odel-based tr**A**nslator) is an LLM-based translation model, which adopts a new translation model paradigm: it begins with fine-tuning on monolingual data and is further optimized using high-quality parallel data. This two-step fine-tuning process ensures strong translation performance.
|
311 |
+
Please find more details in our [paper](https://arxiv.org/abs/2309.11674).
|
312 |
+
```
|
313 |
+
@misc{xu2023paradigm,
|
314 |
+
title={A Paradigm Shift in Machine Translation: Boosting Translation Performance of Large Language Models},
|
315 |
+
author={Haoran Xu and Young Jin Kim and Amr Sharaf and Hany Hassan Awadalla},
|
316 |
+
year={2023},
|
317 |
+
eprint={2309.11674},
|
318 |
+
archivePrefix={arXiv},
|
319 |
+
primaryClass={cs.CL}
|
320 |
+
}
|
321 |
+
```
|
322 |
+
We release four translation models presented in the paper:
|
323 |
+
- **ALMA-7B**: Full-weight Fine-tune LLaMA-2-7B on 20B monolingual tokens and then **Full-weight** fine-tune on human-written parallel data
|
324 |
+
- **ALMA-7B-LoRA**: Full-weight Fine-tune LLaMA-2-7B on 20B monolingual tokens and then **LoRA** fine-tune on human-written parallel data
|
325 |
+
- **ALMA-13B**: Full-weight Fine-tune LLaMA-2-7B on 12B monolingual tokens and then **Full-weight** fine-tune on human-written parallel data
|
326 |
+
- **ALMA-13B-LoRA** (Our best system): Full-weight Fine-tune LLaMA-2-7B on 12B monolingual tokens and then **LoRA** fine-tune on human-written parallel data
|
327 |
+
|
328 |
+
Model checkpoints are released at huggingface:
|
329 |
+
| Models | Base Model Link | LoRA Link |
|
330 |
+
|:-------------:|:---------------:|:---------:|
|
331 |
+
| ALMA-7B | [haoranxu/ALMA-7B](https://huggingface.co/haoranxu/ALMA-7B) | - |
|
332 |
+
| ALMA-7B-LoRA | [haoranxu/ALMA-7B-Pretrain](https://huggingface.co/haoranxu/ALMA-7B-Pretrain) | [haoranxu/ALMA-7B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-7B-Pretrain-LoRA) |
|
333 |
+
| ALMA-13B | [haoranxu/ALMA-13B](https://huggingface.co/haoranxu/ALMA-13B) | - |
|
334 |
+
| ALMA-13B-LoRA | [haoranxu/ALMA-13B-Pretrain](https://huggingface.co/haoranxu/ALMA-13B-Pretrain) | [haoranxu/ALMA-13B-Pretrain-LoRA](https://huggingface.co/haoranxu/ALMA-13B-Pretrain-LoRA) |
|
335 |
+
|
336 |
+
**Note that `ALMA-7B-Pretrain` and `ALMA-13B-Pretrain` are NOT translation models. They only experience stage 1 monolingual fine-tuning (20B tokens for the 7B model and 12B tokens for the 13B model), and should be utilized in conjunction with their LoRA models for translation purposes.**
|
337 |
+
|
338 |
+
A quick start to use our best system (ALMA-13B-LoRA) for translation. An example of translating "我爱机器翻译。" into English:
|
339 |
+
```
|
340 |
+
import torch
|
341 |
+
from peft import PeftModel
|
342 |
+
from transformers import AutoModelForCausalLM
|
343 |
+
from transformers import LlamaTokenizer
|
344 |
+
|
345 |
+
# Load base model and LoRA weights
|
346 |
+
model = AutoModelForCausalLM.from_pretrained("haoranxu/ALMA-13B-Pretrain", torch_dtype=torch.float16, device_map="auto")
|
347 |
+
model = PeftModel.from_pretrained(model, "haoranxu/ALMA-13B-Pretrain-LoRA")
|
348 |
+
tokenizer = LlamaTokenizer.from_pretrained("haoranxu/ALMA-13B-Pretrain", padding_side='left')
|
349 |
+
|
350 |
+
# Add the source setence into the prompt template
|
351 |
+
prompt="Translate this from Chinese to English:\nChinese: 我爱机器翻译。\nEnglish:"
|
352 |
+
input_ids = tokenizer(prompt, return_tensors="pt", padding=True, max_length=40, truncation=True).input_ids.cuda()
|
353 |
+
|
354 |
+
# Translation
|
355 |
+
with torch.no_grad():
|
356 |
+
generated_ids = model.generate(input_ids=input_ids, num_beams=5, max_new_tokens=20, do_sample=True, temperature=0.6, top_p=0.9)
|
357 |
+
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
358 |
+
print(outputs)
|
359 |
+
```
|
360 |
+
|
361 |
+
Please find more details in our [GitHub repository](https://github.com/fe1ixxu/ALMA)
|