Text Generation
Transformers
Safetensors
English
phi3
code
sql
text-to-sql
text2sql
t2sql
text2text-generation
conversational
custom_code
text-generation-inference
Instructions to use HridaAI/Hrida-T2SQL-3B-V0.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HridaAI/Hrida-T2SQL-3B-V0.2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HridaAI/Hrida-T2SQL-3B-V0.2", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("HridaAI/Hrida-T2SQL-3B-V0.2", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("HridaAI/Hrida-T2SQL-3B-V0.2", trust_remote_code=True) 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
- vLLM
How to use HridaAI/Hrida-T2SQL-3B-V0.2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HridaAI/Hrida-T2SQL-3B-V0.2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HridaAI/Hrida-T2SQL-3B-V0.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HridaAI/Hrida-T2SQL-3B-V0.2
- SGLang
How to use HridaAI/Hrida-T2SQL-3B-V0.2 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 "HridaAI/Hrida-T2SQL-3B-V0.2" \ --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": "HridaAI/Hrida-T2SQL-3B-V0.2", "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 "HridaAI/Hrida-T2SQL-3B-V0.2" \ --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": "HridaAI/Hrida-T2SQL-3B-V0.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HridaAI/Hrida-T2SQL-3B-V0.2 with Docker Model Runner:
docker model run hf.co/HridaAI/Hrida-T2SQL-3B-V0.2
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: text2text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
+
- sql
|
| 10 |
+
- text-to-sql
|
| 11 |
+
- text2sql
|
| 12 |
+
- t2sql
|
| 13 |
+
base_model:
|
| 14 |
+
- microsoft/Phi-3.5-mini-instruct
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
Introducing Hrida-T2SQL-3B-V0.2, our latest small language model (SLM) tailored for data scientists and industry professionals. This advanced model marks a significant upgrade from our previous release, now equipped with 128k token context window as defaultfor handling even the most intricate data queries with precision. Powered by the Phi 3 architecture, it effortlessly converts natural language queries into precise SQL commands, enhancing data analysis efficiency and decision-making capabilities.
|
| 18 |
+
|
| 19 |
+
Blog & benchmark coming soon!
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Prompt Template
|
| 23 |
+
|
| 24 |
+
```txt
|
| 25 |
+
### Instruction:
|
| 26 |
+
Provide the system prompt.
|
| 27 |
+
|
| 28 |
+
### Dialect:
|
| 29 |
+
Specify the SQL dialect (e.g., MySQL, PostgreSQL, SQL Server, etc.).
|
| 30 |
+
|
| 31 |
+
### Context:
|
| 32 |
+
Provide the database schema including table names, column names, and data types.
|
| 33 |
+
|
| 34 |
+
### Input:
|
| 35 |
+
User's query.
|
| 36 |
+
|
| 37 |
+
### Response:
|
| 38 |
+
Expected SQL query output based on the input and context.
|
| 39 |
+
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
- **Instruction (System Prompt)**: This guides the model on processing input to generate the SQL query response effectively.
|
| 43 |
+
- **Dialect (Optional)**: Specify the SQL variant the model should use to ensure the generated query conforms to the correct syntax.
|
| 44 |
+
- **Context**: Provide the database schema to the model for generating accurate SQL queries.
|
| 45 |
+
- **Input**: Provide the user query for the model to comprehend and transform into an SQL query.
|
| 46 |
+
- **Response**: Expected output from the model.
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Chat Prompt Template
|
| 50 |
+
|
| 51 |
+
```txt
|
| 52 |
+
<s>
|
| 53 |
+
<|system|>
|
| 54 |
+
{ Instruction / System Prompt }
|
| 55 |
+
<|user|>
|
| 56 |
+
{ Context / User Query } <|end|>
|
| 57 |
+
<|assistant|>
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## Run the Model
|
| 61 |
+
|
| 62 |
+
### Using Transformers
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
import torch
|
| 66 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 67 |
+
|
| 68 |
+
# Define the model and tokenizer
|
| 69 |
+
model_id = "HridaAI/Hrida-T2SQL-3B-V0.2"
|
| 70 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 71 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
|
| 72 |
+
|
| 73 |
+
# Define the context and prompt
|
| 74 |
+
prompt = """
|
| 75 |
+
Answer to the query will be in the form of an SQL query.
|
| 76 |
+
### Context: CREATE TABLE Employees (
|
| 77 |
+
EmployeeID INT PRIMARY KEY,
|
| 78 |
+
FirstName VARCHAR(50),
|
| 79 |
+
LastName VARCHAR(50),
|
| 80 |
+
Age INT,
|
| 81 |
+
DepartmentID INT,
|
| 82 |
+
Salary DECIMAL(10, 2),
|
| 83 |
+
DateHired DATE,
|
| 84 |
+
Active BOOLEAN,
|
| 85 |
+
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
|
| 86 |
+
);
|
| 87 |
+
|
| 88 |
+
CREATE TABLE Departments (
|
| 89 |
+
DepartmentID INT PRIMARY KEY,
|
| 90 |
+
DepartmentName VARCHAR(100),
|
| 91 |
+
Location VARCHAR(100)
|
| 92 |
+
);
|
| 93 |
+
### Input: if the hiring date of John is 25/12/2024 and he is 48 years old how long it will take him to retire lets say the retirement age is 55?
|
| 94 |
+
### Response:
|
| 95 |
+
"""
|
| 96 |
+
# Prepare the input
|
| 97 |
+
messages = [{"role": "user", "content": prompt}]
|
| 98 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
|
| 99 |
+
|
| 100 |
+
# Generate the output
|
| 101 |
+
outputs = model.generate(inputs, max_length=300)
|
| 102 |
+
print(tokenizer.decode(outputs[0]))
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
### Using MLX
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
from mlx_lm import generate, load
|
| 111 |
+
|
| 112 |
+
model,tokenizer = load("HridaAI/Hrida-T2SQL-3B-V0.2")
|
| 113 |
+
|
| 114 |
+
prompt = """
|
| 115 |
+
Answer to the quey will be in the form of SQL query.
|
| 116 |
+
### Context: CREATE TABLE Employees (
|
| 117 |
+
EmployeeID INT PRIMARY KEY,
|
| 118 |
+
FirstName VARCHAR(50),
|
| 119 |
+
LastName VARCHAR(50),
|
| 120 |
+
Age INT,
|
| 121 |
+
DepartmentID INT,
|
| 122 |
+
Salary DECIMAL(10, 2),
|
| 123 |
+
DateHired DATE,
|
| 124 |
+
Active BOOLEAN,
|
| 125 |
+
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
|
| 126 |
+
);
|
| 127 |
+
|
| 128 |
+
CREATE TABLE Departments (
|
| 129 |
+
DepartmentID INT PRIMARY KEY,
|
| 130 |
+
DepartmentName VARCHAR(100),
|
| 131 |
+
Location VARCHAR(100)
|
| 132 |
+
); ### Input: if the hiring date of John is 25/12/2024 and he is 48 years old how long it will take him to retire lets say the retirement age is 55?
|
| 133 |
+
### Response:"""
|
| 134 |
+
|
| 135 |
+
response = generate(model=model,tokenizer=tokenizer,prompt=prompt, verbose=True)
|
| 136 |
+
|
| 137 |
+
```
|