From 8c933b810a68eb57d6486b86fc8770a325971d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82uszniak?= Date: Fri, 29 May 2026 14:50:44 +0200 Subject: [PATCH] feat(executorch-bindings): accept Float16Array dataPtr for fp16 tensors (#373) Add `Float16Array` to the `TensorBuffer` union so users exporting fp16 models can pass half-precision inputs ergonomically alongside `ScalarType.HALF`. `bfloat16` has no native TypedArray and is left for callers to pack into a raw `ArrayBuffer` / `Uint16Array` view. --- .../03-hooks/03-executorch-bindings/useExecutorchModule.md | 2 +- packages/react-native-executorch/src/types/common.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/docs/03-hooks/03-executorch-bindings/useExecutorchModule.md b/docs/docs/03-hooks/03-executorch-bindings/useExecutorchModule.md index 7429b4b60e..270691432a 100644 --- a/docs/docs/03-hooks/03-executorch-bindings/useExecutorchModule.md +++ b/docs/docs/03-hooks/03-executorch-bindings/useExecutorchModule.md @@ -47,7 +47,7 @@ You need more details? Check the following resources: [`TensorPtr`](../../06-api-reference/interfaces/TensorPtr.md) is a JS representation of the underlying tensor, which is then passed to the model. You can read more about creating tensors [here](https://docs.pytorch.org/executorch/stable/extension-tensor.html). On JS side, the TensorPtr holds the following information: -[`dataPtr`](../../06-api-reference/interfaces/TensorPtr.md#dataptr) - Represents a data buffer that will be used to create a tensor on the native side. This can be either an `ArrayBuffer` or a `TypedArray`. If your model takes in a datatype which is not covered by any of the `TypedArray` types, just pass an `ArrayBuffer` here. +[`dataPtr`](../../06-api-reference/interfaces/TensorPtr.md#dataptr) - Represents a data buffer that will be used to create a tensor on the native side. This can be either an `ArrayBuffer` or a `TypedArray` (including `Float16Array` for half-precision tensors paired with `ScalarType.HALF`). For datatypes without a matching `TypedArray` — e.g. `bfloat16` — pack the raw bytes into an `ArrayBuffer` (or a `Uint16Array` view) and pass it directly. [`sizes`](../../06-api-reference/interfaces/TensorPtr.md#sizes) - Represents a shape of a given tensor, i.e. for a 640x640 RGB image with a batch size of 1, you would need to pass `[1, 3, 640, 640]` here. diff --git a/packages/react-native-executorch/src/types/common.ts b/packages/react-native-executorch/src/types/common.ts index e8afa8ff4d..96647a0ada 100644 --- a/packages/react-native-executorch/src/types/common.ts +++ b/packages/react-native-executorch/src/types/common.ts @@ -34,7 +34,7 @@ export enum ScalarType { */ LONG = 4, /** - * Half-precision floating point type (16-bit). + * Half-precision (IEEE 754 binary16) floating point type. Pair with a `Float16Array` data buffer. */ HALF = 5, /** @@ -109,6 +109,7 @@ export enum ScalarType { */ export type TensorBuffer = | ArrayBuffer + | Float16Array | Float32Array | Float64Array | Int8Array