# liliupeng28/icml26-cvsearch architecture

> Architecture diagram of the GitHub repository liliupeng28/icml26-cvsearch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/liliupeng28/icml26-cvsearch
- Repository: https://github.com/liliupeng28/icml26-cvsearch

## Overview

1. **Repository shape**
   - The repo is organized as three major subsystems: `cvsearch/` for the CVSearch orchestration logic, `llava/` for multimodal LLM backbones and serving/training utilities, and `sam3/` for the visual expert and region-search machinery.
   - In practice, CVSearch is the top-level pipeline, while LLaVA and SAM3 are the model/runtime dependencies it composes.

2. **CVSearch core**
   - `cvsearch/CVSearch.py` and `cvsearch/perform_CVSearch.py` appear to be the main inference entrypoints for the paper’s “assess-then-search” workflow.
   - `cvsearch/models/` contains backbone-specific wrappers for **LLaVA**, **InternVL**, **QwenVL**, and **SAM3**, plus search-specific helpers like `tree.py` and `utils.py`.
   - This layer is where the framework decides when to answer directly, when to invoke visual search, and how to merge search results back into the final reasoning step.

3. **Search strategy boundary**
   - The architectural boundary in CVSearch is between **language-side assessment/reasoning** and **vision-side exploration**.
   - The search side uses semantic-aware patching and iterative bottom-up exploration rather than a fixed grid, which is why there is dedicated tree/search logic instead of just image preprocessing.
   - The repository’s benchmark-specific example prompts in `cvsearch/ic_examples/` indicate that search behavior is conditioned by task format and benchmark style.

4. **Backbone model adapters**
   - `cvsearch/models/modeling_llava.py`, `modeling_internvl.py`, and `modeling_qwenvl.py` provide a compatibility layer over different multimodal LLM families.
   - These wrappers likely normalize prompt format, image input handling, and response parsing so the search controller can work across multiple model backbones.
   - `modeling_sam3.py` connects the search framework to the SAM3 visual expert.

5. **LLaVA subsystem**
   - `llava/` is a self-contained multimodal model stack: conversation formatting, multimodal utilities, model builders, language-model variants, vision encoders, projectors, and resamplers.
   - It includes support for several LLM families under `llava/model/language_model/` and multiple vision encoders under `llava/model/multimodal_encoder/`.
   - The presence of projectors and resamplers shows the main architectural boundary inside LLaVA: raw visual embeddings are transformed before they are injected into the language model.

6. **SAM3 subsystem**
   - `sam3/` is the repository’s second major model stack and serves as the visual expert / segmentation engine used by CVSearch.
   - It contains:
     - `model/` for the core SAM3 image/video/trackers, encoders, decoders, memory, and vision-language combiner components,
     - `agent/` for higher-level inference orchestration with LLM and SAM3 clients,
     - `eval/` for image/video segmentation and tracking benchmarks,
     - `train/` for dataset loading, losses, transforms, and distributed training.
   - This subsystem is broader than just segmentation; it also supports tracking and video inference, which suggests CVSearch can rely on SAM3 for richer local-region discovery.

7. **Runtime data flow**
   - Typical flow: a benchmark sample is loaded, the chosen MLLM backbone performs an initial assessment, and CVSearch decides whether the answer is confident enough or whether search is required.
   - If search is triggered, the framework delegates to SAM3-based region proposal / expert assistance, crops or patches are generated, and the backbone is queried again with more focused visual evidence.
   - The search loop continues with pruning and adaptive patch selection until the answer is produced or the search budget is exhausted.

8. **Evaluation pipeline**
   - `cvsearch/eval/` contains benchmark-specific result scripts for `fines-bench`, `hr-bench`, `mme-realworld`, `treebench`, and `vstar`.
   - `cvsearch/run_eval_cvsearch.sh` is the main automation entrypoint for running the paper evaluations and generating answer files.
   - The evaluation flow is file-based: model outputs are written as JSONL answer logs, then scored by benchmark-specific post-processing scripts.

