SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.02490 · NeurIPS · 2024

MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention

Xufang Luo, Dongsheng Li, Amir Abdi, Yuqing Yang, Huiqiang Jiang, Yucheng Li, Chengruidong Zhang, Qianhui Wu, Surin Ahn, Zhenhua Han, Chin-Yew Lin, Lili Qiu

arXiv · PDF · Open in the Atlas

Code that ran

10 of 12 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, 3 violated it and 1 has no contract verdict; 5 failures 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/2407.02490.json · badge: /api/ran/2407.02490.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
microsoft/LLMLingua canonical (classifier label)
classifier basis: census
8 ran · 2 no recorded run
microsoft/MInference canonical (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
FunctionStatusWhere it lives
filter_by_metric Ran
ran; our contract draft was wrong, not the code
microsoft/LLMLingua/experiments/securitylingua/filter.py
code served (permissive licence) · get_code("c03b7f062823101c")
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 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.

from collections import defaultdict
import numpy as np

# Set seed for reproducibility
np.random.seed(0)

# Create sample data with all required metrics
data = defaultdict(list)

# Generate 10 data points with all metrics
num_samples = 10
metrics = ['labels', 'origin', 'comp', 'retrieval', 'comp_rate', 'variation_rate', 'hitting_rate', 'matching_rate', 'alignment_gap']

for i in range(num_samples):
    data['labels'].append(i % 2)  # Binary labels
    data['origin'].append(np.random.rand())  # Random float between 0 and 1
    data['comp'].append(np.random.rand())
    data['retrieval'].append(np.random.rand())
    data['comp_rate'].append(np.random.rand())
    data['variation_rate'].append(np.random.rand())
    data['hitting_rate'].append(np.random.rand())
    data['matching_rate'].append(np.random.rand())
    data['alignment_gap'].append(np.random.rand())

ARGS = {
    'data': data,
    'metric_name': 'comp_rate',
    'percentile': 50.0
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, 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
get_pure_token Ran
ran on a synthesized input
microsoft/LLMLingua/llmlingua/utils.py
code served (permissive licence) · get_code("c60f40b9d6ed164e")
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 str. 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

# The function only uses string operations on token and checks substrings in model_name
# No complex objects needed

# Test with a BERT-based model
token_1 = "##hello"
model_name_1 = "bert-base-multilingual-cased"

ARGS = {
    "token": token_1,
    "model_name": model_name_1
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
is_begin_of_new_word Ran
ran, violated the contract we drafted
microsoft/LLMLingua/llmlingua/utils.py
code served (permissive licence) · get_code("82091eb9827b6af7")
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 bool, 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 string

# Define test arguments for is_begin_of_new_word function

token_1 = "hello"
token_2 = "##world"
token_3 = "▁token"

model_name_bert = "bert-base-multilingual-cased"
model_name_xlm = "xlm-roberta-large"

force_tokens_set = {"hello", "world", "test"}

token_map_dict = {
    "key1": "value1",
    "key2": "value2",
    "key3": "##suffix"
}

ARGS = {
    "token": token_1,
    "model_name": model_name_bert,
    "force_tokens": force_tokens_set,
    "token_map": token_map_dict
}
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 bool, 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
is_equal Ran
ran, violated the contract we drafted
microsoft/LLMLingua/experiments/llmlingua2/data_collection/label_word.py
code served (permissive licence) · get_code("7da9282cb2dcf1ab")
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 bool, 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

torch.manual_seed(0)

ARGS = {
    "token1": "Hello",
    "token2": "HELLO"
}
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 bool, 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
is_equal Ran
ran, violated the contract we drafted
microsoft/LLMLingua/experiments/securitylingua/label_word.py
code served (permissive licence) · get_code("5c2c5ab6b6d57f48")
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 bool, 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 numpy as np

torch.manual_seed(0)

ARGS = {
    "token1": "HELLO",
    "token2": "hello",
}
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 bool, 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
load_and_split_data Ran
ran; our contract draft was wrong, not the code
microsoft/LLMLingua/experiments/securitylingua/train_roberta.py
code served (permissive licence) · get_code("10fb3b88a9539710")
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. 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 random
from pathlib import Path
import tempfile

torch.manual_seed(0)

# Create a temporary directory and a mock data file
temp_dir = tempfile.mkdtemp()
data_path = Path(temp_dir) / "mock_data.pt"

# Create mock data with 'origin' and 'labels' keys
mock_data = {
    'origin': ['This is a sample text.', 'Another sample text here.', 'Yet another sample.', 'Fourth sample text.', 'Fifth sample text.', 'Sixth sample text.', 'Seventh sample text.', 'Eighth sample text.', 'Ninth sample text.', 'Tenth sample text.'],
    'labels': [[0, 1], [1, 0], [0, 1], [1, 1], [0, 0], [1, 0], [0, 1], [1, 0], [0, 1], [1, 1]]
}

torch.save(mock_data, data_path)

ARGS = {
    'data_path': str(data_path),
    'seed': 42
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
accelerate, 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
replace_added_token Ran
ran; our contract draft was wrong, not the code
microsoft/LLMLingua/llmlingua/utils.py
code served (permissive licence) · get_code("c22578e87f0bdd2c")
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 str. 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

# The function takes a token (string) and token_map (dict)
# It iterates through token_map items and replaces new_token with ori_token in the token string
# token_map keys are ori_token (original), values are new_token (replacement)

# Simple test case
token = "hello world new_token1 new_token2"
token_map = {
    "original1": "new_token1",
    "original2": "new_token2"
}

ARGS = {
    "token": token,
    "token_map": token_map
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
setup_logging Ran
ran; our contract draft was wrong, not the code
microsoft/LLMLingua/experiments/securitylingua/label_word.py
code served (permissive licence) · get_code("4e369dc3b4632635")
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 RootLogger. 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 logging
import os
import tempfile

# Create a temporary directory for logging
temp_dir = tempfile.mkdtemp()
save_path = os.path.join(temp_dir, "logs", "model.log")

ARGS = {
    "save_path": save_path
}
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 RootLogger — a RootLogger output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a RootLogger 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
truncate_by_tokens Ran
ran, honoured the contract we drafted
microsoft/MInference/experiments/infinite_bench/run_infinitebench.py
code served (permissive licence) · get_code("c1c592b93449e76c")
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 1, 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

class SimpleTokenizer:
    def encode(self, text):
        # Simple tokenizer that splits on spaces and returns token list
        # Each word becomes a token ID (we'll use indices)
        words = text.split()
        return list(range(len(words)))

# Create a simple tokenizer instance
tok = SimpleTokenizer()

# Define arguments for truncate_by_tokens
ARGS = {
    'input': 'the quick brown fox jumps over the lazy dog and runs through the forest',
    'tok': tok,
    'max_tokens': 10,
    'manner': 'middle'
}
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 1, 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
truncate_input Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/MInference/experiments/infinite_bench/run_infinitebench.py
code served (permissive licence) · get_code("db3017985563c2a7")
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 1, 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)

# The function takes:
# - input: list (used with len(), slicing with [0:split] and [-split:], and concatenation with +)
# - max_length: int (used in comparisons and arithmetic)
# - manner: str (used in equality check with 'middle')

# Create a simple list input
input_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Set max_length to trigger the middle truncation logic
max_length_val = 4

# Set manner to 'middle' to exercise that branch
manner_val = 'middle'

ARGS = {
    'input': input_list,
    'max_length': max_length_val,
    'manner': manner_val
}
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 1, 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
setup_wandb Not yet run
unverified (harvested, no recorded run)
microsoft/LLMLingua/experiments/securitylingua/train_roberta.py
code served (permissive licence) · get_code("bdd16b22daad11a5")
How it ran

no invocation recorded.

split_string Not yet run
unverified (harvested, no recorded run)
microsoft/LLMLingua/experiments/securitylingua/label_word.py
code served (permissive licence) · get_code("469e5cfe9fc2ef17")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 11 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
is_equal 1 other paper
1 later
2408.04259 (2024-08)
EfficientRAG: Efficient Retriever for Multi-Hop Question Answering

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

The computational challenges of Large Language Model (LLM) inference remain a significant barrier to their widespread deployment, especially as prompt lengths continue to increase. Due to the quadratic complexity of the attention computation, it takes 30 minutes for an 8B LLM to process a prompt of 1M tokens (i.e., the pre-filling stage) on a single A100 GPU. Existing methods for speeding up prefilling often fail to maintain acceptable accuracy or efficiency when applied to long-context LLMs. To address this gap, we introduce MInference (Milliontokens Inference), a sparse calculation method designed to accelerate pre-filling of long-sequence processing. Specifically, we identify three unique patterns in long-context attention matrices-the A-shape, Vertical-Slash, and Block-Sparsethat can be leveraged for efficient sparse computation on GPUs. We determine the optimal pattern for each attention head offline and dynamically build sparse indices based on the assigned pattern during inference. With the pattern and sparse indices, we perform efficient sparse attention calculations via our optimized GPU kernels to significantly reduce the latency in the pre-filling stage of longcontext LLMs. Our proposed technique can be directly applied to existing LLMs without any modifications to the pre-training setup or additional fine-tuning. By evaluating on a wide range of downstream tasks, including InfiniteBench, RULER, PG-19, and Needle In A Haystack, and models including LLaMA-3-1M, GLM-4-1M, Yi-200K, Phi-3-128K, and Qwen2-128K, we demonstrate that MInference effectively reduces inference latency by up to 10× for pre-filling on an A100, while maintaining accuracy. Our code is available at https://aka.ms/MInference.

For agents

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

get_harvested_code_for_paper("2407.02490")
get_code_for_paper("2407.02490")
have("2407.02490")

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

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

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

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

Connect an agent — have() is free.