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

Remove usage of deprecated _serialize #33000

Merged
merged 6 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion sdks/python/apache_beam/ml/inference/onnx_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ def load_model(self) -> ort.InferenceSession:
# when path is remote, we should first load into memory then deserialize
f = FileSystems.open(self._model_uri, "rb")
model_proto = onnx.load(f)
model_proto_bytes = onnx._serialize(model_proto)
model_proto_bytes = model_proto
if not isinstance(model_proto, bytes):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_proto_bytes should be used below, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good catch - fixed

if (hasattr(model_proto, "SerializeToString")
and callable(model_proto.SerializeToString)):
model_proto = model_proto.SerializeToString()
else:
raise TypeError(
f"No SerializeToString method is detected on loaded model. "
+ f"Type of model: {type(model_proto)}"
)
ort_session = ort.InferenceSession(
model_proto_bytes,
sess_options=self._session_options,
Expand Down
Loading