TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

🐛 [Bug] SIGSEGV in torch.compile(backend='tensorrt') on Jetson Thor (aarch64, CUDA 13) — enqueueV3 reports unset output tensor address

Open potoior opened this issue 1 month ago • 4 comments

Description

torch.compile(..., backend="tensorrt") crashes the entire process with SIGSEGV (exit code 139) on Jetson AGX Thor (aarch64, CUDA 13) when compiling a large partitioned transformer (~1.3B video-diffusion DiT). Right before the crash, the TensorRT runtime logs an API usage error indicating that an output tensor address was never bound:

ERROR: [Torch-TensorRT] - IExecutionContext::enqueueV3: Error Code 3: API Usage Error (Parameter check failed, condition: mContext.profileObliviousBindings.at(profileObliviousIndex) || getPtrOrNull(mOutputAllocators, profileObliviousIndex). Neither address or allocator is set for output tensor output5. Call setOutputTensorAddress, setTensorAddress or setOutputAllocator before enqueue/execute. In enqueueV3 at /_src/runtime/api/executionContext.cpp:2864)

The error appears twice, then the process dies with Segmentation fault (core dumped). No Python-level exception is raised — the crash is not catchable from Python and takes down the whole hosting application.

Environment

Component Version
Hardware NVIDIA Jetson AGX Thor (T5000), 128 GB unified memory
OS Ubuntu 24.04, JetPack 7.2.1 (L4T R39.2.1)
CUDA 13.0 (torch +cu130 build)
Python 3.12
PyTorch 2.12.1+cu130 (official aarch64 wheel from PyPI)
torch-tensorrt 2.12.1
TensorRT 10.16.1.11 (tensorrt_cu13 wheels, pulled by torch-tensorrt)

Model & invocation

The model is the EchoMimicV3 flash-pro DiT (open source: antgroup/echomimic_v3, entry point infer_flash.py) — a ~1.3B video diffusion transformer derived from Wan2.1-Fun-V1.1-1.3B-InP, with spatiotemporal self-attention plus audio cross-attention conditioning. Sequence length ~26k tokens per forward (20fps bucket); the input signature includes a nested tuple context=(prompt_embeds, audio_embeds, frame_count_int, None).

transformer = torch.compile(
    transformer,
    backend="tensorrt",
    options={"enabled_precisions": [torch.float16], "truncate_double": True},
)

truncate_double=True is required because the model's RoPE frequency table contains float64 constants — without it, conversion fails with ValueError: TensorRT does not support float64 (double) precision. That error and its documented remedy work as intended (not the bug being reported here).

Steps to reproduce

  1. On Jetson AGX Thor with the environment above: pip install torch-tensorrt==2.12.1 (pulls tensorrt 10.16.1.11 cu13 wheels).
  2. Wrap the DiT with the torch.compile call shown above.
  3. Run the standard denoising loop (5 steps; each step calls the compiled module twice for conditional/unconditional CFG).
  4. Dynamo tracing and partitioning appear to proceed (conversion warnings stream for several minutes), then the two enqueueV3 errors above are logged, and the process terminates with SIGSEGV (exit 139) before any denoising step completes (progress stays at 0/5).

We are working on reducing a minimal standalone reproducer — the signature suggests a partitioned subgraph with ≥6 outputs (output5) where the runtime fails to bind an output address before enqueueV3. The full model context is open source (weights on ModelScope/HF: BadToBest/EchoMimicV3, base PAI/Wan2.1-Fun-V1.1-1.3B-InP); happy to provide the exact command line and patches if useful.

Controls on the same machine

  • Small-model probe (3-layer MLP → FP16 engine via the same backend="tensorrt" + same options): engine builds, executes, and matches eager numerics. The base aarch64/CUDA-13 TRT path works.
  • Same DiT with the default inductor backend (torch.compile(transformer, dynamic=False)): dynamo captures cleanly (27/28 subgraphs) and runs fine — no crash.
  • So the failure is specific to the tensorrt backend with this large partitioned graph on this platform.

Secondary issue: torchao pulled in at install time

pip install torch-tensorrt==2.12.1 also installs torchao==0.18.0 into an environment that did not previously have it. With torchao present, import diffusers (0.33.1) then fails with:

