TheBloke commited on
Commit
25b9738
1 Parent(s): f44fc52

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +537 -0
README.md ADDED
@@ -0,0 +1,537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: NumbersStation/nsql-llama-2-7B
3
+ inference: false
4
+ license: llama2
5
+ model_creator: NumbersStation
6
+ model_name: NSQL Llama-2 7B
7
+ model_type: llama
8
+ prompt_template: '{prompt}
9
+
10
+
11
+ SELECT
12
+
13
+ '
14
+ quantized_by: TheBloke
15
+ widget:
16
+ - example_title: Number stadiums
17
+ text: "CREATE TABLE stadium (\n stadium_id number,\n location text,\n name\
18
+ \ text,\n capacity number,\n)\n\n-- Using valid SQLite, answer the following\
19
+ \ questions for the tables provided above.\n\n-- how many stadiums in total?\n\
20
+ \nSELECT"
21
+ - example_title: Open work orders
22
+ text: 'CREATE TABLE work_orders ( ID NUMBER, CREATED_AT TEXT, COST FLOAT, INVOICE_AMOUNT
23
+ FLOAT, IS_DUE BOOLEAN, IS_OPEN BOOLEAN, IS_OVERDUE BOOLEAN, COUNTRY_NAME TEXT,
24
+ )
25
+
26
+
27
+ -- Using valid SQLite, answer the following questions for the tables provided
28
+ above.
29
+
30
+
31
+ -- how many work orders are open?
32
+
33
+
34
+ SELECT'
35
+ - example_title: Stadium capacity
36
+ text: 'CREATE TABLE stadium ( stadium_id number, location text, name text, capacity
37
+ number, highest number, lowest number, average number )
38
+
39
+
40
+ CREATE TABLE singer ( singer_id number, name text, country text, song_name text,
41
+ song_release_year text, age number, is_male others )
42
+
43
+
44
+ CREATE TABLE concert ( concert_id number, concert_name text, theme text, stadium_id
45
+ text, year text )
46
+
47
+
48
+ CREATE TABLE singer_in_concert ( concert_id number, singer_id text )
49
+
50
+
51
+ -- Using valid SQLite, answer the following questions for the tables provided
52
+ above.
53
+
54
+
55
+ -- What is the maximum, the average, and the minimum capacity of stadiums ?
56
+
57
+
58
+ SELECT'
59
+ ---
60
+ <!-- markdownlint-disable MD041 -->
61
+
62
+ <!-- header start -->
63
+ <!-- 200823 -->
64
+ <div style="width: auto; margin-left: auto; margin-right: auto">
65
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
66
+ </div>
67
+ <div style="display: flex; justify-content: space-between; width: 100%;">
68
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
69
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
70
+ </div>
71
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
72
+ <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>
73
+ </div>
74
+ </div>
75
+ <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>
76
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
77
+ <!-- header end -->
78
+
79
+ # NSQL Llama-2 7B - AWQ
80
+ - Model creator: [NumbersStation](https://huggingface.co/NumbersStation)
81
+ - Original model: [NSQL Llama-2 7B](https://huggingface.co/NumbersStation/nsql-llama-2-7B)
82
+
83
+ <!-- description start -->
84
+ ## Description
85
+
86
+ This repo contains AWQ model files for [NumbersStation's NSQL Llama-2 7B](https://huggingface.co/NumbersStation/nsql-llama-2-7B).
87
+
88
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
89
+
90
+
91
+ ### About AWQ
92
+
93
+ 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.
94
+
95
+ It is supported by:
96
+
97
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
98
+ - [vLLM](https://github.com/vllm-project/vllm) - Llama and Mistral models only
99
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
100
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
101
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
102
+
103
+ <!-- description end -->
104
+ <!-- repositories-available start -->
105
+ ## Repositories available
106
+
107
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/nsql-llama-2-7B-AWQ)
108
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/nsql-llama-2-7B-GPTQ)
109
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/nsql-llama-2-7B-GGUF)
110
+ * [NumbersStation's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/NumbersStation/nsql-llama-2-7B)
111
+ <!-- repositories-available end -->
112
+
113
+ <!-- prompt-template start -->
114
+ ## Prompt template: nsql
115
+
116
+ ```
117
+ {prompt}
118
+
119
+ SELECT
120
+
121
+ ```
122
+
123
+ <!-- prompt-template end -->
124
+
125
+
126
+ <!-- README_AWQ.md-provided-files start -->
127
+ ## Provided files, and AWQ parameters
128
+
129
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
130
+
131
+ Models are released as sharded safetensors files.
132
+
133
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
134
+ | ------ | ---- | -- | ----------- | ------- | ---- |
135
+ | [main](https://huggingface.co/TheBloke/nsql-llama-2-7B-AWQ/tree/main) | 4 | 128 | [code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1/viewer/) | 4096 | 3.89 GB
136
+
137
+ <!-- README_AWQ.md-provided-files end -->
138
+
139
+ <!-- README_AWQ.md-text-generation-webui start -->
140
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
141
+
142
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
143
+
144
+ 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.
145
+
146
+ 1. Click the **Model tab**.
147
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/nsql-llama-2-7B-AWQ`.
148
+ 3. Click **Download**.
149
+ 4. The model will start downloading. Once it's finished it will say "Done".
150
+ 5. In the top left, click the refresh icon next to **Model**.
151
+ 6. In the **Model** dropdown, choose the model you just downloaded: `nsql-llama-2-7B-AWQ`
152
+ 7. Select **Loader: AutoAWQ**.
153
+ 8. Click Load, and the model will load and is now ready for use.
154
+ 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.
155
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
156
+ <!-- README_AWQ.md-text-generation-webui end -->
157
+
158
+ <!-- README_AWQ.md-use-from-vllm start -->
159
+ ## Multi-user inference server: vLLM
160
+
161
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
162
+
163
+ - Please ensure you are using vLLM version 0.2 or later.
164
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
165
+
166
+ For example:
167
+
168
+ ```shell
169
+ python3 -m vllm.entrypoints.api_server --model TheBloke/nsql-llama-2-7B-AWQ --quantization awq --dtype auto
170
+ ```
171
+
172
+ - When using vLLM from Python code, again set `quantization=awq`.
173
+
174
+ For example:
175
+
176
+ ```python
177
+ from vllm import LLM, SamplingParams
178
+
179
+ prompts = [
180
+ "Tell me about AI",
181
+ "Write a story about llamas",
182
+ "What is 291 - 150?",
183
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
184
+ ]
185
+ prompt_template=f'''{prompt}
186
+
187
+ SELECT
188
+ '''
189
+
190
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
191
+
192
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
193
+
194
+ llm = LLM(model="TheBloke/nsql-llama-2-7B-AWQ", quantization="awq", dtype="auto")
195
+
196
+ outputs = llm.generate(prompts, sampling_params)
197
+
198
+ # Print the outputs.
199
+ for output in outputs:
200
+ prompt = output.prompt
201
+ generated_text = output.outputs[0].text
202
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
203
+ ```
204
+ <!-- README_AWQ.md-use-from-vllm start -->
205
+
206
+ <!-- README_AWQ.md-use-from-tgi start -->
207
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
208
+
209
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
210
+
211
+ Example Docker parameters:
212
+
213
+ ```shell
214
+ --model-id TheBloke/nsql-llama-2-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
215
+ ```
216
+
217
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
218
+
219
+ ```shell
220
+ pip3 install huggingface-hub
221
+ ```
222
+
223
+ ```python
224
+ from huggingface_hub import InferenceClient
225
+
226
+ endpoint_url = "https://your-endpoint-url-here"
227
+
228
+ prompt = "Tell me about AI"
229
+ prompt_template=f'''{prompt}
230
+
231
+ SELECT
232
+ '''
233
+
234
+ client = InferenceClient(endpoint_url)
235
+ response = client.text_generation(prompt,
236
+ max_new_tokens=128,
237
+ do_sample=True,
238
+ temperature=0.7,
239
+ top_p=0.95,
240
+ top_k=40,
241
+ repetition_penalty=1.1)
242
+
243
+ print(f"Model output: ", response)
244
+ ```
245
+ <!-- README_AWQ.md-use-from-tgi end -->
246
+
247
+ <!-- README_AWQ.md-use-from-python start -->
248
+ ## Inference from Python code using Transformers
249
+
250
+ ### Install the necessary packages
251
+
252
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
253
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
254
+
255
+ ```shell
256
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
257
+ ```
258
+
259
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
260
+
261
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
262
+
263
+ ```shell
264
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
265
+ ```
266
+
267
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
268
+
269
+ ```shell
270
+ pip3 uninstall -y autoawq
271
+ git clone https://github.com/casper-hansen/AutoAWQ
272
+ cd AutoAWQ
273
+ pip3 install .
274
+ ```
275
+
276
+ ### Transformers example code (requires Transformers 4.35.0 and later)
277
+
278
+ ```python
279
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
280
+
281
+ model_name_or_path = "TheBloke/nsql-llama-2-7B-AWQ"
282
+
283
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
284
+ model = AutoModelForCausalLM.from_pretrained(
285
+ model_name_or_path,
286
+ low_cpu_mem_usage=True,
287
+ device_map="cuda:0"
288
+ )
289
+
290
+ # Using the text streamer to stream output one token at a time
291
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
292
+
293
+ prompt = "Tell me about AI"
294
+ prompt_template=f'''{prompt}
295
+
296
+ SELECT
297
+ '''
298
+
299
+ # Convert prompt to tokens
300
+ tokens = tokenizer(
301
+ prompt_template,
302
+ return_tensors='pt'
303
+ ).input_ids.cuda()
304
+
305
+ generation_params = {
306
+ "do_sample": True,
307
+ "temperature": 0.7,
308
+ "top_p": 0.95,
309
+ "top_k": 40,
310
+ "max_new_tokens": 512,
311
+ "repetition_penalty": 1.1
312
+ }
313
+
314
+ # Generate streamed output, visible one token at a time
315
+ generation_output = model.generate(
316
+ tokens,
317
+ streamer=streamer,
318
+ **generation_params
319
+ )
320
+
321
+ # Generation without a streamer, which will include the prompt in the output
322
+ generation_output = model.generate(
323
+ tokens,
324
+ **generation_params
325
+ )
326
+
327
+ # Get the tokens from the output, decode them, print them
328
+ token_output = generation_output[0]
329
+ text_output = tokenizer.decode(token_output)
330
+ print("model.generate output: ", text_output)
331
+
332
+ # Inference is also possible via Transformers' pipeline
333
+ from transformers import pipeline
334
+
335
+ pipe = pipeline(
336
+ "text-generation",
337
+ model=model,
338
+ tokenizer=tokenizer,
339
+ **generation_params
340
+ )
341
+
342
+ pipe_output = pipe(prompt_template)[0]['generated_text']
343
+ print("pipeline output: ", pipe_output)
344
+
345
+ ```
346
+ <!-- README_AWQ.md-use-from-python end -->
347
+
348
+ <!-- README_AWQ.md-compatibility start -->
349
+ ## Compatibility
350
+
351
+ The files provided are tested to work with:
352
+
353
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
354
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
355
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
356
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
357
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
358
+
359
+ <!-- README_AWQ.md-compatibility end -->
360
+
361
+ <!-- footer start -->
362
+ <!-- 200823 -->
363
+ ## Discord
364
+
365
+ For further support, and discussions on these models and AI in general, join us at:
366
+
367
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
368
+
369
+ ## Thanks, and how to contribute
370
+
371
+ Thanks to the [chirper.ai](https://chirper.ai) team!
372
+
373
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
374
+
375
+ 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.
376
+
377
+ 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.
378
+
379
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
380
+
381
+ * Patreon: https://patreon.com/TheBlokeAI
382
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
383
+
384
+ **Special thanks to**: Aemon Algiz.
385
+
386
+ **Patreon special mentions**: Brandon Frisco, LangChain4j, Spiking Neurons AB, transmissions 11, Joseph William Delisle, Nitin Borwankar, Willem Michiel, Michael Dempsey, vamX, Jeffrey Morgan, zynix, jjj, Omer Bin Jawed, Sean Connelly, jinyuan sun, Jeromy Smith, Shadi, Pawan Osman, Chadd, Elijah Stavena, Illia Dulskyi, Sebastain Graf, Stephen Murray, terasurfer, Edmond Seymore, Celu Ramasamy, Mandus, Alex, biorpg, Ajan Kanaga, Clay Pascal, Raven Klaugh, 阿明, K, ya boyyy, usrbinkat, Alicia Loh, John Villwock, ReadyPlayerEmma, Chris Smitley, Cap'n Zoog, fincy, GodLy, S_X, sidney chen, Cory Kujawski, OG, Mano Prime, AzureBlack, Pieter, Kalila, Spencer Kim, Tom X Nguyen, Stanislav Ovsiannikov, Michael Levine, Andrey, Trailburnt, Vadim, Enrico Ros, Talal Aujan, Brandon Phillips, Jack West, Eugene Pentland, Michael Davis, Will Dee, webtim, Jonathan Leane, Alps Aficionado, Rooh Singh, Tiffany J. Kim, theTransient, Luke @flexchar, Elle, Caitlyn Gatomon, Ari Malik, subjectnull, Johann-Peter Hartmann, Trenton Dambrowitz, Imad Khwaja, Asp the Wyvern, Emad Mostaque, Rainer Wilmers, Alexandros Triantafyllidis, Nicholas, Pedro Madruga, SuperWojo, Harry Royden McLaughlin, James Bentley, Olakabola, David Ziegler, Ai Maven, Jeff Scroggin, Nikolai Manek, Deo Leter, Matthew Berman, Fen Risland, Ken Nordquist, Manuel Alberto Morcote, Luke Pendergrass, TL, Fred von Graf, Randy H, Dan Guido, NimbleBox.ai, Vitor Caleffi, Gabriel Tamborski, knownsqashed, Lone Striker, Erik Bjäreholt, John Detwiler, Leonard Tan, Iucharbius
387
+
388
+
389
+ Thank you to all my generous patrons and donaters!
390
+
391
+ And thank you again to a16z for their generous grant.
392
+
393
+ <!-- footer end -->
394
+
395
+ # Original model card: NumbersStation's NSQL Llama-2 7B
396
+
397
+
398
+ # NSQL-Llama-2-7B
399
+
400
+ ## Model Description
401
+
402
+ NSQL is a family of autoregressive open-source large foundation models (FMs) designed specifically for SQL generation tasks.
403
+
404
+ In this repository we are introducing a new member of NSQL, NSQL-Llama-2-7B. It's based on Meta's original [Llama-2 7B model](https://huggingface.co/meta-llama/Llama-2-7b) and further pre-trained on a dataset of general SQL queries and then fine-tuned on a dataset composed of text-to-SQL pairs.
405
+
406
+ ## Training Data
407
+
408
+ The general SQL queries are the SQL subset from [The Stack](https://huggingface.co/datasets/bigcode/the-stack), containing 1M training samples. The labeled text-to-SQL pairs come from more than 20 public sources across the web from standard datasets. We hold out Spider and GeoQuery datasets for use in evaluation.
409
+
410
+ ## Evaluation Data
411
+
412
+ We evaluate our models on two text-to-SQL benchmarks: Spider and GeoQuery.
413
+
414
+ ## Training Procedure
415
+
416
+ NSQL was trained using cross-entropy loss to maximize the likelihood of sequential inputs. For finetuning on text-to-SQL pairs, we only compute the loss over the SQL portion of the pair. The model is trained using 80GB A100s, leveraging data and model parallelism. We pre-trained for 3 epochs and fine-tuned for 10 epochs.
417
+
418
+ ## Intended Use and Limitations
419
+
420
+ The model was designed for text-to-SQL generation tasks from given table schema and natural language prompts. The model works best with the prompt format defined below and outputting `SELECT` queries.
421
+
422
+ ## How to Use
423
+
424
+ Example 1:
425
+
426
+ ```python
427
+ import torch
428
+ from transformers import AutoTokenizer, AutoModelForCausalLM
429
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-llama-2-7B")
430
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-llama-2-7B", torch_dtype=torch.bfloat16)
431
+
432
+ text = """CREATE TABLE stadium (
433
+ stadium_id number,
434
+ location text,
435
+ name text,
436
+ capacity number,
437
+ highest number,
438
+ lowest number,
439
+ average number
440
+ )
441
+
442
+ CREATE TABLE singer (
443
+ singer_id number,
444
+ name text,
445
+ country text,
446
+ song_name text,
447
+ song_release_year text,
448
+ age number,
449
+ is_male others
450
+ )
451
+
452
+ CREATE TABLE concert (
453
+ concert_id number,
454
+ concert_name text,
455
+ theme text,
456
+ stadium_id text,
457
+ year text
458
+ )
459
+
460
+ CREATE TABLE singer_in_concert (
461
+ concert_id number,
462
+ singer_id text
463
+ )
464
+
465
+ -- Using valid SQLite, answer the following questions for the tables provided above.
466
+
467
+ -- What is the maximum, the average, and the minimum capacity of stadiums ?
468
+
469
+ SELECT"""
470
+
471
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
472
+
473
+ generated_ids = model.generate(input_ids, max_length=500)
474
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
475
+ ```
476
+
477
+ Example 2:
478
+
479
+ ```python
480
+ import torch
481
+ from transformers import AutoTokenizer, AutoModelForCausalLM
482
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-llama-2-7B")
483
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-llama-2-7B", torch_dtype=torch.bfloat16)
484
+
485
+ text = """CREATE TABLE stadium (
486
+ stadium_id number,
487
+ location text,
488
+ name text,
489
+ capacity number,
490
+ )
491
+
492
+ -- Using valid SQLite, answer the following questions for the tables provided above.
493
+
494
+ -- how many stadiums in total?
495
+
496
+ SELECT"""
497
+
498
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
499
+
500
+ generated_ids = model.generate(input_ids, max_length=500)
501
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
502
+ ```
503
+
504
+ Example 3:
505
+
506
+ ```python
507
+ import torch
508
+ from transformers import AutoTokenizer, AutoModelForCausalLM
509
+ tokenizer = AutoTokenizer.from_pretrained("NumbersStation/nsql-llama-2-7B")
510
+ model = AutoModelForCausalLM.from_pretrained("NumbersStation/nsql-llama-2-7B", torch_dtype=torch.bfloat16)
511
+
512
+ text = """CREATE TABLE work_orders (
513
+ ID NUMBER,
514
+ CREATED_AT TEXT,
515
+ COST FLOAT,
516
+ INVOICE_AMOUNT FLOAT,
517
+ IS_DUE BOOLEAN,
518
+ IS_OPEN BOOLEAN,
519
+ IS_OVERDUE BOOLEAN,
520
+ COUNTRY_NAME TEXT,
521
+ )
522
+
523
+ -- Using valid SQLite, answer the following questions for the tables provided above.
524
+
525
+ -- how many work orders are open?
526
+
527
+ SELECT"""
528
+
529
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
530
+
531
+ generated_ids = model.generate(input_ids, max_length=500)
532
+ print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
533
+ ```
534
+
535
+
536
+
537
+ For more information (e.g., run with your local database), please find examples in [this repository](https://github.com/NumbersStationAI/NSQL).