Text Generation
Transformers
Safetensors
English
llama
text-to-sql
conversational
text-generation-inference
Instructions to use Ary-007/Text-to-sql-llama-3.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ary-007/Text-to-sql-llama-3.2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ary-007/Text-to-sql-llama-3.2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ary-007/Text-to-sql-llama-3.2") model = AutoModelForCausalLM.from_pretrained("Ary-007/Text-to-sql-llama-3.2", 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ary-007/Text-to-sql-llama-3.2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ary-007/Text-to-sql-llama-3.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": "Ary-007/Text-to-sql-llama-3.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ary-007/Text-to-sql-llama-3.2
- SGLang
How to use Ary-007/Text-to-sql-llama-3.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 "Ary-007/Text-to-sql-llama-3.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": "Ary-007/Text-to-sql-llama-3.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 "Ary-007/Text-to-sql-llama-3.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": "Ary-007/Text-to-sql-llama-3.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Ary-007/Text-to-sql-llama-3.2 with Docker Model Runner:
docker model run hf.co/Ary-007/Text-to-sql-llama-3.2
| license: mit | |
| datasets: | |
| - gretelai/synthetic_text_to_sql | |
| language: | |
| - en | |
| base_model: | |
| - meta-llama/Llama-3.2-3B-Instruct | |
| library_name: transformers | |
| tags: | |
| - text-to-sql | |
| ## Model Details | |
| This model is a fine-tuned version of Llama-3.2-3B-Instruct designed specifically for Text-to-SQL tasks. It was trained to accept a database schema and a natural language question, and output a valid SQL query along with a brief explanation of the logic. | |
| It is lightweight (3B parameters), making it suitable for local deployment on consumer GPUs using 4-bit quantization. | |
| ### Model Description | |
| 1) Base Model: unsloth/Llama-3.2-3B-Instruct | |
| 2) Fine-tuning Framework: Unsloth (QLoRA) | |
| 3) Dataset: gretelai/synthetic_text_to_sql | |
| ## Uses | |
| The model was trained using the Alpaca prompt format. For best results, structure your input as follows: | |
|  | |
| ## How to Get Started with the Model | |
| ```python | |
| import torch | |
| from transformers import pipeline | |
| model_id = "Ary-007/Text-to-sql-llama-3.2" | |
| # Load the pipeline | |
| pipe = pipeline( | |
| "text-generation", | |
| model=model_id, | |
| device_map="auto", | |
| ) | |
| # Define the schema (Context) | |
| schema = """ | |
| CREATE TABLE employees ( | |
| id INT, | |
| name TEXT, | |
| department TEXT, | |
| salary INT, | |
| hire_date DATE | |
| ); | |
| """ | |
| # Define the user question | |
| question = "Find the name and salary of employees in the 'Engineering' department who earn more than 80000." | |
| # Format the prompt exactly as trained | |
| prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. | |
| ### Instruction: | |
| Company Database : {schema} | |
| ### Input: | |
| SQL Prompt :{question} | |
| ### Response: | |
| """ | |
| outputs = pipe( | |
| prompt, | |
| max_new_tokens=200, | |
| do_sample=True, | |
| temperature=0.1, | |
| top_p=0.9 | |
| ) | |
| print(outputs[0]["generated_text"]) | |
| ``` | |
| ## Training Details | |
| The model was fine-tuned using Unsloth on a Tesla T4 GPU (Google Colab). | |
| Hyperparameters | |
| 1) Rank (r): 16 | |
| 2) LoRA Alpha: 16 | |
| 3) Target Modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj | |
| 4) Quantization: 4-bit (Normal Float4) | |
| 5) Max Sequence Length: 2048 | |
| 6) Learning Rate: 2e-4 | |
| 7) Optim: adamw_8bit | |
| 8) Max Steps: 60 | |
| ## Dataset Info | |
| The model was trained on the gretelai/synthetic_text_to_sql dataset, utilizing the following fields: | |
| 1) sql_context: Used as the database schema context. | |
| 2) sql_prompt: The natural language question. | |
| 3) sql: The target SQL query. | |
| 4) sql_explanation: The explanation of the query logic. | |
| ## Limitations | |
| 1) Training Steps: This model was trained for a limited number of steps (60) as a proof of concept. It may not generalize well to extremely complex or unseen database schemas. | |
| 2) Hallucination: Like all LLMs, it may generate syntactically correct but logically incorrect SQL. Always validate the output before running it on a production database. | |
| 3) Scope: It is optimized for standard SQL (similar to SQLite/PostgreSQL) as presented in the GretelAI dataset. | |
| ## License | |
| This model is derived from Llama-3.2 and is subject to the Llama 3.2 Community License. |