TheBloke commited on
Commit
3a7b291
·
1 Parent(s): b3bdd46

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +521 -0
README.md ADDED
@@ -0,0 +1,521 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: defog/sqlcoder-7b
3
+ inference: false
4
+ language:
5
+ - en
6
+ license: cc-by-sa-4.0
7
+ model_creator: Defog.ai
8
+ model_name: SQLCoder 7B
9
+ model_type: mistral
10
+ pipeline_tag: text-generation
11
+ prompt_template: "## Task\nGenerate a SQL query to answer the following question:\n\
12
+ `{prompt}`\n\n### Database Schema\nThis query will run on a database whose schema\
13
+ \ is represented in this string:\nCREATE TABLE products (\n product_id INTEGER\
14
+ \ PRIMARY KEY, -- Unique ID for each product\n name VARCHAR(50), -- Name of the\
15
+ \ product\n price DECIMAL(10,2), -- Price of each unit of the product\n quantity\
16
+ \ INTEGER -- Current quantity in stock\n);\n\nCREATE TABLE sales (\n sale_id INTEGER\
17
+ \ PRIMARY KEY, -- Unique ID for each sale\n product_id INTEGER, -- ID of product\
18
+ \ sold\n customer_id INTEGER, -- ID of customer who made purchase\n salesperson_id\
19
+ \ INTEGER, -- ID of salesperson who made the sale\n sale_date DATE, -- Date the\
20
+ \ sale occurred\n quantity INTEGER -- Quantity of product sold\n);\n\n-- sales.product_id\
21
+ \ can be joined with products.product_id\n\n### SQL\nGiven the database schema,\
22
+ \ here is the SQL query that answers `{prompt}`:\n```sql\n"
23
+ quantized_by: TheBloke
24
+ tags:
25
+ - code
26
+ ---
27
+ <!-- markdownlint-disable MD041 -->
28
+
29
+ <!-- header start -->
30
+ <!-- 200823 -->
31
+ <div style="width: auto; margin-left: auto; margin-right: auto">
32
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
33
+ </div>
34
+ <div style="display: flex; justify-content: space-between; width: 100%;">
35
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
36
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
37
+ </div>
38
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
39
+ <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>
40
+ </div>
41
+ </div>
42
+ <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>
43
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
44
+ <!-- header end -->
45
+
46
+ # SQLCoder 7B - AWQ
47
+ - Model creator: [Defog.ai](https://huggingface.co/defog)
48
+ - Original model: [SQLCoder 7B](https://huggingface.co/defog/sqlcoder-7b)
49
+
50
+ <!-- description start -->
51
+ ## Description
52
+
53
+ This repo contains AWQ model files for [Defog.ai's SQLCoder 7B](https://huggingface.co/defog/sqlcoder-7b).
54
+
55
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
56
+
57
+
58
+ ### About AWQ
59
+
60
+ 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.
61
+
62
+ It is supported by:
63
+
64
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
65
+ - [vLLM](https://github.com/vllm-project/vllm) - Llama and Mistral models only
66
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
67
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
68
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
69
+
70
+ <!-- description end -->
71
+ <!-- repositories-available start -->
72
+ ## Repositories available
73
+
74
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/sqlcoder-7B-AWQ)
75
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/sqlcoder-7B-GPTQ)
76
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/sqlcoder-7B-GGUF)
77
+ * [Defog.ai's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/defog/sqlcoder-7b)
78
+ <!-- repositories-available end -->
79
+
80
+ <!-- prompt-template start -->
81
+ ## Prompt template: Sqlcoder
82
+
83
+ ```
84
+ ## Task
85
+ Generate a SQL query to answer the following question:
86
+ `{prompt}`
87
+
88
+ ### Database Schema
89
+ This query will run on a database whose schema is represented in this string:
90
+ CREATE TABLE products (
91
+ product_id INTEGER PRIMARY KEY, -- Unique ID for each product
92
+ name VARCHAR(50), -- Name of the product
93
+ price DECIMAL(10,2), -- Price of each unit of the product
94
+ quantity INTEGER -- Current quantity in stock
95
+ );
96
+
97
+ CREATE TABLE sales (
98
+ sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
99
+ product_id INTEGER, -- ID of product sold
100
+ customer_id INTEGER, -- ID of customer who made purchase
101
+ salesperson_id INTEGER, -- ID of salesperson who made the sale
102
+ sale_date DATE, -- Date the sale occurred
103
+ quantity INTEGER -- Quantity of product sold
104
+ );
105
+
106
+ -- sales.product_id can be joined with products.product_id
107
+
108
+ ### SQL
109
+ Given the database schema, here is the SQL query that answers `{prompt}`:
110
+ ```sql
111
+
112
+ ```
113
+
114
+ <!-- prompt-template end -->
115
+
116
+
117
+ <!-- README_AWQ.md-provided-files start -->
118
+ ## Provided files, and AWQ parameters
119
+
120
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
121
+
122
+ Models are released as sharded safetensors files.
123
+
124
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
125
+ | ------ | ---- | -- | ----------- | ------- | ---- |
126
+ | [main](https://huggingface.co/TheBloke/sqlcoder-7B-AWQ/tree/main) | 4 | 128 | [code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1/viewer/) | 4096 | 4.15 GB
127
+
128
+ <!-- README_AWQ.md-provided-files end -->
129
+
130
+ <!-- README_AWQ.md-text-generation-webui start -->
131
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
132
+
133
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
134
+
135
+ 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.
136
+
137
+ 1. Click the **Model tab**.
138
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/sqlcoder-7B-AWQ`.
139
+ 3. Click **Download**.
140
+ 4. The model will start downloading. Once it's finished it will say "Done".
141
+ 5. In the top left, click the refresh icon next to **Model**.
142
+ 6. In the **Model** dropdown, choose the model you just downloaded: `sqlcoder-7B-AWQ`
143
+ 7. Select **Loader: AutoAWQ**.
144
+ 8. Click Load, and the model will load and is now ready for use.
145
+ 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.
146
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
147
+ <!-- README_AWQ.md-text-generation-webui end -->
148
+
149
+ <!-- README_AWQ.md-use-from-vllm start -->
150
+ ## Multi-user inference server: vLLM
151
+
152
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
153
+
154
+ - Please ensure you are using vLLM version 0.2 or later.
155
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
156
+
157
+ For example:
158
+
159
+ ```shell
160
+ python3 -m vllm.entrypoints.api_server --model TheBloke/sqlcoder-7B-AWQ --quantization awq --dtype auto
161
+ ```
162
+
163
+ - When using vLLM from Python code, again set `quantization=awq`.
164
+
165
+ For example:
166
+
167
+ ```python
168
+ from vllm import LLM, SamplingParams
169
+
170
+ prompts = [
171
+ "Tell me about AI",
172
+ "Write a story about llamas",
173
+ "What is 291 - 150?",
174
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
175
+ ]
176
+ prompt_template=f'''## Task
177
+ Generate a SQL query to answer the following question:
178
+ `{prompt}`
179
+
180
+ ### Database Schema
181
+ This query will run on a database whose schema is represented in this string:
182
+ CREATE TABLE products (
183
+ product_id INTEGER PRIMARY KEY, -- Unique ID for each product
184
+ name VARCHAR(50), -- Name of the product
185
+ price DECIMAL(10,2), -- Price of each unit of the product
186
+ quantity INTEGER -- Current quantity in stock
187
+ );
188
+
189
+ CREATE TABLE sales (
190
+ sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
191
+ product_id INTEGER, -- ID of product sold
192
+ customer_id INTEGER, -- ID of customer who made purchase
193
+ salesperson_id INTEGER, -- ID of salesperson who made the sale
194
+ sale_date DATE, -- Date the sale occurred
195
+ quantity INTEGER -- Quantity of product sold
196
+ );
197
+
198
+ -- sales.product_id can be joined with products.product_id
199
+
200
+ ### SQL
201
+ Given the database schema, here is the SQL query that answers `{prompt}`:
202
+ ```sql
203
+ '''
204
+
205
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
206
+
207
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
208
+
209
+ llm = LLM(model="TheBloke/sqlcoder-7B-AWQ", quantization="awq", dtype="auto")
210
+
211
+ outputs = llm.generate(prompts, sampling_params)
212
+
213
+ # Print the outputs.
214
+ for output in outputs:
215
+ prompt = output.prompt
216
+ generated_text = output.outputs[0].text
217
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
218
+ ```
219
+ <!-- README_AWQ.md-use-from-vllm start -->
220
+
221
+ <!-- README_AWQ.md-use-from-tgi start -->
222
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
223
+
224
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
225
+
226
+ Example Docker parameters:
227
+
228
+ ```shell
229
+ --model-id TheBloke/sqlcoder-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
230
+ ```
231
+
232
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
233
+
234
+ ```shell
235
+ pip3 install huggingface-hub
236
+ ```
237
+
238
+ ```python
239
+ from huggingface_hub import InferenceClient
240
+
241
+ endpoint_url = "https://your-endpoint-url-here"
242
+
243
+ prompt = "Tell me about AI"
244
+ prompt_template=f'''## Task
245
+ Generate a SQL query to answer the following question:
246
+ `{prompt}`
247
+
248
+ ### Database Schema
249
+ This query will run on a database whose schema is represented in this string:
250
+ CREATE TABLE products (
251
+ product_id INTEGER PRIMARY KEY, -- Unique ID for each product
252
+ name VARCHAR(50), -- Name of the product
253
+ price DECIMAL(10,2), -- Price of each unit of the product
254
+ quantity INTEGER -- Current quantity in stock
255
+ );
256
+
257
+ CREATE TABLE sales (
258
+ sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
259
+ product_id INTEGER, -- ID of product sold
260
+ customer_id INTEGER, -- ID of customer who made purchase
261
+ salesperson_id INTEGER, -- ID of salesperson who made the sale
262
+ sale_date DATE, -- Date the sale occurred
263
+ quantity INTEGER -- Quantity of product sold
264
+ );
265
+
266
+ -- sales.product_id can be joined with products.product_id
267
+
268
+ ### SQL
269
+ Given the database schema, here is the SQL query that answers `{prompt}`:
270
+ ```sql
271
+ '''
272
+
273
+ client = InferenceClient(endpoint_url)
274
+ response = client.text_generation(prompt,
275
+ max_new_tokens=128,
276
+ do_sample=True,
277
+ temperature=0.7,
278
+ top_p=0.95,
279
+ top_k=40,
280
+ repetition_penalty=1.1)
281
+
282
+ print(f"Model output: ", response)
283
+ ```
284
+ <!-- README_AWQ.md-use-from-tgi end -->
285
+
286
+ <!-- README_AWQ.md-use-from-python start -->
287
+ ## Inference from Python code using Transformers
288
+
289
+ ### Install the necessary packages
290
+
291
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
292
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
293
+
294
+ ```shell
295
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
296
+ ```
297
+
298
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
299
+
300
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
301
+
302
+ ```shell
303
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
304
+ ```
305
+
306
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
307
+
308
+ ```shell
309
+ pip3 uninstall -y autoawq
310
+ git clone https://github.com/casper-hansen/AutoAWQ
311
+ cd AutoAWQ
312
+ pip3 install .
313
+ ```
314
+
315
+ ### Transformers example code (requires Transformers 4.35.0 and later)
316
+
317
+ ```python
318
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
319
+
320
+ model_name_or_path = "TheBloke/sqlcoder-7B-AWQ"
321
+
322
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
323
+ model = AutoModelForCausalLM.from_pretrained(
324
+ model_name_or_path,
325
+ low_cpu_mem_usage=True,
326
+ device_map="cuda:0"
327
+ )
328
+
329
+ # Using the text streamer to stream output one token at a time
330
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
331
+
332
+ prompt = "Tell me about AI"
333
+ prompt_template=f'''## Task
334
+ Generate a SQL query to answer the following question:
335
+ `{prompt}`
336
+
337
+ ### Database Schema
338
+ This query will run on a database whose schema is represented in this string:
339
+ CREATE TABLE products (
340
+ product_id INTEGER PRIMARY KEY, -- Unique ID for each product
341
+ name VARCHAR(50), -- Name of the product
342
+ price DECIMAL(10,2), -- Price of each unit of the product
343
+ quantity INTEGER -- Current quantity in stock
344
+ );
345
+
346
+ CREATE TABLE sales (
347
+ sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
348
+ product_id INTEGER, -- ID of product sold
349
+ customer_id INTEGER, -- ID of customer who made purchase
350
+ salesperson_id INTEGER, -- ID of salesperson who made the sale
351
+ sale_date DATE, -- Date the sale occurred
352
+ quantity INTEGER -- Quantity of product sold
353
+ );
354
+
355
+ -- sales.product_id can be joined with products.product_id
356
+
357
+ ### SQL
358
+ Given the database schema, here is the SQL query that answers `{prompt}`:
359
+ ```sql
360
+ '''
361
+
362
+ # Convert prompt to tokens
363
+ tokens = tokenizer(
364
+ prompt_template,
365
+ return_tensors='pt'
366
+ ).input_ids.cuda()
367
+
368
+ generation_params = {
369
+ "do_sample": True,
370
+ "temperature": 0.7,
371
+ "top_p": 0.95,
372
+ "top_k": 40,
373
+ "max_new_tokens": 512,
374
+ "repetition_penalty": 1.1
375
+ }
376
+
377
+ # Generate streamed output, visible one token at a time
378
+ generation_output = model.generate(
379
+ tokens,
380
+ streamer=streamer,
381
+ **generation_params
382
+ )
383
+
384
+ # Generation without a streamer, which will include the prompt in the output
385
+ generation_output = model.generate(
386
+ tokens,
387
+ **generation_params
388
+ )
389
+
390
+ # Get the tokens from the output, decode them, print them
391
+ token_output = generation_output[0]
392
+ text_output = tokenizer.decode(token_output)
393
+ print("model.generate output: ", text_output)
394
+
395
+ # Inference is also possible via Transformers' pipeline
396
+ from transformers import pipeline
397
+
398
+ pipe = pipeline(
399
+ "text-generation",
400
+ model=model,
401
+ tokenizer=tokenizer,
402
+ **generation_params
403
+ )
404
+
405
+ pipe_output = pipe(prompt_template)[0]['generated_text']
406
+ print("pipeline output: ", pipe_output)
407
+
408
+ ```
409
+ <!-- README_AWQ.md-use-from-python end -->
410
+
411
+ <!-- README_AWQ.md-compatibility start -->
412
+ ## Compatibility
413
+
414
+ The files provided are tested to work with:
415
+
416
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
417
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
418
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
419
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
420
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
421
+
422
+ <!-- README_AWQ.md-compatibility end -->
423
+
424
+ <!-- footer start -->
425
+ <!-- 200823 -->
426
+ ## Discord
427
+
428
+ For further support, and discussions on these models and AI in general, join us at:
429
+
430
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
431
+
432
+ ## Thanks, and how to contribute
433
+
434
+ Thanks to the [chirper.ai](https://chirper.ai) team!
435
+
436
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
437
+
438
+ 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.
439
+
440
+ 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.
441
+
442
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
443
+
444
+ * Patreon: https://patreon.com/TheBlokeAI
445
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
446
+
447
+ **Special thanks to**: Aemon Algiz.
448
+
449
+ **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
450
+
451
+
452
+ Thank you to all my generous patrons and donaters!
453
+
454
+ And thank you again to a16z for their generous grant.
455
+
456
+ <!-- footer end -->
457
+
458
+ # Original model card: Defog.ai's SQLCoder 7B
459
+
460
+ # Defog SQLCoder
461
+ Defog's SQLCoder is a state-of-the-art LLM for converting natural language questions to SQL queries.
462
+
463
+ [Interactive Demo](https://defog.ai/sqlcoder-demo/) | [🤗 HF Repo](https://huggingface.co/defog/sqlcoder2) | [♾️ Colab](https://colab.research.google.com/drive/1z4rmOEiFkxkMiecAWeTUlPl0OmKgfEu7?usp=sharing) | [🐦 Twitter](https://twitter.com/defogdata)
464
+
465
+ ## TL;DR
466
+ SQLCoder-7B is a 7B parameter model that outperforms `gpt-3.5-turbo` for natural language to SQL generation tasks on our [sql-eval](https://github.com/defog-ai/sql-eval) framework, and significantly outperforms all popular open-source models. When fine-tuned on a given schema, it also outperforms `gpt-4`
467
+
468
+ SQLCoder-7B is fine-tuned on a base Mistral-7B model.
469
+
470
+ ## Results on novel datasets not seen in training
471
+ | model | perc_correct |
472
+ |-|-|
473
+ | gpt4-2023-10-04 | 82.0 |
474
+ | defog-sqlcoder2 | 74.5 |
475
+ | gpt4-2023-08-28 | 74.0 |
476
+ | defog-sqlcoder-7b | 71.0 |
477
+ | gpt-3.5-2023-10-04 | 66.0 |
478
+ | claude-2 | 64.5 |
479
+ | gpt-3.5-2023-08-28 | 61.0 |
480
+ | claude_instant_1 | 61.0 |
481
+ | text-davinci-003 | 52.5 |
482
+
483
+ ## License
484
+ The code in this repo (what little there is of it) is Apache-2 licensed. The model weights have a `CC BY-SA 4.0` license. The TL;DR is that you can use and modify the model for any purpose – including commercial use. However, if you modify the weights (for example, by fine-tuning), you must open-source your modified weights under the same license terms.
485
+
486
+ ## Training
487
+ SQLCoder was trained on more than 20,000 human-curated questions. These questions were based on 10 different schemas. None of the schemas in the training data were included in our evaluation framework.
488
+
489
+ You can read more about our [training approach](https://defog.ai/blog/open-sourcing-sqlcoder2-7b/) and [evaluation framework](https://defog.ai/blog/open-sourcing-sqleval/).
490
+
491
+ ## Results by question category
492
+ We classified each generated question into one of 5 categories. The table displays the percentage of questions answered correctly by each model, broken down by category.
493
+ | query_category | gpt-4 | sqlcoder2-15b | sqlcoder-7b | gpt-3.5 | claude-2 | claude-instant | gpt-3 |
494
+ |:-----------------|--------:|----------------:|--------------:|----------:|-----------:|-----------------:|--------:|
495
+ | date | 72 | 76 | 64 | 68 | 52 | 48 | 32 |
496
+ | group_by | 91.4 | 80 | 82.9 | 77.1 | 71.4 | 71.4 | 71.4 |
497
+ | order_by | 82.9 | 77.1 | 74.3 | 68.6 | 74.3 | 74.3 | 68.6 |
498
+ | ratio | 80 | 60 | 54.3 | 37.1 | 57.1 | 45.7 | 25.7 |
499
+ | join | 82.9 | 77.1 | 74.3 | 71.4 | 65.7 | 62.9 | 57.1 |
500
+ | where | 80 | 77.1 | 74.3 | 74.3 | 62.9 | 60 | 54.3 |
501
+
502
+ ## Using SQLCoder
503
+ You can use SQLCoder via the `transformers` library by downloading our model weights from the Hugging Face repo. We have added sample code for [inference](./inference.py) on a [sample database schema](./metadata.sql).
504
+ ```bash
505
+ python inference.py -q "Question about the sample database goes here"
506
+
507
+ # Sample question:
508
+ # Do we get more revenue from customers in New York compared to customers in San Francisco? Give me the total revenue for each city, and the difference between the two.
509
+ ```
510
+
511
+ You can also use a demo on our website [here](https://defog.ai/sqlcoder-demo), or run SQLCoder in Colab [here](https://colab.research.google.com/drive/13BIKsqHnPOBcQ-ba2p77L5saiepTIwu0#scrollTo=ZpbVgVHMkJvC)
512
+
513
+ ## Hardware Requirements
514
+ SQLCoder has been tested on an A100 40GB GPU with `bfloat16` weights. You can also load an 8-bit and 4-bit quantized version of the model on consumer GPUs with 20GB or more of memory – like RTX 4090, RTX 3090, and Apple M2 Pro, M2 Max, or M2 Ultra Chips with 20GB or more of memory.
515
+
516
+ ## Todo
517
+
518
+ - [x] Open-source the v1 model weights
519
+ - [x] Train the model on more data, with higher data variance
520
+ - [ ] Tune the model further with Reward Modelling and RLHF
521
+ - [ ] Pretrain a model from scratch that specializes in SQL analysis