Skip to content

fix: fall back to PyTorch for ops TensorRT-RTX cannot serve on Turing (SM 7.5) - #4546

Closed
tp5uiuc wants to merge 1 commit into
pytorch:mainfrom
tp5uiuc:fix/tensorrt-rtx-turing-capability-guards
Closed

fix: fall back to PyTorch for ops TensorRT-RTX cannot serve on Turing (SM 7.5)#4546
tp5uiuc wants to merge 1 commit into
pytorch:mainfrom
tp5uiuc:fix/tensorrt-rtx-turing-capability-guards

Conversation

@tp5uiuc

Copy link
Copy Markdown
Collaborator

Description

TensorRT-RTX supports SM 7.5 and up, but its support matrix states that on Turing it "does not support FP32 GEMMs and 3D convolutions in this release", and Turing has no bfloat16 hardware. Torch-TensorRT had no notion of this and handed those ops to TensorRT-RTX anyway. Observed on a Turing GPU:

  • FP32 GEMM, dynamic shapes — the engine builds, runs, and returns an all-zero tensor of the correct shape and dtype, with no exception and no NaN. This is the motivating case: it is silent, so the user gets plausible-looking output that is entirely wrong.
  • FP32 GEMM, static shapes — createExecutionContext() returns null.
  • 3D convolution — same null execution context.
  • bfloat16 — segmentation fault.

How

  • _utils.py: get_target_compute_capabilities() / trt_rtx_targets_turing(). Guards key off the capabilities being built for, not the build host — querying the local device would bake the build machine into an ahead-of-time artifact.
  • aten_ops_converters.py: gemm_capability_validator on matmul/mm/bmm/dot/mv/addmm (fp32 operands only, so fp16 with use_fp32_acc is unaffected); 3D convolution rejected in convolution_capability_validator — forward only, since transposed 3D works on Turing.
  • partitioning/: bfloat16 gated in both partitioners rather than per-converter, as the crash is not operator-specific. Mirrors the existing complex-dtype handling.
  • _settings.py / _defaults.py / _compiler.py: new target_compute_capabilities option on all three compile entry points, added to _SETTINGS_TO_BE_ENGINE_INVARIANT so a cached engine built for different targets is never reused.
  • _TRTInterpreter.py: the same list drives setComputeCapability(), so partitioning and engine targeting cannot drift apart.
  • Tests: skip_if_trt_rtx_turing() in the conversion harness, applied to the affected matmul, cdist (p == 2), convolution (3D) and binary-op (bf16) tests.

Testing

On a Turing GPU all four cases now fall back to PyTorch and produce correct results (cosine 1.000000), while fp16 GEMM, transposed 3D convolution and 2D convolution still run on TensorRT. On an SM 8.9 GPU behaviour is unchanged by default, and compiling with target_compute_capabilities=[(7, 5)] reproduces Turing's partitioning — so this is testable without Turing hardware. Affected conversion suites: 121 passed, 57 skipped, 0 failed (previously 23 failures).

Notes for reviewers

  • On Turing, fp32 GEMMs now run in PyTorch. Some fp32 GEMM shapes do execute correctly on Turing today, so this guard is deliberately broader than strictly necessary — the documented contract says unsupported, and the failure mode when it does bite is silent wrong answers. Happy to narrow it if you prefer.
  • Guards read meta["val"], as other validators in this module do. Converter unit tests build graphs with empty node meta, so validators cannot fire there at all; those tests skip explicitly instead.
  • Includes one unrelated one-line change: a pre-existing untyped return in _settings.py is bound to a typed local, because that file is now in the changed set and --strict mypy blocks the commit on it.
  • No behaviour change on any architecture other than Turing.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

TensorRT-RTX supports SM 7.5 and up, but its support matrix states that on
Turing it does not support FP32 GEMMs or 3D convolutions, and Turing has no
bfloat16 hardware at all. Torch-TensorRT had no notion of this and handed
those ops to TensorRT-RTX anyway. On a Turing GPU that produces:
- FP32 GEMM, static shapes: createExecutionContext() returns null
- FP32 GEMM, dynamic shapes: the engine builds and runs, returning an
all-zero tensor of the correct shape and dtype, with no exception
- 3D convolution: null execution context
- bfloat16: segmentation fault
The dynamic-shape GEMM case is the motivating one, since it fails silently.
Guards key off the compute capabilities being built for rather than the build
host, via a new target_compute_capabilities option, so an ahead-of-time build
for another architecture partitions correctly instead of baking in the build
machine's capabilities. The same list drives setComputeCapability(), keeping
partitioning and engine targeting consistent, and is engine-invariant so a
cached engine built for different targets is never reused.
The convolution guard covers forward 3D convolution only; transposed 3D
convolution works on Turing and is left on TensorRT. The GEMM guard keys on
fp32 operands, so fp16 GEMMs accumulating in fp32 are unaffected.
bfloat16 is gated in the partitioners rather than per-converter because the
crash is not operator-specific, mirroring the existing complex-dtype handling.
Converter unit tests build graphs with empty node meta, so dtype-based
capability validators cannot fire there; the affected tests skip explicitly.
Also binds one pre-existing untyped return in _settings.py to a typed local:
that file is now in the changed set, so --strict mypy blocks the commit on it.
@github-actionsgithub-actionsBot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Aug 21, 2026
@tp5uiuc

