Skip to content

Commit

Permalink
Maintain compatibility with onnx 1.14
Browse files Browse the repository at this point in the history
onnx 1.15 introduced some performance optimizations. We can forego
their usage if onnx<1.15 without loss of functionality.
  • Loading branch information
cbourjau committed Feb 7, 2024
1 parent 8cb7271 commit af88200
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/spox/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,16 @@ def maybe(
return cls(tuple(value), name) if value is not None else None

def _to_onnx_deref(self) -> AttributeProto:
return make_attribute(
self._name, self.value, attr_type=self._attribute_proto_type
)
# the attr_type argument was only added in onnx>=1.15. It is a
# performance optimization for which we don't want to
# introduce a version bound. If we fail, we try again without
# it.
try:
return make_attribute(
self._name, self.value, attr_type=self._attribute_proto_type
)
except TypeError:
return make_attribute(self._name, self.value)


class AttrFloat32s(_AttrIterable[float]):
Expand Down
2 changes: 1 addition & 1 deletion tests/type_inference/test_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_scaler_inference():
def test_scaler_inference_fails_mismatched_lengths():
(x,) = arguments(x=Tensor(np.float64, ("N", 3)))
with pytest.raises(InferenceError):
op_ml.scaler(x, offset=[0.0, 0.1], scale=[1])
op_ml.scaler(x, offset=[0.0, 0.1], scale=[1.0])

0 comments on commit af88200

Please sign in to comment.