TheBloke commited on
Commit
ac7bbea
1 Parent(s): 174876e

Upload README.md

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