Instructions to use ragraph-ai/stable-cypher-instruct-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ragraph-ai/stable-cypher-instruct-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ragraph-ai/stable-cypher-instruct-3b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ragraph-ai/stable-cypher-instruct-3b") model = AutoModelForCausalLM.from_pretrained("ragraph-ai/stable-cypher-instruct-3b") 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]:])) - llama-cpp-python
How to use ragraph-ai/stable-cypher-instruct-3b with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="ragraph-ai/stable-cypher-instruct-3b", filename="stable-cypher-instruct-3b.Q4_K_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use ragraph-ai/stable-cypher-instruct-3b with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M # Run inference directly in the terminal: llama-cli -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M # Run inference directly in the terminal: llama-cli -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
Use Docker
docker model run hf.co/ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use ragraph-ai/stable-cypher-instruct-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ragraph-ai/stable-cypher-instruct-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ragraph-ai/stable-cypher-instruct-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
- SGLang
How to use ragraph-ai/stable-cypher-instruct-3b 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 "ragraph-ai/stable-cypher-instruct-3b" \ --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": "ragraph-ai/stable-cypher-instruct-3b", "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 "ragraph-ai/stable-cypher-instruct-3b" \ --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": "ragraph-ai/stable-cypher-instruct-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use ragraph-ai/stable-cypher-instruct-3b with Ollama:
ollama run hf.co/ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
- Unsloth Studio new
How to use ragraph-ai/stable-cypher-instruct-3b with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ragraph-ai/stable-cypher-instruct-3b to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ragraph-ai/stable-cypher-instruct-3b to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ragraph-ai/stable-cypher-instruct-3b to start chatting
- Docker Model Runner
How to use ragraph-ai/stable-cypher-instruct-3b with Docker Model Runner:
docker model run hf.co/ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
- Lemonade
How to use ragraph-ai/stable-cypher-instruct-3b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ragraph-ai/stable-cypher-instruct-3b:Q4_K_M
Run and chat with the model
lemonade run user.stable-cypher-instruct-3b-Q4_K_M
List all available models
lemonade list
Model Description
A specialized 3B parameters model beating SOTA models such as GPT4-o at generating CYPHER. It's a finetune of https://huggingface.co/stabilityai/stable-code-instruct-3b trained on https://github.com/neo4j-labs/text2cypher/tree/main/datasets/synthetic_opus_demodbs to generate CYPHER queries from text to query GraphDB such as neo4j.
Usage
Safetensors (recommended)
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("ragraph-ai/stable-cypher-instruct-3b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("ragraph-ai/stable-cypher-instruct-3b", torch_dtype=torch.bfloat16, trust_remote_code=True)
messages = [
{
"role": "user",
"content": "Show me the people who have Python and Cloud skills and have been in the company for at least 3 years."
}
]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
tokens = model.generate(
**inputs,
max_new_tokens=128,
do_sample=True,
top_p=0.9,
temperature=0.2,
pad_token_id=tokenizer.eos_token_id,
)
outputs = tokenizer.batch_decode(tokens[:, inputs.input_ids.shape[-1]:], skip_special_tokens=False)[0]
GGUF
from llama_cpp import Llama
# Load the GGUF model
print("Loading model...")
model = Llama(
model_path=r"C:\Users\John\stable-cypher-instruct-3b.Q4_K_M.gguf",
n_ctx=512,
n_batch=512,
n_gpu_layers=-1, # Use all available GPU layers
max_tokens=128,
top_p=0.9,
temperature=0.2,
verbose=False
)
# Define your question
question = "Show me the people who have Python and Cloud skills and have been in the company for at least 3 years."
# Create the full prompt (simulating the apply_chat_template function)
full_prompt = f"<|im_start|>system\nCreate a Cypher statement to answer the following question:<|im_end|>\n<|im_start|>user\n{question}<|im_end|>\n<|im_start|>assistant\n"
# Generate response
print("Generating response...")
response = model(
full_prompt,
max_tokens=128,
stop=["<|im_end|>", "<|im_start|>"],
echo=False
)
# Extract and print the generated response
answer = response['choices'][0]['text'].strip()
print("\nQuestion:", question)
print("\nGenerated Cypher statement:")
print(answer)
Performance
| Metric | stable-code-instruct-3b | gpt4-o | stable-cypher-instruct-3b |
|---|---|---|---|
| BLEU-4 | 19.07 | 32.35 | 88.63 |
| ROUGE-1 | 39.49 | 69.17 | 95.09 |
| ROUGE-2 | 24.82 | 46.97 | 90.71 |
| ROUGE-L | 29.63 | 65.24 | 91.51 |
| Jaro-Winkler | 52.21 | 86.38 | 95.69 |
| Jaccard | 25.55 | 72.80 | 90.78 |
| Pass@1 | 0.00 | 0.00 | 51.80 |
Example
Eval params
Reproducability
This is the config file from Llama Factory :
{
"top.model_name": "Custom",
"top.finetuning_type": "lora",
"top.adapter_path": [],
"top.quantization_bit": "none",
"top.template": "default",
"top.rope_scaling": "none",
"top.booster": "none",
"train.training_stage": "Supervised Fine-Tuning",
"train.dataset_dir": "data",
"train.dataset": [
"cypher_opus"
],
"train.learning_rate": "2e-4",
"train.num_train_epochs": "5.0",
"train.max_grad_norm": "1.0",
"train.max_samples": "5000",
"train.compute_type": "fp16",
"train.cutoff_len": 256,
"train.batch_size": 16,
"train.gradient_accumulation_steps": 2,
"train.val_size": 0.1,
"train.lr_scheduler_type": "cosine",
"train.logging_steps": 10,
"train.save_steps": 100,
"train.warmup_steps": 20,
"train.neftune_alpha": 0,
"train.optim": "adamw_torch",
"train.resize_vocab": false,
"train.packing": false,
"train.upcast_layernorm": false,
"train.use_llama_pro": false,
"train.shift_attn": false,
"train.report_to": false,
"train.num_layer_trainable": 3,
"train.name_module_trainable": "all",
"train.lora_rank": 64,
"train.lora_alpha": 64,
"train.lora_dropout": 0.1,
"train.loraplus_lr_ratio": 0,
"train.create_new_adapter": false,
"train.use_rslora": false,
"train.use_dora": true,
"train.lora_target": "",
"train.additional_target": "",
"train.dpo_beta": 0.1,
"train.dpo_ftx": 0,
"train.orpo_beta": 0.1,
"train.reward_model": null,
"train.use_galore": false,
"train.galore_rank": 16,
"train.galore_update_interval": 200,
"train.galore_scale": 0.25,
"train.galore_target": "all"
}
I used llama.cpp to merge the LoRa and generate the quants.
The progress achieved from the base model is significant but you will still need to finetune on your company's syntax and entities. I've been tickering with the training parameters for a few batches of training but there is room for improvements. I'm open to the idea of making a full tutorial if there is enough interest in this project.
- Downloads last month
- 625
Model tree for ragraph-ai/stable-cypher-instruct-3b
Base model
stabilityai/stable-code-instruct-3b
