Android/fix evalue string serialization#17609
Conversation
toByteArray() used toString() (returning "EValue@...") instead of toStr(), and allocated the buffer using char count instead of byte count. fromByteArray() threw an exception for strings instead of deserializing them. Fix both directions using a length-prefixed format, and also fix the misleading "Unknown Tensor dtype" error message. Add round-trip tests for ASCII, empty, and Unicode strings.
Chinese (3-byte UTF-8) and emoji (4-byte UTF-8 + surrogate pairs) cover more encoding edge cases than Japanese hiragana alone.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/17609
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 53 PendingAs of commit f9bc02c with merge base cf08087 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
This PR fixes critical bugs in EValue string serialization/deserialization for the Android ExecuTorch extension. Previously, toByteArray() used toString() (which returned "EValue@..." object representation) instead of toStr(), and fromByteArray() threw an exception for strings. The fix implements a length-prefixed binary format for strings and corrects the error message.
Changes:
- Fixed string serialization to use
toStr()instead oftoString()and implements length-prefixed format - Fixed string deserialization to properly decode strings instead of throwing exceptions
- Improved error message from "Unknown Tensor dtype" to "Unknown EValue type code"
- Added comprehensive round-trip tests for ASCII, empty, Chinese, and emoji strings
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| extension/android/executorch_android/src/main/java/org/pytorch/executorch/EValue.java | Fixes string serialization/deserialization logic and error messages |
| extension/android/executorch_android/src/test/java/org/pytorch/executorch/EValueTest.kt | Adds comprehensive tests for string serialization round-trips including Unicode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
toByteArray() used toString() (returning "EValue@...") instead of
toStr(), and allocated the buffer using char count instead of byte
count. fromByteArray() threw an exception for strings instead of
deserializing them. Fix both directions using a length-prefixed
format, and also fix the misleading "Unknown Tensor dtype" error
message. Add round-trip tests for ASCII, empty, and Unicode strings.
Test plan
CI