Skip to content

Conversation

@neonwatty
Copy link

@neonwatty neonwatty commented Dec 12, 2025

Problem

Preparing a different PR I noticed that running tests locally on Node.js 20+ causes the Llama fp16/q4f16 dtype tests to fail:

TypeError: Tensor.data must be a typed array (4) for float16 tensors, but got typed array (0).

Cause

onnxruntime-common detects Float16Array (available in Node 20+) and uses it for float16 tensors. However, onnxruntime-node's native binding was written before Float16Array existed and only accepts Uint16Array.

Fix

This PR adds a workaround that hides Float16Array before onnxruntime loads, forcing it to use Uint16Array instead.

There's an upstream PR to add Float16Array support to onnxruntime-node (microsoft/onnxruntime#26742), but it hasn't merged yet (and onnxruntime PRs can take many months to merge). Once it does, this workaround can be removed.

Test plan

  • npm test passes locally on Node.js 20+
  • fp16/q4f16 dtype tests now pass

onnxruntime-common uses Float16Array when available (Node 20+), but
onnxruntime-node's native binding only accepts Uint16Array for float16
tensors. This causes dtype tests to fail locally with:

  TypeError: Tensor.data must be a typed array (4) for float16 tensors,
  but got typed array (0).

Add a workaround that hides Float16Array before onnxruntime loads,
forcing it to use Uint16Array instead.

Upstream PR to add Float16Array support:
microsoft/onnxruntime#26742
@xenova
Copy link
Collaborator

xenova commented Dec 12, 2025

Hi 👋 thanks for the PR. Preferably, we'd be able to fix this for normal running, not just unit tests. Any ideas? It seems like any call to new Tensor(...) for type=float16 produces Float16Array values, even if the the data passed in is Uint16Array.

@xenova
Copy link
Collaborator

xenova commented Dec 12, 2025

I did a bit of digging and #1482 seems to fix it. How does that look?

@neonwatty
Copy link
Author

Perfection - #1482 is a better fix - closing this one.

@neonwatty neonwatty closed this Dec 12, 2025
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.

2 participants