SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2604.07394 · 2026

Flux Attention: Context-Aware Hybrid Attention for Efficient LLMs Inference

Yi Yang, Juntao Li, Min Zhang, Zhiyi Hong, Kebin Liu, Quantong Qiu, Qingqing Dang, Haitian Wang, Router Head

arXiv · PDF · Open in the Atlas

Code that ran

7 of 9 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; 2 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 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/2604.07394.json · badge: /api/ran/2604.07394.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
qqtang-code/FluxAttention canonical (classifier label)
classifier basis: census
7 ran · 2 no recorded run
FunctionStatusWhere it lives
create_causal_mask Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
qqtang-code/FluxAttention/fluxattn/src/Xattention.py
code served (permissive licence) · get_code("c9d0d9d7eb54483a")
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 4, dtype family float, shape (2, 3, 4, 20) as a later run recorded it. 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, 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)

ARGS = {
    "batch_size": 2,
    "head_num": 3,
    "block_size": 4,
    "block_num": 5,
    "divide_block_num": 2,
}
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 4, dtype family float, shape (2, 3, 4, 20) — shape (2, 3, 4, 20) 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
generate_streaming_info_blocksparse_flash_attn Ran
ran, honoured the contract we drafted
qqtang-code/FluxAttention/fluxattn/training/modeling_flash_llama.py
code served (permissive licence) · get_code("13f436e0309e6fd0")
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 1, dtype family int, shape (8,) 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)

ARGS = {
    "sink_block_num": 2,
    "local_block_num": 3,
    "n_query_heads": 4,
    "device": "cpu"
}
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 1, dtype family int, shape (8,) — shape (8,) 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
min_lr_bound Ran
ran, honoured the contract we drafted
qqtang-code/FluxAttention/fluxattn/training/lh_trainer.py
code served (permissive licence) · get_code("2718b0555714208e")
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 float, ndim 0, dtype family float, 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 torch.nn as nn

torch.manual_seed(0)

# Define a simple wrapped function that takes a float and returns a float
def dummy_lr_func(step: float) -> float:
    """Simple learning rate schedule function"""
    return 0.1 * (0.95 ** (step / 1000.0))

# Set up arguments for min_lr_bound
ARGS = {
    "current_step": 5,
    "wrapped_func": dummy_lr_func,
    "min_lr_ratio": 0.01,
    "warmup_steps": 10
}
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 float, ndim 0, dtype family float, 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
repeat_kv Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
qqtang-code/FluxAttention/fluxattn/training/eval/modeling_flash_llama.py
code served (permissive licence) · get_code("56fbb035393380b6")
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 4, 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.

import torch

torch.manual_seed(0)

# The function repeat_kv takes:
# 1. hidden_states: torch.Tensor - a tensor that gets unsqueezed, expanded, and reshaped
# 2. n_rep: int - a repetition factor

# Looking at the function body:
# - hidden_states is accessed with .shape[-2], .shape[-1], and len(hidden_states.shape)
# - It supports unsqueeze(-2), expand(), and reshape()
# - The shape should have at least 3 dimensions based on the slicing [:-2]

# Create a small 4D tensor: (batch=2, seq=3, heads=4, dim=5)
hidden_states = torch.randn(2, 3, 4, 5)

# n_rep is just an integer
n_rep = 2

ARGS = {
    "hidden_states": hidden_states,
    "n_rep": n_rep,
}
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 4, dtype family float — no output shape is stated: observe_signature.py could not observe it (import:OSError)
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
rmsnorm_func Ran
ran; our contract draft was wrong, not the code
qqtang-code/FluxAttention/fluxattn/training/eval/modeling_flash_llama.py
code served (permissive licence) · get_code("349dce8e37362617")
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 2, dtype family float, shape (2, 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)

# Analyze the function:
# - hidden_states: tensor that is converted to float32, has .pow(), .mean(), operations, and final .to(input_dtype)
# - weight: tensor that is multiplied with hidden_states
# - variance_epsilon: scalar added to variance

# hidden_states shape: (batch, ..., dim) where mean(-1) is taken, so last dim is important
# weight shape: must broadcast with hidden_states after normalization

# Create tiny tensors
batch_size = 2
hidden_dim = 4

