TheBloke commited on
Commit
ab280a9
1 Parent(s): be1bb8a

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +547 -0
README.md ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: tokyotech-llm/Swallow-7b-instruct-hf
3
+ inference: false
4
+ language:
5
+ - en
6
+ - ja
7
+ library_name: transformers
8
+ license: llama2
9
+ model_creator: tokyotech-llm
10
+ model_name: Swallow 7B Instruct
11
+ model_type: llama
12
+ pipeline_tag: text-generation
13
+ prompt_template: "\u4EE5\u4E0B\u306B\u3001\u3042\u308B\u30BF\u30B9\u30AF\u3092\u8AAC\
14
+ \u660E\u3059\u308B\u6307\u793A\u304C\u3042\u308A\u307E\u3059\u3002\u30EA\u30AF\u30A8\
15
+ \u30B9\u30C8\u3092\u9069\u5207\u306B\u5B8C\u4E86\u3059\u308B\u305F\u3081\u306E\u56DE\
16
+ \u7B54\u3092\u8A18\u8FF0\u3057\u3066\u304F\u3060\u3055\u3044\u3002\\n\\n### \u6307\
17
+ \u793A:\\n{prompt}\\n\\n### \u5FDC\u7B54:\n"
18
+ quantized_by: TheBloke
19
+ ---
20
+ <!-- markdownlint-disable MD041 -->
21
+
22
+ <!-- header start -->
23
+ <!-- 200823 -->
24
+ <div style="width: auto; margin-left: auto; margin-right: auto">
25
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
26
+ </div>
27
+ <div style="display: flex; justify-content: space-between; width: 100%;">
28
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
29
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
30
+ </div>
31
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
32
+ <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>
33
+ </div>
34
+ </div>
35
+ <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>
36
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
37
+ <!-- header end -->
38
+
39
+ # Swallow 7B Instruct - AWQ
40
+ - Model creator: [tokyotech-llm](https://huggingface.co/tokyotech-llm)
41
+ - Original model: [Swallow 7B Instruct](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf)
42
+
43
+ <!-- description start -->
44
+ ## Description
45
+
46
+ This repo contains AWQ model files for [tokyotech-llm's Swallow 7B Instruct](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf).
47
+
48
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
49
+
50
+
51
+ ### About AWQ
52
+
53
+ 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 with equivalent or better quality compared to the most commonly used GPTQ settings.
54
+
55
+ AWQ models are currently supported on Linux and Windows, with NVidia GPUs only. macOS users: please use GGUF models instead.
56
+
57
+ It is supported by:
58
+
59
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
60
+ - [vLLM](https://github.com/vllm-project/vllm) - version 0.2.2 or later for support for all model types.
61
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
62
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
63
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
64
+
65
+ <!-- description end -->
66
+ <!-- repositories-available start -->
67
+ ## Repositories available
68
+
69
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/Swallow-7B-Instruct-AWQ)
70
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/Swallow-7B-Instruct-GPTQ)
71
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/Swallow-7B-Instruct-GGUF)
72
+ * [tokyotech-llm's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf)
73
+ <!-- repositories-available end -->
74
+
75
+ <!-- prompt-template start -->
76
+ ## Prompt template: Swallow-Instruct
77
+
78
+ ```
79
+ 以下に、あるタスクを説明する指示があります。リクエストを適切に完了するための回答を記述してください。\n\n### 指示:\n{prompt}\n\n### 応答:
80
+
81
+ ```
82
+
83
+ <!-- prompt-template end -->
84
+
85
+
86
+ <!-- README_AWQ.md-provided-files start -->
87
+ ## Provided files, and AWQ parameters
88
+
89
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
90
+
91
+ Models are released as sharded safetensors files.
92
+
93
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
94
+ | ------ | ---- | -- | ----------- | ------- | ---- |
95
+ | [main](https://huggingface.co/TheBloke/Swallow-7B-Instruct-AWQ/tree/main) | 4 | 128 | [Alpaca Japanese](https://huggingface.co/datasets/fujiki/japanese_alpaca_data/viewer/) | 4096 | 4.07 GB
96
+
97
+ <!-- README_AWQ.md-provided-files end -->
98
+
99
+ <!-- README_AWQ.md-text-generation-webui start -->
100
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
101
+
102
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
103
+
104
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
105
+
106
+ 1. Click the **Model tab**.
107
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/Swallow-7B-Instruct-AWQ`.
108
+ 3. Click **Download**.
109
+ 4. The model will start downloading. Once it's finished it will say "Done".
110
+ 5. In the top left, click the refresh icon next to **Model**.
111
+ 6. In the **Model** dropdown, choose the model you just downloaded: `Swallow-7B-Instruct-AWQ`
112
+ 7. Select **Loader: AutoAWQ**.
113
+ 8. Click Load, and the model will load and is now ready for use.
114
+ 9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
115
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
116
+ <!-- README_AWQ.md-text-generation-webui end -->
117
+
118
+ <!-- README_AWQ.md-use-from-vllm start -->
119
+ ## Multi-user inference server: vLLM
120
+
121
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
122
+
123
+ - Please ensure you are using vLLM version 0.2 or later.
124
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
125
+
126
+ For example:
127
+
128
+ ```shell
129
+ python3 -m vllm.entrypoints.api_server --model TheBloke/Swallow-7B-Instruct-AWQ --quantization awq --dtype auto
130
+ ```
131
+
132
+ - When using vLLM from Python code, again set `quantization=awq`.
133
+
134
+ For example:
135
+
136
+ ```python
137
+ from vllm import LLM, SamplingParams
138
+
139
+ prompts = [
140
+ "Tell me about AI",
141
+ "Write a story about llamas",
142
+ "What is 291 - 150?",
143
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
144
+ ]
145
+ prompt_template=f'''以下に、あるタスクを説明する指示があります。リクエストを適切に完了するための回答を記述してください。\n\n### 指示:\n{prompt}\n\n### 応答:
146
+ '''
147
+
148
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
149
+
150
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
151
+
152
+ llm = LLM(model="TheBloke/Swallow-7B-Instruct-AWQ", quantization="awq", dtype="auto")
153
+
154
+ outputs = llm.generate(prompts, sampling_params)
155
+
156
+ # Print the outputs.
157
+ for output in outputs:
158
+ prompt = output.prompt
159
+ generated_text = output.outputs[0].text
160
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
161
+ ```
162
+ <!-- README_AWQ.md-use-from-vllm start -->
163
+
164
+ <!-- README_AWQ.md-use-from-tgi start -->
165
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
166
+
167
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
168
+
169
+ Example Docker parameters:
170
+
171
+ ```shell
172
+ --model-id TheBloke/Swallow-7B-Instruct-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
173
+ ```
174
+
175
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
176
+
177
+ ```shell
178
+ pip3 install huggingface-hub
179
+ ```
180
+
181
+ ```python
182
+ from huggingface_hub import InferenceClient
183
+
184
+ endpoint_url = "https://your-endpoint-url-here"
185
+
186
+ prompt = "Tell me about AI"
187
+ prompt_template=f'''以下に、あるタスクを説明する指示があります。リクエストを適切に完了するための回答を記述してください。\n\n### 指示:\n{prompt}\n\n### 応答:
188
+ '''
189
+
190
+ client = InferenceClient(endpoint_url)
191
+ response = client.text_generation(prompt,
192
+ max_new_tokens=128,
193
+ do_sample=True,
194
+ temperature=0.7,
195
+ top_p=0.95,
196
+ top_k=40,
197
+ repetition_penalty=1.1)
198
+
199
+ print(f"Model output: ", response)
200
+ ```
201
+ <!-- README_AWQ.md-use-from-tgi end -->
202
+
203
+ <!-- README_AWQ.md-use-from-python start -->
204
+ ## Inference from Python code using Transformers
205
+
206
+ ### Install the necessary packages
207
+
208
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
209
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
210
+
211
+ ```shell
212
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
213
+ ```
214
+
215
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
216
+
217
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
218
+
219
+ ```shell
220
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
221
+ ```
222
+
223
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
224
+
225
+ ```shell
226
+ pip3 uninstall -y autoawq
227
+ git clone https://github.com/casper-hansen/AutoAWQ
228
+ cd AutoAWQ
229
+ pip3 install .
230
+ ```
231
+
232
+ ### Transformers example code (requires Transformers 4.35.0 and later)
233
+
234
+ ```python
235
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
236
+
237
+ model_name_or_path = "TheBloke/Swallow-7B-Instruct-AWQ"
238
+
239
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
240
+ model = AutoModelForCausalLM.from_pretrained(
241
+ model_name_or_path,
242
+ low_cpu_mem_usage=True,
243
+ device_map="cuda:0"
244
+ )
245
+
246
+ # Using the text streamer to stream output one token at a time
247
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
248
+
249
+ prompt = "Tell me about AI"
250
+ prompt_template=f'''以下に、あるタスクを説明する指示があります。リクエストを適切に完了するための回答を記述してください。\n\n### 指示:\n{prompt}\n\n### 応答:
251
+ '''
252
+
253
+ # Convert prompt to tokens
254
+ tokens = tokenizer(
255
+ prompt_template,
256
+ return_tensors='pt'
257
+ ).input_ids.cuda()
258
+
259
+ generation_params = {
260
+ "do_sample": True,
261
+ "temperature": 0.7,
262
+ "top_p": 0.95,
263
+ "top_k": 40,
264
+ "max_new_tokens": 512,
265
+ "repetition_penalty": 1.1
266
+ }
267
+
268
+ # Generate streamed output, visible one token at a time
269
+ generation_output = model.generate(
270
+ tokens,
271
+ streamer=streamer,
272
+ **generation_params
273
+ )
274
+
275
+ # Generation without a streamer, which will include the prompt in the output
276
+ generation_output = model.generate(
277
+ tokens,
278
+ **generation_params
279
+ )
280
+
281
+ # Get the tokens from the output, decode them, print them
282
+ token_output = generation_output[0]
283
+ text_output = tokenizer.decode(token_output)
284
+ print("model.generate output: ", text_output)
285
+
286
+ # Inference is also possible via Transformers' pipeline
287
+ from transformers import pipeline
288
+
289
+ pipe = pipeline(
290
+ "text-generation",
291
+ model=model,
292
+ tokenizer=tokenizer,
293
+ **generation_params
294
+ )
295
+
296
+ pipe_output = pipe(prompt_template)[0]['generated_text']
297
+ print("pipeline output: ", pipe_output)
298
+
299
+ ```
300
+ <!-- README_AWQ.md-use-from-python end -->
301
+
302
+ <!-- README_AWQ.md-compatibility start -->
303
+ ## Compatibility
304
+
305
+ The files provided are tested to work with:
306
+
307
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
308
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
309
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
310
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
311
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
312
+
313
+ <!-- README_AWQ.md-compatibility end -->
314
+
315
+ <!-- footer start -->
316
+ <!-- 200823 -->
317
+ ## Discord
318
+
319
+ For further support, and discussions on these models and AI in general, join us at:
320
+
321
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
322
+
323
+ ## Thanks, and how to contribute
324
+
325
+ Thanks to the [chirper.ai](https://chirper.ai) team!
326
+
327
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
328
+
329
+ 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.
330
+
331
+ 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.
332
+
333
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
334
+
335
+ * Patreon: https://patreon.com/TheBlokeAI
336
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
337
+
338
+ **Special thanks to**: Aemon Algiz.
339
+
340
+ **Patreon special mentions**: Michael Levine, 阿明, Trailburnt, Nikolai Manek, John Detwiler, Randy H, Will Dee, Sebastain Graf, NimbleBox.ai, Eugene Pentland, Emad Mostaque, Ai Maven, Jim Angel, Jeff Scroggin, Michael Davis, Manuel Alberto Morcote, Stephen Murray, Robert, Justin Joy, Luke @flexchar, Brandon Frisco, Elijah Stavena, S_X, Dan Guido, Undi ., Komninos Chatzipapas, Shadi, theTransient, Lone Striker, Raven Klaugh, jjj, Cap'n Zoog, Michel-Marie MAUDET (LINAGORA), Matthew Berman, David, Fen Risland, Omer Bin Jawed, Luke Pendergrass, Kalila, OG, Erik Bjäreholt, Rooh Singh, Joseph William Delisle, Dan Lewis, TL, John Villwock, AzureBlack, Brad, Pedro Madruga, Caitlyn Gatomon, K, jinyuan sun, Mano Prime, Alex, Jeffrey Morgan, Alicia Loh, Illia Dulskyi, Chadd, transmissions 11, fincy, Rainer Wilmers, ReadyPlayerEmma, knownsqashed, Mandus, biorpg, Deo Leter, Brandon Phillips, SuperWojo, Sean Connelly, Iucharbius, Jack West, Harry Royden McLaughlin, Nicholas, terasurfer, Vitor Caleffi, Duane Dunston, Johann-Peter Hartmann, David Ziegler, Olakabola, Ken Nordquist, Trenton Dambrowitz, Tom X Nguyen, Vadim, Ajan Kanaga, Leonard Tan, Clay Pascal, Alexandros Triantafyllidis, JM33133, Xule, vamX, ya boyyy, subjectnull, Talal Aujan, Alps Aficionado, wassieverse, Ari Malik, James Bentley, Woland, Spencer Kim, Michael Dempsey, Fred von Graf, Elle, zynix, William Richards, Stanislav Ovsiannikov, Edmond Seymore, Jonathan Leane, Martin Kemka, usrbinkat, Enrico Ros
341
+
342
+
343
+ Thank you to all my generous patrons and donaters!
344
+
345
+ And thank you again to a16z for their generous grant.
346
+
347
+ <!-- footer end -->
348
+
349
+ # Original model card: tokyotech-llm's Swallow 7B Instruct
350
+
351
+
352
+ # Swallow
353
+
354
+ Our Swallow model has undergone continuous pre-training from the Llama 2 family, primarily with the addition of Japanese language data. The tuned versions use supervised fine-tuning (SFT).
355
+ Links to other models can be found in the index.
356
+
357
+ ## Swallow Model Index
358
+ |Model|Swallow-hf|Swallow-instruct-hf|
359
+ |---|---|---|
360
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf)|
361
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-hf)|
362
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-hf)|
363
+
364
+
365
+ ![logo](./logo.png)
366
+
367
+ This repository provides large language models developed by [TokyoTech-LLM](https://tokyotech-llm.github.io/).
368
+ Read our [blog post](https://zenn.dev/tokyotech_lm/articles/d6cb3a8fdfc907) or our paper (preprint coming soon) for more details!
369
+
370
+
371
+ ## Model Details
372
+
373
+ * **Model type**: Please refer to LLaMA-2 technical report for details on the model architecture.
374
+ * **Language(s)**: Japanese English
375
+ * **Library**: [Megatron-LM](https://github.com/rioyokotalab/Megatron-Llama2)
376
+ * **Tokenizer**: This model employs a tokenizer that features a broadened vocabulary based on Japanese data. This allows for a more efficient representation of text using fewer tokens, leading to a notably faster inference process.
377
+ * **Contact**: swallow[at]nlp.c.titech.ac.jp
378
+
379
+ ## Base Model Performance
380
+
381
+ ### Japanese version
382
+
383
+ |Model|Size|JCommonsenseQA|JEMHopQA|NIILC|JSQuAD|XL-Sum|MGSM|WMT20-en-ja|WMT20-ja-en|
384
+ |---|---|---|---|---|---|---|---|---|---|
385
+ | | |4-shot|4-shot|4-shot|4-shot|1-shot|4-shot|4-shot|4-shot|
386
+ |Llama 2|7B|0.3852|0.4240|0.3410|0.7917|0.1905|0.0760|0.1783|0.1738|
387
+ |Swallow|7B|0.4808|0.5078|0.5968|0.8573|0.1830|0.1240|0.2510|0.1511|
388
+ |Llama 2|13B|0.6997|0.4415|0.4170|0.8533|0.2139|0.1320|0.2146|0.1982|
389
+ |Swallow|13B|0.7837|0.5063|0.6398|0.9005|0.2168|0.2040|0.2720|0.1771|
390
+ |Llama 2|70B|0.8686|0.4656|0.5256|0.9080|**0.2361**|0.3560|0.2643|**0.2398**|
391
+ |Swallow|70B|**0.9348**|**0.6290**|**0.6960**|**0.9176**|0.2266|**0.4840**|**0.3043**|0.2298|
392
+
393
+ ## Usage
394
+
395
+ First install additional dependencies in [requirements.txt](./requirements.txt):
396
+
397
+ ```sh
398
+ pip install -r requirements.txt
399
+ ```
400
+
401
+ ### Use the instruct model
402
+
403
+ ```python
404
+ import torch
405
+ from transformers import AutoTokenizer, AutoModelForCausalLM
406
+
407
+ model_name = "tokyotech-llm/Swallow-7b-instruct-hf"
408
+
409
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
410
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")
411
+
412
+
413
+ PROMPT_DICT = {
414
+ "prompt_input": (
415
+ "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
416
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
417
+ "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"
418
+
419
+ ),
420
+ "prompt_no_input": (
421
+ "以下に、あるタスクを説明する指示があります。"
422
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
423
+ "### 指示:\n{instruction}\n\n### 応答:"
424
+ ),
425
+ }
426
+
427
+ def create_prompt(instruction, input=None):
428
+ """
429
+ Generates a prompt based on the given instruction and an optional input.
430
+ If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
431
+ If no input is provided, it uses the 'prompt_no_input' template.
432
+
433
+ Args:
434
+ instruction (str): The instruction describing the task.
435
+ input (str, optional): Additional input providing context for the task. Default is None.
436
+
437
+ Returns:
438
+ str: The generated prompt.
439
+ """
440
+ if input:
441
+ # Use the 'prompt_input' template when additional input is provided
442
+ return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
443
+ else:
444
+ # Use the 'prompt_no_input' template when no additional input is provided
445
+ return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)
446
+
447
+ # Example usage
448
+ instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
449
+ input_example = "東京工業大学の主なキャンパスについて教えてください"
450
+ prompt = create_prompt(instruction_example, input_example)
451
+
452
+ input_ids = tokenizer.encode(
453
+ prompt,
454
+ add_special_tokens=False,
455
+ return_tensors="pt"
456
+ )
457
+
458
+ tokens = model.generate(
459
+ input_ids.to(device=model.device),
460
+ max_new_tokens=128,
461
+ temperature=0.99,
462
+ top_p=0.95,
463
+ do_sample=True,
464
+ )
465
+
466
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
467
+ print(out)
468
+
469
+ ```
470
+
471
+ ### Use the base model
472
+
473
+ ```python
474
+ import torch
475
+ from transformers import AutoTokenizer, AutoModelForCausalLM
476
+
477
+ model_name = "tokyotech-llm/Swallow-7b-hf"
478
+
479
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
480
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
481
+
482
+ prompt = "東京工業大学の主なキャンパスは、"
483
+ input_ids = tokenizer.encode(
484
+ prompt,
485
+ add_special_tokens=False,
486
+ return_tensors="pt"
487
+ )
488
+ tokens = model.generate(
489
+ input_ids.to(device=model.device),
490
+ max_new_tokens=128,
491
+ temperature=0.99,
492
+ top_p=0.95,
493
+ do_sample=True,
494
+ )
495
+
496
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
497
+ print(out)
498
+ ```
499
+
500
+ ## Training Datasets
501
+
502
+ ### Continual Pre-Training
503
+ The following datasets were used for continual pre-training.
504
+
505
+ - [Japanese Wikipedia](https://dumps.wikimedia.org/other/cirrussearch)
506
+ - [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
507
+ - Swallow Corpus
508
+ - [The Pile](https://huggingface.co/datasets/EleutherAI/pile)
509
+
510
+
511
+ ### Instruction Tuning
512
+
513
+ The following datasets were used for the instruction tuning.
514
+
515
+ - [Anthropic HH-RLHF](https://huggingface.co/datasets/kunishou/hh-rlhf-49k-ja)
516
+ - [Databricks Dolly 15-k](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
517
+ - [OpenAssistant Conversations Dataset](https://huggingface.co/datasets/kunishou/oasst1-89k-ja)
518
+
519
+ ## Risks and Limitations
520
+
521
+ The models released here are still in the early stages of our research and development and have not been tuned to ensure outputs align with human intent and safety considerations.
522
+
523
+ ## Acknowledgements
524
+
525
+ We thank Meta Research for releasing Llama 2 under an open license for others to build on.
526
+
527
+ Our project is supported by the [ABCI Large-scale Language Model Building Support Program](https://abci.ai/en/link/llm_support_program.html) of the National Institute of Advanced Industrial Science and Technology.
528
+
529
+ ## License
530
+
531
+ Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
532
+
533
+ ## Authors
534
+
535
+ Here are the team members:
536
+ - From [Okazaki Laboratory](https://www.nlp.c.titech.ac.jp/index.en.html), the following members:
537
+ - [Naoaki Okazaki](https://www.chokkan.org/index.ja.html)
538
+ - [Sakae Mizuki](https://s-mizuki-nlp.github.io/)
539
+ - [Hiroki Iida](https://meshidenn.github.io/)
540
+ - [Mengsay Loem](https://loem-ms.github.io/)
541
+ - [Shota Hirai](https://huggingface.co/Kotemo428)
542
+ - [Kakeru Hattori](https://aya-se.vercel.app/)
543
+ - [Masanari Ohi](https://twitter.com/stjohn2007)
544
+ - From [YOKOTA Laboratory](https://www.rio.gsic.titech.ac.jp/en/index.html), the following members:
545
+ - [Rio Yokota](https://twitter.com/rioyokota)
546
+ - [Kazuki Fujii](https://twitter.com/okoge_kaz)
547
+ - [Taishi Nakamura](https://twitter.com/Setuna7777_2)