Reject sessions whose provider claimed no nodes (trt-rtx ran everything on CPU)

Merged
TO
1d ago
+366-3

Fixes the defect found by the model-zoo rehearsal in #81 for #73. A provider could be reported as selected while every node ran on CPU.

The bug

On RTX 5070 / WSL2 with the quantized all-MiniLM-L6-v2:

  • Explicit request: linml run --provider trt-rtx --require-provider exited 0 and reported selectedProvider: NvTensorRTRTXExecutionProvider. All 162 profiled kernels actually ran on CPU.
  • Zero-config: it picked trt-rtx for the same model, the same way.

Root cause. TensorRT-RTX's capability check rejects MatMulInteger (onnxOpCheckers.cpp: checkMatMulInteger ... false) and logs "No graph will run on TensorRT execution provider". ORT then assigns the whole graph to the CPU EP. Session creation still succeeds, and InferencePipeline treats any session that creates and runs as the selected provider. So nothing failed and nothing was reported.

The fix

At session creation, OnnxSessionFactory now records ORT's graph partitioning (session.record_ep_graph_assignment_info) and reads it back through Session_GetEpGraphAssignmentInfo (C API, ORT 1.24+). When a non-CPU provider was assigned zero nodes while CPU was assigned some, it rejects the session with ProviderClaimedNoNodesException. The existing session-creation error handling then does the right thing on every path:

PathBeforeAfter
--provider X --require-providerexit 0, "X" selected, CPU ran everythingexit 3: Required provider 'X' cannot run this model: ... claimed none of the model's nodes; all 458 would run on CPUExecutionProvider
--provider X (soft)"X" selectedfalls back to CPU; the reason is recorded in fallbackChain
zero-configpicks Xskips X with the reason, tries the next ranked provider
serve, liblinml bindingssame as abovesame as above (all go through InferencePipeline → OnnxSessionFactory)

Partial CPU fallback is untouched. CUDA running 340 kernels with 62 on CPU is normal ORT behavior, so the check fires only when the provider gets nothing. If the assignment can't be read (older runtime, or a wrapper layout change), the session is kept and the gap is logged at debug level, so behavior never gets worse than today.

Interop

The managed wrapper doesn't expose the assignment API, so EpGraphAssignment binds the C API function table directly, following the existing NativeLibrary-plus-delegate pattern in CudaStickyError.

  • Slot indices: counted from onnxruntime_c_api.h; the table is append-only. Session_GetEpGraphAssignmentInfo is slot 407, directly after CreateEnvWithOptions (406).
  • Guards against a wrong slot:
    • A test cross-checks the counted slots against the managed wrapper's own OrtApi mirror struct (GetErrorMessage, ReleaseStatus, CreateEnvWithOptions must sit at the same indices).
    • A test reads a real CPU session's assignment through the bound slots end to end.
    • The functions are bound only when the runtime serves C API version 24.
  • Plugin EPs: onnxruntime#32998 reports this API returning nothing for a WebGPU plugin EP. Before building this, I checked it against the vendored TRT-RTX plugin from Python, using ORT 1.32 with the same plugin and runtime libraries:
    • mobilenetv2-7 shows 102 nodes on NvTensorRTRTXExecutionProvider, so the API reports this plugin correctly.
    • The quantized MiniLM shows all 458 nodes on CPU.
    • Even if a plugin hit #32998, no subgraphs at all means "nothing to conclude", so working sessions are never rejected.

Verification

  • .NET tests: 489 pass on Windows: 52 Runtime.Onnx (9 new), 25 Policy, 232 CLI, 160 Catalog, 20 Integration.
  • Real GPU (RTX 5070, WSL2, this branch published for linux-x64):
CaseResult
mobilenetv2-7, --provider trt-rtx --require-providerexit 0, selected trt-rtx, kernel on NvTensorRTRTXExecutionProvider (unchanged)
quantized MiniLM, --provider trt-rtx --require-providerexit 3: cannot run this model: ... claimed none of the model's nodes; all 458 would run on CPUExecutionProvider
quantized MiniLM, --provider trt-rtx (soft)exit 0, selected CPU, fallbackChain carries the reason
quantized MiniLM, --provider cuda --require-providerexit 0, 340 kernels on CUDA and 62 on CPU (unchanged: partial fallback is allowed)
quantized MiniLM, --provider cpu --require-providerexit 0 (unchanged)
mobilenetv2-7, zero-configstill selects trt-rtx (unchanged)
quantized MiniLM, zero-configskips trt-rtx, then hangs in TensorRT (see below)
quantized MiniLM, --provider trt --require-provider (bounded check of the pre-existing hang)killed at 300s (exit 137), so the hang exists without this PR

Behavior change worth knowing

With trt-rtx now correctly skipped for this model, zero-config moves to the next ranked provider, the built-in TensorRT EP. TensorRT hangs on this model, both when requested explicitly and via zero-config, past 15 minutes, while it builds an int8 engine for MatMulInteger. The rehearsal had already recorded this as three 300s timeouts. So on a host that ranks TensorRT next, zero-config for this model goes from "finished, but secretly on CPU" to "stuck in TensorRT". That hang isn't caused by this PR. It would hit any host without trt-rtx, and explicit --provider trt today. It needs its own fix, either a session-creation timeout or demoting TensorRT for quantized-int8 graphs, and I'd rather not hide it inside this change.

šŸ¤– Generated with Claude Code