SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2312.04302 · 2023

Prompt Highlighter: Interactive Control for Multi-Modal LLMs

arXiv · PDF · Open in the Atlas

Code that ran

4 of 7 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; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 3 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/2312.04302.json · badge: /api/ran/2312.04302.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
dvlab-research/prompt-highlighter canonical (classifier label)
classifier basis: census
4 ran · 3 no recorded run
FunctionStatusWhere it lives
llama_new_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
dvlab-research/prompt-highlighter/highlighter_modules/attention_llama_llava.py
code served (permissive licence) · get_code("3b5481f5e9be9f14")
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 tuple. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 math
import torch
import torch.nn as nn
from typing import Optional, Tuple, List

torch.manual_seed(0)

# Create a minimal LlamaAttention-like module
class MinimalLlamaAttention(nn.Module):
    def __init__(self, hidden_size=8, num_heads=2):
        super().__init__()
        self.hidden_size = hidden_size
        self.num_heads = num_heads
        self.head_dim = hidden_size // num_heads
        
        self.q_proj = nn.Linear(hidden_size, hidden_size)
        self.k_proj = nn.Linear(hidden_size, hidden_size)
        self.v_proj = nn.Linear(hidden_size, hidden_size)
        self.o_proj = nn.Linear(hidden_size, hidden_size)
        
        # Mock rotary embeddings
        self.rotary_emb = MockRotaryEmbedding(self.head_dim)
        
        # Initialize hl_mask as None
        self.hl_mask = None

class MockRotaryEmbedding:
    def __init__(self, dim):
        self.dim = dim
    
    def __call__(self, x, seq_len=None):
        # Return cos and sin of appropriate shape
        # (num_heads, seq_len, head_dim)
        if seq_len is None:
            seq_len = x.shape[-2]
        num_heads = x.shape[0]
        head_dim = x.shape[-1]
        
        cos = torch.ones(num_heads, seq_len, head_dim)
        sin = torch.zeros(num_heads, seq_len, head_dim)
        return cos, sin

def mock_apply_rotary_pos_emb(q, k, cos, sin, position_ids):
    # Simple mock: just return q and k unchanged
    return q, k

def mock_repeat_kv(x, rep):
    return x

# Patch the imports in the test
import sys
from unittest.mock import MagicMock

# Create test instance
attention_module = MinimalLlamaAttention(hidden_size=8, num_heads=2)

# Set up parameters
batch_size = 2
seq_length = 3
hidden_size = 8

hidden_states = torch.randn(batch_size, seq_length, hidden_size)
position_ids = torch.arange(seq_length).unsqueeze(0).expand(batch_size, -1).long()

# Create attention mask: shape (batch_size, 1, seq_length, seq_length)
attention_mask = torch.zeros(batch_size, 1, seq_length, seq_length)

# No past key value for this test
past_key_value = None

ARGS = {
    'self': attention_module,
    'hidden_states': hidden_states,
    'attention_mask': attention_mask,
    'position_ids': position_ids,
    'past_key_value': past_key_value,
    'output_attentions': False,
    'use_cache': False,
    'attention_weight': 7.0
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
prepare_llava_hl_inputs_for_generation Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
dvlab-research/prompt-highlighter/highlighter_modules/attention_llama_llava.py
code served (permissive licence) · get_code("39225cb7adeb18ef")
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 dict. 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 torch
import torch.nn as nn

torch.manual_seed(0)

# Create small tensors for testing
batch_size = 2
seq_length = 5
vocab_size = 100
hidden_dim = 4

input_ids = torch.randint(0, vocab_size, (batch_size, seq_length))
attention_mask = torch.ones((batch_size, seq_length), dtype=torch.long)
inputs_embeds = torch.randn(batch_size, seq_length, hidden_dim)

# Create past_key_values (KV cache structure)
# Typical structure: tuple of tuples, where each inner tuple is (key, value) for each layer
num_layers = 2
num_heads = 2
head_dim = hidden_dim // num_heads

past_key_values = tuple(
    (
        torch.randn(batch_size, num_heads, seq_length, head_dim),
        torch.randn(batch_size, num_heads, seq_length, head_dim)
    )
    for _ in range(num_layers)
)

# Create image tensor (arbitrary shape for vision input)
images = torch.randn(batch_size, 3, 224, 224)

# Create masked_token_map
masked_token_map = torch.ones((batch_size, seq_length), dtype=torch.bool)

# Create a mock self object with the method
class MockLLaVAModel:
    def prepare_llava_hl_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs):
        if past_key_values:
            input_ids = input_ids[:, -1:]
        if inputs_embeds is not None and past_key_values is None:
            model_inputs = {'inputs_embeds': inputs_embeds}
        else:
            model_inputs = {'input_ids': input_ids}
        model_inputs.update({'past_key_values': past_key_values, 'use_cache': kwargs.get('use_cache'), 'attention_mask': attention_mask, 'images': kwargs.get('images', None), 'masked_token_map': kwargs.get('masked_token_map', None), 'attention_weight': kwargs.get('attention_weight', 1.0), 'perturb_weight': kwargs.get('perturb_weight', 0.01)})
        return model_inputs

self = MockLLaVAModel()

