Skip to content

Commit

Permalink
[js/web] allow proxy to load model with 1GB <= size < 2GB (microsoft#…
Browse files Browse the repository at this point in the history
…19178)

### Description

allow proxy to load model with 1GB <= size < 2GB

resolves microsoft#19157.
  • Loading branch information
fs-eire authored Jan 17, 2024
1 parent bc219ed commit 146ebaf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions js/web/lib/wasm/wasm-utils-load-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ export const loadFile = async(file: string|Blob|ArrayBufferLike|Uint8Array): Pro
}
const reader = response.body.getReader();

// use WebAssembly Memory to allocate larger ArrayBuffer
const pages = Math.ceil(fileSize / 65536);
const buffer = new WebAssembly.Memory({initial: pages, maximum: pages}).buffer;
let buffer;
try {
// try to create ArrayBuffer directly
buffer = new ArrayBuffer(fileSize);
} catch (e) {
if (e instanceof RangeError) {
// use WebAssembly Memory to allocate larger ArrayBuffer
const pages = Math.ceil(fileSize / 65536);
buffer = new WebAssembly.Memory({initial: pages, maximum: pages}).buffer;
} else {
throw e;
}
}

let offset = 0;
// eslint-disable-next-line no-constant-condition
Expand Down

0 comments on commit 146ebaf

Please sign in to comment.