spatialchain commited on
Commit
1bbc95c
Β·
verified Β·
1 Parent(s): a2a4a1f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +199 -165
README.md CHANGED
@@ -1,207 +1,241 @@
1
  ---
2
  base_model: Qwen/Qwen3-VL-4B-Thinking
3
  library_name: peft
4
- pipeline_tag: text-generation
5
  tags:
6
- - base_model:adapter:Qwen/Qwen3-VL-4B-Thinking
7
- - lora
8
- - transformers
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
- # Model Card for Model ID
12
 
13
- <!-- Provide a quick summary of what the model is/does. -->
14
 
 
 
 
 
 
 
 
 
15
 
 
16
 
17
- ## Model Details
18
-
19
- ### Model Description
20
-
21
- <!-- Provide a longer summary of what this model is. -->
22
-
23
-
24
-
25
- - **Developed by:** [More Information Needed]
26
- - **Funded by [optional]:** [More Information Needed]
27
- - **Shared by [optional]:** [More Information Needed]
28
- - **Model type:** [More Information Needed]
29
- - **Language(s) (NLP):** [More Information Needed]
30
- - **License:** [More Information Needed]
31
- - **Finetuned from model [optional]:** [More Information Needed]
32
-
33
- ### Model Sources [optional]
34
-
35
- <!-- Provide the basic links for the model. -->
36
-
37
- - **Repository:** [More Information Needed]
38
- - **Paper [optional]:** [More Information Needed]
39
- - **Demo [optional]:** [More Information Needed]
40
-
41
- ## Uses
42
-
43
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
-
45
- ### Direct Use
46
-
47
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
-
49
- [More Information Needed]
50
-
51
- ### Downstream Use [optional]
52
-
53
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
-
55
- [More Information Needed]
56
-
57
- ### Out-of-Scope Use
58
-
59
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
-
61
- [More Information Needed]
62
-
63
- ## Bias, Risks, and Limitations
64
-
65
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
-
67
- [More Information Needed]
68
-
69
- ### Recommendations
70
 
71
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
 
73
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
 
 
 
74
 
75
- ## How to Get Started with the Model
76
 
77
- Use the code below to get started with the model.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- [More Information Needed]
80
 
81
  ## Training Details
82
 
83
- ### Training Data
84
-
85
- <!-- 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. -->
86
-
87
- [More Information Needed]
88
-
89
- ### Training Procedure
90
-
91
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
-
93
- #### Preprocessing [optional]
94
-
95
- [More Information Needed]
96
-
97
-
98
- #### Training Hyperparameters
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
-
102
- #### Speeds, Sizes, Times [optional]
103
-
104
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
-
106
- [More Information Needed]
107
 
108
  ## Evaluation
109
 
110
- <!-- This section describes the evaluation protocols and provides the results. -->
111
-
112
- ### Testing Data, Factors & Metrics
113
 
114
- #### Testing Data
115
 
116
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- [More Information Needed]
119
 
120
- #### Factors
121
 
122
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
 
124
- [More Information Needed]
 
 
 
 
125
 
126
- #### Metrics
127
 
128
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
 
130
- [More Information Needed]
 
 
131
 
132
- ### Results
133
 
134
- [More Information Needed]
 
 
135
 
136
- #### Summary
137
 
 
 
 
 
138
 
 
139
 
140
- ## Model Examination [optional]
141
 
142
- <!-- Relevant interpretability work for the model goes here -->
 
 
 
 
 
 
 
143
 
144
- [More Information Needed]
145
 
146
  ## Environmental Impact
147
 
148
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
-
150
- 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).
151
-
152
- - **Hardware Type:** [More Information Needed]
153
- - **Hours used:** [More Information Needed]
154
- - **Cloud Provider:** [More Information Needed]
155
- - **Compute Region:** [More Information Needed]
156
- - **Carbon Emitted:** [More Information Needed]
157
-
158
- ## Technical Specifications [optional]
159
-
160
- ### Model Architecture and Objective
161
-
162
- [More Information Needed]
163
-
164
- ### Compute Infrastructure
165
-
166
- [More Information Needed]
167
-
168
- #### Hardware
169
-
170
- [More Information Needed]
171
-
172
- #### Software
173
-
174
- [More Information Needed]
175
-
176
- ## Citation [optional]
177
-
178
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
-
180
- **BibTeX:**
181
-
182
- [More Information Needed]
183
-
184
- **APA:**
185
-
186
- [More Information Needed]
187
-
188
- ## Glossary [optional]
189
-
190
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
-
192
- [More Information Needed]
193
-
194
- ## More Information [optional]
195
-
196
- [More Information Needed]
197
-
198
- ## Model Card Authors [optional]
199
-
200
- [More Information Needed]
201
-
202
- ## Model Card Contact
203
-
204
- [More Information Needed]
205
- ### Framework versions
206
-
207
- - PEFT 0.19.1
 
1
  ---
2
  base_model: Qwen/Qwen3-VL-4B-Thinking
3
  library_name: peft
4
+ pipeline_tag: image-text-to-text
5
  tags:
6
+ - base_model:adapter:Qwen/Qwen3-VL-4B-Thinking
7
+ - lora
8
+ - peft
9
+ - transformers
10
+ - spatial-reasoning
11
+ - visual-question-answering
12
+ - chain-of-thought
13
+ license: apache-2.0
14
+ datasets:
15
+ - spatialchain/SpatialChain-Benchmark
16
+ language:
17
+ - en
18
  ---
19
 
20
+ # Qwen3-VL-4B-Thinking β€” SpatialChain LoRA Adapter
21
 
22
+ A LoRA adapter for **Qwen3-VL-4B-Thinking** fine-tuned on the [SpatialChain-Benchmark](https://huggingface.co/datasets/spatialchain/SpatialChain-Benchmark) dataset. The model learns to produce **scene-graph-grounded chain-of-thought reasoning** for binary spatial visual questions, structured as:
23
 
24
+ ```
25
+ <think>
26
+ [step-by-step spatial reasoning]
27
+ </think>
28
+ <answer>
29
+ yes / no
30
+ </answer>
31
+ ```
32
 
33
+ > An 8B variant is also available: [spatialchain/Qwen3-VL-8B-Thinking-SpatialChain](https://huggingface.co/spatialchain/Qwen3-VL-8B-Thinking-SpatialChain)
34
 
35
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ ## Model Details
38
 
39
+ | Field | Value |
40
+ |-------|-------|
41
+ | **Base model** | [Qwen/Qwen3-VL-4B-Thinking](https://huggingface.co/Qwen/Qwen3-VL-4B-Thinking) |
42
+ | **Adapter type** | LoRA (PEFT) |
43
+ | **Training data** | [SpatialChain-Benchmark](https://huggingface.co/datasets/spatialchain/SpatialChain-Benchmark) train split (28,350 examples) |
44
+ | **Task** | Binary spatial VQA with chain-of-thought |
45
+ | **Language** | English |
46
+ | **License** | Apache 2.0 |
47
 
48
+ ---
49
 
50
+ ## Quick Start
51
+
52
+ ```python
53
+ from transformers import AutoProcessor, AutoModelForVision2Seq
54
+ from peft import PeftModel
55
+ from PIL import Image
56
+ import torch
57
+
58
+ base = "Qwen/Qwen3-VL-4B-Thinking"
59
+ adapter = "spatialchain/Qwen3-VL-4B-Thinking-SpatialChain"
60
+
61
+ processor = AutoProcessor.from_pretrained(base, trust_remote_code=True)
62
+ model = AutoModelForVision2Seq.from_pretrained(
63
+ base, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True
64
+ )
65
+ model = PeftModel.from_pretrained(model, adapter)
66
+ model.eval()
67
+
68
+ image = Image.open("your_image.jpg").convert("RGB")
69
+
70
+ messages = [
71
+ {
72
+ "role": "system",
73
+ "content": [{"type": "text", "text": (
74
+ "Your task:\n"
75
+ "1. Analyze the image carefully.\n"
76
+ "2. Provide concise reasoning grounded in visible evidence from the image.\n"
77
+ "3. End your response with 'Answer: <one short sentence>'."
78
+ )}],
79
+ },
80
+ {
81
+ "role": "user",
82
+ "content": [
83
+ {"type": "image", "image": image},
84
+ {"type": "text", "text": "Is there a fence to the left of the person?"},
85
+ ],
86
+ },
87
+ ]
88
+
89
+ text = processor.apply_chat_template(
90
+ messages, tokenize=False, add_generation_prompt=True
91
+ )
92
+ inputs = processor(text=text, images=[image], return_tensors="pt").to(model.device)
93
+
94
+ with torch.inference_mode():
95
+ ids = model.generate(
96
+ **inputs,
97
+ max_new_tokens=512,
98
+ do_sample=True,
99
+ temperature=0.6,
100
+ top_p=0.95,
101
+ top_k=20,
102
+ )
103
+
104
+ print(processor.tokenizer.decode(ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
105
+ ```
106
+
107
+ ### With 4-bit quantization (lower VRAM)
108
+
109
+ ```python
110
+ from transformers import BitsAndBytesConfig
111
+
112
+ bnb = BitsAndBytesConfig(
113
+ load_in_4bit=True,
114
+ bnb_4bit_quant_type="nf4",
115
+ bnb_4bit_compute_dtype=torch.bfloat16,
116
+ bnb_4bit_use_double_quant=True,
117
+ )
118
+ model = AutoModelForVision2Seq.from_pretrained(
119
+ base, quantization_config=bnb, device_map="auto", trust_remote_code=True
120
+ )
121
+ model = PeftModel.from_pretrained(model, adapter)
122
+ ```
123
 
124
+ ---
125
 
126
  ## Training Details
127
 
128
+ ### Dataset
129
+
130
+ [SpatialChain-Benchmark](https://huggingface.co/datasets/spatialchain/SpatialChain-Benchmark) β€” 28,350 training examples pairing spatially-oriented GQA questions with scene-graph-grounded reasoning chains. Questions cover 11 spatial relation types (`left_of`, `right_of`, `above`, `behind`, `near`, `inside`, …); chains were generated with Claude Haiku 4.5 (extended thinking) and retained only when the generated answer matched the GQA ground truth.
131
+
132
+ Each training example target:
133
+ ```
134
+ <think>
135
+ Looking at the image, let me trace through this step-by-step:
136
+ (1) Locating the knife β€” I can see a knife on the left side of the plate.
137
+ (2) Finding the bread to the right of the knife β€” there is a large piece of bread ...
138
+ (3) Examining what is to the right of that bread β€” gray birds are standing on the plate.
139
+ (4) Looking for kittens β€” I do not see any kittens anywhere in the image.
140
+ </think>
141
+ <answer>
142
+ No, there is a bird to the right of the bread.
143
+ </answer>
144
+ ```
145
+
146
+ ### Hyperparameters
147
+
148
+ | Hyperparameter | Value |
149
+ |----------------|-------|
150
+ | Base model | Qwen3-VL-4B-Thinking |
151
+ | Quantization | 4-bit NF4 (BitsAndBytes) |
152
+ | LoRA rank (r) | 16 |
153
+ | LoRA alpha | 32 |
154
+ | LoRA dropout | 0.05 |
155
+ | RSLoRA | βœ“ |
156
+ | Target modules | all-linear |
157
+ | Modules to save | `lm_head`, `embed_tokens` |
158
+ | Epochs | 2 |
159
+ | Per-device batch size | 4 |
160
+ | Gradient accumulation | 3 (effective batch = 12) |
161
+ | Learning rate | 3 Γ— 10⁻⁡ |
162
+ | LR schedule | cosine |
163
+ | Warmup ratio | 0.05 |
164
+ | Max sequence length | 32,768 |
165
+ | Image max size | 640 px |
166
+ | Optimizer | AdamW fused |
167
+ | Hardware | 1 Γ— A100 80 GB |
168
+ | Training framework | HuggingFace Transformers + PEFT |
169
 
170
+ ---
 
 
 
 
 
 
171
 
172
  ## Evaluation
173
 
174
+ ### SpatialChain test set (n = 899)
 
 
175
 
176
+ Evaluation uses two complementary axes. **Axis 1** measures VQA accuracy (exact match after normalisation). **Axis 2** uses a scene-graph-aware LLM judge scoring reasoning faithfulness and completeness independently of the final answer β€” see the [evaluation code](https://huggingface.co/datasets/spatialchain/SpatialChain-Benchmark) for the full judge protocol.
177
 
178
+ | Metric | Base (4B) | **This model (4B FT)** |
179
+ |--------|-----------|------------------------|
180
+ | VQA Accuracy | 78.44% | **82.23%** |
181
+ | Macro F1 | 82.01% | **86.67%** |
182
+ | Yes-accuracy | 77.74% | 91.34% |
183
+ | No-accuracy | 79.64% | 66.57% |
184
+ | ROUGE-1 vs. reference chain | 0.403 | **0.657** |
185
+ | Token F1 vs. reference chain | 0.392 | **0.646** |
186
+ | Reasoning faithfulness (judge) | 0.585 | **0.631** |
187
+ | Reasoning completeness (judge) | 0.658 | **0.708** |
188
+ | Pass rate | 77.6% | **80.2%** |
189
+ | Shortcut rate ↓ | 26.4% | **19.4%** |
190
 
191
+ **Shortcut rate** = fraction of *correct* answers where the judge scores reasoning faithfulness < 0.5. Lower is better.
192
 
193
+ ### External benchmarks
194
 
195
+ SFT on SpatialChain improves in-domain performance but introduces a **stylistic specialisation effect** on out-of-distribution benchmarks β€” the model adopts the SpatialChain chain format even when the input distribution differs. Replay-augmented training is recommended to mitigate this.
196
 
197
+ | Benchmark | Base | Fine-tuned | Ξ” |
198
+ |-----------|------|------------|---|
199
+ | SpatialChain test | 78.4% | **82.2%** | +3.8 pp |
200
+ | [FlagEval/ERQA](https://huggingface.co/datasets/FlagEval/ERQA) | 45.3% | 38.0% | βˆ’7.3 pp |
201
+ | [FlagEval/EmbSpatial-Bench](https://huggingface.co/datasets/FlagEval/EmbSpatial-Bench) | 79.1% | 75.7% | βˆ’3.4 pp |
202
 
203
+ ---
204
 
205
+ ## Intended Use
206
 
207
+ - **Spatial VQA** β€” binary yes/no questions about object positions and relations in images
208
+ - **Reasoning audit** β€” producing interpretable spatial chains that can be verified against scene structure
209
+ - **Research** β€” studying the relationship between chain-of-thought quality and answer correctness in VLMs
210
 
211
+ ## Out-of-Scope Use
212
 
213
+ - Tasks requiring metric depth or 3D reasoning (scene graphs are symbolic, not metric)
214
+ - Open-ended image captioning or generation
215
+ - Non-English inputs
216
 
217
+ ## Bias and Limitations
218
 
219
+ - **Yes-bias** β€” the fine-tuned model exhibits a larger yes/no accuracy gap (+24.8 pp) than the base model (+1.9 pp), consistent with the 58% yes-rate in training data. Evaluation should report Yes-acc and No-acc separately.
220
+ - **Stylistic specialisation** β€” the model adopts a fixed reasoning format ("Looking at the image, let me trace through this step-by-step…") on all inputs, which may degrade performance on benchmarks with different prompt styles.
221
+ - **GQA domain** β€” training images are sourced from GQA (Visual Genome); performance on non-natural-image domains is unknown.
222
+ - **Projective bias** β€” 62.7% of training examples involve `left_of` / `right_of` relations; depth-ordered relations (`close`, `far`) are underrepresented.
223
 
224
+ ---
225
 
226
+ ## Citation
227
 
228
+ ```bibtex
229
+ @article{spatialchain2026,
230
+ title = {SpatialChain: A Benchmark for Auditing Spatial Reasoning Faithfulness in VLMs},
231
+ author = {Anonymous},
232
+ journal = {Under review at NeurIPS 2026},
233
+ year = {2026}
234
+ }
235
+ ```
236
 
237
+ ---
238
 
239
  ## Environmental Impact
240
 
241
+ Training ran for approximately **5 hours** on a single **A100 80 GB** GPU (cloud instance). Carbon emissions can be estimated with the [ML Impact Calculator](https://mlco2.github.io/impact#compute).