Skip to content

Commit

Permalink
Update Torch to ONNX export in conformance (#2269)
Browse files Browse the repository at this point in the history
### Changes

Do constant folding while exporting to ONNX from Torch

### Reason for changes

Conformance test regressgion of ONNX after updating torch to 2.1
Model graphs are updated and contain BatchNorm. Therefore bias locates
no more as Conv attribute but in BatchNorm layer. It leads to not
applying FBC and BC algorithms to these biases.

### Related tickets

125203

### Tests

N/A
  • Loading branch information
kshpv authored Nov 17, 2023
1 parent 21f618c commit 0c7a8d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
9 changes: 1 addition & 8 deletions tests/post_training/pipelines/image_classification_timm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,7 @@ def prepare_model(self) -> None:

if self.backend == BackendType.ONNX:
onnx_path = self.output_model_dir / "model_fp32.onnx"
torch.onnx.export(
timm_model,
self.dummy_tensor,
onnx_path,
export_params=True,
opset_version=13,
do_constant_folding=False,
)
torch.onnx.export(timm_model, self.dummy_tensor, onnx_path, export_params=True, opset_version=13)
self.model = onnx.load(onnx_path)
self.input_name = self.model.graph.input[0].name

Expand Down
4 changes: 2 additions & 2 deletions tests/post_training/reference_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ timm/levit_128_backend_TORCH:
metric_value: 0.73346
metric_value_fp32: 0.7405
timm/levit_128_backend_ONNX:
metric_value: 0.73184
metric_value: 0.73286
metric_value_fp32: 0.7405
timm/levit_128_backend_OV:
metric_value: 0.7334
Expand Down Expand Up @@ -321,7 +321,7 @@ timm/visformer_small_backend_TORCH:
metric_value: 0.77728
metric_value_fp32: 0.77902
timm/visformer_small_backend_ONNX:
metric_value: 0.77432
metric_value: 0.77678
metric_value_fp32: 0.77902
timm/visformer_small_backend_OV:
metric_value: 0.77686
Expand Down

0 comments on commit 0c7a8d5

Please sign in to comment.