Skip to content

feat: add prefix cache for KV cache reuse during inference#928

Open
enjoysport2022 wants to merge 1 commit intoPhysical-Intelligence:mainfrom
enjoysport2022:feature/prefix-cache-optimization
Open

feat: add prefix cache for KV cache reuse during inference#928
enjoysport2022 wants to merge 1 commit intoPhysical-Intelligence:mainfrom
enjoysport2022:feature/prefix-cache-optimization

Conversation

@enjoysport2022
Copy link
Copy Markdown

Add caching infrastructure to avoid redundant computation of prefix embeddings (images + language) when observation hasn't changed between consecutive inference calls. This can provide significant speedup in continuous robot control scenarios.

Changes:

  • Add prefix_cache.py with PrefixCacheKey and PrefixCache classes
  • Add sample_actions_with_cache() method to Pi0 model
  • Add enable_prefix_cache parameter to Policy and create_trained_policy
  • Add clear_cache() and reset() methods to Policy

Usage:
policy = create_trained_policy(config, checkpoint, enable_prefix_cache=True) result = policy.infer(obs) # Auto-caches prefix policy.reset() # Clear cache for new episode

Add caching infrastructure to avoid redundant computation of prefix
embeddings (images + language) when observation hasn't changed between
consecutive inference calls. This can provide significant speedup in
continuous robot control scenarios.

Changes:
- Add prefix_cache.py with PrefixCacheKey and PrefixCache classes
- Add sample_actions_with_cache() method to Pi0 model
- Add enable_prefix_cache parameter to Policy and create_trained_policy
- Add clear_cache() and reset() methods to Policy

Usage:
  policy = create_trained_policy(config, checkpoint, enable_prefix_cache=True)
  result = policy.infer(obs)  # Auto-caches prefix
  policy.reset()  # Clear cache for new episode
@enjoysport2022 enjoysport2022 force-pushed the feature/prefix-cache-optimization branch from b4411ea to b64ff9d Compare April 17, 2026 15:30
@jimmyt857 jimmyt857 removed their request for review April 20, 2026 18:59
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