Text Generation
Transformers
Safetensors
English
qwen2
trl
grpo
conversational
text-generation-inference
Instructions to use DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO") model = AutoModelForCausalLM.from_pretrained("DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO
- SGLang
How to use DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO 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 "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO" \ --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": "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", "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 "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO" \ --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": "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO with Docker Model Runner:
docker model run hf.co/DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO
Update README.md
Browse files
README.md
CHANGED
|
@@ -34,12 +34,14 @@ config = PeftConfig.from_pretrained("DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoni
|
|
| 34 |
|
| 35 |
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length=2560)
|
| 36 |
model = PeftModel.from_pretrained(model, "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", is_trainable=False)
|
|
|
|
| 37 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length = 2560)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
You are an expert SQL Query Writer.
|
| 44 |
Given relevant Schemas and the Question, you first understand the problem entirely and then reason about the best possible approach to come up with an answer.
|
| 45 |
Once, you are confident in your reasoning, you will then start generating the SQL Query as the answer that accurately solves the given question leveraging some or all schemas.
|
|
@@ -58,13 +60,26 @@ FROM TABLE_NAME
|
|
| 58 |
WHERE
|
| 59 |
CONDITION
|
| 60 |
</answer>"""
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
SCHEMAS:
|
| 66 |
---------------
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
CREATE TABLE lab (
|
| 69 |
subject_id text,
|
| 70 |
hadm_id text,
|
|
@@ -127,23 +142,23 @@ CREATE TABLE prescriptions (
|
|
| 127 |
formulary_drug_cd text,
|
| 128 |
route text,
|
| 129 |
drug_dose text
|
| 130 |
-
)
|
|
|
|
| 131 |
|
| 132 |
-
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
]
|
| 138 |
|
| 139 |
-
inputs = tokenizer.apply_chat_template(
|
| 140 |
tokenize=True,
|
| 141 |
add_generation_prompt=True,
|
| 142 |
return_dict=True,
|
| 143 |
return_tensors="pt")
|
| 144 |
|
| 145 |
with torch.inference_mode():
|
| 146 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
| 147 |
|
| 148 |
outputs = tokenizer.batch_decode(outputs)
|
| 149 |
print(outputs[0].split("<|im_start|>assistant")[-1])
|
|
|
|
| 34 |
|
| 35 |
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length=2560)
|
| 36 |
model = PeftModel.from_pretrained(model, "DeathReaper0965/Qwen2.5-3B-Inst-SQL-Reasoning-GRPO", is_trainable=False)
|
| 37 |
+
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct", max_length = 2560)
|
| 39 |
|
| 40 |
+
def create_prompt(schemas, question):
|
| 41 |
+
prompt = [
|
| 42 |
+
{
|
| 43 |
+
'role': 'system',
|
| 44 |
+
'content': """\
|
| 45 |
You are an expert SQL Query Writer.
|
| 46 |
Given relevant Schemas and the Question, you first understand the problem entirely and then reason about the best possible approach to come up with an answer.
|
| 47 |
Once, you are confident in your reasoning, you will then start generating the SQL Query as the answer that accurately solves the given question leveraging some or all schemas.
|
|
|
|
| 60 |
WHERE
|
| 61 |
CONDITION
|
| 62 |
</answer>"""
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
'role': 'user',
|
| 66 |
+
'content': f"""\
|
| 67 |
SCHEMAS:
|
| 68 |
---------------
|
| 69 |
|
| 70 |
+
{schemas}
|
| 71 |
+
|
| 72 |
+
---------------
|
| 73 |
+
|
| 74 |
+
QUESTION: "{question}"\
|
| 75 |
+
"""
|
| 76 |
+
}
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
return prompt
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
schemas = """\
|
| 83 |
CREATE TABLE lab (
|
| 84 |
subject_id text,
|
| 85 |
hadm_id text,
|
|
|
|
| 142 |
formulary_drug_cd text,
|
| 143 |
route text,
|
| 144 |
drug_dose text
|
| 145 |
+
)\
|
| 146 |
+
"""
|
| 147 |
|
| 148 |
+
question = "How many patients whose admission type is emergency and diagnoses icd9 code is 56210?"
|
| 149 |
|
| 150 |
+
example_prompt = create_prompt(schemas, question)
|
| 151 |
+
|
| 152 |
+
streamer = TextStreamer(tokenizer, skip_prompt=True)
|
|
|
|
| 153 |
|
| 154 |
+
inputs = tokenizer.apply_chat_template(example_prompt,
|
| 155 |
tokenize=True,
|
| 156 |
add_generation_prompt=True,
|
| 157 |
return_dict=True,
|
| 158 |
return_tensors="pt")
|
| 159 |
|
| 160 |
with torch.inference_mode():
|
| 161 |
+
outputs = model.generate(**inputs, max_new_tokens=1024, streamer=streamer)
|
| 162 |
|
| 163 |
outputs = tokenizer.batch_decode(outputs)
|
| 164 |
print(outputs[0].split("<|im_start|>assistant")[-1])
|