Repository navigation
[None][feat] support C++ streaming KV events with multimodal payloads #19359
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
Merged
pcastonguay
merged 16 commits into
NVIDIA:main
from
GuanLuo:feat/streaming-kv-events-cpp-dto
Oct 6, 2026
+1,222
−492
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1454f28
[None][feat] support C++ streaming KV event capture
GuanLuo 63db7b7
[None][fix] select streaming KV lifecycle with C++ backend
GuanLuo 3e0a0df
[None][fix] preserve multimodal streaming KV events
GuanLuo 7f9e71b
[None][fix] address streaming KV event review findings
GuanLuo b3971b0
[None][docs] clarify streaming KV event contract
GuanLuo 99f1810
[None][fix] align KV block forward declaration
GuanLuo 2008129
Merge upstream/main into feat/streaming-kv-events-cpp-dto
GuanLuo 3a381b2
Simplify native-only streaming KV event plumbing
GuanLuo 36d9f9b
Preserve common creation notification interface for streaming events
GuanLuo 328c7cd
fix: select streaming event groups from public layer configuration
GuanLuo 4dd4d14
docs: acknowledge missing LoRA identity in V2 streaming events
GuanLuo 256aca7
fix: preserve LoRA identity in native streaming KV events
GuanLuo 1aabf98
test: cover native streaming removals at the entry cap
GuanLuo 2bf0ea7
Merge branch 'main' into feat/streaming-kv-events-cpp-dto
GuanLuo e78a68b
Merge branch 'main' into feat/streaming-kv-events-cpp-dto
GuanLuo 526e0dd
fix: remove unused lifecycle import after main merge
GuanLuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
90 changes: 90 additions & 0 deletions
90
cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2/eventData.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "kv_cache_manager_v2/eventData.h" | ||
|
|
||
| #include "kv_cache_manager_v2/blockRadixTree.h" | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| namespace tensorrt_llm::batch_manager::kv_cache_manager_v2 | ||
| { | ||
|
|
||
| std::string digestToHex(Digest const& digest) | ||
| { | ||
| constexpr char kHex[] = "0123456789abcdef"; | ||
| std::string result(digest.size() * 2, '\0'); | ||
| auto out = result.begin(); | ||
| for (auto byte : digest) | ||
| { | ||
| auto const value = std::to_integer<unsigned>(byte); | ||
| *out++ = kHex[value >> 4U]; | ||
| *out++ = kHex[value & 0x0FU]; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| DecodedEventBlock decodeEventBlock(Block const& block, std::optional<int> mmTokenIdOffset) | ||
| { | ||
| DecodedEventBlock result; | ||
| result.tokenIds.reserve(block.tokens.size()); | ||
|
|
||
| Digest const* itemDigest = nullptr; | ||
| if (mmTokenIdOffset.has_value() && block.prev != nullptr && block.prev->type() == NodeBase::Type::kBLOCK) | ||
| { | ||
| itemDigest = static_cast<Block const*>(block.prev)->getLastTokenDigest().get(); | ||
| } | ||
| bool inMmRun = false; | ||
| for (auto const& token : block.tokens) | ||
| { | ||
| if (token.isDigest()) | ||
| { | ||
| result.tokenIds.emplace_back(std::in_place_index<1>, digestToHex(token.digest())); | ||
| if (mmTokenIdOffset.has_value()) | ||
| { | ||
| itemDigest = &token.digest(); | ||
| result.mmKeys.push_back( | ||
| {std::string(reinterpret_cast<char const*>(itemDigest->data()), itemDigest->size()), 0, | ||
| std::nullopt, false}); | ||
| inMmRun = true; | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| auto const tokenId = token.tokenId(); | ||
| result.tokenIds.emplace_back(std::in_place_index<0>, tokenId); | ||
| if (itemDigest != nullptr && tokenId > *mmTokenIdOffset) | ||
| { | ||
| if (!inMmRun) | ||
| { | ||
| result.mmKeys.push_back( | ||
| {std::string(reinterpret_cast<char const*>(itemDigest->data()), itemDigest->size()), | ||
| tokenId - *mmTokenIdOffset, std::nullopt, false}); | ||
| } | ||
| inMmRun = true; | ||
| } | ||
| else | ||
| { | ||
| // Text separates runs of the same item, so retain its digest for later continuations. | ||
| inMmRun = false; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace tensorrt_llm::batch_manager::kv_cache_manager_v2 | ||
61 changes: 61 additions & 0 deletions
61
cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2/eventData.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "kv_cache_manager_v2/common.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| namespace tensorrt_llm::batch_manager::kv_cache_manager_v2 | ||
| { | ||
|
|
||
| struct Block; | ||
|
|
||
| using EventTokenId = std::variant<int64_t, std::string>; | ||
|
|
||
| struct MmKey | ||
| { | ||
| std::string hash; | ||
| int startOffset = 0; | ||
| std::optional<std::string> uuid; | ||
| bool hasUuidField = false; | ||
|
|
||
| bool operator==(MmKey const& other) const | ||
| { | ||
| return hash == other.hash && startOffset == other.startOffset && uuid == other.uuid | ||
| && hasUuidField == other.hasUuidField; | ||
| } | ||
| }; | ||
|
|
||
| struct DecodedEventBlock | ||
| { | ||
| std::vector<EventTokenId> tokenIds; | ||
| std::vector<MmKey> mmKeys; | ||
| }; | ||
|
|
||
| [[nodiscard]] std::string digestToHex(Digest const& digest); | ||
|
|
||
| //! Decode the V2 digest-first multimodal representation used by KV event consumers. | ||
| //! When mmTokenIdOffset is absent, tokens are still preserved but no MM segments are derived. | ||
| [[nodiscard]] DecodedEventBlock decodeEventBlock(Block const& block, std::optional<int> mmTokenIdOffset); | ||
|
|
||
| } // namespace tensorrt_llm::batch_manager::kv_cache_manager_v2 |
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 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.