Add KV cache support for efficient parallel PFN evaluation#27
Open
eytan wants to merge 2 commits intoSamuelGabriel:mainfrom
Open
Add KV cache support for efficient parallel PFN evaluation#27eytan wants to merge 2 commits intoSamuelGabriel:mainfrom
eytan wants to merge 2 commits intoSamuelGabriel:mainfrom
Conversation
add mtpfn codebase
Implements context caching for PFN models to reduce memory usage and improve performance during parallel evaluations, such as multi-start optimization in Bayesian optimization. The key insight is that when evaluating many candidate points against the same training data, we can cache the key-value representations from the training context and reuse them across all parallel evaluations, rather than recomputing them for each candidate. Changes: - Multi-head attention now supports caching and reusing KV representations - Encoder state can be saved/restored for MultivariatePFNModel - PFNModel gains `cache_training_context()` context manager for easy cache management - Added discretized acquisition functions compatible with Riemann posteriors
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
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.
This PR implements context caching for PFN models to reduce memory usage and
improve runtime performance during parallel evaluations, such as multi-start
optimization in BayesOpt.
The key insight is that when evaluating many candidate points against
the same training data, we can cache the key-value representations from
the training context and reuse them across all parallel evaluations,
rather than recomputing them for each candidate.
Changes:
cache_training_context()context manager for easy cache managementTo give you a sense of the speed up / memory use improvement, here are some benchmarks I ran on my laptop (cpu)