Instructions to use kristiannordby/llama3-sqlcoder-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kristiannordby/llama3-sqlcoder-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kristiannordby/llama3-sqlcoder-ft")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kristiannordby/llama3-sqlcoder-ft") model = AutoModelForCausalLM.from_pretrained("kristiannordby/llama3-sqlcoder-ft", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kristiannordby/llama3-sqlcoder-ft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kristiannordby/llama3-sqlcoder-ft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kristiannordby/llama3-sqlcoder-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kristiannordby/llama3-sqlcoder-ft
- SGLang
How to use kristiannordby/llama3-sqlcoder-ft 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 "kristiannordby/llama3-sqlcoder-ft" \ --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": "kristiannordby/llama3-sqlcoder-ft", "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 "kristiannordby/llama3-sqlcoder-ft" \ --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": "kristiannordby/llama3-sqlcoder-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kristiannordby/llama3-sqlcoder-ft with Docker Model Runner:
docker model run hf.co/kristiannordby/llama3-sqlcoder-ft
Update README.md
Browse files
README.md
CHANGED
|
@@ -16,6 +16,14 @@ base_model:
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
Prompt:
|
| 20 |
```
|
| 21 |
### Task
|
|
@@ -30,6 +38,32 @@ Given the database schema, here is the SQL query that [QUESTION]{user_question}[
|
|
| 30 |
[SQL]
|
| 31 |
```
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
### Model Description
|
| 35 |
|
|
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
| 19 |
+
To load the model:
|
| 20 |
+
```
|
| 21 |
+
# Load model directly
|
| 22 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 23 |
+
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained("kristiannordby/llama3-sqlcoder-ft")
|
| 25 |
+
model = AutoModelForCausalLM.from_pretrained("kristiannordby/llama3-sqlcoder-ft")
|
| 26 |
+
```
|
| 27 |
Prompt:
|
| 28 |
```
|
| 29 |
### Task
|
|
|
|
| 38 |
[SQL]
|
| 39 |
```
|
| 40 |
|
| 41 |
+
To prompt the model for generation:
|
| 42 |
+
```
|
| 43 |
+
def build_prompt(user_question, create_table_statements):
|
| 44 |
+
return (
|
| 45 |
+
"### Task\n"
|
| 46 |
+
f"Generate a SQL query to answer [QUESTION]{user_question}[/QUESTION]\n\n"
|
| 47 |
+
"### Database Schema\n"
|
| 48 |
+
"The query will run on a database with the following schema:\n"
|
| 49 |
+
f"{create_table_statements}\n\n"
|
| 50 |
+
"### Answer\n"
|
| 51 |
+
f"Given the database schema, here is the SQL query that [QUESTION]{user_question}[/QUESTION]\n"
|
| 52 |
+
"[SQL]\n"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
def build_output(sql):
|
| 56 |
+
# Add a newline at end; if the data has a closing "[/SQL]", add it here!
|
| 57 |
+
return f"{sql.strip()}\n"
|
| 58 |
+
|
| 59 |
+
create_table_statements = "YOUR TABLE SCHEMA HERE"
|
| 60 |
+
inputs = build_prompt("YOUR PROMPT HERE", create_table_statements)
|
| 61 |
+
input_ids = tokenizer(inputs, return_tensors="pt", padding = True, truncation = True, max_length = 512).input_ids.to(model.device)
|
| 62 |
+
outputs = model.generate(input_ids, max_new_tokens=100)
|
| 63 |
+
output = tokenizer.decode(outputs[0])
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
|
| 67 |
|
| 68 |
### Model Description
|
| 69 |
|