Text Generation
Transformers
Safetensors
GGUF
PEFT
English
phi
nl2sql
custom_code
text-generation-inference
Instructions to use pavankumarbalijepalli/phi2-sqlcoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pavankumarbalijepalli/phi2-sqlcoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pavankumarbalijepalli/phi2-sqlcoder", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("pavankumarbalijepalli/phi2-sqlcoder", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("pavankumarbalijepalli/phi2-sqlcoder", trust_remote_code=True) - PEFT
How to use pavankumarbalijepalli/phi2-sqlcoder with PEFT:
Task type is invalid.
- llama-cpp-python
How to use pavankumarbalijepalli/phi2-sqlcoder with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="pavankumarbalijepalli/phi2-sqlcoder", filename="phi2_sqlcoder_f16.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use pavankumarbalijepalli/phi2-sqlcoder with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf pavankumarbalijepalli/phi2-sqlcoder:F16 # Run inference directly in the terminal: llama-cli -hf pavankumarbalijepalli/phi2-sqlcoder:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf pavankumarbalijepalli/phi2-sqlcoder:F16 # Run inference directly in the terminal: llama-cli -hf pavankumarbalijepalli/phi2-sqlcoder:F16
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 pavankumarbalijepalli/phi2-sqlcoder:F16 # Run inference directly in the terminal: ./llama-cli -hf pavankumarbalijepalli/phi2-sqlcoder:F16
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 pavankumarbalijepalli/phi2-sqlcoder:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf pavankumarbalijepalli/phi2-sqlcoder:F16
Use Docker
docker model run hf.co/pavankumarbalijepalli/phi2-sqlcoder:F16
- LM Studio
- Jan
- vLLM
How to use pavankumarbalijepalli/phi2-sqlcoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pavankumarbalijepalli/phi2-sqlcoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pavankumarbalijepalli/phi2-sqlcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/pavankumarbalijepalli/phi2-sqlcoder:F16
- SGLang
How to use pavankumarbalijepalli/phi2-sqlcoder with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "pavankumarbalijepalli/phi2-sqlcoder" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pavankumarbalijepalli/phi2-sqlcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "pavankumarbalijepalli/phi2-sqlcoder" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pavankumarbalijepalli/phi2-sqlcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use pavankumarbalijepalli/phi2-sqlcoder with Ollama:
ollama run hf.co/pavankumarbalijepalli/phi2-sqlcoder:F16
- Unsloth Studio new
How to use pavankumarbalijepalli/phi2-sqlcoder 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 pavankumarbalijepalli/phi2-sqlcoder 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 pavankumarbalijepalli/phi2-sqlcoder to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for pavankumarbalijepalli/phi2-sqlcoder to start chatting
- Docker Model Runner
How to use pavankumarbalijepalli/phi2-sqlcoder with Docker Model Runner:
docker model run hf.co/pavankumarbalijepalli/phi2-sqlcoder:F16
- Lemonade
How to use pavankumarbalijepalli/phi2-sqlcoder with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull pavankumarbalijepalli/phi2-sqlcoder:F16
Run and chat with the model
lemonade run user.phi2-sqlcoder-F16
List all available models
lemonade list
Update README.md
Browse files
README.md
CHANGED
|
@@ -15,9 +15,11 @@ tags:
|
|
| 15 |
widget:
|
| 16 |
- text: "### Task\nGenerate a SQL query to answer the following question:\n`How many heads of the departments are older than 56?`\n\n### Database Schema\nThe query will run on a database with the following schema:\nCREATE TABLE head (age INTEGER)\n\n### Answer\nGiven the database schema, here is the SQL query that answers `How many heads of the departments are older than 56?`:\n```sql"
|
| 17 |
example_title: "One Table"
|
|
|
|
|
|
|
| 18 |
---
|
| 19 |
|
| 20 |
-
#
|
| 21 |
|
| 22 |
# Model Card for Model ID
|
| 23 |
|
|
@@ -175,26 +177,50 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
| 175 |
|
| 176 |
<!-- This should link to a Dataset Card if possible. -->
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
#### Factors
|
| 181 |
|
| 182 |
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
|
|
|
| 183 |
|
| 184 |
-
[More Information Needed]
|
| 185 |
|
| 186 |
#### Metrics
|
| 187 |
|
| 188 |
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
### Results
|
| 193 |
|
| 194 |
-
|
|
|
|
| 195 |
|
| 196 |
#### Summary
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
## Environmental Impact
|
| 200 |
|
|
@@ -202,11 +228,11 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
| 202 |
|
| 203 |
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 204 |
|
| 205 |
-
- **Hardware Type:**
|
| 206 |
-
- **Hours used:**
|
| 207 |
-
- **Cloud Provider:**
|
| 208 |
-
- **Compute Region:**
|
| 209 |
-
- **Carbon Emitted:**
|
| 210 |
|
| 211 |
|
| 212 |
## Citation [optional]
|
|
|
|
| 15 |
widget:
|
| 16 |
- text: "### Task\nGenerate a SQL query to answer the following question:\n`How many heads of the departments are older than 56?`\n\n### Database Schema\nThe query will run on a database with the following schema:\nCREATE TABLE head (age INTEGER)\n\n### Answer\nGiven the database schema, here is the SQL query that answers `How many heads of the departments are older than 56?`:\n```sql"
|
| 17 |
example_title: "One Table"
|
| 18 |
+
- text: "### Task\nGenerate a SQL query to answer the following question:\n`Show the name and number of employees for the departments managed by heads whose temporary acting value is 'Yes'?`\n\n### Database Schema\nThe query will run on a database with the following schema:\nCREATE TABLE management (department_id VARCHAR, temporary_acting VARCHAR); CREATE TABLE department (name VARCHAR, num_employees VARCHAR, department_id VARCHAR)\n\n### Answer\nGiven the database schema, here is the SQL query that answers `Show the name and number of employees for the departments managed by heads whose temporary acting value is 'Yes'?`:\n```sql"
|
| 19 |
+
example_title: "Two Tables"
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# Thanks for being patient! 💜💜
|
| 23 |
|
| 24 |
# Model Card for Model ID
|
| 25 |
|
|
|
|
| 177 |
|
| 178 |
<!-- This should link to a Dataset Card if possible. -->
|
| 179 |
|
| 180 |
+
Used b-mc2/sql-create-context and split the data into training and testing datasets. The holdout dataset is used for testing the model.
|
| 181 |
|
| 182 |
#### Factors
|
| 183 |
|
| 184 |
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 185 |
+
The complexity of the questions are calculated using the number of tables per question, number of joins, group by, and sub queries per answer. This complexity is used to prepare the test data by stratifying the split around the complexity.
|
| 186 |
|
|
|
|
| 187 |
|
| 188 |
#### Metrics
|
| 189 |
|
| 190 |
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 191 |
+
* __Execution Success:__ This metric is used to find out if the generated query is executable without arising any errors. For this, a sqllite3 connection is made to the memory, and using context the dummy tables are created. Then the predicted SQL is executed. This checks out if the generated query is in proper syntax, and if the model is hallucinating any new columns.
|
| 192 |
+
* __Inference Time:__ This metric is used to find out which model is providing results in less amount of time. This combined with the execution success, gives the efficiency of the model.
|
| 193 |
+
-
|
| 194 |
### Results
|
| 195 |
|
| 196 |
+
* __Execution Success:__ Finetuned Phi-2 has 29% more success rate than the SQLCoder-7b-2
|
| 197 |
+
* __Inference Time:__ Finetuned Phi-2 has 41% increased inference speed than SQLCoder-7b-2
|
| 198 |
|
| 199 |
#### Summary
|
| 200 |
+
* __Reduced Inference Time and Memory Footprint:__ The fine-tuned Phi-2 model
|
| 201 |
+
demonstrated a reduction in inference time and memory usage compared to the DeFog
|
| 202 |
+
SQLCoder. This is attributed to Phi-2's smaller size and the efficiency of quantization
|
| 203 |
+
techniques employed during fine-tuning. This finding implies that NL2SQL models can
|
| 204 |
+
be deployed on lower-powered devices like laptops or even mobile phones, potentially
|
| 205 |
+
democratizing access to this technology for a wider range of users.
|
| 206 |
+
|
| 207 |
+
* __Competitive Performance on Easy and Medium Queries:__ The fine-tuned Phi-2
|
| 208 |
+
achieved comparable performance to the DeFog SQLCoder in terms of accuracy on easy,
|
| 209 |
+
medium, and hard difficulty queries. This indicates that Phi-2, despite its smaller size,
|
| 210 |
+
can effectively handle a significant portion of real-world NL2SQL tasks, especially for
|
| 211 |
+
simpler queries.
|
| 212 |
+
|
| 213 |
+
* __Challenges with Complex Queries:__ While Phi-2 performed well on easier queries, it
|
| 214 |
+
encountered challenges with complex queries, exhibiting a drop in execution success
|
| 215 |
+
compared to the DeFog SQLCoder. This highlights the trade-off between model size and
|
| 216 |
+
complexity, suggesting that larger models might still be necessary for tackling highly
|
| 217 |
+
intricate tasks.
|
| 218 |
+
|
| 219 |
+
* __Potential for Further Improvement:__ The fine-tuning process employed in this study
|
| 220 |
+
can be further optimized by exploring different hyperparameter configurations and
|
| 221 |
+
potentially investigating alternative fine-tuning techniques like adapter-based methods.
|
| 222 |
+
This optimization has the potential to improve the model's performance on complex
|
| 223 |
+
queries while maintaining its efficiency.
|
| 224 |
|
| 225 |
## Environmental Impact
|
| 226 |
|
|
|
|
| 228 |
|
| 229 |
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 230 |
|
| 231 |
+
- **Hardware Type:** A100 PCIE 40GB X1
|
| 232 |
+
- **Hours used:** 18 Hours
|
| 233 |
+
- **Cloud Provider:** Google Cloud
|
| 234 |
+
- **Compute Region:** Asia-East-1
|
| 235 |
+
- **Carbon Emitted:** 2.52 kg eq. CO2
|
| 236 |
|
| 237 |
|
| 238 |
## Citation [optional]
|