Instructions to use JosephZ/R1-SGG-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JosephZ/R1-SGG-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="JosephZ/R1-SGG-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("JosephZ/R1-SGG-7B") model = AutoModelForImageTextToText.from_pretrained("JosephZ/R1-SGG-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use JosephZ/R1-SGG-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "JosephZ/R1-SGG-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JosephZ/R1-SGG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/JosephZ/R1-SGG-7B
- SGLang
How to use JosephZ/R1-SGG-7B 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 "JosephZ/R1-SGG-7B" \ --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": "JosephZ/R1-SGG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "JosephZ/R1-SGG-7B" \ --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": "JosephZ/R1-SGG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use JosephZ/R1-SGG-7B with Docker Model Runner:
docker model run hf.co/JosephZ/R1-SGG-7B
# Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("JosephZ/R1-SGG-7B")
model = AutoModelForImageTextToText.from_pretrained("JosephZ/R1-SGG-7B")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))- Model Description
- R1-SGG: Compile Scene Graphs with Reinforcement Learning
- ✨ Happy Compiling!
Model Description
An end-to-end multimodal LLM for Scene Graph Generation (SGG), which was introduced in Compile Scene Graphs with Reinforcement Learning
R1-SGG: Compile Scene Graphs with Reinforcement Learning
Structured Visual Reasoning with Multimodal LLMs and Reinforcement Learning

🚀 Update
- ✅
R1-SGG-7B, R1-SGG-Zero-7B
- ✅ Support PSG dataset (bbox format only, not Panoptic)
- ✅ Updated loss implementation
- ✅ Always use
custom_per_device_train_batch_sizeinstead ofper_device_train_batch_sizefor faster sampling under gradient accumulation - ⚠️ Current loss implementation might still be affected by gradient accumulation: trl issue #3021
🛠️ Setup Environment
bash install.sh
Main dependencies:
- torch == 2.5.0 or 2.5.1 (cu124, optional)
- transformers (supports Qwen2VL, Qwen2.5VL)
- trl
- vLLM
📚 Dataset
Load preprocessed datasets via:
from datasets import load_dataset
db_train = load_dataset("JosephZ/vg150_train_sgg_prompt")["train"]
db_val = load_dataset("JosephZ/vg150_val_sgg_prompt")["train"]
or for PSG:
db_train = load_dataset("JosephZ/psg_train_sg")["train"] # keys: image_id, image, objects, relationships
db_val = load_dataset("JosephZ/psg_test_sg")["train"]
We transformed VG150 into HuggingFace Datasets format with keys:
image_idimageprompt_openprompt_closeobjectsrelationships
🔥 Supported Models
- Qwen/Qwen2-VL-2B-Instruct
- Qwen/Qwen2-VL-7B-Instruct
- Qwen/Qwen2.5-VL-3B-Instruct
- Qwen/Qwen2.5-VL-7B-Instruct
🏋️♂️ Training
Training with Supervised Fine-Tuning (SFT)
For SLURM users:
sbatch scripts/sft/7B_sgg.sh
For local machines:
bash scripts/sft_local/7B_sgg.sh
⏱️ Approximate training time:
- 2B models: ~4 hours (4×A100 SXM4 GPUs)
- 7B models: ~10 hours (4×A100 SXM4 GPUs)
Training with Reinforcement Learning (GRPO)
** Update (11/05/2025): to use "Hard Recall"**:
--reward_funcs format_reward edge_hard_reward
For A100 GPUs:
sbatch scripts/grpo/train_a100_2B.sh
(12 hours on 16×A100 GPUs)
For GH200 GPUs:
sbatch scripts/grpo/train_gh200.sh
(16 hours on 16×GH200 GPUs)
For clusters with many RTX_3090/4090 GPUs:
sbatch scripts/grpo/train_fused.sh
- Training 7B models on 24GB cards is possible with Zero3, but slow due to communication bottlenecks.
- (Fun fact: training with 120×RTX_4090 is crazy but severely limited by communication latency.)
💡 Recommended learning rate: 6e-7.
🧪 Inference and Evaluation
Inference with SFT-trained models:
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR
For models trained with predefined categories, add true:
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR true
Inference with GRPO-trained models:
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR false/true true
Evaluation:
DATASET_TYPE=vg # or psg
python src/sgg_gather_preds.py $DATASET_TYPE $OUTPUT_DIR sgg_pred_results.json
python src/vg150_eval.py $DATASET sgg_pred_results.json
🤝 Acknowledgement
The GRPOTrainer used in this project is based on trl's GRPOTrainer, extended to support multimodal inputs.
📖 Citation
If you find this work helpful, please cite:
@article{chen2025compile,
title={Compile Scene Graphs with Reinforcement Learning},
author={Chen, Zuyao and Wu, Jinlin and Lei, Zhen and Pollefeys, Marc and Chen, Chang Wen},
journal={arXiv preprint arXiv:2504.13617},
year={2025}
}
✨ Happy Compiling!
- Downloads last month
- 30
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="JosephZ/R1-SGG-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)