Skip to content

Conversation

@farok-amo
Copy link

Summary

Fixes TypeError when saving Meridian models in textproto format

Problem

When calling save_meridian() with a .textproto or .txtpb file path,
the function raises:
TypeError: a bytes-like object is required, not 'str'

This occurs because:

  • The file is opened in binary mode ('wb') on line 355
  • text_format.MessageToString() returns a string, not bytes
  • Writing a string to a binary file causes the TypeError

Solution

Encode the string to UTF-8 bytes before writing:

f.write(text_format.MessageToString(serialized_kernel).encode('utf-8'))

Testing

  • Tested manually with .textproto format
  • Confirms the TypeError is resolved
  • .binpb format unchanged (already returns bytes)

When saving to .textproto or .txtpb format, the file is opened in 
binary mode ('wb') but text_format.MessageToString() returns a string.
This causes a TypeError: 'a bytes-like object is required, not str'.

Fixed by encoding the string to UTF-8 bytes before writing to the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant