Skip to content

Conversation

@larryliu0820
Copy link
Contributor

@larryliu0820 larryliu0820 commented Oct 30, 2025

The Android binding exposes helpers for feeding IEEE-754 half-precision (FP16) inputs directly.
Use Tensor.fromBlob(shortArray, shape) or reuse a direct ShortBuffer created via
Tensor.allocateHalfBuffer(numElements) to avoid extra copies:

val shape = longArrayOf(24, 4096)
val halfData: ShortArray = buildHalfEncodedData()
val tensor = Tensor.fromBlob(halfData, shape)

val buffer = Tensor.allocateHalfBuffer(halfData.size)
buffer.put(halfData)
buffer.rewind()
val tensorNoCopy = Tensor.fromBlob(buffer, shape)

All buffers must be direct and use the native byte order; the helper above takes care of this.

The Android binding exposes helpers for feeding IEEE-754 half-precision (FP16) inputs directly.
Use `Tensor.fromBlob(shortArray, shape)` or reuse a direct `ShortBuffer` created via
`Tensor.allocateHalfBuffer(numElements)` to avoid extra copies:

```kotlin
val shape = longArrayOf(24, 4096)
val halfData: ShortArray = buildHalfEncodedData()
val tensor = Tensor.fromBlob(halfData, shape)

val buffer = Tensor.allocateHalfBuffer(halfData.size)
buffer.put(halfData)
buffer.rewind()
val tensorNoCopy = Tensor.fromBlob(buffer, shape)
```

All buffers must be direct and use the native byte order; the helper above takes care of this.
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 30, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15479

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 7665b71 with merge base 9d68039 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 30, 2025
@larryliu0820 larryliu0820 added ciflow/android Trigger Android CI release notes: android Android Java and JNI code labels Oct 30, 2025
@larryliu0820 larryliu0820 merged commit dcc9a91 into main Oct 31, 2025
240 of 245 checks passed
@larryliu0820 larryliu0820 deleted the jni_float16 branch October 31, 2025 07:01
abhinaykukkadapu pushed a commit to abhinaykukkadapu/executorch that referenced this pull request Nov 6, 2025
The Android binding exposes helpers for feeding IEEE-754 half-precision
(FP16) inputs directly.
Use `Tensor.fromBlob(shortArray, shape)` or reuse a direct `ShortBuffer`
created via
`Tensor.allocateHalfBuffer(numElements)` to avoid extra copies:

```kotlin
val shape = longArrayOf(24, 4096)
val halfData: ShortArray = buildHalfEncodedData()
val tensor = Tensor.fromBlob(halfData, shape)

val buffer = Tensor.allocateHalfBuffer(halfData.size)
buffer.put(halfData)
buffer.rewind()
val tensorNoCopy = Tensor.fromBlob(buffer, shape)
```

All buffers must be direct and use the native byte order; the helper
above takes care of this.
jirioc pushed a commit to nxp-upstream/executorch that referenced this pull request Dec 19, 2025
The Android binding exposes helpers for feeding IEEE-754 half-precision
(FP16) inputs directly.
Use `Tensor.fromBlob(shortArray, shape)` or reuse a direct `ShortBuffer`
created via
`Tensor.allocateHalfBuffer(numElements)` to avoid extra copies:

```kotlin
val shape = longArrayOf(24, 4096)
val halfData: ShortArray = buildHalfEncodedData()
val tensor = Tensor.fromBlob(halfData, shape)

val buffer = Tensor.allocateHalfBuffer(halfData.size)
buffer.put(halfData)
buffer.rewind()
val tensorNoCopy = Tensor.fromBlob(buffer, shape)
```

All buffers must be direct and use the native byte order; the helper
above takes care of this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/android Trigger Android CI CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: android Android Java and JNI code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants