HongruCai commited on
Commit
6484db7
·
verified ·
1 Parent(s): 7b0421d

Publish EngramEdit checkpoint, standalone inference and model card

Browse files

Sanitize only the historical model path; preserve all memory tensors. Include evaluation scope and 95% confidence intervals.

Files changed (10) hide show
  1. LICENSE +22 -0
  2. README.md +162 -0
  3. SHA256SUMS +9 -0
  4. engramedit_memory.py +138 -0
  5. engramedit_state.pt +3 -0
  6. inference.py +92 -0
  7. manifest.json +73 -0
  8. requirements.txt +11 -0
  9. results.json +40 -0
  10. verification.json +39 -0
LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 jianghc
4
+ Copyright (c) 2026 HongruCai
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
README.md CHANGED
@@ -1,3 +1,165 @@
1
  ---
 
 
2
  license: mit
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ base_model:
3
+ - meituan-longcat/LongCat-Flash-Lite
4
  license: mit
5
+ pipeline_tag: text-generation
6
+ language:
7
+ - en
8
+ tags:
9
+ - engramedit
10
+ - knowledge-editing
11
+ - additive-memory
12
+ - custom_code
13
+ - mcf
14
  ---
15
+
16
+ # EngramEdit LongCat Flash Lite MCF 2K
17
+
18
+ ## Overview
19
+
20
+ EngramEdit updates factual knowledge through conditional n-gram memory while keeping the pretrained LongCat backbone, hashed embedding tables, and projections frozen. It stores cumulative residual vectors indexed by exact token-ID n-grams and adds them when those keys are activated.
21
+
22
+ This repository provides the final additive-memory checkpoint for **2,000 MCF cases**. It is **not a complete language model or a PEFT/LoRA adapter**. You need the original [LongCat-Flash-Lite](https://huggingface.co/meituan-longcat/LongCat-Flash-Lite) weights and the included memory loader. Do not pass this checkpoint repository directly to `AutoModelForCausalLM.from_pretrained`.
23
+
24
+ | Setting | Value |
25
+ | --- | --- |
26
+ | Benchmark | [MultiCounterFact (MEMIT distribution)](https://memit.baulab.info/data/dsets/multi_counterfact.json) |
27
+ | Cases | 2000 |
28
+ | Atomic editing requests | 2000 |
29
+ | Processed / skipped requests | 2000 / 0 |
30
+ | Sequential batch size | 100 cases |
31
+ | Additional edit expressions | 4 per fact, in addition to the original prompt |
32
+ | Exact n-gram lengths | 2, 3, 4 |
33
+ | Base-model precision | BF16 |
34
+ | Base-model revision | `b62b68827ead0b7fef3ba98b57f18484acaaec06` |
35
+
36
+ ## Links
37
+
38
+ - Paper: **TODO — add the EngramEdit paper link.**
39
+ - GitHub code: **TODO — add the public EngramEdit repository link.** The compatible branch is `release/public`, code snapshot `dbb67d580706720f14f1fae168d4df96d6831877`.
40
+ - Hugging Face collection: **TODO — add the collection link.**
41
+ - Companion checkpoints: [MCF 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).
42
+
43
+ Single-prompt inference uses the files included here and does not depend on the placeholder GitHub link.
44
+
45
+ ## Evaluation
46
+
47
+ The following results come from the completed final evaluation of this saved state. Values are percentages with **95% confidence intervals**, computed as `1.96 × case-level standard deviation / sqrt(number of cases)`.
48
+
49
+ | Metric | Result (%) |
50
+ | --- | ---: |
51
+ | Efficacy | 99.30 ± 0.37 |
52
+ | Generalization | 96.75 ± 0.70 |
53
+ | Specificity | 85.22 ± 0.92 |
54
+
55
+ Efficacy and Generalization compare the new and original target losses. Specificity measures preference for the original target on neighborhood prompts. The scores are aggregated at the case level.
56
+
57
+ Independent reload evaluation on all 2,000 cases exactly reproduced the three core metrics, all 52,000 compared labels, and every compared target loss. Sampled Consistency/Fluency and GLUE were not part of this reload check.
58
+
59
+ The published checkpoint replaces only the historical local model-path metadata with the canonical base-model ID. Every memory tensor, key, dtype, and processed/skipped request ID is verified unchanged. `results.json` contains the original summary and confidence-interval calculations; `verification.json` records the scope and status of the checks.
60
+
61
+ Different hardware or dependency versions may produce numerical differences. CF sampled generation metrics cannot be expected to reproduce exactly without the original random state.
62
+
63
+ ### Example evaluation script
64
+
65
+ Once the public code link above is available, run from the compatible `release/public` code checkout:
66
+
67
+ ```bash
68
+ python scripts/prepare/download.py --datasets mcf --data_dir ./data
69
+ python -c 'from dsets import AttributeSnippets, get_tfidf_vectorizer; AttributeSnippets("./data"); get_tfidf_vectorizer("./data")'
70
+
71
+ python -m experiments.checkpoint evaluate \
72
+ --bundle_dir ./checkpoints/mcf \
73
+ --model_name ./base-model/LongCat-Flash-Lite \
74
+ --data_dir ./data \
75
+ --output_dir ./results/mcf-reloaded
76
+ ```
77
+
78
+ This reuses the original benchmark evaluators without editing again. No paraphrases, frequency caches, Wikipedia corpus, or target optimization are needed. The default check evaluates CF/zsRE core metrics or MQuAKE direct/CoT generation; GLUE is separate.
79
+
80
+ ## Usage Example
81
+
82
+ Install the tested dependencies and download this checkpoint plus the pinned base model. The base model is large; the original validation used two GPUs with sufficient combined VRAM. All paths below are relative to your working directory, including the Hugging Face cache.
83
+
84
+ ```bash
85
+ pip install torch==2.9.1 --index-url https://download.pytorch.org/whl/cu128
86
+ export HF_HOME=./hf-cache
87
+ pip install huggingface-hub==0.36.2
88
+ ```
89
+
90
+ ```python
91
+ from huggingface_hub import snapshot_download
92
+
93
+ checkpoint_dir = snapshot_download(
94
+ repo_id="ModalityDance/EngramEdit-LongCat-Flash-Lite-MCF-2K",
95
+ local_dir="./checkpoints/mcf",
96
+ cache_dir="./hf-cache",
97
+ )
98
+ base_model_dir = snapshot_download(
99
+ repo_id="meituan-longcat/LongCat-Flash-Lite",
100
+ revision="b62b68827ead0b7fef3ba98b57f18484acaaec06",
101
+ local_dir="./base-model/LongCat-Flash-Lite",
102
+ cache_dir="./hf-cache",
103
+ )
104
+ ```
105
+
106
+ ```bash
107
+ pip install -r ./checkpoints/mcf/requirements.txt
108
+
109
+ # CPU-only checksum check; does not load the base weights.
110
+ python ./checkpoints/mcf/inference.py \
111
+ --base_model ./base-model/LongCat-Flash-Lite \
112
+ --check_only
113
+
114
+ # Single-prompt inference.
115
+ python ./checkpoints/mcf/inference.py \
116
+ --base_model ./base-model/LongCat-Flash-Lite \
117
+ --prompt "The mother tongue of Danielle Darrieux is" \
118
+ --max_new_tokens 32
119
+ ```
120
+
121
+ For programmatic inference, inspect the downloaded loader before importing it:
122
+
123
+ ```python
124
+ import sys
125
+ from pathlib import Path
126
+ import torch
127
+
128
+ checkpoint_dir = Path("./checkpoints/mcf").resolve()
129
+ sys.path.insert(0, str(checkpoint_dir))
130
+ from inference import load_edited_model
131
+
132
+ model, tokenizer = load_edited_model(
133
+ base_model_dir="./base-model/LongCat-Flash-Lite",
134
+ checkpoint_dir=checkpoint_dir,
135
+ )
136
+ inputs = tokenizer("The mother tongue of Danielle Darrieux is", return_tensors="pt").to(
137
+ model.get_input_embeddings().weight.device
138
+ )
139
+ with torch.no_grad():
140
+ output = model.generate(
141
+ **inputs, do_sample=False, max_new_tokens=32,
142
+ pad_token_id=tokenizer.pad_token_id,
143
+ )
144
+ print(tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
145
+ ```
146
+
147
+ The base model uses trusted custom model code. This example demonstrates loading and generation, not the benchmark scoring procedure. Exact-key activation depends on tokenization and prompt formatting; arbitrary chat templates need not activate the same keys as the evaluation prompts.
148
+
149
+ ### Repository files
150
+
151
+ - `engramedit_state.pt`: additive memory and processed/skipped request IDs.
152
+ - `manifest.json`: base revision, evaluation settings, and compatibility checksums.
153
+ - `engramedit_memory.py`, `inference.py`: standalone loading and inference.
154
+ - `results.json`, `verification.json`: evaluation summary and verification scope.
155
+ - `requirements.txt`, `LICENSE`, `SHA256SUMS`: dependencies, license, and file checksums.
156
+
157
+ Base weights are not included. The memory loader is identical to the validated release implementation except that its constant n-gram-length import is made standalone.
158
+
159
+ ## Citation
160
+
161
+ **TODO — replace this section with the EngramEdit paper citation and BibTeX.**
162
+
163
+ ## License
164
+
165
+ The provided memory checkpoint and loader are released under the **MIT License**; see [LICENSE](LICENSE). The separately downloaded [LongCat-Flash-Lite base model](https://huggingface.co/meituan-longcat/LongCat-Flash-Lite) is also distributed under MIT. Benchmark datasets retain their own applicable terms.
SHA256SUMS ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ dedd4129ab4845bded9f6043c7aafe8f1aff136ac868ab41a036bd06414d7b60 LICENSE
2
+ 587298c0c28c8420321656a6499a4f4fde5b847d3ecb7ffdeb16ab06a14e66a3 README.md
3
+ e35cc2822f4232e9ec25107f6fdf8d88e0059541a818d6196a2d32e79c6a66e8 engramedit_memory.py
4
+ c4eb44035f60ec28c41006feed3429454c4f4f821f528b6164a54de8d6d6a33c engramedit_state.pt
5
+ fcaa60f964802ebd233334cc0ffc46e5af9ceb3048e58c51c2781cd1ed82bbdc inference.py
6
+ 75becb0776fbeb0fa190964db204c08ac337dc72d896abdd8d4100360cc10438 manifest.json
7
+ b4ea95de316226f5be30012913c83ddfc55f509db434706c58655d914eb6b982 requirements.txt
8
+ 8526db28fb45ee67a68ada6942c669fca3db8034ccd28fde92fc3847c4c89543 results.json
9
+ 6acb5281f3ab3ea07b55f5422ce201b704f151483de469f3cc9eff790af0abe7 verification.json
engramedit_memory.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Exact-key additive memory and saved editing states."""
2
+
3
+ from pathlib import Path
4
+ from typing import Dict, Optional, Tuple
5
+
6
+ import torch
7
+ from torch import nn
8
+
9
+ NGRAM_LENGTHS = (2, 3, 4) # Same constant as the release implementation.
10
+
11
+
12
+ class EngramEditEmbedding(nn.Module):
13
+ """Add cumulative updates whenever their exact n-grams are activated."""
14
+
15
+ def __init__(self, base_embedding):
16
+ super().__init__()
17
+ self.base_embedding = base_embedding
18
+ self.key_lengths = NGRAM_LENGTHS
19
+ self.updates = {length: {} for length in NGRAM_LENGTHS}
20
+ self.processed_request_ids = set()
21
+ self.skipped_request_ids = set()
22
+
23
+ @property
24
+ def config(self):
25
+ return self.base_embedding.config
26
+
27
+ def _context_with_history(
28
+ self,
29
+ input_ids: torch.Tensor,
30
+ ngram_context: Optional[torch.Tensor],
31
+ ) -> torch.Tensor:
32
+ if ngram_context is not None:
33
+ return torch.cat(
34
+ [ngram_context[..., -(self.config.emb_neighbor_num - 1) :], input_ids],
35
+ dim=-1,
36
+ )
37
+ return input_ids
38
+
39
+ def _iter_position_keys(
40
+ self,
41
+ context: torch.Tensor,
42
+ seq_len: int,
43
+ eos_token_id: Optional[int],
44
+ ):
45
+ full_len = context.size(-1)
46
+ start_offset = full_len - seq_len
47
+ for batch_idx in range(context.size(0)):
48
+ row = context[batch_idx].tolist()
49
+ for pos in range(seq_len):
50
+ ctx_idx = start_offset + pos
51
+ available = {}
52
+ for length in self.key_lengths:
53
+ key_start = ctx_idx - length + 1
54
+ if key_start < 0:
55
+ continue
56
+ key_tokens = row[key_start : ctx_idx + 1]
57
+ if eos_token_id is not None and eos_token_id in key_tokens[:-1]:
58
+ continue
59
+ available[length] = tuple(key_tokens)
60
+ yield batch_idx, pos, available
61
+
62
+ def _activated_updates(
63
+ self,
64
+ input_ids: torch.Tensor,
65
+ ngram_context: Optional[torch.Tensor],
66
+ output: torch.Tensor,
67
+ ) -> torch.Tensor:
68
+ context = self._context_with_history(input_ids, ngram_context)
69
+ residual = torch.zeros_like(output)
70
+ for batch_idx, pos, keys in self._iter_position_keys(
71
+ context, input_ids.size(-1), self.config.eos_token_id
72
+ ):
73
+ for length, key in keys.items():
74
+ stored = self.updates[length].get(key)
75
+ if stored is not None:
76
+ residual[batch_idx, pos, :] += stored.to(
77
+ output.device, dtype=output.dtype
78
+ )
79
+ return residual
80
+
81
+ def forward(
82
+ self, input_ids: torch.Tensor, ngram_context: Optional[torch.Tensor] = None
83
+ ) -> torch.Tensor:
84
+ base_output = self.base_embedding(input_ids, ngram_context=ngram_context)
85
+ if not any(self.updates[length] for length in NGRAM_LENGTHS):
86
+ return base_output
87
+
88
+ residual = self._activated_updates(input_ids, ngram_context, base_output)
89
+ return base_output + residual
90
+
91
+ def add_updates(
92
+ self,
93
+ residuals: Dict[Tuple[int, Tuple[int, ...]], torch.Tensor],
94
+ storage_dtype: torch.dtype,
95
+ ) -> None:
96
+ for (length, key), residual in residuals.items():
97
+ stored_residual = residual.detach().to(dtype=storage_dtype).cpu()
98
+ current = self.updates[length].get(key)
99
+ if current is None:
100
+ self.updates[length][key] = stored_residual.clone()
101
+ else:
102
+ self.updates[length][key] = current + stored_residual
103
+
104
+ def snapshot(self, model_name):
105
+ return {
106
+ "model_name": model_name,
107
+ "ngram_key_lengths": list(NGRAM_LENGTHS),
108
+ "processed_request_ids": sorted(self.processed_request_ids),
109
+ "skipped_request_ids": sorted(self.skipped_request_ids),
110
+ "memory": self.updates,
111
+ }
112
+
113
+ def load_snapshot(self, payload):
114
+ self.updates = {
115
+ length: {key: value.detach().cpu() for key, value in table.items()}
116
+ for length, table in payload["memory"].items()
117
+ }
118
+ self.processed_request_ids = set(payload["processed_request_ids"])
119
+ self.skipped_request_ids = set(payload["skipped_request_ids"])
120
+
121
+ def save(self, directory, model_name):
122
+ path = Path(directory) / "engramedit_state.pt"
123
+ temporary = path.with_suffix(".pt.tmp")
124
+ torch.save(self.snapshot(model_name), temporary)
125
+ temporary.replace(path)
126
+
127
+
128
+ def prepare_engramedit_model(model, state_dir=None):
129
+ """Install additive memory, optionally loading a saved editing state."""
130
+ if not hasattr(model, "model") or not hasattr(model.model, "ngram_embeddings"):
131
+ raise ValueError("Expected a LongCat model with model.ngram_embeddings.")
132
+ if not isinstance(model.model.ngram_embeddings, EngramEditEmbedding):
133
+ model.model.ngram_embeddings = EngramEditEmbedding(model.model.ngram_embeddings)
134
+ if state_dir is not None:
135
+ path = Path(state_dir) / "engramedit_state.pt"
136
+ payload = torch.load(path, map_location="cpu", weights_only=True)
137
+ model.model.ngram_embeddings.load_snapshot(payload)
138
+ return model
engramedit_state.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4eb44035f60ec28c41006feed3429454c4f4f821f528b6164a54de8d6d6a33c
3
+ size 59332765
inference.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Load published EngramEdit additive memory without the training repository."""
2
+ import argparse
3
+ import hashlib
4
+ import json
5
+ from pathlib import Path
6
+
7
+ import torch
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer
9
+
10
+ from engramedit_memory import prepare_engramedit_model
11
+
12
+
13
+ def sha256(path):
14
+ digest = hashlib.sha256()
15
+ with Path(path).open("rb") as stream:
16
+ for block in iter(lambda: stream.read(8 * 1024 * 1024), b""):
17
+ digest.update(block)
18
+ return digest.hexdigest()
19
+
20
+
21
+ def check_bundle(base_model_dir, checkpoint_dir):
22
+ base_model_dir, checkpoint_dir = Path(base_model_dir), Path(checkpoint_dir)
23
+ manifest = json.loads((checkpoint_dir / "manifest.json").read_text())
24
+ if manifest["format_version"] != 1:
25
+ raise ValueError("Unsupported checkpoint manifest")
26
+ checks = {checkpoint_dir / "engramedit_state.pt": manifest["checkpoint_sha256"]}
27
+ for root, hashes in (
28
+ (base_model_dir, manifest["base_model"]["files_sha256"]),
29
+ (checkpoint_dir, manifest["standalone_files_sha256"]),
30
+ ):
31
+ for name, expected in hashes.items():
32
+ path = root / name
33
+ if not path.resolve().is_relative_to(root.resolve()):
34
+ raise ValueError(f"Unsafe manifest path: {name}")
35
+ checks[path] = expected
36
+ for path, expected in checks.items():
37
+ if sha256(path) != expected:
38
+ raise ValueError(f"Checksum mismatch: {path}")
39
+ return manifest
40
+
41
+
42
+ def load_edited_model(base_model_dir, checkpoint_dir):
43
+ """Use a trusted local base-model snapshot and the downloaded memory bundle."""
44
+ manifest = check_bundle(base_model_dir, checkpoint_dir)
45
+ model = AutoModelForCausalLM.from_pretrained(
46
+ str(base_model_dir),
47
+ torch_dtype=getattr(torch, manifest["evaluation"]["torch_dtype"]),
48
+ device_map="auto",
49
+ trust_remote_code=True,
50
+ local_files_only=True,
51
+ )
52
+ tokenizer = AutoTokenizer.from_pretrained(
53
+ str(base_model_dir), trust_remote_code=True, local_files_only=True,
54
+ fix_mistral_regex=True,
55
+ )
56
+ if tokenizer.pad_token is None:
57
+ tokenizer.pad_token = tokenizer.eos_token
58
+ model = prepare_engramedit_model(model, state_dir=checkpoint_dir)
59
+ model.eval()
60
+ return model, tokenizer
61
+
62
+
63
+ def main():
64
+ parser = argparse.ArgumentParser(description=__doc__)
65
+ parser.add_argument("--base_model", type=Path, required=True)
66
+ parser.add_argument("--checkpoint_dir", type=Path, default=Path(__file__).resolve().parent)
67
+ parser.add_argument("--prompt")
68
+ parser.add_argument("--max_new_tokens", type=int, default=32)
69
+ parser.add_argument("--check_only", action="store_true")
70
+ args = parser.parse_args()
71
+ if args.check_only:
72
+ check_bundle(args.base_model, args.checkpoint_dir)
73
+ print("Checkpoint, loader, and base-model configuration checksums: PASS")
74
+ return
75
+ if not args.prompt:
76
+ parser.error("--prompt is required unless --check_only is set")
77
+ if args.max_new_tokens <= 0:
78
+ parser.error("--max_new_tokens must be positive")
79
+ model, tokenizer = load_edited_model(args.base_model, args.checkpoint_dir)
80
+ inputs = tokenizer(args.prompt, return_tensors="pt").to(
81
+ model.get_input_embeddings().weight.device
82
+ )
83
+ with torch.no_grad():
84
+ output = model.generate(
85
+ **inputs, do_sample=False, max_new_tokens=args.max_new_tokens,
86
+ pad_token_id=tokenizer.pad_token_id,
87
+ )
88
+ print(tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
89
+
90
+
91
+ if __name__ == "__main__":
92
+ main()
manifest.json ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format_version": 1,
3
+ "base_model": {
4
+ "repo_id": "meituan-longcat/LongCat-Flash-Lite",
5
+ "revision": "b62b68827ead0b7fef3ba98b57f18484acaaec06",
6
+ "files_sha256": {
7
+ "config.json": "c5719c2df9c931b11b0336a0fa8bfdceae617c5303d1bad7197436a7daea33a0",
8
+ "configuration_longcat_ngram.py": "a16827e05dd0e4a5d97d5636bfd69d82a8d7698f22c42a15b10ccb810ea83c41",
9
+ "generation_config.json": "f9631f9f51372ad6707a0b5d3b422b936ecfe5ce883ad7162bb0fb012a2a7903",
10
+ "model.safetensors.index.json": "5dfb90170455b0489b89d56d3e53ea87d5aeedbd1c79c6d841ec7fc3c9ac8bcd",
11
+ "modeling_longcat_ngram.py": "d75c6bfc20a1c8045b3958eb2e2167d3e80bb110e8475d64390abe8eb160968f",
12
+ "parse_model_response.py": "8b501fac0e68b0f1d8bfe5f9148e19fd927acc0336e9f46608d86a95314a8142",
13
+ "special_tokens_map.json": "e0137d1717388944c22ab5a36a7f15e5180a69bead466d9da671a16b6f4e4ee9",
14
+ "tokenizer.json": "fd227140f6dfb2478bd710d2cf7223913761259a283a1f1bc35c8d9bddba8f1f",
15
+ "tokenizer_config.json": "f12798e83397ee682396deec089e1745fbabea184370a3da7805b0dfe395c616"
16
+ },
17
+ "weight_shards_hashed": false
18
+ },
19
+ "evaluation": {
20
+ "ds_name": "mcf",
21
+ "dataset_size_limit": 2000,
22
+ "num_edits": 100,
23
+ "mquake_shuffle_seed": null,
24
+ "torch_dtype": "bfloat16"
25
+ },
26
+ "data_sha256": {
27
+ "multi_counterfact.json": "977a6acce4705507b5fd6bfcea8f61cd78f9ed0f9cd9c9a6bcd6c8a3ed61c833",
28
+ "attribute_snippets.json": "10b5c1cd105e54d5983c72de1b45bfc88bc7af786f7b99def2557886ff23385b",
29
+ "idf.npy": "c073d642589d4ac6432f467230329b36364a01e72de63a77a3624b745b923dda",
30
+ "tfidf_vocab.json": "8a78c4f20d8d85dadfd14e283d71af255482ff18aa0eb8a81716024c05ff888b"
31
+ },
32
+ "source_sha256": {
33
+ "EngramEdit/data.py": "8677d4a3c22498a594fa16960746a0ad9af317afea00911f3bc6170c2b26b571",
34
+ "EngramEdit/memory.py": "7399284180e40ff6834ec39d45939e4da306bdb3be84f0b9a36fef9d52c42bb2",
35
+ "dsets/__init__.py": "e4512555e7a1620ab79b8f2d7af5d19d45911e7cf78a0bc41377ebbf90c8e183",
36
+ "dsets/attr_snippets.py": "5609b673c650d6e05f59bf26883e4e02669bd1a9bf35fe66ef1fa7be1c33bf22",
37
+ "dsets/counterfact.py": "bd587cdea9647363393b4df82a5d9796c99ec5aada820e3460958f7bbacde089",
38
+ "dsets/mquake.py": "267929795631f341df73ad5167d66bcd3054ef9a738d052b479fded0280707d4",
39
+ "dsets/mquake_prompts/multihop-cot-prompts.txt": "2476d9e7d01b09c8417d0cfe49d1bc522e76dd93283c0f5674378ba1d3c90e58",
40
+ "dsets/mquake_prompts/multihop-prompts.txt": "7552bd739459c0d8c72c6c660daade35cf612a0fb875be92270db50ae55a907f",
41
+ "dsets/tfidf_stats.py": "4e6a3896799aefdd466ab2b5eaf51125a3e151d6a42015d211ea3ea5e5595006",
42
+ "dsets/zsre.py": "ad161152ddeb67cb18edc504d942f38737714bc9fb52b34e3b3e64620f07dc31",
43
+ "experiments/evaluate.py": "aced512d14c196f5a94a68d31876f99cdc2c718ea6cc18342f3b5fe533dff0ea",
44
+ "experiments/py/eval_utils_counterfact.py": "a3efc7241c1bfb927a2da1441a64d8330f01fa2a5e5d3ecf3cabd679b33a9253",
45
+ "experiments/py/eval_utils_mquake.py": "8e188601eda3325e601c1f148ada5cad4259567f3580eb528465564ac23821d4",
46
+ "experiments/py/eval_utils_zsre.py": "8399b05ca0925049a9f2d838e2b7756f936d17ae2266ef92c5e21ae6efa59715",
47
+ "experiments/summarize.py": "9453dddbbef26b12694977e934629a50d75aa6f7c4e7e9889f35da642f887a17",
48
+ "experiments/utils.py": "617986ecd84c33ec14f42135e36d91b0e7cf33bf6b7e2c40b51aa3fdf0eed54f",
49
+ "util/__init__.py": "020ffc730105a1a0dcaa9e7e67012c91933ce508231311c23a155e00657c9f5f",
50
+ "util/generate.py": "46f5d96bb3524824c27629cc39b58b83384cd99c7c932eaed80034f6d50831d9",
51
+ "util/globals.py": "2e045bc1bc94d8f7e5005639e56b4cee11e32008c9cd3832d4f98f07440137b9",
52
+ "util/hparams.py": "09e9fec3f476ff68009230f1251044bec21aa71797d484033f736057bbe294b0",
53
+ "util/nethook.py": "83d113d7a466bdcbbab3713b4010148d8dd6376f6ef2ee7b76de8f597ac90984",
54
+ "util/perplexity.py": "e0dc2678eb331aba94d70bddad30ce983b3a062c35d180d1f524835f2966161e",
55
+ "util/repr_tools.py": "0c7d2069f4ef9e4b8a606d33965163c32b93650a61acea923e66eff24cacaa00"
56
+ },
57
+ "checkpoint_sha256": "c4eb44035f60ec28c41006feed3429454c4f4f821f528b6164a54de8d6d6a33c",
58
+ "environment": {
59
+ "torch": "2.9.1+cu128",
60
+ "transformers": "4.57.6",
61
+ "accelerate": "1.10.0",
62
+ "numpy": "2.4.6"
63
+ },
64
+ "standalone_files_sha256": {
65
+ "engramedit_memory.py": "e35cc2822f4232e9ec25107f6fdf8d88e0059541a818d6196a2d32e79c6a66e8",
66
+ "inference.py": "fcaa60f964802ebd233334cc0ffc46e5af9ceb3048e58c51c2781cd1ed82bbdc"
67
+ },
68
+ "release_code": {
69
+ "branch": "release/public",
70
+ "revision": "dbb67d580706720f14f1fae168d4df96d6831877",
71
+ "public_url": null
72
+ }
73
+ }
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install the CUDA build of PyTorch separately (see README).
2
+ accelerate==1.10.0
3
+ datasets==2.21.0
4
+ einops==0.8.1
5
+ huggingface-hub==0.36.2
6
+ nltk==3.9.1
7
+ numpy>=1.26,<2.5
8
+ scikit-learn==1.6.1
9
+ scipy==1.15.2
10
+ tqdm>=4.67,<5
11
+ transformers==4.57.6
results.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "ds_name": "mcf",
3
+ "num_case_files": 2000,
4
+ "metrics": {
5
+ "post/Efficacy": {
6
+ "mean": 99.3,
7
+ "std": 8.337265738837884,
8
+ "n": 2000,
9
+ "ci95_half_width": 0.3653967815950217
10
+ },
11
+ "post/Generalization": {
12
+ "mean": 96.75,
13
+ "std": 16.02927010191044,
14
+ "n": 2000,
15
+ "ci95_half_width": 0.7025137365205039
16
+ },
17
+ "post/Specificity": {
18
+ "mean": 85.215,
19
+ "std": 21.09155696007291,
20
+ "n": 2000,
21
+ "ci95_half_width": 0.9243782402350241
22
+ },
23
+ "post/Fluency": {
24
+ "mean": 566.7149800704743,
25
+ "std": 23.964539775298128,
26
+ "n": 2000,
27
+ "ci95_half_width": 1.0502922637464571
28
+ },
29
+ "post/Consistency": {
30
+ "mean": 16.255638114756966,
31
+ "std": 8.259973557722628,
32
+ "n": 2000,
33
+ "ci95_half_width": 0.36200930240140405
34
+ },
35
+ "post/Utility": {
36
+ "mean": 93.755
37
+ }
38
+ },
39
+ "confidence_interval": "Normal approximation: mean +/- 1.96 * population case std / sqrt(n)"
40
+ }
verification.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "prepared_at_utc": "2026-10-05T13:55:58.307001+00:00",
3
+ "publication_changes": {
4
+ "only_changed_state_field": "model_name",
5
+ "replacement_value": "meituan-longcat/LongCat-Flash-Lite"
6
+ },
7
+ "tensor_count": 9194,
8
+ "all_memory_tensors_bitwise_equal_to_original": true,
9
+ "keys_dtypes_processed_and_skipped_ids_unchanged": true,
10
+ "standalone_forward_and_history_checks": "passed",
11
+ "processed_requests": 2000,
12
+ "skipped_requests": 0,
13
+ "original_state_reload_evaluation": {
14
+ "dataset": "mcf",
15
+ "case_count": 2000,
16
+ "loss_atol": 0.0001,
17
+ "passed": true,
18
+ "mismatched_cases": [],
19
+ "max_absolute_loss_delta": 0.0,
20
+ "compared_labels": 52000,
21
+ "changed_labels": 0,
22
+ "compared_generation_strings": 0,
23
+ "changed_generation_strings": 0,
24
+ "metric_deltas_pp": {
25
+ "Efficacy": 0.0,
26
+ "Generalization": 0.0,
27
+ "Specificity": 0.0
28
+ },
29
+ "excluded": [
30
+ "MCF sampled Consistency/Fluency",
31
+ "GLUE/capability metrics"
32
+ ]
33
+ },
34
+ "notes": [
35
+ "Tensor identity is verified on the sanitized publication copy.",
36
+ "Original-state reload results do not constitute a new full GPU run of the sanitized archive.",
37
+ "Sampled CF Consistency/Fluency and GLUE are not included in strict reload verification."
38
+ ]
39
+ }