From 80f2e04e9acc33e0a882a77fc97bb965b74be35b Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Sat, 8 Aug 2026 14:44:33 -0700 Subject: [PATCH 1/2] fix: build against TensorRT older than 10.15 Building Torch-TensorRT against TensorRT 10.13 or older fails to compile: core/runtime/TRTEngine.cpp:298: error: 'class nvinfer1::ICudaEngine' has no member named 'getAliasedInputTensor' That API was added in TensorRT 10.15, together with the IKVCacheUpdateLayer that produces the aliasing it reports. The runtime calls it unconditionally, while the package declares a bare tensorrt dependency with no minimum version, so an older TensorRT produces a compile error rather than a clear message. The call only reconciles the build-time aliased I/O map against what the engine reports. On older TensorRT there is nothing to reconcile against, so the build-time map stands on its own and the reconciliation is skipped. Gate it with a direct version check at the point of use, matching how the ScatterAdd plugin include is gated in core/plugins/register_plugins.cpp. --- core/runtime/TRTEngine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/runtime/TRTEngine.cpp b/core/runtime/TRTEngine.cpp index fb96628ec5..b8b711375e 100644 --- a/core/runtime/TRTEngine.cpp +++ b/core/runtime/TRTEngine.cpp @@ -292,6 +292,10 @@ TRTEngine::TRTEngine( // engines built outside Torch-TensorRT). User-declared aliases (kind=kUser) // are preserved as-is since TRT doesn't know about them. this->aliased_io = aliased_io; +// ICudaEngine::getAliasedInputTensor is not available before TRT 10.15 (e.g. Jetpack +// L4T builds), where an engine cannot report its aliasing and the build-time map is +// the only source of truth. +#if NV_TENSORRT_MAJOR > 10 || (NV_TENSORRT_MAJOR == 10 && NV_TENSORRT_MINOR >= 15) for (const auto& out_name : this->out_binding_names) { // TRT returns nullptr / empty string for non-aliased outputs; any thrown // exception is a real error in the engine state and propagates. @@ -315,6 +319,7 @@ TRTEngine::TRTEngine( it->second = AliasedIOSpec{std::string(aliased_in), AliasKind::kKVCacheUpdate}; } } +#endif // Precompute the set of input binding names that are the alias source of some // output (for the O(1) per-call membership test) and validate every aliased From 9bce699cff6e1109b999ee158857cdecf022959f Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Sat, 8 Aug 2026 16:03:21 -0700 Subject: [PATCH 2/2] fix: fall back when TensorRT has no KV-cache update layer Exporting a model with a KV cache on TensorRT 10.13 or older fails with: AttributeError: module 'tensorrt' has no attribute 'KVCacheMode' add_kv_cache_update and KVCacheMode were added in TensorRT 10.15. The KV fast path calls both unconditionally, and the validator that gates it checks only graph shape, so a qualifying graph reaches the call on any TensorRT version. This one is worse than a compile error: it surfaces during export and reads like a bug in the user's model rather than a version gap. emit_kv_cache_update_layer already returns None to mean "fast path unavailable", and its callers fall back to the general scatter, so check for the API and take that existing path instead of raising. --- .../dynamo/conversion/impl/slice_scatter.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/py/torch_tensorrt/dynamo/conversion/impl/slice_scatter.py b/py/torch_tensorrt/dynamo/conversion/impl/slice_scatter.py index c277a4ca6b..579fee0429 100644 --- a/py/torch_tensorrt/dynamo/conversion/impl/slice_scatter.py +++ b/py/torch_tensorrt/dynamo/conversion/impl/slice_scatter.py @@ -97,6 +97,16 @@ def emit_kv_cache_update_layer( logger.debug("KV cache update: skipped — input is not a direct network input") return None + # add_kv_cache_update and KVCacheMode do not exist before TensorRT 10.15 (e.g. + # Jetpack L4T builds). Returning None here takes the caller's existing fallback + # instead of raising AttributeError, which reads like a bug in the model. + if not hasattr(ctx.net, "add_kv_cache_update") or not hasattr(trt, "KVCacheMode"): + logger.debug( + "KV cache update: skipped, this TensorRT build has no " + "KV-cache update layer" + ) + return None + layer = ctx.net.add_kv_cache_update( cache, src, write_indices, trt.KVCacheMode.LINEAR )