samrat-kar commited on
Commit
ea93491
·
verified ·
1 Parent(s): b0922bc

Add model card

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-Coder-7B-Instruct
3
+ library_name: peft
4
+ license: apache-2.0
5
+ pipeline_tag: text-generation
6
+ language: [en]
7
+ datasets: [samrat-kar/ap-sql-peft]
8
+ tags:
9
+ - base_model:adapter:Qwen/Qwen2.5-Coder-7B-Instruct
10
+ - lora
11
+ - qlora
12
+ - text-to-sql
13
+ - oracle
14
+ - accounts-payable
15
+ ---
16
+
17
+ # ap-sql-v1
18
+
19
+ A LoRA adapter for `Qwen/Qwen2.5-Coder-7B-Instruct` that turns Accounts Payable questions into read-only Oracle SQL.
20
+ It is built for an AI data-analyst assistant that answers questions over a schema modelled on Oracle Fusion AP,
21
+ Payments and Supplier tables.
22
+
23
+ The model gets a system prompt containing the relevant table DDL (from schema retrieval) and a business glossary.
24
+ It answers with a single ```` ```sql ```` block. It has also learned to fix a query when it is given the Oracle error
25
+ from its previous attempt, and to answer follow-up questions in a conversation.
26
+
27
+ ## Results
28
+
29
+ Execution accuracy on the 179-case held-out test split. The generated SQL and the gold SQL were both run on Oracle 23ai
30
+ and their result sets compared. A case counts only when the rows match exactly. The adapter was served by
31
+ vLLM 0.12.0 on the AWQ base `Qwen/Qwen2.5-Coder-7B-Instruct-AWQ`.
32
+
33
+ | Model | T1 | T2 | T3 | T4 | T5 | Overall |
34
+ |---|---|---|---|---|---|---|
35
+ | Base `Qwen2.5-Coder-7B-Instruct-AWQ` | 57% | 32% | 21% | 32% | 56% | 35% |
36
+ | **ap-sql-v1** | **97%** | **96%** | **90%** | **89%** | **89%** | **93%** |
37
+
38
+ Invented-column errors (ORA-00904) fell from 43 cases to 0. The adapter adds about 1 second of median latency
39
+ (2.8 s to 3.8 s on an RTX 5070 Ti Laptop GPU).
40
+
41
+ **Caveats.** 149 of the 179 test cases are templated, as is most of the training set. No test case shares a template
42
+ group or an identical question with the training data, but real user questions will vary more than the test set.
43
+ The eval uses each case's stored prompt, so it measures the model on its own; schema retrieval is outside its scope.
44
+
45
+ ## Usage
46
+
47
+ ### vLLM
48
+
49
+ ```bash
50
+ vllm serve Qwen/Qwen2.5-Coder-7B-Instruct-AWQ --quantization awq_marlin \
51
+ --enable-lora --max-lora-rank 16 --lora-modules ap-sql-v1=samrat-kar/ap-sql-v1
52
+ ```
53
+
54
+ Then send `model="ap-sql-v1"` to the OpenAI-compatible `/v1/chat/completions` endpoint.
55
+
56
+ ### Transformers + PEFT
57
+
58
+ ```python
59
+ from transformers import AutoModelForCausalLM, AutoTokenizer
60
+ from peft import PeftModel
61
+
62
+ base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct", torch_dtype="auto", device_map="auto")
63
+ model = PeftModel.from_pretrained(base, "samrat-kar/ap-sql-v1")
64
+ tok = AutoTokenizer.from_pretrained("samrat-kar/ap-sql-v1")
65
+ ```
66
+
67
+ Use the same system-prompt format as the training data (see the dataset). The schema must be given as `CREATE TABLE` DDL.
68
+
69
+ ## Training
70
+
71
+ | | |
72
+ |---|---|
73
+ | Method | QLoRA: 4-bit NF4 base with double quantisation, bf16 compute |
74
+ | LoRA | r=16, alpha=32, dropout=0.05; q/k/v/o/gate/up/down projections |
75
+ | Data | 1,441 train / 95 val rows from `samrat-kar/ap-sql-peft` |
76
+ | Schedule | 3 epochs, 273 optimizer steps, lr 2e-4 cosine, effective batch 16, paged AdamW 8-bit |
77
+ | Max length | 3,840 tokens |
78
+ | Final train loss | 0.0157 |
79
+ | Compute | 2.5 h, peak 17.5 GB GPU memory |
80
+
81
+ The loss is computed on the assistant turn only.
82
+
83
+ ## Limitations
84
+
85
+ - Trained on a single demo schema. Other schemas, or other Fusion modules, need new training data.
86
+ - Produces Oracle dialect only (`FETCH FIRST N ROWS ONLY`, `ADD_MONTHS`, `TRUNC`).
87
+ - Always run the output through read-only guardrails and a read-only database user. The model is not a security boundary.