Copy link
Copy Markdown
CollaboratorAuthor

Closing in favour of a reviewable series. This PR was one commit; the work it started grew to
cover nine root causes, and reviewing that as a single diff is not reasonable.

Replaced by six PRs. Three are not Turing bugs at all — they reproduce on an L40S with
torch_executed_ops and are live for every user today:

PRwhat
#4647mutable module strands PyTorch-executed weights on the CPU
#4648save(retrace=False) raises on a fully-fallback graph

The Turing work is a stack, based on #4643:

PRwhat
#4643capability guards + compute-capability targeting — this PR's content, plus the gaps found since
#46443D convolution hidden from the guard by the pad-folding pass
#4645the GEMM cdist emits internally
#4646FP32 GEMMs reaching TensorRT-RTX through linear and attention

Three things found after this PR was opened are folded into #4643 rather than shipped as
follow-ups, because they repair code this PR introduced and a reviewer should not have to read
past a bug to reach the fix:

  • the addmm guard here fired with no matching test skip, turning 11 green Turing tests red;
  • the compute capability was gated on a falsy check, so the default declared nothing and
    num_compute_capabilities stayed 0 — that one resolution bug accounts for 42 of the 91
    original Turing failures;
  • bfloat16 was gated at the partitioner, which converter unit tests bypass.

Verified at the series tip on a T4 (SM 7.5) and an L40S (SM 8.9), driver-matched, all six test
modules: T4 2668 passed / 17 failed / 226 skipped; L40S 2780 / 13 / 118; 2911 collected each.
The L40S shows no status change anywhere — every guard is inert off Turing.

Not fixed: 5 models/ cosine-similarity failures on Turing (0.9862–0.9872 against a 0.99
threshold). They compile fully to TensorRT with no capability fallback logged, so the guards are
ruled out, and they predate this branch. Not diagnosed.

@tp5uiuctp5uiuc closed this Aug 29, 2026
tp5uiuc added a commit that referenced this pull request Aug 29, 2026
impl.normalization.cdist_forward computes p == 2 with a matrix-multiply layer for
compute_mode 1, or 0/absent with an operand above the row threshold. That GEMM is
emitted inside the converter, so the graph holds a single _cdist_forward node and
no mm/bmm for gemm_capability_validator to reject, and on Turing TensorRT-RTX
fails cuDNN graph compilation with "No valid engine configs for
Matmul_MUL_SUB_SQRT_", leaving a null execution context.
Zero tests were failing: PR #4546 skipped the covering tests rather than guarding
the converter, so nothing was red while the conversion path stayed open. A skip
protects CI; it does not protect a caller.
Which arguments emit a GEMM is decided by cdist_emits_matmul, the predicate
cdist_forward itself uses, so the guard cannot drift from the branch it mirrors.
Unlike gemm_capability_validator this is deliberately not dtype-keyed: measured on
a T4 the fused pattern fails for FP16 operands too, so what predicts failure is
whether the matmul layer is emitted, not its precision. The row threshold is
load-bearing rather than an optimisation -- below it no GEMM is emitted, and
rejecting anyway would regress, since PyTorch's cdist_cuda has no Half kernel.
One behaviour note: where exactly one operand's row count is statically known and
exceeds the threshold, the shared predicate rejects, whereas reading the shapes
directly would have failed open. Rejecting is correct -- the converter's condition
is an or, so a single known operand above the threshold already decides it. The
case is unreachable today because the converter is not registered
supports_dynamic_shapes, so the partitioner refuses a partially dynamic cdist
first.
tp5uiuc added a commit that referenced this pull request Aug 30, 2026
impl.normalization.cdist_forward computes p == 2 with a matrix-multiply layer for
compute_mode 1, or 0/absent with an operand above the row threshold. That GEMM is
emitted inside the converter, so the graph holds a single _cdist_forward node and
no mm/bmm for gemm_capability_validator to reject, and on Turing TensorRT-RTX
fails cuDNN graph compilation with "No valid engine configs for
Matmul_MUL_SUB_SQRT_", leaving a null execution context.
Zero tests were failing: PR #4546 skipped the covering tests rather than guarding
the converter, so nothing was red while the conversion path stayed open. A skip
protects CI; it does not protect a caller.
Which arguments emit a GEMM is decided by cdist_emits_matmul, the predicate
cdist_forward itself uses, so the guard cannot drift from the branch it mirrors.
Unlike gemm_capability_validator this is deliberately not dtype-keyed: measured on
a T4 the fused pattern fails for FP16 operands too, so what predicts failure is
whether the matmul layer is emitted, not its precision. The row threshold is
load-bearing rather than an optimisation -- below it no GEMM is emitted, and
rejecting anyway would regress, since PyTorch's cdist_cuda has no Half kernel.
One behaviour note: where exactly one operand's row count is statically known and
exceeds the threshold, the shared predicate rejects, whereas reading the shapes
directly would have failed open. Rejecting is correct -- the converter's condition
is an or, so a single known operand above the threshold already decides it. The
case is unreachable today because the converter is not registered
supports_dynamic_shapes, so the partitioner refuses a partially dynamic cdist
first.
tp5uiuc added a commit that referenced this pull request Aug 30, 2026
impl.normalization.cdist_forward computes p == 2 with a matrix-multiply layer for
compute_mode 1, or 0/absent with an operand above the row threshold. That GEMM is
emitted inside the converter, so the graph holds a single _cdist_forward node and
no mm/bmm for gemm_capability_validator to reject, and on Turing TensorRT-RTX
fails cuDNN graph compilation with "No valid engine configs for
Matmul_MUL_SUB_SQRT_", leaving a null execution context.
Zero tests were failing: PR #4546 skipped the covering tests rather than guarding
the converter, so nothing was red while the conversion path stayed open. A skip
protects CI; it does not protect a caller.
Which arguments emit a GEMM is decided by cdist_emits_matmul, the predicate
cdist_forward itself uses, so the guard cannot drift from the branch it mirrors.
Unlike gemm_capability_validator this is deliberately not dtype-keyed: measured on
a T4 the fused pattern fails for FP16 operands too, so what predicts failure is
whether the matmul layer is emitted, not its precision. The row threshold is
load-bearing rather than an optimisation -- below it no GEMM is emitted, and
rejecting anyway would regress, since PyTorch's cdist_cuda has no Half kernel.
One behaviour note: where exactly one operand's row count is statically known and
exceeds the threshold, the shared predicate rejects, whereas reading the shapes
directly would have failed open. Rejecting is correct -- the converter's condition
is an or, so a single known operand above the threshold already decides it. The
case is unreachable today because the converter is not registered
supports_dynamic_shapes, so the partitioner refuses a partially dynamic cdist
first.
tp5uiuc added a commit that referenced this pull request Aug 30, 2026
impl.normalization.cdist_forward computes p == 2 with a matrix-multiply layer for
compute_mode 1, or 0/absent with an operand above the row threshold. That GEMM is
emitted inside the converter, so the graph holds a single _cdist_forward node and
no mm/bmm for gemm_capability_validator to reject, and on Turing TensorRT-RTX
fails cuDNN graph compilation with "No valid engine configs for
Matmul_MUL_SUB_SQRT_", leaving a null execution context.
Zero tests were failing: PR #4546 skipped the covering tests rather than guarding
the converter, so nothing was red while the conversion path stayed open. A skip
protects CI; it does not protect a caller.
Which arguments emit a GEMM is decided by cdist_emits_matmul, the predicate
cdist_forward itself uses, so the guard cannot drift from the branch it mirrors.
Unlike gemm_capability_validator this is deliberately not dtype-keyed: measured on
a T4 the fused pattern fails for FP16 operands too, so what predicts failure is
whether the matmul layer is emitted, not its precision. The row threshold is
load-bearing rather than an optimisation -- below it no GEMM is emitted, and
rejecting anyway would regress, since PyTorch's cdist_cuda has no Half kernel.
One behaviour note: where exactly one operand's row count is statically known and
exceeds the threshold, the shared predicate rejects, whereas reading the shapes
directly would have failed open. Rejecting is correct -- the converter's condition
is an or, so a single known operand above the threshold already decides it. The
case is unreachable today because the converter is not registered
supports_dynamic_shapes, so the partitioner refuses a partially dynamic cdist
first.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signedcomponent: api [Python]Issues re: Python APIcomponent: conversionIssues re: Conversion stagecomponent: coreIssues re: The core compilercomponent: dynamoIssues relating to the `torch.compile` or `torch._dynamo.export` pathscomponent: testsIssues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@tp5uiuc