Instructions to use alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql
- SGLang
How to use alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql 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 "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql with Docker Model Runner:
docker model run hf.co/alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql
How to use from
SGLangUse 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 "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql" \
--host 0.0.0.0 \
--port 30000# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'Quick Links
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
MODEL_NAME = "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
torch_dtype="auto",
device_map="auto"
)
model = PeftModel.from_pretrained(model, MODEL_NAME)
model.eval()
test_data = {
'db_id': 'cre_Students_Information_Systems',
'schema': 'CREATE TABLE Students (\n`student_id` INTEGER NOT NULL,\n`bio_data` VARCHAR(255) NOT NULL,\n`student_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`student_id`)\n)\nCREATE TABLE Transcripts (\n`transcript_id` INTEGER NOT NULL,\n`student_id` INTEGER NOT NULL,\n`date_of_transcript` DATETIME(3),\n`transcript_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`transcript_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id)\n)\nCREATE TABLE Behaviour_Monitoring (\n`behaviour_monitoring_id` INTEGER NOT NULL,\n`student_id` INTEGER NOT NULL,\n`behaviour_monitoring_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`behaviour_monitoring_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id)\n)\nCREATE TABLE Addresses (\n`address_id` INTEGER NOT NULL,\n`address_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`address_id`)\n)\nCREATE TABLE Ref_Event_Types (\n`event_type_code` CHAR(10) NOT NULL,\n`event_type_description` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`event_type_code`)\n)\nCREATE TABLE Ref_Achievement_Type (\n`achievement_type_code` CHAR(15) NOT NULL,\n`achievement_type_description` VARCHAR(80),\nPRIMARY KEY (`achievement_type_code`)\n)\nCREATE TABLE Ref_Address_Types (\n`address_type_code` CHAR(10) NOT NULL,\n`address_type_description` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`address_type_code`)\n)\nCREATE TABLE Ref_Detention_Type (\n`detention_type_code` CHAR(10) NOT NULL,\n`detention_type_description` VARCHAR(80),\nPRIMARY KEY (`detention_type_code`)\n)\nCREATE TABLE Student_Events (\n`event_id` INTEGER NOT NULL,\n`event_type_code` CHAR(10) NOT NULL,\n`student_id` INTEGER NOT NULL,\n`event_date` DATETIME(3),\n`other_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`event_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id),\nFOREIGN KEY (event_type_code) REFERENCES Ref_Event_Types (event_type_code)\n)\nCREATE TABLE Teachers (\n`teacher_id` INTEGER NOT NULL,\n`teacher_details` VARCHAR(255),\nPRIMARY KEY (`teacher_id`)\n)\nCREATE TABLE Student_Loans (\n`student_loan_id` INTEGER NOT NULL,\n`student_id` INTEGER NOT NULL,\n`date_of_loan` DATETIME(3),\n`amount_of_loan` DECIMAL(15,4),\n`other_details` VARCHAR(255),\nPRIMARY KEY (`student_loan_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id)\n)\nCREATE TABLE Classes (\n`class_id` INTEGER NOT NULL,\n`student_id` INTEGER NOT NULL,\n`teacher_id` INTEGER NOT NULL,\n`class_details` VARCHAR(255) NOT NULL,\nPRIMARY KEY (`class_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id),\nFOREIGN KEY (teacher_id) REFERENCES Teachers (teacher_id)\n)\nCREATE TABLE Students_Addresses (\n`student_address_id` INTEGER NOT NULL,\n`address_id` INTEGER NOT NULL,\n`address_type_code` CHAR(10) NOT NULL,\n`student_id` INTEGER NOT NULL,\n`date_from` DATETIME(3),\n`date_to` DATETIME(3),\nPRIMARY KEY (`student_address_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id),\nFOREIGN KEY (address_id) REFERENCES Addresses (address_id),\nFOREIGN KEY (address_type_code) REFERENCES Ref_Address_Types (address_type_code)\n)\nCREATE TABLE Detention (\n`detention_id` INTEGER NOT NULL,\n`detention_type_code` CHAR(10) NOT NULL,\n`student_id` INTEGER NOT NULL,\n`datetime_detention_start` DATETIME(3),\n`datetime_detention_end` DATETIME(3),\n`detention_summary` VARCHAR(255),\n`other_details` VARCHAR(255),\nPRIMARY KEY (`detention_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id),\nFOREIGN KEY (detention_type_code) REFERENCES Ref_Detention_Type (detention_type_code)\n)\nCREATE TABLE Achievements (\n`achievement_id` INTEGER NOT NULL,\n`achievement_type_code` CHAR(15) NOT NULL,\n`student_id` INTEGER NOT NULL,\n`date_achievement` DATETIME(3),\n`achievement_details` VARCHAR(255),\n`other_details` VARCHAR(255),\nPRIMARY KEY (`achievement_id`),\nFOREIGN KEY (student_id) REFERENCES Students (student_id),\nFOREIGN KEY (achievement_type_code) REFERENCES Ref_Achievement_Type (achievement_type_code)\n)',
'question': 'What are the type code, details, and date of each achievement?'
}
system_prompt = (
"You are an SQL query generator that converts natural language inputs into SQL queries, "
"strictly adhering to the provided database schema. Your task is to:\n\n"
"Carefully analyze the natural language input to understand its requirements. "
"Generate a SQL query that retrieves the correct results based only on the database schema provided.\n\n"
"Rules:\n\n"
"Do NOT use any tables, columns, or data outside the provided database schema.\n"
"Ensure the SQL query is syntactically correct and efficient.\n"
"If the input involves ambiguity or missing details, "
"assume the most common or straightforward interpretation.\n\n"
"Respond with only the SQL query, formatted cleanly and consistently. "
"Do not include explanations, comments, or extra text."
)
user_prompt = (
"Database schema: {schema}\n\n"
"Natural language input: {user_query}\n\n"
"Answer: "
)
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt.format(schema=test_data['schema'], user_query=test_data['question'])}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
Install from pip and serve model
# Install SGLang from pip: pip install sglang# Start the SGLang server: python3 -m sglang.launch_server \ --model-path "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql" \ --host 0.0.0.0 \ --port 30000# Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "alpecevit/Qwen2.5-Coder-7B-Instruct-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'