Skip to content

Commit

Permalink
Fix react native load from Uint8Array buffer bug (#17739)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->

Use `.buffer` of Uint8Array to get ArrayBuffer.

TODO: Add E2E React Native test case to cover JS level testing to avoid
future breakage.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

#17732

Co-authored-by: rachguo <[email protected]>
  • Loading branch information
2 people authored and snnn committed Sep 30, 2023
1 parent 0161115 commit 6e3c907
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/react_native/lib/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ class OnnxruntimeSessionHandler implements SessionHandler {
let results: Binding.ModelLoadInfoType;
// load a model
if (typeof this.#pathOrBuffer === 'string') {
// load model from model path
results = await this.#inferenceSession.loadModel(normalizePath(this.#pathOrBuffer), options);
} else {
// load model from buffer
if (!this.#inferenceSession.loadModelFromBlob) {
throw new Error('Native module method "loadModelFromBlob" is not defined');
}
const modelBlob = jsiHelper.storeArrayBuffer(this.#pathOrBuffer);
const modelBlob = jsiHelper.storeArrayBuffer(this.#pathOrBuffer.buffer);
results = await this.#inferenceSession.loadModelFromBlob(modelBlob, options);
}
// resolve promise if onnxruntime session is successfully created
Expand Down

0 comments on commit 6e3c907

Please sign in to comment.