Instructions to use QuantFactory/sqlcoder-7b-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use QuantFactory/sqlcoder-7b-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="QuantFactory/sqlcoder-7b-GGUF", filename="sqlcoder-7b.Q2_K.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use QuantFactory/sqlcoder-7b-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
Use Docker
docker model run hf.co/QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use QuantFactory/sqlcoder-7b-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QuantFactory/sqlcoder-7b-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantFactory/sqlcoder-7b-GGUF", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
- Ollama
How to use QuantFactory/sqlcoder-7b-GGUF with Ollama:
ollama run hf.co/QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
- Unsloth Studio new
How to use QuantFactory/sqlcoder-7b-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/sqlcoder-7b-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/sqlcoder-7b-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for QuantFactory/sqlcoder-7b-GGUF to start chatting
- Docker Model Runner
How to use QuantFactory/sqlcoder-7b-GGUF with Docker Model Runner:
docker model run hf.co/QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
- Lemonade
How to use QuantFactory/sqlcoder-7b-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull QuantFactory/sqlcoder-7b-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.sqlcoder-7b-GGUF-Q4_K_M
List all available models
lemonade list
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
|
| 4 |
+
license: cc-by-sa-4.0
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
tags:
|
| 9 |
+
- code
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+

|
| 14 |
+
|
| 15 |
+
# QuantFactory/sqlcoder-7b-GGUF
|
| 16 |
+
This is quantized version of [defog/sqlcoder-7b](https://huggingface.co/defog/sqlcoder-7b) created using llama.cpp
|
| 17 |
+
|
| 18 |
+
# Original Model Card
|
| 19 |
+
|
| 20 |
+
# IMPORTANT
|
| 21 |
+
This model is now outdated. Please use [`defog/sqlcoder-7b-2`](https://huggingface.co/defog/sqlcoder-7b-2) for much better performance!
|
| 22 |
+
|
| 23 |
+
# Defog SQLCoder
|
| 24 |
+
Defog's SQLCoder is a state-of-the-art LLM for converting natural language questions to SQL queries.
|
| 25 |
+
|
| 26 |
+
[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)
|
| 27 |
+
|
| 28 |
+
## TL;DR
|
| 29 |
+
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`
|
| 30 |
+
|
| 31 |
+
SQLCoder-7B is fine-tuned on a base Mistral-7B model.
|
| 32 |
+
|
| 33 |
+
## Results on novel datasets not seen in training
|
| 34 |
+
| model | perc_correct |
|
| 35 |
+
|-|-|
|
| 36 |
+
| gpt4-2023-10-04 | 82.0 |
|
| 37 |
+
| defog-sqlcoder2 | 74.5 |
|
| 38 |
+
| gpt4-2023-08-28 | 74.0 |
|
| 39 |
+
| defog-sqlcoder-7b | 71.0 |
|
| 40 |
+
| gpt-3.5-2023-10-04 | 66.0 |
|
| 41 |
+
| claude-2 | 64.5 |
|
| 42 |
+
| gpt-3.5-2023-08-28 | 61.0 |
|
| 43 |
+
| claude_instant_1 | 61.0 |
|
| 44 |
+
| text-davinci-003 | 52.5 |
|
| 45 |
+
|
| 46 |
+
## License
|
| 47 |
+
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.
|
| 48 |
+
|
| 49 |
+
## Training
|
| 50 |
+
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.
|
| 51 |
+
|
| 52 |
+
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/).
|
| 53 |
+
|
| 54 |
+
## Results by question category
|
| 55 |
+
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.
|
| 56 |
+
| query_category | gpt-4 | sqlcoder2-15b | sqlcoder-7b | gpt-3.5 | claude-2 | claude-instant | gpt-3 |
|
| 57 |
+
|:-----------------|--------:|----------------:|--------------:|----------:|-----------:|-----------------:|--------:|
|
| 58 |
+
| date | 72 | 76 | 64 | 68 | 52 | 48 | 32 |
|
| 59 |
+
| group_by | 91.4 | 80 | 82.9 | 77.1 | 71.4 | 71.4 | 71.4 |
|
| 60 |
+
| order_by | 82.9 | 77.1 | 74.3 | 68.6 | 74.3 | 74.3 | 68.6 |
|
| 61 |
+
| ratio | 80 | 60 | 54.3 | 37.1 | 57.1 | 45.7 | 25.7 |
|
| 62 |
+
| join | 82.9 | 77.1 | 74.3 | 71.4 | 65.7 | 62.9 | 57.1 |
|
| 63 |
+
| where | 80 | 77.1 | 74.3 | 74.3 | 62.9 | 60 | 54.3 |
|
| 64 |
+
|
| 65 |
+
## Using SQLCoder
|
| 66 |
+
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).
|
| 67 |
+
```bash
|
| 68 |
+
python inference.py -q "Question about the sample database goes here"
|
| 69 |
+
|
| 70 |
+
# Sample question:
|
| 71 |
+
# 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.
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
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)
|
| 75 |
+
|
| 76 |
+
## Hardware Requirements
|
| 77 |
+
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.
|
| 78 |
+
|
| 79 |
+
## Todo
|
| 80 |
+
|
| 81 |
+
- [x] Open-source the v1 model weights
|
| 82 |
+
- [x] Train the model on more data, with higher data variance
|
| 83 |
+
- [ ] Tune the model further with Reward Modelling and RLHF
|
| 84 |
+
- [ ] Pretrain a model from scratch that specializes in SQL analysis
|