Run this model with HF Jobs
Run xiain/SwiftCypher-4B-LoRA on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/xiain/SwiftCypher-4B-LoRA. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/xiain/SwiftCypher-4B-LoRA on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/xiain/SwiftCypher-4B-LoRA. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/xiain/SwiftCypher-4B-LoRA. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use xiain/SwiftCypher-4B-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use xiain/SwiftCypher-4B-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen3-4B-Instruct-2507") model = PeftModel.from_pretrained(base_model, "xiain/SwiftCypher-4B-LoRA") - Transformers
How to use xiain/SwiftCypher-4B-LoRA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="xiain/SwiftCypher-4B-LoRA") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("xiain/SwiftCypher-4B-LoRA", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use xiain/SwiftCypher-4B-LoRA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xiain/SwiftCypher-4B-LoRA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xiain/SwiftCypher-4B-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/xiain/SwiftCypher-4B-LoRA
- SGLang
How to use xiain/SwiftCypher-4B-LoRA 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 "xiain/SwiftCypher-4B-LoRA" \ --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": "xiain/SwiftCypher-4B-LoRA", "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 "xiain/SwiftCypher-4B-LoRA" \ --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": "xiain/SwiftCypher-4B-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use xiain/SwiftCypher-4B-LoRA with Docker Model Runner:
docker model run hf.co/xiain/SwiftCypher-4B-LoRA
⚡ SwiftCypher-4B (PEFT LoRA Adapter)
#1 Ranked Lightweight Bilingual Text-to-Cypher & GraphRAG Adapter (bf16, r=32) for Qwen/Qwen3-4B-Instruct-2507
This repository contains the official bf16 PEFT LoRA adapter (r=32, lora_alpha=64) for SwiftCypher-4B, trained on Qwen/Qwen3-4B-Instruct-2507 for vLLM multi-LoRA serving, Transformers inference, and secondary domain fine-tuning. Ready-to-run quantized GGUF weights (Q8_0 and Q4_K_M) are available at xiain/SwiftCypher-4B-GGUF.
🇨🇳 点击展开简体中文完整说明与六冠王排行榜 (Simplified Chinese Overview & Rankings)
为什么选择 SwiftCypher-4B?
SwiftCypher-4B 基于纯指令无思考废话的 Qwen/Qwen3-4B-Instruct-2507 微调,专为 Neo4j、Memgraph、FalkorDB、Kùzu 与 GraphRAG 知识图谱问答打造。采用 “70% 中英多格式生成 + 20% 报错 1-Shot 自修复 + 10% 缺字段防幻觉拒答” 三合一训练配方,配合 <2ms openCypher AST 语法树 + (起点)-[:关系]->(终点) 方向白名单护栏,彻底解决传统小模型“关系箭头写反”和“遇到不存在属性强行瞎编”两大顽疾。
| 核心评测维度(3B~4B 轻量级赛道) | 同级排名 | SwiftCypher-4B | Neo4j 官方 4B (2025.04) |
原始基座 Qwen3-4B |
相比官方专用模型提升 |
|---|---|---|---|---|---|
真实图库执行准确率 (EX, 中英综合) |
🥇 #1 | 70.83% | 70.42% | 51.67% | **+0.41%**(较基座 +19.16%) |
中文 GraphRAG 真实图库执行率 (ZH EX) |
🥇 #1 | 79.17% | 76.67% | 56.67% | **+2.50%**(较基座 +22.50%) |
| 不对称关系箭头方向陷阱执行率 | 🥇 #1 | 60.00% | 50.00% | 38.33% | **+10.00%**(较基座 +21.67%) |
缺字段防幻觉拒答 (Refusal F1) |
🥇 #1 (专用模型) | 88.00% | 0.00% (零拒答全瞎编) | 88.89% | +88.00% |
| Neo4j 2025v1 官方集方向+白名单合规率 | 🥇 #1 | 95.40% | 94.80% | 65.40% | **+0.60%**(较基座 +30.00%) |
严格 JSON 契约合规率与长尾延迟 (p95) |
🥇 #1 | 99.33% (2105ms) |
0.00% (4081ms) |
100.00% (3135ms) |
长尾延迟降低 48.4% |
一行命令本地开跑 (Ollama)
ollama run hf.co/xiain/SwiftCypher-4B-GGUF:Q8_0
ollama run hf.co/xiain/SwiftCypher-4B-GGUF:Q4_K_M
完整 FastAPI 生产护栏网关、<2ms 零模型 --check 校验工具及中文文档详见 GitHub:**https://github.com/2422725977/swift-cypher**。
🏆 #1 Category Rankings in the 3B–4B Lightweight Class
| Evaluation Dimension (3B–4B Class) | Rank | SwiftCypher-4B | Neo4j Official 4B (2025.04) |
Base Qwen3-4B-2507 |
Gain vs. Neo4j Official |
|---|---|---|---|---|---|
Live Graph Execution (EX, EN+ZH) |
🥇 #1 | 70.83% | 70.42% | 51.67% | +0.41% (+19.16% vs Base) |
Chinese GraphRAG Execution (ZH EX) |
🥇 #1 | 79.17% | 76.67% | 56.67% | +2.50% (+22.50% vs Base) |
Asymmetric Direction-Trap EX |
🥇 #1 | 60.00% | 50.00% | 38.33% | +10.00% (+21.67% vs Base) |
Missing-Schema Anti-Hallucination (F1) |
🥇 #1 (Specialist) | 88.00% | 0.00% (0% refusal) | 88.89% | +88.00% |
| Neo4j 2025v1 Schema + Direction Valid | 🥇 #1 | 95.40% | 94.80% | 65.40% | +0.60% (+30.00% vs Base) |
Strict JSON Contract & Tail Latency (p95) |
🥇 #1 | 99.33% (2105ms) |
0.00% (4081ms) |
100.00% (3135ms) |
-48.4% faster p95 |
📊 Full Ranked Two-Track Competitor Leaderboard (800 Zero-Leakage Queries)
Fairness Protocol: Raw Cypher specialists (
Neo4j-Gemma-3-4B-2025.04 (Official)andQwen2.5-Coder-3B-Instruct) are evaluated in Track 1 (NativeRaw) using Neo4j's official prompt and markdown fence stripping so they are never penalized for not emitting our JSON schema.
| Rank | System / Model | Track | Kuzu Live EX | EN EX | ZH EX | Direction-Trap EX | Refusal F1 | Neo4j 2025v1 Schema+Dir | Structural F1 | Strict JSON % | p50 (bs=1) |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 🥇 #1 | SwiftCypher-4B (+Guardrail+1Shot) | Track 2 (JSON) |
70.83% | 62.50% | 79.17% | 60.00% | 88.00% | 95.40% | 90.64% | 99.33% | 1768 ms |
| 🥈 #2 | SwiftCypher-4B (Standalone) | Track 2 (JSON) |
70.83% | 62.50% | 79.17% | 60.00% | 87.10% | 95.40% | 91.59% | 99.33% | 1768 ms |
| 🥉 #3 | Neo4j-Gemma-3-4B-2025.04 (Official) |
Track 1 (NativeRaw) |
70.42% | 64.17% | 76.67% | 50.00% | 0.00% | 94.80% | 92.55% | 0.00% (T2) | 2249 ms |
| #4 | Qwen2.5-Coder-3B-Instruct |
Track 1 (NativeRaw) |
51.67% | 54.17% | 49.17% | 41.67% | 78.79% | 55.60% | 79.60% | 100.00% (T2) | 913 ms |
| #5 | Qwen3-4B-Instruct-2507 (Base) |
Track 1 (NativeRaw) |
51.67% | 46.67% | 56.67% | 38.33% | 88.89% | 65.40% | 81.14% | 100.00% (T2) | 1695 ms |
🔬 Post-Training Pareto Ablation (SFT vs. RPO-DPO vs. WARP) & Reproducible Audit Files
| Variant | Kuzu Live EX | Direction-Trap EX | Refusal F1 | False Refusal Rate | Neo4j 2025v1 Schema+Dir | Structural F1 | p50 Latency |
Composite Pareto Score |
|---|---|---|---|---|---|---|---|---|
| SFT (Selected) | 70.83% | 60.00% | 87.10% | 4.17% | 95.40% | 91.59% | 1768 ms | 0.7690 |
| DPO | 33.75% | 35.00% | 51.08% | 46.67% | 83.40% | 77.94% | 1909 ms | 0.2722 |
| WARP | 65.42% | 50.00% | 81.08% | 11.67% | 91.80% | 87.78% | 2751 ms | 0.6713 |
Hosted Reproducible Ranking & Evaluation Artifacts (In This Repo)
outputs/leaderboard_rankings.json— Complete#1–#5ranked leaderboard & category deltasoutputs/benchmark_report.json— Raw Two-Track (NativeRawvsStructured JSON) metrics across 800 queriesoutputs/pareto_selection_report.json— SFT vs. RPO-DPO vs. WARP (0.85*SFT + 0.15*DPO) Pareto selection audit
🚀 Quickstart (Transformers + PEFT & vLLM Serving)
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_id = "Qwen/Qwen3-4B-Instruct-2507"
lora_id = "xiain/SwiftCypher-4B-LoRA"
tok = AutoTokenizer.from_pretrained(base_id)
base = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, lora_id).eval()
system_prompt = (
"You are SwiftCypher, a read-only openCypher generator for Neo4j, Memgraph, FalkorDB, and Kuzu.\n"
"Output ONLY one JSON object matching:\n"
'{"plan": string, "answerable": boolean, "cypher": string, "labels": string[], '
'"rel_types": string[], "missing_info": string[]}\n'
"Rules:\n"
"1. Use ONLY labels, relationship types, relationship directions (-> / <-), and properties present in the Schema.\n"
'2. Keep "plan" empty ("") for 1-2 hop queries; use <=60 chars only for 3+ hops or error repair.\n'
'3. Emit read-only Cypher only (MATCH, OPTIONAL MATCH, WHERE, WITH, UNWIND, RETURN, ORDER BY, SKIP, LIMIT, UNION). Never emit write/admin clauses.\n'
'4. If required labels, relationships, properties, or target entities are missing from the Schema, set "answerable": false, "cypher": "", and list missing items in "missing_info".'
)
msgs = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": "Schema:\n(:Person {name: STRING})-[:ACTED_IN]->(:Movie {title: STRING})\n\nQuestion:\n查询参演过 The Matrix 的演员姓名。"},
]
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
inputs = tok(prompt, return_tensors="pt").to(model.device)
out_ids = model.generate(**inputs, max_new_tokens=192, do_sample=False)
print(tok.decode(out_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
# Serve directly with vLLM dynamic LoRA adapter loading
vllm serve Qwen/Qwen3-4B-Instruct-2507 \
--enable-lora \
--lora-modules swiftcypher=xiain/SwiftCypher-4B-LoRA \
--max-lora-rank 64
Full <2ms AST/Direction Guardrail, FastAPI gateway, and benchmark suite: https://github.com/2422725977/swift-cypher.
- Downloads last month
- 28
Model tree for xiain/SwiftCypher-4B-LoRA
Base model
Qwen/Qwen3-4B-Instruct-2507Datasets used to train xiain/SwiftCypher-4B-LoRA
xiain/SwiftCypher-Kuzu-Live-300
Space using xiain/SwiftCypher-4B-LoRA 1
Collection including xiain/SwiftCypher-4B-LoRA
Evaluation results
- Execution Accuracy (System + 1-Shot Guardrail) on SwiftCypher-Kuzu-Live-300test set self-reported70.830
- Chinese GraphRAG Execution Accuracy on SwiftCypher-Kuzu-Live-300test set self-reported79.170
- Asymmetric Direction-Trap EX on SwiftCypher-Kuzu-Live-300test set self-reported60.000
- Anti-Hallucination Refusal F1 on SwiftCypher-Kuzu-Live-300test set self-reported88.000
- Strict JSON Compliance on SwiftCypher-Kuzu-Live-300test set self-reported99.330
- Schema & Direction Whitelist Valid Rate (System) on neo4j/text2cypher-2025v1test set self-reported95.400
- OpenCypher AST Syntax Valid Rate (Standalone) on neo4j/text2cypher-2025v1test set self-reported98.200
- Structural Cypher F1 on neo4j/text2cypher-2025v1test set self-reported90.640