[React Native] Fix float16 tensor crash by mapping to Uint16Array#27549
[React Native] Fix float16 tensor crash by mapping to Uint16Array#27549tianleiwu merged 4 commits intomicrosoft:mainfrom
Conversation
Hermes does not support Float16Array (ES2024). The React Native binding maps ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 to "Float16Array" which causes a crash when the JSI global lookup returns undefined. Change to "Uint16Array" to match the approach taken in the Node.js binding fix (microsoft#27327).
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in the React Native ONNX Runtime binding when models with float16 inputs or outputs are used on Hermes (the default JS engine since React Native 0.70). The crash occurs because Hermes does not implement Float16Array (an ES2024 feature), causing a lookup of Float16Array on the global object to return undefined. The fix maps ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 to "Uint16Array" instead, which carries the same raw IEEE 754 half-precision bit pattern and is universally supported in Hermes. This mirrors the approach taken for the same issue in the Node.js binding (PR #27327).
Changes:
- Change the
dataTypeToTypedArrayMapentry forONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16from"Float16Array"to"Uint16Array"inTensorUtils.cpp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
@microsoft-github-policy-service agree company="Built With Science" |
|
Sorry, not too familiar with these test artifacts. I think the first CI run fail because models weren't created right. I also added the test models to XCode. Is it expected for me to run RN CI tests locally before I PR? |
|
Looks like RN CI passed, dont think i did anything to the windows related failures? |
|
/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
Can you please rerun it doesn't look related as far as I can tell. |
Description
Fixes float16 tensor support in the React Native binding by mapping
ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16toUint16Arrayinstead ofFloat16Array.Hermes does not support
Float16Array. When the binding tries to construct aFloat16Arrayvia the JSI global lookup, it getsundefinedand crashes.This is the React Native equivalent of #27327 (the Node.js fix for the same issue, merged Feb 2026).
Motivation
Any React Native app using Hermes (the default since RN 0.70) using a model with float16 inputs/outputs crashes at runtime on both iOS and Android.
Changes
js/react_native/cpp/TensorUtils.cpp: Change"Float16Array"to"Uint16Array"indataTypeToTypedArrayMapResolves #27548