Skip to content

Commit 77c1bfa

Browse files
committed
feat(hstu): add native inference and history KV caching
Add model-owned HSTU conversion, TensorRT graphs and C++ ranking/retrieval with verified history-prefix reuse, bounded native storage and independent decode sessions. Keep optional original CUDA attention in a verified, bundle-scoped provider with complete third-party notices. Extend the shared runtime only for recommendation tasks, cache storage, scoped plugins and stateful CUDA Graph execution. Document joint runtime rebuild requirements and the external storage adapter boundary. Signed-off-by: yifeif <277870278+yifeif-nv@users.noreply.github.com>
1 parent 4b9cc2b commit 77c1bfa

152 files changed

Lines changed: 17568 additions & 115 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ASSET_LICENSES.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,29 @@ with the rest of the project:
193193
- `families/openfold3/tests/data/openfold3_features.npz`
194194
- `families/openfold3/tests/data/openfold3_structure.json`
195195

196+
## HSTU native-provider license copies
197+
198+
The [HSTU third-party notice](families/hstu/third_party/NOTICE.txt) records
199+
attribution for the optional native attention provider. Its accompanying
200+
license files preserve the full upstream terms. The kernel sources are
201+
obtained separately at build time and verified against
202+
`native_attention_source.json`.
203+
204+
- `FBGEMM.LICENSE.txt` and `HSTU.LICENSE.txt`: verbatim BSD license files from
205+
[FBGEMM revision 43791a0ade113a0ad5530c2a4948870dd0f7e417](https://github.com/pytorch/FBGEMM/tree/43791a0ade113a0ad5530c2a4948870dd0f7e417).
206+
- `CUTLASS.LICENSE.txt`: verbatim license from its pinned
207+
[CUTLASS revision 571edeb2d0ac872a8392fc49285b156b07884b4e](https://github.com/jwfromm/cutlass/tree/571edeb2d0ac872a8392fc49285b156b07884b4e).
208+
The compiled C++ headers use BSD-3-Clause; the separate Python CuTeDSL
209+
exception in this license does not apply to those headers.
210+
- `CCCL.LICENSE.txt`: verbatim [CCCL 3.3.3 license](https://github.com/NVIDIA/cccl/blob/v3.3.3/LICENSE),
211+
including CUB's BSD terms and Thrust/libcu++ notices. These headers come from
212+
the installed CUDA development toolkit.
213+
- `NOTICE.txt`: source attribution and dependency boundaries. The builder
214+
combines this text with the full licenses into `attention_native.NOTICE`
215+
whenever it embeds the native attention library in a model bundle.
216+
217+
This source distribution contains no third-party HSTU model weights or
218+
prebuilt native provider libraries. Users supply their own model checkpoints
219+
and the separately licensed CUDA, TensorRT and cuBLAS runtime dependencies.
220+
196221
<!-- Collaborative review anchor: batch 2. -->

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ set(TRTMC_CUDA_INCLUDE_DIR ${CUDAToolkit_INCLUDE_DIRS})
8686
set(TRTMC_CUDART_LIBRARY CUDA::cudart)
8787

8888
add_library(trtmc_core SHARED
89+
core/runtime/cache/history_cache.cpp
8990
core/runtime/bundle/bundle_format.cpp
9091
core/runtime/primitives/cuda_common.cpp
9192
core/runtime/primitives/device_tensor.cpp
@@ -455,6 +456,12 @@ if(TRTMC_BUILD_EXAMPLES)
455456
endif()
456457

457458
if(TRTMC_BUILD_TESTS)
459+
add_executable(test_history_cache core/runtime/tests/test_history_cache.cpp)
460+
target_link_libraries(test_history_cache PRIVATE trtmc_core)
461+
target_compile_options(test_history_cache PRIVATE -Wall -Wextra -Wpedantic)
462+
add_test(NAME history_cache COMMAND test_history_cache)
463+
set_tests_properties(history_cache PROPERTIES LABELS cpu)
464+
458465
add_executable(test_bundle_format_v1 core/runtime/tests/test_bundle_format_v1.cpp)
459466
target_include_directories(test_bundle_format_v1 PRIVATE ${PROJECT_SOURCE_DIR}/core)
460467
target_link_libraries(test_bundle_format_v1 PRIVATE trtmc_core)
@@ -552,6 +559,17 @@ if(TRTMC_BUILD_TESTS)
552559
LIBRARY_OUTPUT_DIRECTORY "${_trtmc_test_runtime_root}"
553560
)
554561

562+
add_library(trtmc_test_backend_fake_trt SHARED core/runtime/tests/fake_backend.cpp)
563+
target_include_directories(trtmc_test_backend_fake_trt PRIVATE
564+
${PROJECT_SOURCE_DIR}/core/runtime/include
565+
)
566+
target_link_libraries(trtmc_test_backend_fake_trt PRIVATE CUDA::cudart)
567+
target_compile_definitions(trtmc_test_backend_fake_trt PRIVATE TRTMC_FAKE_BACKEND_NAME="trt")
568+
set_target_properties(trtmc_test_backend_fake_trt PROPERTIES
569+
OUTPUT_NAME trtmc_backend_trt
570+
LIBRARY_OUTPUT_DIRECTORY "${_trtmc_test_runtime_root}"
571+
)
572+
555573
add_library(trtmc_test_family_fake SHARED core/runtime/tests/fake_family.cpp)
556574
target_include_directories(trtmc_test_family_fake PRIVATE ${PROJECT_SOURCE_DIR}/core/runtime/include)
557575
target_link_libraries(trtmc_test_family_fake PRIVATE trtmc_core)
@@ -571,6 +589,7 @@ if(TRTMC_BUILD_TESTS)
571589
add_dependencies(test_family_loader
572590
trtmc_test_backend_fake
573591
trtmc_test_backend_fake_rtx
592+
trtmc_test_backend_fake_trt
574593
trtmc_test_family_fake
575594
)
576595
add_custom_command(TARGET test_family_loader POST_BUILD

apps/task_runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ inline bool uses_existing_task_runtime(std::string_view primary_task) noexcept {
3333
ISpeechToolSessionProvider::kTask,
3434
IEmbedding::kTask,
3535
IEncoding::kTask,
36+
IRecommendation::kTask,
3637
IReranking::kTask,
3738
ISegmentation::kTask,
3839
IPointPromptedSegmentation::kTask,

conanfile.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import json
77
import os
8+
import shutil
89
import stat
910
import subprocess
1011
from pathlib import Path
@@ -44,6 +45,34 @@ def _make_executable(path: Path) -> None:
4445
path.chmod(path.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
4546

4647

48+
def _package_native_commands(build: Path, destinations: tuple[Path, ...]) -> None:
49+
"""Ship root-level native commands, including family-owned trtmc-* binaries."""
50+
commands = [build / "trtmc"]
51+
commands.extend(
52+
path for path in sorted(build.glob("trtmc-*")) if not path.suffix and not path.is_dir()
53+
)
54+
for command in commands:
55+
try:
56+
mode = command.lstat().st_mode
57+
if not stat.S_ISREG(mode) or not mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH):
58+
raise ConanException(f"native command is not a regular executable: {command}")
59+
with command.open("rb") as source:
60+
if source.read(4) != b"\x7fELF":
61+
raise ConanException(f"native command is not an ELF executable: {command}")
62+
for directory in destinations:
63+
directory.mkdir(parents=True, exist_ok=True)
64+
target = directory / command.name
65+
if target.exists() or target.is_symlink():
66+
raise ConanException(f"duplicate native command destination: {target}")
67+
# Copy this exact build output; recursive basename matching can
68+
# otherwise replace it with a nested target of the same name.
69+
shutil.copy2(command, target)
70+
_make_executable(target)
71+
_set_runpath(target, "$ORIGIN")
72+
except OSError as error:
73+
raise ConanException(f"cannot package native command {command}: {error}") from error
74+
75+
4776
class TensorRTModelConnectConan(ConanFile):
4877
name = "tensorrt-model-connect"
4978
version = "0.1.0"
@@ -91,8 +120,7 @@ def package(self) -> None:
91120
],
92121
check=True,
93122
)
94-
copy(self, "trtmc", src=str(build), dst=str(module_bin), keep_path=False)
95-
copy(self, "trtmc-server", src=str(build), dst=str(module_bin), keep_path=False)
123+
_package_native_commands(build, (module_bin,))
96124
for library in ("libtrtmc_core.so", "libtrtmc_runtime.so"):
97125
copy(self, library, src=str(build), dst=str(module_bin), keep_path=False)
98126
copy(
@@ -196,7 +224,7 @@ def package(self) -> None:
196224
):
197225
raise ConanException("native runtime package is incomplete")
198226

199-
for executable in (native, native_server, benchmark_worker, dataset_benchmark):
227+
for executable in (benchmark_worker, dataset_benchmark):
200228
_make_executable(executable)
201229
_set_runpath(executable, "$ORIGIN")
202230
for library in shared_runtime:

0 commit comments

Comments
 (0)