-
Notifications
You must be signed in to change notification settings - Fork 12k
Hybrid recurrent cache #13904
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
Closed
gabe-l-hart
wants to merge
24
commits into
ggml-org:gg/kv-cache-simplify-part3
from
gabe-l-hart:HybridRecurrentCache
Closed
Hybrid recurrent cache #13904
gabe-l-hart
wants to merge
24
commits into
ggml-org:gg/kv-cache-simplify-part3
from
gabe-l-hart:HybridRecurrentCache
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced May 29, 2025
ggml-ci
256f1b7
to
9d05381
Compare
9d05381
to
2b984f4
Compare
ggml-ci
Sorry about the massive changes, hopefully we are almost converging to the final version of the implementation. See #13746 (comment) for the latest short-term plan. |
No problem, and thanks for the quick work getting these pieces overhauled! I'll plan to keep this branch up to date as the changes roll in so that it will hopefully be ready for review quickly once its turn comes. |
Also, split llama_model_is_recurrent into llm_arch_is_recurrent in llama-arch with llama_model_is_recurrent delegating to llm_arch_is_recurrent. The same split is done for hybird. This is needed because there are places where the llama_model has not yet been initialized but we need to check if the model is recurrent (specifically for the per-layer recurrent check array in hparams). Branch: GraniteFour Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: GraniteFour
…s in hparams Branch: GraniteFour Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
…l is recurrent Branch: GraniteFour Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
The implementation of the hybrid cache intentionally does not specify the types of the child caches, so there was a naming mismatch with these predicate functions that used "hybrid" to imply "hybrid recurrent." Branch: HybridCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
This will be needed by other cache types as well, so centralizing the definition will make it more reusable. Branch: HybridCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: HybridCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: HybridCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: GraniteFour Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
This follows the pattern in iswa where the two child caches are held explicitly to support the case where a model requires a single attention cache and a single recurrent cache where each layer uses exactly one of the caches. This is a rewrite of the more generic approach in the original hybrid cache PR: ggml-org#13276 Branch: HybridRecurrentCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
This includes a refactor of the create_memory logic to avoid needing to use the arch enum explicitly unless a model needs explicit cache instantiation logic beyond the standard logic for recurrent, hybrid, unified, and iswa. Branch: HybridRecurrentCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: HybridRecurrentCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: HybridRecurrentCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
089c968
to
4a2709f
Compare
f23e4cc
to
71619f2
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dependencies
Description
This PR replaces my initial (more generic) attempt in #13276. Following Georgi's comment, this version is explicit about owning two child caches, one
unified
and onerecurrent
. This greatly simplifies the logic and avoids the need for additional interface changes to support managing child caches in the abstract.This PR has been verified to be minimally functional in #13550 (Granite 4 / Bamba).