Interpretability for VLMs (pure hand-written, no vibe-coding)
Python
4
15 commits
updated Jan 6, 2026
π We encourage everyone to explore deeper on VLMs based on our methods!
Inspired by the dual-stream hypothesis of human vision, which distinguishes the "what" and "where" pathways, we deconstruct the visual processing in VLMs into two parts:
For object recognition, we convert images into text token maps and find that the model's perception of image content unfolds as a two-stage process from shallow to deep layers, beginning with attribute recognition and culminating in semantic disambiguation.
For spatial perception, we theoretically derive and empirically verify the geometric structure underlying the positional representation in VLMs.
Based on these findings, we introduce an instruction-agnostic token compression algorithm based on a plug-and-play visual decoder to improve decoding efficiency, and a RoPE scaling technique to enhance spatial reasoning. Through rigorous experiments, our work validates these analyses, offering a deeper understanding of VLM internals and providing clear principles for designing more capable future architectures.
We recommend you to create a conda environment first as follows:
conda create -n mm python=3.12
conda activate mm
Then clone our repository and install the required packages:
git clone https://github.com/Siriuslala/vlm_interp.git
cd vlm_interp
pip install -r requirements.txt
Before starting, please create a .env file, and finish the configuration of the environment variables following the example in .env_example:
ROOT_DIR=./ # where your code is located
DATA_DIR=/path/to/your/data # where your data is located
WORK_DIR=/path/to/your/work # intermediate files (e.g., model checkpoints, log files, etc.)
[vlm_interp/]
βββ .env_example
βββ eval # evaluation scripts
β βββ CHAIR
β βββ COCO
β βββ GQA
β βββ MMBench
β βββ MME
β βββ POPE
β βββ SQA
β βββ TextVQA
β βββ VQA
β βββ VSR
β βββ WhatsUp
β β βββ bboxes # our annotations for WhatsUp
β β βββ dataset_zoo
β βββ custom_data.py
β βββ data_utils.py
βββ font
β βββ SimHei.ttf
βββ model # include the visual decoder and RoPE scaling model
β βββ qwen2_vl_rope_scaling.py
β βββ unembedding.py
βββ patch # monkey patch files
β βββ intern_2_5_hijack.py
β βββ internvl2_5_utils
β βββ llava1_5_vl_hijack.py
β βββ monkey_patch.py
β βββ qwen2_5_vl_hijack.py
βββ requirements.txt
βββ test # simple tests
β βββ test_intern.py
β βββ test_llava.py
β βββ test_pred.py
β βββ test_pred_batch.py
β βββ test_qwen.py
βββ test_direction.py # test scripts for the exploration of spatial perception
βββ test_pos_embed.py # test scripts for the exploration of positional embedding
βββ test_seg_map.py # test scripts for the exploration of object recognition
βββ train_rope_scaling # scripts for training the RoPE scaling model
β βββ qwen2_vl_sft_parallel.py
β βββ qwen2_vl_sft_single_gpu.py
β βββ qwen_vl_finetune
β βββ scripts
β βββ sft.sh
β βββ sft_official.sh
β βββ sft_parellel.sh
βββ train_unembedding # scripts for training the visual decoder for token compression
β βββ dataset.py
β βββ draw.py
β βββ scripts
β β βββ train.sh
β βββ train.py
βββ utils
βββ __init__.py
βββ data_process.py # scripts for processing the dataset
βββ download.py
βββ draw_file_tree.py
βββ env.sh
βββ font.sh
βββ intern_vl.py
The scripts for object recognition are located in test_seg_map.py.
This script contains the functions corresponding to the experiments in Section 3 of our paper. Specific usage details can be found in the comments of the script (after if __name__ == '__main__':).
Some of the important functions in test_seg_map.py are:
seg_with_unembedding_tokens: draw the text maps and segmentation maps for LLaVA;seg_with_unembedding_tokens_qwen: draw the text maps and segmentation maps for QwenVL;The scripts for spatial perception are located in test_direction.py.
This script contains the functions corresponding to the experiments in Section 4 of our paper. Specific usage details can be found in the comments of the script (after if __name__ == '__main__':).
Some of the important functions in test_direction.py are:
explore_1d_pos_embed_visual_geometry: plot the 1D positional embedding in visual geometry (Section 4.1);get_relation_representations_layerwise: plot the relation representations layerwise for left of, right of, behind, in front of (Section 4.2);intervene_in_spatial_reasoning: intervene in the spatial reasoning process (Section 4.2);erase_object_in_llm: the erase test in Section 4.2;@article{li2025reading,
title={Reading Images Like Texts: Sequential Image Understanding in Vision-Language Models},
author={Li, Yueyan and Zhao, Chenggong and Zang, Zeyuan and Yuan, Caixia and Wang, Xiaojie},
journal={arXiv preprint arXiv:2509.19191},
year={2025}
}
Interpretability for VLMs (pure hand-written, no vibe-coding)
Python
4
15 commits
updated Jan 6, 2026
π We encourage everyone to explore deeper on VLMs based on our methods!
Inspired by the dual-stream hypothesis of human vision, which distinguishes the "what" and "where" pathways, we deconstruct the visual processing in VLMs into two parts:
For object recognition, we convert images into text token maps and find that the model's perception of image content unfolds as a two-stage process from shallow to deep layers, beginning with attribute recognition and culminating in semantic disambiguation.
For spatial perception, we theoretically derive and empirically verify the geometric structure underlying the positional representation in VLMs.
Based on these findings, we introduce an instruction-agnostic token compression algorithm based on a plug-and-play visual decoder to improve decoding efficiency, and a RoPE scaling technique to enhance spatial reasoning. Through rigorous experiments, our work validates these analyses, offering a deeper understanding of VLM internals and providing clear principles for designing more capable future architectures.
We recommend you to create a conda environment first as follows:
conda create -n mm python=3.12
conda activate mm
Then clone our repository and install the required packages:
git clone https://github.com/Siriuslala/vlm_interp.git
cd vlm_interp
pip install -r requirements.txt
Before starting, please create a .env file, and finish the configuration of the environment variables following the example in .env_example:
ROOT_DIR=./ # where your code is located
DATA_DIR=/path/to/your/data # where your data is located
WORK_DIR=/path/to/your/work # intermediate files (e.g., model checkpoints, log files, etc.)
[vlm_interp/]
βββ .env_example
βββ eval # evaluation scripts
β βββ CHAIR
β βββ COCO
β βββ GQA
β βββ MMBench
β βββ MME
β βββ POPE
β βββ SQA
β βββ TextVQA
β βββ VQA
β βββ VSR
β βββ WhatsUp
β β βββ bboxes # our annotations for WhatsUp
β β βββ dataset_zoo
β βββ custom_data.py
β βββ data_utils.py
βββ font
β βββ SimHei.ttf
βββ model # include the visual decoder and RoPE scaling model
β βββ qwen2_vl_rope_scaling.py
β βββ unembedding.py
βββ patch # monkey patch files
β βββ intern_2_5_hijack.py
β βββ internvl2_5_utils
β βββ llava1_5_vl_hijack.py
β βββ monkey_patch.py
β βββ qwen2_5_vl_hijack.py
βββ requirements.txt
βββ test # simple tests
β βββ test_intern.py
β βββ test_llava.py
β βββ test_pred.py
β βββ test_pred_batch.py
β βββ test_qwen.py
βββ test_direction.py # test scripts for the exploration of spatial perception
βββ test_pos_embed.py # test scripts for the exploration of positional embedding
βββ test_seg_map.py # test scripts for the exploration of object recognition
βββ train_rope_scaling # scripts for training the RoPE scaling model
β βββ qwen2_vl_sft_parallel.py
β βββ qwen2_vl_sft_single_gpu.py
β βββ qwen_vl_finetune
β βββ scripts
β βββ sft.sh
β βββ sft_official.sh
β βββ sft_parellel.sh
βββ train_unembedding # scripts for training the visual decoder for token compression
β βββ dataset.py
β βββ draw.py
β βββ scripts
β β βββ train.sh
β βββ train.py
βββ utils
βββ __init__.py
βββ data_process.py # scripts for processing the dataset
βββ download.py
βββ draw_file_tree.py
βββ env.sh
βββ font.sh
βββ intern_vl.py
The scripts for object recognition are located in test_seg_map.py.
This script contains the functions corresponding to the experiments in Section 3 of our paper. Specific usage details can be found in the comments of the script (after if __name__ == '__main__':).
Some of the important functions in test_seg_map.py are:
seg_with_unembedding_tokens: draw the text maps and segmentation maps for LLaVA;seg_with_unembedding_tokens_qwen: draw the text maps and segmentation maps for QwenVL;The scripts for spatial perception are located in test_direction.py.
This script contains the functions corresponding to the experiments in Section 4 of our paper. Specific usage details can be found in the comments of the script (after if __name__ == '__main__':).
Some of the important functions in test_direction.py are:
explore_1d_pos_embed_visual_geometry: plot the 1D positional embedding in visual geometry (Section 4.1);get_relation_representations_layerwise: plot the relation representations layerwise for left of, right of, behind, in front of (Section 4.2);intervene_in_spatial_reasoning: intervene in the spatial reasoning process (Section 4.2);erase_object_in_llm: the erase test in Section 4.2;@article{li2025reading,
title={Reading Images Like Texts: Sequential Image Understanding in Vision-Language Models},
author={Li, Yueyan and Zhao, Chenggong and Zang, Zeyuan and Yuan, Caixia and Wang, Xiaojie},
journal={arXiv preprint arXiv:2509.19191},
year={2025}
}