Skip to content

fix bug when calling _concat_caches in kv.py #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RixinLiu
Copy link

Description

Summary: (fix a bug when calling _concat_caches function)

BUG Description:

Traceback (most recent call last):
  File "/root/Misc/test.py", line 24, in <module>
    merged_cache = mem.get_cache([cache_item_1.id, cache_item_2.id])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/lib/python3.12/site-packages/memos/memories/activation/kv.py", line 81, in get_cache
    return self._concat_caches(caches_to_merge)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/lib/python3.12/site-packages/memos/memories/activation/kv.py", line 245, in _concat_caches
    merged.key_cache.append(torch.cat(keys, dim=-2))
    ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'KeyValuesWrapper' object has no attribute 'append'

Solution:
The solution replaced merged.key_cache.append and merged.value_cache.append with operations on merged.layers[layer].keys and merged.layers[layer].values. This aligns with the DynamicCache structure, where keys and values are stored per layer. Additionally, the code now correctly retrieves keys and values from c.layers[layer].keys and c.layers[layer].values respectively.

Fix: #(not applicable)

Docs Issue/PR: (not applicable)

Reviewer: @(not applicable)

Checklist:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant