Skip to content

Incorrect CumSum outputs since TensorRT 10.8+ #4551

Open

Description

@toothache

Description

I've been working on upgrading TensorRT version recently but observed significant accuracy drops for one of our ONNX model. After investigation, we identified the issue is caused by the CumSum layers. Specifically, when multiple CumSum layers coexist inside the model, some CumSum outputs appear incorrect - as if they're operating on the same axis even though they're configured on different axes.

I tried several different TensorRT versions, and the issue affects TensorRT 10.8 and above.

I have already submitted an issue at onnx_tensorrt repo. However, I suspect the root cause may lie within the ICumulativeLayer since constructing a TensorRT network using TensorRT python API still repro the issue (See the test script below).

Environment

TensorRT Version: 10.11.0.33

NVIDIA GPU: A10

NVIDIA Driver Version: 550.144.06

CUDA Version: 12.9

CUDNN Version: 9.10.2

Operating System:

Python Version (if applicable):

Tensorflow Version (if applicable):

PyTorch Version (if applicable):

Baremetal or Container (if so, version): nvcr.io/nvidia/tensorrt::25.06-py3

Relevant Files

Model link:
I can repro for both ONNX models and TRT engines.

Steps To Reproduce

Commands or scripts:


import tensorrt as trt
import numpy as np
import torch


def create_cumsum_engine(input_shape=(4, 2)):
    """Create TensorRT engine with cumsum operations using add_cumulative layer"""
    logger = trt.Logger(trt.Logger.WARNING)

    builder = trt.Builder(logger)
    network = builder.create_network(0)

    # Input tensor
    input_tensor = network.add_input("data", trt.float32, input_shape)

    # Create scalar axis tensors for cumulative operations (must be 0D/scalar)
    axis_0_tensor = network.add_constant(shape=(), weights=np.array(0, dtype=np.int32))
    axis_1_tensor = network.add_constant(shape=(), weights=np.array(1, dtype=np.int32))

    # Add cumulative layer for axis=0
    cumulative_0 = network.add_cumulative(
        input_tensor,
        axis_0_tensor.get_output(0),
        trt.CumulativeOperation.SUM,
        exclusive=False,
        reverse=False,
    )
    output_0 = cumulative_0.get_output(0)

    # Add cumulative layer for axis=1
    cumulative_1 = network.add_cumulative(
        input_tensor,
        axis_1_tensor.get_output(0),
        trt.CumulativeOperation.SUM,
        exclusive=False,
        reverse=False,
    )
    output_1 = cumulative_1.get_output(0)

    # Mark outputs
    network.mark_output(output_0)
    network.mark_output(output_1)
    output_0.name = "cumsum_axis_0"
    output_1.name = "cumsum_axis_1"

    # Build engine
    config = builder.create_builder_config()
    config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, 1 << 20) # 1 MiB
    serialized_engine = builder.build_serialized_network(network, config)

    runtime = trt.Runtime(logger)
    engine = runtime.deserialize_cuda_engine(serialized_engine)
    return engine


def run_tensorrt_inference(engine, input_tensor: torch.tensor):
    """Run inference using TensorRT engine"""
    context = engine.create_execution_context()

    # Set tensor addresses for v3 API
    context.set_tensor_address("data", input_tensor.data_ptr())

    # Allocate output tensors as torch CUDA tensors
    output_0_tensor = torch.empty_like(input_tensor)
    output_1_tensor = torch.empty_like(input_tensor)

    context.set_tensor_address("cumsum_axis_0", output_0_tensor.data_ptr())
    context.set_tensor_address("cumsum_axis_1", output_1_tensor.data_ptr())

    # Run inference
    context.execute_async_v3(stream_handle=0)

    # Copy outputs back to CPU numpy arrays
    output_0 = output_0_tensor.cpu().numpy()
    output_1 = output_1_tensor.cpu().numpy()

    return output_0, output_1


