TheBloke commited on
Commit
e2d9826
·
1 Parent(s): ce9d678

Upload README.md

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