Skip to content

Exporters: OnnxConfig(ort_ep=...) names the ONNX Runtime execution provider, adds TensorRT - #50643

Closed
IlyasMoutawwakil wants to merge 5 commits into
mainfrom
exporters-modelopt-quantizer
Closed

IlyasMoutawwakil wants to merge 5 commits into
mainfrom
exporters-modelopt-quantizer

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

Adds OnnxConfig(ort_ep=...): the ONNX Runtime execution provider the export will run on. It replaces ort_fusions (still accepted, with a deprecation warning) and adds TensorRT.

OnnxConfig(ort_ep="cuda")      # fused into the CUDA provider's ops, as `ort_fusions="cuda"` did
OnnxConfig(ort_ep="tensorrt")  # no ONNX Runtime fusions (TensorRT fuses the graph itself), boolean attention mask
OnnxConfig()                   # a standard graph, as before
ort_ep ONNX Runtime fusions Patch sets
None none onnx, onnx.default
"cpu", "cuda", "webgpu", "dml" for that provider onnx, onnx.default
"tensorrt" none onnx, onnx.tensorrt

TensorRT builds a faster engine from the boolean mask: EmbeddingGemma2 (google/embeddinggemma-2, bf16, 8 sentences × 128 tokens, static shapes, CUDA graphs) on a B200 goes from 3.00 ms to 2.53 ms, 7.3x eager instead of 5.5x, with the same accuracy.

Every other export keeps the additive mask, as on main: torchlib's boolean softmax guards each attention with an IsNaN/Where, which ONNX Runtime's own kernels pay for (2x on a 2520-patch vision attention on its CPU provider). The boolean-to-additive conversion moves out of _patch_sdpa into its own patch, _additive_sdpa_mask, registered under a new onnx.default patch set. apply_patches takes several patch sets: ONNX exports apply onnx plus onnx.default, or onnx.tensorrt (empty for now) for the TensorRT provider.

B200, driver 580.126.20; torch 2.13.0+cu130, onnxruntime-gpu 1.29.0 (CUDA 13), TensorRT 10.16.1.11. Latency is the median over ≥300 calls and 10 s.

Dropped from this PR

