Skip to content

feat: share multimodal hash helpers#4704

Open
CUHKSZzxy wants to merge 4 commits into
InternLM:mainfrom
CUHKSZzxy:feat/share-vl-mm-hasher
Open

feat: share multimodal hash helpers#4704
CUHKSZzxy wants to merge 4 commits into
InternLM:mainfrom
CUHKSZzxy:feat/share-vl-mm-hasher

Conversation

@CUHKSZzxy

Copy link
Copy Markdown
Collaborator

Summary

  • move multimodal content hashing into a shared VL helper
  • update PyTorch prefix-cache paths to use the shared helper while preserving existing cache-key behavior
  • populate dict-style multimodal content hashes before TurboMind conversion when prefix caching is enabled

Validation

  • Focused VL hasher unit tests passed
  • PyTorch block-trie prefix-cache unit tests passed
  • Real PyTorch VL server repeated-image check showed cache reuse on a cacheable repeated multimodal prompt

Assistance

Assisted with Codex + GPT-5.5 xHigh Fast, reviewed manually

@CUHKSZzxy CUHKSZzxy marked this pull request as ready for review June 25, 2026 09:28
Copilot AI review requested due to automatic review settings June 25, 2026 09:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes multimodal content hashing into a shared lmdeploy.vl helper module, then updates PyTorch prefix-cache code paths (and tests) to use the shared implementation while keeping existing cache-key behavior stable.

Changes:

  • Added lmdeploy/vl/hasher.py with deterministic hashing helpers for both dataclass-style and dict-style multimodal payloads.
  • Rewired PyTorch prefix-cache hashing call sites to use the shared VL hasher (including unit test monkeypatch targets).
  • Added focused unit tests covering hash stability, sensitivity to content/meta/mRoPE, and ignoring position-only keys for dict-style items.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lmdeploy/vl/hasher.py Introduces shared deterministic multimodal hashing + “ensure content_hash” helpers for two multimodal representations.
lmdeploy/pytorch/multimodal/data_type.py Removes local hashing implementation and re-exports shared hashing helpers for compatibility.
lmdeploy/pytorch/messages.py Updates prefix-cache meta hashing fallback to call the shared VL hasher.
lmdeploy/pytorch/engine/engine.py Ensures multimodal content hashes are populated after preprocessing when prefix caching is enabled.
tests/test_lmdeploy/test_vl/test_hasher.py Adds unit tests validating hash determinism and correct inclusion/exclusion rules.
tests/pytorch/paging/test_block_trie.py Adjusts monkeypatching to target the shared hasher module instead of the previous PyTorch-local symbol.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lvhan028 lvhan028 added the enhancement New feature or request label Jun 30, 2026
Comment thread lmdeploy/pytorch/engine/engine.py Outdated
DistServeInitRequest,
)
from lmdeploy.utils import get_logger, get_model
from lmdeploy.vl import hasher as mm_hasher

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have alias make_multimodal_content_hash in pytorch/multimodal/data_type.py, the change in engine.py and messages.py might not be necessary.

lzhangzz
lzhangzz previously approved these changes Jun 30, 2026
grimoire
grimoire previously approved these changes Jun 30, 2026
@lvhan028

lvhan028 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

It does not match what I had in mind for multimodal fingerprints.

What I expect

  • Compute a stable content fingerprint early in the request path (before engine-specific preprocessing).
  • Attach it to each multimodal item and pass it through to all backends
  • Treat the fingerprint as general multimodal metadata, not something that only exists when enable_prefix_caching is on.

@lvhan028 lvhan028 dismissed stale reviews from grimoire and lzhangzz July 1, 2026 08:42

requirement mismatched

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants