SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2408.08696 · 2024

Turning Trash into Treasure: Accelerating Inference of Large Language Models with Token Recycling

arXiv · PDF · Open in the Atlas

Code that ran

8 of 8 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, 1 violated it and 0 have no contract verdict; 7 failures of our instrument; 0 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/2408.08696.json · badge: /api/ran/2408.08696.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
hemingkx/Spec-Bench canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
luowaterbi/tokenrecycling canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
smpanaro/token-recycling reimplementation (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
FunctionStatusWhere it lives
baseline_forward Ran
ran; our contract draft was wrong, not the code
hemingkx/Spec-Bench/evaluation/inference_baseline.py
code served (permissive licence) · get_code("b354a46df3f907b8")
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 torch.nn as nn

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __call__(self, text):
        # Return a minimal input_ids tensor
        return self
    
    @property
    def input_ids(self):
        return torch.tensor([[1, 2, 3, 4]], dtype=torch.long)

# Create a minimal model that implements generate()
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def generate(self, input_ids, do_sample=False, temperature=0.0, max_new_tokens=1):
        # Return generated output_ids that extend the input
        batch_size = input_ids.shape[0]
        input_len = input_ids.shape[1]
        # Generate max_new_tokens new token ids
        new_tokens = torch.randint(0, 100, (batch_size, max_new_tokens), dtype=torch.long)
        output_ids = torch.cat([input_ids, new_tokens], dim=1)
        return output_ids

# Create a minimal inputs object with input_ids attribute
class MinimalInputs:
    def __init__(self):
        self.input_ids = torch.tensor([[1, 2, 3, 4]], dtype=torch.long)

# Build the arguments
inputs = MinimalInputs()
model = MinimalModel()
tokenizer = MinimalTokenizer()
max_new_tokens = 3
temperature = 0.7
do_sample = True

ARGS = {
    "inputs": inputs,
    "model": model,
    "tokenizer": tokenizer,
    "max_new_tokens": max_new_tokens,
    "temperature": temperature,
    "do_sample": do_sample
}
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
choose_tree_template Ran
ran; our contract draft was wrong, not the code
luowaterbi/tokenrecycling/model/recycling/tree_template_.py
pointer only (licence: NONE) · get_code("11a5f4d33e62670d")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, luowaterbi/tokenrecycling when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

ea_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
hemingkx/Spec-Bench/evaluation/inference_eagle2.py
code served (permissive licence) · get_code("a847b79719e8cea9")
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

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        pass

# Create a minimal model that implements eagenerate method
class MinimalEAModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def eagenerate(self, input_ids, temperature=0.0, max_new_tokens=10, log=False):
        # Mock implementation that returns the expected tuple
        # (input_ids, new_token, step, accept_length_list)
        batch_size = input_ids.shape[0]
        new_token = torch.randint(0, 100, (batch_size, 5))
        step = torch.tensor(5)
        accept_length_list = [1, 2, 1, 2, 1]
        return (input_ids, new_token, step, accept_length_list)

# Create a minimal inputs object with input_ids attribute
class MinimalInputs:
    def __init__(self):
        self.input_ids = torch.randint(0, 100, (1, 8))

# Build the arguments
inputs = MinimalInputs()
model = MinimalEAModel()
tokenizer = MinimalTokenizer()
max_new_tokens = 10
temperature = 0.7

ARGS = {
    'inputs': inputs,
    'model': model,
    'tokenizer': tokenizer,
    'max_new_tokens': max_new_tokens,
    'temperature': temperature,
}
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
lookahead_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
hemingkx/Spec-Bench/evaluation/inference_lookahead.py
code served (permissive licence) · get_code("57aba3c21a2ebe44")
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

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MockTokenizer:
    pass

# Create a minimal model that implements the generate method
class MockModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def generate(self, input_ids, do_sample=False, temperature=0.0, max_new_tokens=10):
        # Return (output_ids, idx, accept_length_list)
        # output_ids should be a tensor with shape matching input but extended
        batch_size = input_ids.shape[0]
        seq_len = input_ids.shape[1]
        
        # Generate output_ids by extending input_ids
        output_ids = torch.cat([
            input_ids,
            torch.randint(0, 100, (batch_size, max_new_tokens))
        ], dim=1)
        
        idx = torch.tensor(5)
        accept_length_list = [1, 2]
        
        return output_ids, idx, accept_length_list

# Create a minimal inputs object with input_ids attribute
class MockInputs:
    def __init__(self, input_ids):
        self.input_ids = input_ids

# Set up arguments
inputs = MockInputs(input_ids=[[10, 20, 30, 40], [50, 60, 70, 80]])
model = MockModel()
tokenizer = MockTokenizer()
max_new_tokens = 5

ARGS = {
    "inputs": inputs,
    "model": model,
    "tokenizer": tokenizer,
    "max_new_tokens": max_new_tokens
}
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
map_breadthfirst Ran
ran; our contract draft was wrong, not the code
smpanaro/token-recycling/src/token_recycling.py
pointer only (licence: NONE) · get_code("54c658b820659f2c")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, smpanaro/token-recycling when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

map_depthfirst Ran
ran; our contract draft was wrong, not the code
smpanaro/token-recycling/src/token_recycling.py
pointer only (licence: NONE) · get_code("374944ca8ccfdcbc")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, smpanaro/token-recycling when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

pld_forward Ran
ran; our contract draft was wrong, not the code
hemingkx/Spec-Bench/evaluation/inference_pld.py
code served (permissive licence) · get_code("ccf07672a5bb126f")
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 torch.nn as nn
from transformers import StoppingCriteriaList, MaxLengthCriteria

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        self.pad_token_id = 0
        self.eos_token_id = 2

# Create a minimal model that implements greedy_search_pld
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def greedy_search_pld(self, input_ids, attention_mask=None, stopping_criteria=None, 
                          draft_matching_window_size=None, draft_num_candidate_tokens=None, 
                          use_cache=None, pad_token_id=None, eos_token_id=None, 
                          return_dict_in_generate=None):
        # Return dummy outputs: (output_ids, idx, accept_length_list)
        # output_ids should be a tensor with shape [batch_size, sequence_length]
        batch_size = input_ids.shape[0]
        input_len = input_ids.shape[1]
        max_new_tokens = 5
        
        # Create output with some new tokens, including an EOS token for one sequence
        output_ids = torch.cat([
            input_ids,
            torch.randint(3, 100, (batch_size, max_new_tokens))
        ], dim=1)
        
        # Add EOS token to first sequence to test the EOS handling logic
        output_ids[0, input_len + 2] = eos_token_id
        
        idx = torch.tensor(1)
        accept_length_list = [1, 2, 1, 3, 2]
        
        return output_ids, idx, accept_length_list

# Create a minimal inputs object
class MinimalInputs:
    def __init__(self, input_ids, attention_mask):
        self.input_ids = input_ids
        self.attention_mask = attention_mask

# Construct arguments
batch_size = 2
seq_len = 6
max_new_tokens = 5

input_ids = torch.randint(3, 100, (batch_size, seq_len))
attention_mask = torch.ones((batch_size, seq_len))

inputs = MinimalInputs(input_ids, attention_mask)
model = MinimalModel()
tokenizer = MinimalTokenizer()

ARGS = {
    "inputs": inputs,
    "model": model,
    "tokenizer": tokenizer,
    "max_new_tokens": max_new_tokens
}
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
txt_compare Ran
ran, violated the contract we drafted
hemingkx/Spec-Bench/evaluation/equal.py
code served (permissive licence) · get_code("3e8e4782434ee868")
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 tempfile
import os

# Create two temporary text files for comparison
temp_dir = tempfile.mkdtemp()

# Create first file with some content
file_path1 = os.path.join(temp_dir, "file1.txt")
with open(file_path1, 'w', encoding='utf-8') as f:
    f.write("Hello world\n")
    f.write("Line two\n")
    f.write("Line three\n")

# Create second file with identical content
file_path2 = os.path.join(temp_dir, "file2.txt")
with open(file_path2, 'w', encoding='utf-8') as f:
    f.write("Hello world\n")
    f.write("Line two\n")
    f.write("Line three\n")

ARGS = {
    "file_path1": file_path1,
    "file_path2": file_path2,
}
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

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 6 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
lookahead_forward 1 other paper
1 dated earlier
2406.16758 (2024-06)
Towards Fast Multilingual LLM Inference: Speculative Decoding and Specialized Drafters
pld_forward 1 other paper
1 dated earlier
2406.16758 (2024-06)
Towards Fast Multilingual LLM Inference: Speculative Decoding and Specialized Drafters

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

Massive parameters of LLMs have made inference latency a fundamental bottleneck. Speculative decoding represents a lossless approach to accelerate inference through a guess-and-verify paradigm. Some methods rely on additional architectures to guess draft tokens, which need extra training before use. Alternatively, retrieval-based training-free techniques build libraries from pre-existing corpora or by n-gram generation. However, they face challenges like large storage requirements, time-consuming retrieval, and limited adaptability. Observing that candidate tokens generated during the decoding process are likely to reoccur in future sequences, we propose Token Recycling. It stores candidate tokens in an adjacency matrix and employs a breadth-first-search (BFS)-like algorithm to construct a draft tree, which is then validated through tree attention. New candidate tokens from the decoding process are then used to update the matrix. Token Recycling requires \textless2MB of additional storage and achieves approximately 2x speedup across all sizes of LLMs. It significantly outperforms existing train-free methods by 30\% and even a widely recognized training method by 25\%.

For agents

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

get_harvested_code_for_paper("2408.08696")
get_code_for_paper("2408.08696")
have("2408.08696")

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

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

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

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

Connect an agent — have() is free.