SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2403.11299 · ECCV · 2024

SQ-LLaVA: Self-Questioning for Large Vision-Language Assistant

Zhiqiang Tao, Can Qin, Zeyuan Chen, Jiamian Wang, Ran Xu, Guohao Sun

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 1 failure of our instrument; 2 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2403.11299.json · badge: /api/ran/2403.11299.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
heliossun/sq-llava canonical (classifier label)
classifier basis not recorded on the link
2 ran · 2 no recorded run
heliossun/SQ-LLaVA community
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
BroadMultiHeadAttention Ran
ran on a synthesized input
heliossun/SQ-LLaVA/sqllava/model/crossattentionLayer.py
code served (permissive licence) · get_code("d02a03fedb337e4b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from einops import rearrange
from torch import einsum

class BroadMultiHeadAttention(nn.Module):

    def __init__(self, dim, heads):
        super(BroadMultiHeadAttention, self).__init__()
        self.dim = dim
        self.heads = heads
        self.scale = (dim / heads) ** (-0.5)
        self.attend = nn.Softmax(dim=-1)

    def attend_with_rpe(self, Q, K):
        if Q.shape[0] == 1:
            Q = rearrange(Q.squeeze(0), 'i (heads d) -> heads i d', heads=self.heads)
            K = rearrange(K, 'b j (heads d) -> b heads j d', heads=self.heads)
            dots = einsum('hid, bhjd -> bhij', Q, K) * self.scale
        else:
            Q = rearrange(Q, 'b i (heads d) -> b heads i d', heads=self.heads)
            K = rearrange(K, 'b j (heads d) -> b heads j d', heads=self.heads)
            dots = einsum('bhid, bhjd -> bhij', Q, K) * self.scale
        return self.attend(dots)

    def forward(self, Q, K, V):
        attn = self.attend_with_rpe(Q, K)
        B, _, _ = K.shape
        _, N, _ = Q.shape
        V = rearrange(V, 'b j (heads d) -> b heads j d', heads=self.heads)
        out = einsum('bhij, bhjd -> bhid', attn, V)
        out = rearrange(out, 'b heads n d -> b n (heads d)', b=B, n=N)
        return out


INIT_ARGS = {
    'dim': 4,
    'heads': 2,
}

ARGS = {
    'Q': torch.randn(2, 3, 4),
    'K': torch.randn(2, 5, 4),
    'V': torch.randn(2, 5, 4),
}

if __name__ == '__main__':
    model = BroadMultiHeadAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
CrossAttentionLayer Ran
ran on a synthesized input
heliossun/SQ-LLaVA/sqllava/model/crossattentionLayer.py
code served (permissive licence) · get_code("437f9ed9e855f0de")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from einops import rearrange
from torch import einsum

class BroadMultiHeadAttention(nn.Module):

    def __init__(self, dim, heads):
        super(BroadMultiHeadAttention, self).__init__()
        self.dim = dim
        self.heads = heads
        self.scale = (dim / heads) ** (-0.5)
        self.attend = nn.Softmax(dim=-1)

    def attend_with_rpe(self, Q, K):
        if Q.shape[0] == 1:
            Q = rearrange(Q.squeeze(0), 'i (heads d) -> heads i d', heads=self.heads)
            K = rearrange(K, 'b j (heads d) -> b heads j d', heads=self.heads)
            dots = einsum('hid, bhjd -> bhij', Q, K) * self.scale
        else:
            Q = rearrange(Q, 'b i (heads d) -> b heads i d', heads=self.heads)
            K = rearrange(K, 'b j (heads d) -> b heads j d', heads=self.heads)
            dots = einsum('bhid, bhjd -> bhij', Q, K) * self.scale
        return self.attend(dots)

    def forward(self, Q, K, V):
        attn = self.attend_with_rpe(Q, K)
        B, _, _ = K.shape
        _, N, _ = Q.shape
        V = rearrange(V, 'b j (heads d) -> b heads j d', heads=self.heads)
        out = einsum('bhij, bhjd -> bhid', attn, V)
        out = rearrange(out, 'b heads n d -> b n (heads d)', b=B, n=N)
        return out

class CrossAttentionLayer(nn.Module):

    def __init__(self, qk_dim, v_dim, query_token_dim, tgt_token_dim, num_heads=8, attn_drop=0.0, proj_drop=0.0, drop_path=0.0, dropout=0.0):
        super(CrossAttentionLayer, self).__init__()
        assert qk_dim % num_heads == 0, f'dim {qk_dim} should be divided by num_heads {num_heads}.'
        assert v_dim % num_heads == 0, f'dim {v_dim} should be divided by num_heads {num_heads}.'
        self.num_heads = num_heads
        head_dim = qk_dim // num_heads
        self.scale = head_dim ** (-0.5)
        self.norm1 = nn.LayerNorm(query_token_dim)
        self.norm2 = nn.LayerNorm(query_token_dim)
        self.multi_head_attn = BroadMultiHeadAttention(qk_dim, num_heads)
        self.q = nn.Linear(query_token_dim, qk_dim, bias=True)
        self.k = nn.Linear(tgt_token_dim, qk_dim, bias=True)
        self.v = nn.Linear(tgt_token_dim, v_dim, bias=True)
        self.proj = nn.Linear(v_dim, query_token_dim)
        self.proj_drop = nn.Dropout(proj_drop)
        self.ffn = nn.Sequential(nn.Linear(query_token_dim, query_token_dim), nn.GELU(), nn.Dropout(dropout), nn.Linear(query_token_dim, query_token_dim), nn.Dropout(dropout))

    def forward(self, query, tgt_token):
        short_cut = query
        query = self.norm1(query)
        q = self.q(query)
        k = self.k(tgt_token)
        v = self.v(tgt_token)
        x = self.multi_head_attn(q, k, v)
        x = short_cut + self.proj_drop(self.proj(x))
        x = x + self.ffn(self.norm2(x))
        return x

INIT_ARGS = {
    'qk_dim': 8,
    'v_dim': 8,
    'query_token_dim': 4,
    'tgt_token_dim': 6,
    'num_heads': 2,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
    'drop_path': 0.0,
    'dropout': 0.0,
}

ARGS = {
    'query': torch.randn(1, 3, 4),
    'tgt_token': torch.randn(2, 5, 6),
}

if __name__ == '__main__':
    model = CrossAttentionLayer(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 3, 4)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
load_image Ran
ran, honoured the contract we drafted
heliossun/sq-llava/sqllava/eval/run_llava.py
code served (permissive licence) · get_code("9b3c1cb391672ccb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Image. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
from PIL import Image
import os

# Create a temporary image file for testing
temp_dir = tempfile.mkdtemp()
temp_image_path = os.path.join(temp_dir, "test_image.jpg")

# Create a simple test image
test_image = Image.new('RGB', (100, 100), color=(73, 109, 137))
test_image.save(temp_image_path)

# Define ARGS with a local file path
ARGS = {
    'image_file': temp_image_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, requests — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Image — a Image output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Image output the recorded ndim 3 and dtype family int describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
split_to_even_chunks Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
heliossun/sq-llava/llava_trainer.py
code served (permissive licence) · get_code("10893c4608c08075")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list, ndim 2, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Analyzing the function:
# - indices: a list/sequence of indices that will be iterated over
# - lengths: a dict-like or list-like object that maps indices to their lengths (accessed via lengths[index])
# - num_chunks: an integer specifying how many chunks to split into

# Create sample data
indices = [0, 1, 2, 3, 4, 5]
lengths = {0: 10, 1: 15, 2: 8, 3: 12, 4: 9, 5: 11}
num_chunks = 3

ARGS = {
    "indices": indices,
    "lengths": lengths,
    "num_chunks": num_chunks,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family int — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_mm_adapter_state_maybe_zero_3 Not yet run
unverified (harvested, no recorded run)
heliossun/sq-llava/llava_trainer.py
code served (permissive licence) · get_code("bb35e3ac741bb2c9")
How it ran

no invocation recorded.

maybe_zero_3 Not yet run
unverified (harvested, no recorded run)
heliossun/sq-llava/llava_trainer.py
code served (permissive licence) · get_code("735025744c1ab0cf")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 4 the same month, 4 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
load_image 85 other papers
19 dated earlier, 5 the same month, 57 later, 4 same year, order not determinable
2112.05682 (2021-12)
Self-attention Does Not Need $O(n^2)$ Memory
2305.10973 (2023-05)
Drag Your GAN: Interactive Point-based Manipulation on the Generative Image Manifold
2307.10490 (2023-07)
Abusing Images and Sounds for Indirect Instruction Injection in Multi-Modal LLMs
and 82 more not named here
get_mm_adapter_state_maybe_zero_3 43 other papers
10 dated earlier, 1 the same month, 32 later
2304.05884 (2023-04)
Unicom: Universal and Compact Representation Learning for Image Retrieval
2304.08485 (2023-04)
Visual Instruction Tuning
2310.03744 (2023-10)
Improved Baselines with Visual Instruction Tuning
and 40 more not named here
maybe_zero_3 42 other papers
10 dated earlier, 1 the same month, 31 later
2304.05884 (2023-04)
Unicom: Universal and Compact Representation Learning for Image Retrieval
2304.08485 (2023-04)
Visual Instruction Tuning
2310.03744 (2023-10)
Improved Baselines with Visual Instruction Tuning
and 39 more not named here
split_to_even_chunks 40 other papers
9 dated earlier, 1 the same month, 30 later
2304.05884 (2023-04)
Unicom: Universal and Compact Representation Learning for Image Retrieval
2304.08485 (2023-04)
Visual Instruction Tuning
2310.03744 (2023-10)
Improved Baselines with Visual Instruction Tuning
and 37 more not named here

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Recent advances in vision-language models have shown notable generalization in broad tasks through visual instruction tuning. However, bridging the gap between the pre-trained vision encoder and the large language models (LLMs) becomes the whole network's bottleneck. To improve cross-modality alignment, existing works usually consider more visual instruction data covering a broader range of vision tasks to fine-tune the model for question-answering, which, however, is costly to obtain and has not thoroughly explored the rich contextual information contained in images. This paper first attempts to harness the overlooked context within visual instruction data, training the model to self-supervised "learning" how to ask high-quality questions. In this way, we introduce a novel framework named SQ-LLaVA: Self-Questioning for Large Vision-Language Assistant. SQ-LLaVA exhibits proficiency in generating flexible and meaningful image-related questions while analyzing the visual clue and prior language knowledge, signifying an advanced level of generalized visual understanding. Moreover, fine-tuning SQ-LLaVA on higher-quality instruction data shows a performance improvement compared with traditional visual-instruction tuning methods. This improvement highlights the efficacy of self-questioning techniques in achieving a deeper and more nuanced comprehension of visual content across various contexts. Our code is available at https://github.com/heliossun/SQ-LLaVA.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2403.11299")
get_code_for_paper("2403.11299")
have("2403.11299")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2403.11299.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2403.11299.svg)](https://syntology.ai/paper/2403.11299)

Connect an agent — have() is free.