Skip to content

[Mobile] Clearly document endianness requirements for OnnxTensor.createTensor #26408

@sapphire-arches

Description

@sapphire-arches

Describe the issue

The obvious way to build an input tensor can lead to unexpected results. onnxruntime should document that it requires native byte order in FloatBuffers, and (optionally) throw an IllegalArgumentException when provided with a buffer in non-native byte order.

To reproduce

val input = ByteBuffer.allocateDirect(tensorSize * 4).asFloatBuffer()
// Fill input using input.put
OnnxTensor.createTensor(env, input, longArrayOf(tensorSize))

This code snippet will result in lots of NaNs downstream because ByteBuffer defaults to enforced-BigEndian mode. Instead, you need to call .order(ByteOrder.nativeOrder()) to ensure floats are stored in native byte order.

Urgency

Trivial to work around, but very annoying to debug.

Platform

Android

OS Version

n/a

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

onnxruntime-android

ONNX Runtime Version or Commit ID

1.23.1

ONNX Runtime API

Java/Kotlin

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:Javaissues related to the Java APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions