Views
No views yet
git clone git@github.com:wangyu-ustc/MemoryLLM.git
cd MemoryLLM1from modeling_memoryllm import MemoryLLM
2from configuration_memoryllm import MemoryLLMConfig
3from transformers import AutoTokenizer
4model = MemoryLLM.from_pretrained("YuWangX/memoryllm-8b")
5tokenizer = AutoTokenizer.from_pretrained("YuWangX/memoryllm-8b")1model = model.cuda()
2
3# Self-Update with the new context
4ctx = "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."
5
6# 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.
7model.inject_memory(tokenizer(ctx, return_tensors='pt', add_special_tokens=False).input_ids.cuda(), update_memory=True)
8
9# Generation
10inputs = tokenizer("Question: What fruits does David like? Answer:", return_tensors='pt', add_special_tokens=False).input_ids.cuda()
11outputs = model.generate(input_ids=inputs, max_new_tokens=20)
12response = tokenizer.decode(outputs[0][inputs.shape[1]:])
13print(response)