SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2511.05832 · ICLR · 2025

Hilbert-Guided Sparse Local Attention

Yunge Li, Lanyu Xu

arXiv · PDF · Open in the Atlas

Code that ran

8 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 4 failures of our instrument; 2 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/2511.05832.json · badge: /api/ran/2511.05832.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
Yunge6666/Hilbert-Local-Attention community
Papers with Code archive
8 ran · 2 no recorded run
FunctionStatusWhere it lives
GilbertPathCache Ran
ran on a synthesized input · constructed an object; no result was computed
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("0cd8d046c5019b75")
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, GilbertPathCache: 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

torch.manual_seed(0)

class GilbertPathCache:

    def __init__(self):
        self.cache = {}

    def get_or_create_path(self, H, W):
        key = (H, W)
        if key not in self.cache:
            path = gilbert2d(W, H)
            forward_map = torch.zeros((H, W), dtype=torch.long)
            reverse_map = torch.zeros((H * W, 2), dtype=torch.long)
            for idx, (x, y) in enumerate(path[:H * W]):
                if y < H and x < W:
                    forward_map[y, x] = idx
                    reverse_map[idx, 0] = y
                    reverse_map[idx, 1] = x
            self.cache[key] = {'path': path, 'forward_map': forward_map, 'reverse_map': reverse_map, 'H': H, 'W': W}
        return self.cache[key]

    def precompute_paths(self, resolutions):
        for H, W in resolutions:
            self.get_or_create_path(H, W)

    def clear_cache(self):
        self.cache.clear()


def sgn(x):
    return -1 if x < 0 else 1 if x > 0 else 0


def generate2d(x: int, y: int, ax: int, ay: int, bx: int, by: int, result):
    w = abs(ax + ay)
    h = abs(bx + by)
    dax, day = (sgn(ax), sgn(ay))
    dbx, dby = (sgn(bx), sgn(by))
    if h == 1 or w == 1:
        if h == 1:
            for _ in range(w):
                result.append((x, y))
                x, y = (x + dax, y + day)
        elif w == 1:
            for _ in range(h):
                result.append((x, y))
                x, y = (x + dbx, y + dby)
        return
    ax2, ay2 = (ax // 2, ay // 2)
    bx2, by2 = (bx // 2, by // 2)
    w2 = abs(ax2 + ay2)
    h2 = abs(bx2 + by2)
    if 2 * w > 3 * h:
        if w2 % 2 and w > 2:
            ax2, ay2 = (ax2 + dax, ay2 + day)
        generate2d(x, y, ax2, ay2, bx, by, result)
        generate2d(x + ax2, y + ay2, ax - ax2, ay - ay2, bx, by, result)
    else:
        if h2 % 2 and h > 2:
            bx2, by2 = (bx2 + dbx, by2 + dby)
        generate2d(x, y, bx2, by2, ax2, ay2, result)
        generate2d(x + bx2, y + by2, ax, ay, bx - bx2, by - by2, result)
        generate2d(x + (ax - dax) + (bx2 - dbx), y + (ay - day) + (by2 - dby), -bx2, -by2, -(ax - ax2), -(ay - ay2), result)


def gilbert2d(width, height):
    result = []
    if width >= height:
        generate2d(0, 0, width, 0, 0, height, result)
    else:
        generate2d(0, 0, 0, height, width, 0, result)
    return result


ARGS = {}
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 GilbertPathCache — 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 GilbertPathCache 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
WindowAttention Ran
ran on a synthesized input · constructed an object; no result was computed
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("2132f2ba5f5ca484")
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, WindowAttention: 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

torch.manual_seed(0)

# WindowAttention parameters
dim = 4
window_size = (2, 2)
num_heads = 2
input_resolution = (4, 3)
qkv_bias = True
qk_scale = None
attn_drop = 0.1
proj_drop = 0.1
shift_size = 0

ARGS = {
    "dim": dim,
    "window_size": window_size,
    "num_heads": num_heads,
    "input_resolution": input_resolution,
    "qkv_bias": qkv_bias,
    "qk_scale": qk_scale,
    "attn_drop": attn_drop,
    "proj_drop": proj_drop,
    "shift_size": shift_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type WindowAttention — 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 WindowAttention 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
gilbert2d Ran
ran, honoured the contract we drafted
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("970fcca41b5bcf82")
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 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.

def sgn(x):
    return -1 if x < 0 else 1 if x > 0 else 0

def generate2d(x: int, y: int, ax: int, ay: int, bx: int, by: int, result):
    w = abs(ax + ay)
    h = abs(bx + by)
    dax, day = (sgn(ax), sgn(ay))
    dbx, dby = (sgn(bx), sgn(by))
    if h == 1 or w == 1:
        if h == 1:
            for _ in range(w):
                result.append((x, y))
                x, y = (x + dax, y + day)
        elif w == 1:
            for _ in range(h):
                result.append((x, y))
                x, y = (x + dbx, y + dby)
        return
    ax2, ay2 = (ax // 2, ay // 2)
    bx2, by2 = (bx // 2, by // 2)
    w2 = abs(ax2 + ay2)
    h2 = abs(bx2 + by2)
    if 2 * w > 3 * h:
        if w2 % 2 and w > 2:
            ax2, ay2 = (ax2 + dax, ay2 + day)
        generate2d(x, y, ax2, ay2, bx, by, result)
        generate2d(x + ax2, y + ay2, ax - ax2, ay - ay2, bx, by, result)
    else:
        if h2 % 2 and h > 2:
            bx2, by2 = (bx2 + dbx, by2 + dby)
        generate2d(x, y, bx2, by2, ax2, ay2, result)
        generate2d(x + bx2, y + by2, ax, ay, bx - bx2, by - by2, result)
        generate2d(x + (ax - dax) + (bx2 - dbx), y + (ay - day) + (by2 - dby), -bx2, -by2, -(ax - ax2), -(ay - ay2), result)

def gilbert2d(width, height):
    result = []
    if width >= height:
        generate2d(0, 0, width, 0, 0, height, result)
    else:
        generate2d(0, 0, 0, height, width, 0, result)
    return result

ARGS = {
    "width": 8,
    "height": 6
}
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 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
gilbert_shift_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("fae6570c89b0b0a7")
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 Tensor, ndim 3, dtype family float, shape (2, 4, 3) 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

torch.manual_seed(0)

# Create a small Gilbert sequence tensor
# Shape: (B, N, C) = (2, 4, 3)
# B=2 (batch size), N=4 (sequence length), C=3 (channels)
x = torch.randn(2, 4, 3)

# Shift size parameter
shift_size = 1

ARGS = {
    "x": x,
    "shift_size": shift_size,
}
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 Tensor, ndim 3, dtype family float, shape (2, 4, 3) — shape (2, 4, 3) 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: none by the harness; any seed is in the setup block
gilbert_shift_reverse Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("8f27c3af24bbc8f9")
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 Tensor, ndim 3, dtype family float, shape (2, 4, 3) 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

torch.manual_seed(0)

# Create a small shifted Gilbert sequence tensor
# Shape: (B=2, N=4, C=3)
x = torch.randn(2, 4, 3)

# Define shift size
shift_size = 1

ARGS = {
    "x": x,
    "shift_size": shift_size,
}
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 Tensor, ndim 3, dtype family float, shape (2, 4, 3) — shape (2, 4, 3) 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: none by the harness; any seed is in the setup block
gilbert_tensor_to_windows Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("41ad57b96f86bf0c")
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 Tensor, ndim 3, dtype family float, shape (2, 16, 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

torch.manual_seed(0)

# Create a small Gilbert sequence tensor
# Shape: (B, N, C) where B=batch, N=sequence length, C=channels
B = 2
N = 16  # Must be divisible by window_size^2
C = 4
x = torch.randn(B, N, C)

# Window size
window_size = 4  # So window_size^2 = 16, which divides N=16 evenly

# Create reverse_map - this parameter is read but not used in the function body
# Based on the function signature, it appears to be metadata about the Gilbert sequence
# We'll create a simple mapping
reverse_map = {i: i for i in range(N)}

# Shift size parameter
shift_size = 0

ARGS = {
    "x": x,
    "window_size": window_size,
    "reverse_map": reverse_map,
    "shift_size": shift_size,
}
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 Tensor, ndim 3, dtype family float, shape (2, 16, 4) — shape (2, 16, 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: none by the harness; any seed is in the setup block
gilbert_windows_to_tensor Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("f8ddeb4e57c75167")
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 Tensor, ndim 3, dtype family float, shape (2, 12, 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

torch.manual_seed(0)

# Parameters for gilbert_windows_to_tensor
B = 2  # batch size
H = 4  # original height
W = 3  # original width
num_windows = 6  # number of windows
window_size_sq = 9  # window_size * window_size (3x3 window)
C = 4  # channel dimension

# Create x_windows with shape (B*num_windows, window_size_sq, C)
# B*num_windows = 2*6 = 12
x_windows = torch.randn(B * num_windows, window_size_sq, C)

ARGS = {
    "x_windows": x_windows,
    "B": B,
    "H": H,
    "W": W,
}
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 Tensor, ndim 3, dtype family float, shape (2, 12, 4) — shape (2, 12, 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: none by the harness; any seed is in the setup block
sgn Ran
ran, honoured the contract we drafted
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("441e92cd07dd8324")
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 int, ndim 0, dtype family int, shape () 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 numpy as np

torch.manual_seed(0)

ARGS = {
    "x": 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () 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: none by the harness; any seed is in the setup block
SwinTransformerBlock Not yet run
unverified (harvested, no recorded run)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("5b0fbf3070f2cc49")
How it ran

no invocation recorded.

generate2d Not yet run
unverified (harvested, no recorded run)
Yunge6666/Hilbert-Local-Attention/hwt.py
code served (permissive licence) · get_code("bd1ee63e84e6b28c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 9 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
sgn
brick of this paper's assembly: helper
2 other papers
2 dated earlier
2407.21773 (2024-07)
RainMamba: Enhanced Locality Learning with State Space Models for Video Deraining
2505.22535 (2025-05)
RiverMamba: A State Space Model for Global River Discharge and Flood Forecasting

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

The quadratic compute and memory costs of global self-attention severely limit its use in high-resolution images. Local attention reduces complexity by restricting attention to neighborhoods. Block-sparse kernels can further improve the efficiency of local attention, but conventional local attention patterns often fail to deliver significant speedups because tokens within a window are not contiguous in the 1D sequence. This work proposes a novel method for constructing windows and neighborhoods based on the Hilbert curve. Image tokens are first reordered along a Hilbert curve, and windows and neighborhoods are then formed on the reordered 1D sequence. From a block-sparse perspective, this strategy significantly increases block sparsity and can be combined with existing block-sparse kernels to improve the efficiency of 2D local attention. Experiments show that the proposed Hilbert Window Attention and Hilbert Slide Attention can accelerate window attention and slide attention by about 4× and 18×, respectively. To assess practicality, the strategy is instantiated as the Hilbert Window Transformer and the Hilbert Neighborhood Transformer, both of which achieve end-to-end speedups with minimal accuracy loss. Overall, combining Hilbert-guided local attention with block-sparse kernels offers a general and practical approach to enhancing the efficiency of 2D local attention for images.

For agents

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

get_harvested_code_for_paper("2511.05832")
get_code_for_paper("2511.05832")
have("2511.05832")

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

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

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

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

Connect an agent — have() is free.