Instructions to use Arogyasami/Llama-2-7b-text2sql-finetune with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Arogyasami/Llama-2-7b-text2sql-finetune with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Arogyasami/Llama-2-7b-text2sql-finetune")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Arogyasami/Llama-2-7b-text2sql-finetune") model = AutoModelForCausalLM.from_pretrained("Arogyasami/Llama-2-7b-text2sql-finetune", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Arogyasami/Llama-2-7b-text2sql-finetune with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Arogyasami/Llama-2-7b-text2sql-finetune" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Arogyasami/Llama-2-7b-text2sql-finetune", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Arogyasami/Llama-2-7b-text2sql-finetune
- SGLang
How to use Arogyasami/Llama-2-7b-text2sql-finetune 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 "Arogyasami/Llama-2-7b-text2sql-finetune" \ --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": "Arogyasami/Llama-2-7b-text2sql-finetune", "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 "Arogyasami/Llama-2-7b-text2sql-finetune" \ --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": "Arogyasami/Llama-2-7b-text2sql-finetune", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Arogyasami/Llama-2-7b-text2sql-finetune with Docker Model Runner:
docker model run hf.co/Arogyasami/Llama-2-7b-text2sql-finetune
# Llama-2 7B Text-to-SQL (Fine-Tuned with LoRA)
## π Model Overview
This repository contains a fine-tuned version of Meta's **Llama-3 (8B)**, optimized specifically for the **Natural Language to SQL (Text-to-SQL)** generation task. By converting conversational English into executable SQL queries, this model is designed to bridge the gap between non-technical stakeholders and complex relational databases.
- **Developer:** DanielMartin Arogyasami
- **Base Model:** Meta-Llama-3-8B
- **Task:** Text-to-SQL (Code Generation)
- **Fine-Tuning Methodology:** Low-Rank Adaptation (LoRA) / PEFT
- **Language:** English, SQL
- **License:** Meta Llama 3 Community License / MIT (for fine-tuned weights)
## π― Intended Use Cases
This model is highly specialized for deployment in regulated enterprise environments (e.g., healthcare, finance), where data sovereignty is paramount.
- **Enterprise Data Retrieval:** Empowering business users to query databases using natural language, significantly reducing reliance on specialized SQL programmers.
- **Agentic AI Workflows:** Serving as the SQL-generation agent within larger Retrieval-Augmented Generation (RAG) and enterprise AI architectures.
- **Privacy-Preserving Analytics:** Allowing companies to run text-to-SQL conversions entirely on-premises or within air-gapped Virtual Private Clouds (VPCs). This ensures compliance with HIPAA and FDA CFR Part 11, as no sensitive data is transmitted to external proprietary APIs.
## βοΈ Technical Details & Training
This model was trained using **Parameter-Efficient Fine-Tuning (PEFT)**. Specifically, **LoRA (Low-Rank Adaptation)** was applied to the foundational Llama-3 model. This approach adapts the foundational reasoning capabilities of Llama-3 to the strict syntax requirements of SQL generation, while significantly reducing computational overhead.
* **Adapter:** LoRA
* **Target Modules:** Attention weights (`q_proj`, `v_proj`)
* **Precision:** FP16 / 4-bit Quantization (QLoRA) supported for edge-deployment.
* **Architecture:** Auto-Regressive Transformer.
## π How to Use (Inference)
You can load this model and run inference using the `transformers` and `peft` libraries from Hugging Face.
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model and tokenizer
base_model_id = "meta-llama/Meta-Llama-3-8B"
adapter_id = "Arogyasami/Llama-3-8b-text2sql-finetune"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16, device_map="auto")
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, adapter_id)
# Define your schema and question
schema = "CREATE TABLE Employees (ID int, Name varchar(255), Department varchar(255), Salary int);"
question = "What is the average salary of employees in the Sales department?"
prompt = f"Given the following database schema:\n{schema}\n\nWrite a SQL query to answer this question: {question}\n\nSQL:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
# Generate SQL
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
β οΈ Limitations & Bias
- Deterministic Requirement: Generative AI models can "hallucinate." While fine-tuned to minimize this, generated queries must be validated before execution, especially in clinical contexts where erroneous data retrieval could impact regulatory submissions.
- Schema Complexity: While the model performs exceptionally well on standard schemas, highly complex schemas with dozens of nested joins may reduce accuracy.
- Security: Always execute generated SQL in a safe, read-only environment. The model does not inherently enforce database permissions.
π Environmental Impact
By utilizing LoRA instead of full-parameter fine-tuning, the computational cost and carbon footprint required to train this model were drastically reduced. Its 8B parameter size allows it to be served efficiently on consumer-grade hardware (e.g., NVIDIA RTX 4090 or A10G), democratizing advanced AI access.
π€ Acknowledgements & Citation
- Meta for the foundational Llama-3 architecture.
- If this model assists in your research or enterprise architecture, please cite: Arogyasami, DanielMartin. (2024). Llama-3 8B Text-to-SQL (Fine-Tuned with LoRA). Hugging Face.
- Downloads last month
- 9