[ONNX] Set fallback=False by default (#162726)

This change addresses confusing error messages users encounter when using the ONNX exporter with default settings. Previously, `fallback=True` was the default, which would attempt to fall back to the TorchScript exporter when the dynamo path failed, leading to mixed error messages that obscured the actual issues.

## Problem

When `fallback=True` by default:
- Users get confusing error messages mixing dynamo and TorchScript export failures
- Error messages tell users to provide the `f` argument unnecessarily
- Dynamo error messages get flushed with TorchScript errors when both paths fail
- Users expecting the dynamo path get unexpected fallback behavior

## Solution

Changed the default from `fallback=True` to `fallback=False` in both:
- `torch.onnx.export()` function
- `torch.onnx._internal.exporter._compat.export_compat()` function

## Impact

**Before:**
```python
# Would fallback to TorchScript on dynamo failure, causing mixed error messages
torch.onnx.export(model, args)
```

**After:**
```python
# Clean dynamo-only errors by default
torch.onnx.export(model, args)

# Advanced users can still opt-in to fallback behavior
torch.onnx.export(model, args, fallback=True)
```

Fixes #162697

Pull Request resolved: https://github.com/pytorch/pytorch/pull/162726
Approved by: https://github.com/titaiwangms, https://github.com/xadupre
This commit is contained in:
justinchuby 2025-09-11 18:09:58 +00:00 committed by PyTorch MergeBot
parent 463fbc8ca0
commit 43d9b5ecaa
2 changed files with 2 additions and 2 deletions

View File

@ -81,7 +81,7 @@ def export(
profile: bool = False,
dump_exported_program: bool = False,
artifacts_dir: str | os.PathLike = ".",
fallback: bool = True,
fallback: bool = False,
# BC options
export_params: bool = True,
keep_initializers_as_inputs: bool = False,

View File

@ -67,7 +67,7 @@ def export_compat(
profile: bool = False,
dump_exported_program: bool = False,
artifacts_dir: str | os.PathLike = ".",
fallback: bool = True,
fallback: bool = False,
# Legacy export parameters for fallback
legacy_export_kwargs: dict[str, Any] | None = None,
) -> _onnx_program.ONNXProgram: