SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.03279 · EMNLP · 2024

Lifelong Knowledge Editing for LLMs with Retrieval-Augmented Continuous Prompt Learning

Hui Xue, Taolin Zhang, Chengyu Wang, Qizhou Chen, Xiaofeng He, Longtao Huang, Dongyang Li, 𝐿𝐿𝐿𝐿𝑀𝑀, • 𝐸𝐸𝐸𝐸𝐸𝐸𝑡𝑡

arXiv · PDF · Open in the Atlas

Code that ran

7 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (4 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 3 failures of our instrument; 4 no recorded run), measured 2026-11-23; 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/2405.03279.json · badge: /api/ran/2405.03279.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
qizhou000/RECIPE marked official in Papers with Code
Papers with Code archive
7 ran · 4 no recorded run
FunctionStatusWhere it lives
KnowledgeRepModel Ran
ran on a synthesized input · constructed an object; no result was computed
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("7af30496f8e6ecb5")
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, KnowledgeRepModel: the run constructed the object and did not call it, so no result was computed. 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
from transformers import RobertaModel, RobertaTokenizer

torch.manual_seed(0)

# Create minimal stand-in classes for RobertaTokenizer and RobertaModel
class MockRobertaTokenizer:
    def __call__(self, sentences, return_tensors=None, padding=False, truncation=False):
        batch_size = len(sentences)
        seq_len = 5
        mock_input_ids = torch.randint(0, 1000, (batch_size, seq_len))
        mock_attention_mask = torch.ones(batch_size, seq_len, dtype=torch.long)
        
        class MockTokenizerOutput:
            def __init__(self, input_ids, attention_mask):
                self.input_ids = input_ids
                self.attention_mask = attention_mask
            
            def to(self, device):
                return self
            
            def keys(self):
                return ['input_ids', 'attention_mask']
            
            def __getitem__(self, key):
                if key == 'input_ids':
                    return self.input_ids
                elif key == 'attention_mask':
                    return self.attention_mask
        
        return MockTokenizerOutput(mock_input_ids, mock_attention_mask)

class MockRobertaPooler(nn.Module):
    def forward(self, hidden_states):
        return hidden_states[:, 0, :]

class MockRobertaEncoder(nn.Module):
    def forward(self, hidden_states):
        class MockEncoderOutput:
            def __init__(self, last_hidden_state):
                self.last_hidden_state = last_hidden_state
        return MockEncoderOutput(hidden_states)

class MockRobertaModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.encoder = MockRobertaEncoder()
        self.pooler = MockRobertaPooler()
    
    def forward(self, input_ids, attention_mask):
        batch_size, seq_len = input_ids.shape
        last_hidden_state = torch.randn(batch_size, seq_len, 768)
        pooler_output = self.pooler(last_hidden_state)
        
        class MockModelOutput:
            def __init__(self, lhs, po):
                self.last_hidden_state = lhs
                self.pooler_output = po
        
        return MockModelOutput(last_hidden_state, pooler_output)

# Monkey-patch the transformers module functions
original_tokenizer = RobertaTokenizer.from_pretrained
original_model = RobertaModel.from_pretrained

def mock_tokenizer_from_pretrained(path):
    return MockRobertaTokenizer()

def mock_model_from_pretrained(path):
    return MockRobertaModel()

RobertaTokenizer.from_pretrained = staticmethod(mock_tokenizer_from_pretrained)
RobertaModel.from_pretrained = staticmethod(mock_model_from_pretrained)

ARGS = {
    'rep_n': 2048,
    'prot_token_n': 10,
    'device': 'cpu',
    'base_path': 'models/roberta-base'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type KnowledgeRepModel — 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 KnowledgeRepModel 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
ParallelDataset Ran
ran on a synthesized input · constructed an object; no result was computed
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("804969a3f054faa8")
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, ParallelDataset: 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 numpy as np
import torch
import torch.nn as nn

torch.manual_seed(0)

def get_data_by_ids_func(ids):
    """Stand-in function that returns dummy data for given ids"""
    batch_size = len(ids)
    # Return a simple dict with tensor data
    return {
        'features': torch.randn(batch_size, 4),
        'labels': torch.randint(0, 2, (batch_size,))
    }

ARGS = {
    'sample_count': 100,
    'get_data_by_ids_func': get_data_by_ids_func,
    'batch_size': [16, 32],
    'shuffle': True,
    'buffer_size': 8,
    'drop_last': False,
    'random_seed': 42
}
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 ParallelDataset — 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 ParallelDataset 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
PromptTransformer Ran
ran on a synthesized input · constructed an object; no result was computed
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("65642b6f8132e7c7")
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, PromptTransformer: the run constructed the object and did not call it, so no result was computed. 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)

# The function uses knowledge_reps as input to forward()
# It expects a tensor of shape (batch_size, in_dim)
# The forward method reshapes output to (batch_size, prompt_token_n, out_dim)

