File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -435,7 +435,19 @@ async function sessionRun(session, inputs) {
435435 const checkedInputs = validateInputs ( session , inputs ) ;
436436 try {
437437 // pass the original ort tensor
438- const ortFeed = Object . fromEntries ( Object . entries ( checkedInputs ) . map ( ( [ k , v ] ) => [ k , v . ort_tensor ] ) ) ;
438+ const ortFeed = Object . fromEntries ( Object . entries ( checkedInputs ) . map ( ( [ k , v ] ) => {
439+ const tensor = /** @type {any } */ ( v . ort_tensor ) ;
440+ if ( apis . IS_NODE_ENV ) {
441+ // In recent versions of Node.js, which support Float16Array, we need to convert
442+ // the Float16Array to Uint16Array for ONNX Runtime to accept it.
443+ // NOTE: This will be removed in Transformers.js v4.0.
444+ if ( typeof Float16Array !== "undefined" && tensor . cpuData instanceof Float16Array ) {
445+ tensor . cpuData = new Uint16Array ( tensor . cpuData . buffer ) ; // reinterpret as Uint16Array
446+ }
447+ }
448+ return [ k , tensor ] ;
449+ } ) ) ;
450+
439451 const output = await runInferenceSession ( session , ortFeed ) ;
440452 return replaceTensors ( output ) ;
441453 } catch ( e ) {
You can’t perform that action at this time.
0 commit comments