Commit
·
e760888
1
Parent(s):
1e0979d
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: llama2
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
pipeline_tag: text-generation
|
6 |
+
|
7 |
+
---
|
8 |
+
# **Code-Llama-2-13B-instruct-text2sql-GPTQ Model Card**
|
9 |
+
|
10 |
+
**Model Name**: Code-Llama-2-13B-instruct-text2sql-GPTQ
|
11 |
+
|
12 |
+
**Description**: This model is a GPTQ quantisation of a fine-tuned version of the Code Llama 2 with 13 billion parameters, specifically tailored for text-to-SQL tasks. It has been trained to generate SQL queries given a database schema and a natural language question. The GPTQ quantisation was performed with AutoGPTQ.
|
13 |
+
|
14 |
+
## Model Information
|
15 |
+
|
16 |
+
- **Base Model**: [bugdaryan/Code-Llama-2-13B-instruct-text2sql](https://huggingface.co/bugdaryan/Code-Llama-2-13B-instruct-text2sql)
|
17 |
+
|
18 |
+
## GPTQ Parameters
|
19 |
+
|
20 |
+
- **bits**: 4
|
21 |
+
- **group_size**: 128
|
22 |
+
- **desc_act**: False
|
23 |
+
- **damp_percent**: 0.01
|
24 |
+
|
25 |
+
## GPTQ dataset
|
26 |
+
|
27 |
+
- **Dataset**: [bugdaryan/sql-create-context-instruction](https://huggingface.co/bugdaryan/sql-create-context-instruction)
|
28 |
+
- **Randomized Rows**: 1024
|
29 |
+
|
30 |
+
## License
|
31 |
+
|
32 |
+
This model is governed by a custom commercial license from Code Llama. For details, please visit: [Custom Commercial License](https://ai.meta.com/resources/models-and-libraries/llama-downloads/)
|
33 |
+
|
34 |
+
## Intended Use
|
35 |
+
|
36 |
+
**Intended Use Cases**: This model is intended for commercial and research use in English. It is designed for text-to-SQL tasks, enabling users to generate SQL queries from natural language questions.
|
37 |
+
|
38 |
+
**Out-of-Scope Uses**: Any use that violates applicable laws or regulations, use in languages other than English, or any other use prohibited by the Acceptable Use Policy and Licensing Agreement for Code Llama and its variants.
|
39 |
+
|
40 |
+
## Example Code
|
41 |
+
|
42 |
+
You can use the Code-Llama-2-13B-instruct-text2sql-GPTQ model to generate SQL queries from natural language questions, as demonstrated in the following code snippet:
|
43 |
+
```cmd
|
44 |
+
pip install -q accelerate transformers optimum auto-gptq
|
45 |
+
```
|
46 |
+
|
47 |
+
```python
|
48 |
+
import torch
|
49 |
+
from transformers import AutoTokenizer
|
50 |
+
from auto_gptq import AutoGPTQForCausalLM
|
51 |
+
|
52 |
+
model_name = 'support-pvelocity/Code-Llama-2-13B-instruct-text2sql-GPTQ'
|
53 |
+
|
54 |
+
model = AutoGPTQForCausalLM.from_quantized(model_name, use_safetensors=True, device_map='auto')
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
56 |
+
|
57 |
+
table = "CREATE TABLE sales ( sale_id number PRIMARY KEY, product_id number, customer_id number, salesperson_id number, sale_date DATE, quantity number, FOREIGN KEY (product_id) REFERENCES products(product_id), FOREIGN KEY (customer_id) REFERENCES customers(customer_id), FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id)); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number, FOREIGN KEY (product_id) REFERENCES products(product_id)); CREATE TABLE customers ( customer_id number PRIMARY KEY, name text, address text ); CREATE TABLE salespeople ( salesperson_id number PRIMARY KEY, name text, region text ); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number );"
|
58 |
+
|
59 |
+
question = 'Find the salesperson who made the most sales.'
|
60 |
+
|
61 |
+
prompt = f"[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: {table} Question: {question} [/INST] Here is the SQLite query to answer to the question: {question}: ``` "
|
62 |
+
|
63 |
+
tokens = tokenizer(prompt, return_tensors="pt").to('cuda:0')
|
64 |
+
input_ids = tokens.input_ids
|
65 |
+
|
66 |
+
generated_ids = model.generate(input_ids=input_ids, max_length=4048, pad_token_id=tokenizer.eos_token_id)
|
67 |
+
output = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
68 |
+
output = output.split('```')[2]
|
69 |
+
print(output)
|
70 |
+
```
|
71 |
+
|
72 |
+
This code demonstrates how to utilize the model for generating SQL queries based on a provided database schema and a natural language question. It showcases the model's capability to assist in SQL query generation for text-to-SQL tasks.
|