File size: 4,470 Bytes
7b0421d
6484db7
 
7b0421d
6484db7
d63e2f1
 
 
 
7b0421d
6484db7
d63e2f1
6484db7
 
 
d63e2f1
6484db7
d63e2f1
6484db7
 
 
d860f97
d63e2f1
 
6484db7
cea6c47
6484db7
d63e2f1
 
 
 
 
 
 
 
 
6484db7
 
cea6c47
d63e2f1
 
cea6c47
d63e2f1
cea6c47
 
6484db7
d63e2f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cea6c47
6484db7
cea6c47
d63e2f1
6484db7
cea6c47
6484db7
d63e2f1
 
 
6484db7
 
 
 
d63e2f1
 
 
 
 
d860f97
 
 
 
d63e2f1
 
6484db7
 
 
f640176
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
base_model:
- meituan-longcat/LongCat-Flash-Lite
license: mit
pipeline_tag: text-generation
tags:
- engramedit
- knowledge-editing
- conditional-memory
---

# EngramEdit: CounterFact 路 2K

## Overview

Conditional memory expands an LLM's capacity through learned **n-gram embeddings** that participate in its computation. **EngramEdit** enables decoupled knowledge updates by updating these embeddings while keeping the Transformer backbone fixed. Revised facts remain usable across different expressions and in multi-hop reasoning, while unrelated knowledge and general capabilities are largely preserved.

This repository provides the EngramEdit checkpoint for **2,000 CounterFact (MCF) edits** on [LongCat-Flash-Lite](https://huggingface.co/meituan-longcat/LongCat-Flash-Lite). The checkpoint contains the learned conditional memory updates. Load it together with the base model using the EngramEdit code below.

## Links

[馃搫 Paper](https://arxiv.org/abs/2610.10533) 路 [馃 Hugging Face Paper](https://huggingface.co/papers/2610.10533) 路 [馃寪 Project Page](https://modalitydance.github.io/EngramEdit/) 路 [馃捇 GitHub](https://github.com/ModalityDance/EngramEdit) 路 [馃И Usage Example](https://github.com/ModalityDance/EngramEdit#usage-example) 路 [馃搳 Evaluation](https://github.com/ModalityDance/EngramEdit#direct-evaluation)

**Checkpoints:** [馃 CounterFact 路 2K](https://huggingface.co/ModalityDance/EngramEdit-LongCat-Flash-Lite-MCF-2K) 路 [馃 ZsRE 路 2K](https://huggingface.co/ModalityDance/EngramEdit-LongCat-Flash-Lite-ZsRE-2K) 路 [馃 MQuAKE 路 3K](https://huggingface.co/ModalityDance/EngramEdit-LongCat-Flash-Lite-MQuAKE-3K)

## Usage

Clone the [code repository](https://github.com/ModalityDance/EngramEdit), follow its [installation instructions](https://github.com/ModalityDance/EngramEdit#1-installation), and run the example from that checkout. Download the base model once:

```bash
hf download meituan-longcat/LongCat-Flash-Lite --local-dir data/LongCat-Flash-Lite
```

The example compares the model's response before and after loading the checkpoint. No editing, expression generation, or frequency-cache preparation is needed.

This example uses a CounterFact edit from French to English. Counterfactual targets are benchmark edits, not claims about real-world facts.

```python
from pathlib import Path

import torch
from huggingface_hub import hf_hub_download

from experiments.utils import load_model
from EngramEdit import prepare_engramedit_model

# Load the base model.
model, tokenizer = load_model("data/LongCat-Flash-Lite", "bfloat16")
prompt = "The mother tongue of Danielle Darrieux is"
target = "English"


@torch.inference_mode()
def answer(prompt):
    inputs = tokenizer(prompt, return_tensors="pt").to(
        model.get_input_embeddings().weight.device
    )
    output = model.generate(
        **inputs, do_sample=False, max_new_tokens=32,
        pad_token_id=tokenizer.pad_token_id,
    )
    return tokenizer.decode(
        output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True
    )


# Inspect the query and the target fact.
print("Prompt:", prompt)
# Prompt: The mother tongue of Danielle Darrieux is
print("Target answer:", target)
# Target answer: English

# Responses below are illustrative, not recorded checkpoint outputs.
print("Before loading:", answer(prompt))
# Before loading: French

# Download and load the learned conditional memory updates.
state_path = hf_hub_download(
    repo_id="ModalityDance/EngramEdit-LongCat-Flash-Lite-MCF-2K",
    filename="engramedit_state.pt",
    local_dir="checkpoints/mcf",
)
model = prepare_engramedit_model(model, state_dir=Path(state_path).parent)

# Ask the same question with the checkpoint loaded.
print("After loading:", answer(prompt))
# After loading: English
```

## Citation

```bibtex
@misc{cai2026engramedit,
  title  = {EngramEdit: Decoupled Knowledge Updates in LLMs through Conditional Memory},
  author = {Hongru Cai and Ran Wei and Wenjie Wang and Chengfa Wu and Ning Song and Yongqi Li and Wenjie Li},
  year   = {2026},
  eprint = {2610.10533},
  archivePrefix = {arXiv},
  primaryClass = {cs.CL},
  url    = {https://arxiv.org/abs/2610.10533}
}
```

## License

This checkpoint is released under the [MIT License](https://github.com/ModalityDance/EngramEdit/blob/main/LICENSE). The base model is distributed separately under its [own license](https://huggingface.co/meituan-longcat/LongCat-Flash-Lite/blob/main/LICENSE).