NameError: name 'logger' is not defined
  File ".../diffusers/quantizers/torchao/torchao_quantizer.py", line 91, in _update_torch_safe_globals

Uninstalling torchao fixes the import, and torch-tensorrt works fine without it (only the usual "Unable to import quantization op ... modelopt" optional-dependency warnings). It looks like the torchao dependency could be made optional or version-constrained to avoid breaking unrelated libraries in the same environment.

Logs

Tail of the run log:

0%|          | 0/5 [00:00<?, ?it/s]
... (conversion warnings for several minutes) ...
WARNING:torch_tensorrt.dynamo.conversion.converter_utils:Detected unparsable type in node formatting: <class 'NoneType'>
WARNING:torch_tensorrt.dynamo.conversion.converter_utils:Detected unparsable type in node formatting: <class 'NoneType'>
WARNING:torch_tensorrt.dynamo.conversion.converter_utils:Detected unparsable type in node formatting: <class 'NoneType'>
Segmentation fault (core dumped)

Process exit code: 139 (SIGSEGV).

Expected behavior

Either a successful engine build/execution, or a Python-level exception raised by the partitioner/runtime. A native crash that kills the hosting process makes the tensorrt backend unusable for this class of models on Jetson Thor.

potoior avatar Nov 03 '26 09:11 potoior

Update — further root-cause narrowing (from the same repro environment):

  1. Pure-Python runtime control: reran with use_python_runtime=True (which routes execution through dynamo/runtime/_PythonTorchTensorRTModule instead of the C++ runtime module). Identical failure: same two enqueueV3 errors + SIGSEGV (exit 139). So the crash is not in the C++ runtime wrapper — both independent execution paths die identically.

  2. Instrumentation result: we instrumented _PythonTorchTensorRTModule at the deserialize_cuda_engine call site to dump the engine's actual output tensor list vs. the output_binding_names passed by the converter. The instrumentation never fired — the process crashes before any partition module is ever instantiated, while converter warnings are still streaming.

  3. Conclusion: the failing enqueueV3 invocation happens during engine build, not at inference time. The most likely mechanism: the failing subgraph contains data-dependent-shape (DDS) operators, which in TRT 10+ cause the builder to perform a build-time engine execution for shape inference. That build-time execution hits the unset-output-binding condition (the output5 error), then crashes natively. This would also explain why a small static-shaped MLP compiles and runs fine on the same machine.

The model does contain shape-dynamic elements (variable audio length → variable frame count), and the runtime module signature includes requires_output_allocator / symbolic_shape_expressions fields for exactly such cases — suggesting the build-time DDS execution path is worth scrutiny on aarch64 / CUDA 13.

Happy to run any additional instrumentation you'd like on this hardware.

potoior avatar Nov 03 '26 10:11 potoior

Update 2 — gdb backtrace confirms the crash is entirely inside libnvinfer (TRT core)

We re-ran the repro under gdb (batch mode). The process dies with SIGSEGV and the backtrace shows all 30 frames inside libnvinfer.so.10 (from tensorrt_libs wheel) — no Python frames, no libtorchtrt frames, no libtorch frames anywhere near the crash:

#0  0x...62fc in ?? () from .../tensorrt_libs/libnvinfer.so.10
#1  0x...38f0 in ?? () from .../tensorrt_libs/libnvinfer.so.10
... (frames 2-29, all libnvinfer.so.10) ...
#29 0x...077c in ?? () from .../tensorrt_libs/libnvinfer.so.10

(The two enqueueV3 "output tensor address not set" API-usage errors appear just before the crash, and the crash happens during the build phase — before any partition module is ever instantiated, per instrumentation of _PythonTorchTensorRTModule.setup_engine which never fires.)

This confirms the fault is in the TensorRT 10.16.1.11 (cu13, aarch64) builder's internal execution path, not in the torch-tensorrt integration layer. Repro environment: Jetson AGX Thor / JetPack 7.2.1 / CUDA 13.0 / torch 2.12.1+cu130 / torch-tensorrt 2.12.1, model context as described above.

Happy to share the full gdb log or run any further instrumentation you need on this hardware.

potoior avatar Nov 03 '26 10:11 potoior

@micwill755 can you take a look?

narendasan avatar Nov 06 '26 00:11 narendasan