ARGS = {
    'self': self,
    'input_ids': input_ids,
    'past_key_values': past_key_values,
    'attention_mask': attention_mask,
    'inputs_embeds': inputs_embeds,
    'use_cache': True,
    'images': images,
    'masked_token_map': masked_token_map,
    'attention_weight': 1.5,
    'perturb_weight': 0.02
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float 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
qformer_new_forward Ran
ran; our contract draft was wrong, not the code
dvlab-research/prompt-highlighter/highlighter_modules/attention_qformer.py
code served (permissive licence) · get_code("c28cc1cc33573efa")
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 tuple. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 torch
import torch.nn as nn
import math

torch.manual_seed(0)

# Build a minimal QFormer attention layer class
class MinimalQFormerAttention(nn.Module):
    def __init__(self):
        super().__init__()
        self.num_attention_heads = 2
        self.attention_head_size = 2
        self.all_head_size = self.num_attention_heads * self.attention_head_size
        
        self.query = nn.Linear(4, self.all_head_size)
        self.key = nn.Linear(4, self.all_head_size)
        self.value = nn.Linear(4, self.all_head_size)
        
        self.dropout = nn.Dropout(0.1)
        self.position_embedding_type = "absolute"
        self.max_position_embeddings = 512
        
        # For relative position embeddings if needed
        self.distance_embedding = nn.Embedding(2 * self.max_position_embeddings - 1, self.attention_head_size)
        
        # For cross-attention masking
        self.hl_mask = torch.zeros(3)  # small mask
        self.save_attention = False
        self.attention_weight = math.log(7.0)
    
    def transpose_for_scores(self, x):
        # x shape: (batch_size, seq_length, all_head_size)
        batch_size, seq_length, _ = x.size()
        x = x.view(batch_size, seq_length, self.num_attention_heads, self.attention_head_size)
        return x.permute(0, 2, 1, 3)  # (batch_size, num_heads, seq_length, head_size)
    
    def save_attention_map(self, attention_probs):
        pass
    
    def save_attn_gradients(self, grad):
        pass

self_attention = MinimalQFormerAttention()

# Create tensors for the forward pass
batch_size = 2
seq_length = 3
hidden_dim = 4

hidden_states = torch.randn(batch_size, seq_length, hidden_dim)
attention_mask = torch.zeros(batch_size, 1, 1, seq_length)

ARGS = {
    'self': self_attention,
    'hidden_states': hidden_states,
    'attention_mask': attention_mask,
    'head_mask': None,
    'encoder_hidden_states': None,
    'encoder_attention_mask': None,
    'past_key_value': None,
    'output_attentions': False,
    'attention_weight': 7.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
txt_highlight_mask Ran
ran; our contract draft was wrong, not the code
dvlab-research/prompt-highlighter/highlighter_modules/utils.py
code served (permissive licence) · get_code("b043cf35354245c1")
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 tuple, ndim 2, dtype family float; 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.

class SimpleTokenizer:
    def tokenize(self, text):
        # Simple whitespace tokenizer
        return text.split()

tokenizer = SimpleTokenizer()
txt_prompt = "the quick brown fox jumps over lazy dog"
highlighted_idx_range = [" quick brown", [4, 10]]

ARGS = {
    "tokenizer": tokenizer,
    "txt_prompt": txt_prompt,
    "highlighted_idx_range": highlighted_idx_range,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple 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
blip_hl_generate Not yet run
unverified (harvested, no recorded run)
dvlab-research/prompt-highlighter/highlighter_modules/attention_qformer.py
code served (permissive licence) · get_code("92a6bceb61aa27f7")
How it ran

no invocation recorded.

llama_attn_forward Not yet run
unverified (harvested, no recorded run)
dvlab-research/prompt-highlighter/highlighter_modules/attention_llama_llava.py
code served (permissive licence) · get_code("22268c65d02b5f37")
How it ran

no invocation recorded.

qformer_attn_forward Not yet run
unverified (harvested, no recorded run)
dvlab-research/prompt-highlighter/highlighter_modules/attention_qformer.py
code served (permissive licence) · get_code("8bfff27cc6e1ad26")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 7 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.

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

This study targets a critical aspect of multi-modal LLMs' (LLMs&VLMs) inference: explicit controllable text generation. Multi-modal LLMs empower multi-modality understanding with the capability of semantic generation yet bring less explainability and heavier reliance on prompt contents due to their autoregressive generative nature. While manipulating prompt formats could improve outputs, designing specific and precise prompts per task can be challenging and ineffective. To tackle this issue, we introduce a novel inference method, Prompt Highlighter, which enables users to highlight specific prompt spans to interactively control the focus during generation. Motivated by the classifier-free diffusion guidance, we form regular and unconditional context pairs based on highlighted tokens, demonstrating that the autoregressive generation in models can be guided in a classifier-free way. Notably, we find that, during inference, guiding the models with highlighted tokens through the attention weights leads to more desired outputs. Our approach is compatible with current LLMs and VLMs, achieving impressive customized generation results without training. Experiments confirm its effectiveness in focusing on input contexts and generating reliable content. Without tuning on LLaVA-v1.5, our method secured 70.7 in the MMBench test and 1552.5 in MME-perception. The code is available at: https://github.com/dvlab-research/Prompt-Highlighter/

For agents

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

get_harvested_code_for_paper("2312.04302")
get_code_for_paper("2312.04302")
have("2312.04302")

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

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

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

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

Connect an agent — have() is free.