Skip to content

[Polygraphy] Add clear error for mismatched ONNX Slice input lengths (#4470) - #4862

Closed
njh1205 wants to merge 1 commit into
NVIDIA:mainfrom
njh1205:fix-4470-polygraphy-slice-length-check
Closed

njh1205 wants to merge 1 commit into
NVIDIA:mainfrom
njh1205:fix-4470-polygraphy-slice-length-check

Conversation

@njh1205

@njh1205 njh1205 commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

TensorRT's ONNX parser rejects Slice ops whose starts/ends/axes/steps have inconsistent lengths with a low-level assertion (e.g. "Assertion failed: (starts.size() == axes.size())", see #4470), which is hard to diagnose. Since the TRT ONNX parser source is closed in the OSS release, this fix lands at the Polygraphy tooling layer: NetworkFromOnnx / NetworkFromOnnxPath now validate Slice input lengths before invoking the parser and raise a clear, actionable error naming the offending node.

Changes

  • polygraphy/backend/trt/util.py: add check_onnx_slice_input_lengths() (resolves initializer / Constant-node / static-shape inputs).
  • polygraphy/backend/trt/loader.py: run the check in both ONNX import paths.
  • tests/backend/trt/test_onnx_slice_check.py: CPU-runnable regression tests (no TensorRT required).
  • CHANGELOG.md: Unreleased entry.

Validation

Fixes #4470 (tooling-layer solution; the parser itself is closed-source).

… in Polygraphy

TensorRT's ONNX parser rejects Slice ops whose starts/ends/axes/steps
have inconsistent lengths with a low-level assertion (e.g. "Assertion
failed: (starts.size() == axes.size())"). NetworkFromOnnx and
NetworkFromOnnxPath now validate Slice input lengths up front and raise
an actionable error naming the offending node.

Adds check_onnx_slice_input_lengths in backend/trt/util.py, wires it into
both ONNX import loaders, and adds CPU-runnable regression tests.

Signed-off-by: njh1205 <1979582049@qq.com>
@pranavm-nvidia

Copy link
Copy Markdown
Collaborator

Let's fix it in the ONNX parser: https://github.com/onnx/onnx-tensorrt/blob/11.3-GA/onnxOpImporters.cpp#L6406. I think the fix would be to change:

        axes = nbInputs > 3 && !inputs.at(3).isNullTensor() ? ShapeTensor(ctx, inputs.at(3))
                                                            : iotaShapeVector(dims.size());

to:

        axes = nbInputs > 3 && !inputs.at(3).isNullTensor() ? ShapeTensor(ctx, inputs.at(3))
                                                            : iotaShapeVector(starts.size());

(which is already the behavior of the else branch).

@njh1205

njh1205 commented Sep 29, 2026

Copy link
Copy Markdown
Author

Parser-level fix now in place: onnx/onnx-tensorrt#1064 (11.3-GA) and #1065 (8.5-GA). See those PRs for the one-line parser fix and the regression test; closing this Polygraphy pre-check workaround in favor of the parser fix.

@njh1205 njh1205 closed this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The onnx parser failed to parse a valid model: Slice (importSlice): INVALID_NODE: Assertion failed: (starts.size() == axes.size())

3 participants