9. **Benchmark configuration and prompts**
   - The JSON files in `cvsearch/ic_examples/` encode task-specific few-shot or reasoning templates for different benchmarks and modes.
   - This makes prompt formatting part of the architecture, not just an external concern, because the search strategy depends on benchmark-specific instruction structure.

10. **Training code is present but not the main CVSearch path**
   - CVSearch itself is described as training-free, but the repo still includes training stacks for the underlying models.
   - `llava/train/` contains LLaVA fine-tuning, DPO, memory-aware, and search-training entrypoints.
   - `sam3/train/` contains full training support for SAM3, including configs, datasets, losses, optimizers, and distributed utilities.
   - These training subsystems are supporting infrastructure rather than the primary inference architecture.

11. **Serving and deployment**
   - `llava/serve/` provides controller/worker/gradio/CLI components for serving LLaVA-style models.
   - `sam3/agent/` provides agent-style inference and client abstractions for SAM3 and LLM integration.
   - These are separate runtime surfaces from the CVSearch benchmark runner, useful for demos or interactive use rather than batch evaluation.

12. **Model and asset dependencies**
   - The repo includes CLIP/EVA-related encoder code and vocab assets, indicating that visual encoding depends on pretrained vision backbones and their tokenization/configuration.
   - The README also calls out external checkpoints for SAM3, LLaVA-OneVision, InternVL2.5, and Qwen2.5/3-VL, plus the evaluation dataset bundle under `datasets/hr_data`.
   - Those external artifacts are important architectural dependencies because the repo mostly orchestrates pretrained models rather than defining them from scratch.

13. **Key architectural takeaway**
   - The repo is a composition framework: CVSearch coordinates an MLLM backbone plus a visual expert, with benchmark-specific evaluation wrappers around that loop.
   - The main diagram should show three boundaries: **multimodal reasoning backbones**, **visual search/expert extraction**, and **evaluation/benchmark drivers**.

Main entry points: [`cvsearch/models`](https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/models) (Model Adapters), [`llava/model/llava_arch.py`](https://github.com/liliupeng28/icml26-cvsearch/blob/main/llava/model/llava_arch.py) (LLaVA Arch), [`cvsearch/CVSearch.py`](https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/CVSearch.py) (CVSearch API), [`sam3/model`](https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/model) (SAM3 Model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cvsearch["CVSearch"]
  node_cvsearch_entry["CVSearch API<br/>orchestrator entrypoints<br/>[CVSearch.py]"]
  node_cvsearch_runner["Search Runner<br/>batch runner"]
  node_cvsearch_models["Model Adapters<br/>backbone wrappers"]
  node_cvsearch_tree{{"Search Tree<br/>search state<br/>[tree.py]"}}
  node_cvsearch_prompts["IC Prompts<br/>benchmark prompts"]
end

subgraph group_llava["LLaVA"]
  node_llava_builder["Model Builder<br/>model assembly<br/>[builder.py]"]
  node_llava_arch["LLaVA Arch<br/>multimodal core<br/>[llava_arch.py]"]
  node_llava_vision["Vision Encoders<br/>image encoders"]
  node_llava_projector["Projectors<br/>feature bridge"]
  node_llava_resampler["Resamplers<br/>token reducer"]
  node_llava_lms["LLM Variants<br/>language backbones"]
end

subgraph group_sam3["SAM3"]
  node_sam3_core["SAM3 Model<br/>vision expert core"]
  node_sam3_agent["Agent Runtime<br/>inference orchestration"]
  node_sam3_eval["SAM3 Eval<br/>segmentation/tracking eval"]
  node_sam3_train["SAM3 Train<br/>training stack"]
end

subgraph group_eval["Evaluation"]
  node_cvsearch_eval["Bench Eval<br/>benchmark scoring"]
  node_cvsearch_script["Eval Script<br/>automation"]
end

node_cvsearch_entry -->|"dispatches to"| node_cvsearch_models
node_cvsearch_runner -->|"invokes"| node_cvsearch_entry
node_cvsearch_models -->|"uses"| node_llava_builder
node_cvsearch_models -->|"coordinates"| node_cvsearch_tree
node_cvsearch_models -->|"calls"| node_sam3_core
node_cvsearch_models -->|"conditions on"| node_cvsearch_prompts
node_llava_builder -->|"assembles"| node_llava_arch
node_llava_arch -->|"ingests"| node_llava_vision
node_llava_arch -->|"routes through"| node_llava_projector
node_llava_arch -->|"optionally uses"| node_llava_resampler
node_llava_arch -->|"pairs with"| node_llava_lms
node_sam3_agent -->|"orchestrates"| node_sam3_core
node_sam3_agent -->|"pairs with"| node_llava_lms
node_sam3_core -.->|"feeds"| node_sam3_eval
node_sam3_core -.->|"trained by"| node_sam3_train
node_cvsearch_entry -->|"delegates search to"| node_sam3_agent
node_cvsearch_entry -->|"produces outputs for"| node_cvsearch_eval
node_cvsearch_script -->|"automates"| node_cvsearch_runner
node_cvsearch_eval -.->|"depends on"| node_cvsearch_prompts

click node_cvsearch_entry "https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/CVSearch.py"
click node_cvsearch_runner "https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/perform_CVSearch.py"
click node_cvsearch_models "https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/models"
click node_cvsearch_tree "https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/models/tree.py"
click node_cvsearch_prompts "https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/ic_examples"
click node_llava_builder "https://github.com/liliupeng28/icml26-cvsearch/blob/main/llava/model/builder.py"
click node_llava_arch "https://github.com/liliupeng28/icml26-cvsearch/blob/main/llava/model/llava_arch.py"
click node_llava_vision "https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_encoder"
click node_llava_projector "https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_projector"
click node_llava_resampler "https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_resampler"
click node_llava_lms "https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/language_model"
click node_sam3_core "https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/model"
click node_sam3_agent "https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/agent"
click node_sam3_eval "https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/eval"
click node_sam3_train "https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/train"
click node_cvsearch_eval "https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/eval"
click node_cvsearch_script "https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/run_eval_cvsearch.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cvsearch_entry,node_cvsearch_runner,node_cvsearch_models,node_cvsearch_tree,node_cvsearch_prompts toneBlue
class node_llava_builder,node_llava_arch,node_llava_vision,node_llava_projector,node_llava_resampler,node_llava_lms toneAmber
class node_sam3_core,node_sam3_agent,node_sam3_eval,node_sam3_train toneMint
class node_cvsearch_eval,node_cvsearch_script toneRose
```

## Components

### CVSearch

Top-level assess-then-search orchestration and benchmark runners.

- [CVSearch API](https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/CVSearch.py): orchestrator entrypoints · Main inference entrypoints for the assess-then-search loop. · `cvsearch/CVSearch.py`
- [Search Runner](https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/perform_CVSearch.py): batch runner · Command-line flow for running CVSearch over benchmarks. · `cvsearch/perform_CVSearch.py`
- [Model Adapters](https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/models): backbone wrappers · Compatibility layer for different multimodal backbones and search helpers. · `cvsearch/models`
- [Search Tree](https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/models/tree.py): search state · Tree and utility logic for iterative bottom-up exploration and pruning. · `cvsearch/models/tree.py`
- [IC Prompts](https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/ic_examples): benchmark prompts · Benchmark-conditioned few-shot and reasoning templates. · `cvsearch/ic_examples`

### LLaVA

Multimodal language backbone stack used as one of the model runtimes.

- [Model Builder](https://github.com/liliupeng28/icml26-cvsearch/blob/main/llava/model/builder.py): model assembly · Builds and wires LLaVA multimodal models and components. · `llava/model/builder.py`
- [LLaVA Arch](https://github.com/liliupeng28/icml26-cvsearch/blob/main/llava/model/llava_arch.py): multimodal core · Core interface for mixing visual features into the language model. · `llava/model/llava_arch.py`
- [Vision Encoders](https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_encoder): image encoders · CLIP/EVA/HF/OpenCLIP/SigLIP-style visual backbones. · `llava/model/multimodal_encoder`
- [Projectors](https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_projector): feature bridge · Transforms visual embeddings before they enter the language model. · `llava/model/multimodal_projector`
- [Resamplers](https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/multimodal_resampler): token reducer · Compresses or reorganizes visual tokens for multimodal prompting. · `llava/model/multimodal_resampler`
- [LLM Variants](https://github.com/liliupeng28/icml26-cvsearch/tree/main/llava/model/language_model): language backbones · Supported language-model families used inside LLaVA. · `llava/model/language_model`

### SAM3

Visual expert, segmentation, tracking, and agent runtime.

- [SAM3 Model](https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/model): vision expert core · Image/video segmentation, tracking, memory, and combiner components. · `sam3/model`
- [Agent Runtime](https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/agent): inference orchestration · Higher-level LLM/SAM3 client integration and iterative region search assistance. · `sam3/agent`
- [SAM3 Eval](https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/eval): segmentation/tracking eval · Benchmark and metric toolkits for image, video, and tracking evaluation. · `sam3/eval`
- [SAM3 Train](https://github.com/liliupeng28/icml26-cvsearch/tree/main/sam3/train): training stack · Datasets, losses, transforms, optimizers, and distributed training support. · `sam3/train`

### Evaluation

Benchmark-specific scoring and automation around CVSearch.

- [Bench Eval](https://github.com/liliupeng28/icml26-cvsearch/tree/main/cvsearch/eval): benchmark scoring · Benchmark-specific result scripts for CVSearch outputs. · `cvsearch/eval`
- [Eval Script](https://github.com/liliupeng28/icml26-cvsearch/blob/main/cvsearch/run_eval_cvsearch.sh): automation · Main shell entrypoint for running paper evaluations. · `cvsearch/run_eval_cvsearch.sh`

## Connections

- CVSearch API → Model Adapters: dispatches to · Selects a backbone-specific wrapper and search mode.
- Search Runner → CVSearch API: invokes · Batch runner launches the core inference flow.
- Model Adapters → Model Builder: uses · LLaVA-compatible adapter can instantiate a LLaVA stack.
- Model Adapters → Search Tree: coordinates · Search wrappers manage tree state and adaptive patch selection.
- Model Adapters → SAM3 Model: calls · SAM3 adapter links search control to the visual expert.
- Model Adapters → IC Prompts: conditions on · Prompt templates vary by benchmark and reasoning mode.
- Model Builder → LLaVA Arch: assembles · Builds the multimodal model around the shared architecture.
- LLaVA Arch → Vision Encoders: ingests · Consumes visual features from supported encoders.
- LLaVA Arch → Projectors: routes through · Projects image features before language fusion.
- LLaVA Arch → Resamplers: optionally uses · Token compression/reformatting for multimodal inputs.
- LLaVA Arch → LLM Variants: pairs with · Multiple language-model families are supported behind the same interface.
- Agent Runtime → SAM3 Model: orchestrates · Agent layer drives SAM3 inference and expert queries.
- Agent Runtime → LLM Variants: pairs with · Agent runtime can combine LLM reasoning with SAM3 outputs.
- SAM3 Model → SAM3 Eval: feeds · Core model outputs are scored by evaluation tooling.
- SAM3 Model → SAM3 Train: trained by · Training stack supports the underlying SAM3 model family.
- CVSearch API → Agent Runtime: delegates search to · Search loop can request region proposals or expert assistance.
- CVSearch API → Bench Eval: produces outputs for · Inference emits answer logs consumed by benchmark scripts.
- Eval Script → Search Runner: automates · Shell wrapper launches evaluation runs.
- Bench Eval → IC Prompts: depends on · Benchmark post-processing assumes task-specific prompt/output formats.
