Skip to content

[React Native] Fix float16 tensor crash by mapping to Uint16Array#27549

Merged
tianleiwu merged 4 commits intomicrosoft:mainfrom
kevinlam92:fix/react-native-float16-uint16
Mar 20, 2026
Merged

[React Native] Fix float16 tensor crash by mapping to Uint16Array#27549
tianleiwu merged 4 commits intomicrosoft:mainfrom
kevinlam92:fix/react-native-float16-uint16

Conversation

@kevinlam92
Copy link
Contributor

Description

Fixes float16 tensor support in the React Native binding by mapping ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 to Uint16Array instead of Float16Array.

Hermes does not support Float16Array. When the binding tries to construct a Float16Array via the JSI global lookup, it gets undefined and 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" in dataTypeToTypedArrayMap

Resolves #27548

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).
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 dataTypeToTypedArrayMap entry for ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 from "Float16Array" to "Uint16Array" in TensorUtils.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.

@kevinlam92
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Built With Science"

@kevinlam92
Copy link
Contributor Author

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?

@kevinlam92
Copy link
Contributor Author

@tianleiwu

Looks like RN CI passed, dont think i did anything to the windows related failures?

@tianleiwu
Copy link
Contributor

/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
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@tianleiwu tianleiwu enabled auto-merge (squash) March 13, 2026 18:10
@kevinlam92
Copy link
Contributor Author

@tianleiwu

Can you please rerun Win_TRT_Minimal_CUDA_Test_CI?

it doesn't look related as far as I can tell.

@tianleiwu tianleiwu merged commit b10fa54 into microsoft:main Mar 20, 2026
89 of 91 checks passed
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.

[React Native] Float16 tensor crashes becuase Hermes does not support Float16Array

3 participants