Reproduced on Thor (aarch64, CUDA 13.0) with the exact stack from the report: torch 2.12.1+cu130, torch-tensorrt 2.12.1, TensorRT 10.16.1.11 (cu13 wheels). I used the real WanTransformerAudioMask3DModel from antgroup/echomimic_v3 (flash-pro config, random fp16 weights) with the pipeline's call signature. At full scale (30 layers, 25,344 tokens per forward) I get the same two enqueueV3 "output5" errors followed by SIGSEGV (exit 139). It also reproduces with just 2 layers and a 768-token sequence.

There are two independent problems, and the enqueueV3 errors are not the cause of the crash.

1. The segfault is a TensorRT 10.16 builder bug (two IAttentionLayers with constant-scaled Q)

The crash happens in builder.build_engine_with_config for the partition containing WanI2VCrossAttentionAudio + FFN. I reduced it to a script that uses only the TensorRT API, with no torch or torch-tensorrt:

import numpy as np, tensorrt as trt

builder = trt.Builder(trt.Logger(trt.Logger.WARNING))
net = builder.create_network(1 << int(trt.NetworkDefinitionCreationFlag.STRONGLY_TYPED))
H, D, f16 = 12, 128, trt.float16
q = net.add_input("q", f16, (1, H, 768, D))
k1, v1 = net.add_input("k1", f16, (1, H, 512, D)), net.add_input("v1", f16, (1, H, 512, D))
k2, v2 = net.add_input("k2", f16, (1, H, 257, D)), net.add_input("v2", f16, (1, H, 257, D))

def attn(k, v):
    s = net.add_constant((1, 1, 1, 1), trt.Weights(np.array([D ** -0.5], dtype=np.float16))).get_output(0)
    sq = net.add_elementwise(q, s, trt.ElementWiseOperation.PROD).get_output(0)
    layer = net.add_attention(sq, k, v, trt.AttentionNormalizationOp.SOFTMAX, False)
    layer.decomposable = True
    return layer.get_output(0)

out = net.add_elementwise(attn(k1, v1), attn(k2, v2), trt.ElementWiseOperation.SUM).get_output(0)
net.mark_output(out)
builder.build_serialized_network(net, builder.create_builder_config())  # SIGSEGV on 10.16.1.11
Variant Result on TRT 10.16.1.11
two attention layers, constant scale on Q SIGSEGV
one attention layer, constant scale builds
two attention layers, scale as a runtime input builds
two attention layers, no scale builds

Whether Q is shared between the two attentions doesn't matter. On the torch-tensorrt side, this pattern comes from the _scaled_dot_product_flash_attention converter when scale is not None: get_trt_tensor(ctx, scale, ...) creates a constant that is multiplied into Q before add_attention. When scale is None, the factor is computed from a shape layer and the build succeeds. In this model, the three cross-attentions (text, CLIP image, audio) all reach the converter with an explicit scale.

I couldn't compare against TRT 10.14.1.31, because its addAttention rejects a second attention layer in the same network. I also haven't checked whether the bug is specific to Thor/aarch64.

Workaround: options={"decompose_attention": True, ...}. With it, the full model compiles and runs all 5 denoising steps. Outputs match eager (output mean 0.6319 vs 0.6320 at step 0), and each step takes about 5.8 s vs 10.5 s in eager.

2. The enqueueV3 "output5" errors come from a zero-size engine output

These errors are printed while an engine that has already been built is executing, not during an engine build. rope_apply does torch.cat([x_i, x[i, seq_len:]]), and seq_len equals the full length, so x[i, seq_len:] is empty. A graph break at grid_sizes.tolist() turns that empty tensor into an engine output with shape (0, 12, 128), which is output5. Its data_ptr() is null, so TRT rejects the binding. rope_apply runs once for q and once for k, which gives exactly two errors. The outputs are still correct because the tensor is empty. Even so, the runtime should handle zero-volume outputs, for example by binding a dummy non-null address or skipping them. Guarding the cat with if seq_len < x.size(1) in the model removes the errors.

Secondary: torchao / diffusers

I reproduced this too. The NameError is a diffusers 0.33.1 bug: _update_torch_safe_globals uses logger before it's defined. torchao 0.18 only triggers that code path. Still, torch-tensorrt making torchao an optional dependency would avoid the problem.

I have filed a bug with TensorRT to investigate further.

micwill755 avatar Nov 06 '26 03:11 micwill755