Fix Windows float16 model-path conversion (#33193)
### Description
I fixed float16 conversion from a model path on Windows. The converter
now closes its temporary model before ONNX opens it for shape inference
and loading, then removes it in `finally`. It keeps the temporary output
beside the original model so relative external-weight paths continue to
resolve.
I added tests for embedded and external weights, three `keep_io_types`
settings, repeated conversions, unchanged input files, and cleanup after
inference or loading errors.
### Motivation and Context
Calling `convert_float_to_float16(str(model_path))` with default shape
inference raises `PermissionError` on Windows because
`NamedTemporaryFile` remains open when `onnx.load` reopens it. The
string-path route supports models that exceed in-memory shape
inference's size limit, so disabling inference would lose the intended
behavior.
Existing ModelProto and inference-disabled path conversions produce
identical models before and after this change. Existing model and
external-weight files remain byte-identical.
### Validation
I tested on Windows with Python 3.13.3, ONNX 1.18.0 and the ONNX Runtime
1.30.0 CPU wheel, while importing the converter from source.
- `test_float16.py`: 13 passed, 6 subtests passed. Against pristine
source, all six new conversion subcases fail with the expected
PermissionError.
- 30 compatibility controls pass on both base and patch, including
unchanged files and error cleanup.
- 12 converted-model cases pass ONNX validation and real CPU inference
with the expected values.
- `lintrunner onnxruntime/python/tools/transformers/float16.py
onnxruntime/test/python/transformers/test_float16.py` and `git diff
--check` pass.
I ran the test module from its directory with the installed native wheel
preloaded and the selected source directory on `PYTHONPATH`:
```python
import onnxruntime
import float16
import pytest
raise SystemExit(pytest.main(["test_float16.py", "--import-mode=importlib", "-q"]))
```
I have not run the native build, full repository suite, other platforms
or a model larger than 2 GB locally.
AI assistance disclosure: AI-assisted development tools were used during
investigation and implementation. The reported tests were run against
the final diff.
---------
Co-authored-by: xadupre <xadupre@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>