Instructions to use defog/sqlcoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use defog/sqlcoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="defog/sqlcoder")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("defog/sqlcoder") model = AutoModelForCausalLM.from_pretrained("defog/sqlcoder") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use defog/sqlcoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "defog/sqlcoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "defog/sqlcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/defog/sqlcoder
- SGLang
How to use defog/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 "defog/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": "defog/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 "defog/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": "defog/sqlcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use defog/sqlcoder with Docker Model Runner:
docker model run hf.co/defog/sqlcoder
schema consideration and warnings
Thank you for your model.
I have tested the model but the model sometimes did not consider the database schema when I gave the entire database , giving the inaccurate queries...
and
I got the below warning
warnings. warn(
Setting pad_token_id to eos_token_id:0 for open-end generation.
anyone can explain the above warning
Hi there! Thanks for trying out the model, and for your feedback.
Could you share the schema you shared with the model? For large databases, we typically use a pruning function, like the one here for the model to focus its attention better. We will release documentation for this pruning function tomorrow.
Are you using our colab notebook for inference? https://colab.research.google.com/drive/1z4rmOEiFkxkMiecAWeTUlPl0OmKgfEu7 You shouldn't get any warning messages with the following code:
eos_token_id = tokenizer.convert_tokens_to_ids(["```"])[0]
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
generated_ids = model.generate(
**inputs,
num_return_sequences=1,
eos_token_id=eos_token_id,
pad_token_id=eos_token_id,
max_new_tokens=400,
do_sample=False,
num_beams=5
)
Hey Hi ! Thank you for your response..
I have tried your colab it is good. Thank you for that but I have connected the entire database not only schema because i need both sql_query and results based on my database.
when I tried with a small-size database it gave a query and answer but when I used a large-size database it got below error.
RuntimeError: The size of tensor a (8192) must match the size of tensor b (28769) at non-singleton dimension 2
Is there any limitation for model ?
please consider the screenshots for both large and small databases.
Thanks !!!!
@rishdotblog I noticed you mentioned "For large databases, we typically use a pruning function, like the one here for the model to focus its attention better." Would it be possible for you to provide with some real-time examples. So, we can understand and follow it.
will the response quality increase if I send top 5 records along with the schema?

