YuWangX commited on
Commit
e2a1285
·
verified ·
1 Parent(s): 4084804

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +43 -3
README.md CHANGED
@@ -1,3 +1,43 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+
6
+ This model is continually pre-trained from [meta-llama/Meta-Llama-3-8B](https://huggingface.co/meta-llama/Meta-Llama-3-8B) with the structure proposed in [MemoryLLM](https://arxiv.org/abs/2402.04624).
7
+ We equip Llama-3 with 12800 memory tokens in each layer, leading to a memory pool of 1.67B parameters.
8
+
9
+
10
+ To use the model, please use the following code:
11
+ ```
12
+ git clone [email protected]:wangyu-ustc/MemoryLLM.git
13
+ cd MemoryLLM
14
+ ```
15
+ Then simply use the following code to load the model:
16
+ ```python
17
+ from modeling_memoryllm import MemoryLLM
18
+ from configuration_memoryllm import MemoryLLMConfig
19
+ from transformers import AutoTokenizer
20
+ model = MemoryLLM.from_pretrained("YuWangX/memoryllm-8b")
21
+ tokenizer = AutoTokenizer.from_pretrained("YuWangX/memoryllm-8b")
22
+ ```
23
+
24
+ ### How to use the model
25
+
26
+ Inject a piece of context into the model using the following script:
27
+
28
+ ```python
29
+ model = model.cuda()
30
+
31
+ # Self-Update with the new context
32
+ ctx = "Last week, John had a wonderful picnic with David. During their conversation, David mentioned multiple times that he likes eating apples. Though he didn't mention any other fruits, John says he can infer that David also like bananas."
33
+
34
+ # please make sure the context to inject into the memory is larger than 16 tokens, this is the hard minimum when training the model. The memory will be disturbed when less than 16 tokens are injected into the memory.
35
+ model.inject_memory(tokenizer(ctx, return_tensors='pt', add_special_tokens=False).input_ids.cuda(), update_memory=True)
36
+
37
+ # Generation
38
+ inputs = tokenizer("Question: What fruits does David like? Answer:", return_tensors='pt', add_special_tokens=False).input_ids.cuda()
39
+ outputs = model.generate(input_ids=inputs, max_new_tokens=20)
40
+ response = tokenizer.decode(outputs[0][inputs.shape[1]:])
41
+ print(response)
42
+ ```
43
+