def test_cumsum_implementations():
    """Test and compare different cumsum implementations"""
    print("Testing cumsum implementations...")

    # Test data
    input_shape = (4, 2)
    test_data = np.ones(input_shape, dtype=np.float32)

    print(f"Input data:\n{test_data}\n")

    # NumPy reference
    np_cumsum_0 = np.cumsum(test_data, axis=0)
    np_cumsum_1 = np.cumsum(test_data, axis=1)

    print("NumPy cumsum axis=0:")
    print(np_cumsum_0)
    print("\nNumPy cumsum axis=1:")
    print(np_cumsum_1)

    # Test TensorRT implementation with add_cumulative
    print("\n" + "=" * 50)
    print("Testing TensorRT add_cumulative approach...")

    engine = create_cumsum_engine(input_shape)
    test_tensor = torch.from_numpy(test_data).float().cuda()
    trt_out_0, trt_out_1 = run_tensorrt_inference(engine, test_tensor)

    print("TensorRT cumsum axis=0:")
    print(trt_out_0)
    print("\nTensorRT cumsum axis=1:")
    print(trt_out_1)


if __name__ == "__main__":
    test_cumsum_implementations()

Output:

> python cumsum_tensorrt_simple.py
Testing cumsum implementations...
Input data:
[[1. 1.]
 [1. 1.]
 [1. 1.]
 [1. 1.]]

NumPy cumsum axis=0:
[[1. 1.]
 [2. 2.]
 [3. 3.]
 [4. 4.]]

NumPy cumsum axis=1:
[[1. 2.]
 [1. 2.]
 [1. 2.]
 [1. 2.]]

==================================================
Testing TensorRT add_cumulative approach...
[08/12/2025-07:03:05] [TRT] [W] Using default stream in enqueueV3() may lead to performance issues due to additional calls to cudaStreamSynchronize() by TensorRT to ensure correct synchronization. Please use non-default stream instead.
TensorRT cumsum axis=0:
[[1. 2.]
 [1. 2.]
 [1. 2.]
 [1. 2.]]

TensorRT cumsum axis=1:
[[1. 2.]
 [1. 2.]
 [1. 2.]
 [1. 2.]]

Have you tried the latest release?: No. The latest version I tried is TRT 10.11.

Can this model run on other frameworks? For example run ONNX model with ONNXRuntime (polygraphy run <model.onnx> --onnxrt):

Activity

  1. added
    Module:ONNX
    on Aug 12, 2025
  2. changed the title [-]Incorrect CumSum outputs since TensorRT 12.8[/-] [+]Incorrect CumSum outputs since TensorRT 10.8[/+] on Aug 12, 2025
  3. changed the title [-]Incorrect CumSum outputs since TensorRT 10.8[/-] [+]Incorrect CumSum outputs since TensorRT 10.8+[/+] on Aug 12, 2025
  4. self-assigned this
    on Aug 14, 2025
  5. added
    triaged
    Module:Accuracy
    internal-bug-tracked
    on Aug 14, 2025
  6. kevinch-nv commented on Aug 14, 2025

    @kevinch-nv
    Collaborator

    Thanks, I was able to repro. We are investigating internally.

  7. toothache commented on Sep 23, 2025

    @toothache
    Author

    @kevinch-nv , any update for the fix? Thanks!

  8. lmarshall12 commented on Jan 26, 2026

    @lmarshall12

    @kevinch-nv an update on this would also be appreciated, this is stopping us from using tensorrt completely.

  9. whateverforever commented on Jul 3, 2026

    @whateverforever

    cough

  10. ervinyoung9025 commented on Sep 8, 2026

    @ervinyoung9025

    you can use tensorrt 11.2. I have already tried this, and fixed the same problem

  11. kvnloo commented on Sep 28, 2026

    @kvnloo

    There is a recent report that TensorRT 11.2 may no longer reproduce this.

    It would be useful to rerun the exact minimal two-CumSum network across:

    • one known affected version such as 10.11;
    • 11.1;
    • 11.2/current.

    For each version, compare both outputs against a NumPy or PyTorch reference for axis 0 and axis 1.

    If 11.2 is consistently correct, documenting the first fixed version here would help users currently pinned to older TRT releases and may let this issue be closed without further OSS work.

    I would keep the exact same engine/network construction across all versions so the result is a clean version-boundary check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Module:AccuracyModule:ONNXinternal-bug-trackedtriaged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions