Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix weekly CI pipeline errors #1741

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,19 @@ def eval_function( # type: ignore[override]
return self._graph.add_function_call(function, inputs, attributes)


@runtime_typing.checked
def _add_attribute_to_torchscript_node(
node: torch.Node,
key: str,
value: Union[float, int, str, bytes, Sequence[float], Sequence[int], torch.Tensor],
value: Union[
float,
int,
str,
bytes,
Sequence[float],
Sequence[int],
torch.Tensor,
ir.TensorProtocol,
],
):
"""Initializes the right attribute based on type of value."""
if isinstance(value, float):
Expand Down
10 changes: 8 additions & 2 deletions onnxscript/ir/serde_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
self.skipTest("numpy<1.25 does not support bool dtype in from_dlpack")
np.testing.assert_array_equal(np.from_dlpack(tensor), tensor.numpy())

@unittest.skipIf(

Check warning on line 87 in onnxscript/ir/serde_test.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/ir/serde_test.py#L87

Added line #L87 was not covered by tests
version_utils.onnx_older_than("1.17"),
"numpy_helper.to_array was not correctly implemented in onnx<1.17",
)
def test_tensor_proto_tensor_bfloat16(self):
expected_array = np.array(
[[-3.0, -1.0, -0.5, -0.0, +0.0, 0.5, 1.0, 42.0, 2.0]], dtype=ml_dtypes.bfloat16
Expand All @@ -95,15 +99,17 @@
np.array([[-3.0, -1.0, -0.5, -0.0, +0.0, 0.5, 1.0, 42.0, 2.0]]),
)
tensor = serde.TensorProtoTensor(tensor_proto)
np.testing.assert_array_equal(tensor.numpy().view(ml_dtypes.bfloat16), expected_array)
np.testing.assert_array_equal(tensor.numpy(), expected_array)

Check warning on line 102 in onnxscript/ir/serde_test.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/ir/serde_test.py#L102

Added line #L102 was not covered by tests
raw_data = tensor.tobytes()
tensor_proto_from_raw_data = onnx.TensorProto(
dims=tensor_proto.dims,
data_type=tensor_proto.data_type,
raw_data=raw_data,
)
array_from_raw_data = onnx.numpy_helper.to_array(tensor_proto_from_raw_data)
np.testing.assert_array_equal(array_from_raw_data, expected_array)
np.testing.assert_array_equal(

Check warning on line 110 in onnxscript/ir/serde_test.py

View check run for this annotation

Codecov / codecov/patch

onnxscript/ir/serde_test.py#L110

Added line #L110 was not covered by tests
array_from_raw_data.view(ml_dtypes.bfloat16), expected_array
)
# Test dlpack
with self.assertRaises(BufferError):
# NumPy does not support bfloat16 in from_dlpack
Expand Down
Loading