File size: 2,522 Bytes
ae4ce30
80c8bf0
503f4be
 
 
 
ae4ce30
 
 
 
 
 
 
503f4be
ae4ce30
 
 
80c8bf0
503f4be
ae4ce30
503f4be
ae4ce30
503f4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b7f866
503f4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae4ce30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
base_model: unsloth/Phi-3-mini-4k-instruct
datasets:
- b-mc2/sql-create-context
- Clinton/Text-to-sql-v1
- knowrohit07/know_sql
language:
- en
license: apache-2.0
tags:
- text-generation-inference
- transformers
- unsloth
- phi-3
- trl
---

This is a **unsloth/Phi-3-mini-4k-instruct**  model, fine-tuned on **[b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context)**, **[Clinton/Text-to-sql-v1](https://huggingface.co/datasets/Clinton/Text-to-sql-v1)** and **[knowrohit07/know_sql](https://huggingface.co/datasets/knowrohit07/know_sql)** 
dataset. 

## Model Usage

Use the `unsloth` library to laod and run the model.

Install `unsloth` and other dependencies.

```python
# Installs Unsloth, Xformers (Flash Attention) and all other packages!
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
!pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes torch
```

Use `FastLanguageModel` to download and laod the model from hf hub.

```python
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "dmedhi/Phi-3-mini-4k-instruct-text2SQL",
    max_seq_length = 2048
    dtype = None
    load_in_4bit = True
)
FastLanguageModel.for_inference(model)

prompt = """Below is a question that describes a SQL function, paired with a table Context that provides SQL table context. Write an answer that fullfils the user query.

### Question:
{}

### Context:
{}

### Answer:
{}"""

inputs = tokenizer(
[
    prompt.format(
        "What is the latest year that has ferrari 166 fl as the winning constructor?",
        """CREATE TABLE table_name_7 (
            year INTEGER,
            winning_constructor VARCHAR
        )""",
        ""
    )
], return_tensors = "pt").to("cuda")

outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
tokenizer.batch_decode(outputs)

```
```bash
# ["<s> Below is a question that describes a SQL function, paired with a table Context that provides SQL table context. Write an answer that fullfils the user query.\n\n### Question:\nWhat is the latest year that has ferrari 166 fl as the winning constructor?\n\n### Context:\nCREATE TABLE table_name_7 (\n    year INTEGER,\n    winning_constructor VARCHAR\n)\n\n### Answer:\nTo find the latest year that Ferrari 166 FL was the winning constructor, you can use the following SQL query:\n\n```sql\nSELECT MAX(year)\nFROM table_name_7\nWHERE winning_constructor = 'Ferrari 166 FL';\n```\n"]
```