0
# Version Conversion
1
2
Convert ONNX models between different IR versions and operator set versions to maintain compatibility across framework versions. This module enables model migration and ensures compatibility with different ONNX runtime versions.
3
4
## Capabilities
5
6
### Version Conversion
7
8
Convert models between different ONNX versions with automatic operator and type updates.
9
10
```python { .api }
11
def convert_version(model, target_version):
12
"""
13
Convert ONNX model to target version.
14
15
Parameters:
16
- model: ModelProto to convert
17
- target_version: Target ONNX opset version (integer)
18
19
Returns:
20
ModelProto: Converted model with updated operators and types
21
22
Raises:
23
ValueError: If conversion is not possible or target version is invalid
24
RuntimeError: If conversion fails due to unsupported operators
25
"""
26
```
27
28
## Usage Examples
29
30
### Basic Version Conversion
31
32
```python
33
import onnx
34
from onnx import version_converter
35
36
# Load model with older opset version
37
model = onnx.load_model("model_v11.onnx")
38
print(f"Original opset version: {model.opset_import[0].version}")
39
40
# Convert to newer version
41
try:
42
converted_model = version_converter.convert_version(model, 14)
43
print(f"Converted to opset version: {converted_model.opset_import[0].version}")
44
45
# Validate converted model
46
onnx.checker.check_model(converted_model)
47
print("Conversion successful and model is valid!")
48
49
# Save converted model
50
onnx.save_model(converted_model, "model_v14.onnx")
51
52
except Exception as e:
53
print(f"Conversion failed: {e}")
54
```