This PR also added a ModelOpt ONNX quantizer and an ONNX Runtime calibration table for TensorRT's implicit int8. Neither beat plain bf16 TensorRT at acceptable accuracy, so both are removed:

  • Calibration-table int8 on an A100: 0.98–1.03x bf16/fp16 TensorRT on BERT-base (32×128), ViT-base (32 images) and SmolLM2-360M prefill (8×512). TensorRT falls back to fp16 for the linear layers' weights, which a calibration table can't name, so the engines keep fp16 weights. On a B200 it reached 1.28x on EmbeddingGemma2, at a lowest cosine of 0.93 to eager fp32.
  • ModelOpt (explicit Q/DQ): slower than bf16 TensorRT and less accurate on both GPUs. On an A100, 0.71x on EmbeddingGemma2 (cosine 0.76) and 0.94x on Qwen3.5-0.8B generate (69% of eager's tokens). On a B200, no recipe beat bf16 at cosine ≥ 0.999.

Tests

tests/exporters/test_fusions.py::test_tensorrt_keeps_the_boolean_mask: ort_ep="tensorrt" keeps the IsNaN guard and adds no com.microsoft ops, the default export has no IsNaN, and both match. test_ort_fusions_is_the_deprecated_ort_ep: ort_fusions maps to ort_ep, and passing both raises.

🤖 Generated with Claude Code

🤖 mlinter review state

@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Nov 12, 2026 •

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@IlyasMoutawwakil
IlyasMoutawwakil changed the base branch from main to exporters-main-fixes November 15, 2026 17:31

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model linter — first pass

transformers-mlinter found 1 item(s) in the model files this PR touches. These are structural conventions a maintainer would otherwise flag by hand.

This is automated and advisory — it does not block merging.

rule count what it checks
TRF057 1 Public model, config, output and processor classes and their public methods must carry @auto_docstring.
1 item(s) outside this diff
  • src/transformers/models/molmo2/modular_molmo2.py:1581 TRF057 — TRF057: Molmo2Model.get_video_features in modeling_molmo2.py has no @auto_docstring. No parent method it could inherit the decorator from declares it. Add @auto_docstring as the innermost decorator here.

IlyasMoutawwakil added a commit that referenced this pull request Nov 15, 2026
…porters-multimodal-decomposition

The export-path fixes and `OrtFusionConfig` move to #50785, below this PR, and the ModelOpt
quantizer (#50643) sits between them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil
IlyasMoutawwakil marked this pull request as ready for review November 16, 2026 07:43
@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #50787 November 17, 2026 16:19

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model linter — first pass

transformers-mlinter found 3 item(s) in the model files this PR touches. These are structural conventions a maintainer would otherwise flag by hand.

This is automated and advisory — it does not block merging.

rule count what it checks
TRF057 3 Public model, config, output and processor classes and their public methods must carry @auto_docstring.
3 item(s) outside this diff
  • src/transformers/models/hy_v4_vl/modular_hy_v4_vl.py:514 TRF057 — TRF057: HYV4VLModel.get_image_features in modeling_hy_v4_vl.py has no @auto_docstring. Declaring @can_return_tuple here drops every decorator of the parent method. Add @auto_docstring as the innermost decorator here.
  • src/transformers/models/hy_v4_vl/modular_hy_v4_vl.py:538 TRF057 — TRF057: HYV4VLModel.get_video_features in modeling_hy_v4_vl.py has no @auto_docstring. Declaring @can_return_tuple here drops every decorator of the parent method. Add @auto_docstring as the innermost decorator here.
  • src/transformers/models/moss_transcribe_diarize/modular_moss_transcribe_diarize.py:779 TRF057 — TRF057: MossTranscribeDiarizeForConditionalGeneration.get_audio_features in modeling_moss_transcribe_diarize.py has no @auto_docstring. No parent method it could inherit the decorator from declares it. Add @auto_docstring as the innermost decorator here.

ModelOptOnnxQuantizer quantizes the converted ONNX graph for TensorRT, OnnxConfig(for_tensorrt=True) keeps the
attention mask boolean at opset 22, and the ONNX runner hands TensorRT an ONNX Runtime calibration table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the exporters-modelopt-quantizer branch from 4b07912 to 306ee58 Compare November 22, 2026 20:26
IlyasMoutawwakil added a commit that referenced this pull request Nov 22, 2026
#50643)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #50888 November 22, 2026 20:30
@IlyasMoutawwakil
IlyasMoutawwakil changed the base branch from exporters-main-fixes to main November 22, 2026 20:30
…and the TensorRT calibration table

Neither beat bf16 TensorRT at acceptable accuracy. Without the main-fixes opset default of 23, for_tensorrt needs no
opset of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil IlyasMoutawwakil changed the title Exporters: ModelOpt quantizer for the converted ONNX model Exporters: OnnxConfig(for_tensorrt=True) keeps the attention mask boolean for TensorRT Nov 23, 2026
IlyasMoutawwakil and others added 2 commits November 23, 2026 13:33
…tead of an inline conditional

apply_patches takes several patch sets: ONNX exports apply onnx plus onnx.default, or onnx.tensorrt for
ONNX Runtime's TensorRT execution provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ovider, ort_fusions deprecated

ort_ep takes cpu / cuda / webgpu / dml (fuse for that provider) or tensorrt (no fusions, boolean attention mask),
replacing ort_fusions and for_tensorrt. ort_fusions still works, with a deprecation warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil IlyasMoutawwakil changed the title Exporters: OnnxConfig(for_tensorrt=True) keeps the attention mask boolean for TensorRT Exporters: OnnxConfig(ort_ep=...) names the ONNX Runtime execution provider, adds TensorRT Nov 23, 2026
TensorRT showed no speedup with either SDPA mask variant on generation (SmolLM2-360M, A100).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants