Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,173 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# Model
|
| 7 |
|
| 8 |
<!-- Provide a quick summary of what the model is/does. -->
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
##
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
|
| 159 |
-
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
-
|
|
|
|
| 192 |
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model:
|
| 3 |
+
- Qwen/Qwen2-VL-7B-Instruct
|
| 4 |
+
datasets:
|
| 5 |
+
- JosephZ/vg150_train_sgg_prompt
|
| 6 |
library_name: transformers
|
| 7 |
+
license: apache-2.0
|
| 8 |
+
metrics:
|
| 9 |
+
- recall
|
| 10 |
+
tags:
|
| 11 |
+
- image
|
| 12 |
+
- scene-graph
|
| 13 |
+
- scene-graph-generation
|
| 14 |
+
pipeline_tag: image-text-to-text
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# Model Description
|
| 18 |
|
| 19 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 20 |
+
An end-to-end multimodal LLM for Scene Graph Generation (SGG), which was introduced in [Compile Scene Graphs with Reinforcement Learning](https://huggingface.co/papers/2504.13617)
|
| 21 |
|
| 22 |
+
# R1-SGG: Compile Scene Graphs with Reinforcement Learning
|
| 23 |
|
| 24 |
+
## **Structured Visual Reasoning with Multimodal LLMs and Reinforcement Learning**
|
| 25 |
+
[](https://arxiv.org/abs/2504.13617) [](LICENSE) [](https://huggingface.co/spaces/JosephZ/R1-SGG)
|
| 26 |
+
---
|
| 27 |
|
| 28 |
+
## 🚀 Update
|
| 29 |
+
- ✅ [R1-SGG-7B](https://huggingface.co/JosephZ/R1-SGG-7B), [R1-SGG-Zero-7B](https://huggingface.co/JosephZ/R1-SGG-Zero-7B)
|
| 30 |
+
- ✅ Support [PSG](https://github.com/Jingkang50/OpenPSG) dataset (bbox format only, not Panoptic)
|
| 31 |
+
- ✅ Updated loss implementation
|
| 32 |
+
- ✅ Always use `custom_per_device_train_batch_size` instead of `per_device_train_batch_size` for faster sampling under gradient accumulation
|
| 33 |
+
- ⚠️ Current loss implementation might still be affected by gradient accumulation: [trl issue #3021](https://github.com/huggingface/trl/issues/3021)
|
|
|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, Qwen2.5VL)
|
| 45 |
+
- trl
|
| 46 |
+
- vLLM
|
| 47 |
+
```
|
| 48 |
|
| 49 |
+
---
|
| 50 |
|
| 51 |
+
## 📚 Dataset
|
| 52 |
+
Load preprocessed datasets via:
|
| 53 |
+
```python
|
| 54 |
+
from datasets import load_dataset
|
| 55 |
+
|
| 56 |
+
db_train = load_dataset("JosephZ/vg150_train_sgg_prompt")["train"]
|
| 57 |
+
db_val = load_dataset("JosephZ/vg150_val_sgg_prompt")["train"]
|
| 58 |
+
```
|
| 59 |
+
or for PSG:
|
| 60 |
+
```python
|
| 61 |
+
db_train = load_dataset("JosephZ/psg_train_sg")["train"] # keys: image_id, image, objects, relationships
|
| 62 |
+
db_val = load_dataset("JosephZ/psg_test_sg")["train"]
|
| 63 |
+
```
|
| 64 |
+
We transformed VG150 into HuggingFace Datasets format with keys:
|
| 65 |
+
- `image_id`
|
| 66 |
+
- `image`
|
| 67 |
+
- `prompt_open`
|
| 68 |
+
- `prompt_close`
|
| 69 |
+
- `objects`
|
| 70 |
+
- `relationships`
|
| 71 |
|
| 72 |
+
---
|
| 73 |
|
| 74 |
+
## 🔥 Supported Models
|
| 75 |
+
- [x] Qwen/Qwen2-VL-2B-Instruct
|
| 76 |
+
- [x] Qwen/Qwen2-VL-7B-Instruct
|
| 77 |
+
- [x] Qwen/Qwen2.5-VL-3B-Instruct
|
| 78 |
+
- [x] Qwen/Qwen2.5-VL-7B-Instruct
|
| 79 |
|
| 80 |
+
---
|
| 81 |
|
| 82 |
+
## 🏋️♂️ Training
|
| 83 |
|
| 84 |
+
### Training with Supervised Fine-Tuning (SFT)
|
| 85 |
|
| 86 |
+
For **SLURM users**:
|
| 87 |
+
```bash
|
| 88 |
+
sbatch scripts/sft/7B_sgg.sh
|
| 89 |
+
```
|
| 90 |
|
| 91 |
+
For **local machines**:
|
| 92 |
+
```bash
|
| 93 |
+
bash scripts/sft_local/7B_sgg.sh
|
| 94 |
+
```
|
| 95 |
+
⏱️ Approximate training time:
|
| 96 |
+
- 2B models: ~4 hours (4×A100 SXM4 GPUs)
|
| 97 |
+
- 7B models: ~10 hours (4×A100 SXM4 GPUs)
|
| 98 |
|
| 99 |
+
---
|
| 100 |
|
| 101 |
+
### Training with Reinforcement Learning (GRPO)
|
| 102 |
+
** Update (11/05/2025): to use "Hard Recall"**:
|
| 103 |
+
```
|
| 104 |
+
--reward_funcs format_reward edge_hard_reward
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
For **A100 GPUs**:
|
| 108 |
+
```bash
|
| 109 |
+
sbatch scripts/grpo/train_a100_2B.sh
|
| 110 |
+
```
|
| 111 |
+
(12 hours on 16×A100 GPUs)
|
| 112 |
+
|
| 113 |
+
For **GH200 GPUs**:
|
| 114 |
+
```bash
|
| 115 |
+
sbatch scripts/grpo/train_gh200.sh
|
| 116 |
+
```
|
| 117 |
+
(16 hours on 16×GH200 GPUs)
|
| 118 |
+
|
| 119 |
+
For clusters with many RTX_3090/4090 GPUs:
|
| 120 |
+
```bash
|
| 121 |
+
sbatch scripts/grpo/train_fused.sh
|
| 122 |
+
```
|
| 123 |
+
- Training 7B models on 24GB cards is possible with Zero3, but slow due to communication bottlenecks.
|
| 124 |
+
- (Fun fact: training with 120×RTX_4090 is crazy but severely limited by communication latency.)
|
| 125 |
+
|
| 126 |
+
💡 **Recommended learning rate**: `6e-7`.
|
| 127 |
|
| 128 |
+
---
|
| 129 |
|
| 130 |
+
## 🧪 Inference and Evaluation
|
| 131 |
+
|
| 132 |
+
### Inference with SFT-trained models:
|
| 133 |
+
```bash
|
| 134 |
+
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR
|
| 135 |
+
```
|
| 136 |
+
For models trained **with predefined categories**, add `true`:
|
| 137 |
+
```bash
|
| 138 |
+
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR true
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
### Inference with GRPO-trained models:
|
| 142 |
+
```bash
|
| 143 |
+
bash scripts/inference/run_sgg_inference.sh $DATASET $MODEL_NAME $OUTPUT_DIR false/true true
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### Evaluation:
|
| 147 |
+
```bash
|
| 148 |
+
DATASET_TYPE=vg # or psg
|
| 149 |
+
python src/sgg_gather_preds.py $DATASET_TYPE $OUTPUT_DIR sgg_pred_results.json
|
| 150 |
+
python src/vg150_eval.py $DATASET sgg_pred_results.json
|
| 151 |
+
```
|
| 152 |
|
| 153 |
+
---
|
| 154 |
|
| 155 |
+
## 🤝 Acknowledgement
|
| 156 |
+
The `GRPOTrainer` used in this project is based on [trl's GRPOTrainer](https://github.com/huggingface/trl/blob/main/trl/trainer/grpo_trainer.py), extended to support multimodal inputs.
|
| 157 |
|
| 158 |
+
---
|
| 159 |
|
| 160 |
+
## 📖 Citation
|
| 161 |
+
If you find this work helpful, please cite:
|
| 162 |
+
```bibtex
|
| 163 |
+
@article{chen2025compile,
|
| 164 |
+
title={Compile Scene Graphs with Reinforcement Learning},
|
| 165 |
+
author={Chen, Zuyao and Wu, Jinlin and Lei, Zhen and Pollefeys, Marc and Chen, Chang Wen},
|
| 166 |
+
journal={arXiv preprint arXiv:2504.13617},
|
| 167 |
+
year={2025}
|
| 168 |
+
}
|
| 169 |
+
```
|
| 170 |
|
| 171 |
+
---
|
| 172 |
|
| 173 |
+
# ✨ Happy Compiling!
|