SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2111.14330 · ICLR · 2022

Sparse DETR: Efficient End-to-End Object Detection with Learnable Sparsity

Byungseok Roh, Jaewoong Shin, Wuhyun Shin, Saehoon Kim, Kakaobrain, Lunit

arXiv · PDF · Open in the Atlas

Code that ran

3 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 4 no recorded run), measured 2026-11-23; 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/2111.14330.json · badge: /api/ran/2111.14330.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
kakaobrain/sparse-detr canonical (classifier label)
classifier basis: classifier_2025
3 ran · 4 no recorded run
FunctionStatusWhere it lives
DeformableTransformerDecoder Ran
ran on a synthesized input · constructed an object; no result was computed
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("13b669de90269931")
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 an instance of its own class, DeformableTransformerDecoder: the run constructed the object and did not call it, so no result was computed. 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
from torch import Tensor

torch.manual_seed(0)

# Create a minimal decoder layer that satisfies the interface used in forward()
class MinimalDecoderLayer(nn.Module):
    def __init__(self, d_model=256):
        super().__init__()
        self.d_model = d_model
        self.linear = nn.Linear(d_model, d_model)
    
    def forward(self, tgt, query_pos, reference_points_input, src, src_spatial_shapes, src_level_start_index, src_padding_mask=None):
        # Must return (output, sampling_locations, attn_weights)
        batch_size = tgt.shape[0]
        num_queries = tgt.shape[1]
        num_levels = src_spatial_shapes.shape[0]
        
        output = self.linear(tgt)
        
        # sampling_locations: [batch, num_queries, num_heads, num_levels, 2]
        sampling_locations = torch.randn(batch_size, num_queries, 1, num_levels, 2)
        
        # attn_weights: [batch, num_queries, num_heads, num_levels]
        attn_weights = torch.randn(batch_size, num_queries, 1, num_levels)
        
        return output, sampling_locations, attn_weights

# Create minimal decoder_layer
decoder_layer = MinimalDecoderLayer(d_model=256)

# Construct ARGS
ARGS = {
    'decoder_layer': decoder_layer,
    'num_layers': 6,
    'return_intermediate': True,
}
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 DeformableTransformerDecoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DeformableTransformerDecoder 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
DeformableTransformerEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("648c97fae3ca9e11")
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 an instance of its own class, DeformableTransformerEncoder: the run constructed the object and did not call it, so no result was computed. 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
import copy

torch.manual_seed(0)

# Create a minimal encoder layer that satisfies the usage in forward()
class MinimalEncoderLayer(nn.Module):
    def __init__(self, d_model=4):
        super().__init__()
        self.d_model = d_model
        self.linear = nn.Linear(d_model, d_model)
    
    def forward(self, output, pos, reference_points, spatial_shapes, level_start_index, 
                padding_mask, tgt=None):
        # The forward method needs to return (tgt, sampling_locations, attn_weights)
        batch_size = output.size(0)
        seq_len = output.size(1)
        num_levels = len(spatial_shapes)
        num_points = 4  # deformable attention typically uses 4 points
        
        # Process output through layer
        if tgt is not None:
            result = self.linear(tgt)
        else:
            result = self.linear(output)
        
        # Create dummy sampling_locations and attn_weights
        sampling_locations = torch.randn(batch_size, seq_len, num_levels, num_points, 2)
        attn_weights = torch.randn(batch_size, seq_len, num_levels, num_points)
        
        return result, sampling_locations, attn_weights

# Build encoder_layer
encoder_layer = MinimalEncoderLayer(d_model=4)

# Build arguments for DeformableTransformerEncoder.__init__
num_layers = 2

# For forward() call, we need to construct:
batch_size = 2
seq_len = 5
d_model = 4
num_levels = 3

# src tensor
src = torch.randn(batch_size, seq_len, d_model)

# spatial_shapes: list of (H, W) tuples for each level
spatial_shapes = [(8, 6), (4, 3), (2, 2)]

# level_start_index: cumulative index where each level starts
level_start_index = torch.tensor([0, 48, 60], dtype=torch.long)  # 8*6=48, 4*3=12, 2*2=4

# valid_ratios: shape (batch_size, num_levels, 2) for width and height ratios
valid_ratios = torch.ones(batch_size, num_levels, 2)

# pos: positional encoding, same shape as src
pos = torch.randn(batch_size, seq_len, d_model)

# padding_mask: optional mask
padding_mask = None

# topk_inds: optional sparse indices, shape (batch_size, topk)
topk_inds = None

# output_proposals: optional proposals (only used when aux_heads=True)
output_proposals = None

# sparse_token_nums: optional sparse token counts
sparse_token_nums = None

ARGS = {
    'encoder_layer': encoder_layer,
    'num_layers': num_layers,
    'mask_predictor_dim': 256,
}
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 DeformableTransformerEncoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a DeformableTransformerEncoder 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
MaskPredictor Ran
ran on a synthesized input · constructed an object; no result was computed
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("c181c1b23d599313")
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 an instance of its own class, MaskPredictor: the run constructed the object and did not call it, so no result was computed. 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
from torch import nn

torch.manual_seed(0)

# Create a MaskPredictor instance to understand parameter requirements
# __init__ takes: in_dim, h_dim

# Based on the forward method:
# - x is split along last dimension into h_dim // 2 parts
# - So input dimension should be compatible with h_dim
# - The layer1 output is h_dim, then split into h_dim // 2 pieces

in_dim = 8
h_dim = 16

ARGS = {
    "in_dim": in_dim,
    "h_dim": h_dim,
}
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 MaskPredictor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MaskPredictor 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
DeformableTransformer Not yet run
unverified (harvested, no recorded run)
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("87ecfe0a8fbc1ea2")
How it ran

no invocation recorded.

DeformableTransformerDecoderLayer Not yet run
unverified (harvested, no recorded run)
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("575115b86e118f85")
How it ran

no invocation recorded.

DeformableTransformerEncoderLayer Not yet run
unverified (harvested, no recorded run)
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("f8bfa71e9ead60c0")
How it ran

no invocation recorded.

MSDeformAttn Not yet run
unverified (harvested, no recorded run)
kakaobrain/sparse-detr/models/deformable_transformer.py
code served (permissive licence) · get_code("196198adff3ea1cd")
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-23.

Repositories linked to this paper

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

Abstract

DETR is the first end-to-end object detector using a transformer encoder-decoder architecture and demonstrates competitive performance but low computational efficiency on high resolution feature maps. The subsequent work, Deformable DETR, enhances the efficiency of DETR by replacing dense attention with deformable attention, which achieves 10× faster convergence and improved performance. Deformable DETR uses the multiscale feature to ameliorate performance, however, the number of encoder tokens increases by 20× compared to DETR, and the computation cost of the encoder attention remains a bottleneck. In our preliminary experiment, we observe that the detection performance hardly deteriorates even if only a part of the encoder token is updated. Inspired by this observation, we propose Sparse DETR that selectively updates only the tokens expected to be referenced by the decoder, thus help the model effectively detect objects. In addition, we show that applying an auxiliary detection loss on the selected tokens in the encoder improves the performance while minimizing computational overhead. We validate that Sparse DETR achieves better performance than Deformable DETR even with only 10% encoder tokens on the COCO dataset. Albeit only the encoder tokens are sparsified, the total computation cost decreases by 38% and the frames per second (FPS) increases by 42% compared to Deformable DETR. Code is available at https://github.com/kakaobrain/sparse-detr.

For agents

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

get_harvested_code_for_paper("2111.14330")
get_code_for_paper("2111.14330")
have("2111.14330")

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

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

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

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

Connect an agent — have() is free.