[https://nvbugs/6226933][fix] canonicalize multimodal cache-key serialization to prevent hash collisions#14800
Conversation
|
/bot run |
|
PR_Github #51272 [ run ] triggered by Bot. Commit: |
|
PR_Github #51272 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51319 [ run ] triggered by Bot. Commit: |
|
PR_Github #51319 [ run ] completed with state
|
|
/bot run |
1 similar comment
|
/bot run |
…lization to prevent hash collisions Multimodal cache keys (apply_mm_hashes) fed a non-canonical serialization that omitted shape/dtype/dimensions and modality identity, so semantically different multimodal inputs could serialize to identical bytes and incorrectly share KV-cache blocks (enable_block_reuse is on by default). Encode every multimodal value canonically and self-describingly as [type tag][typed metadata][length-prefixed payload]: images carry mode+width+height, tensors/ndarrays carry dtype+shape, containers are length-framed (dict keys sorted, ints width/sign-unambiguous, bool distinct from int), VideoData carries a modality tag and its sampling metadata, and AudioData binds samples to sample_rate. The per-item hash is prefixed with a versioned scheme tag and the two divergent list-framing paths are unified. Adds regression tests for each collision class. Fixes NVIDIA#14603. Signed-off-by: venkywonka <23023424+venkywonka@users.noreply.github.com>
… serialization serialize_item raised ValueError on numpy scalar values (np.int64, np.float32, np.bool_, ...) reachable through VideoData metadata, because in numpy 2.x these are not subclasses of Python int/float/bool and bypassed every type check. Normalize numpy scalars to their equivalent Python scalar via .item() and recurse, so numpy-typed metadata hashes identically to its Python counterpart. Adds a regression test. Signed-off-by: venkywonka <23023424+venkywonka@users.noreply.github.com>
fdf0786 to
d6e7d0d
Compare
|
/bot run |
|
PR_Github #51366 [ run ] triggered by Bot. Commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR overhauls multimodal KV-cache hashing with versioned scheme identification and canonical serialization. A versioned tag is prepended to all hashes. The new ChangesMultimodal Hash Scheme Versioning and Canonical Serialization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…ainer-agnostic Address PR review feedback: - Merge the torch.Tensor and np.ndarray serialization paths so the container type is not part of the cache-key identity; only dtype, shape and raw bytes are. A tensor and an ndarray with identical content now hash identically. - Collapse the tuple/list tags into a single ordered-sequence tag (the container type is not part of the identity). The VideoData-vs-frame-list distinction is unaffected; it comes from the modality tag in _update_hash. - Single backticks in the serialize_item docstring; concise test helper docstring; drop redundant per-test docstrings. - Add serialize_item container-agnostic regression tests. Signed-off-by: venkywonka <23023424+venkywonka@users.noreply.github.com>
|
PR_Github #51366 [ run ] completed with state |
|
/bot run |
|
PR_Github #51410 [ run ] triggered by Bot. Commit: |
|
PR_Github #51410 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51411 [ run ] triggered by Bot. Commit: |
|
PR_Github #51411 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51415 [ run ] triggered by Bot. Commit: |
|
PR_Github #51415 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51438 [ run ] triggered by Bot. Commit: |
|
PR_Github #51438 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51468 [ run ] triggered by Bot. Commit: |
|
PR_Github #51468 [ run ] completed with state
|
|
/bot run |
|
PR_Github #51502 [ run ] triggered by Bot. Commit: |
|
PR_Github #51502 [ run ] completed with state |
Problem
Multimodal KV-cache block reuse (
enable_block_reuse=Trueby default) keys cache blocks on a BLAKE3 content hash of each multimodal item (apply_mm_hashes). The serialization feeding that hash omitted semantic structure, so semantically different inputs produced identical bytes and therefore identical cache keys, which can cause incorrect cross-request KV-cache reuse / cache poisoning for multimodal serving. Reported in #14603.On
main, the following distinct inputs collided to the same hash:(3,224,224)vs(1,3,224,224))VideoDatadiffering only in sampling metadata (fps / duration / frames_indices / total_num_frames)VideoData(no audio) vs a plain list of the same framesFix
Make multimodal serialization canonical and self-describing — every value is encoded as
[type tag][typed metadata][length-prefixed payload]:boolis distinct fromintVideoDatacarries a modality tag and includes its sampling metadata in the hash;AudioDatabinds samples to sample_rateTests
Adds CPU-only regression tests in
tests/unittest/llmapi/test_llm_kv_cache_events.pycovering each collision class (transposed image dims, reshaped ndarray, reshaped tensor, video-metadata sensitivity, and VideoData-vs-frame-list), plus a positive determinism test (identical inputs still match). Updates one existing assertion that had encoded the VideoData-vs-list collision as expected behavior.Summary by CodeRabbit
Release Notes
Refactor
Tests