Downloads · 30 days
15
13% of all-time downloads
neurondb/postgres-llm-qlora
postgres-llm-qlora is a text generation model from neurondb. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
QLoRA fine-tuned adapter for PostgreSQL SQL / text-to-SQL on Qwen/Qwen2.5-Coder-3B-Instruct. Trained on the neurondb/neurondb-postgresql-sql dataset. Use this adapter with the base model to generate PostgreSQL-compati…
Downloads · 30 days
15
13% of all-time downloads
All-time downloads
113
Public
Repo size
490 MB
Likes
1
Public
Click a slice to open those files.
.safetensors479 MB · 98%
From the Hugging Face model README
QLoRA fine-tuned adapter for PostgreSQL SQL / text-to-SQL on Qwen/Qwen2.5-Coder-3B-Instruct. Trained on the neurondb/neurondb-postgresql-sql dataset. Use this adapter with the base model to generate PostgreSQL-compatible SQL from natural language instructions. Use this adapter with the base model to generate PostgreSQL-compatible SQL from natural language instructions.
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
adapter_path = "YOUR_USER/postgres-llm-qlora" # or local path
base_model = "Qwen/Qwen2.5-Coder-3B-Instruct"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
base_model,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter_path)
tokenizer = AutoTokenizer.from_pretrained(adapter_path, trust_remote_code=True)
model.eval()
prompt = "Create a table users with columns id (serial primary key), name (text), email (text);"
text = f"### Instruction:\n{prompt}\n\n### Response:\n"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(out[0][inputs["input_ids"].size(1):], skip_special_tokens=True)
print(response)
# After loading model + tokenizer as above
from transformers import pipeline
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, device=model.device)
out = pipe("### Instruction:\nList all tables.\n\n### Response:\n", max_new_tokens=128, do_sample=False)
print(out[0]["generated_text"])
Use the same instruction format as in training:
### Instruction:
<your natural language or task>
### Response:
The model will generate SQL (and optionally an explanation) after ### Response:.
This model was fine-tuned on neurondb/neurondb-postgresql-sql (~212k instruction pairs). The dataset includes:
question, optional schema (DDL), sql (PostgreSQL/PL-pgSQL), optional explanationSee the dataset card for schema, difficulty distribution, categories, and license.
Apache 2.0. Base model (Qwen2.5-Coder) follows its original license.
If you use this adapter, please cite the training dataset and the base model / PEFT:
Dataset:
@dataset{neurondb_postgresql_sql_2026,
title={NeuronDB PostgreSQL SQL & PL/pgSQL Instruction Dataset},
author={NeuronDB Team},
year={2026},
url={https://huggingface.co/datasets/neurondb/neurondb-postgresql-sql},
}
PEFT:
@software{peft,
title = {PEFT: State-of-the-art Parameter-Efficient Fine-Tuning},
author = {Hugging Face},
year = {2023},
url = {https://github.com/huggingface/peft}
}