hidden_states = torch.randn(batch_size, hidden_dim, dtype=torch.float32)
weight = torch.ones(hidden_dim, dtype=torch.float32)
variance_epsilon = 1e-6

ARGS = {
    "hidden_states": hidden_states,
    "weight": weight,
    "variance_epsilon": variance_epsilon,
}
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 2, dtype family float, shape (2, 4) — shape (2, 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
rotate_half Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
qqtang-code/FluxAttention/fluxattn/training/modeling_flash_qwen.py
code served (permissive licence) · get_code("ce8a56552eacab99")
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 2, dtype family float, shape (2, 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 numpy as np
from einops import rearrange, repeat

torch.manual_seed(0)

# Construct tensor arguments
# The function takes x (a tensor) and interleaved (a boolean)
# x should have shape that can be chunked or indexed along last dimension
# Let's create a tensor with shape (2, 4) - batch size 2, feature dim 4
x_tensor = torch.randn(2, 4)

ARGS = {
    "x": x_tensor,
    "interleaved": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 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
worker_pack_chunk Ran
ran; our contract draft was wrong, not the code
qqtang-code/FluxAttention/fluxattn/training/dataset_packing.py
code served (permissive licence) · get_code("4476c5672f1aafdf")
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 1, 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.

import torch
import torch.nn as nn
import numpy as np
from unittest.mock import Mock

# Create a mock tokenizer that behaves like a HuggingFace tokenizer
class MockTokenizer:
    def __init__(self):
        self.eos_token_id = 2
        self.pad_token_id = 0
    
    def __call__(self, text, add_special_tokens=False):
        # Simple mock: return a reasonable number of token IDs based on text length
        token_count = max(1, len(text.split()) + 5)
        return {'input_ids': list(range(token_count))}
    
    def apply_chat_template(self, messages, tokenize=False, enable_thinking=False):
        # Concatenate message contents with role labels
        result = ""
        for msg in messages:
            role = msg['role']
            content = msg['content']
            result += f"[{role}]: {content}\n"
        return result

# Create mock dataset with diverse items
chunk_dataset = [
    {
        'context': 'The Earth orbits the Sun.',
        'question': 'What does the Earth orbit?',
        'answer': 'The Earth orbits the Sun.',
        'metadata': {'task': 'Single QA', 'is_prefix': True}
    },
    {
        'context': 'Paris is the capital of France. France is in Europe.',
        'question': 'What continent is France in?',
        'answer': 'Europe',
        'metadata': {'task': 'MultiHop QA', 'is_prefix': True}
    },
    {
        'context': 'Breaking News: Stock market reaches all-time high.',
        'question': '',
        'answer': 'The stock market has reached an all-time high today.',
        'metadata': {'task': 'Summarization', 'is_prefix': False}
    },
    {
        'context': 'def hello():\n    print("world")',
        'question': 'Complete this function',
        'answer': 'def hello():\n    print("world")',
        'metadata': {'task': 'Code', 'is_prefix': True}
    },
    {
        'context': 'Example context',
        'question': 'Example question',
        'answer': 'Example answer',
        'metadata': {'task': 'In-Context Learning', 'is_prefix': True}
    },
]

tokenizer = MockTokenizer()
max_seq_len = 512
min_seq_len = 10
worker_id = 0
is_sft = True

ARGS = {
    'chunk_dataset': chunk_dataset,
    'tokenizer': tokenizer,
    'max_seq_len': max_seq_len,
    'min_seq_len': min_seq_len,
    'worker_id': worker_id,
    'is_sft': is_sft
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — 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
apply_rotary_emb_torch Not yet run
unverified (harvested, no recorded run)
qqtang-code/FluxAttention/fluxattn/training/modeling_flash_qwen.py
code served (permissive licence) · get_code("2ed34e7143f94ce9")
How it ran

no invocation recorded.

find_blocks_chunked Not yet run
unverified (harvested, no recorded run)
qqtang-code/FluxAttention/fluxattn/src/Xattention.py
code served (permissive licence) · get_code("7b8a227c2f32a62d")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 9 are also present in other papers whose code we hold (9 with at least one paper dated earlier, 2 the same month, 2 later) and 0 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
rmsnorm_func 8 other papers
7 dated earlier, 1 undated
2310.03668 (2023-10)
GoLLIE: Annotation Guidelines improve Zero-Shot Information-Extraction
2312.15166 (2023-12)
SOLAR 10.7B: Scaling Large Language Models with Simple yet Effective Depth Up-Scaling
2402.09739 (2024-02)
QuRating: Selecting High-Quality Data for Training Language Models
and 5 more not named here
apply_rotary_emb_torch 6 other papers
4 dated earlier, 1 the same month, 1 later
2309.06180 (2023-09)
Efficient Memory Management for Large Language Model Serving with PagedAttention
2407.08608 (2024-07)
FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
2412.06464 (2024-12)
Gated Delta Networks: Improving Mamba2 with Delta Rule
and 3 more not named here
rotate_half 6 other papers
4 dated earlier, 1 the same month, 1 later
2309.06180 (2023-09)
Efficient Memory Management for Large Language Model Serving with PagedAttention
2407.08608 (2024-07)
FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision
2412.06464 (2024-12)
Gated Delta Networks: Improving Mamba2 with Delta Rule
and 3 more not named here
repeat_kv 4 other papers
4 dated earlier
2402.09739 (2024-02)
QuRating: Selecting High-Quality Data for Training Language Models
2410.02660 (2024-10)
How to Train Long-Context Language Models (Effectively)
2025.acl-long.366 (2025 (year only))
How to Train Long-Context Language Models (Effectively)
and 1 more not named here
min_lr_bound 3 other papers
3 dated earlier
2410.02660 (2024-10)
How to Train Long-Context Language Models (Effectively)
2025.acl-long.366 (2025 (year only))
How to Train Long-Context Language Models (Effectively)
2602.05258 (2026-02)
CoPE: Clipped RoPE as A Scalable Free Lunch for Long Context LLMs
create_causal_mask 2 other papers
2 dated earlier
2509.24745 (2025-09)
ProxyAttn: Guided Sparse Attention via Representative Heads
2601.17367 (2026-01)
Elastic Attention: Test-time Adaptive Sparsity Ratios for Efficient Transformers
find_blocks_chunked 2 other papers
2 dated earlier
2509.24745 (2025-09)
ProxyAttn: Guided Sparse Attention via Representative Heads
2601.17367 (2026-01)
Elastic Attention: Test-time Adaptive Sparsity Ratios for Efficient Transformers
generate_streaming_info_blocksparse_flash_attn 1 other paper
1 dated earlier
2601.17367 (2026-01)
Elastic Attention: Test-time Adaptive Sparsity Ratios for Efficient Transformers
worker_pack_chunk 1 other paper
1 dated earlier
2601.17367 (2026-01)
Elastic Attention: Test-time Adaptive Sparsity Ratios for Efficient Transformers

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 computational complexity of standard attention mechanisms presents a severe scalability bottleneck for LLMs in long-context scenarios. While hybrid attention mechanisms combining Full Attention (FA) and Sparse Attention (SA) offer a potential solution, existing methods typically rely on static allocation ratios that fail to accommodate the variable retrieval demands of different tasks. Furthermore, head-level dynamic sparsity often introduces severe computational load imbalance and synchronization long-tails, which hinder hardware acceleration during autoregressive decoding. To bridge this gap, we introduce Flux Attention, a context-aware framework that dynamically optimizes attention computation at the layer level. By integrating a lightweight Layer Router into frozen pretrained LLMs, the proposed method adaptively routes each layer to FA or SA based on the input context. This layer-wise routing preserves high-fidelity information retrieval while ensuring contiguous memory access, translating theoretical computational reductions into practical wall-clock speedups. As a parameter-efficient approach, our framework requires only 12 hours of training on 8×A800 GPUs. Extensive experiments across multiple long-context and mathematical reasoning benchmarks demonstrate that Flux Attention achieves a superior trade-off between performance and inference speed compared with baseline models, with speed improvements of up to 2.8× and 2.0× in the prefill and decode stages.

For agents

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

get_harvested_code_for_paper("2604.07394")
get_code_for_paper("2604.07394")
have("2604.07394")

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

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

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

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

Connect an agent — have() is free.