ARGS = {
    'in_dim': 2048,
    'out_dim': 1600,
    'prompt_token_n': 3,
    'device': 'cpu'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PromptTransformer — 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 PromptTransformer 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
RECIPEConfig Ran
ran on a synthesized input · constructed an object; no result was computed
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("b84382c69b38db7f")
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, RECIPEConfig: 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 yaml
import json
from dataclasses import dataclass, asdict

torch.manual_seed(0)

# Create a minimal TrainingConfig
training_config = {
    'krm_lr': 0.001,
    'pt_lr': 0.0005,
    'relia_lambda': 0.1,
    'gen_lambda': 0.2,
    'loc_lambda': 0.15,
    'contra_lambda': 0.05,
    'query_knowledge_t': 0.07,
    'query_prototype_t': 0.08,
    'constra_hinge_scale': 1.0,
    'edit_hinge_scale': 1.5,
    'batch_size': 16,
    'sample_count': 100,
    'random_seed': 42,
    'eps': 1e-08
}

ARGS = {
    'prompt_token_n': 10,
    'edit_model_name': 'bert-base-uncased',
    'knowledge_rep_dim': 768,
    'knowl_rep_prot_token_n': 5,
    'model_hidden_size': 768,
    'begin_layer_path': 'encoder.layer.0',
    'lm_head_path': 'lm_head',
    'training': training_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type RECIPEConfig — 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 RECIPEConfig 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
find_module Ran
ran; our contract draft was wrong, not the code
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("0b7bebf9d95d540c")
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 Linear. 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 nested module structure to test find_module
class SimpleModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(4, 3)
        self.layer2 = nn.Sequential(
            nn.Linear(3, 2),
            nn.ReLU(),
            nn.Linear(2, 1)
        )
        self.nested = nn.ModuleDict({
            'sub1': nn.Linear(1, 2),
            'sub2': nn.Linear(2, 3)
        })

module = SimpleModule()

# Test cases for different module_path patterns:
# 1. Simple attribute access: "layer1"
# 2. Nested attribute access: "layer2.0" (accessing Sequential's first layer)
# 3. Deep nesting: "nested.sub1"

ARGS = {
    "module": module,
    "module_path": "layer1"
}
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 Linear — a Linear output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Linear 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
hinge_label_loss Ran
ran; our contract draft was wrong, not the code
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("532d15ae38761ef5")
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 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)

class SimpleModel(nn.Module):
    def __init__(self, vocab_size=10, hidden_size=4):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_size)
        self.linear = nn.Linear(hidden_size, vocab_size)
    
    def forward(self, input_ids):
        x = self.embedding(input_ids)
        logits = self.linear(x)
        return type('obj', (object,), {'logits': logits})()

model = SimpleModel(vocab_size=8, hidden_size=4)

batch_size = 2
seq_length = 3
vocab_size = 8

input_ids = torch.randint(0, vocab_size, (batch_size, seq_length))
label_ids = torch.randint(0, vocab_size, (batch_size, seq_length))
masks = torch.ones((batch_size, seq_length), dtype=torch.float32)

ARGS = {
    'model': model,
    'input_ids': input_ids,
    'label_ids': label_ids,
    'masks': masks,
    'average': True,
    'eps': 1e-08,
    'hinge_scale': 1.1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, 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
logit_KL_loss Ran
ran; our contract draft was wrong, not the code
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("1897158165b40b18")
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 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)

# Construct tiny tensors with distinct dimensions
# logits1 and logits2: shape (batch=2, seq_len=3, vocab=4)
# These are passed to log_softmax and softmax along dim 2
logits1 = torch.randn(2, 3, 4)
logits2 = torch.randn(2, 3, 4)

# masks: shape (batch=2, seq_len=3)
# Used for element-wise multiplication with kl_loss and summing
masks = torch.ones(2, 3)

ARGS = {
    "logits1": logits1,
    "logits2": logits2,
    "masks": masks,
    "average": True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, 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
BaseEditor Not yet run
unverified (harvested, no recorded run)
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("11dd857ade8eded8")
How it ran

no invocation recorded.

EditorConfig Not yet run
unverified (harvested, no recorded run)
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("972549486d7dfecb")
How it ran

no invocation recorded.

RECIPE Not yet run
unverified (harvested, no recorded run)
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("8c1cfd9a64ce7e2e")
How it ran

no invocation recorded.

set_tokenizer_pad_id Not yet run
unverified (harvested, no recorded run)
qizhou000/RECIPE/editors/recipe/recipe.py
code served (permissive licence) · get_code("062542a916d19f67")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 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 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.

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

Model editing aims to correct outdated or erroneous knowledge in large language models (LLMs) without the need for costly retraining. Lifelong model editing is the most challenging task that caters to the continuous editing requirements of LLMs. Prior works primarily focus on single or batch editing; nevertheless, these methods fall short in lifelong editing scenarios due to catastrophic knowledge forgetting and the degradation of model performance. Although retrieval-based methods alleviate these issues, they are impeded by slow and cumbersome processes of integrating the retrieved knowledge into the model. In this work, we introduce RECIPE, a RetriEval-augmented ContInuous Prompt lEarning method, to boost editing efficacy and inference efficiency in lifelong learning. RECIPE first converts knowledge statements into short and informative continuous prompts, prefixed to the LLM's input query embedding, to efficiently refine the response grounded on the knowledge. It further integrates the Knowledge Sentinel (KS) that acts as an intermediary to calculate a dynamic threshold, determining whether the retrieval repository contains relevant knowledge. Our retriever and prompt encoder are jointly trained to achieve editing properties, i.e., reliability, generality, and locality. In our experiments, RECIPE is assessed extensively across multiple LLMs and editing datasets, where it achieves superior editing performance. RECIPE also demonstrates its capability to maintain the overall performance of LLMs alongside showcasing fast editing and inference speed. 1

For agents

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

get_harvested_code_for_paper("2405.03279")
get_code_for_paper("2405.03279")
have("2405.03279")

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

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

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

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

Connect an agent — have() is free.