/*! * ONNX Runtime Web v1.26.0 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var Q2=Object.create;var li=Object.defineProperty;var eI=Object.getOwnPropertyDescriptor;var tI=Object.getOwnPropertyNames;var nI=Object.getPrototypeOf,rI=Object.prototype.hasOwnProperty;var Ps=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var N=(r,e)=>()=>(r&&(e=r(r=0)),e);var re=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Sr=(r,e)=>{for(var n in e)li(r,n,{get:e[n],enumerable:!0})},Bp=(r,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of tI(e))!rI.call(r,o)&&o!==n&&li(r,o,{get:()=>e[o],enumerable:!(t=eI(e,o))||t.enumerable});return r};var ye=(r,e,n)=>(n=r!=null?Q2(nI(r)):{},Bp(e||!r||!r.__esModule?li(n,"default",{value:r,enumerable:!0}):n,r)),Xr=r=>Bp(li({},"__esModule",{value:!0}),r);var ci,$r,ar,oI,Fp,Es=N(()=>{"use strict";ci=new Map,$r=[],ar=(r,e,n)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let t=ci.get(r);if(t===void 0)ci.set(r,{backend:e,priority:n});else{if(t.priority>n)return;if(t.priority===n&&t.backend!==e)throw new Error(`cannot register backend "${r}" using priority ${n}`)}if(n>=0){let o=$r.indexOf(r);o!==-1&&$r.splice(o,1);for(let i=0;i<$r.length;i++)if(ci.get($r[i]).priority<=n){$r.splice(i,0,r);return}$r.push(r)}return}throw new TypeError("not a valid backend")},oI=async r=>{let e=ci.get(r);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let n=!!e.initPromise;try{return n||(e.initPromise=e.backend.init(r)),await e.initPromise,e.initialized=!0,e.backend}catch(t){return n||(e.error=`${t}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},Fp=async r=>{let e=r.executionProviders||[],n=e.map(u=>typeof u=="string"?u:u.name),t=n.length===0?$r:n,o,i=[],a=new Set;for(let u of t){let l=await oI(u);typeof l=="string"?i.push({name:u,err:l}):(o||(o=l),o===l&&a.add(u))}if(!o)throw new Error(`no available backend found. ERR: ${i.map(u=>`[${u.name}] ${u.err}`).join(", ")}`);for(let{name:u,err:l}of i)n.includes(u)&&console.warn(`removing requested execution provider "${u}" from session options because it is not available: ${l}`);let s=e.filter(u=>a.has(typeof u=="string"?u:u.name));return[o,new Proxy(r,{get:(u,l)=>l==="executionProviders"?s:Reflect.get(u,l)})]}});var Vp=N(()=>{"use strict";Es()});var Gp,Up=N(()=>{"use strict";Gp="1.26.0"});var Wp,st,Cs=N(()=>{"use strict";Up();Wp="warning",st={wasm:{},webgl:{},webgpu:{},versions:{common:Gp},set logLevel(r){if(r!==void 0){if(typeof r!="string"||["verbose","info","warning","error","fatal"].indexOf(r)===-1)throw new Error(`Unsupported logging level: ${r}`);Wp=r}},get logLevel(){return Wp}};Object.defineProperty(st,"logLevel",{enumerable:!0})});var ce,Hp=N(()=>{"use strict";Cs();ce=st});var qp,jp,Kp=N(()=>{"use strict";qp=(r,e)=>{let n=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=r.dims[3],n.height=r.dims[2];let t=n.getContext("2d");if(t!=null){let o,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=r.dims[2],i=r.dims[3]):(o=r.dims[3],i=r.dims[2]);let a=e?.format!==void 0?e.format:"RGB",s=e?.norm,u,l;s===void 0||s.mean===void 0?u=[255,255,255,255]:typeof s.mean=="number"?u=[s.mean,s.mean,s.mean,s.mean]:(u=[s.mean[0],s.mean[1],s.mean[2],0],s.mean[3]!==void 0&&(u[3]=s.mean[3])),s===void 0||s.bias===void 0?l=[0,0,0,0]:typeof s.bias=="number"?l=[s.bias,s.bias,s.bias,s.bias]:(l=[s.bias[0],s.bias[1],s.bias[2],0],s.bias[3]!==void 0&&(l[3]=s.bias[3]));let d=i*o,p=0,h=d,g=d*2,b=-1;a==="RGBA"?(p=0,h=d,g=d*2,b=d*3):a==="RGB"?(p=0,h=d,g=d*2):a==="RBG"&&(p=0,g=d,h=d*2);for(let _=0;_{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),t;if(n!=null){let o,i,a;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(o=r.dims[2],i=r.dims[1],a=r.dims[3]):(o=r.dims[3],i=r.dims[2],a=r.dims[1]);let s=e!==void 0&&e.format!==void 0?e.format:"RGB",u=e?.norm,l,d;u===void 0||u.mean===void 0?l=[255,255,255,255]:typeof u.mean=="number"?l=[u.mean,u.mean,u.mean,u.mean]:(l=[u.mean[0],u.mean[1],u.mean[2],255],u.mean[3]!==void 0&&(l[3]=u.mean[3])),u===void 0||u.bias===void 0?d=[0,0,0,0]:typeof u.bias=="number"?d=[u.bias,u.bias,u.bias,u.bias]:(d=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(d[3]=u.bias[3]));let p=i*o;if(e!==void 0&&(e.format!==void 0&&a===4&&e.format!=="RGBA"||a===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let h=4,g=0,b=1,_=2,I=3,w=0,v=p,S=p*2,A=-1;s==="RGBA"?(w=0,v=p,S=p*2,A=p*3):s==="RGB"?(w=0,v=p,S=p*2):s==="RBG"&&(w=0,S=p,v=p*2),t=n.createImageData(o,i);for(let P=0;P{"use strict";di();Ds=(r,e)=>{if(r===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:n,width:t}=e,o=e.norm??{mean:255,bias:0},i,a;typeof o.mean=="number"?i=[o.mean,o.mean,o.mean,o.mean]:i=[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],typeof o.bias=="number"?a=[o.bias,o.bias,o.bias,o.bias]:a=[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let s=e.format!==void 0?e.format:"RGBA",u=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",l=n*t,d=u==="RGBA"?new Float32Array(l*4):new Float32Array(l*3),p=4,h=0,g=1,b=2,_=3,I=0,w=l,v=l*2,S=-1;s==="RGB"&&(p=3,h=0,g=1,b=2,_=-1),u==="RGBA"?S=l*3:u==="RBG"?(I=0,v=l,w=l*2):u==="BGR"&&(v=0,w=l,I=l*2);for(let P=0;P{let n=typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement,t=typeof ImageData<"u"&&r instanceof ImageData,o=typeof ImageBitmap<"u"&&r instanceof ImageBitmap,i=typeof r=="string",a,s=e??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=d=>typeof HTMLCanvasElement<"u"&&d instanceof HTMLCanvasElement||d instanceof OffscreenCanvas?d.getContext("2d"):null;if(n){let d=u();d.width=r.width,d.height=r.height;let p=l(d);if(p!=null){let h=r.height,g=r.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(h=e.resizedHeight,g=e.resizedWidth),e!==void 0){if(s=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");s.tensorFormat="RGBA",s.height=h,s.width=g}else s.tensorFormat="RGBA",s.height=h,s.width=g;p.drawImage(r,0,0),a=p.getImageData(0,0,g,h).data}else throw new Error("Can not access image data")}else if(t){let d,p;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(d=e.resizedHeight,p=e.resizedWidth):(d=r.height,p=r.width),e!==void 0&&(s=e),s.format="RGBA",s.height=d,s.width=p,e!==void 0){let h=u();h.width=p,h.height=d;let g=l(h);if(g!=null)g.putImageData(r,0,0),a=g.getImageData(0,0,p,d).data;else throw new Error("Can not access image data")}else a=r.data}else if(o){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let d=u();d.width=r.width,d.height=r.height;let p=l(d);if(p!=null){let h=r.height,g=r.width;return p.drawImage(r,0,0,g,h),a=p.getImageData(0,0,g,h).data,s.height=h,s.width=g,Ds(a,s)}else throw new Error("Can not access image data")}else{if(i)return new Promise((d,p)=>{let h=u(),g=l(h);if(!r||!g)return p();let b=new Image;b.crossOrigin="Anonymous",b.src=r,b.onload=()=>{h.width=b.width,h.height=b.height,g.drawImage(b,0,0,h.width,h.height);let _=g.getImageData(0,0,h.width,h.height);s.height=h.height,s.width=h.width,d(Ds(_.data,s))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(a!==void 0)return Ds(a,s);throw new Error("Input data provided is not supported - aborted tensor creation")},Zp=(r,e)=>{let{width:n,height:t,download:o,dispose:i}=e,a=[1,t,n,4];return new pt({location:"texture",type:"float32",texture:r,dims:a,download:o,dispose:i})},Jp=(r,e)=>{let{dataType:n,dims:t,download:o,dispose:i}=e;return new pt({location:"gpu-buffer",type:n??"float32",gpuBuffer:r,dims:t,download:o,dispose:i})},Yp=(r,e)=>{let{dataType:n,dims:t,download:o,dispose:i}=e;return new pt({location:"ml-tensor",type:n??"float32",mlTensor:r,dims:t,download:o,dispose:i})},Qp=(r,e,n)=>new pt({location:"cpu-pinned",type:r,data:e,dims:n??[e.length]})});var Ar,wo,tf,nf,rf=N(()=>{"use strict";Ar=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),wo=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),tf=!1,nf=()=>{if(!tf){tf=!0;let r=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,n=globalThis.Float16Array,t=typeof n<"u"&&n.from;r&&(Ar.set("int64",BigInt64Array),wo.set(BigInt64Array,"int64")),e&&(Ar.set("uint64",BigUint64Array),wo.set(BigUint64Array,"uint64")),t?(Ar.set("float16",n),wo.set(n,"float16")):Ar.set("float16",Uint16Array)}}});var of,af,sf=N(()=>{"use strict";di();of=r=>{let e=1;for(let n=0;n{switch(r.location){case"cpu":return new pt(r.type,r.data,e);case"cpu-pinned":return new pt({location:"cpu-pinned",data:r.data,type:r.type,dims:e});case"texture":return new pt({location:"texture",texture:r.texture,type:r.type,dims:e});case"gpu-buffer":return new pt({location:"gpu-buffer",gpuBuffer:r.gpuBuffer,type:r.type,dims:e});case"ml-tensor":return new pt({location:"ml-tensor",mlTensor:r.mlTensor,type:r.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${r.location} is not supported`)}}});var pt,di=N(()=>{"use strict";Kp();ef();rf();sf();pt=class{constructor(e,n,t){nf();let o,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,o=e.type,i=e.dims,e.location){case"cpu-pinned":{let s=Ar.get(o);if(!s)throw new TypeError(`unsupported type "${o}" to create tensor from pinned buffer`);if(!(e.data instanceof s))throw new TypeError(`buffer should be of type ${s.name}`);this.cpuData=e.data;break}case"texture":{if(o!=="float32")throw new TypeError(`unsupported type "${o}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}case"ml-tensor":{if(o!=="float32"&&o!=="float16"&&o!=="int32"&&o!=="int64"&&o!=="uint32"&&o!=="uint64"&&o!=="int8"&&o!=="uint8"&&o!=="bool"&&o!=="uint4"&&o!=="int4")throw new TypeError(`unsupported type "${o}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,u;if(typeof e=="string")if(o=e,u=t,e==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");s=n}else{let l=Ar.get(e);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(n)){if(e==="float16"&&l===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${l.name} as data.`);e==="uint64"||e==="int64"?s=l.from(n,BigInt):s=l.from(n)}else if(n instanceof l)s=n;else if(n instanceof Uint8ClampedArray)if(e==="uint8")s=Uint8Array.from(n);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(e==="float16"&&n instanceof Uint16Array&&l!==Uint16Array)s=new globalThis.Float16Array(n.buffer,n.byteOffset,n.length);else throw new TypeError(`A ${o} tensor's data must be type of ${l}`)}else if(u=n,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let l=typeof e[0];if(l==="string")o="string",s=e;else if(l==="boolean")o="bool",s=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${l}.`)}else if(e instanceof Uint8ClampedArray)o="uint8",s=Uint8Array.from(e);else{let l=wo.get(e.constructor);if(l===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);o=l,s=e}if(u===void 0)u=[s.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");i=u,this.cpuData=s,this.dataLocation="cpu"}let a=of(i);if(this.cpuData&&a!==this.cpuData.length&&!((o==="uint4"||o==="int4")&&Math.ceil(a/2)===this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=o,this.dims=i,this.size=a}static async fromImage(e,n){return Xp(e,n)}static fromTexture(e,n){return Zp(e,n)}static fromGpuBuffer(e,n){return Jp(e,n)}static fromMLTensor(e,n){return Yp(e,n)}static fromPinnedBuffer(e,n,t){return Qp(e,n,t)}toDataURL(e){return qp(this,e)}toImageData(e){return jp(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let n=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=n,e&&this.disposer&&(this.disposer(),this.disposer=void 0),n}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return af(this,e)}}});var $t,ks=N(()=>{"use strict";di();$t=pt});var pi,uf,At,_t,sr,ur,Ns=N(()=>{"use strict";Cs();pi=(r,e)=>{(typeof st.trace>"u"?!st.wasm.trace:!st.trace)||console.timeStamp(`${r}::ORT::${e}`)},uf=(r,e)=>{let n=new Error().stack?.split(/\r\n|\r|\n/g)||[],t=!1;for(let o=0;o{(typeof st.trace>"u"?!st.wasm.trace:!st.trace)||uf("BEGIN",r)},_t=r=>{(typeof st.trace>"u"?!st.wasm.trace:!st.trace)||uf("END",r)},sr=r=>{(typeof st.trace>"u"?!st.wasm.trace:!st.trace)||console.time(`ORT::${r}`)},ur=r=>{(typeof st.trace>"u"?!st.wasm.trace:!st.trace)||console.timeEnd(`ORT::${r}`)}});var fi,lf=N(()=>{"use strict";Es();ks();Ns();fi=class r{constructor(e){this.handler=e}async run(e,n,t){At(),sr("InferenceSession.run");let o={},i={};if(typeof e!="object"||e===null||e instanceof $t||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof $t)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let l of n){if(typeof l!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(l)===-1)throw new RangeError(`'fetches' contains invalid output name: ${l}.`);o[l]=null}if(typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else{let l=!1,d=Object.getOwnPropertyNames(n);for(let p of this.outputNames)if(d.indexOf(p)!==-1){let h=n[p];(h===null||h instanceof $t)&&(l=!0,a=!1,o[p]=h)}if(l){if(typeof t=="object"&&t!==null)i=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else i=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let l of this.inputNames)if(typeof e[l]>"u")throw new Error(`input '${l}' is missing in 'feeds'.`);if(a)for(let l of this.outputNames)o[l]=null;let s=await this.handler.run(e,o,i),u={};for(let l in s)if(Object.hasOwnProperty.call(s,l)){let d=s[l];d instanceof $t?u[l]=d:u[l]=new $t(d.type,d.data,d.dims)}return ur("InferenceSession.run"),_t(),u}async release(){return this.handler.dispose()}static async create(e,n,t,o){At(),sr("InferenceSession.create");let i,a={};if(typeof e=="string"){if(i=e,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let d=e,p=0,h=e.byteLength;if(typeof n=="object"&&n!==null)a=n;else if(typeof n=="number"){if(p=n,!Number.isSafeInteger(p))throw new RangeError("'byteOffset' must be an integer.");if(p<0||p>=d.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${d.byteLength}).`);if(h=e.byteLength-p,typeof t=="number"){if(h=t,!Number.isSafeInteger(h))throw new RangeError("'byteLength' must be an integer.");if(h<=0||p+h>d.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${d.byteLength-p}].`);if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(typeof t<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof n<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(d,p,h)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[s,u]=await Fp(a),l=await s.createInferenceSessionHandler(i,u);return ur("InferenceSession.create"),_t(),new r(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}});var iI,cf=N(()=>{"use strict";lf();iI=fi});var df=N(()=>{"use strict"});var pf=N(()=>{"use strict"});var ff=N(()=>{"use strict"});var hf=N(()=>{"use strict"});var Ls={};Sr(Ls,{InferenceSession:()=>iI,TRACE:()=>pi,TRACE_EVENT_BEGIN:()=>sr,TRACE_EVENT_END:()=>ur,TRACE_FUNC_BEGIN:()=>At,TRACE_FUNC_END:()=>_t,Tensor:()=>$t,env:()=>ce,registerBackend:()=>ar});var ft=N(()=>{"use strict";Vp();Hp();cf();ks();df();pf();Ns();ff();hf()});function lr(r,e,n,t){if(e===void 0)return sI(r);if(n===void 0)hi(r,e,1);else if(typeof n=="number"&&t===void 0)hi(r,e,n);else if(typeof n=="string"&&t===void 0)hi(r,n,1,e);else if(typeof n=="string"&&typeof t=="number")hi(r,n,t,e);else throw new TypeError("input is valid")}function sI(r){return{verbose:lr.verbose.bind(null,r),info:lr.info.bind(null,r),warning:lr.warning.bind(null,r),error:lr.error.bind(null,r),fatal:lr.fatal.bind(null,r)}}function hi(r,e,n,t){let o=vo[t||""]||vo[""];gf[r]{"use strict";Rs=class{log(e,n,t){}},zs=class{log(e,n,t){console.log(`${this.color(e)} ${t?"\x1B[35m"+t+"\x1B[0m ":""}${n}`)}color(e){switch(e){case"verbose":return"\x1B[34;40mv\x1B[0m";case"info":return"\x1B[32mi\x1B[0m";case"warning":return"\x1B[30;43mw\x1B[0m";case"error":return"\x1B[31;40me\x1B[0m";case"fatal":return"\x1B[101mf\x1B[0m";default:throw new Error(`unsupported severity: ${e}`)}}},gf={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},aI={none:new Rs,console:new zs},bf={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1},vo={"":bf};(u=>{function r(l,d){u("verbose",l,d)}u.verbose=r;function e(l,d){u("info",l,d)}u.info=e;function n(l,d){u("warning",l,d)}u.warning=n;function t(l,d){u("error",l,d)}u.error=t;function o(l,d){u("fatal",l,d)}u.fatal=o;function i(l){vo={},a("",l||{})}u.reset=i;function a(l,d){if(l==="*")i(d);else{let p=vo[l]||bf;vo[l]={provider:d.provider||p.provider,minimalSeverity:d.minimalSeverity||p.minimalSeverity,logDateTime:d.logDateTime===void 0?p.logDateTime:d.logDateTime,logSourceLocation:d.logSourceLocation===void 0?p.logSourceLocation:d.logSourceLocation}}}u.set=a;function s(l){let d={};l.logLevel&&(d.minimalSeverity=l.logLevel),a("",d)}u.setWithEnv=s})(lr||={});Be=lr,gi=class{constructor(e,n,t,o,i,a){this.category=e;this.name=n;this.startTime=t;this.endCallback=o;this.timer=i;this.ctx=a}async end(){return this.endCallback(this)}async checkTimer(){if(this.ctx===void 0||this.timer===void 0)throw new Error("No webgl timer found");return this.ctx.endTimer(),this.ctx.waitForQueryAndGetTime(this.timer)}},bi=class{constructor(e,n,t,o){this.category=e;this.name=n;this.startTime=t;this.endTime=o}},yi=class{constructor(e,n,t){this._started=!1;this._flushPointer=0;this._started=!1,this._maxNumberEvents=e===void 0?1e4:e,this._flushBatchSize=n===void 0?10:n,this._flushIntervalInMilliseconds=t===void 0?5e3:t}static create(e){return e===void 0?new this:new this(e.maxNumberEvents,e.flushBatchSize,e.flushIntervalInMilliseconds)}start(){this._started=!0,this._timingEvents=[],this._flushTime=mi(),this._flushPointer=0}stop(){for(this._started=!1;this._flushPointer{s.then(async d=>{i&&await i.end(),u(d)},async d=>{i&&await i.end(),l(d)})});if(!a&&i){let u=i.end();if(u&&typeof u.then=="function")return new Promise((l,d)=>{u.then(()=>{l(s)},p=>{d(p)})})}return s}begin(e,n,t){if(!this._started)throw new Error("profiler is not started yet");if(t===void 0){let o=mi();return this.flush(o),new gi(e,n,o,i=>this.endSync(i))}else{let o=t.beginTimer();return new gi(e,n,0,async i=>this.end(i),o,t)}}async end(e){let n=await e.checkTimer();this._timingEvents.length=this._flushBatchSize||e-this._flushTime>=this._flushIntervalInMilliseconds){for(let n=this._flushPointer;this._flushPointerperformance.now():Date.now});function yf(r,e,n){for(let t of n){let o=t[0],i=t[1],a=t[2],s=t[3],u=t[4];if(r.opType===o){for(let l of e)if((l.domain===i||l.domain==="ai.onnx"&&i==="")&&uI(l.version,a))return{opImpl:s,opInit:u}}}throw new TypeError(`cannot resolve operator '${r.opType}' with opsets: ${e.map(t=>`${t.domain||"ai.onnx"} v${t.version}`).join(", ")}`)}function uI(r,e){if(e.endsWith("+")){let n=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(n)&&n<=r}else if(e.split("-").length===2){let n=e.split("-"),t=Number.parseInt(n[0],10),o=Number.parseInt(n[1],10);return!isNaN(t)&&!isNaN(o)&&t<=r&&r<=o}else return Number.parseInt(e,10)===r}var _f=N(()=>{"use strict"});var wf=re(Ms=>{"use strict";Ms.__esModule=!0;var lI=function(){function r(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=r.EMPTY,e&&r.isGuid(e)&&(this.value=e)}return r.isGuid=function(e){var n=e.toString();return e&&(e instanceof r||r.validator.test(n))},r.create=function(){return new r([r.gen(2),r.gen(1),r.gen(1),r.gen(1),r.gen(3)].join("-"))},r.createEmpty=function(){return new r("emptyguid")},r.parse=function(e){return new r(e)},r.raw=function(){return[r.gen(2),r.gen(1),r.gen(1),r.gen(1),r.gen(3)].join("-")},r.gen=function(e){for(var n="",t=0;t>>=0,(o=0<=r&&r<256)&&(t=Tf[r],t)?t:(n=Le(r,0,!0),o&&(Tf[r]=n),n)):(r|=0,(o=-128<=r&&r<128)&&(t=xf[r],t)?t:(n=Le(r,r<0?-1:0,!1),o&&(xf[r]=n),n))}function Nt(r,e){if(isNaN(r))return e?Jn:Wt;if(e){if(r<0)return Jn;if(r>=Af)return Ef}else{if(r<=-Sf)return wt;if(r+1>=Sf)return Pf}return r<0?Nt(-r,e).neg():Le(r%Jr|0,r/Jr|0,e)}function Le(r,e,n){return new je(r,e,n)}function Fs(r,e,n){if(r.length===0)throw Error("empty string");if(typeof e=="number"?(n=e,e=!1):e=!!e,r==="NaN"||r==="Infinity"||r==="+Infinity"||r==="-Infinity")return e?Jn:Wt;if(n=n||10,n<2||360)throw Error("interior hyphen");if(t===0)return Fs(r.substring(1),e,n).neg();for(var o=Nt(_i(n,8)),i=Wt,a=0;a{kt=null;try{kt=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}je.prototype.__isLong__;Object.defineProperty(je.prototype,"__isLong__",{value:!0});je.isLong=gt;xf={},Tf={};je.fromInt=Or;je.fromNumber=Nt;je.fromBits=Le;_i=Math.pow;je.fromString=Fs;je.fromValue=Ht;If=65536,cI=1<<24,Jr=If*If,Af=Jr*Jr,Sf=Af/2,$f=Or(cI),Wt=Or(0);je.ZERO=Wt;Jn=Or(0,!0);je.UZERO=Jn;Zr=Or(1);je.ONE=Zr;Of=Or(1,!0);je.UONE=Of;Bs=Or(-1);je.NEG_ONE=Bs;Pf=Le(-1,2147483647,!1);je.MAX_VALUE=Pf;Ef=Le(-1,-1,!0);je.MAX_UNSIGNED_VALUE=Ef;wt=Le(0,-2147483648,!1);je.MIN_VALUE=wt;H=je.prototype;H.toInt=function(){return this.unsigned?this.low>>>0:this.low};H.toNumber=function(){return this.unsigned?(this.high>>>0)*Jr+(this.low>>>0):this.high*Jr+(this.low>>>0)};H.toString=function(e){if(e=e||10,e<2||36>>0,d=l.toString(e);if(a=u,a.isZero())return d+s;for(;d.length<6;)d="0"+d;s=""+d+s}};H.getHighBits=function(){return this.high};H.getHighBitsUnsigned=function(){return this.high>>>0};H.getLowBits=function(){return this.low};H.getLowBitsUnsigned=function(){return this.low>>>0};H.getNumBitsAbs=function(){if(this.isNegative())return this.eq(wt)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,n=31;n>0&&(e&1<=0};H.isOdd=function(){return(this.low&1)===1};H.isEven=function(){return(this.low&1)===0};H.equals=function(e){return gt(e)||(e=Ht(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};H.eq=H.equals;H.notEquals=function(e){return!this.eq(e)};H.neq=H.notEquals;H.ne=H.notEquals;H.lessThan=function(e){return this.comp(e)<0};H.lt=H.lessThan;H.lessThanOrEqual=function(e){return this.comp(e)<=0};H.lte=H.lessThanOrEqual;H.le=H.lessThanOrEqual;H.greaterThan=function(e){return this.comp(e)>0};H.gt=H.greaterThan;H.greaterThanOrEqual=function(e){return this.comp(e)>=0};H.gte=H.greaterThanOrEqual;H.ge=H.greaterThanOrEqual;H.compare=function(e){if(gt(e)||(e=Ht(e)),this.eq(e))return 0;var n=this.isNegative(),t=e.isNegative();return n&&!t?-1:!n&&t?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1};H.comp=H.compare;H.negate=function(){return!this.unsigned&&this.eq(wt)?wt:this.not().add(Zr)};H.neg=H.negate;H.add=function(e){gt(e)||(e=Ht(e));var n=this.high>>>16,t=this.high&65535,o=this.low>>>16,i=this.low&65535,a=e.high>>>16,s=e.high&65535,u=e.low>>>16,l=e.low&65535,d=0,p=0,h=0,g=0;return g+=i+l,h+=g>>>16,g&=65535,h+=o+u,p+=h>>>16,h&=65535,p+=t+s,d+=p>>>16,p&=65535,d+=n+a,d&=65535,Le(h<<16|g,d<<16|p,this.unsigned)};H.subtract=function(e){return gt(e)||(e=Ht(e)),this.add(e.neg())};H.sub=H.subtract;H.multiply=function(e){if(this.isZero())return this;if(gt(e)||(e=Ht(e)),kt){var n=kt.mul(this.low,this.high,e.low,e.high);return Le(n,kt.get_high(),this.unsigned)}if(e.isZero())return this.unsigned?Jn:Wt;if(this.eq(wt))return e.isOdd()?wt:Wt;if(e.eq(wt))return this.isOdd()?wt:Wt;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt($f)&&e.lt($f))return Nt(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,o=this.high&65535,i=this.low>>>16,a=this.low&65535,s=e.high>>>16,u=e.high&65535,l=e.low>>>16,d=e.low&65535,p=0,h=0,g=0,b=0;return b+=a*d,g+=b>>>16,b&=65535,g+=i*d,h+=g>>>16,g&=65535,g+=a*l,h+=g>>>16,g&=65535,h+=o*d,p+=h>>>16,h&=65535,h+=i*l,p+=h>>>16,h&=65535,h+=a*u,p+=h>>>16,h&=65535,p+=t*d+o*l+i*u+a*s,p&=65535,Le(g<<16|b,p<<16|h,this.unsigned)};H.mul=H.multiply;H.divide=function(e){if(gt(e)||(e=Ht(e)),e.isZero())throw Error("division by zero");if(kt){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var n=(this.unsigned?kt.div_u:kt.div_s)(this.low,this.high,e.low,e.high);return Le(n,kt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Jn:Wt;var t,o,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return Jn;if(e.gt(this.shru(1)))return Of;i=Jn}else{if(this.eq(wt)){if(e.eq(Zr)||e.eq(Bs))return wt;if(e.eq(wt))return Zr;var a=this.shr(1);return t=a.div(e).shl(1),t.eq(Wt)?e.isNegative()?Zr:Bs:(o=this.sub(e.mul(t)),i=t.add(o.div(e)),i)}else if(e.eq(wt))return this.unsigned?Jn:Wt;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=Wt}for(o=this;o.gte(e);){t=Math.max(1,Math.floor(o.toNumber()/e.toNumber()));for(var s=Math.ceil(Math.log(t)/Math.LN2),u=s<=48?1:_i(2,s-48),l=Nt(t),d=l.mul(e);d.isNegative()||d.gt(o);)t-=u,l=Nt(t,this.unsigned),d=l.mul(e);l.isZero()&&(l=Zr),i=i.add(l),o=o.sub(d)}return i};H.div=H.divide;H.modulo=function(e){if(gt(e)||(e=Ht(e)),kt){var n=(this.unsigned?kt.rem_u:kt.rem_s)(this.low,this.high,e.low,e.high);return Le(n,kt.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};H.mod=H.modulo;H.rem=H.modulo;H.not=function(){return Le(~this.low,~this.high,this.unsigned)};H.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32};H.clz=H.countLeadingZeros;H.countTrailingZeros=function(){return this.low?vf(this.low):vf(this.high)+32};H.ctz=H.countTrailingZeros;H.and=function(e){return gt(e)||(e=Ht(e)),Le(this.low&e.low,this.high&e.high,this.unsigned)};H.or=function(e){return gt(e)||(e=Ht(e)),Le(this.low|e.low,this.high|e.high,this.unsigned)};H.xor=function(e){return gt(e)||(e=Ht(e)),Le(this.low^e.low,this.high^e.high,this.unsigned)};H.shiftLeft=function(e){return gt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?Le(this.low<>>32-e,this.unsigned):Le(0,this.low<>>e|this.high<<32-e,this.high>>e,this.unsigned):Le(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};H.shr=H.shiftRight;H.shiftRightUnsigned=function(e){return gt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?Le(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):e===32?Le(this.high,0,this.unsigned):Le(this.high>>>e-32,0,this.unsigned)};H.shru=H.shiftRightUnsigned;H.shr_u=H.shiftRightUnsigned;H.rotateLeft=function(e){var n;return gt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?Le(this.high,this.low,this.unsigned):e<32?(n=32-e,Le(this.low<>>n,this.high<>>n,this.unsigned)):(e-=32,n=32-e,Le(this.high<>>n,this.low<>>n,this.unsigned))};H.rotl=H.rotateLeft;H.rotateRight=function(e){var n;return gt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?Le(this.high,this.low,this.unsigned):e<32?(n=32-e,Le(this.high<>>e,this.low<>>e,this.unsigned)):(e-=32,n=32-e,Le(this.low<>>e,this.high<>>e,this.unsigned))};H.rotr=H.rotateRight;H.toSigned=function(){return this.unsigned?Le(this.low,this.high,!1):this};H.toUnsigned=function(){return this.unsigned?this:Le(this.low,this.high,!0)};H.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};H.toBytesLE=function(){var e=this.high,n=this.low;return[n&255,n>>>8&255,n>>>16&255,n>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]};H.toBytesBE=function(){var e=this.high,n=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,n>>>24,n>>>16&255,n>>>8&255,n&255]};je.fromBytes=function(e,n,t){return t?je.fromBytesLE(e,n):je.fromBytesBE(e,n)};je.fromBytesLE=function(e,n){return new je(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,n)};je.fromBytesBE=function(e,n){return new je(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],n)};cr=je});var Gs=re(wi=>{"use strict";Object.defineProperty(wi,"__esModule",{value:!0});wi.ArgType=void 0;var Cf;(function(r){r[r.INPUT=0]="INPUT",r[r.OUTPUT=1]="OUTPUT"})(Cf||(wi.ArgType=Cf={}))});var Pr=re(rn=>{"use strict";Object.defineProperty(rn,"__esModule",{value:!0});rn.SIZE_PREFIX_LENGTH=rn.FILE_IDENTIFIER_LENGTH=rn.SIZEOF_INT=rn.SIZEOF_SHORT=void 0;rn.SIZEOF_SHORT=2;rn.SIZEOF_INT=4;rn.FILE_IDENTIFIER_LENGTH=4;rn.SIZE_PREFIX_LENGTH=4});var Us=re(Lt=>{"use strict";Object.defineProperty(Lt,"__esModule",{value:!0});Lt.isLittleEndian=Lt.float64=Lt.float32=Lt.int32=void 0;Lt.int32=new Int32Array(2);Lt.float32=new Float32Array(Lt.int32.buffer);Lt.float64=new Float64Array(Lt.int32.buffer);Lt.isLittleEndian=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1});var Ws=re(vi=>{"use strict";Object.defineProperty(vi,"__esModule",{value:!0});vi.Encoding=void 0;var Df;(function(r){r[r.UTF8_BYTES=1]="UTF8_BYTES",r[r.UTF16_STRING=2]="UTF16_STRING"})(Df||(vi.Encoding=Df={}))});var qs=re(xi=>{"use strict";Object.defineProperty(xi,"__esModule",{value:!0});xi.ByteBuffer=void 0;var on=Pr(),vt=Us(),dI=Ws(),Hs=class r{constructor(e){this.bytes_=e,this.position_=0,this.text_decoder_=new TextDecoder}static allocate(e){return new r(new Uint8Array(e))}clear(){this.position_=0}bytes(){return this.bytes_}position(){return this.position_}setPosition(e){this.position_=e}capacity(){return this.bytes_.length}readInt8(e){return this.readUint8(e)<<24>>24}readUint8(e){return this.bytes_[e]}readInt16(e){return this.readUint16(e)<<16>>16}readUint16(e){return this.bytes_[e]|this.bytes_[e+1]<<8}readInt32(e){return this.bytes_[e]|this.bytes_[e+1]<<8|this.bytes_[e+2]<<16|this.bytes_[e+3]<<24}readUint32(e){return this.readInt32(e)>>>0}readInt64(e){return BigInt.asIntN(64,BigInt(this.readUint32(e))+(BigInt(this.readUint32(e+4))<>8}writeUint16(e,n){this.bytes_[e]=n,this.bytes_[e+1]=n>>8}writeInt32(e,n){this.bytes_[e]=n,this.bytes_[e+1]=n>>8,this.bytes_[e+2]=n>>16,this.bytes_[e+3]=n>>24}writeUint32(e,n){this.bytes_[e]=n,this.bytes_[e+1]=n>>8,this.bytes_[e+2]=n>>16,this.bytes_[e+3]=n>>24}writeInt64(e,n){this.writeInt32(e,Number(BigInt.asIntN(32,n))),this.writeInt32(e+4,Number(BigInt.asIntN(32,n>>BigInt(32))))}writeUint64(e,n){this.writeUint32(e,Number(BigInt.asUintN(32,n))),this.writeUint32(e+4,Number(BigInt.asUintN(32,n>>BigInt(32))))}writeFloat32(e,n){vt.float32[0]=n,this.writeInt32(e,vt.int32[0])}writeFloat64(e,n){vt.float64[0]=n,this.writeInt32(e,vt.int32[vt.isLittleEndian?0:1]),this.writeInt32(e+4,vt.int32[vt.isLittleEndian?1:0])}getBufferIdentifier(){if(this.bytes_.length{"use strict";Object.defineProperty(Ti,"__esModule",{value:!0});Ti.Builder=void 0;var kf=qs(),Ot=Pr(),js=class r{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null,this.text_encoder=new TextEncoder;let n;e?n=e:n=1024,this.bb=kf.ByteBuffer.allocate(n),this.space=n}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,n){e>this.minalign&&(this.minalign=e);let t=~(this.bb.capacity()-this.space+n)+1&e-1;for(;this.space=0&&this.vtable[n]==0;n--);let t=n+1;for(;n>=0;n--)this.addInt16(this.vtable[n]!=0?e-this.vtable[n]:0);let o=2;this.addInt16(e-this.object_start);let i=(t+o)*Ot.SIZEOF_SHORT;this.addInt16(i);let a=0,s=this.space;e:for(n=0;n=0;a--)this.writeInt8(i.charCodeAt(a))}this.prep(this.minalign,Ot.SIZEOF_INT+o),this.addOffset(e),o&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,n){this.finish(e,n,!0)}requiredField(e,n){let t=this.bb.capacity()-e,o=t-this.bb.readInt32(t);if(!(n{"use strict";Object.defineProperty(Ze,"__esModule",{value:!0});Ze.ByteBuffer=Ze.Builder=Ze.Encoding=Ze.isLittleEndian=Ze.float64=Ze.float32=Ze.int32=Ze.SIZE_PREFIX_LENGTH=Ze.FILE_IDENTIFIER_LENGTH=Ze.SIZEOF_INT=Ze.SIZEOF_SHORT=void 0;var pI=Pr();Object.defineProperty(Ze,"SIZEOF_SHORT",{enumerable:!0,get:function(){return pI.SIZEOF_SHORT}});var fI=Pr();Object.defineProperty(Ze,"SIZEOF_INT",{enumerable:!0,get:function(){return fI.SIZEOF_INT}});var hI=Pr();Object.defineProperty(Ze,"FILE_IDENTIFIER_LENGTH",{enumerable:!0,get:function(){return hI.FILE_IDENTIFIER_LENGTH}});var mI=Pr();Object.defineProperty(Ze,"SIZE_PREFIX_LENGTH",{enumerable:!0,get:function(){return mI.SIZE_PREFIX_LENGTH}});var Ii=Us();Object.defineProperty(Ze,"int32",{enumerable:!0,get:function(){return Ii.int32}});Object.defineProperty(Ze,"float32",{enumerable:!0,get:function(){return Ii.float32}});Object.defineProperty(Ze,"float64",{enumerable:!0,get:function(){return Ii.float64}});Object.defineProperty(Ze,"isLittleEndian",{enumerable:!0,get:function(){return Ii.isLittleEndian}});var gI=Ws();Object.defineProperty(Ze,"Encoding",{enumerable:!0,get:function(){return gI.Encoding}});var bI=Nf();Object.defineProperty(Ze,"Builder",{enumerable:!0,get:function(){return bI.Builder}});var yI=qs();Object.defineProperty(Ze,"ByteBuffer",{enumerable:!0,get:function(){return yI.ByteBuffer}})});var Xs=re(an=>{"use strict";var _I=an&&an.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),wI=an&&an.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),vI=an&&an.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&_I(e,r,n);return wI(e,r),e};Object.defineProperty(an,"__esModule",{value:!0});an.ArgTypeAndIndex=void 0;var xI=vI(Re()),Lf=Gs(),Ks=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsArgTypeAndIndex(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsArgTypeAndIndex(e,n){return e.setPosition(e.position()+xI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}argType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt8(this.bb_pos+e):Lf.ArgType.INPUT}index(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb_pos+e):0}static startArgTypeAndIndex(e){e.startObject(2)}static addArgType(e,n){e.addFieldInt8(0,n,Lf.ArgType.INPUT)}static addIndex(e,n){e.addFieldInt32(1,n,0)}static endArgTypeAndIndex(e){return e.endObject()}static createArgTypeAndIndex(e,n,t){return r.startArgTypeAndIndex(e),r.addArgType(e,n),r.addIndex(e,t),r.endArgTypeAndIndex(e)}};an.ArgTypeAndIndex=Ks});var Zs=re(Si=>{"use strict";Object.defineProperty(Si,"__esModule",{value:!0});Si.AttributeType=void 0;var Rf;(function(r){r[r.UNDEFINED=0]="UNDEFINED",r[r.FLOAT=1]="FLOAT",r[r.INT=2]="INT",r[r.STRING=3]="STRING",r[r.TENSOR=4]="TENSOR",r[r.GRAPH=5]="GRAPH",r[r.FLOATS=6]="FLOATS",r[r.INTS=7]="INTS",r[r.STRINGS=8]="STRINGS",r[r.TENSORS=9]="TENSORS",r[r.GRAPHS=10]="GRAPHS",r[r.SPARSE_TENSOR=11]="SPARSE_TENSOR",r[r.SPARSE_TENSORS=12]="SPARSE_TENSORS"})(Rf||(Si.AttributeType=Rf={}))});var Js=re($i=>{"use strict";Object.defineProperty($i,"__esModule",{value:!0});$i.NodeType=void 0;var zf;(function(r){r[r.Primitive=0]="Primitive",r[r.Fused=1]="Fused"})(zf||($i.NodeType=zf={}))});var Qs=re(sn=>{"use strict";var TI=sn&&sn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),II=sn&&sn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),SI=sn&&sn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&TI(e,r,n);return II(e,r),e};Object.defineProperty(sn,"__esModule",{value:!0});sn.Node=void 0;var $I=SI(Re()),AI=eu(),Mf=Js(),Ys=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsNode(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNode(e,n){return e.setPosition(e.position()+$I.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}name(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}docString(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}domain(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,e):null}sinceVersion(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt32(this.bb_pos+e):0}index(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readUint32(this.bb_pos+e):0}opType(e){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb_pos+n,e):null}type(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readInt32(this.bb_pos+e):Mf.NodeType.Primitive}executionProviderType(e){let n=this.bb.__offset(this.bb_pos,18);return n?this.bb.__string(this.bb_pos+n,e):null}inputs(e,n){let t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}inputsLength(){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.__vector_len(this.bb_pos+e):0}outputs(e,n){let t=this.bb.__offset(this.bb_pos,22);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}outputsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}attributes(e,n){let t=this.bb.__offset(this.bb_pos,24);return t?(n||new AI.Attribute).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}attributesLength(){let e=this.bb.__offset(this.bb_pos,24);return e?this.bb.__vector_len(this.bb_pos+e):0}inputArgCounts(e){let n=this.bb.__offset(this.bb_pos,26);return n?this.bb.readInt32(this.bb.__vector(this.bb_pos+n)+e*4):0}inputArgCountsLength(){let e=this.bb.__offset(this.bb_pos,26);return e?this.bb.__vector_len(this.bb_pos+e):0}inputArgCountsArray(){let e=this.bb.__offset(this.bb_pos,26);return e?new Int32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}implicitInputs(e,n){let t=this.bb.__offset(this.bb_pos,28);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}implicitInputsLength(){let e=this.bb.__offset(this.bb_pos,28);return e?this.bb.__vector_len(this.bb_pos+e):0}static startNode(e){e.startObject(13)}static addName(e,n){e.addFieldOffset(0,n,0)}static addDocString(e,n){e.addFieldOffset(1,n,0)}static addDomain(e,n){e.addFieldOffset(2,n,0)}static addSinceVersion(e,n){e.addFieldInt32(3,n,0)}static addIndex(e,n){e.addFieldInt32(4,n,0)}static addOpType(e,n){e.addFieldOffset(5,n,0)}static addType(e,n){e.addFieldInt32(6,n,Mf.NodeType.Primitive)}static addExecutionProviderType(e,n){e.addFieldOffset(7,n,0)}static addInputs(e,n){e.addFieldOffset(8,n,0)}static createInputsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startInputsVector(e,n){e.startVector(4,n,4)}static addOutputs(e,n){e.addFieldOffset(9,n,0)}static createOutputsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startOutputsVector(e,n){e.startVector(4,n,4)}static addAttributes(e,n){e.addFieldOffset(10,n,0)}static createAttributesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startAttributesVector(e,n){e.startVector(4,n,4)}static addInputArgCounts(e,n){e.addFieldOffset(11,n,0)}static createInputArgCountsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addInt32(n[t]);return e.endVector()}static startInputArgCountsVector(e,n){e.startVector(4,n,4)}static addImplicitInputs(e,n){e.addFieldOffset(12,n,0)}static createImplicitInputsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startImplicitInputsVector(e,n){e.startVector(4,n,4)}static endNode(e){return e.endObject()}static createNode(e,n,t,o,i,a,s,u,l,d,p,h,g,b){return r.startNode(e),r.addName(e,n),r.addDocString(e,t),r.addDomain(e,o),r.addSinceVersion(e,i),r.addIndex(e,a),r.addOpType(e,s),r.addType(e,u),r.addExecutionProviderType(e,l),r.addInputs(e,d),r.addOutputs(e,p),r.addAttributes(e,h),r.addInputArgCounts(e,g),r.addImplicitInputs(e,b),r.endNode(e)}};sn.Node=Ys});var nu=re(Ai=>{"use strict";Object.defineProperty(Ai,"__esModule",{value:!0});Ai.EdgeEnd=void 0;var tu=class{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}nodeIndex(){return this.bb.readUint32(this.bb_pos)}srcArgIndex(){return this.bb.readInt32(this.bb_pos+4)}dstArgIndex(){return this.bb.readInt32(this.bb_pos+8)}static sizeOf(){return 12}static createEdgeEnd(e,n,t,o){return e.prep(4,12),e.writeInt32(o),e.writeInt32(t),e.writeInt32(n),e.offset()}};Ai.EdgeEnd=tu});var ou=re(un=>{"use strict";var OI=un&&un.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),PI=un&&un.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),EI=un&&un.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&OI(e,r,n);return PI(e,r),e};Object.defineProperty(un,"__esModule",{value:!0});un.NodeEdge=void 0;var CI=EI(Re()),Bf=nu(),ru=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsNodeEdge(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNodeEdge(e,n){return e.setPosition(e.position()+CI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}nodeIndex(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb_pos+e):0}inputEdges(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new Bf.EdgeEnd).__init(this.bb.__vector(this.bb_pos+t)+e*12,this.bb):null}inputEdgesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}outputEdges(e,n){let t=this.bb.__offset(this.bb_pos,8);return t?(n||new Bf.EdgeEnd).__init(this.bb.__vector(this.bb_pos+t)+e*12,this.bb):null}outputEdgesLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}static startNodeEdge(e){e.startObject(3)}static addNodeIndex(e,n){e.addFieldInt32(0,n,0)}static addInputEdges(e,n){e.addFieldOffset(1,n,0)}static startInputEdgesVector(e,n){e.startVector(12,n,4)}static addOutputEdges(e,n){e.addFieldOffset(2,n,0)}static startOutputEdgesVector(e,n){e.startVector(12,n,4)}static endNodeEdge(e){return e.endObject()}static createNodeEdge(e,n,t,o){return r.startNodeEdge(e),r.addNodeIndex(e,n),r.addInputEdges(e,t),r.addOutputEdges(e,o),r.endNodeEdge(e)}};un.NodeEdge=ru});var au=re(ln=>{"use strict";var DI=ln&&ln.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),kI=ln&&ln.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),NI=ln&&ln.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&DI(e,r,n);return kI(e,r),e};Object.defineProperty(ln,"__esModule",{value:!0});ln.NodesToOptimizeIndices=void 0;var LI=NI(Re()),iu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsNodesToOptimizeIndices(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsNodesToOptimizeIndices(e,n){return e.setPosition(e.position()+LI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}nodeIndices(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.readUint32(this.bb.__vector(this.bb_pos+n)+e*4):0}nodeIndicesLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeIndicesArray(){let e=this.bb.__offset(this.bb_pos,4);return e?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}numInputs(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb_pos+e):0}numOutputs(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readUint32(this.bb_pos+e):0}hasVariadicInput(){let e=this.bb.__offset(this.bb_pos,10);return e?!!this.bb.readInt8(this.bb_pos+e):!1}hasVariadicOutput(){let e=this.bb.__offset(this.bb_pos,12);return e?!!this.bb.readInt8(this.bb_pos+e):!1}numVariadicInputs(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readUint32(this.bb_pos+e):0}numVariadicOutputs(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readUint32(this.bb_pos+e):0}static startNodesToOptimizeIndices(e){e.startObject(7)}static addNodeIndices(e,n){e.addFieldOffset(0,n,0)}static createNodeIndicesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addInt32(n[t]);return e.endVector()}static startNodeIndicesVector(e,n){e.startVector(4,n,4)}static addNumInputs(e,n){e.addFieldInt32(1,n,0)}static addNumOutputs(e,n){e.addFieldInt32(2,n,0)}static addHasVariadicInput(e,n){e.addFieldInt8(3,+n,0)}static addHasVariadicOutput(e,n){e.addFieldInt8(4,+n,0)}static addNumVariadicInputs(e,n){e.addFieldInt32(5,n,0)}static addNumVariadicOutputs(e,n){e.addFieldInt32(6,n,0)}static endNodesToOptimizeIndices(e){return e.endObject()}static createNodesToOptimizeIndices(e,n,t,o,i,a,s,u){return r.startNodesToOptimizeIndices(e),r.addNodeIndices(e,n),r.addNumInputs(e,t),r.addNumOutputs(e,o),r.addHasVariadicInput(e,i),r.addHasVariadicOutput(e,a),r.addNumVariadicInputs(e,s),r.addNumVariadicOutputs(e,u),r.endNodesToOptimizeIndices(e)}};ln.NodesToOptimizeIndices=iu});var uu=re(cn=>{"use strict";var RI=cn&&cn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),zI=cn&&cn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),MI=cn&&cn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&RI(e,r,n);return zI(e,r),e};Object.defineProperty(cn,"__esModule",{value:!0});cn.RuntimeOptimizationRecord=void 0;var BI=MI(Re()),FI=au(),su=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsRuntimeOptimizationRecord(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizationRecord(e,n){return e.setPosition(e.position()+BI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}actionId(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}nodesToOptimizeIndices(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new FI.NodesToOptimizeIndices).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}producedOpIds(e,n){let t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}producedOpIdsLength(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizationRecord(e){e.startObject(4)}static addActionId(e,n){e.addFieldOffset(0,n,0)}static addNodesToOptimizeIndices(e,n){e.addFieldOffset(1,n,0)}static addProducedOpIds(e,n){e.addFieldOffset(3,n,0)}static createProducedOpIdsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startProducedOpIdsVector(e,n){e.startVector(4,n,4)}static endRuntimeOptimizationRecord(e){return e.endObject()}};cn.RuntimeOptimizationRecord=su});var cu=re(dn=>{"use strict";var VI=dn&&dn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),GI=dn&&dn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),UI=dn&&dn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&VI(e,r,n);return GI(e,r),e};Object.defineProperty(dn,"__esModule",{value:!0});dn.RuntimeOptimizationRecordContainerEntry=void 0;var WI=UI(Re()),HI=uu(),lu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsRuntimeOptimizationRecordContainerEntry(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizationRecordContainerEntry(e,n){return e.setPosition(e.position()+WI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}optimizerName(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}runtimeOptimizationRecords(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new HI.RuntimeOptimizationRecord).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}runtimeOptimizationRecordsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizationRecordContainerEntry(e){e.startObject(2)}static addOptimizerName(e,n){e.addFieldOffset(0,n,0)}static addRuntimeOptimizationRecords(e,n){e.addFieldOffset(1,n,0)}static createRuntimeOptimizationRecordsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startRuntimeOptimizationRecordsVector(e,n){e.startVector(4,n,4)}static endRuntimeOptimizationRecordContainerEntry(e){let n=e.endObject();return e.requiredField(n,4),n}static createRuntimeOptimizationRecordContainerEntry(e,n,t){return r.startRuntimeOptimizationRecordContainerEntry(e),r.addOptimizerName(e,n),r.addRuntimeOptimizationRecords(e,t),r.endRuntimeOptimizationRecordContainerEntry(e)}};dn.RuntimeOptimizationRecordContainerEntry=lu});var pu=re(pn=>{"use strict";var qI=pn&&pn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),jI=pn&&pn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),KI=pn&&pn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&qI(e,r,n);return jI(e,r),e};Object.defineProperty(pn,"__esModule",{value:!0});pn.RuntimeOptimizations=void 0;var XI=KI(Re()),ZI=cu(),du=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsRuntimeOptimizations(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsRuntimeOptimizations(e,n){return e.setPosition(e.position()+XI.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}records(e,n){let t=this.bb.__offset(this.bb_pos,4);return t?(n||new ZI.RuntimeOptimizationRecordContainerEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}recordsLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startRuntimeOptimizations(e){e.startObject(1)}static addRecords(e,n){e.addFieldOffset(0,n,0)}static createRecordsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startRecordsVector(e,n){e.startVector(4,n,4)}static endRuntimeOptimizations(e){return e.endObject()}static createRuntimeOptimizations(e,n){return r.startRuntimeOptimizations(e),r.addRecords(e,n),r.endRuntimeOptimizations(e)}};pn.RuntimeOptimizations=du});var xo=re(Oi=>{"use strict";Object.defineProperty(Oi,"__esModule",{value:!0});Oi.TensorDataType=void 0;var Ff;(function(r){r[r.UNDEFINED=0]="UNDEFINED",r[r.FLOAT=1]="FLOAT",r[r.UINT8=2]="UINT8",r[r.INT8=3]="INT8",r[r.UINT16=4]="UINT16",r[r.INT16=5]="INT16",r[r.INT32=6]="INT32",r[r.INT64=7]="INT64",r[r.STRING=8]="STRING",r[r.BOOL=9]="BOOL",r[r.FLOAT16=10]="FLOAT16",r[r.DOUBLE=11]="DOUBLE",r[r.UINT32=12]="UINT32",r[r.UINT64=13]="UINT64",r[r.COMPLEX64=14]="COMPLEX64",r[r.COMPLEX128=15]="COMPLEX128",r[r.BFLOAT16=16]="BFLOAT16",r[r.FLOAT8E4M3FN=17]="FLOAT8E4M3FN",r[r.FLOAT8E4M3FNUZ=18]="FLOAT8E4M3FNUZ",r[r.FLOAT8E5M2=19]="FLOAT8E5M2",r[r.FLOAT8E5M2FNUZ=20]="FLOAT8E5M2FNUZ"})(Ff||(Oi.TensorDataType=Ff={}))});var To=re(fn=>{"use strict";var JI=fn&&fn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),YI=fn&&fn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),QI=fn&&fn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&JI(e,r,n);return YI(e,r),e};Object.defineProperty(fn,"__esModule",{value:!0});fn.Tensor=void 0;var e1=QI(Re()),Vf=xo(),fu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsTensor(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTensor(e,n){return e.setPosition(e.position()+e1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}name(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}docString(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}dims(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+e*8):BigInt(0)}dimsLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}dataType(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readInt32(this.bb_pos+e):Vf.TensorDataType.UNDEFINED}rawData(e){let n=this.bb.__offset(this.bb_pos,12);return n?this.bb.readUint8(this.bb.__vector(this.bb_pos+n)+e):0}rawDataLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}rawDataArray(){let e=this.bb.__offset(this.bb_pos,12);return e?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}stringData(e,n){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}stringDataLength(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__vector_len(this.bb_pos+e):0}externalDataOffset(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readInt64(this.bb_pos+e):BigInt("-1")}static startTensor(e){e.startObject(7)}static addName(e,n){e.addFieldOffset(0,n,0)}static addDocString(e,n){e.addFieldOffset(1,n,0)}static addDims(e,n){e.addFieldOffset(2,n,0)}static createDimsVector(e,n){e.startVector(8,n.length,8);for(let t=n.length-1;t>=0;t--)e.addInt64(n[t]);return e.endVector()}static startDimsVector(e,n){e.startVector(8,n,8)}static addDataType(e,n){e.addFieldInt32(3,n,Vf.TensorDataType.UNDEFINED)}static addRawData(e,n){e.addFieldOffset(4,n,0)}static createRawDataVector(e,n){e.startVector(1,n.length,1);for(let t=n.length-1;t>=0;t--)e.addInt8(n[t]);return e.endVector()}static startRawDataVector(e,n){e.startVector(1,n,1)}static addStringData(e,n){e.addFieldOffset(5,n,0)}static createStringDataVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startStringDataVector(e,n){e.startVector(4,n,4)}static addExternalDataOffset(e,n){e.addFieldInt64(6,n,BigInt("-1"))}static endTensor(e){return e.endObject()}static createTensor(e,n,t,o,i,a,s,u){return r.startTensor(e),r.addName(e,n),r.addDocString(e,t),r.addDims(e,o),r.addDataType(e,i),r.addRawData(e,a),r.addStringData(e,s),r.addExternalDataOffset(e,u),r.endTensor(e)}};fn.Tensor=fu});var mu=re(hn=>{"use strict";var t1=hn&&hn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),n1=hn&&hn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),r1=hn&&hn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&t1(e,r,n);return n1(e,r),e};Object.defineProperty(hn,"__esModule",{value:!0});hn.SparseTensor=void 0;var o1=r1(Re()),Gf=To(),hu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsSparseTensor(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSparseTensor(e,n){return e.setPosition(e.position()+o1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}values(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new Gf.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}indices(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new Gf.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}dims(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+e*8):BigInt(0)}dimsLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}static startSparseTensor(e){e.startObject(3)}static addValues(e,n){e.addFieldOffset(0,n,0)}static addIndices(e,n){e.addFieldOffset(1,n,0)}static addDims(e,n){e.addFieldOffset(2,n,0)}static createDimsVector(e,n){e.startVector(8,n.length,8);for(let t=n.length-1;t>=0;t--)e.addInt64(n[t]);return e.endVector()}static startDimsVector(e,n){e.startVector(8,n,8)}static endSparseTensor(e){return e.endObject()}};hn.SparseTensor=hu});var bu=re(mn=>{"use strict";var i1=mn&&mn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),a1=mn&&mn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),s1=mn&&mn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&i1(e,r,n);return a1(e,r),e};Object.defineProperty(mn,"__esModule",{value:!0});mn.MapType=void 0;var u1=s1(Re()),Uf=xo(),l1=Io(),gu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsMapType(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsMapType(e,n){return e.setPosition(e.position()+u1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}keyType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):Uf.TensorDataType.UNDEFINED}valueType(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new l1.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startMapType(e){e.startObject(2)}static addKeyType(e,n){e.addFieldInt32(0,n,Uf.TensorDataType.UNDEFINED)}static addValueType(e,n){e.addFieldOffset(1,n,0)}static endMapType(e){return e.endObject()}};mn.MapType=gu});var _u=re(gn=>{"use strict";var c1=gn&&gn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),d1=gn&&gn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),p1=gn&&gn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&c1(e,r,n);return d1(e,r),e};Object.defineProperty(gn,"__esModule",{value:!0});gn.SequenceType=void 0;var f1=p1(Re()),h1=Io(),yu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsSequenceType(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsSequenceType(e,n){return e.setPosition(e.position()+f1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}elemType(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new h1.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startSequenceType(e){e.startObject(1)}static addElemType(e,n){e.addFieldOffset(0,n,0)}static endSequenceType(e){return e.endObject()}static createSequenceType(e,n){return r.startSequenceType(e),r.addElemType(e,n),r.endSequenceType(e)}};gn.SequenceType=yu});var wu=re(Pi=>{"use strict";Object.defineProperty(Pi,"__esModule",{value:!0});Pi.DimensionValueType=void 0;var Wf;(function(r){r[r.UNKNOWN=0]="UNKNOWN",r[r.VALUE=1]="VALUE",r[r.PARAM=2]="PARAM"})(Wf||(Pi.DimensionValueType=Wf={}))});var xu=re(bn=>{"use strict";var m1=bn&&bn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),g1=bn&&bn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),b1=bn&&bn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&m1(e,r,n);return g1(e,r),e};Object.defineProperty(bn,"__esModule",{value:!0});bn.DimensionValue=void 0;var y1=b1(Re()),Hf=wu(),vu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDimensionValue(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDimensionValue(e,n){return e.setPosition(e.position()+y1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}dimType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt8(this.bb_pos+e):Hf.DimensionValueType.UNKNOWN}dimValue(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}dimParam(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,e):null}static startDimensionValue(e){e.startObject(3)}static addDimType(e,n){e.addFieldInt8(0,n,Hf.DimensionValueType.UNKNOWN)}static addDimValue(e,n){e.addFieldInt64(1,n,BigInt("0"))}static addDimParam(e,n){e.addFieldOffset(2,n,0)}static endDimensionValue(e){return e.endObject()}static createDimensionValue(e,n,t,o){return r.startDimensionValue(e),r.addDimType(e,n),r.addDimValue(e,t),r.addDimParam(e,o),r.endDimensionValue(e)}};bn.DimensionValue=vu});var Iu=re(yn=>{"use strict";var _1=yn&&yn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),w1=yn&&yn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),v1=yn&&yn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&_1(e,r,n);return w1(e,r),e};Object.defineProperty(yn,"__esModule",{value:!0});yn.Dimension=void 0;var x1=v1(Re()),T1=xu(),Tu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDimension(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDimension(e,n){return e.setPosition(e.position()+x1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}value(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new T1.DimensionValue).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}denotation(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}static startDimension(e){e.startObject(2)}static addValue(e,n){e.addFieldOffset(0,n,0)}static addDenotation(e,n){e.addFieldOffset(1,n,0)}static endDimension(e){return e.endObject()}static createDimension(e,n,t){return r.startDimension(e),r.addValue(e,n),r.addDenotation(e,t),r.endDimension(e)}};yn.Dimension=Tu});var $u=re(_n=>{"use strict";var I1=_n&&_n.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),S1=_n&&_n.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),$1=_n&&_n.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&I1(e,r,n);return S1(e,r),e};Object.defineProperty(_n,"__esModule",{value:!0});_n.Shape=void 0;var A1=$1(Re()),O1=Iu(),Su=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsShape(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsShape(e,n){return e.setPosition(e.position()+A1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}dim(e,n){let t=this.bb.__offset(this.bb_pos,4);return t?(n||new O1.Dimension).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}dimLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startShape(e){e.startObject(1)}static addDim(e,n){e.addFieldOffset(0,n,0)}static createDimVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startDimVector(e,n){e.startVector(4,n,4)}static endShape(e){return e.endObject()}static createShape(e,n){return r.startShape(e),r.addDim(e,n),r.endShape(e)}};_n.Shape=Su});var Ou=re(wn=>{"use strict";var P1=wn&&wn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),E1=wn&&wn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),C1=wn&&wn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&P1(e,r,n);return E1(e,r),e};Object.defineProperty(wn,"__esModule",{value:!0});wn.TensorTypeAndShape=void 0;var D1=C1(Re()),k1=$u(),qf=xo(),Au=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsTensorTypeAndShape(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTensorTypeAndShape(e,n){return e.setPosition(e.position()+D1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}elemType(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt32(this.bb_pos+e):qf.TensorDataType.UNDEFINED}shape(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new k1.Shape).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startTensorTypeAndShape(e){e.startObject(2)}static addElemType(e,n){e.addFieldInt32(0,n,qf.TensorDataType.UNDEFINED)}static addShape(e,n){e.addFieldOffset(1,n,0)}static endTensorTypeAndShape(e){return e.endObject()}};wn.TensorTypeAndShape=Au});var Pu=re(dr=>{"use strict";Object.defineProperty(dr,"__esModule",{value:!0});dr.unionListToTypeInfoValue=dr.unionToTypeInfoValue=dr.TypeInfoValue=void 0;var jf=bu(),Kf=_u(),Xf=Ou(),Ei;(function(r){r[r.NONE=0]="NONE",r[r.tensor_type=1]="tensor_type",r[r.sequence_type=2]="sequence_type",r[r.map_type=3]="map_type"})(Ei||(dr.TypeInfoValue=Ei={}));function N1(r,e){switch(Ei[r]){case"NONE":return null;case"tensor_type":return e(new Xf.TensorTypeAndShape);case"sequence_type":return e(new Kf.SequenceType);case"map_type":return e(new jf.MapType);default:return null}}dr.unionToTypeInfoValue=N1;function L1(r,e,n){switch(Ei[r]){case"NONE":return null;case"tensor_type":return e(n,new Xf.TensorTypeAndShape);case"sequence_type":return e(n,new Kf.SequenceType);case"map_type":return e(n,new jf.MapType);default:return null}}dr.unionListToTypeInfoValue=L1});var Io=re(vn=>{"use strict";var R1=vn&&vn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),z1=vn&&vn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),M1=vn&&vn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&R1(e,r,n);return z1(e,r),e};Object.defineProperty(vn,"__esModule",{value:!0});vn.TypeInfo=void 0;var B1=M1(Re()),Zf=Pu(),Eu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsTypeInfo(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsTypeInfo(e,n){return e.setPosition(e.position()+B1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}denotation(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}valueType(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint8(this.bb_pos+e):Zf.TypeInfoValue.NONE}value(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__union(e,this.bb_pos+n):null}static startTypeInfo(e){e.startObject(3)}static addDenotation(e,n){e.addFieldOffset(0,n,0)}static addValueType(e,n){e.addFieldInt8(1,n,Zf.TypeInfoValue.NONE)}static addValue(e,n){e.addFieldOffset(2,n,0)}static endTypeInfo(e){return e.endObject()}static createTypeInfo(e,n,t,o){return r.startTypeInfo(e),r.addDenotation(e,n),r.addValueType(e,t),r.addValue(e,o),r.endTypeInfo(e)}};vn.TypeInfo=Eu});var Du=re(xn=>{"use strict";var F1=xn&&xn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),V1=xn&&xn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),G1=xn&&xn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&F1(e,r,n);return V1(e,r),e};Object.defineProperty(xn,"__esModule",{value:!0});xn.ValueInfo=void 0;var U1=G1(Re()),W1=Io(),Cu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsValueInfo(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsValueInfo(e,n){return e.setPosition(e.position()+U1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}name(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}docString(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}type(e){let n=this.bb.__offset(this.bb_pos,8);return n?(e||new W1.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startValueInfo(e){e.startObject(3)}static addName(e,n){e.addFieldOffset(0,n,0)}static addDocString(e,n){e.addFieldOffset(1,n,0)}static addType(e,n){e.addFieldOffset(2,n,0)}static endValueInfo(e){return e.endObject()}};xn.ValueInfo=Cu});var Ci=re(Tn=>{"use strict";var H1=Tn&&Tn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),q1=Tn&&Tn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),j1=Tn&&Tn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&H1(e,r,n);return q1(e,r),e};Object.defineProperty(Tn,"__esModule",{value:!0});Tn.Graph=void 0;var K1=j1(Re()),X1=Qs(),Z1=ou(),J1=pu(),Y1=mu(),Q1=To(),eS=Du(),ku=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsGraph(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsGraph(e,n){return e.setPosition(e.position()+K1.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}initializers(e,n){let t=this.bb.__offset(this.bb_pos,4);return t?(n||new Q1.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}initializersLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeArgs(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new eS.ValueInfo).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodeArgsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}nodes(e,n){let t=this.bb.__offset(this.bb_pos,8);return t?(n||new X1.Node).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodesLength(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.__vector_len(this.bb_pos+e):0}maxNodeIndex(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readUint32(this.bb_pos+e):0}nodeEdges(e,n){let t=this.bb.__offset(this.bb_pos,12);return t?(n||new Z1.NodeEdge).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}nodeEdgesLength(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.__vector_len(this.bb_pos+e):0}inputs(e,n){let t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}inputsLength(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.__vector_len(this.bb_pos+e):0}outputs(e,n){let t=this.bb.__offset(this.bb_pos,16);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}outputsLength(){let e=this.bb.__offset(this.bb_pos,16);return e?this.bb.__vector_len(this.bb_pos+e):0}sparseInitializers(e,n){let t=this.bb.__offset(this.bb_pos,18);return t?(n||new Y1.SparseTensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}sparseInitializersLength(){let e=this.bb.__offset(this.bb_pos,18);return e?this.bb.__vector_len(this.bb_pos+e):0}runtimeOptimizations(e){let n=this.bb.__offset(this.bb_pos,20);return n?(e||new J1.RuntimeOptimizations).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startGraph(e){e.startObject(9)}static addInitializers(e,n){e.addFieldOffset(0,n,0)}static createInitializersVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startInitializersVector(e,n){e.startVector(4,n,4)}static addNodeArgs(e,n){e.addFieldOffset(1,n,0)}static createNodeArgsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startNodeArgsVector(e,n){e.startVector(4,n,4)}static addNodes(e,n){e.addFieldOffset(2,n,0)}static createNodesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startNodesVector(e,n){e.startVector(4,n,4)}static addMaxNodeIndex(e,n){e.addFieldInt32(3,n,0)}static addNodeEdges(e,n){e.addFieldOffset(4,n,0)}static createNodeEdgesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startNodeEdgesVector(e,n){e.startVector(4,n,4)}static addInputs(e,n){e.addFieldOffset(5,n,0)}static createInputsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startInputsVector(e,n){e.startVector(4,n,4)}static addOutputs(e,n){e.addFieldOffset(6,n,0)}static createOutputsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startOutputsVector(e,n){e.startVector(4,n,4)}static addSparseInitializers(e,n){e.addFieldOffset(7,n,0)}static createSparseInitializersVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startSparseInitializersVector(e,n){e.startVector(4,n,4)}static addRuntimeOptimizations(e,n){e.addFieldOffset(8,n,0)}static endGraph(e){return e.endObject()}};Tn.Graph=ku});var eu=re(In=>{"use strict";var tS=In&&In.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),nS=In&&In.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),rS=In&&In.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&tS(e,r,n);return nS(e,r),e};Object.defineProperty(In,"__esModule",{value:!0});In.Attribute=void 0;var oS=rS(Re()),Jf=Zs(),Yf=Ci(),Qf=To(),Nu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsAttribute(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsAttribute(e,n){return e.setPosition(e.position()+oS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}name(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}docString(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}type(){let e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt32(this.bb_pos+e):Jf.AttributeType.UNDEFINED}f(){let e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readFloat32(this.bb_pos+e):0}i(){let e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}s(e){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb_pos+n,e):null}t(e){let n=this.bb.__offset(this.bb_pos,16);return n?(e||new Qf.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}g(e){let n=this.bb.__offset(this.bb_pos,18);return n?(e||new Yf.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}floats(e){let n=this.bb.__offset(this.bb_pos,20);return n?this.bb.readFloat32(this.bb.__vector(this.bb_pos+n)+e*4):0}floatsLength(){let e=this.bb.__offset(this.bb_pos,20);return e?this.bb.__vector_len(this.bb_pos+e):0}floatsArray(){let e=this.bb.__offset(this.bb_pos,20);return e?new Float32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}ints(e){let n=this.bb.__offset(this.bb_pos,22);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+e*8):BigInt(0)}intsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}strings(e,n){let t=this.bb.__offset(this.bb_pos,24);return t?this.bb.__string(this.bb.__vector(this.bb_pos+t)+e*4,n):null}stringsLength(){let e=this.bb.__offset(this.bb_pos,24);return e?this.bb.__vector_len(this.bb_pos+e):0}tensors(e,n){let t=this.bb.__offset(this.bb_pos,26);return t?(n||new Qf.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}tensorsLength(){let e=this.bb.__offset(this.bb_pos,26);return e?this.bb.__vector_len(this.bb_pos+e):0}graphs(e,n){let t=this.bb.__offset(this.bb_pos,28);return t?(n||new Yf.Graph).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}graphsLength(){let e=this.bb.__offset(this.bb_pos,28);return e?this.bb.__vector_len(this.bb_pos+e):0}static startAttribute(e){e.startObject(13)}static addName(e,n){e.addFieldOffset(0,n,0)}static addDocString(e,n){e.addFieldOffset(1,n,0)}static addType(e,n){e.addFieldInt32(2,n,Jf.AttributeType.UNDEFINED)}static addF(e,n){e.addFieldFloat32(3,n,0)}static addI(e,n){e.addFieldInt64(4,n,BigInt("0"))}static addS(e,n){e.addFieldOffset(5,n,0)}static addT(e,n){e.addFieldOffset(6,n,0)}static addG(e,n){e.addFieldOffset(7,n,0)}static addFloats(e,n){e.addFieldOffset(8,n,0)}static createFloatsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addFloat32(n[t]);return e.endVector()}static startFloatsVector(e,n){e.startVector(4,n,4)}static addInts(e,n){e.addFieldOffset(9,n,0)}static createIntsVector(e,n){e.startVector(8,n.length,8);for(let t=n.length-1;t>=0;t--)e.addInt64(n[t]);return e.endVector()}static startIntsVector(e,n){e.startVector(8,n,8)}static addStrings(e,n){e.addFieldOffset(10,n,0)}static createStringsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startStringsVector(e,n){e.startVector(4,n,4)}static addTensors(e,n){e.addFieldOffset(11,n,0)}static createTensorsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startTensorsVector(e,n){e.startVector(4,n,4)}static addGraphs(e,n){e.addFieldOffset(12,n,0)}static createGraphsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startGraphsVector(e,n){e.startVector(4,n,4)}static endAttribute(e){return e.endObject()}};In.Attribute=Nu});var Ru=re(Sn=>{"use strict";var iS=Sn&&Sn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),aS=Sn&&Sn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),sS=Sn&&Sn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&iS(e,r,n);return aS(e,r),e};Object.defineProperty(Sn,"__esModule",{value:!0});Sn.DeprecatedKernelCreateInfos=void 0;var uS=sS(Re()),Lu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDeprecatedKernelCreateInfos(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedKernelCreateInfos(e,n){return e.setPosition(e.position()+uS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}nodeIndices(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.readUint32(this.bb.__vector(this.bb_pos+n)+e*4):0}nodeIndicesLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}nodeIndicesArray(){let e=this.bb.__offset(this.bb_pos,4);return e?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+e),this.bb.__vector_len(this.bb_pos+e)):null}kernelDefHashes(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.readUint64(this.bb.__vector(this.bb_pos+n)+e*8):BigInt(0)}kernelDefHashesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startDeprecatedKernelCreateInfos(e){e.startObject(2)}static addNodeIndices(e,n){e.addFieldOffset(0,n,0)}static createNodeIndicesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addInt32(n[t]);return e.endVector()}static startNodeIndicesVector(e,n){e.startVector(4,n,4)}static addKernelDefHashes(e,n){e.addFieldOffset(1,n,0)}static createKernelDefHashesVector(e,n){e.startVector(8,n.length,8);for(let t=n.length-1;t>=0;t--)e.addInt64(n[t]);return e.endVector()}static startKernelDefHashesVector(e,n){e.startVector(8,n,8)}static endDeprecatedKernelCreateInfos(e){return e.endObject()}static createDeprecatedKernelCreateInfos(e,n,t){return r.startDeprecatedKernelCreateInfos(e),r.addNodeIndices(e,n),r.addKernelDefHashes(e,t),r.endDeprecatedKernelCreateInfos(e)}};Sn.DeprecatedKernelCreateInfos=Lu});var eh=re($n=>{"use strict";var lS=$n&&$n.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),cS=$n&&$n.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),dS=$n&&$n.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&lS(e,r,n);return cS(e,r),e};Object.defineProperty($n,"__esModule",{value:!0});$n.DeprecatedNodeIndexAndKernelDefHash=void 0;var pS=dS(Re()),zu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDeprecatedNodeIndexAndKernelDefHash(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedNodeIndexAndKernelDefHash(e,n){return e.setPosition(e.position()+pS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}nodeIndex(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb_pos+e):0}kernelDefHash(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint64(this.bb_pos+e):BigInt("0")}static startDeprecatedNodeIndexAndKernelDefHash(e){e.startObject(2)}static addNodeIndex(e,n){e.addFieldInt32(0,n,0)}static addKernelDefHash(e,n){e.addFieldInt64(1,n,BigInt("0"))}static endDeprecatedNodeIndexAndKernelDefHash(e){return e.endObject()}static createDeprecatedNodeIndexAndKernelDefHash(e,n,t){return r.startDeprecatedNodeIndexAndKernelDefHash(e),r.addNodeIndex(e,n),r.addKernelDefHash(e,t),r.endDeprecatedNodeIndexAndKernelDefHash(e)}};$n.DeprecatedNodeIndexAndKernelDefHash=zu});var Bu=re(An=>{"use strict";var fS=An&&An.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),hS=An&&An.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),mS=An&&An.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&fS(e,r,n);return hS(e,r),e};Object.defineProperty(An,"__esModule",{value:!0});An.DeprecatedSubGraphSessionState=void 0;var gS=mS(Re()),bS=Fu(),Mu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDeprecatedSubGraphSessionState(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedSubGraphSessionState(e,n){return e.setPosition(e.position()+gS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}graphId(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}sessionState(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new bS.DeprecatedSessionState).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startDeprecatedSubGraphSessionState(e){e.startObject(2)}static addGraphId(e,n){e.addFieldOffset(0,n,0)}static addSessionState(e,n){e.addFieldOffset(1,n,0)}static endDeprecatedSubGraphSessionState(e){let n=e.endObject();return e.requiredField(n,4),n}};An.DeprecatedSubGraphSessionState=Mu});var Fu=re(On=>{"use strict";var yS=On&&On.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),_S=On&&On.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),wS=On&&On.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&yS(e,r,n);return _S(e,r),e};Object.defineProperty(On,"__esModule",{value:!0});On.DeprecatedSessionState=void 0;var vS=wS(Re()),xS=Ru(),TS=Bu(),Vu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsDeprecatedSessionState(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsDeprecatedSessionState(e,n){return e.setPosition(e.position()+vS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}kernels(e){let n=this.bb.__offset(this.bb_pos,4);return n?(e||new xS.DeprecatedKernelCreateInfos).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}subGraphSessionStates(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new TS.DeprecatedSubGraphSessionState).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}subGraphSessionStatesLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startDeprecatedSessionState(e){e.startObject(2)}static addKernels(e,n){e.addFieldOffset(0,n,0)}static addSubGraphSessionStates(e,n){e.addFieldOffset(1,n,0)}static createSubGraphSessionStatesVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startSubGraphSessionStatesVector(e,n){e.startVector(4,n,4)}static endDeprecatedSessionState(e){return e.endObject()}static createDeprecatedSessionState(e,n,t){return r.startDeprecatedSessionState(e),r.addKernels(e,n),r.addSubGraphSessionStates(e,t),r.endDeprecatedSessionState(e)}};On.DeprecatedSessionState=Vu});var Uu=re(Pn=>{"use strict";var IS=Pn&&Pn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),SS=Pn&&Pn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),$S=Pn&&Pn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&IS(e,r,n);return SS(e,r),e};Object.defineProperty(Pn,"__esModule",{value:!0});Pn.KernelTypeStrArgsEntry=void 0;var AS=$S(Re()),OS=Xs(),Gu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsKernelTypeStrArgsEntry(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsKernelTypeStrArgsEntry(e,n){return e.setPosition(e.position()+AS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}kernelTypeStr(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}args(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new OS.ArgTypeAndIndex).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}argsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startKernelTypeStrArgsEntry(e){e.startObject(2)}static addKernelTypeStr(e,n){e.addFieldOffset(0,n,0)}static addArgs(e,n){e.addFieldOffset(1,n,0)}static createArgsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startArgsVector(e,n){e.startVector(4,n,4)}static endKernelTypeStrArgsEntry(e){let n=e.endObject();return e.requiredField(n,4),n}static createKernelTypeStrArgsEntry(e,n,t){return r.startKernelTypeStrArgsEntry(e),r.addKernelTypeStr(e,n),r.addArgs(e,t),r.endKernelTypeStrArgsEntry(e)}};Pn.KernelTypeStrArgsEntry=Gu});var Hu=re(En=>{"use strict";var PS=En&&En.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),ES=En&&En.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),CS=En&&En.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&PS(e,r,n);return ES(e,r),e};Object.defineProperty(En,"__esModule",{value:!0});En.OpIdKernelTypeStrArgsEntry=void 0;var DS=CS(Re()),kS=Uu(),Wu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsOpIdKernelTypeStrArgsEntry(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsOpIdKernelTypeStrArgsEntry(e,n){return e.setPosition(e.position()+DS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}opId(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}kernelTypeStrArgs(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new kS.KernelTypeStrArgsEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}kernelTypeStrArgsLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}static startOpIdKernelTypeStrArgsEntry(e){e.startObject(2)}static addOpId(e,n){e.addFieldOffset(0,n,0)}static addKernelTypeStrArgs(e,n){e.addFieldOffset(1,n,0)}static createKernelTypeStrArgsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startKernelTypeStrArgsVector(e,n){e.startVector(4,n,4)}static endOpIdKernelTypeStrArgsEntry(e){let n=e.endObject();return e.requiredField(n,4),n}static createOpIdKernelTypeStrArgsEntry(e,n,t){return r.startOpIdKernelTypeStrArgsEntry(e),r.addOpId(e,n),r.addKernelTypeStrArgs(e,t),r.endOpIdKernelTypeStrArgsEntry(e)}};En.OpIdKernelTypeStrArgsEntry=Wu});var ju=re(Cn=>{"use strict";var NS=Cn&&Cn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),LS=Cn&&Cn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),RS=Cn&&Cn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&NS(e,r,n);return LS(e,r),e};Object.defineProperty(Cn,"__esModule",{value:!0});Cn.KernelTypeStrResolver=void 0;var zS=RS(Re()),MS=Hu(),qu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsKernelTypeStrResolver(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsKernelTypeStrResolver(e,n){return e.setPosition(e.position()+zS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}opKernelTypeStrArgs(e,n){let t=this.bb.__offset(this.bb_pos,4);return t?(n||new MS.OpIdKernelTypeStrArgsEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}opKernelTypeStrArgsLength(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__vector_len(this.bb_pos+e):0}static startKernelTypeStrResolver(e){e.startObject(1)}static addOpKernelTypeStrArgs(e,n){e.addFieldOffset(0,n,0)}static createOpKernelTypeStrArgsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startOpKernelTypeStrArgsVector(e,n){e.startVector(4,n,4)}static endKernelTypeStrResolver(e){return e.endObject()}static createKernelTypeStrResolver(e,n){return r.startKernelTypeStrResolver(e),r.addOpKernelTypeStrArgs(e,n),r.endKernelTypeStrResolver(e)}};Cn.KernelTypeStrResolver=qu});var Xu=re(Dn=>{"use strict";var BS=Dn&&Dn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),FS=Dn&&Dn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),VS=Dn&&Dn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&BS(e,r,n);return FS(e,r),e};Object.defineProperty(Dn,"__esModule",{value:!0});Dn.OperatorSetId=void 0;var GS=VS(Re()),Ku=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsOperatorSetId(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsOperatorSetId(e,n){return e.setPosition(e.position()+GS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}domain(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}version(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}static startOperatorSetId(e){e.startObject(2)}static addDomain(e,n){e.addFieldOffset(0,n,0)}static addVersion(e,n){e.addFieldInt64(1,n,BigInt("0"))}static endOperatorSetId(e){return e.endObject()}static createOperatorSetId(e,n,t){return r.startOperatorSetId(e),r.addDomain(e,n),r.addVersion(e,t),r.endOperatorSetId(e)}};Dn.OperatorSetId=Ku});var Ju=re(kn=>{"use strict";var US=kn&&kn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),WS=kn&&kn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),HS=kn&&kn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&US(e,r,n);return WS(e,r),e};Object.defineProperty(kn,"__esModule",{value:!0});kn.StringStringEntry=void 0;var qS=HS(Re()),Zu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsStringStringEntry(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsStringStringEntry(e,n){return e.setPosition(e.position()+qS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}key(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}value(e){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,e):null}static startStringStringEntry(e){e.startObject(2)}static addKey(e,n){e.addFieldOffset(0,n,0)}static addValue(e,n){e.addFieldOffset(1,n,0)}static endStringStringEntry(e){return e.endObject()}static createStringStringEntry(e,n,t){return r.startStringStringEntry(e),r.addKey(e,n),r.addValue(e,t),r.endStringStringEntry(e)}};kn.StringStringEntry=Zu});var Qu=re(Nn=>{"use strict";var jS=Nn&&Nn.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),KS=Nn&&Nn.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),XS=Nn&&Nn.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&jS(e,r,n);return KS(e,r),e};Object.defineProperty(Nn,"__esModule",{value:!0});Nn.Model=void 0;var ZS=XS(Re()),JS=Ci(),YS=Xu(),QS=Ju(),Yu=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsModel(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsModel(e,n){return e.setPosition(e.position()+ZS.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}irVersion(){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}opsetImport(e,n){let t=this.bb.__offset(this.bb_pos,6);return t?(n||new YS.OperatorSetId).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}opsetImportLength(){let e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__vector_len(this.bb_pos+e):0}producerName(e){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,e):null}producerVersion(e){let n=this.bb.__offset(this.bb_pos,10);return n?this.bb.__string(this.bb_pos+n,e):null}domain(e){let n=this.bb.__offset(this.bb_pos,12);return n?this.bb.__string(this.bb_pos+n,e):null}modelVersion(){let e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readInt64(this.bb_pos+e):BigInt("0")}docString(e){let n=this.bb.__offset(this.bb_pos,16);return n?this.bb.__string(this.bb_pos+n,e):null}graph(e){let n=this.bb.__offset(this.bb_pos,18);return n?(e||new JS.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}graphDocString(e){let n=this.bb.__offset(this.bb_pos,20);return n?this.bb.__string(this.bb_pos+n,e):null}metadataProps(e,n){let t=this.bb.__offset(this.bb_pos,22);return t?(n||new QS.StringStringEntry).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+t)+e*4),this.bb):null}metadataPropsLength(){let e=this.bb.__offset(this.bb_pos,22);return e?this.bb.__vector_len(this.bb_pos+e):0}static startModel(e){e.startObject(10)}static addIrVersion(e,n){e.addFieldInt64(0,n,BigInt("0"))}static addOpsetImport(e,n){e.addFieldOffset(1,n,0)}static createOpsetImportVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startOpsetImportVector(e,n){e.startVector(4,n,4)}static addProducerName(e,n){e.addFieldOffset(2,n,0)}static addProducerVersion(e,n){e.addFieldOffset(3,n,0)}static addDomain(e,n){e.addFieldOffset(4,n,0)}static addModelVersion(e,n){e.addFieldInt64(5,n,BigInt("0"))}static addDocString(e,n){e.addFieldOffset(6,n,0)}static addGraph(e,n){e.addFieldOffset(7,n,0)}static addGraphDocString(e,n){e.addFieldOffset(8,n,0)}static addMetadataProps(e,n){e.addFieldOffset(9,n,0)}static createMetadataPropsVector(e,n){e.startVector(4,n.length,4);for(let t=n.length-1;t>=0;t--)e.addOffset(n[t]);return e.endVector()}static startMetadataPropsVector(e,n){e.startVector(4,n,4)}static endModel(e){return e.endObject()}};Nn.Model=Yu});var th=re(Ln=>{"use strict";var e$=Ln&&Ln.__createBinding||(Object.create?function(r,e,n,t){t===void 0&&(t=n);var o=Object.getOwnPropertyDescriptor(e,n);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(r,t,o)}:function(r,e,n,t){t===void 0&&(t=n),r[t]=e[n]}),t$=Ln&&Ln.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),n$=Ln&&Ln.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var n in r)n!=="default"&&Object.prototype.hasOwnProperty.call(r,n)&&e$(e,r,n);return t$(e,r),e};Object.defineProperty(Ln,"__esModule",{value:!0});Ln.InferenceSession=void 0;var r$=n$(Re()),o$=ju(),i$=Qu(),el=class r{constructor(){this.bb=null,this.bb_pos=0}__init(e,n){return this.bb_pos=e,this.bb=n,this}static getRootAsInferenceSession(e,n){return(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsInferenceSession(e,n){return e.setPosition(e.position()+r$.SIZE_PREFIX_LENGTH),(n||new r).__init(e.readInt32(e.position())+e.position(),e)}static bufferHasIdentifier(e){return e.__has_identifier("ORTM")}ortVersion(e){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,e):null}model(e){let n=this.bb.__offset(this.bb_pos,6);return n?(e||new i$.Model).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}kernelTypeStrResolver(e){let n=this.bb.__offset(this.bb_pos,10);return n?(e||new o$.KernelTypeStrResolver).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startInferenceSession(e){e.startObject(4)}static addOrtVersion(e,n){e.addFieldOffset(0,n,0)}static addModel(e,n){e.addFieldOffset(1,n,0)}static addKernelTypeStrResolver(e,n){e.addFieldOffset(3,n,0)}static endInferenceSession(e){return e.endObject()}static finishInferenceSessionBuffer(e,n){e.finish(n,"ORTM")}static finishSizePrefixedInferenceSessionBuffer(e,n){e.finish(n,"ORTM",!0)}};Ln.InferenceSession=el});var a$,s$,Di,Rt,u$,l$,c$,d$,p$,f$,h$,m$,tl,nl,g$,b$,y$,_$,rl,w$,v$,x$,T$,I$,S$,$$,A$,O$,P$,E$,C$,D$,So,ol,k$,il,N$,nh=N(()=>{"use strict";a$=ye(Gs()),s$=ye(Xs()),Di=ye(eu()),Rt=ye(Zs()),u$=ye(Ru()),l$=ye(eh()),c$=ye(Fu()),d$=ye(Bu()),p$=ye(Iu()),f$=ye(xu()),h$=ye(wu()),m$=ye(nu()),tl=ye(Ci()),nl=ye(th()),g$=ye(Uu()),b$=ye(ju()),y$=ye(bu()),_$=ye(Qu()),rl=ye(Qs()),w$=ye(ou()),v$=ye(Js()),x$=ye(au()),T$=ye(Hu()),I$=ye(Xu()),S$=ye(uu()),$$=ye(cu()),A$=ye(pu()),O$=ye(_u()),P$=ye($u()),E$=ye(mu()),C$=ye(Ju()),D$=ye(To()),So=ye(xo()),ol=ye(Ou()),k$=ye(Io()),il=ye(Pu()),N$=ye(Du())});var $o=N(()=>{"use strict";nh()});var oh=re((c4,rh)=>{"use strict";rh.exports=L$;function L$(r,e){for(var n=new Array(arguments.length-1),t=0,o=2,i=!0;o{"use strict";var Ni=sh;Ni.length=function(e){var n=e.length;if(!n)return 0;for(var t=0;--n%4>1&&e.charAt(n)==="=";)++t;return Math.ceil(e.length*3)/4-t};var Yr=new Array(64),ah=new Array(123);for(qt=0;qt<64;)ah[Yr[qt]=qt<26?qt+65:qt<52?qt+71:qt<62?qt-4:qt-59|43]=qt++;var qt;Ni.encode=function(e,n,t){for(var o=null,i=[],a=0,s=0,u;n>2],u=(l&3)<<4,s=1;break;case 1:i[a++]=Yr[u|l>>4],u=(l&15)<<2,s=2;break;case 2:i[a++]=Yr[u|l>>6],i[a++]=Yr[l&63],s=0;break}a>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,i)),a=0)}return s&&(i[a++]=Yr[u],i[a++]=61,s===1&&(i[a++]=61)),o?(a&&o.push(String.fromCharCode.apply(String,i.slice(0,a))),o.join("")):String.fromCharCode.apply(String,i.slice(0,a))};var ih="invalid encoding";Ni.decode=function(e,n,t){for(var o=t,i=0,a,s=0;s1)break;if((u=ah[u])===void 0)throw Error(ih);switch(i){case 0:a=u,i=1;break;case 1:n[t++]=a<<2|(u&48)>>4,a=u,i=2;break;case 2:n[t++]=(a&15)<<4|(u&60)>>2,a=u,i=3;break;case 3:n[t++]=(a&3)<<6|u,i=0;break}}if(i===1)throw Error(ih);return t-o};Ni.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}});var ch=re((p4,lh)=>{"use strict";lh.exports=Li;function Li(){this._listeners={}}Li.prototype.on=function(e,n,t){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:n,ctx:t||this}),this};Li.prototype.off=function(e,n){if(e===void 0)this._listeners={};else if(n===void 0)this._listeners[e]=[];else for(var t=this._listeners[e],o=0;o{"use strict";gh.exports=dh(dh);function dh(r){return typeof Float32Array<"u"?function(){var e=new Float32Array([-0]),n=new Uint8Array(e.buffer),t=n[3]===128;function o(u,l,d){e[0]=u,l[d]=n[0],l[d+1]=n[1],l[d+2]=n[2],l[d+3]=n[3]}function i(u,l,d){e[0]=u,l[d]=n[3],l[d+1]=n[2],l[d+2]=n[1],l[d+3]=n[0]}r.writeFloatLE=t?o:i,r.writeFloatBE=t?i:o;function a(u,l){return n[0]=u[l],n[1]=u[l+1],n[2]=u[l+2],n[3]=u[l+3],e[0]}function s(u,l){return n[3]=u[l],n[2]=u[l+1],n[1]=u[l+2],n[0]=u[l+3],e[0]}r.readFloatLE=t?a:s,r.readFloatBE=t?s:a}():function(){function e(t,o,i,a){var s=o<0?1:0;if(s&&(o=-o),o===0)t(1/o>0?0:2147483648,i,a);else if(isNaN(o))t(2143289344,i,a);else if(o>34028234663852886e22)t((s<<31|2139095040)>>>0,i,a);else if(o<11754943508222875e-54)t((s<<31|Math.round(o/1401298464324817e-60))>>>0,i,a);else{var u=Math.floor(Math.log(o)/Math.LN2),l=Math.round(o*Math.pow(2,-u)*8388608)&8388607;t((s<<31|u+127<<23|l)>>>0,i,a)}}r.writeFloatLE=e.bind(null,ph),r.writeFloatBE=e.bind(null,fh);function n(t,o,i){var a=t(o,i),s=(a>>31)*2+1,u=a>>>23&255,l=a&8388607;return u===255?l?NaN:s*(1/0):u===0?s*1401298464324817e-60*l:s*Math.pow(2,u-150)*(l+8388608)}r.readFloatLE=n.bind(null,hh),r.readFloatBE=n.bind(null,mh)}(),typeof Float64Array<"u"?function(){var e=new Float64Array([-0]),n=new Uint8Array(e.buffer),t=n[7]===128;function o(u,l,d){e[0]=u,l[d]=n[0],l[d+1]=n[1],l[d+2]=n[2],l[d+3]=n[3],l[d+4]=n[4],l[d+5]=n[5],l[d+6]=n[6],l[d+7]=n[7]}function i(u,l,d){e[0]=u,l[d]=n[7],l[d+1]=n[6],l[d+2]=n[5],l[d+3]=n[4],l[d+4]=n[3],l[d+5]=n[2],l[d+6]=n[1],l[d+7]=n[0]}r.writeDoubleLE=t?o:i,r.writeDoubleBE=t?i:o;function a(u,l){return n[0]=u[l],n[1]=u[l+1],n[2]=u[l+2],n[3]=u[l+3],n[4]=u[l+4],n[5]=u[l+5],n[6]=u[l+6],n[7]=u[l+7],e[0]}function s(u,l){return n[7]=u[l],n[6]=u[l+1],n[5]=u[l+2],n[4]=u[l+3],n[3]=u[l+4],n[2]=u[l+5],n[1]=u[l+6],n[0]=u[l+7],e[0]}r.readDoubleLE=t?a:s,r.readDoubleBE=t?s:a}():function(){function e(t,o,i,a,s,u){var l=a<0?1:0;if(l&&(a=-a),a===0)t(0,s,u+o),t(1/a>0?0:2147483648,s,u+i);else if(isNaN(a))t(0,s,u+o),t(2146959360,s,u+i);else if(a>17976931348623157e292)t(0,s,u+o),t((l<<31|2146435072)>>>0,s,u+i);else{var d;if(a<22250738585072014e-324)d=a/5e-324,t(d>>>0,s,u+o),t((l<<31|d/4294967296)>>>0,s,u+i);else{var p=Math.floor(Math.log(a)/Math.LN2);p===1024&&(p=1023),d=a*Math.pow(2,-p),t(d*4503599627370496>>>0,s,u+o),t((l<<31|p+1023<<20|d*1048576&1048575)>>>0,s,u+i)}}}r.writeDoubleLE=e.bind(null,ph,0,4),r.writeDoubleBE=e.bind(null,fh,4,0);function n(t,o,i,a,s){var u=t(a,s+o),l=t(a,s+i),d=(l>>31)*2+1,p=l>>>20&2047,h=4294967296*(l&1048575)+u;return p===2047?h?NaN:d*(1/0):p===0?d*5e-324*h:d*Math.pow(2,p-1075)*(h+4503599627370496)}r.readDoubleLE=n.bind(null,hh,0,4),r.readDoubleBE=n.bind(null,mh,4,0)}(),r}function ph(r,e,n){e[n]=r&255,e[n+1]=r>>>8&255,e[n+2]=r>>>16&255,e[n+3]=r>>>24}function fh(r,e,n){e[n]=r>>>24,e[n+1]=r>>>16&255,e[n+2]=r>>>8&255,e[n+3]=r&255}function hh(r,e){return(r[e]|r[e+1]<<8|r[e+2]<<16|r[e+3]<<24)>>>0}function mh(r,e){return(r[e]<<24|r[e+1]<<16|r[e+2]<<8|r[e+3])>>>0}});var yh=re((exports,module)=>{"use strict";module.exports=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(r){}return null}});var wh=re(_h=>{"use strict";var al=_h;al.length=function(e){for(var n=0,t=0,o=0;o191&&u<224?a[s++]=(u&31)<<6|e[n++]&63:u>239&&u<365?(u=((u&7)<<18|(e[n++]&63)<<12|(e[n++]&63)<<6|e[n++]&63)-65536,a[s++]=55296+(u>>10),a[s++]=56320+(u&1023)):a[s++]=(u&15)<<12|(e[n++]&63)<<6|e[n++]&63,s>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,a)),s=0);return i?(s&&i.push(String.fromCharCode.apply(String,a.slice(0,s))),i.join("")):String.fromCharCode.apply(String,a.slice(0,s))};al.write=function(e,n,t){for(var o=t,i,a,s=0;s>6|192,n[t++]=i&63|128):(i&64512)===55296&&((a=e.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(a&1023),++s,n[t++]=i>>18|240,n[t++]=i>>12&63|128,n[t++]=i>>6&63|128,n[t++]=i&63|128):(n[t++]=i>>12|224,n[t++]=i>>6&63|128,n[t++]=i&63|128);return t-o}});var xh=re((m4,vh)=>{"use strict";vh.exports=R$;function R$(r,e,n){var t=n||8192,o=t>>>1,i=null,a=t;return function(u){if(u<1||u>o)return r(u);a+u>t&&(i=r(t),a=0);var l=e.call(i,a,a+=u);return a&7&&(a=(a|7)+1),l}}});var Ih=re((g4,Th)=>{"use strict";Th.exports=ct;var Ao=fr();function ct(r,e){this.lo=r>>>0,this.hi=e>>>0}var Er=ct.zero=new ct(0,0);Er.toNumber=function(){return 0};Er.zzEncode=Er.zzDecode=function(){return this};Er.length=function(){return 1};var z$=ct.zeroHash="\0\0\0\0\0\0\0\0";ct.fromNumber=function(e){if(e===0)return Er;var n=e<0;n&&(e=-e);var t=e>>>0,o=(e-t)/4294967296>>>0;return n&&(o=~o>>>0,t=~t>>>0,++t>4294967295&&(t=0,++o>4294967295&&(o=0))),new ct(t,o)};ct.from=function(e){if(typeof e=="number")return ct.fromNumber(e);if(Ao.isString(e))if(Ao.Long)e=Ao.Long.fromString(e);else return ct.fromNumber(parseInt(e,10));return e.low||e.high?new ct(e.low>>>0,e.high>>>0):Er};ct.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var n=~this.lo+1>>>0,t=~this.hi>>>0;return n||(t=t+1>>>0),-(n+t*4294967296)}return this.lo+this.hi*4294967296};ct.prototype.toLong=function(e){return Ao.Long?new Ao.Long(this.lo|0,this.hi|0,!!e):{low:this.lo|0,high:this.hi|0,unsigned:!!e}};var pr=String.prototype.charCodeAt;ct.fromHash=function(e){return e===z$?Er:new ct((pr.call(e,0)|pr.call(e,1)<<8|pr.call(e,2)<<16|pr.call(e,3)<<24)>>>0,(pr.call(e,4)|pr.call(e,5)<<8|pr.call(e,6)<<16|pr.call(e,7)<<24)>>>0)};ct.prototype.toHash=function(){return String.fromCharCode(this.lo&255,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,this.hi&255,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)};ct.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this};ct.prototype.zzDecode=function(){var e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this};ct.prototype.length=function(){var e=this.lo,n=(this.lo>>>28|this.hi<<4)>>>0,t=this.hi>>>24;return t===0?n===0?e<16384?e<128?1:2:e<2097152?3:4:n<16384?n<128?5:6:n<2097152?7:8:t<128?9:10}});var fr=re(sl=>{"use strict";var ae=sl;ae.asPromise=oh();ae.base64=uh();ae.EventEmitter=ch();ae.float=bh();ae.inquire=yh();ae.utf8=wh();ae.pool=xh();ae.LongBits=Ih();ae.isNode=!!(typeof global<"u"&&global&&global.process&&global.process.versions&&global.process.versions.node);ae.global=ae.isNode&&global||typeof window<"u"&&window||typeof self<"u"&&self||sl;ae.emptyArray=Object.freeze?Object.freeze([]):[];ae.emptyObject=Object.freeze?Object.freeze({}):{};ae.isInteger=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};ae.isString=function(e){return typeof e=="string"||e instanceof String};ae.isObject=function(e){return e&&typeof e=="object"};ae.isset=ae.isSet=function(e,n){var t=e[n];return t!=null&&e.hasOwnProperty(n)?typeof t!="object"||(Array.isArray(t)?t.length:Object.keys(t).length)>0:!1};ae.Buffer=function(){try{var r=ae.inquire("buffer").Buffer;return r.prototype.utf8Write?r:null}catch{return null}}();ae._Buffer_from=null;ae._Buffer_allocUnsafe=null;ae.newBuffer=function(e){return typeof e=="number"?ae.Buffer?ae._Buffer_allocUnsafe(e):new ae.Array(e):ae.Buffer?ae._Buffer_from(e):typeof Uint8Array>"u"?e:new Uint8Array(e)};ae.Array=typeof Uint8Array<"u"?Uint8Array:Array;ae.Long=ae.global.dcodeIO&&ae.global.dcodeIO.Long||ae.global.Long||ae.inquire("long");ae.key2Re=/^true|false|0|1$/;ae.key32Re=/^-?(?:0|[1-9][0-9]*)$/;ae.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;ae.longToHash=function(e){return e?ae.LongBits.from(e).toHash():ae.LongBits.zeroHash};ae.longFromHash=function(e,n){var t=ae.LongBits.fromHash(e);return ae.Long?ae.Long.fromBits(t.lo,t.hi,n):t.toNumber(!!n)};function Sh(r,e,n){for(var t=Object.keys(e),o=0;o-1;--i)if(n[o[i]]===1&&this[o[i]]!==void 0&&this[o[i]]!==null)return o[i]}};ae.oneOfSetter=function(e){return function(n){for(var t=0;t{"use strict";Eh.exports=Ce;var zt=fr(),ul,Ri=zt.LongBits,Ah=zt.base64,Oh=zt.utf8;function Oo(r,e,n){this.fn=r,this.len=e,this.next=void 0,this.val=n}function cl(){}function M$(r){this.head=r.head,this.tail=r.tail,this.len=r.len,this.next=r.states}function Ce(){this.len=0,this.head=new Oo(cl,0,0),this.tail=this.head,this.states=null}var Ph=function(){return zt.Buffer?function(){return(Ce.create=function(){return new ul})()}:function(){return new Ce}};Ce.create=Ph();Ce.alloc=function(e){return new zt.Array(e)};zt.Array!==Array&&(Ce.alloc=zt.pool(Ce.alloc,zt.Array.prototype.subarray));Ce.prototype._push=function(e,n,t){return this.tail=this.tail.next=new Oo(e,n,t),this.len+=n,this};function dl(r,e,n){e[n]=r&255}function B$(r,e,n){for(;r>127;)e[n++]=r&127|128,r>>>=7;e[n]=r}function pl(r,e){this.len=r,this.next=void 0,this.val=e}pl.prototype=Object.create(Oo.prototype);pl.prototype.fn=B$;Ce.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new pl((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this};Ce.prototype.int32=function(e){return e<0?this._push(fl,10,Ri.fromNumber(e)):this.uint32(e)};Ce.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)};function fl(r,e,n){for(;r.hi;)e[n++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[n++]=r.lo&127|128,r.lo=r.lo>>>7;e[n++]=r.lo}Ce.prototype.uint64=function(e){var n=Ri.from(e);return this._push(fl,n.length(),n)};Ce.prototype.int64=Ce.prototype.uint64;Ce.prototype.sint64=function(e){var n=Ri.from(e).zzEncode();return this._push(fl,n.length(),n)};Ce.prototype.bool=function(e){return this._push(dl,1,e?1:0)};function ll(r,e,n){e[n]=r&255,e[n+1]=r>>>8&255,e[n+2]=r>>>16&255,e[n+3]=r>>>24}Ce.prototype.fixed32=function(e){return this._push(ll,4,e>>>0)};Ce.prototype.sfixed32=Ce.prototype.fixed32;Ce.prototype.fixed64=function(e){var n=Ri.from(e);return this._push(ll,4,n.lo)._push(ll,4,n.hi)};Ce.prototype.sfixed64=Ce.prototype.fixed64;Ce.prototype.float=function(e){return this._push(zt.float.writeFloatLE,4,e)};Ce.prototype.double=function(e){return this._push(zt.float.writeDoubleLE,8,e)};var F$=zt.Array.prototype.set?function(e,n,t){n.set(e,t)}:function(e,n,t){for(var o=0;o>>0;if(!n)return this._push(dl,1,0);if(zt.isString(e)){var t=Ce.alloc(n=Ah.length(e));Ah.decode(e,t,0),e=t}return this.uint32(n)._push(F$,n,e)};Ce.prototype.string=function(e){var n=Oh.length(e);return n?this.uint32(n)._push(Oh.write,n,e):this._push(dl,1,0)};Ce.prototype.fork=function(){return this.states=new M$(this),this.head=this.tail=new Oo(cl,0,0),this.len=0,this};Ce.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Oo(cl,0,0),this.len=0),this};Ce.prototype.ldelim=function(){var e=this.head,n=this.tail,t=this.len;return this.reset().uint32(t),t&&(this.tail.next=e.next,this.tail=n,this.len+=t),this};Ce.prototype.finish=function(){for(var e=this.head.next,n=this.constructor.alloc(this.len),t=0;e;)e.fn(e.val,n,t),t+=e.len,e=e.next;return n};Ce._configure=function(r){ul=r,Ce.create=Ph(),ul._configure()}});var kh=re((_4,Dh)=>{"use strict";Dh.exports=Rn;var Ch=hl();(Rn.prototype=Object.create(Ch.prototype)).constructor=Rn;var hr=fr();function Rn(){Ch.call(this)}Rn._configure=function(){Rn.alloc=hr._Buffer_allocUnsafe,Rn.writeBytesBuffer=hr.Buffer&&hr.Buffer.prototype instanceof Uint8Array&&hr.Buffer.prototype.set.name==="set"?function(e,n,t){n.set(e,t)}:function(e,n,t){if(e.copy)e.copy(n,t,0,e.length);else for(var o=0;o>>0;return this.uint32(n),n&&this._push(Rn.writeBytesBuffer,n,e),this};function V$(r,e,n){r.length<40?hr.utf8.write(r,e,n):e.utf8Write?e.utf8Write(r,n):e.write(r,n)}Rn.prototype.string=function(e){var n=hr.Buffer.byteLength(e);return this.uint32(n),n&&this._push(V$,n,e),this};Rn._configure()});var bl=re((w4,Mh)=>{"use strict";Mh.exports=et;var jt=fr(),gl,Rh=jt.LongBits,G$=jt.utf8;function Kt(r,e){return RangeError("index out of range: "+r.pos+" + "+(e||1)+" > "+r.len)}function et(r){this.buf=r,this.pos=0,this.len=r.length}var Nh=typeof Uint8Array<"u"?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new et(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new et(e);throw Error("illegal buffer")},zh=function(){return jt.Buffer?function(n){return(et.create=function(o){return jt.Buffer.isBuffer(o)?new gl(o):Nh(o)})(n)}:Nh};et.create=zh();et.prototype._slice=jt.Array.prototype.subarray||jt.Array.prototype.slice;et.prototype.uint32=function(){var e=4294967295;return function(){if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Kt(this,10);return e}}();et.prototype.int32=function(){return this.uint32()|0};et.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(e&1)|0};function ml(){var r=new Rh(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(r.lo=(r.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return r;if(r.lo=(r.lo|(this.buf[this.pos]&127)<<28)>>>0,r.hi=(r.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return r;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Kt(this);if(r.lo=(r.lo|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return r}return r.lo=(r.lo|(this.buf[this.pos++]&127)<>>0,r}if(this.len-this.pos>4){for(;e<5;++e)if(r.hi=(r.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return r}else for(;e<5;++e){if(this.pos>=this.len)throw Kt(this);if(r.hi=(r.hi|(this.buf[this.pos]&127)<>>0,this.buf[this.pos++]<128)return r}throw Error("invalid varint encoding")}et.prototype.bool=function(){return this.uint32()!==0};function zi(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}et.prototype.fixed32=function(){if(this.pos+4>this.len)throw Kt(this,4);return zi(this.buf,this.pos+=4)};et.prototype.sfixed32=function(){if(this.pos+4>this.len)throw Kt(this,4);return zi(this.buf,this.pos+=4)|0};function Lh(){if(this.pos+8>this.len)throw Kt(this,8);return new Rh(zi(this.buf,this.pos+=4),zi(this.buf,this.pos+=4))}et.prototype.float=function(){if(this.pos+4>this.len)throw Kt(this,4);var e=jt.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e};et.prototype.double=function(){if(this.pos+8>this.len)throw Kt(this,4);var e=jt.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e};et.prototype.bytes=function(){var e=this.uint32(),n=this.pos,t=this.pos+e;if(t>this.len)throw Kt(this,e);if(this.pos+=e,Array.isArray(this.buf))return this.buf.slice(n,t);if(n===t){var o=jt.Buffer;return o?o.alloc(0):new this.buf.constructor(0)}return this._slice.call(this.buf,n,t)};et.prototype.string=function(){var e=this.bytes();return G$.read(e,0,e.length)};et.prototype.skip=function(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Kt(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Kt(this);while(this.buf[this.pos++]&128);return this};et.prototype.skipType=function(r){switch(r){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(r=this.uint32()&7)!==4;)this.skipType(r);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+r+" at offset "+this.pos)}return this};et._configure=function(r){gl=r,et.create=zh(),gl._configure();var e=jt.Long?"toLong":"toNumber";jt.merge(et.prototype,{int64:function(){return ml.call(this)[e](!1)},uint64:function(){return ml.call(this)[e](!0)},sint64:function(){return ml.call(this).zzDecode()[e](!1)},fixed64:function(){return Lh.call(this)[e](!0)},sfixed64:function(){return Lh.call(this)[e](!1)}})}});var Gh=re((v4,Vh)=>{"use strict";Vh.exports=Cr;var Fh=bl();(Cr.prototype=Object.create(Fh.prototype)).constructor=Cr;var Bh=fr();function Cr(r){Fh.call(this,r)}Cr._configure=function(){Bh.Buffer&&(Cr.prototype._slice=Bh.Buffer.prototype.slice)};Cr.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))};Cr._configure()});var Wh=re((x4,Uh)=>{"use strict";Uh.exports=Po;var yl=fr();(Po.prototype=Object.create(yl.EventEmitter.prototype)).constructor=Po;function Po(r,e,n){if(typeof r!="function")throw TypeError("rpcImpl must be a function");yl.EventEmitter.call(this),this.rpcImpl=r,this.requestDelimited=!!e,this.responseDelimited=!!n}Po.prototype.rpcCall=function r(e,n,t,o,i){if(!o)throw TypeError("request must be specified");var a=this;if(!i)return yl.asPromise(r,a,e,n,t,o);if(!a.rpcImpl){setTimeout(function(){i(Error("already ended"))},0);return}try{return a.rpcImpl(e,n[a.requestDelimited?"encodeDelimited":"encode"](o).finish(),function(u,l){if(u)return a.emit("error",u,e),i(u);if(l===null){a.end(!0);return}if(!(l instanceof t))try{l=t[a.responseDelimited?"decodeDelimited":"decode"](l)}catch(d){return a.emit("error",d,e),i(d)}return a.emit("data",l,e),i(null,l)})}catch(s){a.emit("error",s,e),setTimeout(function(){i(s)},0);return}};Po.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}});var qh=re(Hh=>{"use strict";var U$=Hh;U$.Service=Wh()});var Kh=re((I4,jh)=>{"use strict";jh.exports={}});var Jh=re(Zh=>{"use strict";var xt=Zh;xt.build="minimal";xt.Writer=hl();xt.BufferWriter=kh();xt.Reader=bl();xt.BufferReader=Gh();xt.util=fr();xt.rpc=qh();xt.roots=Kh();xt.configure=Xh;function Xh(){xt.util._configure(),xt.Writer._configure(xt.BufferWriter),xt.Reader._configure(xt.BufferReader)}Xh()});var Qh=re(($4,Yh)=>{"use strict";Yh.exports=Jh()});var Qr=re((A4,em)=>{"use strict";var Ke=Qh(),K=Ke.Reader,tt=Ke.Writer,E=Ke.util,$=Ke.roots.default||(Ke.roots.default={});$.onnx=function(){var r={};return r.Version=function(){var e={},n=Object.create(e);return n[e[0]="_START_VERSION"]=0,n[e[1]="IR_VERSION_2017_10_10"]=1,n[e[2]="IR_VERSION_2017_10_30"]=2,n[e[3]="IR_VERSION_2017_11_3"]=3,n[e[4]="IR_VERSION_2019_1_22"]=4,n[e[5]="IR_VERSION_2019_3_18"]=5,n[e[6]="IR_VERSION_2019_9_19"]=6,n[e[7]="IR_VERSION_2020_5_8"]=7,n[e[8]="IR_VERSION_2021_7_30"]=8,n[e[9]="IR_VERSION"]=9,n}(),r.AttributeProto=function(){function e(n){if(this.floats=[],this.ints=[],this.strings=[],this.tensors=[],this.graphs=[],this.sparseTensors=[],this.typeProtos=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.name=t.string();break}case 21:{a.refAttrName=t.string();break}case 13:{a.docString=t.string();break}case 20:{a.type=t.int32();break}case 2:{a.f=t.float();break}case 3:{a.i=t.int64();break}case 4:{a.s=t.bytes();break}case 5:{a.t=$.onnx.TensorProto.decode(t,t.uint32());break}case 6:{a.g=$.onnx.GraphProto.decode(t,t.uint32());break}case 22:{a.sparseTensor=$.onnx.SparseTensorProto.decode(t,t.uint32());break}case 14:{a.tp=$.onnx.TypeProto.decode(t,t.uint32());break}case 7:{if(a.floats&&a.floats.length||(a.floats=[]),(s&7)===2)for(var u=t.uint32()+t.pos;t.pos>>0,t.i.high>>>0).toNumber())),t.s!=null&&(typeof t.s=="string"?E.base64.decode(t.s,o.s=E.newBuffer(E.base64.length(t.s)),0):t.s.length>=0&&(o.s=t.s)),t.t!=null){if(typeof t.t!="object")throw TypeError(".onnx.AttributeProto.t: object expected");o.t=$.onnx.TensorProto.fromObject(t.t)}if(t.g!=null){if(typeof t.g!="object")throw TypeError(".onnx.AttributeProto.g: object expected");o.g=$.onnx.GraphProto.fromObject(t.g)}if(t.sparseTensor!=null){if(typeof t.sparseTensor!="object")throw TypeError(".onnx.AttributeProto.sparseTensor: object expected");o.sparseTensor=$.onnx.SparseTensorProto.fromObject(t.sparseTensor)}if(t.tp!=null){if(typeof t.tp!="object")throw TypeError(".onnx.AttributeProto.tp: object expected");o.tp=$.onnx.TypeProto.fromObject(t.tp)}if(t.floats){if(!Array.isArray(t.floats))throw TypeError(".onnx.AttributeProto.floats: array expected");o.floats=[];for(var i=0;i>>0,t.ints[i].high>>>0).toNumber())}if(t.strings){if(!Array.isArray(t.strings))throw TypeError(".onnx.AttributeProto.strings: array expected");o.strings=[];for(var i=0;i=0&&(o.strings[i]=t.strings[i])}if(t.tensors){if(!Array.isArray(t.tensors))throw TypeError(".onnx.AttributeProto.tensors: array expected");o.tensors=[];for(var i=0;i>>0,t.i.high>>>0).toNumber():t.i),t.s!=null&&t.hasOwnProperty("s")&&(i.s=o.bytes===String?E.base64.encode(t.s,0,t.s.length):o.bytes===Array?Array.prototype.slice.call(t.s):t.s),t.t!=null&&t.hasOwnProperty("t")&&(i.t=$.onnx.TensorProto.toObject(t.t,o)),t.g!=null&&t.hasOwnProperty("g")&&(i.g=$.onnx.GraphProto.toObject(t.g,o)),t.floats&&t.floats.length){i.floats=[];for(var s=0;s>>0,t.ints[s].high>>>0).toNumber():t.ints[s]}if(t.strings&&t.strings.length){i.strings=[];for(var s=0;s>>3){case 1:{a.name=t.string();break}case 2:{a.type=$.onnx.TypeProto.decode(t,t.uint32());break}case 3:{a.docString=t.string();break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.name!=null&&t.hasOwnProperty("name")&&!E.isString(t.name))return"name: string expected";if(t.type!=null&&t.hasOwnProperty("type")){var o=$.onnx.TypeProto.verify(t.type);if(o)return"type."+o}return t.docString!=null&&t.hasOwnProperty("docString")&&!E.isString(t.docString)?"docString: string expected":null},e.fromObject=function(t){if(t instanceof $.onnx.ValueInfoProto)return t;var o=new $.onnx.ValueInfoProto;if(t.name!=null&&(o.name=String(t.name)),t.type!=null){if(typeof t.type!="object")throw TypeError(".onnx.ValueInfoProto.type: object expected");o.type=$.onnx.TypeProto.fromObject(t.type)}return t.docString!=null&&(o.docString=String(t.docString)),o},e.toObject=function(t,o){o||(o={});var i={};return o.defaults&&(i.name="",i.type=null,i.docString=""),t.name!=null&&t.hasOwnProperty("name")&&(i.name=t.name),t.type!=null&&t.hasOwnProperty("type")&&(i.type=$.onnx.TypeProto.toObject(t.type,o)),t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.ValueInfoProto"},e}(),r.NodeProto=function(){function e(n){if(this.input=[],this.output=[],this.attribute=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.input&&a.input.length||(a.input=[]),a.input.push(t.string());break}case 2:{a.output&&a.output.length||(a.output=[]),a.output.push(t.string());break}case 3:{a.name=t.string();break}case 4:{a.opType=t.string();break}case 7:{a.domain=t.string();break}case 5:{a.attribute&&a.attribute.length||(a.attribute=[]),a.attribute.push($.onnx.AttributeProto.decode(t,t.uint32()));break}case 6:{a.docString=t.string();break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.input!=null&&t.hasOwnProperty("input")){if(!Array.isArray(t.input))return"input: array expected";for(var o=0;o>>3){case 1:{a.initialization=$.onnx.GraphProto.decode(t,t.uint32());break}case 2:{a.algorithm=$.onnx.GraphProto.decode(t,t.uint32());break}case 3:{a.initializationBinding&&a.initializationBinding.length||(a.initializationBinding=[]),a.initializationBinding.push($.onnx.StringStringEntryProto.decode(t,t.uint32()));break}case 4:{a.updateBinding&&a.updateBinding.length||(a.updateBinding=[]),a.updateBinding.push($.onnx.StringStringEntryProto.decode(t,t.uint32()));break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.initialization!=null&&t.hasOwnProperty("initialization")){var o=$.onnx.GraphProto.verify(t.initialization);if(o)return"initialization."+o}if(t.algorithm!=null&&t.hasOwnProperty("algorithm")){var o=$.onnx.GraphProto.verify(t.algorithm);if(o)return"algorithm."+o}if(t.initializationBinding!=null&&t.hasOwnProperty("initializationBinding")){if(!Array.isArray(t.initializationBinding))return"initializationBinding: array expected";for(var i=0;i>>3){case 1:{a.irVersion=t.int64();break}case 8:{a.opsetImport&&a.opsetImport.length||(a.opsetImport=[]),a.opsetImport.push($.onnx.OperatorSetIdProto.decode(t,t.uint32()));break}case 2:{a.producerName=t.string();break}case 3:{a.producerVersion=t.string();break}case 4:{a.domain=t.string();break}case 5:{a.modelVersion=t.int64();break}case 6:{a.docString=t.string();break}case 7:{a.graph=$.onnx.GraphProto.decode(t,t.uint32());break}case 14:{a.metadataProps&&a.metadataProps.length||(a.metadataProps=[]),a.metadataProps.push($.onnx.StringStringEntryProto.decode(t,t.uint32()));break}case 20:{a.trainingInfo&&a.trainingInfo.length||(a.trainingInfo=[]),a.trainingInfo.push($.onnx.TrainingInfoProto.decode(t,t.uint32()));break}case 25:{a.functions&&a.functions.length||(a.functions=[]),a.functions.push($.onnx.FunctionProto.decode(t,t.uint32()));break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.irVersion!=null&&t.hasOwnProperty("irVersion")&&!E.isInteger(t.irVersion)&&!(t.irVersion&&E.isInteger(t.irVersion.low)&&E.isInteger(t.irVersion.high)))return"irVersion: integer|Long expected";if(t.opsetImport!=null&&t.hasOwnProperty("opsetImport")){if(!Array.isArray(t.opsetImport))return"opsetImport: array expected";for(var o=0;o>>0,t.irVersion.high>>>0).toNumber())),t.opsetImport){if(!Array.isArray(t.opsetImport))throw TypeError(".onnx.ModelProto.opsetImport: array expected");o.opsetImport=[];for(var i=0;i>>0,t.modelVersion.high>>>0).toNumber())),t.docString!=null&&(o.docString=String(t.docString)),t.graph!=null){if(typeof t.graph!="object")throw TypeError(".onnx.ModelProto.graph: object expected");o.graph=$.onnx.GraphProto.fromObject(t.graph)}if(t.metadataProps){if(!Array.isArray(t.metadataProps))throw TypeError(".onnx.ModelProto.metadataProps: array expected");o.metadataProps=[];for(var i=0;i>>0,t.irVersion.high>>>0).toNumber():t.irVersion),t.producerName!=null&&t.hasOwnProperty("producerName")&&(i.producerName=t.producerName),t.producerVersion!=null&&t.hasOwnProperty("producerVersion")&&(i.producerVersion=t.producerVersion),t.domain!=null&&t.hasOwnProperty("domain")&&(i.domain=t.domain),t.modelVersion!=null&&t.hasOwnProperty("modelVersion")&&(typeof t.modelVersion=="number"?i.modelVersion=o.longs===String?String(t.modelVersion):t.modelVersion:i.modelVersion=o.longs===String?E.Long.prototype.toString.call(t.modelVersion):o.longs===Number?new E.LongBits(t.modelVersion.low>>>0,t.modelVersion.high>>>0).toNumber():t.modelVersion),t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),t.graph!=null&&t.hasOwnProperty("graph")&&(i.graph=$.onnx.GraphProto.toObject(t.graph,o)),t.opsetImport&&t.opsetImport.length){i.opsetImport=[];for(var s=0;s>>3){case 1:{a.key=t.string();break}case 2:{a.value=t.string();break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){return typeof t!="object"||t===null?"object expected":t.key!=null&&t.hasOwnProperty("key")&&!E.isString(t.key)?"key: string expected":t.value!=null&&t.hasOwnProperty("value")&&!E.isString(t.value)?"value: string expected":null},e.fromObject=function(t){if(t instanceof $.onnx.StringStringEntryProto)return t;var o=new $.onnx.StringStringEntryProto;return t.key!=null&&(o.key=String(t.key)),t.value!=null&&(o.value=String(t.value)),o},e.toObject=function(t,o){o||(o={});var i={};return o.defaults&&(i.key="",i.value=""),t.key!=null&&t.hasOwnProperty("key")&&(i.key=t.key),t.value!=null&&t.hasOwnProperty("value")&&(i.value=t.value),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.StringStringEntryProto"},e}(),r.TensorAnnotation=function(){function e(n){if(this.quantParameterTensorNames=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.tensorName=t.string();break}case 2:{a.quantParameterTensorNames&&a.quantParameterTensorNames.length||(a.quantParameterTensorNames=[]),a.quantParameterTensorNames.push($.onnx.StringStringEntryProto.decode(t,t.uint32()));break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.tensorName!=null&&t.hasOwnProperty("tensorName")&&!E.isString(t.tensorName))return"tensorName: string expected";if(t.quantParameterTensorNames!=null&&t.hasOwnProperty("quantParameterTensorNames")){if(!Array.isArray(t.quantParameterTensorNames))return"quantParameterTensorNames: array expected";for(var o=0;o>>3){case 1:{a.node&&a.node.length||(a.node=[]),a.node.push($.onnx.NodeProto.decode(t,t.uint32()));break}case 2:{a.name=t.string();break}case 5:{a.initializer&&a.initializer.length||(a.initializer=[]),a.initializer.push($.onnx.TensorProto.decode(t,t.uint32()));break}case 15:{a.sparseInitializer&&a.sparseInitializer.length||(a.sparseInitializer=[]),a.sparseInitializer.push($.onnx.SparseTensorProto.decode(t,t.uint32()));break}case 10:{a.docString=t.string();break}case 11:{a.input&&a.input.length||(a.input=[]),a.input.push($.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 12:{a.output&&a.output.length||(a.output=[]),a.output.push($.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 13:{a.valueInfo&&a.valueInfo.length||(a.valueInfo=[]),a.valueInfo.push($.onnx.ValueInfoProto.decode(t,t.uint32()));break}case 14:{a.quantizationAnnotation&&a.quantizationAnnotation.length||(a.quantizationAnnotation=[]),a.quantizationAnnotation.push($.onnx.TensorAnnotation.decode(t,t.uint32()));break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.node!=null&&t.hasOwnProperty("node")){if(!Array.isArray(t.node))return"node: array expected";for(var o=0;o>>3){case 1:{if(a.dims&&a.dims.length||(a.dims=[]),(s&7)===2)for(var u=t.uint32()+t.pos;t.pos>>0,t.dims[i].high>>>0).toNumber())}if(t.dataType!=null&&(o.dataType=t.dataType|0),t.segment!=null){if(typeof t.segment!="object")throw TypeError(".onnx.TensorProto.segment: object expected");o.segment=$.onnx.TensorProto.Segment.fromObject(t.segment)}if(t.floatData){if(!Array.isArray(t.floatData))throw TypeError(".onnx.TensorProto.floatData: array expected");o.floatData=[];for(var i=0;i=0&&(o.stringData[i]=t.stringData[i])}if(t.int64Data){if(!Array.isArray(t.int64Data))throw TypeError(".onnx.TensorProto.int64Data: array expected");o.int64Data=[];for(var i=0;i>>0,t.int64Data[i].high>>>0).toNumber())}if(t.name!=null&&(o.name=String(t.name)),t.docString!=null&&(o.docString=String(t.docString)),t.rawData!=null&&(typeof t.rawData=="string"?E.base64.decode(t.rawData,o.rawData=E.newBuffer(E.base64.length(t.rawData)),0):t.rawData.length>=0&&(o.rawData=t.rawData)),t.externalData){if(!Array.isArray(t.externalData))throw TypeError(".onnx.TensorProto.externalData: array expected");o.externalData=[];for(var i=0;i>>0,t.uint64Data[i].high>>>0).toNumber(!0))}return o},e.toObject=function(t,o){o||(o={});var i={};if((o.arrays||o.defaults)&&(i.dims=[],i.floatData=[],i.int32Data=[],i.stringData=[],i.int64Data=[],i.doubleData=[],i.uint64Data=[],i.externalData=[]),o.defaults&&(i.dataType=0,i.segment=null,i.name="",o.bytes===String?i.rawData="":(i.rawData=[],o.bytes!==Array&&(i.rawData=E.newBuffer(i.rawData))),i.docString="",i.dataLocation=o.enums===String?"DEFAULT":0),t.dims&&t.dims.length){i.dims=[];for(var a=0;a>>0,t.dims[a].high>>>0).toNumber():t.dims[a]}if(t.dataType!=null&&t.hasOwnProperty("dataType")&&(i.dataType=t.dataType),t.segment!=null&&t.hasOwnProperty("segment")&&(i.segment=$.onnx.TensorProto.Segment.toObject(t.segment,o)),t.floatData&&t.floatData.length){i.floatData=[];for(var a=0;a>>0,t.int64Data[a].high>>>0).toNumber():t.int64Data[a]}if(t.name!=null&&t.hasOwnProperty("name")&&(i.name=t.name),t.rawData!=null&&t.hasOwnProperty("rawData")&&(i.rawData=o.bytes===String?E.base64.encode(t.rawData,0,t.rawData.length):o.bytes===Array?Array.prototype.slice.call(t.rawData):t.rawData),t.doubleData&&t.doubleData.length){i.doubleData=[];for(var a=0;a>>0,t.uint64Data[a].high>>>0).toNumber(!0):t.uint64Data[a]}if(t.docString!=null&&t.hasOwnProperty("docString")&&(i.docString=t.docString),t.externalData&&t.externalData.length){i.externalData=[];for(var a=0;a>>3){case 1:{s.begin=o.int64();break}case 2:{s.end=o.int64();break}default:o.skipType(u&7);break}}return s},n.decodeDelimited=function(o){return o instanceof K||(o=new K(o)),this.decode(o,o.uint32())},n.verify=function(o){return typeof o!="object"||o===null?"object expected":o.begin!=null&&o.hasOwnProperty("begin")&&!E.isInteger(o.begin)&&!(o.begin&&E.isInteger(o.begin.low)&&E.isInteger(o.begin.high))?"begin: integer|Long expected":o.end!=null&&o.hasOwnProperty("end")&&!E.isInteger(o.end)&&!(o.end&&E.isInteger(o.end.low)&&E.isInteger(o.end.high))?"end: integer|Long expected":null},n.fromObject=function(o){if(o instanceof $.onnx.TensorProto.Segment)return o;var i=new $.onnx.TensorProto.Segment;return o.begin!=null&&(E.Long?(i.begin=E.Long.fromValue(o.begin)).unsigned=!1:typeof o.begin=="string"?i.begin=parseInt(o.begin,10):typeof o.begin=="number"?i.begin=o.begin:typeof o.begin=="object"&&(i.begin=new E.LongBits(o.begin.low>>>0,o.begin.high>>>0).toNumber())),o.end!=null&&(E.Long?(i.end=E.Long.fromValue(o.end)).unsigned=!1:typeof o.end=="string"?i.end=parseInt(o.end,10):typeof o.end=="number"?i.end=o.end:typeof o.end=="object"&&(i.end=new E.LongBits(o.end.low>>>0,o.end.high>>>0).toNumber())),i},n.toObject=function(o,i){i||(i={});var a={};if(i.defaults){if(E.Long){var s=new E.Long(0,0,!1);a.begin=i.longs===String?s.toString():i.longs===Number?s.toNumber():s}else a.begin=i.longs===String?"0":0;if(E.Long){var s=new E.Long(0,0,!1);a.end=i.longs===String?s.toString():i.longs===Number?s.toNumber():s}else a.end=i.longs===String?"0":0}return o.begin!=null&&o.hasOwnProperty("begin")&&(typeof o.begin=="number"?a.begin=i.longs===String?String(o.begin):o.begin:a.begin=i.longs===String?E.Long.prototype.toString.call(o.begin):i.longs===Number?new E.LongBits(o.begin.low>>>0,o.begin.high>>>0).toNumber():o.begin),o.end!=null&&o.hasOwnProperty("end")&&(typeof o.end=="number"?a.end=i.longs===String?String(o.end):o.end:a.end=i.longs===String?E.Long.prototype.toString.call(o.end):i.longs===Number?new E.LongBits(o.end.low>>>0,o.end.high>>>0).toNumber():o.end),a},n.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},n.getTypeUrl=function(o){return o===void 0&&(o="type.googleapis.com"),o+"/onnx.TensorProto.Segment"},n}(),e.DataLocation=function(){var n={},t=Object.create(n);return t[n[0]="DEFAULT"]=0,t[n[1]="EXTERNAL"]=1,t}(),e}(),r.SparseTensorProto=function(){function e(n){if(this.dims=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.values=$.onnx.TensorProto.decode(t,t.uint32());break}case 2:{a.indices=$.onnx.TensorProto.decode(t,t.uint32());break}case 3:{if(a.dims&&a.dims.length||(a.dims=[]),(s&7)===2)for(var u=t.uint32()+t.pos;t.pos>>0,t.dims[i].high>>>0).toNumber())}return o},e.toObject=function(t,o){o||(o={});var i={};if((o.arrays||o.defaults)&&(i.dims=[]),o.defaults&&(i.values=null,i.indices=null),t.values!=null&&t.hasOwnProperty("values")&&(i.values=$.onnx.TensorProto.toObject(t.values,o)),t.indices!=null&&t.hasOwnProperty("indices")&&(i.indices=$.onnx.TensorProto.toObject(t.indices,o)),t.dims&&t.dims.length){i.dims=[];for(var a=0;a>>0,t.dims[a].high>>>0).toNumber():t.dims[a]}return i},e.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.SparseTensorProto"},e}(),r.TensorShapeProto=function(){function e(n){if(this.dim=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.dim&&a.dim.length||(a.dim=[]),a.dim.push($.onnx.TensorShapeProto.Dimension.decode(t,t.uint32()));break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.dim!=null&&t.hasOwnProperty("dim")){if(!Array.isArray(t.dim))return"dim: array expected";for(var o=0;o>>3){case 1:{u.dimValue=i.int64();break}case 2:{u.dimParam=i.string();break}case 3:{u.denotation=i.string();break}default:i.skipType(l&7);break}}return u},n.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},n.verify=function(i){if(typeof i!="object"||i===null)return"object expected";var a={};if(i.dimValue!=null&&i.hasOwnProperty("dimValue")&&(a.value=1,!E.isInteger(i.dimValue)&&!(i.dimValue&&E.isInteger(i.dimValue.low)&&E.isInteger(i.dimValue.high))))return"dimValue: integer|Long expected";if(i.dimParam!=null&&i.hasOwnProperty("dimParam")){if(a.value===1)return"value: multiple values";if(a.value=1,!E.isString(i.dimParam))return"dimParam: string expected"}return i.denotation!=null&&i.hasOwnProperty("denotation")&&!E.isString(i.denotation)?"denotation: string expected":null},n.fromObject=function(i){if(i instanceof $.onnx.TensorShapeProto.Dimension)return i;var a=new $.onnx.TensorShapeProto.Dimension;return i.dimValue!=null&&(E.Long?(a.dimValue=E.Long.fromValue(i.dimValue)).unsigned=!1:typeof i.dimValue=="string"?a.dimValue=parseInt(i.dimValue,10):typeof i.dimValue=="number"?a.dimValue=i.dimValue:typeof i.dimValue=="object"&&(a.dimValue=new E.LongBits(i.dimValue.low>>>0,i.dimValue.high>>>0).toNumber())),i.dimParam!=null&&(a.dimParam=String(i.dimParam)),i.denotation!=null&&(a.denotation=String(i.denotation)),a},n.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.denotation=""),i.dimValue!=null&&i.hasOwnProperty("dimValue")&&(typeof i.dimValue=="number"?s.dimValue=a.longs===String?String(i.dimValue):i.dimValue:s.dimValue=a.longs===String?E.Long.prototype.toString.call(i.dimValue):a.longs===Number?new E.LongBits(i.dimValue.low>>>0,i.dimValue.high>>>0).toNumber():i.dimValue,a.oneofs&&(s.value="dimValue")),i.dimParam!=null&&i.hasOwnProperty("dimParam")&&(s.dimParam=i.dimParam,a.oneofs&&(s.value="dimParam")),i.denotation!=null&&i.hasOwnProperty("denotation")&&(s.denotation=i.denotation),s},n.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},n.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TensorShapeProto.Dimension"},n}(),e}(),r.TypeProto=function(){function e(t){if(t)for(var o=Object.keys(t),i=0;i>>3){case 1:{s.tensorType=$.onnx.TypeProto.Tensor.decode(o,o.uint32());break}case 4:{s.sequenceType=$.onnx.TypeProto.Sequence.decode(o,o.uint32());break}case 5:{s.mapType=$.onnx.TypeProto.Map.decode(o,o.uint32());break}case 9:{s.optionalType=$.onnx.TypeProto.Optional.decode(o,o.uint32());break}case 8:{s.sparseTensorType=$.onnx.TypeProto.SparseTensor.decode(o,o.uint32());break}case 6:{s.denotation=o.string();break}default:o.skipType(u&7);break}}return s},e.decodeDelimited=function(o){return o instanceof K||(o=new K(o)),this.decode(o,o.uint32())},e.verify=function(o){if(typeof o!="object"||o===null)return"object expected";var i={};if(o.tensorType!=null&&o.hasOwnProperty("tensorType")){i.value=1;{var a=$.onnx.TypeProto.Tensor.verify(o.tensorType);if(a)return"tensorType."+a}}if(o.sequenceType!=null&&o.hasOwnProperty("sequenceType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=$.onnx.TypeProto.Sequence.verify(o.sequenceType);if(a)return"sequenceType."+a}}if(o.mapType!=null&&o.hasOwnProperty("mapType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=$.onnx.TypeProto.Map.verify(o.mapType);if(a)return"mapType."+a}}if(o.optionalType!=null&&o.hasOwnProperty("optionalType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=$.onnx.TypeProto.Optional.verify(o.optionalType);if(a)return"optionalType."+a}}if(o.sparseTensorType!=null&&o.hasOwnProperty("sparseTensorType")){if(i.value===1)return"value: multiple values";i.value=1;{var a=$.onnx.TypeProto.SparseTensor.verify(o.sparseTensorType);if(a)return"sparseTensorType."+a}}return o.denotation!=null&&o.hasOwnProperty("denotation")&&!E.isString(o.denotation)?"denotation: string expected":null},e.fromObject=function(o){if(o instanceof $.onnx.TypeProto)return o;var i=new $.onnx.TypeProto;if(o.tensorType!=null){if(typeof o.tensorType!="object")throw TypeError(".onnx.TypeProto.tensorType: object expected");i.tensorType=$.onnx.TypeProto.Tensor.fromObject(o.tensorType)}if(o.sequenceType!=null){if(typeof o.sequenceType!="object")throw TypeError(".onnx.TypeProto.sequenceType: object expected");i.sequenceType=$.onnx.TypeProto.Sequence.fromObject(o.sequenceType)}if(o.mapType!=null){if(typeof o.mapType!="object")throw TypeError(".onnx.TypeProto.mapType: object expected");i.mapType=$.onnx.TypeProto.Map.fromObject(o.mapType)}if(o.optionalType!=null){if(typeof o.optionalType!="object")throw TypeError(".onnx.TypeProto.optionalType: object expected");i.optionalType=$.onnx.TypeProto.Optional.fromObject(o.optionalType)}if(o.sparseTensorType!=null){if(typeof o.sparseTensorType!="object")throw TypeError(".onnx.TypeProto.sparseTensorType: object expected");i.sparseTensorType=$.onnx.TypeProto.SparseTensor.fromObject(o.sparseTensorType)}return o.denotation!=null&&(i.denotation=String(o.denotation)),i},e.toObject=function(o,i){i||(i={});var a={};return i.defaults&&(a.denotation=""),o.tensorType!=null&&o.hasOwnProperty("tensorType")&&(a.tensorType=$.onnx.TypeProto.Tensor.toObject(o.tensorType,i),i.oneofs&&(a.value="tensorType")),o.sequenceType!=null&&o.hasOwnProperty("sequenceType")&&(a.sequenceType=$.onnx.TypeProto.Sequence.toObject(o.sequenceType,i),i.oneofs&&(a.value="sequenceType")),o.mapType!=null&&o.hasOwnProperty("mapType")&&(a.mapType=$.onnx.TypeProto.Map.toObject(o.mapType,i),i.oneofs&&(a.value="mapType")),o.denotation!=null&&o.hasOwnProperty("denotation")&&(a.denotation=o.denotation),o.sparseTensorType!=null&&o.hasOwnProperty("sparseTensorType")&&(a.sparseTensorType=$.onnx.TypeProto.SparseTensor.toObject(o.sparseTensorType,i),i.oneofs&&(a.value="sparseTensorType")),o.optionalType!=null&&o.hasOwnProperty("optionalType")&&(a.optionalType=$.onnx.TypeProto.Optional.toObject(o.optionalType,i),i.oneofs&&(a.value="optionalType")),a},e.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},e.getTypeUrl=function(o){return o===void 0&&(o="type.googleapis.com"),o+"/onnx.TypeProto"},e.Tensor=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{u.elemType=i.int32();break}case 2:{u.shape=$.onnx.TensorShapeProto.decode(i,i.uint32());break}default:i.skipType(l&7);break}}return u},t.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")&&!E.isInteger(i.elemType))return"elemType: integer expected";if(i.shape!=null&&i.hasOwnProperty("shape")){var a=$.onnx.TensorShapeProto.verify(i.shape);if(a)return"shape."+a}return null},t.fromObject=function(i){if(i instanceof $.onnx.TypeProto.Tensor)return i;var a=new $.onnx.TypeProto.Tensor;if(i.elemType!=null&&(a.elemType=i.elemType|0),i.shape!=null){if(typeof i.shape!="object")throw TypeError(".onnx.TypeProto.Tensor.shape: object expected");a.shape=$.onnx.TensorShapeProto.fromObject(i.shape)}return a},t.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.elemType=0,s.shape=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(s.elemType=i.elemType),i.shape!=null&&i.hasOwnProperty("shape")&&(s.shape=$.onnx.TensorShapeProto.toObject(i.shape,a)),s},t.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Tensor"},t}(),e.Sequence=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{u.elemType=$.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(l&7);break}}return u},t.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")){var a=$.onnx.TypeProto.verify(i.elemType);if(a)return"elemType."+a}return null},t.fromObject=function(i){if(i instanceof $.onnx.TypeProto.Sequence)return i;var a=new $.onnx.TypeProto.Sequence;if(i.elemType!=null){if(typeof i.elemType!="object")throw TypeError(".onnx.TypeProto.Sequence.elemType: object expected");a.elemType=$.onnx.TypeProto.fromObject(i.elemType)}return a},t.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.elemType=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(s.elemType=$.onnx.TypeProto.toObject(i.elemType,a)),s},t.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Sequence"},t}(),e.Map=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{u.keyType=i.int32();break}case 2:{u.valueType=$.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(l&7);break}}return u},t.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.keyType!=null&&i.hasOwnProperty("keyType")&&!E.isInteger(i.keyType))return"keyType: integer expected";if(i.valueType!=null&&i.hasOwnProperty("valueType")){var a=$.onnx.TypeProto.verify(i.valueType);if(a)return"valueType."+a}return null},t.fromObject=function(i){if(i instanceof $.onnx.TypeProto.Map)return i;var a=new $.onnx.TypeProto.Map;if(i.keyType!=null&&(a.keyType=i.keyType|0),i.valueType!=null){if(typeof i.valueType!="object")throw TypeError(".onnx.TypeProto.Map.valueType: object expected");a.valueType=$.onnx.TypeProto.fromObject(i.valueType)}return a},t.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.keyType=0,s.valueType=null),i.keyType!=null&&i.hasOwnProperty("keyType")&&(s.keyType=i.keyType),i.valueType!=null&&i.hasOwnProperty("valueType")&&(s.valueType=$.onnx.TypeProto.toObject(i.valueType,a)),s},t.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Map"},t}(),e.Optional=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{u.elemType=$.onnx.TypeProto.decode(i,i.uint32());break}default:i.skipType(l&7);break}}return u},t.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")){var a=$.onnx.TypeProto.verify(i.elemType);if(a)return"elemType."+a}return null},t.fromObject=function(i){if(i instanceof $.onnx.TypeProto.Optional)return i;var a=new $.onnx.TypeProto.Optional;if(i.elemType!=null){if(typeof i.elemType!="object")throw TypeError(".onnx.TypeProto.Optional.elemType: object expected");a.elemType=$.onnx.TypeProto.fromObject(i.elemType)}return a},t.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.elemType=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(s.elemType=$.onnx.TypeProto.toObject(i.elemType,a)),s},t.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.Optional"},t}(),e.SparseTensor=function(){function t(o){if(o)for(var i=Object.keys(o),a=0;a>>3){case 1:{u.elemType=i.int32();break}case 2:{u.shape=$.onnx.TensorShapeProto.decode(i,i.uint32());break}default:i.skipType(l&7);break}}return u},t.decodeDelimited=function(i){return i instanceof K||(i=new K(i)),this.decode(i,i.uint32())},t.verify=function(i){if(typeof i!="object"||i===null)return"object expected";if(i.elemType!=null&&i.hasOwnProperty("elemType")&&!E.isInteger(i.elemType))return"elemType: integer expected";if(i.shape!=null&&i.hasOwnProperty("shape")){var a=$.onnx.TensorShapeProto.verify(i.shape);if(a)return"shape."+a}return null},t.fromObject=function(i){if(i instanceof $.onnx.TypeProto.SparseTensor)return i;var a=new $.onnx.TypeProto.SparseTensor;if(i.elemType!=null&&(a.elemType=i.elemType|0),i.shape!=null){if(typeof i.shape!="object")throw TypeError(".onnx.TypeProto.SparseTensor.shape: object expected");a.shape=$.onnx.TensorShapeProto.fromObject(i.shape)}return a},t.toObject=function(i,a){a||(a={});var s={};return a.defaults&&(s.elemType=0,s.shape=null),i.elemType!=null&&i.hasOwnProperty("elemType")&&(s.elemType=i.elemType),i.shape!=null&&i.hasOwnProperty("shape")&&(s.shape=$.onnx.TensorShapeProto.toObject(i.shape,a)),s},t.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},t.getTypeUrl=function(i){return i===void 0&&(i="type.googleapis.com"),i+"/onnx.TypeProto.SparseTensor"},t}(),e}(),r.OperatorSetIdProto=function(){function e(n){if(n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.domain=t.string();break}case 2:{a.version=t.int64();break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){return typeof t!="object"||t===null?"object expected":t.domain!=null&&t.hasOwnProperty("domain")&&!E.isString(t.domain)?"domain: string expected":t.version!=null&&t.hasOwnProperty("version")&&!E.isInteger(t.version)&&!(t.version&&E.isInteger(t.version.low)&&E.isInteger(t.version.high))?"version: integer|Long expected":null},e.fromObject=function(t){if(t instanceof $.onnx.OperatorSetIdProto)return t;var o=new $.onnx.OperatorSetIdProto;return t.domain!=null&&(o.domain=String(t.domain)),t.version!=null&&(E.Long?(o.version=E.Long.fromValue(t.version)).unsigned=!1:typeof t.version=="string"?o.version=parseInt(t.version,10):typeof t.version=="number"?o.version=t.version:typeof t.version=="object"&&(o.version=new E.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber())),o},e.toObject=function(t,o){o||(o={});var i={};if(o.defaults)if(i.domain="",E.Long){var a=new E.Long(0,0,!1);i.version=o.longs===String?a.toString():o.longs===Number?a.toNumber():a}else i.version=o.longs===String?"0":0;return t.domain!=null&&t.hasOwnProperty("domain")&&(i.domain=t.domain),t.version!=null&&t.hasOwnProperty("version")&&(typeof t.version=="number"?i.version=o.longs===String?String(t.version):t.version:i.version=o.longs===String?E.Long.prototype.toString.call(t.version):o.longs===Number?new E.LongBits(t.version.low>>>0,t.version.high>>>0).toNumber():t.version),i},e.prototype.toJSON=function(){return this.constructor.toObject(this,Ke.util.toJSONOptions)},e.getTypeUrl=function(t){return t===void 0&&(t="type.googleapis.com"),t+"/onnx.OperatorSetIdProto"},e}(),r.OperatorStatus=function(){var e={},n=Object.create(e);return n[e[0]="EXPERIMENTAL"]=0,n[e[1]="STABLE"]=1,n}(),r.FunctionProto=function(){function e(n){if(this.input=[],this.output=[],this.attribute=[],this.attributeProto=[],this.node=[],this.opsetImport=[],n)for(var t=Object.keys(n),o=0;o>>3){case 1:{a.name=t.string();break}case 4:{a.input&&a.input.length||(a.input=[]),a.input.push(t.string());break}case 5:{a.output&&a.output.length||(a.output=[]),a.output.push(t.string());break}case 6:{a.attribute&&a.attribute.length||(a.attribute=[]),a.attribute.push(t.string());break}case 11:{a.attributeProto&&a.attributeProto.length||(a.attributeProto=[]),a.attributeProto.push($.onnx.AttributeProto.decode(t,t.uint32()));break}case 7:{a.node&&a.node.length||(a.node=[]),a.node.push($.onnx.NodeProto.decode(t,t.uint32()));break}case 8:{a.docString=t.string();break}case 9:{a.opsetImport&&a.opsetImport.length||(a.opsetImport=[]),a.opsetImport.push($.onnx.OperatorSetIdProto.decode(t,t.uint32()));break}case 10:{a.domain=t.string();break}default:t.skipType(s&7);break}}return a},e.decodeDelimited=function(t){return t instanceof K||(t=new K(t)),this.decode(t,t.uint32())},e.verify=function(t){if(typeof t!="object"||t===null)return"object expected";if(t.name!=null&&t.hasOwnProperty("name")&&!E.isString(t.name))return"name: string expected";if(t.input!=null&&t.hasOwnProperty("input")){if(!Array.isArray(t.input))return"input: array expected";for(var o=0;o{"use strict";Vs();Xe=ye(Qr());Rr();Dr=class{static arraysEqual(e,n){if(e.length!==n.length)return!1;for(let t=0;t1&&d>1)return;s[a-u]=Math.max(l,d)}return s}static index(e,n){let t=new Array(n.length);return r.fillIndex(e,n,t),t}static fillIndex(e,n,t){let o=e.length-n.length;for(let i=0;i=0;v--)l[v]=I%a[v],I=Math.floor(I/a[v]);b||(r.fillIndex(l,e.dims,d),h=e.get(d)),_||(r.fillIndex(l,n.dims,p),g=n.get(p)),u.set(l,t(h,g))}}return u}}static isValidBroadcast(e,n){let t=e.length,o=n.length;if(t>o)return!1;for(let i=1;i<=t;i++)if(e[t-i]!==1&&e[t-i]!==n[o-i])return!1;return!0}static getBroadcastDims(e,n){let t=e.length,o=[];for(let i=0;i1&&s===1&&o.unshift(a)}return o}},Mi=class{static getShapeOfGemmResult(e,n,t,o,i){if(e.length!==2||t.length!==2)throw new Error("shape need to be of size 2");let a,s,u;n?(a=e[1],s=e[0]):(a=e[0],s=e[1]);let l=-1;if(o?(u=t[0],l=1):(u=t[1],l=0),t[l]!==s)throw new Error("dimension mismatch");if(a<=0||u<=0||s<=0)throw new Error("invalid shape specified");if(i&&!bt.isValidBroadcast(i,[a,u]))throw new Error("gemm: invalid bias shape for broadcast");return[a,u,s]}},ht=class r{static tensorDataTypeFromProto(e){switch(e){case Xe.onnx.TensorProto.DataType.INT8:return"int8";case Xe.onnx.TensorProto.DataType.UINT8:return"uint8";case Xe.onnx.TensorProto.DataType.BOOL:return"bool";case Xe.onnx.TensorProto.DataType.INT16:return"int16";case Xe.onnx.TensorProto.DataType.UINT16:return"uint16";case Xe.onnx.TensorProto.DataType.INT32:return"int32";case Xe.onnx.TensorProto.DataType.UINT32:return"uint32";case Xe.onnx.TensorProto.DataType.FLOAT:return"float32";case Xe.onnx.TensorProto.DataType.DOUBLE:return"float64";case Xe.onnx.TensorProto.DataType.STRING:return"string";case Xe.onnx.TensorProto.DataType.INT64:return"int32";case Xe.onnx.TensorProto.DataType.UINT64:return"uint32";default:throw new Error(`unsupported data type: ${Xe.onnx.TensorProto.DataType[e]}`)}}static tensorDataTypeStringToEnum(e){switch(e){case"int8":return Xe.onnx.TensorProto.DataType.INT8;case"uint8":return Xe.onnx.TensorProto.DataType.UINT8;case"bool":return Xe.onnx.TensorProto.DataType.BOOL;case"int16":return Xe.onnx.TensorProto.DataType.INT16;case"uint16":return Xe.onnx.TensorProto.DataType.UINT16;case"int32":return Xe.onnx.TensorProto.DataType.INT32;case"uint32":return Xe.onnx.TensorProto.DataType.UINT32;case"float32":return Xe.onnx.TensorProto.DataType.FLOAT;case"float64":return Xe.onnx.TensorProto.DataType.DOUBLE;case"string":return Xe.onnx.TensorProto.DataType.STRING;case"int64":return Xe.onnx.TensorProto.DataType.INT64;case"uint64":return Xe.onnx.TensorProto.DataType.UINT64;default:throw new Error(`unsupported data type: ${e}`)}}static tensorDimsFromProto(e){return e.map(n=>cr.isLong(n)?n.toNumber():n)}static tensorValueTypeFromProto(e){return{tensorType:r.tensorDataTypeFromProto(e.elemType),shape:{dims:r.tensorDimsFromProto(e.shape.dim.map(n=>n.dimValue))}}}static tensorDimsFromORTFormat(e){let n=[];for(let t=0;te.length)throw new Error(`invalid dimension of ${n} for sizeFromDimension as Tensor has ${e.length} dimensions.`);return r.getSizeFromDimensionRange(e,n,e.length)}static sizeToDimension(e,n){if(n<0||n>e.length)throw new Error(`invalid dimension of ${n} for sizeToDimension as Tensor has ${e.length} dimensions.`);return r.getSizeFromDimensionRange(e,0,n)}static getSizeFromDimensionRange(e,n,t){let o=1;for(let i=n;i=0;--o)t[o]=t[o+1]*e[o+1];return t}static transpose(e){return e.slice().reverse()}static indicesToOffset(e,n,t){t===void 0&&(t=e.length);let o=0;for(let i=0;i=n)throw new Error("unsupported axis for this operation.");return e<0?e+n:e}static normalizeAxes(e,n){return e.map(t=>this.normalizeAxis(t,n))}static incrementIndex(e,n,t){if(n.length===0||e.length===0)throw new Error("Index incrementing unsupported for scalar Tensor");if(t===void 0)t=n.length;else if(t<=0||t>n.length)throw new Error("Incorrect axis to increment on");for(let o=t-1;o>=0&&(e[o]++,!(e[o]=e.length)throw new Error("the dimension with value zero exceeds the dimension size of the input tensor");o[u]=e[u]}else o[u]=n[u];a*=o[u]}}let s=r.size(e);if(i!==-1){if(s%a!==0)throw new Error(`the input tensor cannot be reshaped to the requested shape. Input shape: [${e}] Output shape: [${n}]`);o[i]=s/a}else if(a!==s)throw new Error("reshapedDims and originalDims don't have matching sizes");return o}static sortBasedOnPerm(e,n){return n?n.map(t=>e[t]):e.slice().reverse()}static padShape(e,n){let t=e.length;return e.map((o,i)=>o+n[i]+n[i+t])}static areEqual(e,n){return e.length!==n.length?!1:e.every((t,o)=>t===n[o])}static validateDimsAndCalcSize(e){if(e.length>6)throw new TypeError("Only rank 0 to 6 is supported for tensor shape.");let n=1;for(let t of e){if(!Number.isInteger(t))throw new TypeError(`Invalid shape: ${t} is not an integer`);if(t<0||t>2147483647)throw new TypeError(`Invalid shape: length ${t} is not allowed`);n*=t}return n}static flattenShape(e,n){n<0&&(n+=e.length);let t=e.reduce((a,s)=>a*s,1),o=e.slice(n).reduce((a,s)=>a*s,1);return[t/o,o]}static squeezeShape(e,n){let t=new Array;n=r.normalizeAxes(n,e.length);for(let o=0;o=0;if(i&&e[o]!==1)throw new Error("squeeze an axis of size different than 1");(n.length===0&&e[o]>1||n.length>0&&!i)&&t.push(e[o])}return t}static unsqueezeShape(e,n){let t=new Array(e.length+n.length);t.fill(0);for(let i=0;i=t.length)throw new Error("'axes' has an out of range axis");if(t[a]!==0)throw new Error("'axes' has a duplicate axis");t[a]=1}let o=0;for(let i=0;i=t.length?t.push(n[s+2]):t[s]=n[s+2];for(let s=0;s=t[s]||a[s+t.length]>=t[s])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(e,n,t,o,i,a){if(a){if(i.length!==2*(e.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(n.length!==e.length-2)throw new Error("length of strides should be the length of data dimensions");if(o.length!==e.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let s=0;s{"use strict";rm=ye(wf());Vs();$o();xe=ye(Qr());ze();ot=class r{constructor(e,n,t,o,i,a=rm.Guid.create()){this.dims=e;this.type=n;this.dataProvider=t;this.asyncDataProvider=o;this.cache=i;this.dataId=a;this.size=ne.validateDimsAndCalcSize(e);let s=this.size,u=t===void 0&&o===void 0&&i===void 0;if(i!==void 0&&i.length!==s)throw new RangeError("Input dims doesn't match data length.");if(n==="string"){if(i!==void 0&&(!Array.isArray(i)||!i.every(l=>typeof l=="string")))throw new TypeError("cache should be a string array");u&&(this.cache=new Array(s))}else{if(i!==void 0){let l=om(n);if(!(i instanceof l))throw new TypeError(`cache should be type ${l.name}`)}if(u){let l=new ArrayBuffer(s*W$(n));this.cache=H$(l,n)}}}get data(){if(this.cache===void 0){let e=this.dataProvider(this.dataId);if(e.length!==this.size)throw new Error("Length of data provided by the Data Provider is inconsistent with the dims of this Tensor.");this.cache=e}return this.cache}get stringData(){if(this.type!=="string")throw new TypeError("data type is not string");return this.data}get integerData(){switch(this.type){case"uint8":case"int8":case"uint16":case"int16":case"int32":case"uint32":case"bool":return this.data;default:throw new TypeError("data type is not integer (uint8, int8, uint16, int16, int32, uint32, bool)")}}get floatData(){switch(this.type){case"float32":case"float64":return this.data;default:throw new TypeError("data type is not float (float32, float64)")}}get numberData(){if(this.type!=="string")return this.data;throw new TypeError("type cannot be non-number (string)")}get(e){return this.data[ne.indicesToOffset(e,this.strides)]}set(e,n){this.data[ne.indicesToOffset(e,this.strides)]=n}async getData(){return this.cache===void 0&&(this.cache=await this.asyncDataProvider(this.dataId)),this.cache}get strides(){return this._strides||(this._strides=ne.computeStrides(this.dims)),this._strides}static fromProto(e){if(!e)throw new Error("cannot construct Value from an empty tensor");let n=ht.tensorDataTypeFromProto(e.dataType),t=ht.tensorDimsFromProto(e.dims),o=new r(t,n);if(n==="string")e.stringData.forEach((i,a)=>{o.data[a]=Co(i)});else if(e.rawData&&typeof e.rawData.byteLength=="number"&&e.rawData.byteLength>0){let i=o.data,a=new DataView(e.rawData.buffer,e.rawData.byteOffset,e.rawData.byteLength),s=tm(e.dataType),u=e.rawData.byteLength/s;if(e.rawData.byteLength%s!==0)throw new Error("invalid buffer length");if(i.length!==u)throw new Error("buffer length mismatch");for(let l=0;l0){let i=o.data,a=new DataView(e.rawDataArray().buffer,e.rawDataArray().byteOffset,e.rawDataLength()),s=tm(e.dataType()),u=e.rawDataLength()/s;if(e.rawDataLength()%s!==0)throw new Error("invalid buffer length");if(i.length!==u)throw new Error("buffer length mismatch");for(let l=0;l{"use strict";q$={version:"",attribute:"attribute",varyingVertex:"varying",varyingFrag:"varying",texture2D:"texture2D",output:"gl_FragColor",outputDeclaration:""},j$={version:"#version 300 es",attribute:"in",varyingVertex:"out",varyingFrag:"in",texture2D:"texture",output:"outputColor",outputDeclaration:"out vec4 outputColor;"}});var Ae=N(()=>{"use strict"});async function vl(r,e=t=>0,n){return new Promise((t,o)=>{let i=0,a=()=>{if(r()){t();return}i++;let s=e(i);if(n!=null&&i>=n){o();return}setTimeout(a,s)};a()})}function Bi(r){return eo(typeof r<"u"&&r.length!==0,()=>"empty string found for sampler name"),"get"+r.charAt(0).toUpperCase()+r.slice(1)}function um(r){return eo(typeof r<"u"&&r.length!==0,()=>"empty string found for sampler name"),"get"+r.charAt(0).toUpperCase()+r.slice(1)+"AtOutCoords"}function to(r,e){let n=JSON.parse(JSON.stringify(r));return n=e,n}function no(r,e){return e.map(n=>r[n]).join(", ")}function yt(r){if(r<=1)return"int";if(r===2)return"ivec2";if(r===3)return"ivec3";if(r===4)return"ivec4";if(r===5)return"ivec5";if(r===6)return"ivec6";throw Error(`GPU for rank ${r} is not yet supported`)}function Xt(r=6){return["x","y","z","w","u","v"].slice(0,r)}var zn=N(()=>{"use strict";ze()});function K$(r,e){return Xt(e).map(n=>`${r}.${n}`)}function ro(r,e){return e===1?[r]:K$(r,e)}function Mn(){return` float getChannel(vec4 frag, int dim) { int modCoord = imod(dim, 2); return modCoord == 0 ? frag.r : frag.g; } float getChannel(vec4 frag, vec2 innerDims) { vec2 modCoord = mod(innerDims, 2.); return modCoord.x == 0. ? (modCoord.y == 0. ? frag.r : frag.g) : (modCoord.y == 0. ? frag.b : frag.a); } `}var zr=N(()=>{"use strict";zn()});function Z$(r,e,n){if(r===0)return"false";if(r===1)return`rc > ${e[0]}`;let t="";for(let o=r-2;o= ${e[o-r+2]}`,o= ${r[0]} ? 0. : getA(rc + 1), 0, 0`;let t="r, c",o="r, cp1",i="rp1, c",a="rp1, cp1",s="";if(n>2)for(let u=0;u= ${t}; bool cEdge = cp1 >= ${n}; `}var lm,X$,cm,dm=N(()=>{"use strict";Je();Ae();zn();zr();lm={name:"pack",inputNames:["A"],inputTypes:[1]},X$=(r,e)=>{let n=se(r.session.backend.glContext.version),t=e.dims,o=t.length,i=e.dims.length,a=yt(i),s=ro("rc",i),u=Y$(i,s,t[t.length-2],t[t.length-1]),l;o===0?l=[1,1]:o===1?l=[t[0],1]:l=[t[i-1],t[i-2]];let d=Z$(i,l,s),p=J$(t,s),h=` void main() { ${a} rc = getOutputCoords(); if(${d}) { ${n.output} = vec4(0); } else { ${u} ${n.output} = vec4(${p}); } } `;return{...lm,hasMain:!0,output:{dims:e.dims,type:e.type,textureType:2},shaderSource:h}},cm=(r,e)=>({...lm,get:()=>X$(r,e)})});function xl(r){if(r.length===0)return[1,1,1];let e=1;for(let n=0;n1?r[r.length-2]:1,r[r.length-1]]}function fm(r,e){let n=!1;return r.length===0||e.length===0?n=!0:r.length<2||e.length<2?n=r[r.length-1]===e[e.length-1]:n=r[r.length-1]===e[e.length-1]&&r[r.length-2]===e[e.length-2],n}function tA(r){let e=ne.computeStrides(r),n=["b","r","c"],t="index";return` ivec3 inputCoordsFromReshapedOutCoords(int index) { ${e.map((i,a)=>{let s=`int ${n[a]} = ${t} / ${i}`,u=a===e.length-1?`int ${n[a+1]} = ${t} - ${n[a]} * ${i}`:`index -= ${n[a]} * ${i}`;return`${s}; ${u};`}).join("")} return ivec3(b, r, c); } `}function nA(r){let e=ne.computeStrides(r);return` int getFlattenedIndex(ivec3 coords) { // reverse y, z order return coords.x * ${e[0]} + coords.z * ${e[1]} + coords.y; } `}var Q$,eA,pm,hm=N(()=>{"use strict";ze();Je();Ae();zr();Q$=r=>({name:"Reshape (packed)",inputTypes:[2],inputNames:["A"],cacheHint:`${r}`}),eA=(r,e,n,t)=>{let o=e.dims,i=t,a="";for(let l=0;l<4;l++){let d="";switch(l){case 0:d="outputCoords = rc;";break;case 1:d="outputCoords = ivec3(rc.x, rc.y+1, rc.z);";break;case 2:d="outputCoords = ivec3(rc.x, rc.y, rc.z+1);";break;case 3:d="outputCoords = ivec3(rc.x, rc.y+1, rc.z+1);";break;default:throw new Error}a+=` ${d} ${l>0?"if(outputCoords.y < rows && outputCoords.z < cols){":""} int flattenedIndex = getFlattenedIndex(outputCoords); ivec3 inputRC = inputCoordsFromReshapedOutCoords(flattenedIndex); vec2 innerDims = vec2(float(inputRC.y),float(inputRC.z)); result[${l}] = getChannel(getA(inputRC.x, inputRC.y, inputRC.z), innerDims); ${l>0?"}":""} `}let s=se(r.session.backend.glContext.version),u=` ${tA(o)} ${nA(i)} ${Mn()} void main() { ivec3 rc = getOutputCoords(); vec4 result = vec4(0.0); ivec3 outputCoords; int rows = ${i[2]}; int cols = ${i[1]}; ${a} ${s.output} = result; } `;return{...n,output:{dims:i,type:e.type,textureType:2},shaderSource:u,hasMain:!0}},pm=(r,e,n)=>{let t=Q$(n);return{...t,get:()=>eA(r,e,t,n)}}});var Tl,mm=N(()=>{"use strict";Je();Ae();Tl=(r,e)=>{let n=e.shape,t=se(r.session.backend.glContext.version),o=` const float FLOAT_MAX = 1.70141184e38; const float FLOAT_MIN = 1.17549435e-38; bool isNaN(float val) { return (val < 1.0 || 0.0 < val || val == 0.0) ? false : true; } highp vec4 encodeAsUint8(highp float v) { if (isNaN(v)) { return vec4(255, 255, 255, 255); } highp float av = abs(v); if(av < FLOAT_MIN) { return vec4(0.0, 0.0, 0.0, 0.0); } else if(v > FLOAT_MAX) { return vec4(0.0, 0.0, 128.0, 127.0) / 255.0; } else if(v < -FLOAT_MAX) { return vec4(0.0, 0.0, 128.0, 255.0) / 255.0; } highp vec4 c = vec4(0,0,0,0); highp float e = floor(log2(av)); highp float m = exp2(fract(log2(av))) - 1.0; c[2] = floor(128.0 * m); m -= c[2] / 128.0; c[1] = floor(32768.0 * m); m -= c[1] / 32768.0; c[0] = floor(8388608.0 * m); highp float ebias = e + 127.0; c[3] = floor(ebias / 2.0); ebias -= c[3] * 2.0; c[2] += floor(ebias) * 128.0; c[3] += 128.0 * step(0.0, -v); return c / 255.0; } void main() { float value = ${t.texture2D}(X,TexCoords).r; ${t.output} = encodeAsUint8(value); }`,i={name:"Uint8Encode",inputTypes:[0],inputNames:["X"],output:{dims:n,type:e.tensor.type,textureType:3},shaderSource:o,hasMain:!0};return r.executeProgram(i,[e.tensor])}});function oA(r,e){if(r===1)return"rc";let n="";for(let t=0;t{"use strict";Je();Ae();zn();zr();gm={name:"unpack",inputNames:["A"],inputTypes:[2]},rA=(r,e)=>{let n=e.dims.length,t=ro("rc",n),o=t.slice(-2),i=yt(n),a=Mn(),u=e.dims.length===0?"":oA(n,t),l=n<=1?"rc":`vec2(${o.join(",")})`,d=se(r.session.backend.glContext.version),p=` ${a} void main() { ${i} rc = getOutputCoords(); // Sample the texture with the coords to get the rgba channel value. vec4 packedInput = getA(${u}); ${d.output} = vec4(getChannel(packedInput, ${l}), 0, 0, 0); } `;return{...gm,hasMain:!0,output:{dims:e.dims,type:e.type,textureType:0},shaderSource:p}},bm=(r,e)=>({...gm,get:()=>rA(r,e)})});var Fi,Do,Vi,ko=N(()=>{"use strict";Dt();Fi=class{constructor(e,n=1){if(n===1)this.internalFormat=e.R32F,this.format=e.RED,this.textureType=e.FLOAT,this.channelSize=n;else if(n===4)this.internalFormat=e.RGBA32F,this.format=e.RGBA,this.textureType=e.FLOAT,this.channelSize=n;else throw new Error(`Invalid number of channels: ${n}`)}encode(e,n){let t,o;return e.constructor!==Float32Array&&(Be.warning("Encoder","data was not of type Float32; creating new Float32Array"),o=new Float32Array(e)),n*this.channelSize>e.length?(Be.warning("Encoder","Source data too small. Allocating larger array"),o=e,t=this.allocate(n*this.channelSize),o.forEach((i,a)=>t[a]=i)):(o=e,t=o),t}allocate(e){return new Float32Array(e*4)}decode(e,n){return this.channelSize===1?e.filter((o,i)=>i%4===0).subarray(0,n):e.subarray(0,n)}},Do=class{constructor(e,n=1,t){if(n!==1&&n!==4)throw new Error(`Invalid number of channels: ${n}`);this.internalFormat=e.RGBA,this.format=e.RGBA,this.channelSize=n,this.textureType=t||e.FLOAT}encode(e,n){let t=e;return this.channelSize===1&&(Be.verbose("Encoder","Exploding into a larger array"),t=this.allocate(n),e.forEach((o,i)=>t[i*4]=o)),t}allocate(e){return new Float32Array(e*4)}decode(e,n){return this.channelSize===1?e.filter((o,i)=>i%4===0).subarray(0,n):e.subarray(0,n)}},Vi=class{constructor(e,n=1){this.channelSize=4;if(n===1)this.internalFormat=e.ALPHA,this.format=e.ALPHA,this.textureType=e.UNSIGNED_BYTE,this.channelSize=n;else if(n===4)this.internalFormat=e.RGBA,this.format=e.RGBA,this.textureType=e.UNSIGNED_BYTE,this.channelSize=n;else throw new Error(`Invalid number of channels: ${n}`)}encode(e,n){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}allocate(e){return new Uint8Array(e*this.channelSize)}decode(e,n){if(e instanceof Uint8Array)return e.subarray(0,n);throw new Error(`Invalid array type: ${e.constructor}`)}}});var No,_m,Il,wm=N(()=>{"use strict";ze();Ae();No=(r,e,n)=>{let t=n===0||n===1?1:4,o=n===2,i=n===1||n===2,a=n===4?e.length-1:void 0,s=n===4?e.map((u,l)=>l===e.length-1?u*4:u):void 0;return Il(r,e,t,s,{isPacked:o,reverseWH:i,breakAxis:a})},_m=(r,e,n)=>{let t=No(r,e,n);return[t.width,t.height]},Il=(r,e,n=1,t,o)=>{let i=!!(o&&o.isPacked),[a,s]=r.computeTextureWH(i&&t||e,o),u=e.length,l=e.slice(0);if(u===0&&(l=[1]),n===1)t=e;else if(i){if(n!==4)throw new Error("a packed texture must be 4-channel");t=e,u>0&&(l[u-1]=Math.ceil(l[u-1]/2)),u>1&&(l[u-2]=Math.ceil(l[u-2]/2))}else if(!t)throw new Error("Unpacked shape is needed when using channels > 1");return{width:a,height:s,channels:n,isPacked:i,shape:l,strides:ne.computeStrides(l),unpackedShape:t,reversedWH:o&&o.reverseWH}}});var aA,Gi,xm=N(()=>{"use strict";Dt();Rr();ze();dm();hm();mm();ym();ko();wm();Ae();aA=(r,e)=>{let n=e.map(o=>`${o.unpackedShape.join(",")};${o.width}x${o.height}`).join("_"),t=r.name;return r.cacheHint&&(t+="["+r.cacheHint+"]"),t+=":"+n,t},Gi=class{constructor(e){this.session=e;this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map}calculateTextureWidthAndHeight(e,n){return _m(this.session.layoutStrategy,e,n)}executeProgram(e,n){if(n.lengththis.readTexture(a),async s=>this.readTextureAsync(a),void 0,i),texture:t};return this.setTextureData(a.tensor.dataId,a,e.isPacked),a}getTextureData(e,n=!1){return this.session.isInitializer(e)?this.session.getTextureData(e,n):n?this.packedTextureDataCache.get(e):this.unpackedTextureDataCache.get(e)}setTextureData(e,n,t=!1){this.session.isInitializer(e)?this.session.setTextureData(e,n,t):(t?this.packedTextureDataCache:this.unpackedTextureDataCache).set(e,n)}isTextureLayoutCached(e,n=!1){return!!this.getTextureData(e.dataId,n)}dispose(){this.session.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(e=>this.session.textureManager.releaseTexture(e)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(e=>this.session.textureManager.releaseTexture(e)),this.unpackedTextureDataCache=new Map}readTexture(e){return e.isPacked?this.readTexture(this.unpack(e)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTexture(e,e.tensor.type,e.channels):this.session.textureManager.readUint8TextureAsFloat(Tl(this,e))}async readTextureAsync(e){return e.isPacked?this.readTextureAsync(this.unpack(e)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTextureAsync(e,e.tensor.type,e.channels):this.session.textureManager.readUint8TextureAsFloat(Tl(this,e))}pack(e){return this.executeProgram(cm(this,e.tensor),[e.tensor])}unpack(e){return this.executeProgram(bm(this,e.tensor),[e.tensor])}}});var Sl,_e,dt=N(()=>{"use strict";Sl=class{constructor(e){Object.assign(this,e)}get cacheKey(){return this.key||(this.key=Object.getOwnPropertyNames(this).sort().map(e=>`${this[e]}`).join(";")),this.key}},_e=r=>new Sl(r)});var Tm,Im,Sm,sA,uA,$m=N(()=>{"use strict";dt();Je();Ae();Tm={name:"BatchNormalization",inputNames:["A","Scale","B","Mean","Variance"],inputTypes:[0,0,0,0,0]},Im=(r,e,n)=>(uA(e),[r.run({...Tm,cacheHint:n.cacheKey,get:()=>sA(r,e,n)},e)]),Sm=r=>{let e=r.attributes.getFloat("epsilon",1e-5),n=r.attributes.getFloat("momentum",.9),t=r.attributes.getInt("spatial",1);return _e({epsilon:e,momentum:n,spatial:t})},sA=(r,e,n)=>{let t=se(r.session.backend.glContext.version),o=e[0].dims.length,[i,a]=r.calculateTextureWidthAndHeight(e[1].dims,0),s=` float process(int[${o}] indices) { vec2 position = offsetToCoords(indices[1], ${i}, ${a}); float scale = getColorAsFloat(${t.texture2D}(Scale, position)); float mean = getColorAsFloat(${t.texture2D}(Mean, position)); float variance = getColorAsFloat(${t.texture2D}(Variance, position)); float b = getColorAsFloat(${t.texture2D}(B, position)); return scale * ( (_A(indices) - mean) / sqrt(variance + float(${n.epsilon})) ) + b; }`;return{...Tm,output:{dims:e[0].dims,type:e[0].type,textureType:0},shaderSource:s}},uA=r=>{if(!r||r.length!==5)throw new Error("BatchNormalization requires 5 inputs.");let e=r[0],n=r[1],t=r[2],o=r[3],i=r[4];if(e.dims.length<3||n.dims.length!==1||t.dims.length!==1||o.dims.length!==1||i.dims.length!==1)throw new Error("invalid input shape.");if(n.dims[0]!==e.dims[1]||t.dims[0]!==e.dims[1]||o.dims[0]!==e.dims[1]||i.dims[0]!==e.dims[1])throw new Error("invalid input shape.");if(e.type!=="float32"&&e.type!=="float64"||n.type!=="float32"&&n.type!=="float64"||t.type!=="float32"&&t.type!=="float64"||o.type!=="float32"&&o.type!=="float64"||i.type!=="float32"&&i.type!=="float64")throw new Error("invalid input tensor types.")}});var Ui,Mt,X,Lo,Wi,Yn=N(()=>{"use strict";Ui=class{constructor(e,n,t,o){this.glContext=e;this.programInfo=n;this.inputTextureLayouts=t;this.outputTextureLayout=o}},Mt=class{constructor(e){this.context=e}},X=class{constructor(e,n){this.routineBody=e;this.dependencies=n}},Lo=class{constructor(e,n,t){this.name=e;t?this.dependencies=t:this.dependencies=[],n&&(this.routineBody=n)}addDependency(e){e&&this.dependencies.push(e)}},Wi=class{static returnOrderedNodes(e){if(!e||e.length===0)return[];if(e.length===1)return e;let n=new Set,t=new Set,o=new Array;return this.createOrderedNodes(e,n,t,o),o}static createOrderedNodes(e,n,t,o){for(let i=0;i0)for(let a=0;a b); } vec4 ${r}(vec4 v1, vec4 v2) { return vec4( v1.r > v2.r , v1.g > v2.g, v1.b > v2.b, v1.a > v2.a ); } `,name:r,type:0}}function gA(){let r="less_";return{body:` float ${r}(float a, float b) { return float(a < b); } vec4 ${r}(vec4 v1, vec4 v2) { return vec4( v1.r < v2.r , v1.g < v2.g, v1.b < v2.b, v1.a < v2.a ); } `,name:r,type:0}}function bA(){let r="and_";return{body:` float ${r}(float a, float b) { return float( bool(a) && bool(b) ); } vec4 ${r}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r && b2.r , b1.g && b2.g, b1.b && b2.b, b1.a && b2.a ); } `,name:r,type:0}}function yA(){let r="or_";return{body:` float ${r}(float a, float b) { return float( bool(a) || bool(b) ); } vec4 ${r}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r || b2.r , b1.g || b2.g, b1.b || b2.b, b1.a || b2.a ); } `,name:r,type:0}}function _A(){let r="xor_";return{body:` float ${r}(float a, float b) { return float( bool(a) ^^ bool(b) ); } vec4 ${r}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r ^^ b2.r , b1.g ^^ b2.g, b1.b ^^ b2.b, b1.a ^^ b2.a ); } `,name:r,type:0}}function wA(){return xA("pow")}function vA(){let r="prelu_";return{body:` float ${r}(float a, float b) { return a < 0.0 ? a * b: a; } vec4 ${r}(vec4 v1, vec4 v2) { return vec4( v1.r < 0.0 ? v1.r * v2.r: v1.r, v1.g < 0.0 ? v1.g * v2.g: v1.g, v1.b < 0.0 ? v1.b * v2.b: v1.b, v1.a < 0.0 ? v1.a * v2.a: v1.a ); } `,name:r,type:0}}function xA(r){let e=`${r}_`;return{body:` float ${e}(float a, float b) { return ${r}(a, b); } vec4 ${e}(vec4 v1, vec4 v2) { return ${r}(v1, v2); } `,name:e,type:0}}var Bt,TA,Am,Om,Pm,Em,Cm,Dm,km,Nm,Lm,Rm,zm,Mm,Bm=N(()=>{"use strict";ze();Yn();Je();Ae();Bt=(r,e,n,t=e[0].type,o)=>{let i=r.session.pack?2:0;return{name:n.name,inputNames:["A","B"],inputTypes:[i,i],cacheHint:o,get:()=>TA(r,e,n,t)}},TA=(r,e,n,t=e[0].type)=>{let o=r.session.pack?2:0,i=!ne.areEqual(e[0].dims,e[1].dims),a=e[0].dims,s=r.session.pack;if(i){let d=bt.calcShape(e[0].dims,e[1].dims,!1);if(!d)throw new Error("Can't perform binary op on the given tensors");a=d;let p=a.length,h=e[0].dims.length!==0?e[0].dims.length:1,g=e[1].dims.length!==0?e[1].dims.length:1,b=e[0].dims.length!==0?"bcastIndices_A(indices, aindices);":"aindices[0] = 0;",_=e[1].dims.length!==0?"bcastIndices_B(indices, bindices);":"bindices[0] = 0;",I=se(r.session.backend.glContext.version),w=s?` ${n.body} void main() { vec4 a = getAAtOutCoords(); vec4 b = getBAtOutCoords(); vec4 result = ${n.name}(a, b); ${I.output} = result; }`:` ${n.body} float process(int indices[${p}]) { int aindices[${h}]; int bindices[${g}]; ${b} ${_} return ${n.name}(_A(aindices), _B(bindices)); }`;return{name:n.name,inputNames:["A","B"],inputTypes:[o,o],output:{dims:a,type:t,textureType:o},shaderSource:w,hasMain:s}}let u=se(r.session.backend.glContext.version),l=` ${n.body} void main() { vec4 v1 = ${u.texture2D}(A, TexCoords); vec4 v2 = ${u.texture2D}(B, TexCoords); vec4 result = ${n.name}(v1, v2); ${u.output} = result; } `;return{name:n.name,inputNames:["A","B"],inputTypes:[o,o],output:{dims:e[0].dims,type:t,textureType:o},shaderSource:l,hasMain:!0}},Am=(r,e)=>[r.run(Bt(r,e,cA()),e)],Om=(r,e)=>[r.run(Bt(r,e,bA(),"bool"),e)],Pm=(r,e)=>[r.run(Bt(r,e,dA()),e)],Em=(r,e)=>[r.run(Bt(r,e,hA(),"bool"),e)],Cm=(r,e)=>[r.run(Bt(r,e,mA(),"bool"),e)],Dm=(r,e)=>[r.run(Bt(r,e,gA(),"bool"),e)],km=(r,e)=>[r.run(Bt(r,e,pA()),e)],Nm=(r,e)=>[r.run(Bt(r,e,yA(),"bool"),e)],Lm=(r,e)=>[r.run(Bt(r,e,wA()),e)],Rm=(r,e)=>[r.run(Bt(r,e,vA()),e)],zm=(r,e)=>[r.run(Bt(r,e,fA()),e)],Mm=(r,e)=>[r.run(Bt(r,e,_A(),"bool"),e)]});var Fm,Vm,SA,Gm=N(()=>{"use strict";ze();Fm=(r,e,n)=>(SA(e),[r.cast(e[0],n)]),Vm=r=>ht.tensorDataTypeFromProto(r.attributes.getInt("to")),SA=r=>{if(!r||r.length!==1)throw new Error("Cast requires 1 input.");if(r[0].type==="string")throw new Error("Invalid input type.")}});var $A,AA,Um,Hi,Wm=N(()=>{"use strict";Je();Ae();zn();zr();$A=(r,e)=>({name:"Concat (packed)",inputNames:Array.from({length:r},(n,t)=>`X${t}`),inputTypes:Array(r).fill(2),cacheHint:e}),AA=(r,e,n,t)=>{let o=n[0].dims.slice();if(t>=o.length||t<-1*o.length)throw new Error("axis specified for concat doesn't match input dimensionality");t<0&&(t=o.length+t);let i=o.slice(0);for(let P=1;PP.dims),p=Xt(a),h=new Array(d.length-1);h[0]=d[0][t];for(let P=1;P= ${h[P-1]}) { return getChannel( getX${P}(${Hi(p,g,C)}), vec2(${Hi(b,g,C)})); }`}let w=h.length,v=h[h.length-1];I+=` return getChannel( getX${w}(${Hi(p,g,v)}), vec2(${Hi(b,g,v)}));`;let S=se(r.session.backend.glContext.version),A=` ${l} float getValue(${p.map(P=>"int "+P)}) { ${I} } void main() { ${u} coords = getOutputCoords(); int lastDim = coords.${p[a-1]}; coords.${p[a-1]} = coords.${p[a-2]}; coords.${p[a-2]} = lastDim; vec4 result = vec4(getValue(${s}), 0., 0., 0.); ${s[a-1]} = ${s[a-1]} + 1; if (${s[a-1]} < ${i[a-1]}) { result.g = getValue(${s}); } ${s[a-2]} = ${s[a-2]} + 1; if (${s[a-2]} < ${i[a-2]}) { result.a = getValue(${s}); } ${s[a-1]} = ${s[a-1]} - 1; if (${s[a-2]} < ${i[a-2]} && ${s[a-1]} < ${i[a-1]}) { result.b = getValue(${s}); } ${S.output} = result; } `;return{...e,output:{dims:i,type:n[0].type,textureType:2},shaderSource:A,hasMain:!0}},Um=(r,e,n)=>{let t=$A(e.length,n.cacheKey);return{...t,get:()=>AA(r,t,e,n.axis)}},Hi=(r,e,n)=>{let t=r.indexOf(e);return r.map((i,a)=>a===t?`${i} - ${n}`:i).join()}});var Hm,OA,PA,EA,qm,CA,DA,kA,jm,NA,Km=N(()=>{"use strict";dt();Ae();Wm();Hm=(r,e,n)=>(NA(e),r.session.pack&&e[0].dims.length>1?[r.run(Um(r,e,n),e)]:[r.run(EA(r,e,n),e)]),OA=(r,e)=>({name:"Concat",inputNames:Array.from({length:r},(n,t)=>`X${t}`),inputTypes:Array(r).fill(0),cacheHint:e}),PA=(r,e,n,t)=>{let o=n[0].dims.slice();if(t>=o.length||t<-1*o.length)throw new Error("axis specified for concat doesn't match input dimensionality");t<0&&(t=o.length+t);let i=o.slice(0);for(let g=1;g{let t=OA(e.length,n.cacheKey);return{...t,get:()=>PA(r,t,e,n.axis)}},qm=r=>`int getTextureWhereDataResides(int index) { ${r.map((n,t)=>`if(index<${n}) {return ${t};} `).join("")} }`,CA=r=>qm(r),DA=(r,e)=>{let n=[`float fetchDataFromCorrectTexture(int textureIndex, int indices[${e}]) {`];for(let t=0;t{let e=["int getSizeInConcatAxisValueFromIndex(int index) {"];for(let n=0;n_e({axis:r.attributes.getInt("axis")}),NA=r=>{if(!r||r.length<1)throw new Error("too few inputs");let e=r[0].type,n=r[0].dims.length;if(e==="string")throw new Error("string tensor is not supported yet");for(let t of r){if(t.type!==e)throw new Error("input tensors should be one type");if(t.dims.length!==n)throw new Error("input tensors should have the same shape")}}});function LA(){return Ft("abs")}function RA(){return Ft("acos")}function zA(){return Ft("asin")}function MA(){return Ft("atan")}function BA(){return Ft("ceil")}function FA(){return Ft("cos")}function VA(r){let e="elu";return{body:` const float alpha = float(${r}); float ${e}_(float a) { return a >= 0.0 ? a: (exp(a) - 1.0) * alpha; } vec4 ${e}_(vec4 v) { return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w)); } `,name:e,type:0}}function GA(){return Ft("exp")}function UA(){return Ft("floor")}function $l(r,e){let n="clip";return{body:` const float min = float(${r}); const float max = float(${e}); float ${n}_(float a) { return clamp(a, min, max); } vec4 ${n}_(vec4 v) { return clamp(v, min, max); } `,name:n,type:0}}function WA(){let r="indentity";return{body:` float ${r}_(float a) { return a; } vec4 ${r}_(vec4 v) { return v; } `,name:r,type:0}}function HA(r){let e="leakyRelu";return{body:` const float alpha = float(${r}); float ${e}_(float a) { return a < 0.0 ? a * alpha : a; } vec4 ${e}_(vec4 v) { return vec4(${e}_(v.x), ${e}_(v.y), ${e}_(v.z), ${e}_(v.w)); } `,name:e,type:0}}function qA(){return Ft("log")}function jA(){let r="neg";return{body:` float ${r}_(float a) { return -a; } vec4 ${r}_(vec4 v) { return -v; } `,name:r,type:0}}function KA(){let r="not";return{body:` float ${r}_(float a) { return float( ! bool(a) ); } bool ${r}_(bool a) { return !a; } vec4 ${r}_(vec4 v) { return vec4(!bool(v.x), !bool(v.y), !bool(v.z), !bool(v.w)); } bvec4 ${r}_(bvec4 v) { return bvec4(!v.x, !v.y, !v.z, !v.w); } `,name:r,type:0}}function XA(){return Ft("sin")}function Al(){let r="relu";return{body:` float ${r}_(float a) { return max( a, 0.0 ); } vec4 ${r}_(vec4 v) { return max( v, 0.0 ); } `,name:r,type:0}}function Ol(){let r="sigmoid";return{body:` float ${r}_(float a) { return 1.0 / (1.0 + exp(-a)); } vec4 ${r}_(vec4 v) { return 1.0 / (1.0 + exp(-v)); } `,name:r,type:0}}function ZA(){return Ft("sqrt")}function JA(){return Ft("tan")}function YA(){let r="tanh";return{body:` float ${r}_(float a) { a = clamp(a, -10., 10.); a = exp(2.*a); return (a - 1.) / (a + 1.); } vec4 ${r}_(vec4 v) { v = clamp(v, -10., 10.); v = exp(2.*v); return (v - 1.) / (v + 1.); } `,name:r,type:0}}function Ft(r){return{body:` float ${r}_(float a) { return ${r}(a); } vec4 ${r}_(vec4 v) { return ${r}(v); } `,name:r,type:0}}var QA,nt,Xm,Zm,Jm,Ym,Pl,Qm,eg,eO,tg,ng,rg,og,ig,ag,El,sg,ug,lg,cg,dg,pg,fg,hg,mg,gg,bg,Cl=N(()=>{"use strict";dt();ze();Yn();Je();Ae();QA=(r,e,n,t)=>{let o=r.session.pack?2:0,i=se(r.session.backend.glContext.version);return{...e,output:{dims:n.dims,type:n.type,textureType:o},shaderSource:` ${t.body} void main() { vec4 v = ${i.texture2D}(A, TexCoords); v = ${t.name}_(v); ${i.output} = v; } `,hasMain:!0}},nt=(r,e,n,t)=>{let o=r.session.pack?2:0,i={name:n.name,inputTypes:[o],inputNames:["A"],cacheHint:t};return{...i,get:()=>QA(r,i,e,n)}},Xm=(r,e)=>[r.run(nt(r,e[0],LA()),e)],Zm=(r,e)=>[r.run(nt(r,e[0],RA()),e)],Jm=(r,e)=>[r.run(nt(r,e[0],zA()),e)],Ym=(r,e)=>[r.run(nt(r,e[0],MA()),e)],Pl=(r,e,n)=>[r.run(nt(r,e[0],$l(n.min,n.max),n.cacheKey),e)],Qm=r=>_e({min:r.attributes.getFloat("min",Nr),max:r.attributes.getFloat("max",Lr)}),eg=(r,e)=>{let n=eO(r,e);return Pl(r,[e[0]],n)},eO=(r,e)=>{if(e.length>=3&&(!r.session.isInitializer(e[1].dataId)||!r.session.isInitializer(e[2].dataId)))throw new Error("dynamic clip attributes are not allowed");let n=e.length>=3?e[1].numberData[0]:Nr,t=e.length>=3?e[2].numberData[0]:Lr;return _e({min:n,max:t})},tg=(r,e)=>[r.run(nt(r,e[0],BA()),e)],ng=(r,e)=>[r.run(nt(r,e[0],FA()),e)],rg=(r,e,n)=>[r.run(nt(r,e[0],VA(n.alpha),n.cacheKey),e)],og=r=>_e({alpha:r.attributes.getFloat("alpha",1)}),ig=(r,e)=>[r.run(nt(r,e[0],GA()),e)],ag=(r,e)=>[r.run(nt(r,e[0],UA()),e)],El=(r,e)=>[r.run(nt(r,e[0],WA()),e)],sg=(r,e,n)=>[r.run(nt(r,e[0],HA(n.alpha),n.cacheKey),e)],ug=r=>_e({alpha:r.attributes.getFloat("alpha",.01)}),lg=(r,e)=>[r.run(nt(r,e[0],qA()),e)],cg=(r,e)=>[r.run(nt(r,e[0],jA()),e)],dg=(r,e)=>[r.run(nt(r,e[0],KA()),e)],pg=(r,e)=>[r.run(nt(r,e[0],Al()),e)],fg=(r,e)=>[r.run(nt(r,e[0],Ol()),e)],hg=(r,e)=>[r.run(nt(r,e[0],XA()),e)],mg=(r,e)=>[r.run(nt(r,e[0],ZA()),e)],gg=(r,e)=>[r.run(nt(r,e[0],JA()),e)],bg=(r,e)=>[r.run(nt(r,e[0],YA()),e)]});function Bn(r){let e;switch(r.activation){case"Relu":e=Al();break;case"Sigmoid":e=Ol();break;case"Clip":e=$l(r.clipMin,r.clipMax);break;default:return{activationFunction:"",applyActivation:""}}let n=e.name,t=e.body,o=`value = ${n}_(value);`;return{activationFunction:t,applyActivation:o}}var oo,Mr=N(()=>{"use strict";ze();Cl();oo=r=>{let e=r.getString("activation","");if(e==="Clip"){let[n,t]=r.getFloats("activation_params",[Nr,Lr]);return{activation:e,clipMax:t,clipMin:n,activationCacheKey:`${e}:${n},${t}`}}return{activation:e,activationCacheKey:e}}});var nO,rO,yg,_g=N(()=>{"use strict";Dt();Je();Ae();qi();Mr();nO=(r,e)=>({name:"GroupedConv",inputNames:r?["X","W","Bias"]:["X","W"],inputTypes:r?[0,0,0]:[0,0],cacheHint:e}),rO=(r,e,n,t)=>{let i=e.length>2?"value += getBias(output_channel);":"",a=e[0].dims.slice(),s=e[1].dims.slice(),u=s[0]/t.group;Be.verbose("GroupedConv",`autpPad:${t.autoPad}, dilations:${t.dilations}, group:${t.group}, kernelShape:${t.kernelShape}, pads:${t.pads}, strides:${t.strides}`);let l=io(a,s,t.dilations,t.pads,t.strides),d=se(r.session.backend.glContext.version),{activationFunction:p,applyActivation:h}=Bn(t),g=` const ivec2 strides = ivec2(${t.strides[0]}, ${t.strides[1]}); const ivec2 pads = ivec2(${t.pads[0]}, ${t.pads[1]}); ${p} void main() { ivec4 coords = getOutputCoords(); int batch = coords.x; int output_channel = coords.y; ivec2 xRCCorner = coords.zw * strides - pads; int group_id = output_channel / ${u}; float value = 0.0; for (int wInChannel = 0; wInChannel < ${s[1]}; wInChannel++) { int input_channel = group_id * ${s[1]} + wInChannel; for (int wHeight = 0; wHeight < ${s[2]}; wHeight++) { int xHeight = xRCCorner.x + wHeight * ${t.dilations[0]}; if (xHeight < 0 || xHeight >= ${a[2]}) { continue; } for (int wWidth = 0; wWidth < ${s[3]}; wWidth++) { int xWidth = xRCCorner.y + wWidth * ${t.dilations[1]}; if (xWidth < 0 || xWidth >= ${a[3]}) { continue; } float xVal = getX(batch, input_channel, xWidth, xHeight); float wVal = getW(output_channel, wInChannel, wWidth, wHeight); value += xVal*wVal; } } } ${i} ${h} ${d.output} = vec4(value, .0, .0, .0); } `;return{...n,output:{dims:l,type:e[0].type,textureType:0},shaderSource:g,hasMain:!0}},yg=(r,e,n)=>{let t=nO(e.length>2,n.cacheKey);return{...t,get:()=>rO(r,e,t,n)}}});var oO,iO,wg,vg=N(()=>{"use strict";Je();Ae();zr();oO=r=>({name:"Im2Col (packed)",inputNames:["A"],inputTypes:[2],cacheHint:r}),iO=(r,e,n,t,o,i)=>{let a=n.dims,s=t.dims,u=2,l=3,d=o.length,p=[s[1]*s[2]*s[3],o[2]*o[3]],h=s[2]*s[3],g=Mn(),b=se(r.session.backend.glContext.version),_="";for(let w=0;w<=1;w++)for(let v=0;v<=1;v++)_+=` blockIndex = rc.x + ${v}; pos = rc.y + ${w}; if(blockIndex < ${p[1]} && pos < ${p[0]}) { offsetY = int(blockIndex / (${o[d-1]})) * ${i.strides[0]} - ${i.pads[0]}; d0 = offsetY + ${i.dilations[0]} * (imod(pos, ${h}) / ${s[2]}); if(d0 < ${a[u]} && d0 >= 0) { offsetX = imod(blockIndex, ${o[d-1]}) * ${i.strides[1]} - ${i.pads[1]}; d1 = offsetX + ${i.dilations[1]} * imod(imod(pos, ${h}), ${s[2]}); if(d1 < ${a[l]} && d1 >= 0) { ch = int(float(pos)/ ${h}.); innerDims = vec2(d0, d1); result[${w*2+v}] = getChannel( getA(0, ch, int(innerDims.x), int(innerDims.y)), innerDims); } } } `;let I=` ${g} void main() { ivec2 rc = getOutputCoords(); vec4 result = vec4(0.0); int blockIndex, pos, offsetY, d0, offsetX, d1, ch; vec2 innerDims; ${_} ${b.output} = result; } `;return{...e,output:{dims:p,type:n.type,textureType:2},shaderSource:I,hasMain:!0}},wg=(r,e,n,t,o)=>{let i=oO(o.cacheKey);return{...i,get:()=>iO(r,i,e,n,t,o)}}});function sO(r,e,n){let t=e[0].dims,o=e[1].dims,i=bt.calcShape(t,o,!0);if(!i)throw new Error("Can't use matmul on the given tensors");let a=yt(i.length),s=Xt(),{activationFunction:u,applyActivation:l}=Bn(n),d=e.length>2,p=d?"value += getBiasForMatmul();":"",h=d?`${kl(a,s,e[2].dims,i,!1)}`:"",g=i.length,b=t.length,_=o.length,I=t[t.length-1],w=` ${u} ${h} float process(int indices[${g}]) { int a[${b}]; int b[${_}]; bcastMatmulIndices_A(indices, a); bcastMatmulIndices_B(indices, b); float value; for (int k=0; k<${I}; ++k) { a[${b-1}] = k; b[${_-2}] = k; value += _A(a) * _B(b); } ${p} ${l} return value; }`;return{...r,output:{dims:i,type:e[0].type,textureType:0},shaderSource:w}}function Dl(r,e){let n=aO(r.length>2,e.activationCacheKey);return{...n,get:()=>sO(n,r,e)}}function kl(r,e,n,t,o){let i="",a=n.length,s=t.length,u=s-a;s<2&&a>0?i="coords":i=n.map((_,I)=>`coords.${e[I+u]}`).join(", ");let d=bt.getBroadcastDims(n,t).map(_=>`coords.${e[_+u]} = 0;`).join(` `),h=ne.size(n)===1,g="vec4(outputValue.xx, outputValue.yy)";return h&&(g="vec4(outputValue.x)"),o?` vec4 getBiasForMatmul() { ${r} coords = getOutputCoords(); ${d} vec4 outputValue = getBias(${i}); return ${g}; }`:` float getBiasForMatmul() { ${r} coords = getOutputCoords(); ${d} return getBias(coords.x); }`}var xg,Tg,aO,uO,ji=N(()=>{"use strict";ze();Ae();zn();Mr();Nl();xg=(r,e,n)=>(uO(e),r.session.pack?[r.run(Ki(r,e,n),e)]:[r.run(Dl(e,n),e)]),Tg=r=>oo(r.attributes),aO=(r,e)=>({name:"MatMul",inputNames:r?["A","B","Bias"]:["A","B"],inputTypes:r?[0,0,0]:[0,0],cacheHint:e});uO=r=>{if(!r||r.length!==2)throw new Error("MatMul requires 2 inputs.");if(r[0].dims[r[0].dims.length-1]!==r[1].dims[r[1].dims.length-2])throw new Error("shared dimension does not match.");if(r[0].type!=="float32"&&r[0].type!=="float64"||r[1].type!=="float32"&&r[1].type!=="float64")throw new Error("inputs should be float type");if(r[0].type!==r[1].type)throw new Error("inputs types should match")}});function dO(r,e,n,t){let o=[],i=[],a=n[0].dims,s=n[1].dims,u=a.length,l=s.length,d=t.length,p=d-u,h=d-l;o=a.map((S,A)=>`coords.${e[A+p]}`),o[u-1]="i*2",o.join(", "),i=s.map((S,A)=>`coords.${e[A+h]}`),i[l-2]="i*2",i.join(", ");let g=bt.getBroadcastDims(a,t),b=bt.getBroadcastDims(s,t),_=g.map(S=>`coords.${e[S+p]} = 0;`).join(` `),I=b.map(S=>`coords.${e[S+h]} = 0;`).join(` `),w=`int lastDim = coords.${e[d-1]}; coords.${e[d-1]} = coords.${e[d-2]}; coords.${e[d-2]} = lastDim;`;return` vec4 getAAtOutCoordsMatmul(int i) { ${r} coords = getOutputCoords(); ${w} ${_} vec4 outputValue = getA(${o}); return outputValue; } vec4 getBAtOutCoordsMatmul(int i) { ${r} coords = getOutputCoords(); ${w} ${I} vec4 outputValue = getB(${i}); return outputValue; }`}function pO(r,e){let n="";for(let t=0;t{"use strict";ze();Je();Ae();zn();Mr();ji();lO=(r,e)=>({name:"MatMul (packed)",inputNames:r?["A","B","Bias"]:["A","B"],inputTypes:r?[2,2,2]:[2,2],cacheHint:e}),cO=(r,e,n,t)=>{let o=n.length>2,i=o?"value += getBiasForMatmul();":"",a=n[0].dims,s=n[1].dims,u=bt.calcShape(a,s,!0),l=!ne.areEqual(n[0].dims,n[1].dims);if(!u)throw new Error("Can't use matmul on the given tensors");let d=a[a.length-1],p=Math.ceil(d/2),h=a.length,g=s.length,b=se(r.session.backend.glContext.version),_=yt(u.length),I=u.length,w=Xt(),{activationFunction:v,applyActivation:S}=Bn(t),A=o?`${kl(_,w,n[2].dims,u,!0)}`:"",P=l?`${dO(_,w,n,u)}`:"",C=l?"getAAtOutCoordsMatmul(i)":`getA(${pO(w,h)})`,R=l?"getBAtOutCoordsMatmul(i)":`getB(${fO(w,g)})`,x=l?"":`${_} rc = getOutputCoords(); int lastDim = rc.${w[I-1]}; rc.${w[I-1]} = rc.${w[I-2]}; rc.${w[I-2]} = lastDim; `,B=` ${P} ${A} ${v} void main() { ${x} vec4 value = vec4(0); for (int i = 0; i < ${p}; i++) { vec4 a = ${C}; vec4 b = ${R}; value += (a.rrbb * b.rgrg); value += (a.ggaa * b.baba); } ${i} ${S} ${b.output} = value; }`;return{...e,output:{dims:u,type:n[0].type,textureType:2},shaderSource:B,hasMain:!0}},Ki=(r,e,n)=>{let t=lO(e.length>2,n.activationCacheKey);return{...t,get:()=>cO(r,t,e,n)}}});var Ig,Sg=N(()=>{"use strict";qi();vg();Nl();Ig=(r,e,n)=>{let t=e[0].dims,o=e[1].dims,i=io(t,o,n.dilations,n.pads,n.strides),a=r.run(wg(r,e[0],e[1],i,n),[e[0]]),s=r.reshapePacked(e[1],[o[0],o[1]*o[2]*o[3]]),u=e.length===3?[s,a,e[2]]:[s,a],l=r.run(Ki(r,u,n),u);return r.reshapePacked(l,i)}});var hO,mO,$g,Ll,Rl=N(()=>{"use strict";Ae();hO=r=>({name:"Im2Col",inputNames:["X"],inputTypes:[0],cacheHint:r}),mO=(r,e,n,t,o,i)=>{let a=n.dims,s=t.dims,u=o.length,l=Ll(a,s,o,4),d=` const int XC = ${a[1]}; const int XH = ${a[2]}; const int XW = ${a[3]}; const int KH = ${i.kernelShape[0]}; const int KW = ${i.kernelShape[1]}; const int dilationH = ${i.dilations[0]}; const int dilationW = ${i.dilations[1]}; const int strideH = ${i.strides[0]}; const int strideW = ${i.strides[1]}; const int padH = ${i.pads[0]}; const int padW = ${i.pads[1]}; const int KHKW = KH*KW; const int XCKHKW = XC * KHKW; const int outputChannels = 4; vec4 process(int indices[${u}]) { int b = indices[0]; // batch size int oh = indices[1] * strideH - padH; //output height int ow = indices[2] * strideW - padW; //output width int p = indices[3] * outputChannels; //patch vec4 value = vec4(0.0); for(int i=0; i < outputChannels; ++i) { if(p < XCKHKW) { int patchC = p / KHKW; int patchH = (p - patchC*KHKW) / KW; int patchW = (p - patchC*KHKW) - patchH * KW; int xh2 = oh + patchH * dilationH; int xw2 = ow + patchW * dilationW; int x[${a.length}]; x[0] = b; x[1] = patchC; x[2] = xh2; x[3] = xw2; if(xh2 >= 0 && xh2 < XH && xw2 >= 0 && xw2 < XW) { value[i] = _X(x); } } ++p; } return value; } `;return{...e,output:{dims:l,type:n.type,textureType:4},shaderSource:d}},$g=(r,e,n,t,o)=>{let i=hO(o.cacheKey);return{...i,get:()=>mO(r,i,e,n,t,o)}},Ll=(r,e,n,t=4)=>[n[0],n[2],n[3],Math.ceil(r[1]*e[2]*e[3]/t)]});var gO,bO,Ag,Og=N(()=>{"use strict";ze();Je();Ae();Mr();Rl();gO=(r,e)=>({name:"ConvDotProduct",inputNames:r?["Im2Col","K","B"]:["Im2Col","K"],inputTypes:r?[0,4,0]:[0,4],cacheKey:e.activationCacheKey}),bO=(r,e,n,t,o)=>{let i=n[0].dims,a=n[1].dims,s=[a[0],Math.ceil(i[1]*a[2]*a[3]/4)],u=Ll(i,a,t),[l,d]=r.calculateTextureWidthAndHeight(s,4),p=ne.computeStrides(u),[h,g]=r.calculateTextureWidthAndHeight(u,4),b=t.length,_=n.length<3?"0.0":"_B(b)",I=Math.ceil(i[1]*a[2]*a[3]/4),{activationFunction:w,applyActivation:v}=Bn(o),S=se(r.session.backend.glContext.version),A=` ${w} float process(int indices[${b}]) { int b[1]; b[0] = indices[1]; int im2col[4]; im2col[0] = indices[0]; im2col[1] = indices[2]; im2col[2] = indices[3]; int im2colOffset = im2col[0] * ${p[0]} + im2col[1] * ${p[1]} + im2col[2] * ${p[2]}; int kernelOffset = indices[1] * ${s[1]}; float value = ${_}; for (int i = 0; i < ${I}; ++i) { vec2 im2colCoords = offsetToCoords(im2colOffset, ${h}, ${g}); vec2 kernelCoords = offsetToCoords(kernelOffset, ${l}, ${d}); value += dot(${S.texture2D}(Im2Col, im2colCoords), ${S.texture2D}(K, kernelCoords)); ++im2colOffset; ++kernelOffset; } ${v} return value; }`;return{...e,output:{dims:t,type:n[0].type,textureType:0},shaderSource:A}},Ag=(r,e,n,t)=>{let o=gO(e.length>2,t);return{...o,get:()=>bO(r,o,e,n,t)}}});var io,zl,yO,_O,wO,vO,Ml,xO,qi=N(()=>{"use strict";dt();ze();_g();Sg();Og();Mr();Rl();ji();io=(r,e,n,t,o)=>{let i=r[0],a=r.slice(2),s=a.length,u=e[0],d=e.slice(2).map((b,_)=>b+(b-1)*(n[_]-1)),h=a.map((b,_)=>b+t[_]+t[_+s]).map((b,_)=>Math.floor((b-d[_]+o[_])/o[_]));return[i,u].concat(...h)},zl=(r,e,n)=>(xO(e,n),yO(r,e,n)),yO=(r,e,n)=>{let t=vO(n,e),o=r.session.pack,i=t.kernelShape[0]===1&&t.kernelShape[1]===1;return t.group>1?[r.run(yg(r,e,t),e)]:i&&o?[_O(r,e,t)]:o&&e[0].dims.length===4&&e[0].dims[0]===1&&!i?[Ig(r,e,t)]:[wO(r,e,t)]},_O=(r,e,n)=>{let t=e[0].dims,o=e[1].dims,i=io(t,o,n.dilations,n.pads,n.strides),a=r.reshapeUnpacked(e[0],[t[1],t[2]*t[3]]),s=r.reshapeUnpacked(e[1],[o[0],o[1]]),u=e.length>2?[s,a,e[2]]:[s,a],l=r.run(Dl(u,n),u);return r.reshapeUnpacked(l,i)},wO=(r,e,n)=>{let t=e[0].dims,o=e[1].dims,i=io(t,o,n.dilations,n.pads,n.strides),a=r.run($g(r,e[0],e[1],i,n),[e[0]]),s=e.length===3?[a,e[1],e[2]]:[a,e[1]];return r.run(Ag(r,e,i,n),s)},vO=(r,e)=>{let n=r.kernelShape.slice();if(r.kernelShape.length===0)for(let i=2;i{let e=r.attributes,n=oo(e),t=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),i=e.getInt("group",1),a=e.getInts("kernel_shape",[]),s=e.getInts("pads",[0,0,0,0]),u=e.getInts("strides",[1,1]);return _e({autoPad:t,dilations:o,group:i,kernelShape:a,pads:s,strides:u,...n})},xO=(r,e)=>{if(!r||r.length!==2&&r.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(r[0].dims.length!==4||r[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");let n=r[0].dims[1],t=r[1].dims[1]*e.group;if(n!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(r.length===3&&(r[2].dims.length!==1||r[1].dims[0]!==r[2].dims[0]))throw new Error("invalid bias");let o=r[0].dims.length-2;if(e.dilations.length!==o)throw new Error(`dilations should be ${o}D`);if(e.strides.length!==o)throw new Error(`strides should be ${o}D`);if(e.pads.length!==o*2)throw new Error(`pads should be ${o*2}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==r[1].dims.length-2)throw new Error("invalid kernel shape");if(r[0].type!=="float32"||r[1].type!=="float32")throw new Error("Conv input(X,W) should be float tensor");if(r.length===3&&r[2].type!=="float32")throw new Error("Conv input(bias) should be float tensor")}});var TO,IO,SO,Pg,$O,AO,OO,PO,EO,CO,Eg,DO,Cg=N(()=>{"use strict";dt();Je();Ae();Mr();TO=(r,e,n,t,o,i)=>(r-1)*e+n+(t-1)*o+1-i,IO=(r,e,n,t,o)=>{let i=Math.floor(r/2);e==="SAME_UPPER"?(n[t]=i,n[o]=r-i):e==="SAME_LOWER"&&(n[t]=r-i,n[o]=i)},SO=(r,e,n,t,o,i,a,s)=>{let u=r.length-2,l=s.length===0;for(let d=0;d(DO(e,n),$O(r,e,n)),$O=(r,e,n)=>{let t=CO(n,e);return[EO(r,e,t)]},AO=(r,e)=>({name:"ConvTranspose",inputNames:r?["X","W","B"]:["X","W"],inputTypes:r?[0,0,0]:[0,0],cacheHint:e}),OO=(r,e,n,t)=>{let i=e.length>2?"getB(output_channel)":"0.0",a=e[0].dims,s=e[1].dims,u=s[1],l=s[0]/t.group,d=[e[0].dims[0],e[1].dims[1]*t.group,...t.outputShape],p=se(r.session.backend.glContext.version),{activationFunction:h,applyActivation:g}=Bn(t),b=` const ivec2 strides = ivec2(${t.strides[0]}, ${t.strides[1]}); const ivec2 pads = ivec2(${t.pads[0]}, ${t.pads[1]}); ${h} void main() { ivec4 coords = getOutputCoords(); int batch = coords.x; int output_channel = coords.y; ivec2 loc = coords.zw + pads; int group_id = output_channel / ${u}; int wOutChannel = output_channel - group_id * ${u}; float value = ${i}; for (int inChannelOffset = 0; inChannelOffset < ${l}; inChannelOffset++) { int input_channel = group_id * ${l} + inChannelOffset; for (int wWOff = 0; wWOff < ${s[2]}; wWOff++) { for (int wHOff = 0; wHOff < ${s[3]}; wHOff++) { ivec2 wOff = ivec2(wWOff * ${t.dilations[0]}, wHOff * ${t.dilations[1]}); ivec2 wLoc = loc - wOff; ivec2 wLocIn = wLoc / strides; if ( wLocIn * strides == wLoc && wLocIn.x >= 0 && wLocIn.x < ${a[2]} && wLocIn.y >= 0 && wLocIn.y < ${a[3]} ) { float xVal = getX(batch, input_channel, wLocIn.y, wLocIn.x); float wVal = getW(input_channel, wOutChannel, wHOff, wWOff); value += xVal * wVal; } } } } ${g} ${p.output} = vec4(value, .0, .0, .0); } `;return{...n,output:{dims:d,type:e[0].type,textureType:0},shaderSource:b,hasMain:!0}},PO=(r,e,n)=>{let t=AO(e.length>2,n.cacheKey);return{...t,get:()=>OO(r,e,t,n)}},EO=(r,e,n)=>r.run(PO(r,e,n),e),CO=(r,e)=>{let n=r.kernelShape.slice();if(r.kernelShape.length===0)for(let s=2;s{let e=r.attributes,n=oo(e),t=e.getString("auto_pad","NOTSET"),o=e.getInts("dilations",[1,1]),i=e.getInt("group",1),a=e.getInts("kernel_shape",[]),s=e.getInts("output_padding",[0,0]),u=e.getInts("output_shape",[]),l=e.getInts("pads",[0,0,0,0]),d=e.getInts("strides",[1,1]);return _e({autoPad:t,dilations:o,group:i,kernelShape:a,outputPadding:s,outputShape:u,pads:l,strides:d,...n})},DO=(r,e)=>{if(!r||r.length!==2&&r.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(r[0].dims.length!==4||r[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");let n=r[0].dims[1],t=r[1].dims[0];if(n!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");let o=r[1].dims[1]*e.group;if(r.length===3&&(r[2].dims.length!==1||r[2].dims[0]!==o))throw new Error("invalid bias");let i=r[0].dims.length-2;if(e.dilations.length!==i)throw new Error(`dilations should be ${i}D`);if(e.strides.length!==i)throw new Error(`strides should be ${i}D`);if(e.pads.length!==i*2)throw new Error(`pads should be ${i*2}D`);if(e.outputPadding.length!==i)throw new Error(`output_padding should be ${i}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==r[1].dims.length-2)throw new Error("invalid kernel shape");if(e.outputShape.length!==0&&e.outputShape.length!==r[0].dims.length-2)throw new Error("invalid output shape");if(r[0].type!=="float32"||r[1].type!=="float32")throw new Error("ConvTranspose input(X,W) should be float tensor");if(r.length===3&&r[2].type!=="float32")throw new Error("ConvTranspose input(bias) should be float tensor")}});var Dg,Br,kg,kO,Ng,NO,LO,RO,Xi=N(()=>{"use strict";dt();ze();Ae();Dg={name:"Transpose",inputNames:["A"],inputTypes:[0]},Br=(r,e,n)=>(RO(e),[r.run({...Dg,cacheHint:n.cacheKey,get:()=>kO(r,e[0],n.perm)},e)]),kg=r=>_e({perm:r.attributes.getInts("perm",[])}),kO=(r,e,n)=>{let t=e.dims;n=Ng(t,n);let o=NO(t,n),i=t.length,a=` ${LO("perm",n,i)} float process(int indices[${i}]) { int a[${i}]; perm(a, indices); return _A(a); }`;return{...Dg,output:{dims:o,type:e.type,textureType:0},shaderSource:a}},Ng=(r,e)=>(e&&e.length!==r.length&&(e=[...r.keys()].reverse()),e),NO=(r,e)=>(e=Ng(r,e),ne.sortBasedOnPerm(r,e)),LO=(r,e,n)=>{let t=[];t.push(`void ${r}(out int a[${n}], int src[${n}]) {`);for(let o=0;o{if(!r||r.length!==1)throw new Error("Transpose requires 1 input.");if(r[0].type!=="float32"&&r[0].type!=="float64")throw new Error("input should be float tensor")}});var Lg,Rg,zO,zg=N(()=>{"use strict";Xi();Lg=(r,e,n)=>{zO(e);let t=n.blocksize,o=t*t,i=n.mode==="DCR"?[0,3,4,1,5,2]:[0,1,4,2,5,3],a=n.mode==="DCR"?[e[0].dims[0],t,t,e[0].dims[1]/o,e[0].dims[2],e[0].dims[3]]:[e[0].dims[0],e[0].dims[1]/o,t,t,e[0].dims[2],e[0].dims[3]],s=r.reshapeUnpacked(e[0],a),u={perm:i,cacheKey:`${i}`},[l]=Br(r,[s],u),d=[e[0].dims[0],e[0].dims[1]/o,e[0].dims[2]*t,e[0].dims[3]*t];return[r.reshapeUnpacked(l,d)]},Rg=r=>{let e=r.attributes.getInt("blocksize");if(e<1)throw new Error(`blocksize must be >= 1, but got : ${e} for DepthToSpace`);let n=r.attributes.getString("mode","DCR");if(n!=="DCR"&&n!=="CRD")throw new Error(`unrecognized mode: ${n} for DepthToSpace`);return{mode:n,blocksize:e}},zO=r=>{if(r.length!==1)throw new Error(`DepthToSpace expect 1 inputs, but got ${r.length}`);if(r[0].type==="string"||r[0].dims.length!==4)throw new TypeError("DepthToSpace input should be a 4-D numeric tensor")}});var Mg,Bg,MO,Fg=N(()=>{"use strict";ze();Mg=(r,e,n)=>{MO(e,n);let t=ne.flattenShape(e[0].dims,n);return[r.reshapeUnpacked(e[0],t)]},Bg=r=>r.attributes.getInt("axis",1),MO=(r,e)=>{if(!r||r.length!==1)throw new Error("Flatten requires 1 input.");let n=r[0].dims.length;if(n===0)throw new Error("scalar tensor is not supported.");if(e<-n||e>n)throw new Error("Invalid axis");if(r[0].type==="string")throw new Error("string tensor is not supported.")}});var mr,Ro=N(()=>{"use strict";mr=["float32","float64","int32","int16","int8","uint16","uint32","uint8"]});var Vg,Gg,BO,FO,VO,GO,Ug=N(()=>{"use strict";dt();Ro();ze();Ae();Vg=(r,e,n)=>(GO(e,n.axis),[r.run(VO(r,e,n),e)]),Gg=r=>_e({axis:r.attributes.getInt("axis",0)}),BO={name:"Gather",inputNames:["A","B"],inputTypes:[0,0]},FO=(r,e,n,t)=>{let o=n[0].dims.slice(),i=n[1].dims.slice(),a=new Array(o.length+i.length-1);t=ne.normalizeAxis(t,o.length);let s=[];for(let h=0;h{let t={...BO,cacheHint:n.cacheKey};return{...t,get:()=>FO(r,t,e,n.axis)}},GO=(r,e)=>{if(!r||r.length!==2)throw new Error("Gather requires 2 inputs.");let n=r[0].dims.length;if(n<1)throw new Error("Invalid input shape.");if(e<-n||e>n-1)throw new Error("Invalid axis.");if(mr.indexOf(r[0].type)===-1)throw new Error("Invaid input type.");if(r[1].type!=="int32"&&r[1].type!=="int16")throw new Error("Invaid input type.")}});var Bl,Wg,Hg,qg,UO,WO,HO,jg=N(()=>{"use strict";dt();ze();Ae();Bl=(r,e,n)=>(HO(e,n),[r.run(UO(e,n),e)]),Wg=(r,e)=>{let n=r.attributes.getInt("transA",0)!==0,t=r.attributes.getInt("transB",0)!==0,o=r.attributes.getFloat("alpha",1),i=r.attributes.getFloat("beta",1);return _e({transA:n,transB:t,alpha:o,beta:i,isOptionalC:e})},Hg=r=>Wg(r,!1),qg=r=>Wg(r,!0),UO=(r,e)=>{let n={name:"Gemm",inputNames:r.length===3?["A","B","C"]:["A","B"],inputTypes:r.length===3?[0,0,0]:[0,0],key:e.cacheKey};return{...n,get:()=>WO(n,r,e)}},WO=(r,e,n)=>{let t=e[0].dims.slice(),o=e[1].dims.slice(),[i,a]=Mi.getShapeOfGemmResult(t,n.transA,o,n.transB,e.length===3?e[2].dims:void 0),s=[i,a];if(!s)throw new Error("Can't use gemm on the given tensors");let u=t[t.length-1],l="";n.transA&&(u=t[0]),n.transA&&n.transB?l="value += _A_T(a) * _B_T(b);":n.transA&&!n.transB?l="value += _A_T(a) * _B(b);":!n.transA&&n.transB?l="value += _A(a) * _B_T(b);":!n.transA&&!n.transB&&(l="value += _A(a) * _B(b);");let d=s.length,p=e.length===3?`int c[${e[2].dims.length}];`:"",h=e.length===3?"bcastIndices_C(indices, c);":"",g=e.length===3?"value += beta * _C(c);":"",b=` float process(int indices[${d}]) { int a[${d}]; int b[${d}]; ${p} copyVec(indices, a); copyVec(indices, b); ${h} float value = 0.0; for (int k=0; k<${u}; ++k) { a[${d-1}] = k; b[${d-2}] = k; ${l} } value = value * alpha; ${g} return value; }`;return{...r,output:{dims:s,type:e[0].type,textureType:0},variables:[{name:"alpha",type:"float",data:n.alpha},{name:"beta",type:"float",data:n.beta}],shaderSource:b}},HO=(r,e)=>{if(!r)throw new Error("Input is missing");if(e.isOptionalC&&(r.length<2||r.length>3))throw new Error("Invaid input shape.");if(!e.isOptionalC&&r.length!==3)throw new Error("Gemm requires 3 inputs");if(r.length===3&&r[2].dims.length!==1&&r[2].dims.length!==2)throw new Error("Invalid input shape of C");if(r[0].type!=="float32"&&r[0].type!=="float64"||r[1].type!=="float32"&&r[1].type!=="float64"||r.length===3&&r[2].type!=="float32"&&r[2].type!=="float64")throw new Error("Invalid input type.");if(r[0].type!==r[1].type||r.length===3&&r[0].type!==r[2].type)throw new Error("Input types are mismatched")}});var Kg,Xg,qO,jO,KO,XO,ZO,Zg=N(()=>{"use strict";dt();Ae();Kg=(r,e,n)=>(ZO(e),[r.run(KO(r,e,n),e)]),Xg=r=>{let e=r.attributes.getFloat("scale"),n=r.attributes.getFloats("bias");return _e({scale:e,bias:n})},qO={name:"ImageScaler",inputNames:["X"],inputTypes:[0]},jO=(r,e,n,t)=>{let o=n[0].dims.slice(),i=o.length,s=` ${XO(t.bias.length)} float process(int indices[${i}]) { return _X(indices) * scale + getBias(bias, indices[1]); }`;return{...e,output:{dims:o,type:n[0].type,textureType:0},variables:[{name:"bias",type:"float",arrayLength:t.bias.length,data:t.bias},{name:"scale",type:"float",data:t.scale}],shaderSource:s}},KO=(r,e,n)=>{let t={...qO,cacheHint:n.cacheKey};return{...t,get:()=>jO(r,t,e,n)}},XO=r=>{let e=[`float getBias(float bias[${r}], int channel) {`];for(let n=0;n{if(!r||r.length!==1)throw new Error("ImageScaler requires 1 input.");if(r[0].dims.length!==4)throw new Error("Invalid input shape.");if(r[0].type!=="float32"&&r[0].type!=="float64")throw new Error("Invalid input type.")}});var Yg,Qg,Jg,JO,YO,QO,eP,tP,nP,eb=N(()=>{"use strict";Je();Ae();Yg=(r,e,n)=>{nP(e);let t=r.run(YO(e[0]),e);return[r.run(tP(r,e[0],n,t.dims),[e[0],t,e[1],e[2]])]},Qg=r=>r.attributes.getFloat("epsilon",1e-5),Jg={name:"InstanceNormalization_MeanAndVariance",inputNames:["X"],inputTypes:[0]},JO=(r,e)=>{let n=e.dims.slice(),t=n[1],o=n[2]*n[3],i=[n[0],t],a=` vec4 process(int[2] indices) { vec4 v = vec4(0.0); int a[4]; a[0] = indices[0]; a[1] = indices[1]; float temp = 0.0; for(int a2=0; a2<${n[2]}; a2++) { a[2] = a2; for(int a3=0; a3<${n[3]}; a3++) { a[3] = a3; float x = _X(a); temp += x; } } float mean = temp / float(${o}); temp = 0.0; for(int a2=0; a2<${n[2]}; a2++) { a[2] = a2; for(int a3=0; a3<${n[3]}; a3++) { a[3] = a3; float x = _X(a); temp += (x - mean) * (x - mean); } } v.r = mean; v.g = temp / float(${o}); return v; }`;return{...r,output:{dims:i,type:e.type,textureType:4},shaderSource:a}},YO=r=>({...Jg,get:()=>JO(Jg,r)}),QO={name:"InstanceNormalization_ComputeOutput",inputNames:["X","MeanAndVariance","Scale","B"],inputTypes:[0,4,0,0]},eP=(r,e,n,t,o)=>{let i=se(r.session.backend.glContext.version),[a,s]=r.calculateTextureWidthAndHeight(o,4),[u,l]=[a/4,s],d=` vec4 get_MeanAndVariance(int[2] mv) { int offset = indicesToOffset_MeanAndVariance(mv); vec2 coords = offsetToCoords(offset, ${u}, ${l}); return ${i.texture2D}(MeanAndVariance, coords); } float process(int[4] indices) { int mv[2]; mv[0] = indices[0]; mv[1] = indices[1]; vec4 mean_and_variance = get_MeanAndVariance(mv); float mean = mean_and_variance.r; float variance = mean_and_variance.g; int sb[1]; sb[0] = indices[1]; float scale = _Scale(sb); float b = _B(sb); return scale * (_X(indices) - mean) / sqrt(variance + epsilon) + b; }`;return{...e,output:{dims:n.dims,type:n.type,textureType:0},variables:[{name:"epsilon",type:"float",data:t}],shaderSource:d}},tP=(r,e,n,t)=>{let o={...QO,cacheHint:`${n}`};return{...o,get:()=>eP(r,o,e,n,t)}},nP=r=>{if(!r||r.length!==3)throw new Error("InstanceNormalization requires 3 inputs.");let e=r[0],n=r[1],t=r[2];if(e.dims.length<3||n.dims.length!==1||t.dims.length!==1)throw new Error("Invalid input shape.");if(n.dims[0]!==e.dims[1]||t.dims[0]!==e.dims[1])throw new Error("Input shapes are mismatched.");if(e.type!=="float32"&&e.type!=="float64"||n.type!=="float32"&&n.type!=="float64"||t.type!=="float32"&&t.type!=="float64")throw new Error("Invalid input type.");if(r[0].dims.length!==4)throw new Error("Only support 4-D input shape.")}});function rP(r,e){let n=r[0].dims[1],t=r[0].dims.length,o=-Math.floor((e.size-1)/2),i=Math.ceil((e.size-1)/2),a=`float(${e.alpha}) / float(${e.size})`,s=`float(${e.bias})`,u=`float(${e.beta})`,l=` float process(int indices[${t}]) { int c = indices[1]; float x = _X(indices); float square_sum = 0.0; for (int i = ${o}; i <= ${i}; i++) { int idx = c + i; if (c >= 0 && c < ${n}) { indices[1] = idx; float j = _X(indices); square_sum += j * j; } } return x / pow(${s} + ${a} * square_sum, ${u}); }`;return{...rb,cacheHint:e.cacheKey,output:{dims:r[0].dims,type:r[0].type,textureType:0},shaderSource:l}}function oP(r,e){return{...rb,cacheHint:e.cacheKey,get:()=>rP(r,e)}}var tb,nb,rb,iP,ob=N(()=>{"use strict";dt();Ae();tb=(r,e,n)=>(iP(e),[r.run(oP(e,n),e)]),nb=r=>{let e=r.attributes.getFloat("alpha",1e-4),n=r.attributes.getFloat("beta",.75),t=r.attributes.getFloat("bias",1),o=r.attributes.getInt("size");return _e({alpha:e,beta:n,bias:t,size:o})},rb={name:"LRN",inputNames:["X"],inputTypes:[0]};iP=r=>{if(!r||r.length!==1)throw new Error("LRN requires 1 input.");if(r[0].dims.length!==4)throw new Error('currently only support LRN for input with "NCHW" format');if(r[0].type!=="float32")throw new Error("input should be float type")}});var aP,Fl,ib,ab,sb,sP,uP,lP,cP,dP,pP,fP,hP,ub=N(()=>{"use strict";dt();ze();Je();Ae();aP={name:"Pad",inputNames:["A"],inputTypes:[0]},Fl=(r,e,n)=>(lP(e),[r.run({...aP,cacheHint:n.cacheKey,get:()=>uP(r,e[0],n)},e)]),ib=r=>{let e=r.attributes.getString("mode","constant"),n=r.attributes.getFloat("value",0),t=r.attributes.getInts("pads");return _e({mode:e,value:n,pads:t})},ab=(r,e,n)=>{cP(e);let t=sP(r,e,n);return Fl(r,[e[0]],t)},sb=r=>r.attributes.getString("mode","constant"),sP=(r,e,n)=>{if(!r.session.isInitializer(e[1].dataId)||e.length>=3&&!r.session.isInitializer(e[2].dataId))throw new Error("dynamic pad attributes are not allowed");let t=Array.from(e[1].integerData),o=e.length>=3?e[2].floatData[0]:0;return _e({mode:n,pads:t,value:o})},uP=(r,e,n)=>{let t=ne.padShape(e.dims.slice(),n.pads),o=t.length,a=` ${dP(r,e,n)} float process(int[${o}] indices) { return padA(indices); }`;return{name:"Pad",inputNames:["A"],inputTypes:[0],output:{dims:t,type:e.type,textureType:0},shaderSource:a}},lP=r=>{if(!r||r.length!==1)throw new Error("Pad requires 1 input");if(r[0].type!=="float32"&&r[0].type!=="float64")throw new Error("Invalid input type.")},cP=r=>{if(!r||r.length!==2&&r.length!==3)throw new Error("Pad requires 2 or 3 inputs");if(r[1].type!=="int32")throw new Error("Invalid input type.");if(r.length>=3&&r[2].type==="string")throw new Error("Invalid input type.")},dP=(r,e,n)=>{let t=se(r.session.backend.glContext.version),[o,i]=r.calculateTextureWidthAndHeight(e.dims,0),a=ne.computeStrides(e.dims);switch(n.mode){case"constant":return pP(t,e.dims,a,o,i,n.pads,n.value);case"reflect":return fP(t,e.dims,a,o,i,n.pads);case"edge":return hP(t,e.dims,a,o,i,n.pads);default:throw new Error("Invalid mode")}},pP=(r,e,n,t,o,i,a)=>{let s=e.length,u="";for(let l=s-1;l>=0;--l)u+=` k = m[${l}] - ${i[l]}; if (k < 0) return constant; if (k >= ${e[l]}) return constant; offset += k * ${n[l]}; `;return` float padA(int m[${s}]) { const float constant = float(${a}); int offset = 0; int k = 0; ${u} vec2 coords = offsetToCoords(offset, ${t}, ${o}); float value = getColorAsFloat(${r.texture2D}(A, coords)); return value; } `},fP=(r,e,n,t,o,i)=>{let a=e.length,s="";for(let u=a-1;u>=0;--u)s+=` k = m[${u}] - ${i[u]}; if (k < 0) { k = -k; } { const int _2n_1 = ${2*(e[u]-1)}; k = int( mod( float(k), float(_2n_1) ) ) ; if(k >= ${e[u]}) { k = _2n_1 - k; } } offset += k * ${n[u]}; `;return` float padA(int m[${a}]) { int offset = 0; int k = 0; ${s} vec2 coords = offsetToCoords(offset, ${t}, ${o}); float value = getColorAsFloat(${r.texture2D}(A, coords)); return value; } `},hP=(r,e,n,t,o,i)=>{let a=e.length,s="";for(let u=a-1;u>=0;--u)s+=` k = m[${u}] - ${i[u]}; if (k < 0) k = 0; if (k >= ${e[u]}) k = ${e[u]-1}; offset += k * ${n[u]}; `;return` float padA(int m[${a}]) { int offset = 0; int k = 0; ${s} vec2 coords = offsetToCoords(offset, ${t}, ${o}); float value = getColorAsFloat(${r.texture2D}(A, coords)); return value; } `}});var cb,db,pb,fb,hb,mb,gb,bb,yb,mP,lb,_b,Ji,wb,Zi,gP,vb=N(()=>{"use strict";dt();ze();Ae();cb=(r,e,n)=>{Ji(e);let t={name:"AveragePool",inputNames:["X"],inputTypes:[0],cacheHint:n.cacheKey};return[r.run({...t,get:()=>pb(e,t,!1,n)},e)]},db=r=>{let e=r.attributes.getString("auto_pad","NOTSET"),n=r.attributes.getInt("ceil_mode",0),t=r.attributes.getInt("count_include_pad",0)!==0,o=r.attributes.getInts("kernel_shape"),i=r.attributes.getInts("strides",[]),a=r.attributes.getInts("pads",[]);if(n!==0)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");return _e({autoPad:e,ceilMode:n,countIncludePad:t,kernelShape:o,strides:i,pads:a})},pb=(r,e,n,t)=>{let[o,i]=yb(r,t,n),a=ne.size(o.kernelShape),s="value += _X(x);",u="";o.countIncludePad?u+=`value /= float(${a});`:u+=`value /= float(${a} - pad);`;let d=` ${wb(r[0].dims,o,s,u,"0.0")} `;return{...e,output:{dims:i,type:r[0].type,textureType:0},shaderSource:d}},fb=(r,e,n)=>{Ji(e);let t={name:"GlobalAveragePool",inputNames:["X"],inputTypes:[0],cacheHint:`${n.countIncludePad}`};return[r.run({...t,get:()=>pb(e,t,!0,n)},e)]},hb=r=>{let e=r.attributes.getInt("count_include_pad",0)!==0;return _e({autoPad:"",ceilMode:0,countIncludePad:e,kernelShape:[],strides:[],pads:[]})},mb=(r,e,n)=>{Ji(e);let t={name:"MaxPool",inputNames:["X"],inputTypes:[0],cacheHint:n.cacheKey};return[r.run({...t,get:()=>bb(e,t,!1,n)},e)]},gb=r=>{let e=r.attributes.getString("auto_pad","NOTSET"),n=r.attributes.getInt("ceil_mode",0),t=r.attributes.getInts("kernel_shape"),o=r.attributes.getInts("strides",[]),i=r.attributes.getInts("pads",[]),a=r.attributes.getInt("storage_order",0),s=r.attributes.getInts("dilations",[]);if(a!==0)throw new Error("column major storage order is not yet supported for MaxPool");if(n!==0)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");return _e({autoPad:e,ceilMode:n,countIncludePad:!1,kernelShape:t,strides:o,pads:i,storageOrder:a,dilations:s})},bb=(r,e,n,t)=>{let[o,i]=yb(r,t,n),l=` ${wb(r[0].dims,o,` value = max(_X(x), value); `,"","-1e5")} `;return{...e,output:{dims:i,type:r[0].type,textureType:0},shaderSource:l}},yb=(r,e,n)=>{let t=r[0].dims.slice(),o=Object.hasOwnProperty.call(e,"dilations"),i=e.kernelShape.slice(),a=e.strides.slice(),s=o?e.dilations.slice():[],u=e.pads.slice();kr.adjustPoolAttributes(n,t,i,a,s,u);let l=kr.computePoolOutputShape(n,t,a,s,i,u,e.autoPad),d=Object.assign({},e);return o?Object.assign(d,{kernelShape:i,strides:a,pads:u,dilations:s,cacheKey:e.cacheKey}):Object.assign(d,{kernelShape:i,strides:a,pads:u,cacheKey:e.cacheKey}),[d,l]},mP={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[],cacheKey:""},lb={name:"GlobalMaxPool",inputNames:["X"],inputTypes:[0]},_b=(r,e)=>(Ji(e),[r.run({...lb,get:()=>bb(e,lb,!0,mP)},e)]),Ji=r=>{if(!r||r.length!==1)throw new Error("Pool ops requires 1 input.");if(r[0].type!=="float32"&&r[0].type!=="float64")throw new Error("Invalid input type.")},wb=(r,e,n,t,o)=>{let i=r.length;if(e.kernelShape.length<=2){let a=e.kernelShape[e.kernelShape.length-1],s=e.strides[e.strides.length-1],u=e.pads[e.pads.length/2-1],l=e.pads[e.pads.length-1],d=r[i-1],p="",h="",g="";if(u+l!==0?p=` for (int i = 0; i < ${a}; i++) { x[${i} - 1] = indices[${i} - 1] * ${s} - ${u} + i; if (x[${i} - 1] < 0 || x[${i} - 1] >= ${d}) { pad++; continue; } ${n} }`:p=` for (int i = 0; i < ${a}; i++) { x[${i} - 1] = indices[${i} - 1] * ${s} - ${u} + i; ${n} }`,e.kernelShape.length===2){let _=e.kernelShape[e.kernelShape.length-2],I=e.strides[e.strides.length-2],w=e.pads[e.pads.length/2-2],v=e.pads[e.pads.length-2],S=r[i-2];w+v!==0?h=` for (int j = 0; j < ${_}; j++) { x[${i} - 2] = indices[${i} - 2] * ${I} - ${w} + j; if (x[${i} - 2] < 0 || x[${i} - 2] >= ${S}) { pad+= ${a}; continue; } `:h=` for (int j = 0; j < ${_}; j++) { x[${i} - 2] = indices[${i} - 2] * ${I} - ${w} + j; `,g=` } `}return` float process(int indices[${i}]) { int x[${i}]; copyVec(indices, x); float value = ${o}; int pad = 0; ${h} ${p} ${g} ${t} return value; } `}else{let a=ne.size(e.kernelShape),s=ne.computeStrides(e.kernelShape),u=s.length,l=e.pads.length,d=gP(u),p=Zi(r,"inputDims"),h=Zi(e.pads,"pads"),g=Zi(s,"kernelStrides"),b=Zi(e.strides,"strides"),_=e.pads.reduce((v,S)=>v+S),I="";return _?I=` if (x[j] >= inputDims[j] || x[j] < 0) { pad++; isPad = true; break; } } if (!isPad) { ${n} }`:I=` } ${n} `,` ${d} float process(int indices[${i}]) { int x[${i}]; copyVec(indices, x); int offset[${u}]; int pads[${l}]; int inputDims[${i}]; int kernelStrides[${u}]; int strides[${u}]; ${h} ${p} ${b} ${g} float value = ${o}; int pad = 0; bool isPad = false; for (int i = 0; i < ${a}; i++) { offsetToIndices(i, kernelStrides, offset); isPad = false; for (int j = ${i} - ${u}; j < ${i}; j++) { x[j] = indices[j] * strides[j - ${i} + ${u}] + offset[j - ${i} + ${u}] - pads[j - 2]; ${I} } ${t} return value; } `}},Zi=(r,e)=>{let n="";for(let t=0;t` void offsetToIndices(int offset, int[${r}] strides, out int[${r}] indices) { if (${r} == 0) { return; } for (int i = 0; i < ${r} - 1; ++i) { indices[i] = offset / strides[i]; offset -= indices[i] * strides[i]; } indices[${r} - 1] = offset; }`});var Fr,gr,bP,yP,xb,Tb,Ib,Sb,$b,Ab,Ob,Pb=N(()=>{"use strict";dt();Ro();ze();Ae();Fr=(r,e,n,t,o)=>{yP(e);let i={name:t,inputNames:["A"],inputTypes:[0]};return[r.run({...i,cacheHint:n.cacheKey,get:()=>bP(r,e,n,t,o,i)},e)]},gr=r=>{let e=r.attributes.getInts("axes",[]),n=r.attributes.getInt("keepdims",1)===1;return _e({axes:e,keepDims:n})},bP=(r,e,n,t,o,i)=>{let a=[],s=e[0].dims.length||1,u=[],l=ne.normalizeAxes(n.axes,e[0].dims.length),d=o(e,l),p=d[1];for(let b=0;b=0||l.length===0?(n.keepDims&&a.push(1),p=` for(int j${b} = 0; j${b} < ${e[0].dims[b]}; j${b}++) { inputIdx[${b}] = j${b}; ${p} }`):(u.push(`inputIdx[${b}] = outputIdx[${a.length}];`),a.push(e[0].dims[b]));let g=` float process(int outputIdx[${a.length||1}]) { float value; // final result int inputIdx[${s}]; // addressing input data ${u.join(` `)} ${d[0]} // init ops for reduce max/min ${p} ${d[2]} // final computation for reduce mean return value; }`;return{...i,output:{dims:a,type:e[0].type,textureType:0},shaderSource:g}},yP=r=>{if(!r||r.length!==1)throw new Error("Reduce op requires 1 input.");if(mr.indexOf(r[0].type)===-1)throw new Error("Invalid input type.")},xb=(r,e,n)=>Fr(r,e,n,"ReduceSum",()=>["value = 0.0;","value += _A(inputIdx);",""]),Tb=(r,e,n)=>Fr(r,e,n,"ReduceMean",(o,i)=>{let a=1;for(let s=0;s=0||i.length===0)&&(a*=o[0].dims[s]);return["value = 0.0;","value += _A(inputIdx);",`value /= ${a}.;`]}),Ib=(r,e,n)=>Fr(r,e,n,"ReduceMax",(o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(`inputIdx[${s}] = 0;`);return[`${a.join(` `)} value = _A(inputIdx);`,"value = max(value, _A(inputIdx));",""]}),Sb=(r,e,n)=>Fr(r,e,n,"ReduceMin",(o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(`inputIdx[${s}] = 0;`);return[`${a.join(` `)} value = _A(inputIdx);`,"value = min(value, _A(inputIdx));",""]}),$b=(r,e,n)=>Fr(r,e,n,"ReduceProd",()=>["value = 1.0;","value *= _A(inputIdx);",""]),Ab=(r,e,n)=>Fr(r,e,n,"ReduceLogSum",()=>["value = 0.0;","value += _A(inputIdx);","value = log(value);"]),Ob=(r,e,n)=>Fr(r,e,n,"ReduceLogSumSquare",()=>["float t; value = 0.0;","t = _A(inputIdx); value += t * t;",""])});var Eb,Cb=N(()=>{"use strict";ze();Eb=(r,e)=>{let n=ne.calculateReshapedDims(e[0].dims,e[1].integerData);return r.session.pack?[r.reshapePacked(e[0],n)]:[r.reshapeUnpacked(e[0],n)]}});var Db,Vl,kb,Nb,zo,_P,Gl,Yi,Ul=N(()=>{"use strict";dt();Je();Ae();Db={name:"Upsample",inputNames:["X"],inputTypes:[0]},Vl=(r,e,n)=>(Gl(e,n),[r.run({...Db,cacheHint:n.cacheKey,get:()=>_P(r,e,n)},e)]),kb=r=>zo(r,7),Nb=r=>zo(r,9),zo=(r,e)=>{let n=e>=10,t=r.attributes.getString("mode","nearest");if(t!=="nearest"&&t!=="linear"&&(e<11||t!=="cubic"))throw new Error(`unrecognized mode: ${t}`);let o=[];e<9&&(o=r.attributes.getFloats("scales"),Yi(o,t,n));let i=r.attributes.getFloat("extrapolation_value",0),a=e>10?r.attributes.getString("coordinate_transformation_mode","half_pixel"):"asymmetric";if(["asymmetric","pytorch_half_pixel","tf_half_pixel_for_nn","align_corners","tf_crop_and_resize","half_pixel"].indexOf(a)===-1)throw new Error(`coordinate_transform_mode '${a}' is not supported`);let s=a==="tf_crop_and_resize",u=s,l=t==="nearest"&&e>=11?r.attributes.getString("nearest_mode","round_prefer_floor"):"";if(["round_prefer_floor","round_prefer_ceil","floor","ceil",""].indexOf(l)===-1)throw new Error(`nearest_mode '${l}' is not supported`);let d=r.attributes.getFloat("cubic_coeff_a",-.75),p=r.attributes.getInt("exclude_outside",0)!==0;if(p&&t!=="cubic")throw new Error("exclude_outside can be set to 1 only when mode is CUBIC.");let h=e<11?!0:t==="nearest"&&a==="asymmetric"&&l==="floor",g=0,b=0,_=0;return e>10?r.inputs.length>2?(g=1,b=2,_=3):(b=1,_=2):e===9&&(b=1),_e({opset:e,isResize:n,mode:t,scales:o,extrapolationValue:i,coordinateTransformMode:a,useExtrapolation:u,needRoiInput:s,nearestMode:l,cubicCoefficientA:d,excludeOutside:p,useNearest2xOptimization:h,roiInputIdx:g,scalesInputIdx:b,sizesInputIdx:_})},_P=(r,e,n)=>{let t=se(r.session.backend.glContext.version),[o,i]=r.calculateTextureWidthAndHeight(e[0].dims,0),a=e[0].dims.map((_,I)=>Math.floor(_*n.scales[I])),[s,u]=r.calculateTextureWidthAndHeight(a,0),l=a.length,d=new Array(l),p=new Array(l),h=` int output_pitches[${l}]; int input_pitches[${l}]; `;for(let _=l-1;_>=0;_--)d[_]=_===l-1?1:d[_+1]*a[_+1],p[_]=_===l-1?1:p[_+1]*e[0].dims[_+1],h+=` output_pitches[${_}] = ${d[_]}; input_pitches[${_}] = ${p[_]}; `;let g=` float getInputFloat(int index) { vec2 coords = offsetToCoords(index, ${o}, ${i}); float value = getColorAsFloat(${t.texture2D}(X, coords)); return value; } `,b=n.mode==="nearest"?` ${g} float process(int indices[${l}]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${s}, ${u}); ${h} int d, m; for (int dim = 0; dim < ${l}; ++dim) { d = output_index / output_pitches[dim]; m = output_index - d * output_pitches[dim]; output_index = m; if (scales[dim] != 1 && d > 0) { int d2 = d / scales[dim]; m = d - d2 * scales[dim]; d = d2; } input_index += input_pitches[dim] * d; } return getInputFloat(input_index); }`:l===4?` ${g} float process(int indices[4]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${s}, ${u}); ${h} int m; int index_of_dim0, index_of_dim1, index_of_dim2, index_of_dim3; index_of_dim0 = output_index / output_pitches[0]; m = output_index - index_of_dim0 * output_pitches[0]; index_of_dim1 = m / output_pitches[1]; m = m - index_of_dim1 * output_pitches[1]; index_of_dim2 = m / output_pitches[2]; m = m - index_of_dim2 * output_pitches[2]; index_of_dim3 = m; int index_of_input_dim2, index_of_input_dim3, x_offset, y_offset; index_of_input_dim2 = index_of_dim2 / scales[2]; y_offset = index_of_dim2 - index_of_input_dim2 * scales[2]; index_of_input_dim3 = index_of_dim3 / scales[3]; x_offset = index_of_dim3 - index_of_input_dim3 * scales[3]; input_index = index_of_dim0 * input_pitches[0] + index_of_dim1 * input_pitches[1] + index_of_input_dim2 * input_pitches[2] + index_of_input_dim3; float x00 = getInputFloat(input_index); float x10, x01, x11; bool end_of_dim2 = false; if (index_of_input_dim2 == (${e[0].dims[2]} - 1)) { // It's the end in dimension 2 x01 = x00; end_of_dim2 = true; } else { x01 = getInputFloat(input_index + input_pitches[2]); } if (index_of_input_dim3 == (input_pitches[2] - 1)) { // It's the end in dimension 3 x10 = x00; x11 = x01; } else { x10 = getInputFloat(input_index + 1); x11 = end_of_dim2 ? x10 : getInputFloat(input_index + input_pitches[2] + 1); } float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[2]); float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[2]); return y0 + float(x_offset) * (y1 - y0) / float(scales[3]); }`:` ${g} float process(int indices[2]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${s}, ${u}); ${h} int m; int index_of_dim0, index_of_dim1; index_of_dim0 = output_index / output_pitches[0]; m = output_index - index_of_dim0 * output_pitches[0]; index_of_dim1 = m; int index_of_input_dim0, index_of_input_dim1, x_offset, y_offset; index_of_input_dim0 = index_of_dim0 / scales[0]; y_offset = index_of_dim0 - index_of_input_dim0 * scales[0]; index_of_input_dim1 = index_of_dim1 / scales[1]; x_offset = index_of_dim1 - index_of_input_dim1 * scales[1]; input_index = index_of_input_dim0 * input_pitches[0] + index_of_input_dim1; float x00 = getInputFloat(input_index); float x10, x01, x11; bool end_of_dim0 = false; if (index_of_input_dim0 == (${e[0].dims[0]} - 1)) { // It's the end in dimension 0 x01 = x00; end_of_dim0 = true; } else { x01 = getInputFloat(input_index + input_pitches[0]); } if (index_of_input_dim1 == (input_pitches[0] - 1)) { // It's the end in dimension 1 x10 = x00; x11 = x01; } else { x10 = getInputFloat(input_index + 1); x11 = end_of_dim0 ? x10 : getInputFloat(input_index + input_pitches[0] + 1); } float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[0]); float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[0]); return y0 + float(x_offset) * (y1 - y0) / float(scales[1]); }`;return{...Db,output:{dims:a,type:e[0].type,textureType:0},shaderSource:b,variables:[{name:"scales",type:"int",arrayLength:n.scales.length,data:n.scales.map(_=>Math.ceil(_))}]}},Gl=(r,e)=>{if(!r||e.opset<9&&r.length!==1||e.opset>=9&&e.opset<11&&r.length!==2||e.opset>=11&&r.length<2)throw new Error("invalid inputs.");if(e.scales.length>0&&r[0].dims.length!==e.scales.length)throw new Error("Invalid input shape.");if(r[0].type==="string")throw new Error("Invalid input tensor types.")},Yi=(r,e,n)=>{if(n){for(let t of r)if(t<=0)throw new Error("Scale value should be greater than 0.")}else for(let t of r)if(t<1)throw new Error("Scale value should be greater than or equal to 1.");if((e==="linear"||e==="cubic")&&r.length!==2&&(r.length!==4||r[0]!==1||r[1]!==1))throw new Error(`'Linear' mode and 'Cubic' mode only support 2-D inputs ('Bilinear', 'Bicubic') or 4-D inputs with the corresponding outermost 2 scale values being 1 in the ${n?"Resize":"Upsample"} opeartor.`)}});var Wl,Hl,Lb,Rb,wP,vP,xP,TP,zb=N(()=>{"use strict";Je();Ae();zn();zr();Ul();Wl={name:"Resize",inputNames:["A"],inputTypes:[2]},Hl=(r,e,n)=>(Gl(e,n),[r.run({...Wl,cacheHint:n.cacheKey,get:()=>wP(r,e,n)},e)]),Lb=r=>zo(r,10),Rb=r=>zo(r,11),wP=(r,e,n)=>{let t=se(r.session.backend.glContext.version),[o,i]=vP(e,n);if(o.every(S=>S===1)&&n.coordinateTransformMode!=="tf_crop_and_resize")return{...Wl,output:{dims:i,type:e[0].type,textureType:2},hasMain:!0,shaderSource:`void main() { vec4 v = ${t.texture2D}(X, TexCoords); ${t.output} = v; }`};let s=i.length;if(s<2)throw new Error(`output dimension should be at least 2, but got ${s}`);let u=i[s-2],l=i[s-1],d=e[0].dims;if(s!==d.length)throw new Error(`output dimension should match input ${d.length}, but got ${s}`);let p=d[s-2],h=d[s-1],g=o[s-2],b=o[s-1],_="";if(n.mode!=="linear")throw new Error(`resize (packed) does not support mode: '${n.mode}'`);switch(n.coordinateTransformMode){case"asymmetric":_=` vec4 getSourceFracIndex(ivec4 coords) { return vec4(coords) / scaleWHWH; } `;break;case"half_pixel":_=` vec4 getSourceFracIndex(ivec4 coords) { return (vec4(coords) + 0.5) / scaleWHWH - 0.5; } `;break;case"pytorch_half_pixel":_=` vec4 getSourceFracIndex(ivec4 coords) { vec4 fcoords = vec4(coords); return vec4( ${l}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0, ${u}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0, ${l}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0, ${u}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0 ); } `;break;case"align_corners":_=` vec4 getSourceFracIndex(ivec4 coords) { vec4 resized = vec4(${l}.0 - 1.0, ${u}.0 - 1.0, ${l}.0 - 1.0, ${u}.0 - 1.0); vec4 original = vec4(${h}.0 - 1.0, ${p}.0 - 1.0, ${h}.0 - 1.0, ${p}.0 - 1.0); vec4 new_scale = original / resized; return vec4(coords) * new_scale; } `;break;default:throw new Error(`resize (packed) does not support coordinateTransformMode: '${n.coordinateTransformMode}'`)}let I=yt(s),w=Mn(),v=` const vec2 inputWH = vec2(${p}.0, ${h}.0); const vec4 scaleWHWH = vec4(float(${g}), float(${b}), float(${g}), float(${b})); ${w} ${_} float getAValue(int x10, int r, int c, int d) { return getChannel(getA(x10, r, c, d), vec2(c, d)); } void main() { ${I} rc = getOutputCoords(); int batch = rc[0]; int depth = rc[1]; // retrieve the 4 coordinates that is used in the 4 packed output values. ivec4 coords = ivec4(rc.wz, rc.w + 1, rc.z + 1); // calculate the source index in fraction vec4 sourceFrac = getSourceFracIndex(coords); // get the lower and upper bound of the 4 values that will be packed into one texel. ivec4 x00 = ivec4(max(sourceFrac.xy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xy))); ivec4 x01 = ivec4(max(sourceFrac.xw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xw))); ivec4 x10 = ivec4(max(sourceFrac.zy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zy))); ivec4 x11 = ivec4(max(sourceFrac.zw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zw))); bool hasNextRow = rc.w < ${u-1}; bool hasNextCol = rc.z < ${l-1}; // pack x00, x01, x10, x11's top-left corner into one vec4 structure vec4 topLeft = vec4( getAValue(batch, depth, x00.x, x00.y), hasNextCol ? getAValue(batch, depth, x01.x, x01.y) : 0.0, hasNextRow ? getAValue(batch, depth, x10.x, x10.y) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.y) : 0.0); // pack x00, x01, x10, x11's top-right corner into one vec4 structure vec4 topRight = vec4( getAValue(batch, depth, x00.x, x00.w), hasNextCol ? getAValue(batch, depth, x01.x, x01.w) : 0.0, hasNextRow ? getAValue(batch, depth, x10.x, x10.w) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.w) : 0.0); // pack x00, x01, x10, x11's bottom-left corner into one vec4 structure vec4 bottomLeft = vec4( getAValue(batch, depth, x00.z, x00.y), hasNextCol ? getAValue(batch, depth, x01.z, x01.y) : 0.0, hasNextRow ? getAValue(batch, depth, x10.z, x10.y) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.y) : 0.0); // pack x00, x01, x10, x11's bottom-right corner into one vec4 structure vec4 bottomRight = vec4( getAValue(batch, depth, x00.z, x00.w), hasNextCol ? getAValue(batch, depth, x01.z, x01.w) : 0.0, hasNextRow ? getAValue(batch, depth, x10.z, x10.w) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.w) : 0.0); // calculate the interpolation fraction on u and v direction vec4 frac = vec4(sourceFrac) - floor(sourceFrac); vec4 clampFrac = clamp(frac, vec4(0.0), vec4(1.0)); vec4 top = mix(topLeft, topRight, clampFrac.ywyw); vec4 bottom = mix(bottomLeft, bottomRight, clampFrac.ywyw); vec4 newValue = mix(top, bottom, clampFrac.xxzz); ${t.output} = vec4(newValue); } `;return{...Wl,output:{dims:i,type:e[0].type,textureType:2},hasMain:!0,shaderSource:v}},vP=(r,e)=>{let t=r[0].dims,o=e.scales,i;if(o.length===0){let s=r[e.scalesInputIdx];if(s&&s.size!==0){if(r[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");o=xP(s,e.mode,e.isResize)}else{let u=r[e.sizesInputIdx];if(!u||u.size===0)throw new Error("Either scales or sizes MUST be provided as input.");i=Array.from(u.integerData),o=TP(i,t,e.mode,e.isResize)}}else if(r[e.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");let a=i||t.map((s,u)=>Math.floor(s*o[u]));return[o,a]},xP=(r,e,n)=>{let t=Array.from(r.floatData);return Yi(t,e,n),t},TP=(r,e,n,t)=>{let o=e.length,i=new Array(o);for(let a=0,s=o;a{"use strict";Rr();Mb=(r,e)=>(IP(e),[new ot([e[0].dims.length],"int32",void 0,void 0,new Int32Array(e[0].dims))]),IP=r=>{if(!r||r.length!==1)throw new Error("Shape requires 1 input.")}});var ql,Fb,Vb,Gb,SP,Ub,$P,AP,Wb=N(()=>{"use strict";dt();Ro();ze();Ae();ql={name:"Slice",inputNames:["A"],inputTypes:[0]},Fb=(r,e,n)=>(SP(e),[r.run({...ql,cacheHint:n.cacheKey,get:()=>Gb(r,e[0],n)},e)]),Vb=r=>{let e=r.attributes.getInts("starts"),n=r.attributes.getInts("ends"),t=r.attributes.getInts("axes",[]);return _e({starts:e,ends:n,axes:t})},Gb=(r,e,n)=>{let t=n.axes.length===0?e.dims.slice(0).map((p,h)=>h):n.axes,o=ne.normalizeAxes(t,e.dims.length),i=n.starts.map((p,h)=>p>e.dims[o[h]]-1?e.dims[o[h]]:ne.normalizeAxis(p,e.dims[o[h]])),a=n.ends.map((p,h)=>p>e.dims[o[h]]-1?e.dims[o[h]]:ne.normalizeAxis(p,e.dims[o[h]])),s=e.dims.slice(),u=[];for(let p=0;p0&&u.push(`outputIdx[${o[p]}] += ${i[p]};`);let d=` float process(int outputIdx[${s.length}]) { ${u.join(` `)} return _A(outputIdx); }`;return{...ql,output:{dims:s,type:e.type,textureType:0},shaderSource:d}},SP=r=>{if(!r||r.length!==1)throw new Error("Slice requires 1 input.");if(mr.indexOf(r[0].type)===-1)throw new Error("Invalid input type.")},Ub=(r,e)=>{AP(e);let n=$P(r,e);return[r.run({...ql,cacheHint:n.cacheKey,get:()=>Gb(r,e[0],n)},[e[0]])]},$P=(r,e)=>{if(!r.session.isInitializer(e[1].dataId)||!r.session.isInitializer(e[2].dataId)||e.length>=4&&!r.session.isInitializer(e[3].dataId)||e.length>=5&&!r.session.isInitializer(e[4].dataId))throw new Error("dynamic slice attributes are not allowed");if(e.length>=5&&e[4].integerData.some(a=>a!==1))throw new Error("currently non-1 steps is not supported for Slice");let n=Array.from(e[1].integerData),t=Array.from(e[2].integerData),o=e.length>=4?Array.from(e[3].integerData):[],i=`${o};${n};${t}`;return{starts:n,ends:t,axes:o,cacheKey:i}},AP=r=>{if(!r||r.length<3||r.length>5)throw new Error("Invalid input number.");if(r[1].type!=="int32"||r[1].dims.length!==1)throw new Error("Invalid input type.");if(r[2].type!=="int32"||r[2].dims.length!==1)throw new Error("Invalid input type.");if(r.length>=4&&(r[3].type!=="int32"||r[3].dims.length!==1))throw new Error("Invalid input type.");if(r.length>=5&&(r[4].type!=="int32"||r[4].dims.length!==1))throw new Error("Invalid input type.")}});var Hb,qb,jb,Kb,Xb,Zb,Jb,Yb,OP,PP,EP,Qb,ey=N(()=>{"use strict";dt();ze();Je();Ae();Xi();Hb={name:"SoftmaxComputeMax",inputNames:["A"],inputTypes:[0]},qb={name:"SoftmaxComputeScale",inputNames:["A","Max"],inputTypes:[0,0]},jb={name:"SoftMax",inputNames:["A","Max","Norm"],inputTypes:[0,0,0]},Kb=(r,e,n)=>{Qb(e);let t=e[0].dims.slice(),o=ne.normalizeAxis(n.axis,t.length),i=ne.sizeToDimension(t,o),a=ne.sizeFromDimension(t,o);return Yb(r,e,n,i,a)},Xb=r=>_e({axis:r.attributes.getInt("axis",1)}),Zb=r=>_e({axis:r.attributes.getInt("axis",-1)}),Jb=(r,e,n)=>{Qb(e);let t=e[0].dims.slice(),o=ne.normalizeAxis(n.axis,t.length),i=t.length,a=o!==i-1,s=[],u=[],l=[],d;a&&(u=Array.from({length:i}).map((b,_)=>_),u[o]=i-1,u[i-1]=o,u.map(b=>s.push(t[b])),d=_e({perm:u}),l=Br(r,e,d));let p=a?ne.sizeToDimension(s,i-1):ne.sizeToDimension(t,i-1),h=a?ne.sizeFromDimension(s,i-1):ne.sizeFromDimension(t,i-1),g=Yb(r,a?l:e,n,p,h);return a?Br(r,g,d):g},Yb=(r,e,n,t,o)=>{let i=OP(r,e[0],t,o,[t]),a=r.run({...Hb,cacheHint:n.cacheKey,get:()=>i},e),s=PP(r,e[0],t,o,i.output.dims,[t]),u=r.run({...qb,cacheHint:n.cacheKey,get:()=>s},[e[0],a]),l=EP(r,e[0],t,o,i.output.dims,s.output.dims);return[r.run({...jb,cacheHint:n.cacheKey,get:()=>l},[e[0],a,u])]},OP=(r,e,n,t,o)=>{let[i,a]=r.calculateTextureWidthAndHeight(e.dims,0),s=o.length;if(n<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(o.length!==1)throw new Error("Dimensionality of the output should be 1");if(o[0]!==n)throw new Error("Shape of the output should be equal to logical row count");let u=se(r.session.backend.glContext.version),l=` float process(int[${s}] indices) { int logical_row_start_offset = indices[0] * ${t}; float max = getColorAsFloat(${u.texture2D}(A, offsetToCoords(logical_row_start_offset, ${i}, ${a} ))); for(int i=1; i<${t}; ++i) { float current = getColorAsFloat(${u.texture2D}(A, offsetToCoords(logical_row_start_offset + i, ${i}, ${a}))); if(current > max) max = current; } return max; }`;return{...Hb,output:{dims:o,type:e.type,textureType:0},shaderSource:l}},PP=(r,e,n,t,o,i)=>{let[a,s]=r.calculateTextureWidthAndHeight(e.dims,0),u=i.length;if(n<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(i.length!==1)throw new Error("Dimensionality of the output should be 1");if(i[0]!==n)throw new Error("Shape of the output should be equal to logical row count");if(o.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(o[0]!==n)throw new Error("Shape of the intermediate results should be equal to logical row count");let l=se(r.session.backend.glContext.version),d=` float process(int[${u}] indices) { int logical_row_start_offset = indices[0] * ${t}; float norm_factor = 0.0; float max = _Max(indices); for(int i=0; i<${t}; ++i) { norm_factor += exp(getColorAsFloat(${l.texture2D}(A, offsetToCoords(logical_row_start_offset + i, ${a}, ${s}))) - max); } return norm_factor; }`;return{...qb,output:{dims:i,type:e.type,textureType:0},shaderSource:d}},EP=(r,e,n,t,o,i)=>{let[a,s]=r.calculateTextureWidthAndHeight(e.dims,0),u=e.dims.length;if(n<1||t<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(o.length!==1||i.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(o[0]!==n||i[0]!==n)throw new Error("Shape of the intermediate results should be equal to logical row count");let l=` float process(int[${u}] indices) { // get offset of current logical tensor index from the 2-D texture coordinates (TexCoords) int offset = coordsToOffset(TexCoords, ${a}, ${s}); //determine the logical row for this index int logical_row_index[1]; logical_row_index[0] = offset / ${t}; float norm_factor = _Norm(logical_row_index); // avoid possible division by 0 // if norm_facor is 0, all elements are zero // if so, return 0 if(norm_factor == 0.0) return 0.0; return exp(_A(indices) - _Max(logical_row_index)) / norm_factor; }`;return{...jb,output:{dims:e.dims,type:e.type,textureType:0},shaderSource:l}},Qb=r=>{if(!r||r.length!==1)throw new Error("Softmax requires 1 input.");if(r[0].type!=="float32"&&r[0].type!=="float64")throw new Error("Invalid input type")}});var ty,ny,ry,CP,DP,kP,oy=N(()=>{"use strict";dt();ze();Ae();ty={name:"Split",inputNames:["A"],inputTypes:[0]},ny=(r,e,n)=>{kP(e);let t=ne.normalizeAxis(n.axis,e[0].dims.length),o=CP(r,e,t,n),i=[];for(let a=0;aDP(r,e[0],n,t,a)},e));return i},ry=r=>{let e=r.attributes.getInt("axis",0),n=r.attributes.getInts("split",[]),t=r.outputs.length;return _e({axis:e,split:n,numOutputs:t})},CP=(r,e,n,t)=>{let[,o]=Eo.splitShape(e[0].dims,n,t.split,t.numOutputs);return o.length},DP=(r,e,n,t,o)=>{let[i,a]=Eo.splitShape(e.dims,t,n.split,n.numOutputs),s=a[o],u=i[o],d=` float process(int indices[${u.length}]) { indices[${t}] += ${s}; return _A(indices); } `;return{...ty,cacheHint:`${n.cacheKey}:${o}`,output:{dims:u,type:e.type,textureType:0},shaderSource:d}},kP=r=>{if(!r||r.length!==1)throw new Error("Split requires one input.");if(r[0].type!=="int8"&&r[0].type!=="uint8"&&r[0].type!=="int16"&&r[0].type!=="uint16"&&r[0].type!=="int32"&&r[0].type!=="uint32"&&r[0].type!=="float32"&&r[0].type!=="float64"&&r[0].type!=="bool")throw new Error("Invalid input type.")}});var jl,iy,ay,NP,LP,sy=N(()=>{"use strict";ze();jl=(r,e,n)=>{NP(e);let t=ne.squeezeShape(e[0].dims,n);return[r.reshapeUnpacked(e[0],t)]},iy=(r,e)=>(LP(e),jl(r,[e[0]],Array.from(e[1].integerData))),ay=r=>r.attributes.getInts("axes"),NP=r=>{if(!r||r.length!==1)throw new Error("Squeeze requires 1 input.");if(r[0].type==="string")throw new Error("invalid input tensor types.")},LP=r=>{if(!r||r.length!==2)throw new Error("Squeeze requires 2 inputs.");if(r[1].type!=="int32")throw new Error("Invalid input type.")}});var uy,RP,zP,ly=N(()=>{"use strict";Je();Ae();uy=(r,e)=>{zP(e);let n={name:"Sum",inputNames:e.map((o,i)=>`X${i}`),inputTypes:new Array(e.length).fill(0)};return[r.run({...n,get:()=>RP(r,e,n)},e)]},RP=(r,e,n)=>{let t=se(r.session.backend.glContext.version),o=e[0].dims.slice(),a=` void main() { vec4 result = ${e.map((s,u)=>`${t.texture2D}(X${u},TexCoords)`).join(" + ")}; ${t.output} = result; } `;return{...n,output:{dims:o,type:e[0].type,textureType:0},hasMain:!0,shaderSource:a}},zP=r=>{if(!r||r.length===0)throw new Error("Sum requires inputs.");let e=r[0].dims.length;for(let n=1;n{"use strict";Ro();Ae();cy=(r,e)=>{BP(e);let n={name:"Tile",inputNames:["A"],inputTypes:[0]};return[r.run({...n,get:()=>MP(r,e,n)},e)]},MP=(r,e,n)=>{let t=e[0].dims.slice(),o=new Array(t.length),i=[];for(let u=0;u{if(!r||r.length!==2)throw new Error("Tile requires 2 input.");if(r[1].dims.length!==1)throw new Error("The second input shape must 1 dimension.");if(r[1].dims[0]!==r[0].dims.length)throw new Error("Invalid input shape.");if(mr.indexOf(r[0].type)===-1)throw new Error("Invalid input type.");if(r[1].type!=="int32"&&r[1].type!=="int16")throw new Error("Invalid repeat type.")}});var Kl,py,fy,FP,VP,hy=N(()=>{"use strict";ze();Kl=(r,e,n)=>{FP(e);let t=ne.unsqueezeShape(e[0].dims,n);return[r.reshapeUnpacked(e[0],t)]},py=(r,e)=>(VP(e),Kl(r,[e[0]],Array.from(e[1].integerData))),fy=r=>r.attributes.getInts("axes"),FP=r=>{if(!r||r.length!==1)throw new Error("Unsqueeze requires 1 input.");if(r[0].type==="string")throw new Error("invalid input tensor types.")},VP=r=>{if(!r||r.length!==2)throw new Error("Unsqueeze requires 2 inputs.");if(r[1].type!=="int32")throw new Error("Invalid input type.")}});var my,gy=N(()=>{"use strict";$m();Bm();Gm();Km();qi();Cg();zg();Fg();Ug();jg();Zg();eb();ob();ji();ub();vb();Pb();Cb();zb();Bb();Wb();ey();oy();sy();ly();dy();Xi();Cl();hy();Ul();my=[["Abs","","6+",Xm],["Acos","","7+",Zm],["Add","","7+",Am],["And","","7+",Om],["Asin","","7+",Jm],["Atan","","7+",Ym],["AveragePool","","7+",cb,db],["BatchNormalization","","7+",Im,Sm],["Cast","","6+",Fm,Vm],["Ceil","","6+",tg],["Clip","","6-10",Pl,Qm],["Clip","","11+",eg],["Concat","","4+",Hm,jm],["Conv","","1+",zl,Ml],["ConvTranspose","","1+",Pg,Eg],["Cos","","7+",ng],["Div","","7+",Pm],["Dropout","","7+",El],["DepthToSpace","","1+",Lg,Rg],["Equal","","7+",Em],["Elu","","6+",rg,og],["Exp","","6+",ig],["Flatten","","1+",Mg,Bg],["Floor","","6+",ag],["FusedConv","com.microsoft","1+",zl,Ml],["Gather","","1+",Vg,Gg],["Gemm","","7-10",Bl,Hg],["Gemm","","11+",Bl,qg],["GlobalAveragePool","","1+",fb,hb],["GlobalMaxPool","","1+",_b],["Greater","","7+",Cm],["Identity","","1+",El],["ImageScaler","","1+",Kg,Xg],["InstanceNormalization","","6+",Yg,Qg],["LeakyRelu","","6+",sg,ug],["Less","","7+",Dm],["LRN","","1+",tb,nb],["Log","","6+",lg],["MatMul","","1+",xg,Tg],["MaxPool","","1+",mb,gb],["Mul","","7+",km],["Neg","","6+",cg],["Not","","1+",dg],["Or","","7+",Nm],["Pad","","2-10",Fl,ib],["Pad","","11+",ab,sb],["Pow","","7+",Lm],["PRelu","","7+",Rm],["ReduceLogSum","","1+",Ab,gr],["ReduceMax","","1+",Ib,gr],["ReduceMean","","1+",Tb,gr],["ReduceMin","","1+",Sb,gr],["ReduceProd","","1+",$b,gr],["ReduceSum","","1-12",xb,gr],["ReduceSumSquare","","1+",Ob,gr],["Relu","","6+",pg],["Reshape","","5+",Eb],["Resize","","10",Hl,Lb],["Resize","","11+",Hl,Rb],["Shape","","1+",Mb],["Sigmoid","","6+",fg],["Sin","","7+",hg],["Slice","","10+",Ub],["Slice","","1-9",Fb,Vb],["Softmax","","1-12",Kb,Xb],["Softmax","","13+",Jb,Zb],["Split","","2-12",ny,ry],["Sqrt","","6+",mg],["Squeeze","","1-12",jl,ay],["Squeeze","","13+",iy],["Sub","","7+",zm],["Sum","","6+",uy],["Tan","","7+",gg],["Tanh","","6+",bg],["Tile","","6+",cy],["Transpose","","1+",Br,kg],["Upsample","","7-8",Vl,kb],["Upsample","","9",Vl,Nb],["Unsqueeze","","1-12",Kl,fy],["Unsqueeze","","13+",py],["Xor","","7+",Mm]]});function yy(r){let e={},n;for(;(n=by.exec(r))!==null;){let t=n[3].split(",").map(o=>{let i=o.trim().split(" ");return i&&i.length===2?{type:i[0],name:i[1]}:null}).filter(o=>o!==null);e[n[2]]={params:t,body:n[4]}}for(let t in e){let o=GP.replace("__FUNC__",t),i=new RegExp(o,"gm");for(;(n=i.exec(r))!==null;){let a=n[1],s=n[2],u=n[3].split(","),l=a?`${a} ${s};`:"",d=e[t].body,p="";e[t].params.forEach((g,b)=>{g&&(p+=`${g.type} ${g.name} = ${u[b]}; `)}),d=`${p} ${d}`,d=d.replace("return",`${s} = `);let h=` ${l} { ${d} } `;r=r.replace(n[0],h)}}return r=r.replace(by,""),r}var by,GP,_y=N(()=>{"use strict";by=/@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm,GP="(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;"});function ao(r,e){let n=[],t=[],o=e!=null&&Array.isArray(e)&&e.length===0,i=e==null||o?null:UP(e,r).sort(),a=0;for(let s=0;ss)&&r[s]===1&&(n.push(r[s]),t.push(s)),i[a]<=s&&a++}r[s]!==1&&(n.push(r[s]),t.push(s))}return{newShape:n,keptDims:t}}function UP(r,e){let n=e.length;return r=r==null?e.map((t,o)=>o):[].concat(r),eo(r.every(t=>t>=-n&&t`All values in axis param must be in range [-${n}, ${n}) but got axis ${r}`),eo(r.every(WP),()=>`All values in axis param must be integers but got axis ${r}`),r.map(t=>t<0?n+t:t)}function WP(r){return r%1===0}function HP(r){if(r.length===0)return 1;let e=r[0];for(let n=1;n{"use strict";Dt();ze();Qi=class{constructor(e){this.maxTextureSize=e}computeTextureWH(e,n){let t=this.computeTexture(e,n);return n&&n.isPacked&&(t[0]/=2,t[1]/=2),n&&n.reverseWH?[t[1],t[0]]:t}computeTexture(e,n){let t=n&&n.isPacked;if(e.length===0)return t?[2,2]:[1,1];let o=this.maxTextureSize;if(n&&n.breakAxis!==void 0){let s=n.breakAxis>=e.length?1:e.slice(n.breakAxis).reduce((l,d)=>l*d),u=n.breakAxis<=0?1:e.slice(0,n.breakAxis).reduce((l,d)=>l*d);if(s>o||u>o)Be.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${e}, breakAxis:${n.breakAxis}`);else return[s,u]}let i=e.slice(0);t&&(o=o*2,i=i.map((s,u)=>u>=i.length-2?i[u]%2===0?i[u]:i[u]+1:i[u]),i.length===1&&(i=[2,i[0]])),i.length!==2&&(i=ao(i).newShape);let a=HP(i);return i.length<=1&&a<=o?[1,a]:i.length===2&&i[0]<=o&&i[1]<=o?i:i.length===3&&i[0]*i[1]<=o&&i[2]<=o?[i[0]*i[1],i[2]]:i.length===3&&i[0]<=o&&i[1]*i[2]<=o?[i[0],i[1]*i[2]]:i.length===4&&i[0]*i[1]*i[2]<=o&&i[3]<=o?[i[0]*i[1]*i[2],i[3]]:i.length===4&&i[0]<=o&&i[1]*i[2]*i[3]<=o?[i[0],i[1]*i[2]*i[3]]:t?wy(a/4).map(s=>s*2):wy(a)}}});var ea,vy=N(()=>{"use strict";ze();Yn();Je();Xl();zn();ea=class extends Mt{constructor(e){super(e)}getFunctions(){return{...this.offsetToCoords(),...this.coordsToOffset(),...this.toVec(),...this.valueFrom(),...this.getCommonUtilFuncs(),...this.getInputsSamplingSnippets(),...this.getOutputSamplingSnippet()}}getCustomTypes(){return{}}offsetToCoords(){let e="offsetToCoords";return{offsetToCoords:new X(` vec2 ${e}(int offset, int width, int height) { int t = offset / width; int s = offset - t*width; vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height); return coords; } `)}}coordsToOffset(){let e="coordsToOffset";return{coordsToOffset:new X(` int ${e}(vec2 coords, int width, int height) { float s = coords.s * float(width); float t = coords.t * float(height); int offset = int(t) * width + int(s); return offset; } `)}}getOutputSamplingSnippet(){let e=this.context.outputTextureLayout;return e.isPacked?this.getPackedOutputSamplingSnippet(e):this.getUnpackedOutputSamplingSnippet(e)}getPackedOutputSamplingSnippet(e){let n=e.unpackedShape,t=[e.width,e.height],o={},i="getOutputCoords";switch(n.length){case 0:o[i]=this.getOutputScalarCoords();break;case 1:o[i]=this.getOutputPacked1DCoords(n,t);break;case 2:o[i]=this.getOutputPacked2DCoords(n,t);break;case 3:o[i]=this.getOutputPacked3DCoords(n,t);break;default:o[i]=this.getOutputPackedNDCoords(n,t)}let s=` void setOutput(vec4 val) { ${se(this.context.glContext.version).output} = val; } `,u="floatTextureSetRGBA";return o[u]=new X(s),o}getUnpackedOutputSamplingSnippet(e){let n=e.unpackedShape,t=[e.width,e.height],o={},i="getOutputCoords";switch(n.length){case 0:o[i]=this.getOutputScalarCoords();break;case 1:o[i]=this.getOutputUnpacked1DCoords(n,t);break;case 2:o[i]=this.getOutputUnpacked2DCoords(n,t);break;case 3:o[i]=this.getOutputUnpacked3DCoords(n,t);break;case 4:o[i]=this.getOutputUnpacked4DCoords(n,t);break;case 5:o[i]=this.getOutputUnpacked5DCoords(n,t);break;case 6:o[i]=this.getOutputUnpacked6DCoords(n,t);break;default:throw new Error(`Unsupported output dimensionality: ${n.length}`)}let s=` void setOutput(float val) { ${se(this.context.glContext.version).output} = vec4(val, 0, 0, 0); } `,u="floatTextureSetR";return o[u]=new X(s),o}getOutputScalarCoords(){return new X(` int getOutputCoords() { return 0; } `)}getOutputPacked1DCoords(e,n){let t=n,o="";return t[0]===1?(o=` int getOutputCoords() { return 2 * int(TexCoords.y * ${t[1]}.0); } `,new X(o)):t[1]===1?(o=` int getOutputCoords() { return 2 * int(TexCoords.x * ${t[0]}.0); } `,new X(o)):(o=` int getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${t[0]}, ${t[1]})); return 2 * (resTexRC.y * ${t[0]} + resTexRC.x); } `,new X(o))}getOutputPacked2DCoords(e,n){let t="";if(Dr.arraysEqual(e,n))return t=` ivec2 getOutputCoords() { return 2 * ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); } `,new X(t);let o=n,i=Math.ceil(e[1]/2);return t=` ivec2 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${o[0]}, ${o[1]})); int index = resTexRC.y * ${o[0]} + resTexRC.x; // reverse r and c order for packed texture int r = imod(index, ${i}) * 2; int c = 2 * (index / ${i}); return ivec2(r, c); } `,new X(t)}getOutputPacked3DCoords(e,n){let t=[n[0],n[1]],o=Math.ceil(e[2]/2),i=o*Math.ceil(e[1]/2),a=` ivec3 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${t[0]}, ${t[1]})); int index = resTexRC.y * ${t[0]} + resTexRC.x; int b = index / ${i}; index -= b * ${i}; // reverse r and c order for packed texture int r = imod(index, ${o}) * 2; int c = 2 * (index / ${o}); return ivec3(b, r, c); } `;return new X(a)}getOutputPackedNDCoords(e,n){let t=[n[0],n[1]],o=Math.ceil(e[e.length-1]/2),i=o*Math.ceil(e[e.length-2]/2),a=i,s="",u="b, r, c";for(let d=2;d=0;--u)i[u]=i[u+1]*e[u+1];let a=["r","c","d"],s=i.map((u,l)=>{let d=`int ${a[l]} = index / ${u}`,p=l===i.length-1?`int ${a[l+1]} = index - ${a[l]} * ${u}`:`index -= ${a[l]} * ${u}`;return`${d}; ${p};`}).join("");return t=` ivec3 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); int index = resTexRC.y * ${n[0]} + resTexRC.x; ${s} return ivec3(r, c, d); } `,new X(t)}getOutputUnpacked4DCoords(e,n){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let u=o-3;u>=0;--u)i[u]=i[u+1]*e[u+1];let a=["r","c","d","d2"],s=i.map((u,l)=>{let d=`int ${a[l]} = index / ${u}`,p=l===i.length-1?`int ${a[l+1]} = index - ${a[l]} * ${u}`:`index -= ${a[l]} * ${u}`;return`${d}; ${p};`}).join("");return t=` ivec4 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); int index = resTexRC.y * ${n[0]} + resTexRC.x; ${s} return ivec4(r, c, d, d2); } `,new X(t)}getOutputUnpacked5DCoords(e,n){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let u=o-3;u>=0;--u)i[u]=i[u+1]*e[u+1];let a=["r","c","d","d2","d3"],s=i.map((u,l)=>{let d=`int ${a[l]} = index / ${u}`,p=l===i.length-1?`int ${a[l+1]} = index - ${a[l]} * ${u}`:`index -= ${a[l]} * ${u}`;return`${d}; ${p};`}).join("");return t=` ivec5 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); int index = resTexRC.y * ${n[0]} + resTexRC.x; ${s} return ivec5(r, c, d, d2, d3); } `,new X(t)}getOutputUnpacked6DCoords(e,n){let t="",o=e.length,i=null;o<2&&(i=[]),i=new Array(o-1),i[o-2]=e[o-1];for(let u=o-3;u>=0;--u)i[u]=i[u+1]*e[u+1];let a=["r","c","d","d2","d3","d4"],s=i.map((u,l)=>{let d=`int ${a[l]} = index / ${u}`,p=l===i.length-1?`int ${a[l+1]} = index - ${a[l]} * ${u}`:`index -= ${a[l]} * ${u}`;return`${d}; ${p};`}).join("");return t=` ivec6 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); int index = resTexRC.y * ${n[0]} + resTexRC.x; ${s} return ivec6(r, c, d, d2, d3, d4); } `,new X(t)}getCommonUtilFuncs(){let e={},n="uvFromFlat";e[n]=new X(` vec2 uvFromFlat(int texNumR, int texNumC, int index) { int texC = index / texNumR; int texR = index - texC * texNumR; // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to // v. return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC); } `),n="packedUVfrom1D",e[n]=new X(` vec2 packedUVfrom1D(int texNumR, int texNumC, int index) { int texelIndex = index / 2; int texR = texelIndex / texNumC; int texC = texelIndex - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),n="packedUVfrom2D",e[n]=new X(` vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) { int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2); int texR = texelIndex / texNumC; int texC = texelIndex - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),n="packedUVfrom3D",e[n]=new X(` vec2 packedUVfrom3D(int texNumR, int texNumC, int texelsInBatch, int texelsInLogicalRow, int b, int row, int col) { int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2); int texR = index / texNumC; int texC = index - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),n="sampleTexture";let t=se(this.context.glContext.version);return e[n]=new X(` float sampleTexture(sampler2D textureSampler, vec2 uv) { return ${t.texture2D}(textureSampler, uv).r; }`),e}getInputsSamplingSnippets(){let e={},n=this.context.outputTextureLayout;return this.context.programInfo.inputNames.forEach((t,o)=>{let i=this.context.inputTextureLayouts[o],a=Bi(t);i.isPacked?e[a]=this.getPackedSamplerFromInput(a,t,i):e[a]=this.getUnpackedSamplerFromInput(a,t,i);let s=um(t);i.unpackedShape.length<=n.unpackedShape.length&&(i.isPacked?e[s]=this.getPackedSamplerAtOutputCoords(s,i,n,t):e[s]=this.getUnpackedSamplerAtOutputCoords(s,i,n,t))}),e}getPackedSamplerAtOutputCoords(e,n,t,o){let i=n.unpackedShape,a=t.unpackedShape,u=Bi(o),l=i.length,d=a.length,p=bt.getBroadcastDims(i,a),h=yt(d),g=d-l,b,_=Xt();l===0?b="":d<2&&p.length>=1?b="coords = 0;":b=p.map(x=>`coords.${_[x+g]} = 0;`).join(` `);let I="";d<2&&l>0?I="coords":I=i.map((x,B)=>`coords.${_[B+g]}`).join(", ");let w="return outputValue;",S=ne.size(i)===1,P=ne.size(a)===1;if(l===1&&!S&&!P)w=` return vec4(outputValue.xy, outputValue.xy); `;else if(S&&!P)d===1?w=` return vec4(outputValue.x, outputValue.x, 0., 0.); `:w=` return vec4(outputValue.x); `;else if(p.length){let x=l-2,B=l-1;p.indexOf(x)>-1&&p.indexOf(B)>-1?w="return vec4(outputValue.x);":p.indexOf(x)>-1?w="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":p.indexOf(B)>-1&&(w="return vec4(outputValue.xx, outputValue.zz);")}let C=` int lastDim = coords.${_[d-1]}; coords.${_[d-1]} = coords.${_[d-2]}; coords.${_[d-2]} = lastDim; `,R=` vec4 ${e}() { ${h} coords = getOutputCoords(); ${C} ${b} vec4 outputValue = ${u}(${I}); ${w} } `;return new X(R,["coordinates.getOutputCoords"])}getUnpackedSamplerAtOutputCoords(e,n,t,o){let i=[t.width,t.height],a=[n.width,n.height],s=n.unpackedShape.length,u=t.unpackedShape.length,l=n.unpackedShape,d=t.unpackedShape,p=Bi(o);if(s===u&&Dr.arraysEqual(a,i)){let S=` float ${e}() { return sampleTexture(${o}, TexCoords); } `;return new X(S,["coordinates.sampleTexture"])}let h=yt(u),g=bt.getBroadcastDims(l,d),b=u-s,_,I=Xt();s===0?_="":u<2&&g.length>=1?_="coords = 0;":_=g.map(S=>`coords.${I[S+b]} = 0;`).join(` `);let w="";u<2&&s>0?w="coords":w=n.unpackedShape.map((S,A)=>`coords.${I[A+b]}`).join(", ");let v=` float ${e}() { ${h} coords = getOutputCoords(); ${_} return ${p}(${w}); } `;return new X(v,["coordinates.getOutputCoords"])}getPackedSamplerFromInput(e,n,t){switch(t.unpackedShape.length){case 0:return this.getPackedSamplerScalar(e,n);case 1:return this.getPackedSampler1D(e,n,t);case 2:return this.getPackedSampler2D(e,n,t);case 3:return this.getPackedSampler3D(e,n,t);default:return this.getPackedSamplerND(e,n,t)}}getUnpackedSamplerFromInput(e,n,t){let o=t.unpackedShape;switch(o.length){case 0:return this.getUnpackedSamplerScalar(e,n,t);case 1:return this.getUnpackedSampler1D(e,n,t);case 2:return this.getUnpackedSampler2D(e,n,t);case 3:return this.getUnpackedSampler3D(e,n,t);case 4:return this.getUnpackedSampler4D(e,n,t);case 5:return this.getUnpackedSampler5D(e,n,t);case 6:return this.getUnpackedSampler6D(e,n,t);default:throw new Error(`Unsupported dimension ${o.length}-D`)}}getPackedSamplerScalar(e,n){let t=se(this.context.glContext.version),o=` vec4 ${e}() { return ${t.texture2D}(${n}, halfCR); } `;return new X(o)}getPackedSampler1D(e,n,t){let o=[t.width,t.height],i=[o[1],o[0]],a=se(this.context.glContext.version),u=`vec4 ${e}(int index) { vec2 uv = packedUVfrom1D( ${i[0]}, ${i[1]}, index); return ${a.texture2D}(${n}, uv); }`;return new X(u,["coordinates.packedUVfrom1D"])}getPackedSampler2D(e,n,t){let o=t.unpackedShape,i=[t.width,t.height],a=se(this.context.glContext.version),s=i[0],u=i[1];if(i!=null&&Dr.arraysEqual(o,i)){let g=`vec4 ${e}(int row, int col) { vec2 uv = (vec2(col, row) + halfCR) / vec2(${u}.0, ${s}.0); return ${a.texture2D}(${n}, uv); }`;return new X(g)}let l=i,d=Math.ceil(o[1]/2),h=`vec4 ${e}(int row, int col) { vec2 uv = packedUVfrom2D(${l[1]}, ${l[0]}, ${d}, row, col); return ${a.texture2D}(${n}, uv); }`;return new X(h,["coordinates.packedUVfrom2D"])}getPackedSampler3D(e,n,t){let o=t.unpackedShape,i=[t.width,t.height],a=[i[0],i[1]],s=se(this.context.glContext.version);if(o[0]===1){let b=o.slice(1),_=[1,2],I=to(o,b),w=["b","row","col"],v=JSON.parse(JSON.stringify(t));v.unpackedShape=I;let S=this.getPackedSamplerFromInput(e,n,v),P=`${S.routineBody} vec4 ${e}(int b, int row, int col) { return ${e}(${no(w,_)}); } `;return new X(P,S.dependencies)}let u=a[0],l=a[1],d=Math.ceil(o[2]/2),p=d*Math.ceil(o[1]/2),g=`vec4 ${e}(int b, int row, int col) { vec2 uv = packedUVfrom3D( ${l}, ${u}, ${p}, ${d}, b, row, col); return ${s.texture2D}(${n}, uv);}`;return new X(g,["coordinates.packedUVfrom3D"])}getPackedSamplerND(e,n,t){let o=t.unpackedShape,i=o.length,a=[t.width,t.height],s=se(this.context.glContext.version),u=[a[0],a[1]],l=u[1],d=u[0],p=Math.ceil(o[i-1]/2),h=p*Math.ceil(o[i-2]/2),g="int b, int row, int col",b=`b * ${h} + (row / 2) * ${p} + (col / 2)`;for(let w=2;w{let o=this.context.inputTextureLayouts[t],a=(o.unpackedShape.length>0?o.unpackedShape:o.shape).length,s=`_${n}`;e[s]=new X(this.getValueFromSingle(n,a,o.width,o.height,!1),[`shapeUtils.indicesToOffset${s}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"]),s=s+"_T",e[s]=new X(this.getValueFromSingle(n,a,o.width,o.height,!0),[`shapeUtils.indicesToOffset${s}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"])}),e}getValueFromSingle(e,n,t,o,i){let a=`_${e}`;i&&(a=a+"_T");let s=se(this.context.glContext.version);return` float ${a}(int m[${n}]) { int offset = indicesToOffset${a}(m); vec2 coords = offsetToCoords(offset, ${t}, ${o}); float value = getColorAsFloat(${s.texture2D}(${e}, coords)); return value; } `}getPackedValueFrom(e,n,t,o,i){let a=`_${e}_Pack`;i&&(a=a+"_T");let s=se(this.context.glContext.version);return` vec4 ${a}(int m[${n}]) { int offset = indicesToOffset_${e}(m); vec2 coords = offsetToCoords(offset, ${t}, ${o}); return ${s.texture2D}(${e}, coords); } `}}});var ta,xy=N(()=>{"use strict";Yn();ta=class r extends Mt{constructor(e){super(e)}getFunctions(){return{...this.encodeFloat32(),...this.decodeFloat32()}}getCustomTypes(){return{}}encodeFloat32(){return{encode:new X(`highp vec4 encode(highp float f) { return vec4(f, 0.0, 0.0, 0.0); } `)}}decodeFloat32(){return{decode:new X(`highp float decode(highp vec4 rgba) { return rgba.r; } `)}}encodeUint8(){let e=r.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{encode:new X(` highp vec4 encode(highp float f) { highp float F = abs(f); highp float Sign = step(0.0,-f); highp float Exponent = floor(log2(F)); highp float Mantissa = (exp2(- Exponent) * F); Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa)); highp vec4 rgba; rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0)); rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0); rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0))); rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0))); ${e} rgba = rgba / 255.0; // values need to be normalized to [0,1] return rgba; } `)}}decodeUint8(){let e=r.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{decode:new X(` highp float decode(highp vec4 rgba) { rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255] ${e} highp float Sign = 1.0 - step(128.0,rgba[0])*2.0; highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0; highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000); highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 )); return Result; } `)}}static isLittleEndian(){let e=new ArrayBuffer(4),n=new Uint32Array(e),t=new Uint8Array(e);if(n[0]=3735928559,t[0]===239)return!0;if(t[0]===222)return!1;throw new Error("unknown endianness")}}});var na,Ty=N(()=>{"use strict";Yn();Je();na=class extends Mt{constructor(e){super(e)}getFunctions(){return{...this.setFragColor(),...this.getColorAsFloat()}}getCustomTypes(){return{}}setFragColor(){let e=se(this.context.glContext.version);return{setFragColor:new X(` void setFragColor(float value) { ${e.output} = encode(value); } `,["encoding.encode"])}}getColorAsFloat(){return{getColorAsFloat:new X(` float getColorAsFloat(vec4 color) { return decode(color); } `,["encoding.decode"])}}}});var ra,Iy=N(()=>{"use strict";Yn();ra=class r extends Mt{constructor(e){super(e)}getFunctions(){return{...this.bcastIndex(),...this.bcastMatmulIndex(),...this.offsetToIndices(),...this.indicesToOffset(),...this.incrementIndices()}}getCustomTypes(){return{}}bcastIndex(){let e=this.context.outputTextureLayout.shape.length,n={};return this.context.programInfo.inputNames.forEach((t,o)=>{let i=this.context.inputTextureLayouts[o].unpackedShape;if(i.length<=e){let a=i.length,s=e-a,u=`bcastIndices_${t}`,l="";for(let p=0;p{let i=this.context.inputTextureLayouts[o].shape;if(!(i.length<2||i.length>e)){let a=i.length,s=e-a,u=`bcastMatmulIndices_${t}`,l="";for(let p=0;p{let o=this.context.inputTextureLayouts[t].shape,i=this.context.inputTextureLayouts[t].strides,a=o.length,s=`indicesToOffset_${n}`;e[s]=new X(r.indexToOffsetSingle(s,a,i)),s=`indicesToOffset_${n}_T`,e[s]=new X(r.indexToOffsetSingle(s,a,i.slice().reverse()))}),e}static indexToOffsetSingle(e,n,t){let o="";for(let i=n-1;i>=0;--i)o+=` offset += indices[${i}] * ${t[i]}; `;return` int ${e}(int indices[${n}]) { int offset = 0; ${o} return offset; } `}offsetToIndices(){let e={};return this.context.programInfo.inputNames.forEach((n,t)=>{let o=this.context.inputTextureLayouts[t].shape,i=this.context.inputTextureLayouts[t].strides,a=o.length,s=`offsetToIndices_${n}`;e[s]=new X(r.offsetToIndicesSingle(s,a,i)),s=`offsetToIndices_${n}_T`,e[s]=new X(r.offsetToIndicesSingle(s,a,i.slice().reverse()))}),e}static offsetToIndicesSingle(e,n,t){let o=[];for(let i=0;i{let o=this.context.inputTextureLayouts[t].shape,i=o.length,a=`incrementIndices_${n}`,s="";for(let l=0;l= 0; --i) { if(i > axis) continue; indices[i] += 1; if(indices[i] < shape[i]) { break; } indices[i] = 0; } } `;e[a]=new X(u)}),e}}});var oa,Sy=N(()=>{"use strict";Yn();oa=class extends Mt{constructor(e){super(e)}getCustomTypes(){return{}}getFunctions(){return{...this.binaryVecFunctions(),...this.copyVec(),...this.setVecItem(),...this.getVecItem()}}binaryVecFunctions(){let n=this.context.outputTextureLayout.shape.length,t={add:"+=",sub:"-=",mul:"*=",div:"/="},o={};for(let i in t){let a=`${i}Vec`,s="";for(let l=0;l{"use strict";vy();xy();Ty();Iy();Sy();Zl={encoding:ta,fragcolor:na,vec:oa,shapeUtils:ra,coordinates:ea}});var ia,Ay=N(()=>{"use strict";Yn();_y();$y();Je();ia=class{constructor(e,n,t,o){this.libs={};this.glslLibRoutineDependencyGraph={};this.context=new Ui(e,n,t,o),Object.keys(Zl).forEach(a=>{let s=new Zl[a](this.context);this.libs[a]=s});let i=this.glslLibRoutineDependencyGraph;for(let a in this.libs){let u=this.libs[a].getFunctions();for(let l in u){let d=a+"."+l,p;i[d]?(p=i[d],p.routineBody=u[l].routineBody):(p=new Lo(d,u[l].routineBody),i[d]=p);let h=u[l].dependencies;if(h)for(let g=0;g{let o=t.split(".")[1];e.indexOf(o)!==-1&&n.push(this.glslLibRoutineDependencyGraph[t])}),Wi.returnOrderedNodes(n)}getUniforms(e,n){let t=[];if(e)for(let o of e)t.push(`uniform sampler2D ${o};`);if(n)for(let o of n)t.push(`uniform ${o.type} ${o.name}${o.arrayLength?`[${o.arrayLength}]`:""};`);return t.join(` `)}}});var aa,Oy=N(()=>{"use strict";ft();Dt();Ay();Je();aa=class{constructor(e,n,t){this.profiler=e;this.glContext=n;this.textureLayoutStrategy=t;this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,n){this.repo.set(e,n)}run(e,n,t){this.profiler.event("op",`ProgramManager.run ${e.programInfo.name??"unknown kernel"}`,()=>{let o=this.glContext.gl,i=e.program;o.useProgram(i);try{this.bindOutput(t),this.attributesBound||this.bindAttributes(e.attribLocations),this.bindUniforms(e.uniformLocations,e.programInfo.variables??[],n)}catch(a){throw Be.error("ProgramManager",e.programInfo.shaderSource),a}this.profiler.event("backend","GlContext.draw()",()=>{this.glContext.draw()})},this.glContext)}dispose(){this.vertexShader&&this.glContext.deleteShader(this.vertexShader),this.repo.forEach(e=>this.glContext.deleteProgram(e.program))}build(e,n,t){return this.profiler.event("backend","ProgramManager.build",()=>{let o=new ia(this.glContext,e,n,t),i=o.preprocess(),a=this.compile(i);return{programInfo:e,program:a,uniformLocations:this.getUniformLocations(a,o.context.programInfo.inputNames,o.context.programInfo.variables),attribLocations:this.getAttribLocations(a)}})}compile(e){if(!this.vertexShader){Be.verbose("ProrgramManager","Compiling and caching Vertex shader for the first time");let o=im(this.glContext.version);this.vertexShader=this.glContext.compileShader(o,this.glContext.gl.VERTEX_SHADER)}ce.debug&&Be.verbose("ProrgramManager",`FragShader: ${e} `);let n=this.glContext.compileShader(e,this.glContext.gl.FRAGMENT_SHADER),t=this.glContext.createProgram(this.vertexShader,n);return this.glContext.deleteShader(n),t}bindOutput(e){let n=e.width,t=e.height;Be.verbose("ProrgramManager",`Binding output texture to Framebuffer: w/h=${n}/${t}, shape=${e.shape}, type=${e.tensor.type}`),this.glContext.attachFramebuffer(e.texture,n,t)}bindAttributes(e){let n=e.position,t=e.textureCoord;this.glContext.setVertexAttributes(n,t),this.attributesBound=!0}bindUniforms(e,n,t){let o=this.glContext.gl,i=0;for(let{name:a,type:s,location:u,arrayLength:l}of e){let d=n.find(p=>p.name===a)?.data;if(s!=="sampler2D"&&!d)throw new Error(`variable '${a}' does not have data defined in program info`);switch(s){case"sampler2D":this.bindTexture(t[i],u,i),i++;break;case"float":l?o.uniform1fv(u,d):o.uniform1f(u,d);break;case"int":l?o.uniform1iv(u,d):o.uniform1i(u,d);break;default:throw new Error(`Uniform not implemented: ${s}`)}}}bindTexture(e,n,t){this.glContext.bindTextureToUniform(e.texture,t,n)}getAttribLocations(e){return{position:this.getAttribLocation(e,"position"),textureCoord:this.getAttribLocation(e,"textureCoord")}}getUniformLocations(e,n,t){let o=[];if(n)for(let i of n)o.push({name:i,type:"sampler2D",location:this.getUniformLocation(e,i)});if(t)for(let i of t)o.push({...i,location:this.getUniformLocation(e,i.name)});return o}getUniformLocation(e,n){let o=this.glContext.gl.getUniformLocation(e,n);if(o===null)throw new Error(`Uniform ${n} not found.`);return o}getAttribLocation(e,n){return this.glContext.gl.getAttribLocation(e,n)}}});var sa,Py=N(()=>{"use strict";Dt();ko();sa=class{constructor(e,n,t,o){this.glContext=e;this.layoutStrategy=n;this.profiler=t;this.config=o;this.pendingRead=new Map;o.reuseTextures&&(this.inUseTextures=new Map,this.idleTextures=new Map,this.textureLookup=new Map)}createTextureFromLayout(e,n,t,o){let i=this.toEncoderType(e),a=this.glContext.getEncoder(i,n.channels||1,o);if(n.isPacked&&o===1)throw new Error("not implemented");let s=n.width,u=n.height,l,d;if(this.config.reuseTextures){l=`${s}x${u}_${a.format}_${a.internalFormat}_${a.textureType}`,d=this.inUseTextures.get(l),d||(d=[],this.inUseTextures.set(l,d));let h=this.idleTextures.get(l);if(h&&h.length>0){let g=h.pop();return d.push(g),o===1&&this.glContext.updateTexture(g,s,u,a,this.toTextureData(e,t)),g}}Be.verbose("TextureManager",`Creating new texture of size ${n.width}x${n.height}`);let p=this.glContext.allocateTexture(s,u,a,this.toTextureData(e,t));return this.config.reuseTextures&&(d.push(p),this.textureLookup.set(p,l)),p}readTexture(e,n,t){return t||(t=1),this.profiler.event("backend","TextureManager.readTexture",()=>{let o=e.shape.reduce((a,s)=>a*s)*t,i=this.glContext.readTexture(e.texture,e.width,e.height,o,this.toEncoderType(n),t);return this.toTensorData(n,i)})}async readTextureAsync(e,n,t){let o=e.tensor.dataId;if(t||(t=1),this.pendingRead.has(o)){let i=this.pendingRead.get(o);return new Promise(a=>i?.push(a))}return this.profiler.event("backend","TextureManager.readTextureAsync",async()=>{this.pendingRead.set(o,[]);let i=e.shape.reduce((l,d)=>l*d)*t;await this.glContext.createAndWaitForFence();let a=this.glContext.readTexture(e.texture,e.width,e.height,i,this.toEncoderType(n),t),s=this.toTensorData(n,a),u=this.pendingRead.get(o);return this.pendingRead.delete(o),u?.forEach(l=>l(s)),s})}readUint8TextureAsFloat(e){return this.profiler.event("backend","TextureManager.readUint8TextureAsFloat",()=>{let n=e.shape.reduce((o,i)=>o*i),t=this.glContext.readTexture(e.texture,e.width,e.height,n*4,"byte",4);return new Float32Array(t.buffer,t.byteOffset,n)})}releaseTexture(e,n){let t;if(this.config.reuseTextures&&(t=this.textureLookup.get(e.texture),t)){n&&this.textureLookup.delete(t);let o=this.inUseTextures.get(t);if(o){let i=o.indexOf(e.texture);if(i!==-1){o.splice(i,1);let a=this.idleTextures.get(t);a||(a=[],this.idleTextures.set(t,a)),a.push(e.texture)}}}(!t||n)&&(Be.verbose("TextureManager",`Deleting texture of size ${e.width}x${e.height}`),this.glContext.deleteTexture(e.texture))}toTensorData(e,n){switch(e){case"int16":return n instanceof Int16Array?n:Int16Array.from(n);case"int32":return n instanceof Int32Array?n:Int32Array.from(n);case"int8":return n instanceof Int8Array?n:Int8Array.from(n);case"uint16":return n instanceof Uint16Array?n:Uint16Array.from(n);case"uint32":return n instanceof Uint32Array?n:Uint32Array.from(n);case"uint8":case"bool":return n instanceof Uint8Array?n:Uint8Array.from(n);case"float32":return n instanceof Float32Array?n:Float32Array.from(n);case"float64":return n instanceof Float64Array?n:Float64Array.from(n);default:throw new Error(`TensorData type ${e} is not supported`)}}toTextureData(e,n){if(n)return n instanceof Float32Array?n:new Float32Array(n)}toEncoderType(e){return"float"}clearActiveTextures(){this.glContext.clearActiveTextures()}}});var ua,Ey=N(()=>{"use strict";Dt();_f();xm();gy();Oy();Xl();Py();ua=class{constructor(e,n){this.backend=e;this.context=n;this.layoutStrategy=new Qi(e.glContext.maxTextureSize),this.programManager=new aa(this.context.profiler,e.glContext,this.layoutStrategy),this.textureManager=new sa(e.glContext,this.layoutStrategy,this.context.profiler,{reuseTextures:e.textureCacheMode==="full"}),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map,this.pack=e.pack,this.pack2unpackMap=new Map,this.unpack2packMap=new Map}createInferenceHandler(){return new Gi(this)}onGraphInitialized(e){let n=e.getValues().filter(t=>t.from===-1&&t.tensor).map(t=>t.tensor.dataId);this.initializers=new Set(n)}isInitializer(e){return this.initializers?this.initializers.has(e):!1}addInitializer(e){this.initializers.add(e)}getTextureData(e,n){return n?this.packedTextureDataCache.get(e):this.unpackedTextureDataCache.get(e)}setTextureData(e,n,t=!1){Be.verbose("WebGLSessionHandler","Storing Texture data in cache"),t?this.packedTextureDataCache.set(e,n):this.unpackedTextureDataCache.set(e,n)}dispose(){this.programManager.dispose(),this.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(e=>this.textureManager.releaseTexture(e,!0)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(e=>this.textureManager.releaseTexture(e,!0)),this.unpackedTextureDataCache=new Map}resolve(e,n,t){let o=yf(e,n,my);return{impl:o.opImpl,context:o.opInit?o.opInit(e,t):e}}}});function qP(r){let e=0;for(;e{"use strict";ft();ko();ko();zn();Mo=class{constructor(e,n){this.frameBufferBound=!1;this.itemsToPoll=[];this.gl=e,this.version=n,this.getExtensions(),this.vertexbuffer=this.createVertexbuffer(),this.framebuffer=this.createFramebuffer(),this.queryVitalParameters()}allocateTexture(e,n,t,o){let i=this.gl,a=i.createTexture();i.bindTexture(i.TEXTURE_2D,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE);let s=o?t.encode(o,e*n):null;return i.texImage2D(i.TEXTURE_2D,0,t.internalFormat,e,n,0,t.format,t.textureType,s),this.checkError(),a}updateTexture(e,n,t,o,i){let a=this.gl;a.bindTexture(a.TEXTURE_2D,e);let s=o.encode(i,n*t);a.texSubImage2D(a.TEXTURE_2D,0,0,0,n,t,o.format,o.textureType,s),this.checkError()}attachFramebuffer(e,n,t){let o=this.gl;o.bindTexture(o.TEXTURE_2D,e),o.bindFramebuffer(o.FRAMEBUFFER,this.framebuffer),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,e,0),this.checkError(),o.viewport(0,0,n,t),o.scissor(0,0,n,t)}readTexture(e,n,t,o,i,a){let s=this.gl;a||(a=1),this.frameBufferBound||this.attachFramebuffer(e,n,t);let u=this.getEncoder(i,a),l=u.allocate(n*t);return s.bindTexture(s.TEXTURE_2D,e),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,e,0),s.readPixels(0,0,n,t,s.RGBA,u.textureType,l),this.checkError(),u.decode(l,o)}isFramebufferReady(){return!0}getActiveTexture(){let e=this.gl;return`TEXTURE${e.getParameter(this.gl.ACTIVE_TEXTURE)-e.TEXTURE0}`}getTextureBinding(){return this.gl.getParameter(this.gl.TEXTURE_BINDING_2D)}getFramebufferBinding(){return this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING)}setVertexAttributes(e,n){let t=this.gl;t.vertexAttribPointer(e,3,t.FLOAT,!1,20,0),t.enableVertexAttribArray(e),n!==-1&&(t.vertexAttribPointer(n,2,t.FLOAT,!1,20,12),t.enableVertexAttribArray(n)),this.checkError()}createProgram(e,n){let t=this.gl,o=t.createProgram();return t.attachShader(o,e),t.attachShader(o,n),t.linkProgram(o),o}compileShader(e,n){let t=this.gl,o=t.createShader(n);if(!o)throw new Error(`createShader() returned null with type ${n}`);if(t.shaderSource(o,e),t.compileShader(o),t.getShaderParameter(o,t.COMPILE_STATUS)===!1)throw new Error(`Failed to compile shader: ${t.getShaderInfoLog(o)} Shader source: ${e}`);return o}deleteShader(e){this.gl.deleteShader(e)}bindTextureToUniform(e,n,t){let o=this.gl;o.activeTexture(o.TEXTURE0+n),this.checkError(),o.bindTexture(o.TEXTURE_2D,e),this.checkError(),o.uniform1i(t,n),this.checkError()}draw(){this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),this.checkError()}checkError(){if(ce.debug){let e=this.gl,n=e.getError(),t="";switch(n){case e.NO_ERROR:return;case e.INVALID_ENUM:t="INVALID_ENUM";break;case e.INVALID_VALUE:t="INVALID_VALUE";break;case e.INVALID_OPERATION:t="INVALID_OPERATION";break;case e.INVALID_FRAMEBUFFER_OPERATION:t="INVALID_FRAMEBUFFER_OPERATION";break;case e.OUT_OF_MEMORY:t="OUT_OF_MEMORY";break;case e.CONTEXT_LOST_WEBGL:t="CONTEXT_LOST_WEBGL";break;default:t=`Unknown WebGL Error: ${n.toString(16)}`}throw new Error(t)}}deleteTexture(e){this.gl.deleteTexture(e)}deleteProgram(e){this.gl.deleteProgram(e)}getEncoder(e,n,t=0){if(this.version===2)return new Fi(this.gl,n);switch(e){case"float":return t===1||this.isRenderFloat32Supported?new Do(this.gl,n):new Do(this.gl,n,this.textureHalfFloatExtension.HALF_FLOAT_OES);case"int":throw new Error("not implemented");case"byte":return new Vi(this.gl,n);default:throw new Error(`Invalid dataType: ${e}`)}}clearActiveTextures(){let e=this.gl;for(let n=0;nthis.isTimerResultAvailable(e)),this.getTimerResult(e)}async createAndWaitForFence(){let e=this.createFence(this.gl);return this.pollFence(e)}createFence(e){let n,t=e,o=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),o===null?n=()=>!0:n=()=>{let i=t.clientWaitSync(o,0,0);return i===t.ALREADY_SIGNALED||i===t.CONDITION_SATISFIED},{query:o,isFencePassed:n}}async pollFence(e){return new Promise(n=>{this.addItemToPoll(()=>e.isFencePassed(),()=>n())})}pollItems(){let e=qP(this.itemsToPoll.map(n=>n.isDoneFn));for(let n=0;n<=e;++n){let{resolveFn:t}=this.itemsToPoll[n];t()}this.itemsToPoll=this.itemsToPoll.slice(e+1)}async addItemToPoll(e,n){this.itemsToPoll.push({isDoneFn:e,resolveFn:n}),!(this.itemsToPoll.length>1)&&await vl(()=>(this.pollItems(),this.itemsToPoll.length===0))}}});function Jl(r){let e;if((!r||r==="webgl2")&&"webgl2"in so?e=so.webgl2:(!r||r==="webgl")&&"webgl"in so&&(e=so.webgl),!e)try{let t=KP();e=Dy(t,r)}catch{let t=jP();e=Dy(t,r)}r=r||e.version===1?"webgl":"webgl2";let n=e.gl;return so[r]=e,n.isContextLost()?(delete so[r],Jl(r)):(n.disable(n.DEPTH_TEST),n.disable(n.STENCIL_TEST),n.disable(n.BLEND),n.disable(n.DITHER),n.disable(n.POLYGON_OFFSET_FILL),n.disable(n.SAMPLE_COVERAGE),n.enable(n.SCISSOR_TEST),n.enable(n.CULL_FACE),n.cullFace(n.BACK),e)}function Dy(r,e){let n={alpha:!1,depth:!1,antialias:!1,stencil:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1,failIfMajorPerformanceCaveat:!1},t,o=n;if((!e||e==="webgl2")&&(t=r.getContext("webgl2",o),t))try{return new Mo(t,2)}catch(i){Be.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl2'. Error: ${i}`)}if((!e||e==="webgl")&&(t=r.getContext("webgl",o)||r.getContext("experimental-webgl",o),t))try{return new Mo(t,1)}catch(i){Be.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${i}`)}throw new Error("WebGL is not supported")}function jP(){if(typeof document>"u")throw new TypeError("failed to create canvas: document is not supported");let r=document.createElement("canvas");return r.width=1,r.height=1,r}function KP(){if(typeof OffscreenCanvas>"u")throw new TypeError("failed to create offscreen canvas: OffscreenCanvas is not supported");return new OffscreenCanvas(1,1)}var so,ky=N(()=>{"use strict";Dt();Cy();so={}});var la,Ny=N(()=>{"use strict";ft();Dt();Ey();ky();la=class{get contextId(){return ce.webgl.contextId}set contextId(e){ce.webgl.contextId=e}get matmulMaxBatchSize(){return ce.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(e){ce.webgl.matmulMaxBatchSize=e}get textureCacheMode(){return ce.webgl.textureCacheMode}set textureCacheMode(e){ce.webgl.textureCacheMode=e}get pack(){return ce.webgl.pack}set pack(e){ce.webgl.pack=e}get async(){return ce.webgl.async}set async(e){ce.webgl.async=e}initialize(){try{return this.glContext=Jl(this.contextId),typeof this.matmulMaxBatchSize!="number"&&(this.matmulMaxBatchSize=16),typeof this.textureCacheMode!="string"&&(this.textureCacheMode="full"),typeof this.pack!="boolean"&&(this.pack=!1),typeof this.async!="boolean"&&(this.async=!1),Be.setWithEnv(ce),ce.webgl.context||Object.defineProperty(ce.webgl,"context",{value:this.glContext.gl}),Be.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(e){return Be.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${e}`),!1}}createSessionHandler(e){return new ua(this,e)}dispose(){this.glContext.dispose()}}});async function Yl(r){if(r){let e=typeof r=="string"?[r]:r;for(let n of e){let t=Ly.get(n);if(t)return t;let o=await ZP(n);if(o)return o}}else return Yl(["webgl"]);throw new Error("no available backend to use")}async function ZP(r){let e=XP;if(typeof e[r]<"u"&&JP(e[r])){let n=e[r],t=n.initialize();if(typeof t=="object"&&"then"in t&&(t=await t),t)return Ly.set(r,n),n}}function JP(r){let e=r;return"initialize"in e&&typeof e.initialize=="function"&&"createSessionHandler"in e&&typeof e.createSessionHandler=="function"&&"dispose"in e&&typeof e.dispose=="function"}var Ly,XP,Ry=N(()=>{"use strict";Ny();Ly=new Map,XP={webgl:new la}});var Ql,ca,zy=N(()=>{"use strict";Dt();Ql=class{constructor(e,n){this.op=e;this.node=n}},ca=class{constructor(e,n,t){this.graph=e;this.profiler=t;this.initialize(n)}initialize(e){this.profiler.event("session","ExecutionPlan.initialize",()=>{let n=this.graph.getNodes();if(n.length!==e.length)throw new Error("The size of nodes and OPs do not match.");this._ops=e.map((t,o)=>new Ql(t,n[o])),this.reset(),this._starter=[],this._ops.forEach((t,o)=>{let i=!0;for(let a of t.node.inputs)if(!this._values[a]&&this.graph.getInputIndices().indexOf(a)===-1){i=!1;break}i&&this._starter.push(o)})})}reset(){this._values=this.graph.getValues().map(e=>e.tensor)}async execute(e,n){return this.profiler.event("session","ExecutionPlan.execute",async()=>{this.reset();let t=e.createInferenceHandler(),o=this.graph.getInputIndices();if(n.length!==o.length)throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${n.length} expected: ${o.length}`);n.forEach((d,p)=>{let h=o[p];this._values[h]=d});let i=this._starter.slice(0),a=this.graph.getValues(),s=this.graph.getNodes(),u=0;for(;uthis._values[I]);if(h.indexOf(void 0)!==-1)throw new Error(`unresolved input detected: op: ${p.node}`);let g=h;Be.verbose("ExecPlan",`Running op:${p.node.name} (${g.map((I,w)=>`'${p.node.inputs[w]}': ${I.type}[${I.dims.join(",")}]`).join(", ")})`);let b=await this.profiler.event("node",p.node.name,async()=>p.op.impl(t,g,p.op.context));if(b.length!==p.node.outputs.length)throw new Error("the size of output does not match model definition.");b.forEach((I,w)=>{let v=p.node.outputs[w];if(this._values[v])throw new Error(`output [${v}] already has value: op:${p.node.name}`);this._values[v]=I});let _=new Set;b.forEach((I,w)=>{let v=p.node.outputs[w];for(let S of a[v].to){let A=s[S],P=!0;for(let C of A.inputs)if(!this._values[C]){P=!1;break}P&&_.add(S)}}),i.push(..._)}let l=[];for(let d=0;d{"use strict";$o();Se=ye(Qr());Rr();ze();Bo=class r{constructor(e){if(this._attributes=new Map,e!=null){for(let n of e)n instanceof Se.onnx.AttributeProto?this._attributes.set(n.name,[r.getValue(n),r.getType(n)]):n instanceof Di.Attribute&&this._attributes.set(n.name(),[r.getValue(n),r.getType(n)]);if(this._attributes.sizeot.fromProto(i));if(e instanceof Di.Attribute)return t.map(i=>ot.fromOrtTensor(i))}return n===Se.onnx.AttributeProto.AttributeType.STRING&&e instanceof Se.onnx.AttributeProto?Co(t):n===Se.onnx.AttributeProto.AttributeType.STRINGS&&e instanceof Se.onnx.AttributeProto?t.map(Co):t}static getValueNoCheck(e){return e instanceof Se.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(e):this.getValueNoCheckFromOrtFormat(e)}static getValueNoCheckFromOnnxFormat(e){switch(e.type){case Se.onnx.AttributeProto.AttributeType.FLOAT:return e.f;case Se.onnx.AttributeProto.AttributeType.INT:return e.i;case Se.onnx.AttributeProto.AttributeType.STRING:return e.s;case Se.onnx.AttributeProto.AttributeType.TENSOR:return e.t;case Se.onnx.AttributeProto.AttributeType.GRAPH:return e.g;case Se.onnx.AttributeProto.AttributeType.FLOATS:return e.floats;case Se.onnx.AttributeProto.AttributeType.INTS:return e.ints;case Se.onnx.AttributeProto.AttributeType.STRINGS:return e.strings;case Se.onnx.AttributeProto.AttributeType.TENSORS:return e.tensors;case Se.onnx.AttributeProto.AttributeType.GRAPHS:return e.graphs;default:throw new Error(`unsupported attribute type: ${Se.onnx.AttributeProto.AttributeType[e.type]}`)}}static getValueNoCheckFromOrtFormat(e){switch(e.type()){case Rt.AttributeType.FLOAT:return e.f();case Rt.AttributeType.INT:return e.i();case Rt.AttributeType.STRING:return e.s();case Rt.AttributeType.TENSOR:return e.t();case Rt.AttributeType.GRAPH:return e.g();case Rt.AttributeType.FLOATS:return e.floatsArray();case Rt.AttributeType.INTS:{let n=[];for(let t=0;t{"use strict";My();$o();tc=ye(Qr());Rr();ze();nc={from:(r,e)=>new ec(r,e)},Fn=class{constructor(e){this._from=void 0,this._to=[],this.tensor=void 0,this.type=void 0,e&&(this.type=ht.tensorValueTypeFromProto(e.type.tensorType))}get from(){return this._from}get to(){return this._to}},da=class{constructor(e,n){e instanceof tc.onnx.NodeProto?(this.name=e.name,this.opType=e.opType,this.attributes=new Bo(e.attribute)):e instanceof rl.Node&&(this.name=n??e.name(),this.opType=e.opType(),this.attributes=new Bo(ht.tensorAttributesFromORTFormat(e))),this.inputs=[],this.outputs=[],this.executeNode=!0}},ec=class{constructor(e,n){if(!e)throw new TypeError("graph is empty");this.buildGraph(e),this.transformGraph(n),this.checkIsAcyclic()}getInputIndices(){return this._allInputIndices}getInputNames(){return this._allInputNames}getOutputIndices(){return this._allOutputIndices}getOutputNames(){return this._allOutputNames}getValues(){return this._allData}getNodes(){return this._nodes}buildGraph(e){if(e instanceof tc.onnx.GraphProto)this.buildGraphFromOnnxFormat(e);else if(e instanceof tl.Graph)this.buildGraphFromOrtFormat(e);else throw new TypeError("Graph type is not supported.")}buildGraphFromOnnxFormat(e){let n=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map;if(!e.input)throw new Error("missing information in graph: input");let o=[];for(let i of e.input){if(n.has(i.name))throw new Error(`duplicated input name: ${i.name}`);let a=this._allData.push(new Fn(i))-1;n.set(i.name,a),o.push(i.name)}if(!e.initializer)throw new Error("missing information in graph: initializer");for(let i of e.initializer){let a=n.get(i.name);if(a===void 0){let s=new Fn;s.type={shape:{dims:ht.tensorDimsFromProto(i.dims)},tensorType:ht.tensorDataTypeFromProto(i.dataType)},a=this._allData.push(s)-1,n.set(i.name,a)}this._allData[a]._from=-1,this._allData[a].tensor=ot.fromProto(i)}for(let i=0;i"u"&&(l=this._allData.push(new Fn)-1,n.set(u,l)),a.outputs.push(l),this._allData[l]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${l}`);if(this._allData[l]._from=i,s.opType==="Constant"){if(!s.attribute||s.attribute.length!==1||!s.attribute[0].t)throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(!s.output||s.output.length!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");a.outputs.pop(),a.executeNode=!1,this._allData[l]._from=-1,this._allData[l].tensor=ot.fromProto(s.attribute[0].t)}}}for(let i=0;i"u"){if(u===""&&(s.input.length===3||s.input.length===4)&&s.opType==="Resize")continue;throw new Error(`unrecognized input '${u}' for node: ${s.name}`)}a.inputs.push(l),this._allData[l]._to.push(i)}}return!0}buildGraphFromOrtFormat(e){let n=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map,o=[];for(let i=0;i"u"&&(d=this._allData.push(new Fn)-1,n.set(l,d)),a.outputs.push(d),this._allData[d]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${d}`);if(this._allData[d]._from=i,s.opType()==="Constant"){if(s.attributesLength()!==1||!s.attributes(0).t())throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(s.outputsLength()!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");a.outputs.pop(),a.executeNode=!1,this._allData[d]._from=-1,this._allData[d].tensor=ot.fromOrtTensor(s.attributes(0).t())}}}for(let i=0;i"u")throw new Error(`unrecognized input '${l}' for node: ${s.name()}`);a.inputs.push(d),this._allData[d]._to.push(i)}}}checkIsAcyclic(){let e=new Set;this._allInputIndices.forEach(o=>{this._allData[o]._to.forEach(a=>{e.add(a)})});let n=Array.from(e),t=new Array(this._nodes.length).fill("white");for(;n.length>0;){let o=n.pop();t[o]==="gray"?t[o]="black":(n.push(o),t[o]="gray",this._nodes[o].outputs.forEach(i=>{let a=this._allData[i];if(typeof a.tensor<"u")throw new Error("node outputs should not be initialized");if(a._from!==o)throw new Error("from property of the Value object doesn't match index of Node being processed");a._to.forEach(s=>{if(t[s]==="gray")throw new Error("model graph is cyclic");t[s]==="white"&&n.push(s)})}))}}transformGraph(e){this.removeAllIdentityNodes(),this.removeAllDropoutNodes(),this.fuseConvActivationNodes(),e&&e.transformGraph(this),this.finalizeGraph()}finalizeGraph(){let e=0,n=new Array(this._nodes.length,0),t=0;for(let o=0;o{this._allData[i]._from=-2});this._nodes.splice(t,this._nodes.length-t);for(let o=0;o=0)i._to[a]=n[i._to[a]];else throw new Error("Trying to update a removed node")}e=0;for(let o=0;o0){let i=-1;this._allData[o].from!==void 0&&this._allData[o].from!==-1?(i=this._nodes[this._allData[o].from].outputs.indexOf(o+e),i!==-1&&(this._nodes[this._allData[o].from].outputs[i]=o)):(i=this._allInputIndices.indexOf(o+e),i!==-1&&(this._allInputIndices[i]=o)),this._allData[o].to.forEach(a=>{i=this._nodes[a].inputs.indexOf(o+e),i!==-1&&(this._nodes[a].inputs[i]=o)}),this._allData[o].to.length===0&&(i=this._allOutputIndices.indexOf(o+e),i!==-1&&(this._allOutputIndices[i]=o))}}}deleteNode(e){let n=this._nodes[e];if(n.outputs.length>1){for(let s=1;s0)throw new Error("Node deletion with more than one output connected to other nodes is not supported. ")}n.executeNode=!1;let t=n.inputs[0],o=n.outputs[0],i=this._allData[o].to;for(let s=0;s0)for(let s of i){let u=this._nodes[s].inputs.indexOf(o);if(u===-1)throw new Error("The Node object doesn't have the output Value in it's 'inputs' property ");this._nodes[s].inputs[u]=t,this._allData[t].to.push(s)}}removeAllDropoutNodes(){let e=0;for(let n of this._nodes){if(n.opType==="Dropout"){if(n.inputs.length!==1)throw new Error("Dropout nodes should only contain one input. ");if(n.outputs.length!==1&&n.outputs.length!==2)throw new Error("Dropout nodes should contain either 1 or 2 output(s)");if(n.outputs.length===2&&this._allData[n.outputs[1]]._to.length!==0)throw new Error("Dropout nodes's second output should not be referenced by other nodes");this.deleteNode(e)}e++}}removeAllIdentityNodes(){let e=0;for(let n of this._nodes)n.opType==="Identity"&&this.deleteNode(e),e++}isActivation(e){switch(e.opType){case"Relu":case"Sigmoid":case"Clip":return!0;default:return!1}}fuseConvActivationNodes(){for(let e of this._nodes)if(e.opType==="Conv"){let n=this._allData[e.outputs[0]]._to;if(n.length===1&&this.isActivation(this._nodes[n[0]])){let t=this._nodes[n[0]];if(t.opType==="Clip")if(t.inputs.length===1)try{e.attributes.set("activation_params","floats",[t.attributes.getFloat("min"),t.attributes.getFloat("max")])}catch{e.attributes.set("activation_params","floats",[Nr,Lr])}else if(t.inputs.length>=3&&this._allData[t.inputs[1]].tensor!==void 0&&this._allData[t.inputs[2]].tensor!==void 0)e.attributes.set("activation_params","floats",[this._allData[t.inputs[1]].tensor.floatData[0],this._allData[t.inputs[2]].tensor.floatData[0]]);else continue;e.attributes.set("activation","string",t.opType),this.deleteNode(n[0])}}}}});var Fy,Vy,pa,Gy=N(()=>{"use strict";Fy=ye(Re());By();$o();Vy=ye(Qr());ze();pa=class{constructor(){}load(e,n,t){let o;if(!t)try{this.loadFromOnnxFormat(e,n);return}catch(i){if(t!==void 0)throw i;o=i}try{this.loadFromOrtFormat(e,n)}catch(i){throw t!==void 0?i:new Error(`Failed to load model as ONNX format: ${o} as ORT format: ${i}`)}}loadFromOnnxFormat(e,n){let t=Vy.onnx.ModelProto.decode(e);if(Tt.longToNumber(t.irVersion)<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=t.opsetImport.map(i=>({domain:i.domain,version:Tt.longToNumber(i.version)})),this._graph=nc.from(t.graph,n)}loadFromOrtFormat(e,n){let t=new Fy.ByteBuffer(e),o=nl.InferenceSession.getRootAsInferenceSession(t).model();if(Tt.longToNumber(o.irVersion())<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=[];for(let a=0;a{"use strict";Ry();zy();Dt();Gy();fa=class{constructor(e={}){this._initialized=!1,this.backendHint=e.backendHint,this.profiler=yi.create(e.profiler),this.context={profiler:this.profiler,graphInputTypes:[],graphInputDims:[]}}get inputNames(){return this._model.graph.getInputNames()}get outputNames(){return this._model.graph.getOutputNames()}startProfiling(){this.profiler.start()}endProfiling(){this.profiler.stop()}async loadModel(e,n,t){await this.profiler.event("session","Session.loadModel",async()=>{let o=await Yl(this.backendHint);if(this.sessionHandler=o.createSessionHandler(this.context),this._model=new pa,typeof e=="string"){let i=e.endsWith(".ort");{let s=await(await fetch(e)).arrayBuffer();this.initialize(new Uint8Array(s),i)}}else if(ArrayBuffer.isView(e))this.initialize(e);else{let i=new Uint8Array(e,n||0,t||e.byteLength);this.initialize(i)}})}initialize(e,n){if(this._initialized)throw new Error("already initialized");this.profiler.event("session","Session.initialize",()=>{let t=this.sessionHandler.transformGraph?this.sessionHandler:void 0;this._model.load(e,t,n),this.sessionHandler.onGraphInitialized&&this.sessionHandler.onGraphInitialized(this._model.graph),this.initializeOps(this._model.graph),this._executionPlan=new ca(this._model.graph,this._ops,this.profiler)}),this._initialized=!0}async run(e){if(!this._initialized)throw new Error("session not initialized yet");return this.profiler.event("session","Session.run",async()=>{let n=this.normalizeAndValidateInputs(e),t=await this._executionPlan.execute(this.sessionHandler,n);return this.createOutput(t)})}normalizeAndValidateInputs(e){let n=this._model.graph.getInputNames();if(Array.isArray(e)){if(e.length!==n.length)throw new Error(`incorrect input array length: expected ${n.length} but got ${e.length}`)}else{if(e.size!==n.length)throw new Error(`incorrect input map size: expected ${n.length} but got ${e.size}`);let t=new Array(e.size),o=0;for(let i=0;i{"use strict";ft();Rr();ha=class{constructor(e){this.session=e;this.inputNames=this.session.inputNames,this.outputNames=this.session.outputNames}get inputMetadata(){throw new Error("Getting model metadata is not supported in webgl backend.")}get outputMetadata(){throw new Error("Getting model metadata is not supported in webgl backend.")}async dispose(){}async run(e,n,t){let o=new Map;for(let s in e)if(Object.hasOwnProperty.call(e,s)){let u=e[s];o.set(s,new ot(u.dims,u.type,void 0,void 0,u.data))}let i=await this.session.run(o),a={};return i.forEach((s,u)=>{a[u]=new $t(s.type,s.data,s.dims)}),a}startProfiling(){this.session.startProfiling()}endProfiling(){this.session.endProfiling()}}});var Hy={};Sr(Hy,{onnxjsBackend:()=>YP});var rc,YP,qy=N(()=>{"use strict";Uy();Wy();rc=class{async init(){}async createInferenceSessionHandler(e,n){let t=new fa(n);return typeof e=="string"?await t.loadModel(e):await t.loadModel(e),new ha(t)}},YP=new rc});var ma=N(()=>{"use strict"});var Xy={};Sr(Xy,{default:()=>QP});var jy,Ky,QP,Zy=N(()=>{"use strict";oc();br();ga();jy="ort-wasm-proxy-worker",Ky=globalThis.self?.name===jy;Ky&&(self.onmessage=r=>{let{type:e,in:n}=r.data;try{switch(e){case"init-wasm":ba(n.wasm).then(()=>{ya(n).then(()=>{postMessage({type:e})},t=>{postMessage({type:e,err:t})})},t=>{postMessage({type:e,err:t})});break;case"init-ep":{let{epName:t,env:o}=n;_a(o,t).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:t}=n,o=Fo(t);postMessage({type:e,out:o});break}case"create":{let{model:t,options:o}=n;wa(t,o).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":va(n),postMessage({type:e});break;case"run":{let{sessionId:t,inputIndices:o,inputs:i,outputIndices:a,options:s}=n;xa(t,o,i,a,new Array(a.length).fill(null),s).then(u=>{u.some(l=>l[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:u},Ia([...i,...u]))},u=>{postMessage({type:e,err:u})});break}case"end-profiling":Ta(n),postMessage({type:e});break;default:}}catch(t){postMessage({type:e,err:t})}});QP=Ky?null:r=>new Worker(r??Pt,{type:"module",name:jy})});var Yy={};Sr(Yy,{default:()=>e3});async function Jy(r={}){var e=r,n=!!globalThis.window,t=!!globalThis.WorkerGlobalScope,o=t&&self.name?.startsWith("em-pthread");e.mountExternalData=(c,f)=>{c.startsWith("./")&&(c=c.substring(2)),(e.Xc||(e.Xc=new Map)).set(c,f)},e.unmountExternalData=()=>{delete e.Xc},globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor;let i=c=>async(...f)=>{try{if(e.Yc)throw Error("Session already started");let y=e.Yc={Kd:f[0],errors:[]},m=await c(...f);if(e.Yc!==y)throw Error("Session mismatch");e.dd?.flush();let T=y.errors;if(0k),0{if(c==="webgpu"){[e.dd,e.Ad,e.Ed,e.ed,e.Dd,e.$b,e.Fd,e.Hd,e.Bd,e.Cd,e.Gd]=f;let y=e.dd;e.jsepRegisterBuffer=(m,T,O,k)=>y.registerBuffer(m,T,O,k),e.jsepGetBuffer=m=>y.getBuffer(m),e.jsepCreateDownloader=(m,T,O)=>y.createDownloader(m,T,O),e.jsepOnCreateSession=m=>{y.onCreateSession(m)},e.jsepOnReleaseSession=m=>{y.onReleaseSession(m)},e.jsepOnRunStart=m=>y.onRunStart(m),e.Id=(m,T)=>{y.upload(m,T)}}else if(c==="webnn"){let y=f[0];[e.Wd,e.sd,e.webnnEnsureTensor,e.td,e.webnnDownloadTensor,e.Rd,e.webnnEnableTraceEvent]=f.slice(1),e.webnnReleaseTensorId=e.sd,e.webnnUploadTensor=e.td,e.webnnRegisterMLContext=e.Rd,e.webnnOnRunStart=m=>y.onRunStart(m),e.webnnOnRunEnd=y.onRunEnd.bind(y),e.webnnOnReleaseSession=m=>{y.onReleaseSession(m)},e.webnnCreateMLTensorDownloader=(m,T)=>y.createMLTensorDownloader(m,T),e.webnnRegisterMLTensor=(m,T,O,k)=>y.registerMLTensor(m,T,O,k),e.webnnCreateMLContext=m=>y.createMLContext(m),e.webnnRegisterMLConstant=(m,T,O,k,M,j)=>y.registerMLConstant(m,T,O,k,M,e.Xc,j),e.webnnRegisterGraphInput=y.registerGraphInput.bind(y),e.webnnIsGraphInput=y.isGraphInput.bind(y),e.webnnRegisterGraphOutput=y.registerGraphOutput.bind(y),e.webnnIsGraphOutput=y.isGraphOutput.bind(y),e.webnnCreateTemporaryTensor=y.createTemporaryTensor.bind(y),e.webnnIsGraphInputOutputTypeSupported=y.isGraphInputOutputTypeSupported.bind(y)}};let a=()=>{let c=f=>(...y)=>{let m=tn;return y=f(...y),tn!=m?new Promise((T,O)=>{gs={resolve:T,reject:O}}):y};(()=>{for(let f of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])e[f]=c(e[f])})(),i!==void 0&&(e._OrtRun=i(e._OrtRun),e._OrtRunWithBinding=i(e._OrtRunWithBinding)),a=void 0};e.asyncInit=()=>{a?.()};var s,u,l=(c,f)=>{throw f},d=import.meta.url,p="";if(n||t){try{p=new URL(".",d).href}catch{}t&&(u=c=>{var f=new XMLHttpRequest;return f.open("GET",c,!1),f.responseType="arraybuffer",f.send(null),new Uint8Array(f.response)}),s=async c=>{if(R(c))return new Promise((y,m)=>{var T=new XMLHttpRequest;T.open("GET",c,!0),T.responseType="arraybuffer",T.onload=()=>{T.status==200||T.status==0&&T.response?y(T.response):m(T.status)},T.onerror=m,T.send(null)});var f=await fetch(c,{credentials:"same-origin"});if(f.ok)return f.arrayBuffer();throw Error(f.status+" : "+f.url)}}var h,g,b,_,I,w,v=console.log.bind(console),S=console.error.bind(console),A=v,P=S,C=!1,R=c=>c.startsWith("file://");function x(){nr.buffer!=G.buffer&&mt()}if(o){let c=function(f){try{var y=f.data,m=y.Sc;if(m==="load"){let T=[];self.onmessage=O=>T.push(O),w=()=>{postMessage({Sc:"loaded"});for(let O of T)c(O);self.onmessage=c};for(let O of y.xd)e[O]&&!e[O].proxy||(e[O]=(...k)=>{postMessage({Sc:"callHandler",wd:O,args:k})},O=="print"&&(A=e[O]),O=="printErr"&&(P=e[O]));nr=y.Od,mt(),g=y.Pd,Ne(),ui()}else if(m==="run"){(function(T){var O=(x(),U)[T+52>>>2>>>0];T=(x(),U)[T+56>>>2>>>0],Xd(O,O-T),we(O)})(y.Rc),vs(y.Rc,0,0,1,0,0),Zc(),fs(y.Rc),B||(Ud(),B=!0);try{Ux(y.Md,y.bd)}catch(T){if(T!="unwind")throw T}}else y.target!=="setimmediate"&&(m==="checkMailbox"?B&&ti():m&&(P(`worker: received unknown command ${m}`),P(y)))}catch(T){throw Wd(),T}};var OD=c,B=!1;self.onunhandledrejection=f=>{throw f.reason||f},self.onmessage=c}var G,Z,J,ie,z,U,te,oe,ee,de,ge,Te=!1;function mt(){var c=nr.buffer;e.HEAP8=G=new Int8Array(c),J=new Int16Array(c),e.HEAPU8=Z=new Uint8Array(c),ie=new Uint16Array(c),e.HEAP32=z=new Int32Array(c),e.HEAPU32=U=new Uint32Array(c),te=new Float32Array(c),oe=new Float64Array(c),ee=new BigInt64Array(c),de=new BigUint64Array(c)}function Ve(){Te=!0,o?w():Zn.sb()}function F(c){throw P(c="Aborted("+c+")"),C=!0,c=new WebAssembly.RuntimeError(c+". Build with -sASSERTIONS for more info."),I?.(c),c}function q(){return{a:{ma:h2,gb:f2,g:Wx,J:Hx,f:qx,o:jx,h:Kx,ha:Xx,b:Zx,T:Jx,Ha:nd,n:Yx,$:ad,Xa:sd,Da:ud,Fa:ld,Ya:cd,Va:dd,Oa:pd,Ua:fd,ka:hd,Ea:md,Ba:gd,Wa:bd,Ca:yd,bb:Qx,ea:tT,wa:nT,ua:oT,da:aT,O:sT,H:uT,va:lT,_:gT,xa:bT,Ra:yT,za:wT,Ia:vT,sa:xT,fa:TT,Qa:fs,_a:IT,R:OT,r:kT,c:ds,hb:NT,y:LT,M:RT,D:zT,l:MT,s:$d,ib:BT,I:FT,S:VT,j:GT,u:UT,q:WT,k:HT,La:qT,Ma:jT,Na:KT,Ja:Ed,Ka:Cd,ta:Dd,db:ZT,ab:QT,v:e2,aa:t2,ga:n2,$a:JT,W:r2,Za:o2,Aa:i2,F:XT,U:a2,la:ai,ya:u2,fb:s2,eb:l2,Sa:Rd,Ta:zd,Ga:as,V:Md,ja:Bd,Pa:Fd,ia:Vd,kb:Z2,na:H2,lb:X2,oa:W2,G:L2,d:y2,t:g2,w:m2,A:O2,mb:V2,K:D2,x:v2,pa:G2,Y:q2,ba:F2,nb:B2,ob:M2,P:P2,qa:z2,pb:R2,N:k2,Z:U2,e:b2,B:w2,m:_2,jb:J2,p:T2,z:I2,C:x2,E:S2,L:E2,qb:N2,Q:j2,ca:C2,X:K2,rb:A2,ra:$2,i:d2,a:nr,cb:Zo}}}async function Ne(){function c(m,T){var O=Zn=m.exports;m={};for(let[k,M]of Object.entries(O))typeof M=="function"?(O=ST(M),m[k]=O):m[k]=M;return Zn=m,Zn=function(){var k=Zn,M=Y=>be=>Y(be)>>>0,j=Y=>()=>Y()>>>0;return(k=Object.assign({},k)).tb=M(k.tb),k.Xb=j(k.Xb),k.Zb=M(k.Zb),k.lc=M(k.lc),k.mc=j(k.mc),k.qc=M(k.qc),k}(),Kc.push(Zn._b),Gd=(m=Zn).tb,Ud=m.ub,e._OrtInit=m.vb,e._OrtGetLastError=m.wb,e._OrtCreateSessionOptions=m.xb,e._OrtAppendExecutionProvider=m.yb,e._OrtAddFreeDimensionOverride=m.zb,e._OrtAddSessionConfigEntry=m.Ab,e._OrtReleaseSessionOptions=m.Bb,e._OrtCreateSession=m.Cb,e._OrtReleaseSession=m.Db,e._OrtGetInputOutputCount=m.Eb,e._OrtGetInputOutputMetadata=m.Fb,e._OrtFree=m.Gb,e._OrtCreateTensor=m.Hb,e._OrtGetTensorData=m.Ib,e._OrtReleaseTensor=m.Jb,e._OrtCreateRunOptions=m.Kb,e._OrtAddRunConfigEntry=m.Lb,e._OrtReleaseRunOptions=m.Mb,e._OrtCreateBinding=m.Nb,e._OrtBindInput=m.Ob,e._OrtBindOutput=m.Pb,e._OrtClearBoundOutputs=m.Qb,e._OrtReleaseBinding=m.Rb,e._OrtRunWithBinding=m.Sb,e._OrtRun=m.Tb,e._OrtEndProfiling=m.Ub,e._JsepOutput=m.Vb,e._JsepGetNodeName=m.Wb,si=m.Xb,nn=e._free=m.Yb,yo=e._malloc=m.Zb,vs=m.ac,Wd=m.bc,Hd=m.cc,qd=m.dc,xs=m.ec,jd=m.fc,Kd=m.gc,Ie=m.hc,_o=m.ic,Xd=m.jc,we=m.kc,Ts=m.lc,ve=m.mc,Zd=m.nc,Is=m.oc,Jd=m.pc,Yd=m.qc,Qd=m.rc,Ss=m.sc,ep=m.tc,tp=m.uc,np=m.vc,rp=m.wc,op=m.xc,ip=m.yc,ap=m.zc,sp=m.Ac,up=m.Bc,lp=m.Cc,cp=m.Dc,dp=m.Ec,pp=m.Fc,fp=m.Gc,hp=m.Hc,mp=m.Ic,gp=m.Jc,bp=m.Kc,yp=m.Lc,_p=m.Mc,wp=m.Nc,vp=m.Pc,xp=m.Qc,Tp=m.$c,Ip=m.ad,Sp=m.fd,$p=m.jd,Ap=m.kd,Op=m.ld,Pp=m.md,Ep=m.nd,Cp=m.od,Dp=m.pd,kp=m.qd,Np=m.vd,Lp=m.Sd,Rp=m.Td,zp=m.Ud,Mp=m.Vd,g=T,Zn}var f,y=q();return e.instantiateWasm?new Promise(m=>{e.instantiateWasm(y,(T,O)=>{m(c(T,O))})}):o?c(new WebAssembly.Instance(g,q()),g):(ge??=e.locateFile?e.locateFile?e.locateFile("ort-wasm-simd-threaded.jsep.wasm",p):p+"ort-wasm-simd-threaded.jsep.wasm":new URL("ort-wasm-simd-threaded.jsep.wasm",import.meta.url).href,f=await async function(m){var T=ge;if(!h&&!R(T))try{var O=fetch(T,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(O,m)}catch(k){P(`wasm streaming compile failed: ${k}`),P("falling back to ArrayBuffer instantiation")}return async function(k,M){try{var j=await async function(Y){if(!h)try{var be=await s(Y);return new Uint8Array(be)}catch{}if(Y==ge&&h)Y=new Uint8Array(h);else{if(!u)throw"both async and sync fetching of the wasm failed";Y=u(Y)}return Y}(k);return await WebAssembly.instantiate(j,M)}catch(Y){P(`failed to asynchronously prepare wasm: ${Y}`),F(Y)}}(T,m)}(y),c(f.instance,f.module))}class rt{name="ExitStatus";constructor(f){this.message=`Program terminated with exit(${f})`,this.status=f}}var Ge=c=>{c.terminate(),c.onmessage=()=>{}},at=[],Ee=0,He=null,Gt=c=>{tr.length==0&&(Yc(),Jc(tr[0]));var f=tr.pop();if(!f)return 6;go.push(f),xr[c.Rc]=f,f.Rc=c.Rc;var y={Sc:"run",Md:c.Ld,bd:c.bd,Rc:c.Rc};return f.postMessage(y,c.rd),0},St=0,We=(c,f,...y)=>{var m,T=16*y.length,O=ve(),k=Ts(T),M=k>>>3;for(m of y)typeof m=="bigint"?((x(),ee)[M++>>>0]=1n,(x(),ee)[M++>>>0]=m):((x(),ee)[M++>>>0]=0n,(x(),oe)[M++>>>0]=m);return c=Hd(c,0,T,k,f),we(O),c};function Zo(c){if(o)return We(0,1,c);if(b=c,!(0{if(b=c,o)throw jc(c),"unwind";Zo(c)},tr=[],go=[],Kc=[],xr={},Xc=c=>{var f=c.Rc;delete xr[f],tr.push(c),go.splice(go.indexOf(c),1),c.Rc=0,qd(f)};function Zc(){Kc.forEach(c=>c())}var Jc=c=>new Promise(f=>{c.onmessage=T=>{var O=T.data;if(T=O.Sc,O.Zc&&O.Zc!=si()){var k=xr[O.Zc];k?k.postMessage(O,O.rd):P(`Internal error! Worker sent a message "${T}" to target pthread ${O.Zc}, but that thread no longer exists!`)}else T==="checkMailbox"?ti():T==="spawnThread"?Gt(O):T==="cleanupThread"?ei(()=>{Xc(xr[O.Nd])}):T==="loaded"?(c.loaded=!0,f(c)):O.target==="setimmediate"?c.postMessage(O):T==="uncaughtException"?c.onerror(O.error):T==="callHandler"?e[O.wd](...O.args):T&&P(`worker sent an unknown command ${T}`)},c.onerror=T=>{throw P(`worker sent an error! ${T.filename}:${T.lineno}: ${T.message}`),T};var y,m=[];for(y of[])e.propertyIsEnumerable(y)&&m.push(y);c.postMessage({Sc:"load",xd:m,Od:nr,Pd:g})});function Yc(){var c=new Worker((()=>{let f=URL;return import.meta.url>"file:"&&import.meta.url<"file;"?new f("ort.all.bundle.min.mjs",import.meta.url):new URL(import.meta.url)})(),{type:"module",workerData:"em-pthread",name:"em-pthread"});tr.push(c)}var nr,Ux=(c,f)=>{St=0,c=Ss(c,f),0>>=0);return(x(),G)[f.Tc+12>>>0]==0&&(Qc(f,!0),Yo--),ed(f,!1),Jo.push(f),Yd(c)}var jr=0,Hx=()=>{Ie(0,0);var c=Jo.pop();Zd(c.cd),jr=0};function Qc(c,f){f=f?1:0,(x(),G)[c.Tc+12>>>0]=f}function ed(c,f){f=f?1:0,(x(),G)[c.Tc+13>>>0]=f}class ss{constructor(f){this.cd=f,this.Tc=f-24}}var us=c=>{var f=jr;if(!f)return _o(0),0;var y=new ss(f);(x(),U)[y.Tc+16>>>2>>>0]=f;var m=(x(),U)[y.Tc+4>>>2>>>0];if(!m)return _o(0),f;for(var T of c){if(T===0||T===m)break;if(Jd(T,m,y.Tc+16))return _o(T),f}return _o(m),f};function qx(){return us([])}function jx(c){return us([c>>>0])}function Kx(c,f,y,m){return us([c>>>0,f>>>0,y>>>0,m>>>0])}var Xx=()=>{var c=Jo.pop();c||F("no exception to throw");var f=c.cd;throw(x(),G)[c.Tc+13>>>0]==0&&(Jo.push(c),ed(c,!0),Qc(c,!1),Yo++),Is(f),jr=f};function Zx(c,f,y){var m=new ss(c>>>=0);throw f>>>=0,y>>>=0,(x(),U)[m.Tc+16>>>2>>>0]=0,(x(),U)[m.Tc+4>>>2>>>0]=f,(x(),U)[m.Tc+8>>>2>>>0]=y,Is(c),Yo++,jr=c}var Jx=()=>Yo;function td(c,f,y,m){return o?We(2,1,c,f,y,m):nd(c,f,y,m)}function nd(c,f,y,m){if(c>>>=0,f>>>=0,y>>>=0,m>>>=0,!globalThis.SharedArrayBuffer)return 6;var T=[];return o&&T.length===0?td(c,f,y,m):(c={Ld:y,Rc:c,bd:m,rd:T},o?(c.Sc="spawnThread",postMessage(c,T),0):Gt(c))}function Yx(c){throw jr||=c>>>0,jr}var rd=globalThis.TextDecoder&&new TextDecoder,od=(c,f,y,m)=>{if(y=f+y,m)return y;for(;c[f]&&!(f>=y);)++f;return f},id=(c,f=0,y,m)=>{if(16<(y=od(c,f>>>=0,y,m))-f&&c.buffer&&rd)return rd.decode(c.buffer instanceof ArrayBuffer?c.subarray(f,y):c.slice(f,y));for(m="";f(T=(240&T)==224?(15&T)<<12|O<<6|k:(7&T)<<18|O<<12|k<<6|63&c[f++])?m+=String.fromCharCode(T):(T-=65536,m+=String.fromCharCode(55296|T>>10,56320|1023&T))}}else m+=String.fromCharCode(T)}return m},Qe=(c,f,y)=>(c>>>=0)?id((x(),Z),c,f,y):"";function ad(c,f,y){return o?We(3,1,c,f,y):0}function sd(c,f){if(o)return We(4,1,c,f)}function ud(c,f){if(o)return We(5,1,c,f)}function ld(c,f,y){if(o)return We(6,1,c,f,y)}function cd(c,f,y){return o?We(7,1,c,f,y):0}function dd(c,f){if(o)return We(8,1,c,f)}function pd(c,f,y){if(o)return We(9,1,c,f,y)}function fd(c,f,y,m){if(o)return We(10,1,c,f,y,m)}function hd(c,f,y,m){if(o)return We(11,1,c,f,y,m)}function md(c,f,y,m){if(o)return We(12,1,c,f,y,m)}function gd(c){if(o)return We(13,1,c)}function bd(c,f){if(o)return We(14,1,c,f)}function yd(c,f,y){if(o)return We(15,1,c,f,y)}var Qx=()=>F(""),en=c=>{c>>>=0;for(var f="";;){var y=(x(),Z)[c++>>>0];if(!y)return f;f+=String.fromCharCode(y)}},ls={},cs={},eT={},Kr=class extends Error{constructor(c){super(c),this.name="BindingError"}};function Xn(c,f,y={}){return function(m,T,O={}){var k=T.name;if(!m)throw new Kr(`type "${k}" must have a positive integer typeid pointer`);if(cs.hasOwnProperty(m)){if(O.yd)return;throw new Kr(`Cannot register type '${k}' twice`)}cs[m]=T,delete eT[m],ls.hasOwnProperty(m)&&(T=ls[m],delete ls[m],T.forEach(M=>M()))}(c,f,y)}var _d=(c,f,y)=>{switch(f){case 1:return y?m=>(x(),G)[m>>>0]:m=>(x(),Z)[m>>>0];case 2:return y?m=>(x(),J)[m>>>1>>>0]:m=>(x(),ie)[m>>>1>>>0];case 4:return y?m=>(x(),z)[m>>>2>>>0]:m=>(x(),U)[m>>>2>>>0];case 8:return y?m=>(x(),ee)[m>>>3>>>0]:m=>(x(),de)[m>>>3>>>0];default:throw new TypeError(`invalid integer width (${f}): ${c}`)}};function tT(c,f,y,m,T){c>>>=0,y>>>=0,f=en(f>>>0);let O=k=>k;if(m=m===0n){let k=8*y;O=M=>BigInt.asUintN(k,M),T=O(T)}Xn(c,{name:f,Oc:O,Vc:(k,M)=>(typeof M=="number"&&(M=BigInt(M)),M),Uc:_d(f,y,!m),Wc:null})}function nT(c,f,y,m){Xn(c>>>=0,{name:f=en(f>>>0),Oc:function(T){return!!T},Vc:function(T,O){return O?y:m},Uc:function(T){return this.Oc((x(),Z)[T>>>0])},Wc:null})}var wd=[],Tr=[0,1,,1,null,1,!0,1,!1,1];function ds(c){9<(c>>>=0)&&--Tr[c+1]==0&&(Tr[c]=void 0,wd.push(c))}var Ct=c=>{if(!c)throw new Kr(`Cannot use deleted val. handle = ${c}`);return Tr[c]},Ut=c=>{switch(c){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let f=wd.pop()||Tr.length;return Tr[f]=c,Tr[f+1]=1,f}};function ps(c){return this.Oc((x(),U)[c>>>2>>>0])}var rT={name:"emscripten::val",Oc:c=>{var f=Ct(c);return ds(c),f},Vc:(c,f)=>Ut(f),Uc:ps,Wc:null};function oT(c){return Xn(c>>>0,rT)}var iT=(c,f)=>{switch(f){case 4:return function(y){return this.Oc((x(),te)[y>>>2>>>0])};case 8:return function(y){return this.Oc((x(),oe)[y>>>3>>>0])};default:throw new TypeError(`invalid float width (${f}): ${c}`)}};function aT(c,f,y){y>>>=0,Xn(c>>>=0,{name:f=en(f>>>0),Oc:m=>m,Vc:(m,T)=>T,Uc:iT(f,y),Wc:null})}function sT(c,f,y,m,T){c>>>=0,y>>>=0,f=en(f>>>0);let O=M=>M;if(m===0){var k=32-8*y;O=M=>M<>>k,T=O(T)}Xn(c,{name:f,Oc:O,Vc:(M,j)=>j,Uc:_d(f,y,m!==0),Wc:null})}function uT(c,f,y){function m(O){var k=(x(),U)[O>>>2>>>0];return O=(x(),U)[O+4>>>2>>>0],new T((x(),G).buffer,O,k)}var T=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][f];Xn(c>>>=0,{name:y=en(y>>>0),Oc:m,Uc:m},{yd:!0})}var rr=(c,f,y)=>{var m=(x(),Z);if(f>>>=0,0=k){if(f>=y)break;m[f++>>>0]=k}else if(2047>=k){if(f+1>=y)break;m[f++>>>0]=192|k>>6,m[f++>>>0]=128|63&k}else if(65535>=k){if(f+2>=y)break;m[f++>>>0]=224|k>>12,m[f++>>>0]=128|k>>6&63,m[f++>>>0]=128|63&k}else{if(f+3>=y)break;m[f++>>>0]=240|k>>18,m[f++>>>0]=128|k>>12&63,m[f++>>>0]=128|k>>6&63,m[f++>>>0]=128|63&k,O++}}m[f>>>0]=0,c=f-T}else c=0;return c},Qo=c=>{for(var f=0,y=0;y=m?f++:2047>=m?f+=2:55296<=m&&57343>=m?(f+=4,++y):f+=3}return f};function lT(c,f){Xn(c>>>=0,{name:f=en(f>>>0),Oc(y){var m=(x(),U)[y>>>2>>>0];return m=Qe(y+4,m,!0),nn(y),m},Vc(y,m){m instanceof ArrayBuffer&&(m=new Uint8Array(m));var T=typeof m=="string";if(!(T||ArrayBuffer.isView(m)&&m.BYTES_PER_ELEMENT==1))throw new Kr("Cannot pass non-string to std::string");var O=T?Qo(m):m.length,k=yo(4+O+1),M=k+4;return(x(),U)[k>>>2>>>0]=O,T?rr(m,M,O+1):(x(),Z).set(m,M>>>0),y!==null&&y.push(nn,k),k},Uc:ps,Wc(y){nn(y)}})}var vd=globalThis.TextDecoder?new TextDecoder("utf-16le"):void 0,cT=(c,f,y)=>{if(c>>>=1,16<(f=od((x(),ie),c,f/2,y))-c&&vd)return vd.decode((x(),ie).slice(c,f));for(y="";c>>0];y+=String.fromCharCode(m)}return y},dT=(c,f,y)=>{if(y??=2147483647,2>y)return 0;var m=f;y=(y-=2)<2*c.length?y/2:c.length;for(var T=0;T>>1>>>0]=O,f+=2}return(x(),J)[f>>>1>>>0]=0,f-m},pT=c=>2*c.length,fT=(c,f,y)=>{var m="";c>>>=2;for(var T=0;!(T>=f/4);T++){var O=(x(),U)[c+T>>>0];if(!O&&!y)break;m+=String.fromCodePoint(O)}return m},hT=(c,f,y)=>{if(f>>>=0,y??=2147483647,4>y)return 0;var m=f;y=m+y-4;for(var T=0;T>>2>>>0]=O,(f+=4)+4>y)break}return(x(),z)[f>>>2>>>0]=0,f-m},mT=c=>{for(var f=0,y=0;y>>=0,f>>>=0,y=en(y>>>=0),f===2)var m=cT,T=dT,O=pT;else m=fT,T=hT,O=mT;Xn(c,{name:y,Oc:k=>{var M=(x(),U)[k>>>2>>>0];return M=m(k+4,M*f,!0),nn(k),M},Vc:(k,M)=>{if(typeof M!="string")throw new Kr(`Cannot pass non-string to C++ string type ${y}`);var j=O(M),Y=yo(4+j+f);return(x(),U)[Y>>>2>>>0]=j/f,T(M,Y+4,j+f),k!==null&&k.push(nn,Y),Y},Uc:ps,Wc(k){nn(k)}})}function bT(c,f){Xn(c>>>=0,{zd:!0,name:f=en(f>>>0),Oc:()=>{},Vc:()=>{}})}function yT(c){vs(c>>>0,!t,1,!n,131072,!1),Zc()}var ei=c=>{if(!C)try{if(c(),!(0Number((navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)||[])[2]);function fs(c){c>>>=0,_T||(Atomics.waitAsync((x(),z),c>>>2,c).value.then(ti),c+=128,Atomics.store((x(),z),c>>>2,1))}var ti=()=>ei(()=>{var c=si();c&&(fs(c),Kd())});function wT(c,f){(c>>>=0)==f>>>0?setTimeout(ti):o?postMessage({Zc:c,Sc:"checkMailbox"}):(c=xr[c])&&c.postMessage({Sc:"checkMailbox"})}var hs=[];function vT(c,f,y,m,T){for(f>>>=0,T>>>=0,hs.length=0,y=T>>>3,m=T+m>>>3;y>>0]?(x(),ee)[y++>>>0]:(x(),oe)[y++>>>0],hs.push(O)}return(f?$s[f]:p2[c])(...hs)}var xT=()=>{St=0};function TT(c){c>>>=0,o?postMessage({Sc:"cleanupThread",Nd:c}):Xc(xr[c])}function IT(c){}var ni=c=>{try{c()}catch(f){F(f)}};function ST(c){var f=(...y)=>{ri.push(c);try{return c(...y)}finally{C||(ri.pop(),tn&&or===1&&ri.length===0&&(or=0,St+=1,ni(Rp),typeof Fibers<"u"&&Fibers.Zd()))}};return Id.set(c,f),f}var or=0,tn=null,xd=0,ri=[],ms=new Map,Td=new Map,Id=new Map,$T=0,gs=null,AT=[],Sd=c=>function(f){if(!C){if(or===0){var y=!1,m=!1;f((T=0)=>{if(!C&&(xd=T,y=!0,m)){or=2,ni(()=>zp(tn)),typeof MainLoop<"u"&&MainLoop.ud&&MainLoop.resume(),T=!1;try{var O=function(){var j=(x(),z)[tn+8>>>2>>>0];return j=Td.get(j),j=Id.get(j),--St,j()}()}catch(j){O=j,T=!0}var k=!1;if(!tn){var M=gs;M&&(gs=null,(T?M.reject:M.resolve)(O),k=!0)}if(T&&!k)throw O}}),m=!0,y||(or=1,tn=function(){var T=yo(65548),O=T+12;if((x(),U)[T>>>2>>>0]=O,(x(),U)[T+4>>>2>>>0]=O+65536,O=ri[0],!ms.has(O)){var k=$T++;ms.set(O,k),Td.set(k,O)}return O=ms.get(O),(x(),z)[T+8>>>2>>>0]=O,T}(),typeof MainLoop<"u"&&MainLoop.ud&&MainLoop.pause(),ni(()=>Lp(tn)))}else or===2?(or=0,ni(Mp),nn(tn),tn=null,AT.forEach(ei)):F(`invalid state: ${or}`);return xd}}(f=>{c().then(f)});function OT(c){return c>>>=0,Sd(async()=>{var f=await Ct(c);return Ut(f)})}var bs=[],PT=c=>{var f=bs.length;return bs.push(c),f},ET=(c,f)=>{for(var y=Array(c),m=0;m>>2>>>0],k=cs[O];if(k===void 0)throw c=`parameter ${m}`,O=Gd(O),f=en(O),nn(O),new Kr(`${c} has unknown type ${f}`);y[T]=k}return y},CT=(c,f,y)=>{var m=[];return c=c(m,y),m.length&&((x(),U)[f>>>2>>>0]=Ut(m)),c},DT={},oi=c=>{var f=DT[c];return f===void 0?en(c):f};function kT(c,f,y){var[m,...T]=ET(c,f>>>0);f=m.Vc.bind(m);var O=T.map(j=>j.Uc.bind(j));c--;var k={toValue:Ct};switch(c=O.map((j,Y)=>{var be=`argFromPtr${Y}`;return k[be]=j,`${be}(args${Y?"+"+8*Y:""})`}),y){case 0:var M="toValue(handle)";break;case 2:M="new (toValue(handle))";break;case 3:M="";break;case 1:k.getStringOrSymbol=oi,M="toValue(handle)[getStringOrSymbol(methodName)]"}return M+=`(${c})`,m.zd||(k.toReturnWire=f,k.emval_returnValue=CT,M=`return emval_returnValue(toReturnWire, destructorsRef, ${M})`),M=`return function (handle, methodName, destructorsRef, args) { ${M} }`,y=new Function(Object.keys(k),M)(...Object.values(k)),M=`methodCaller<(${T.map(j=>j.name)}) => ${m.name}>`,PT(Object.defineProperty(y,"name",{value:M}))}function NT(c,f){return f>>>=0,(c=Ct(c>>>0))==Ct(f)}function LT(c){return(c>>>=0)?(c=oi(c),Ut(globalThis[c])):Ut(globalThis)}function RT(c){return c=oi(c>>>0),Ut(e[c])}function zT(c,f){return f>>>=0,c=Ct(c>>>0),f=Ct(f),Ut(c[f])}function MT(c){9<(c>>>=0)&&(Tr[c+1]+=1)}function $d(c,f,y,m,T){return bs[c>>>0](f>>>0,y>>>0,m>>>0,T>>>0)}function BT(c,f,y,m,T){return $d(c>>>0,f>>>0,y>>>0,m>>>0,T>>>0)}function FT(){return Ut([])}function VT(c){c=Ct(c>>>0);for(var f=Array(c.length),y=0;y>>0))}function UT(){return Ut({})}function WT(c){for(var f=Ct(c>>>=0);f.length;){var y=f.pop();f.pop()(y)}ds(c)}function HT(c,f,y){f>>>=0,y>>>=0,c=Ct(c>>>0),f=Ct(f),y=Ct(y),c[f]=y}function qT(c,f){c=-9007199254740992>c||9007199254740992>>=0,c=new Date(1e3*c),(x(),z)[f>>>2>>>0]=c.getUTCSeconds(),(x(),z)[f+4>>>2>>>0]=c.getUTCMinutes(),(x(),z)[f+8>>>2>>>0]=c.getUTCHours(),(x(),z)[f+12>>>2>>>0]=c.getUTCDate(),(x(),z)[f+16>>>2>>>0]=c.getUTCMonth(),(x(),z)[f+20>>>2>>>0]=c.getUTCFullYear()-1900,(x(),z)[f+24>>>2>>>0]=c.getUTCDay(),c=(c.getTime()-Date.UTC(c.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,(x(),z)[f+28>>>2>>>0]=c}var Ad=c=>c%4==0&&(c%100!=0||c%400==0),Od=[0,31,60,91,121,152,182,213,244,274,305,335],Pd=[0,31,59,90,120,151,181,212,243,273,304,334];function jT(c,f){c=-9007199254740992>c||9007199254740992>>=0,c=new Date(1e3*c),(x(),z)[f>>>2>>>0]=c.getSeconds(),(x(),z)[f+4>>>2>>>0]=c.getMinutes(),(x(),z)[f+8>>>2>>>0]=c.getHours(),(x(),z)[f+12>>>2>>>0]=c.getDate(),(x(),z)[f+16>>>2>>>0]=c.getMonth(),(x(),z)[f+20>>>2>>>0]=c.getFullYear()-1900,(x(),z)[f+24>>>2>>>0]=c.getDay();var y=(Ad(c.getFullYear())?Od:Pd)[c.getMonth()]+c.getDate()-1|0;(x(),z)[f+28>>>2>>>0]=y,(x(),z)[f+36>>>2>>>0]=-60*c.getTimezoneOffset(),y=new Date(c.getFullYear(),6,1).getTimezoneOffset();var m=new Date(c.getFullYear(),0,1).getTimezoneOffset();c=0|(y!=m&&c.getTimezoneOffset()==Math.min(m,y)),(x(),z)[f+32>>>2>>>0]=c}function KT(c){c>>>=0;var f=new Date((x(),z)[c+20>>>2>>>0]+1900,(x(),z)[c+16>>>2>>>0],(x(),z)[c+12>>>2>>>0],(x(),z)[c+8>>>2>>>0],(x(),z)[c+4>>>2>>>0],(x(),z)[c>>>2>>>0],0),y=(x(),z)[c+32>>>2>>>0],m=f.getTimezoneOffset(),T=new Date(f.getFullYear(),6,1).getTimezoneOffset(),O=new Date(f.getFullYear(),0,1).getTimezoneOffset(),k=Math.min(O,T);return 0>y?(x(),z)[c+32>>>2>>>0]=+(T!=O&&k==m):0>>2>>>0]=f.getDay(),y=(Ad(f.getFullYear())?Od:Pd)[f.getMonth()]+f.getDate()-1|0,(x(),z)[c+28>>>2>>>0]=y,(x(),z)[c>>>2>>>0]=f.getSeconds(),(x(),z)[c+4>>>2>>>0]=f.getMinutes(),(x(),z)[c+8>>>2>>>0]=f.getHours(),(x(),z)[c+12>>>2>>>0]=f.getDate(),(x(),z)[c+16>>>2>>>0]=f.getMonth(),(x(),z)[c+20>>>2>>>0]=f.getYear(),c=f.getTime(),BigInt(isNaN(c)?-1:c/1e3)}function Ed(c,f,y,m,T,O,k){return o?We(16,1,c,f,y,m,T,O,k):-52}function Cd(c,f,y,m,T,O){if(o)return We(17,1,c,f,y,m,T,O)}var bo={},XT=()=>performance.timeOrigin+performance.now();function Dd(c,f){if(o)return We(18,1,c,f);if(bo[c]&&(clearTimeout(bo[c].id),delete bo[c]),!f)return 0;var y=setTimeout(()=>{delete bo[c],ei(()=>jd(c,performance.timeOrigin+performance.now()))},f);return bo[c]={id:y,Yd:f},0}function ZT(c,f,y,m){c>>>=0,f>>>=0,y>>>=0,m>>>=0;var T=new Date().getFullYear(),O=new Date(T,0,1).getTimezoneOffset();T=new Date(T,6,1).getTimezoneOffset();var k=Math.max(O,T);(x(),U)[c>>>2>>>0]=60*k,(x(),z)[f>>>2>>>0]=+(O!=T),c=(f=M=>{var j=Math.abs(M);return`UTC${0<=M?"-":"+"}${String(Math.floor(j/60)).padStart(2,"0")}${String(j%60).padStart(2,"0")}`})(O),f=f(T),TDate.now(),YT=1;function QT(c,f,y){if(y>>>=0,!(0<=c&&3>=c))return 28;if(c===0)c=Date.now();else{if(!YT)return 52;c=performance.timeOrigin+performance.now()}return c=Math.round(1e6*c),(x(),ee)[y>>>3>>>0]=BigInt(c),0}var ys=[],kd=(c,f)=>{ys.length=0;for(var y;y=(x(),Z)[c++>>>0];){var m=y!=105;f+=(m&=y!=112)&&f%8?4:0,ys.push(y==112?(x(),U)[f>>>2>>>0]:y==106?(x(),ee)[f>>>3>>>0]:y==105?(x(),z)[f>>>2>>>0]:(x(),oe)[f>>>3>>>0]),f+=m?8:4}return ys};function e2(c,f,y){return c>>>=0,f=kd(f>>>0,y>>>0),$s[c](...f)}function t2(c,f,y){return c>>>=0,f=kd(f>>>0,y>>>0),$s[c](...f)}var n2=()=>{};function r2(c,f){return P(Qe(c>>>0,f>>>0))}var o2=()=>{throw St+=1,"unwind"};function i2(){return 4294901760}var a2=()=>navigator.hardwareConcurrency,Ir={},ii=c=>{var f;return(f=/\bwasm-function\[\d+\]:(0x[0-9a-f]+)/.exec(c))?+f[1]:(f=/:(\d+):\d+(?:\)|$)/.exec(c))?2147483648|+f[1]:0},Nd=c=>{for(var f of c)(c=ii(f))&&(Ir[c]=f)};function s2(){var c=Error().stack.toString().split(` `);return c[0]=="Error"&&c.shift(),Nd(c),Ir.gd=ii(c[3]),Ir.Jd=c,Ir.gd}function ai(c){if(!(c=Ir[c>>>0]))return 0;var f;if(f=/^\s+at .*\.wasm\.(.*) \(.*\)$/.exec(c))c=f[1];else if(f=/^\s+at (.*) \(.*\)$/.exec(c))c=f[1];else{if(!(f=/^(.+?)@/.exec(c)))return 0;c=f[1]}nn(ai.hd??0),f=Qo(c)+1;var y=yo(f);return y&&rr(c,y,f),ai.hd=y,ai.hd}function u2(c){c>>>=0;var f=(x(),Z).length;if(c<=f||4294901760=y;y*=2){var m=f*(1+.2/y);m=Math.min(m,c+100663296);e:{m=(Math.min(4294901760,65536*Math.ceil(Math.max(c,m)/65536))-nr.buffer.byteLength+65535)/65536|0;try{nr.grow(m),mt();var T=1;break e}catch{}T=void 0}if(T)return!0}return!1}function l2(c,f,y){if(c>>>=0,f>>>=0,Ir.gd==c)var m=Ir.Jd;else(m=Error().stack.toString().split(` `))[0]=="Error"&&m.shift(),Nd(m);for(var T=3;m[T]&&ii(m[T])!=c;)++T;for(c=0;c>>2>>>0]=ii(m[c+T]);return c}var _s,ws={},Ld=()=>{if(!_s){var c,f={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:"./this.program"};for(c in ws)ws[c]===void 0?delete f[c]:f[c]=ws[c];var y=[];for(c in f)y.push(`${c}=${f[c]}`);_s=y}return _s};function Rd(c,f){if(o)return We(19,1,c,f);c>>>=0,f>>>=0;var y,m=0,T=0;for(y of Ld()){var O=f+m;(x(),U)[c+T>>>2>>>0]=O,m+=rr(y,O,1/0)+1,T+=4}return 0}function zd(c,f){if(o)return We(20,1,c,f);c>>>=0,f>>>=0;var y=Ld();for(var m of((x(),U)[c>>>2>>>0]=y.length,c=0,y))c+=Qo(m)+1;return(x(),U)[f>>>2>>>0]=c,0}function Md(c){return o?We(21,1,c):52}function Bd(c,f,y,m){return o?We(22,1,c,f,y,m):52}function Fd(c,f,y,m){return o?We(23,1,c,f,y,m):70}var c2=[null,[],[]];function Vd(c,f,y,m){if(o)return We(24,1,c,f,y,m);f>>>=0,y>>>=0,m>>>=0;for(var T=0,O=0;O>>2>>>0],M=(x(),U)[f+4>>>2>>>0];f+=8;for(var j=0;j>>0],$e=c2[Y];be===0||be===10?((Y===1?A:P)(id($e)),$e.length=0):$e.push(be)}T+=M}return(x(),U)[m>>>2>>>0]=T,0}function d2(c){return c>>>0}o||function(){for(var c=e.numThreads-1;c--;)Yc();at.push(async()=>{var f=async function(){if(!o)return Promise.all(tr.map(Jc))}();Ee++,await f,--Ee==0&&He&&(f=He,He=null,f())})}(),o||(nr=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),mt()),e.wasmBinary&&(h=e.wasmBinary),e.stackSave=()=>ve(),e.stackRestore=c=>we(c),e.stackAlloc=c=>Ts(c),e.setValue=function(c,f,y="i8"){switch(y.endsWith("*")&&(y="*"),y){case"i1":case"i8":(x(),G)[c>>>0]=f;break;case"i16":(x(),J)[c>>>1>>>0]=f;break;case"i32":(x(),z)[c>>>2>>>0]=f;break;case"i64":(x(),ee)[c>>>3>>>0]=BigInt(f);break;case"float":(x(),te)[c>>>2>>>0]=f;break;case"double":(x(),oe)[c>>>3>>>0]=f;break;case"*":(x(),U)[c>>>2>>>0]=f;break;default:F(`invalid type for setValue: ${y}`)}},e.getValue=function(c,f="i8"){switch(f.endsWith("*")&&(f="*"),f){case"i1":case"i8":return(x(),G)[c>>>0];case"i16":return(x(),J)[c>>>1>>>0];case"i32":return(x(),z)[c>>>2>>>0];case"i64":return(x(),ee)[c>>>3>>>0];case"float":return(x(),te)[c>>>2>>>0];case"double":return(x(),oe)[c>>>3>>>0];case"*":return(x(),U)[c>>>2>>>0];default:F(`invalid type for getValue: ${f}`)}},e.UTF8ToString=Qe,e.stringToUTF8=rr,e.lengthBytesUTF8=Qo;var Gd,Ud,si,nn,yo,vs,Wd,Hd,qd,xs,jd,Kd,Ie,_o,Xd,we,Ts,ve,Zd,Is,Jd,Yd,Qd,Ss,ep,tp,np,rp,op,ip,ap,sp,up,lp,cp,dp,pp,fp,hp,mp,gp,bp,yp,_p,wp,vp,xp,Tp,Ip,Sp,$p,Ap,Op,Pp,Ep,Cp,Dp,kp,Np,Lp,Rp,zp,Mp,Zn,p2=[Zo,jc,td,ad,sd,ud,ld,cd,dd,pd,fd,hd,md,gd,bd,yd,Ed,Cd,Dd,Rd,zd,Md,Bd,Fd,Vd],$s={973212:(c,f,y,m,T)=>{if(e===void 0||!e.Xc)return 1;if((c=Qe(Number(c>>>0))).startsWith("./")&&(c=c.substring(2)),!(c=e.Xc.get(c)))return 2;if(f=Number(f>>>0),y=Number(y>>>0),m=Number(m>>>0),f+y>c.byteLength)return 3;try{let O=c.subarray(f,f+y);switch(T){case 0:(x(),Z).set(O,m>>>0);break;case 1:e.Qd?e.Qd(m,O):e.Id(m,O);break;default:return 4}return 0}catch{return 4}},974036:(c,f,y)=>{e.td(c,(x(),Z).subarray(f>>>0,f+y>>>0))},974100:()=>e.Wd(),974142:c=>{e.sd(c)},974179:()=>{e.Bd()},974210:()=>{e.Cd()},974239:()=>{e.Gd()},974264:c=>e.Ad(c),974297:c=>e.Ed(c),974329:(c,f,y)=>{e.ed(Number(c),Number(f),Number(y),!0)},974392:(c,f,y)=>{e.ed(Number(c),Number(f),Number(y))},974449:()=>typeof wasmOffsetConverter<"u",974506:c=>{e.$b("Abs",c,void 0)},974557:c=>{e.$b("Neg",c,void 0)},974608:c=>{e.$b("Floor",c,void 0)},974661:c=>{e.$b("Ceil",c,void 0)},974713:c=>{e.$b("Reciprocal",c,void 0)},974771:c=>{e.$b("Sqrt",c,void 0)},974823:c=>{e.$b("Exp",c,void 0)},974874:c=>{e.$b("Erf",c,void 0)},974925:c=>{e.$b("Sigmoid",c,void 0)},974980:(c,f,y)=>{e.$b("HardSigmoid",c,{alpha:f,beta:y})},975059:c=>{e.$b("Log",c,void 0)},975110:c=>{e.$b("Sin",c,void 0)},975161:c=>{e.$b("Cos",c,void 0)},975212:c=>{e.$b("Tan",c,void 0)},975263:c=>{e.$b("Asin",c,void 0)},975315:c=>{e.$b("Acos",c,void 0)},975367:c=>{e.$b("Atan",c,void 0)},975419:c=>{e.$b("Sinh",c,void 0)},975471:c=>{e.$b("Cosh",c,void 0)},975523:c=>{e.$b("Asinh",c,void 0)},975576:c=>{e.$b("Acosh",c,void 0)},975629:c=>{e.$b("Atanh",c,void 0)},975682:c=>{e.$b("Tanh",c,void 0)},975734:c=>{e.$b("Not",c,void 0)},975785:(c,f,y)=>{e.$b("Clip",c,{min:f,max:y})},975854:c=>{e.$b("Clip",c,void 0)},975906:(c,f)=>{e.$b("Elu",c,{alpha:f})},975964:c=>{e.$b("Gelu",c,void 0)},976016:c=>{e.$b("Relu",c,void 0)},976068:(c,f)=>{e.$b("LeakyRelu",c,{alpha:f})},976132:(c,f)=>{e.$b("ThresholdedRelu",c,{alpha:f})},976202:(c,f)=>{e.$b("Cast",c,{to:f})},976260:c=>{e.$b("Add",c,void 0)},976311:c=>{e.$b("Sub",c,void 0)},976362:c=>{e.$b("Mul",c,void 0)},976413:c=>{e.$b("Div",c,void 0)},976464:c=>{e.$b("Pow",c,void 0)},976515:c=>{e.$b("Equal",c,void 0)},976568:c=>{e.$b("Greater",c,void 0)},976623:c=>{e.$b("GreaterOrEqual",c,void 0)},976685:c=>{e.$b("Less",c,void 0)},976737:c=>{e.$b("LessOrEqual",c,void 0)},976796:(c,f,y,m,T)=>{e.$b("ReduceMean",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},976971:(c,f,y,m,T)=>{e.$b("ReduceMax",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},977145:(c,f,y,m,T)=>{e.$b("ReduceMin",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},977319:(c,f,y,m,T)=>{e.$b("ReduceProd",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},977494:(c,f,y,m,T)=>{e.$b("ReduceSum",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},977668:(c,f,y,m,T)=>{e.$b("ReduceL1",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},977841:(c,f,y,m,T)=>{e.$b("ReduceL2",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},978014:(c,f,y,m,T)=>{e.$b("ReduceLogSum",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},978191:(c,f,y,m,T)=>{e.$b("ReduceSumSquare",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},978371:(c,f,y,m,T)=>{e.$b("ReduceLogSumExp",c,{keepDims:!!f,noopWithEmptyAxes:!!y,axes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},978551:c=>{e.$b("Where",c,void 0)},978604:(c,f,y)=>{e.$b("Transpose",c,{perm:f?Array.from((x(),z).subarray(Number(f)>>>0,Number(y)>>>0)):[]})},978728:(c,f,y,m)=>{e.$b("DepthToSpace",c,{blocksize:f,mode:Qe(y),format:m?"NHWC":"NCHW"})},978861:(c,f,y,m)=>{e.$b("DepthToSpace",c,{blocksize:f,mode:Qe(y),format:m?"NHWC":"NCHW"})},978994:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe,ir)=>{e.$b("ConvTranspose",c,{format:j?"NHWC":"NCHW",autoPad:f,dilations:[y],group:m,kernelShape:[T],pads:[O,k],strides:[M],wIsConst:()=>!!(x(),G)[Y>>>0],outputPadding:be?Array.from((x(),z).subarray(Number(be)>>>0,Number($e)>>>0)):[],outputShape:Ue?Array.from((x(),z).subarray(Number(Ue)>>>0,Number(qe)>>>0)):[],activation:Qe(ir)})},979427:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("ConvTranspose",c,{format:M?"NHWC":"NCHW",autoPad:f,dilations:Array.from((x(),z).subarray(Number(y)>>>0,2+(Number(y)>>>0)>>>0)),group:m,kernelShape:Array.from((x(),z).subarray(Number(T)>>>0,2+(Number(T)>>>0)>>>0)),pads:Array.from((x(),z).subarray(Number(O)>>>0,4+(Number(O)>>>0)>>>0)),strides:Array.from((x(),z).subarray(Number(k)>>>0,2+(Number(k)>>>0)>>>0)),wIsConst:()=>!!(x(),G)[j>>>0],outputPadding:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],outputShape:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[],activation:Qe(qe)})},980088:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe,ir)=>{e.$b("ConvTranspose",c,{format:j?"NHWC":"NCHW",autoPad:f,dilations:[y],group:m,kernelShape:[T],pads:[O,k],strides:[M],wIsConst:()=>!!(x(),G)[Y>>>0],outputPadding:be?Array.from((x(),z).subarray(Number(be)>>>0,Number($e)>>>0)):[],outputShape:Ue?Array.from((x(),z).subarray(Number(Ue)>>>0,Number(qe)>>>0)):[],activation:Qe(ir)})},980521:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("ConvTranspose",c,{format:M?"NHWC":"NCHW",autoPad:f,dilations:Array.from((x(),z).subarray(Number(y)>>>0,2+(Number(y)>>>0)>>>0)),group:m,kernelShape:Array.from((x(),z).subarray(Number(T)>>>0,2+(Number(T)>>>0)>>>0)),pads:Array.from((x(),z).subarray(Number(O)>>>0,4+(Number(O)>>>0)>>>0)),strides:Array.from((x(),z).subarray(Number(k)>>>0,2+(Number(k)>>>0)>>>0)),wIsConst:()=>!!(x(),G)[j>>>0],outputPadding:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],outputShape:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[],activation:Qe(qe)})},981182:(c,f)=>{e.$b("GlobalAveragePool",c,{format:f?"NHWC":"NCHW"})},981273:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("AveragePool",c,{format:qe?"NHWC":"NCHW",auto_pad:f,ceil_mode:y,count_include_pad:m,storage_order:T,dilations:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[],kernel_shape:M?Array.from((x(),z).subarray(Number(M)>>>0,Number(j)>>>0)):[],pads:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],strides:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[]})},981752:(c,f)=>{e.$b("GlobalAveragePool",c,{format:f?"NHWC":"NCHW"})},981843:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("AveragePool",c,{format:qe?"NHWC":"NCHW",auto_pad:f,ceil_mode:y,count_include_pad:m,storage_order:T,dilations:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[],kernel_shape:M?Array.from((x(),z).subarray(Number(M)>>>0,Number(j)>>>0)):[],pads:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],strides:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[]})},982322:(c,f)=>{e.$b("GlobalMaxPool",c,{format:f?"NHWC":"NCHW"})},982409:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("MaxPool",c,{format:qe?"NHWC":"NCHW",auto_pad:f,ceil_mode:y,count_include_pad:m,storage_order:T,dilations:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[],kernel_shape:M?Array.from((x(),z).subarray(Number(M)>>>0,Number(j)>>>0)):[],pads:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],strides:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[]})},982884:(c,f)=>{e.$b("GlobalMaxPool",c,{format:f?"NHWC":"NCHW"})},982971:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe)=>{e.$b("MaxPool",c,{format:qe?"NHWC":"NCHW",auto_pad:f,ceil_mode:y,count_include_pad:m,storage_order:T,dilations:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[],kernel_shape:M?Array.from((x(),z).subarray(Number(M)>>>0,Number(j)>>>0)):[],pads:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],strides:$e?Array.from((x(),z).subarray(Number($e)>>>0,Number(Ue)>>>0)):[]})},983446:(c,f,y,m,T)=>{e.$b("Gemm",c,{alpha:f,beta:y,transA:m,transB:T})},983550:c=>{e.$b("MatMul",c,void 0)},983604:(c,f,y,m)=>{e.$b("ArgMax",c,{keepDims:!!f,selectLastIndex:!!y,axis:m})},983712:(c,f,y,m)=>{e.$b("ArgMin",c,{keepDims:!!f,selectLastIndex:!!y,axis:m})},983820:(c,f)=>{e.$b("Softmax",c,{axis:f})},983883:(c,f)=>{e.$b("Concat",c,{axis:f})},983943:(c,f,y,m,T)=>{e.$b("Split",c,{axis:f,numOutputs:y,splitSizes:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},984099:c=>{e.$b("Expand",c,void 0)},984153:(c,f)=>{e.$b("Gather",c,{axis:Number(f)})},984224:(c,f)=>{e.$b("GatherElements",c,{axis:Number(f)})},984303:(c,f)=>{e.$b("GatherND",c,{batch_dims:Number(f)})},984382:(c,f,y,m,T,O,k,M,j,Y,be)=>{e.$b("Resize",c,{antialias:f,axes:y?Array.from((x(),z).subarray(Number(y)>>>0,Number(m)>>>0)):[],coordinateTransformMode:Qe(T),cubicCoeffA:O,excludeOutside:k,extrapolationValue:M,keepAspectRatioPolicy:Qe(j),mode:Qe(Y),nearestMode:Qe(be)})},984744:(c,f,y,m,T,O,k)=>{e.$b("Slice",c,{starts:f?Array.from((x(),z).subarray(Number(f)>>>0,Number(y)>>>0)):[],ends:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[],axes:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[]})},985008:c=>{e.$b("Tile",c,void 0)},985060:(c,f,y)=>{e.$b("InstanceNormalization",c,{epsilon:f,format:y?"NHWC":"NCHW"})},985174:(c,f,y)=>{e.$b("InstanceNormalization",c,{epsilon:f,format:y?"NHWC":"NCHW"})},985288:c=>{e.$b("Range",c,void 0)},985341:(c,f)=>{e.$b("Einsum",c,{equation:Qe(f)})},985422:(c,f,y,m,T)=>{e.$b("Pad",c,{mode:f,value:y,pads:m?Array.from((x(),z).subarray(Number(m)>>>0,Number(T)>>>0)):[]})},985565:(c,f,y,m,T,O)=>{e.$b("BatchNormalization",c,{epsilon:f,momentum:y,spatial:!!T,trainingMode:!!m,format:O?"NHWC":"NCHW"})},985734:(c,f,y,m,T,O)=>{e.$b("BatchNormalization",c,{epsilon:f,momentum:y,spatial:!!T,trainingMode:!!m,format:O?"NHWC":"NCHW"})},985903:(c,f,y)=>{e.$b("CumSum",c,{exclusive:Number(f),reverse:Number(y)})},986e3:(c,f,y)=>{e.$b("DequantizeLinear",c,{axis:f,blockSize:y})},986090:(c,f,y,m,T)=>{e.$b("GridSample",c,{align_corners:f,mode:Qe(y),padding_mode:Qe(m),format:T?"NHWC":"NCHW"})},986260:(c,f,y,m,T)=>{e.$b("GridSample",c,{align_corners:f,mode:Qe(y),padding_mode:Qe(m),format:T?"NHWC":"NCHW"})},986430:(c,f)=>{e.$b("ScatterND",c,{reduction:Qe(f)})},986515:(c,f,y,m,T,O,k,M,j)=>{e.$b("Attention",c,{numHeads:f,isUnidirectional:y,maskFilterValue:m,scale:T,doRotary:O,qkvHiddenSizes:k?Array.from((x(),z).subarray(Number(M)>>>0,Number(M)+k>>>0)):[],pastPresentShareBuffer:!!j})},986787:c=>{e.$b("BiasAdd",c,void 0)},986842:c=>{e.$b("BiasSplitGelu",c,void 0)},986903:c=>{e.$b("FastGelu",c,void 0)},986959:(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe,ir,As)=>{e.$b("Conv",c,{format:$e?"NHWC":"NCHW",auto_pad:f,dilations:y?Array.from((x(),z).subarray(Number(y)>>>0,Number(m)>>>0)):[],group:T,kernel_shape:O?Array.from((x(),z).subarray(Number(O)>>>0,Number(k)>>>0)):[],pads:M?Array.from((x(),z).subarray(Number(M)>>>0,Number(j)>>>0)):[],strides:Y?Array.from((x(),z).subarray(Number(Y)>>>0,Number(be)>>>0)):[],w_is_const:()=>!!(x(),G)[Number(Ue)>>>0],activation:Qe(qe),activation_params:ir?Array.from((x(),te).subarray(Number(ir)>>>0,Number(As)>>>0)):[]})},987543:c=>{e.$b("Gelu",c,void 0)},987595:(c,f,y,m,T,O,k,M,j)=>{e.$b("GroupQueryAttention",c,{numHeads:f,kvNumHeads:y,scale:m,softcap:T,doRotary:O,rotaryInterleaved:k,smoothSoftmax:M,localWindowSize:j})},987812:(c,f,y,m)=>{e.$b("LayerNormalization",c,{axis:f,epsilon:y,simplified:!!m})},987923:(c,f,y,m)=>{e.$b("LayerNormalization",c,{axis:f,epsilon:y,simplified:!!m})},988034:(c,f,y,m,T,O)=>{e.$b("MatMulNBits",c,{k:f,n:y,accuracyLevel:m,bits:T,blockSize:O})},988161:(c,f,y,m,T,O)=>{e.$b("MultiHeadAttention",c,{numHeads:f,isUnidirectional:y,maskFilterValue:m,scale:T,doRotary:O})},988320:(c,f)=>{e.$b("QuickGelu",c,{alpha:f})},988384:(c,f,y,m,T)=>{e.$b("RotaryEmbedding",c,{interleaved:!!f,numHeads:y,rotaryEmbeddingDim:m,scale:T})},988523:(c,f,y)=>{e.$b("SkipLayerNormalization",c,{epsilon:f,simplified:!!y})},988625:(c,f,y)=>{e.$b("SkipLayerNormalization",c,{epsilon:f,simplified:!!y})},988727:(c,f,y,m)=>{e.$b("GatherBlockQuantized",c,{gatherAxis:f,quantizeAxis:y,blockSize:m})},988848:c=>{e.Fd(c)},988882:(c,f)=>e.Hd(Number(c),Number(f),e.Yc.Kd,e.Yc.errors)};function f2(c,f,y){return Sd(async()=>{await e.Dd(Number(c),Number(f),Number(y))})}function h2(){return typeof wasmOffsetConverter<"u"}function m2(c,f,y,m){var T=ve();try{return sp(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function g2(c,f,y){var m=ve();try{return rp(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;Ie(1,0)}}function b2(c){var f=ve();try{ep(c)}catch(y){if(we(f),y!==y+0)throw y;Ie(1,0)}}function y2(c,f){var y=ve();try{return Ss(c,f)}catch(m){if(we(y),m!==m+0)throw m;Ie(1,0)}}function _2(c,f,y){var m=ve();try{Qd(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;Ie(1,0)}}function w2(c,f){var y=ve();try{up(c,f)}catch(m){if(we(y),m!==m+0)throw m;Ie(1,0)}}function v2(c,f,y,m,T,O,k){var M=ve();try{return ip(c,f,y,m,T,O,k)}catch(j){if(we(M),j!==j+0)throw j;Ie(1,0)}}function x2(c,f,y,m,T,O){var k=ve();try{tp(c,f,y,m,T,O)}catch(M){if(we(k),M!==M+0)throw M;Ie(1,0)}}function T2(c,f,y,m){var T=ve();try{ap(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function I2(c,f,y,m,T){var O=ve();try{np(c,f,y,m,T)}catch(k){if(we(O),k!==k+0)throw k;Ie(1,0)}}function S2(c,f,y,m,T,O,k){var M=ve();try{cp(c,f,y,m,T,O,k)}catch(j){if(we(M),j!==j+0)throw j;Ie(1,0)}}function $2(c,f,y,m,T,O,k){var M=ve();try{dp(c,f,y,m,T,O,k)}catch(j){if(we(M),j!==j+0)throw j;Ie(1,0)}}function A2(c,f,y,m,T,O,k,M){var j=ve();try{mp(c,f,y,m,T,O,k,M)}catch(Y){if(we(j),Y!==Y+0)throw Y;Ie(1,0)}}function O2(c,f,y,m,T){var O=ve();try{return lp(c,f,y,m,T)}catch(k){if(we(O),k!==k+0)throw k;Ie(1,0)}}function P2(c,f,y){var m=ve();try{return gp(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;Ie(1,0)}}function E2(c,f,y,m,T,O,k,M){var j=ve();try{bp(c,f,y,m,T,O,k,M)}catch(Y){if(we(j),Y!==Y+0)throw Y;Ie(1,0)}}function C2(c,f,y,m,T,O,k,M,j,Y,be,$e){var Ue=ve();try{pp(c,f,y,m,T,O,k,M,j,Y,be,$e)}catch(qe){if(we(Ue),qe!==qe+0)throw qe;Ie(1,0)}}function D2(c,f,y,m,T,O){var k=ve();try{return fp(c,f,y,m,T,O)}catch(M){if(we(k),M!==M+0)throw M;Ie(1,0)}}function k2(c,f,y){var m=ve();try{return yp(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;return Ie(1,0),0n}}function N2(c,f,y,m,T,O,k,M,j){var Y=ve();try{op(c,f,y,m,T,O,k,M,j)}catch(be){if(we(Y),be!==be+0)throw be;Ie(1,0)}}function L2(c){var f=ve();try{return _p(c)}catch(y){if(we(f),y!==y+0)throw y;Ie(1,0)}}function R2(c,f){var y=ve();try{return Np(c,f)}catch(m){if(we(y),m!==m+0)throw m;return Ie(1,0),0n}}function z2(c){var f=ve();try{return wp(c)}catch(y){if(we(f),y!==y+0)throw y;return Ie(1,0),0n}}function M2(c,f,y,m){var T=ve();try{return $p(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function B2(c,f,y,m,T){var O=ve();try{return Ap(c,f,y,m,T)}catch(k){if(we(O),k!==k+0)throw k;Ie(1,0)}}function F2(c,f,y,m,T,O){var k=ve();try{return Op(c,f,y,m,T,O)}catch(M){if(we(k),M!==M+0)throw M;Ie(1,0)}}function V2(c,f,y,m,T,O){var k=ve();try{return Pp(c,f,y,m,T,O)}catch(M){if(we(k),M!==M+0)throw M;Ie(1,0)}}function G2(c,f,y,m,T,O,k,M){var j=ve();try{return hp(c,f,y,m,T,O,k,M)}catch(Y){if(we(j),Y!==Y+0)throw Y;Ie(1,0)}}function U2(c,f,y,m,T){var O=ve();try{return Ep(c,f,y,m,T)}catch(k){if(we(O),k!==k+0)throw k;return Ie(1,0),0n}}function W2(c,f,y,m){var T=ve();try{return Cp(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function H2(c,f,y,m){var T=ve();try{return Dp(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function q2(c,f,y,m,T,O,k,M,j,Y,be,$e){var Ue=ve();try{return kp(c,f,y,m,T,O,k,M,j,Y,be,$e)}catch(qe){if(we(Ue),qe!==qe+0)throw qe;Ie(1,0)}}function j2(c,f,y,m,T,O,k,M,j,Y,be){var $e=ve();try{Ip(c,f,y,m,T,O,k,M,j,Y,be)}catch(Ue){if(we($e),Ue!==Ue+0)throw Ue;Ie(1,0)}}function K2(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe,ir,As){var Y2=ve();try{Sp(c,f,y,m,T,O,k,M,j,Y,be,$e,Ue,qe,ir,As)}catch(Os){if(we(Y2),Os!==Os+0)throw Os;Ie(1,0)}}function X2(c,f,y){var m=ve();try{return vp(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;Ie(1,0)}}function Z2(c,f,y){var m=ve();try{return xp(c,f,y)}catch(T){if(we(m),T!==T+0)throw T;Ie(1,0)}}function J2(c,f,y,m){var T=ve();try{Tp(c,f,y,m)}catch(O){if(we(T),O!==O+0)throw O;Ie(1,0)}}function ui(){if(0{_=c,I=f})}var e3,t3,Qy=N(()=>{"use strict";e3=Jy,t3=globalThis.self?.name?.startsWith("em-pthread");t3&&Jy()});var n_,ac,n3,Pt,r_,ic,r3,o3,o_,i3,e_,i_,t_,a_,ga=N(()=>{"use strict";ma();n_=typeof location>"u"?void 0:location.origin,ac=import.meta.url>"file:"&&import.meta.url<"file;",n3=()=>{if(!!1){if(ac){let r=URL;return new URL(new r("ort.all.bundle.min.mjs",import.meta.url).href,n_).href}return import.meta.url}},Pt=n3(),r_=()=>{if(Pt&&!Pt.startsWith("blob:"))return Pt.substring(0,Pt.lastIndexOf("/")+1)},ic=(r,e)=>{try{let n=e??Pt;return(n?new URL(r,n):new URL(r)).origin===n_}catch{return!1}},r3=(r,e)=>{let n=e??Pt;try{return(n?new URL(r,n):new URL(r)).href}catch{return}},o3=(r,e)=>`${e??"./"}${r}`,o_=async r=>{let n=await(await fetch(r,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},i3=async r=>(await import(/*webpackIgnore:true*/ /*@vite-ignore*/r)).default,e_=(Zy(),Xr(Xy)).default,i_=async()=>{if(!Pt)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(ic(Pt))return[void 0,e_()];let r=await o_(Pt);return[r,e_(r)]},t_=(Qy(),Xr(Yy)).default,a_=async(r,e,n,t)=>{let o=t_&&!(r||e);if(o)if(Pt)o=ic(Pt)||t&&!n;else if(t&&!n)o=!0;else throw new Error("cannot determine the script source URL.");if(o)return[void 0,t_];{let i="ort-wasm-simd-threaded.jsep.mjs",a=r??r3(i,e),s=!!1&&n&&a&&!ic(a,e),u=s?await o_(a):a??o3(i,e);return[s?u:void 0,await i3(u)]}}});var sc,uc,Sa,s_,a3,s3,u3,ba,Me,br=N(()=>{"use strict";ga();uc=!1,Sa=!1,s_=!1,a3=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},s3=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},u3=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}},ba=async r=>{if(uc)return Promise.resolve();if(Sa)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(s_)throw new Error("previous call to 'initializeWebAssembly()' failed.");Sa=!0;let e=r.initTimeout,n=r.numThreads;if(r.simd!==!1){if(r.simd==="relaxed"){if(!u3())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!s3())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let t=a3();n>1&&!t&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+n+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),r.numThreads=n=1);let o=r.wasmPaths,i=typeof o=="string"?o:void 0,a=o?.mjs,s=a?.href??a,u=o?.wasm,l=u?.href??u,d=r.wasmBinary,[p,h]=await a_(s,i,n>1,!!d||!!l),g=!1,b=[];if(e>0&&b.push(new Promise(_=>{setTimeout(()=>{g=!0,_()},e)})),b.push(new Promise((_,I)=>{let w={numThreads:n};if(d)w.wasmBinary=d,w.locateFile=v=>v;else if(l||i)w.locateFile=v=>l??i+v;else if(s&&s.indexOf("blob:")!==0)w.locateFile=v=>new URL(v,s).href;else if(p){let v=r_();v&&(w.locateFile=S=>v+S)}h(w).then(v=>{Sa=!1,uc=!0,sc=v,_(),p&&URL.revokeObjectURL(p)},v=>{Sa=!1,s_=!0,I(v)})})),await Promise.race(b),g)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},Me=()=>{if(uc&&sc)return sc;throw new Error("WebAssembly is not initialized yet.")}});var Et,Vo,Oe,$a=N(()=>{"use strict";br();Et=(r,e)=>{let n=Me(),t=n.lengthBytesUTF8(r)+1,o=n._malloc(t);return n.stringToUTF8(r,o,t),e.push(o),o},Vo=(r,e,n,t)=>{if(typeof r=="object"&&r!==null){if(n.has(r))throw new Error("Circular reference in options");n.add(r)}Object.entries(r).forEach(([o,i])=>{let a=e?e+o:o;if(typeof i=="object")Vo(i,a+".",n,t);else if(typeof i=="string"||typeof i=="number")t(a,i.toString());else if(typeof i=="boolean")t(a,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},Oe=r=>{let e=Me(),n=e.stackSave();try{let t=e.PTR_SIZE,o=e.stackAlloc(2*t);e._OrtGetLastError(o,o+t);let i=Number(e.getValue(o,t===4?"i32":"i64")),a=e.getValue(o+t,"*"),s=a?e.UTF8ToString(a):"";throw new Error(`${r} ERROR_CODE: ${i}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(n)}}});var u_,l_=N(()=>{"use strict";br();$a();u_=r=>{let e=Me(),n=0,t=[],o=r||{};try{if(r?.logSeverityLevel===void 0)o.logSeverityLevel=2;else if(typeof r.logSeverityLevel!="number"||!Number.isInteger(r.logSeverityLevel)||r.logSeverityLevel<0||r.logSeverityLevel>4)throw new Error(`log severity level is not valid: ${r.logSeverityLevel}`);if(r?.logVerbosityLevel===void 0)o.logVerbosityLevel=0;else if(typeof r.logVerbosityLevel!="number"||!Number.isInteger(r.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${r.logVerbosityLevel}`);r?.terminate===void 0&&(o.terminate=!1);let i=0;return r?.tag!==void 0&&(i=Et(r.tag,t)),n=e._OrtCreateRunOptions(o.logSeverityLevel,o.logVerbosityLevel,!!o.terminate,i),n===0&&Oe("Can't create run options."),r?.extra!==void 0&&Vo(r.extra,"",new WeakSet,(a,s)=>{let u=Et(a,t),l=Et(s,t);e._OrtAddRunConfigEntry(n,u,l)!==0&&Oe(`Can't set a run config entry: ${a} - ${s}.`)}),[n,t]}catch(i){throw n!==0&&e._OrtReleaseRunOptions(n),t.forEach(a=>e._free(a)),i}}});var l3,c3,d3,uo,p3,c_,d_=N(()=>{"use strict";br();$a();l3=r=>{switch(r){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"layout":return 3;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${r}`)}},c3=r=>{switch(r){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${r}`)}},d3=r=>{r.extra||(r.extra={}),r.extra.session||(r.extra.session={});let e=r.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),r.executionProviders&&r.executionProviders.some(n=>(typeof n=="string"?n:n.name)==="webgpu")&&(r.enableMemPattern=!1)},uo=(r,e,n,t)=>{let o=Et(e,t),i=Et(n,t);Me()._OrtAddSessionConfigEntry(r,o,i)!==0&&Oe(`Can't set a session config entry: ${e} - ${n}.`)},p3=async(r,e,n)=>{let t=e.executionProviders;for(let o of t){let i=typeof o=="string"?o:o.name,a=[];switch(i){case"webnn":if(i="WEBNN",uo(r,"session.disable_quant_qdq","1",n),uo(r,"session.disable_qdq_constant_folding","1",n),typeof o!="string"){let h=o?.deviceType;h&&uo(r,"deviceType",h,n)}break;case"webgpu":if(i="JS",typeof o!="string"){let p=o;if(p?.preferredLayout){if(p.preferredLayout!=="NCHW"&&p.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${p.preferredLayout}`);uo(r,"preferredLayout",p.preferredLayout,n)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${i}`)}let s=Et(i,n),u=a.length,l=0,d=0;if(u>0){l=Me()._malloc(u*Me().PTR_SIZE),n.push(l),d=Me()._malloc(u*Me().PTR_SIZE),n.push(d);for(let p=0;p{let e=Me(),n=0,t=[],o=r||{};d3(o);try{let i=l3(o.graphOptimizationLevel??"all"),a=c3(o.executionMode??"sequential"),s=typeof o.logId=="string"?Et(o.logId,t):0,u=o.logSeverityLevel??2;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log severity level is not valid: ${u}`);let l=o.logVerbosityLevel??0;if(!Number.isInteger(l)||l<0||l>4)throw new Error(`log verbosity level is not valid: ${l}`);let d=typeof o.optimizedModelFilePath=="string"?Et(o.optimizedModelFilePath,t):0;if(n=e._OrtCreateSessionOptions(i,!!o.enableCpuMemArena,!!o.enableMemPattern,a,!!o.enableProfiling,0,s,u,l,d),n===0&&Oe("Can't create session options."),o.executionProviders&&await p3(n,o,t),o.enableGraphCapture!==void 0){if(typeof o.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${o.enableGraphCapture}`);uo(n,"enableGraphCapture",o.enableGraphCapture.toString(),t)}if(o.freeDimensionOverrides)for(let[p,h]of Object.entries(o.freeDimensionOverrides)){if(typeof p!="string")throw new Error(`free dimension override name must be a string: ${p}`);if(typeof h!="number"||!Number.isInteger(h)||h<0)throw new Error(`free dimension override value must be a non-negative integer: ${h}`);let g=Et(p,t);e._OrtAddFreeDimensionOverride(n,g,h)!==0&&Oe(`Can't set a free dimension override: ${p} - ${h}.`)}return o.extra!==void 0&&Vo(o.extra,"",new WeakSet,(p,h)=>{uo(n,p,h,t)}),[n,t]}catch(i){throw n!==0&&e._OrtReleaseSessionOptions(n)!==0&&Oe("Can't release session options."),t.forEach(a=>e._free(a)),i}}});var yr,Vn,_r,lo,Go,Aa,Oa,lc,ue=N(()=>{"use strict";yr=r=>{switch(r){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${r}`)}},Vn=r=>{switch(r){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${r}`)}},_r=(r,e)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][r],t=typeof e=="number"?e:e.reduce((o,i)=>o*i,1);return n>0?Math.ceil(t*n):void 0},lo=r=>{switch(r){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${r}`)}},Go=r=>{switch(r){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${r}`)}},Aa=r=>r==="float32"||r==="float16"||r==="int32"||r==="int64"||r==="uint32"||r==="uint8"||r==="bool"||r==="uint4"||r==="int4",Oa=r=>r==="float32"||r==="float16"||r==="int32"||r==="int64"||r==="uint32"||r==="uint64"||r==="int8"||r==="uint8"||r==="bool"||r==="uint4"||r==="int4",lc=r=>{switch(r){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${r}`)}}});var Uo,cc=N(()=>{"use strict";ma();Uo=async r=>{if(typeof r=="string")if(!1)try{let{readFile:e}=Ps("node:fs/promises");return new Uint8Array(await e(r))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=Ps("node:fs"),t=n(r),o=[];for await(let i of t)o.push(i);return new Uint8Array(Buffer.concat(o))}throw e}else{let e=await fetch(r);if(!e.ok)throw new Error(`failed to load external data file: ${r}`);let n=e.headers.get("Content-Length"),t=n?parseInt(n,10):0;if(t<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${r}, no response body.`);let o=e.body.getReader(),i;try{i=new ArrayBuffer(t)}catch(s){if(s instanceof RangeError){let u=Math.ceil(t/65536);i=new WebAssembly.Memory({initial:u,maximum:u}).buffer}else throw s}let a=0;for(;;){let{done:s,value:u}=await o.read();if(s)break;let l=u.byteLength;new Uint8Array(i,a,l).set(u),a+=l}return new Uint8Array(i,0,t)}}else return r instanceof Blob?new Uint8Array(await r.arrayBuffer()):r instanceof Uint8Array?r:new Uint8Array(r)}});var f3,h3,p_,f_,Pa,m3,me,Gn=N(()=>{"use strict";ue();f3=["V","I","W","E","F"],h3=(r,e)=>{console.log(`[${f3[r]},${new Date().toISOString()}]${e}`)},Pa=(r,e)=>{p_=r,f_=e},m3=(r,e)=>{let n=Go(r),t=Go(p_);n>=t&&h3(n,typeof e=="function"?e():e)},me=(...r)=>{f_&&m3(...r)}});var dc,Un,D,Gr,Ea,h_,m_,pe=N(()=>{"use strict";dc=class{static calcMatMulShape(e,n){return e[1]!==n[0]?void 0:[e[0],n[1]]}},Un=class{static calcShape(e,n,t=!1){let o=e.length,i=n.length;if(o===0)return n;if(i===0)return e;let a=Math.max(e.length,n.length),s=new Array(a);if(t){if(o<2||i<2)return;let u=dc.calcMatMulShape([e[o-2],e[o-1]],[n[i-2],n[i-1]]);if(u===void 0)return;[s[a-2],s[a-1]]=u}for(let u=t?3:1;u<=a;u++){let l=o-u<0?1:e[o-u],d=i-u<0?1:n[i-u];if(l!==d&&l>1&&d>1)return;let p=Math.max(l,d);if(l&&d)s[a-u]=Math.max(l,d);else{if(p>1)return;s[a-u]=0}}return s}static isValidBroadcast(e,n){let t=e.length,o=n.length;if(t>o)return!1;for(let i=1;i<=t;i++)if(e[t-i]!==1&&e[t-i]!==n[o-i])return!1;return!0}},D=class r{static size(e){return r.getSizeFromDimensionRange(e,0,e.length)}static convertShape(e,n=4){let t=e.length;if(t===0)return[];let o=new Array(t),i=t-1;for(;i>=0;){if(e[i]%n===0){o[i]=e[i]/n;break}if(n%e[i]!==0)throw new Error("cannot convert shape");o[i]=1,n/=e[i],i--}for(i--;i>=0;i--)o[i]=e[i];return o}static sizeFromDimension(e,n){if(n<0||n>e.length)throw new Error(`invalid dimension of ${n} for sizeFromDimension as Tensor has ${e.length} dimensions.`);return r.getSizeFromDimensionRange(e,n,e.length)}static sizeToDimension(e,n){if(n<0||n>e.length)throw new Error(`invalid dimension of ${n} for sizeToDimension as Tensor has ${e.length} dimensions.`);return r.getSizeFromDimensionRange(e,0,n)}static getSizeFromDimensionRange(e,n,t){let o=1;for(let i=n;i=0;--o)t[o]=t[o+1]*e[o+1];return t}static normalizeAxis(e,n){if(e<-n&&e>=n)throw new Error("unsupported axis for this operation.");return e<0?e+n:e}static normalizeAxes(e,n){return e.map(t=>this.normalizeAxis(t,n??e.length))}static sortBasedOnPerm(e,n){return n?n.map(t=>e[t]):e.slice().reverse()}static padShape(e,n){let t=e.length;return e.map((o,i)=>o+n[i]+n[i+t])}static areEqual(e,n){return e.length!==n.length?!1:e.every((t,o)=>t===n[o])}},Gr=class r{static adjustPoolAttributes(e,n,t,o,i,a){if(!e&&t.length!==n.length-2)throw new Error("length of specified kernel shapes should be 2 less than length of input dimensions");if(e)for(let s=0;s=t.length?t.push(n[s+2]):t[s]=n[s+2];for(let s=0;s=t[s]||a[s+t.length]>=t[s])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(e,n,t,o,i,a,s){if(s){if(i.length!==2*(e.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(n.length!==e.length-2)throw new Error("length of strides should be the length of data dimensions");if(o.length!==e.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let u=0;u{"use strict";ue();Ca=(r,e)=>new(lo(e))(r)});var b_,hc,y_,g3,g_,b3,__,Da,ka,fc,w_,v_=N(()=>{"use strict";ue();Gn();b_=new Map([["float32",32],["float16",16],["int32",32],["uint32",32],["int64",64],["uint64",64],["int8",8],["uint8",8],["int4",4],["uint4",4]]),hc=(r,e)=>{if(e==="int32")return r;let n=b_.get(e);if(!n)throw new Error(`WebNN backend does not support data type: ${e}`);let t=n/8;if(r.byteLength%t!==0)throw new Error(`Invalid Uint8Array length - must be a multiple of ${t}.`);let o=r.byteLength/t,i=new(lo(e))(r.buffer,r.byteOffset,o);switch(e){case"int64":case"uint64":{let a=new Int32Array(o);for(let s=0;s2147483647n||u<-2147483648n)throw new Error("Can not convert int64 data to int32 - value out of range.");a[s]=Number(u)}return new Uint8Array(a.buffer)}case"int8":case"uint8":case"uint32":{if(e==="uint32"&&i.some(s=>s>2147483647))throw new Error("Can not convert uint32 data to int32 - value out of range.");let a=Int32Array.from(i,Number);return new Uint8Array(a.buffer)}default:throw new Error(`Unsupported data conversion from ${e} to 'int32'`)}},y_=(r,e)=>{if(e==="int32")return r;if(r.byteLength%4!==0)throw new Error("Invalid Uint8Array length - must be a multiple of 4 (int32).");let n=r.byteLength/4,t=new Int32Array(r.buffer,r.byteOffset,n);switch(e){case"int64":{let o=BigInt64Array.from(t,BigInt);return new Uint8Array(o.buffer)}case"uint64":{if(t.some(i=>i<0))throw new Error("Can not convert int32 data to uin64 - negative value found.");let o=BigUint64Array.from(t,BigInt);return new Uint8Array(o.buffer)}case"int8":{if(t.some(i=>i<-128||i>127))throw new Error("Can not convert int32 data to int8 - value out of range.");let o=Int8Array.from(t,Number);return new Uint8Array(o.buffer)}case"uint8":{if(t.some(o=>o<0||o>255))throw new Error("Can not convert int32 data to uint8 - value out of range.");return Uint8Array.from(t,Number)}case"uint32":{if(t.some(i=>i<0))throw new Error("Can not convert int32 data to uint32 - negative value found.");let o=Uint32Array.from(t,Number);return new Uint8Array(o.buffer)}default:throw new Error(`Unsupported data conversion from 'int32' to ${e}`)}},g3=1,g_=()=>g3++,b3=new Map([["int8","int32"],["uint8","int32"],["uint32","int32"],["int64","int32"]]),__=(r,e)=>{let n=b_.get(r);if(!n)throw new Error(`WebNN backend does not support data type: ${r}`);return e.length>0?Math.ceil(e.reduce((t,o)=>t*o)*n/8):0},Da=class{constructor(e){this.isDataConverted=!1;let{sessionId:n,context:t,tensor:o,dataType:i,shape:a,fallbackDataType:s}=e;this.sessionId=n,this.mlContext=t,this.mlTensor=o,this.dataType=i,this.tensorShape=a,this.fallbackDataType=s}get tensor(){return this.mlTensor}get type(){return this.dataType}get fallbackType(){return this.fallbackDataType}get shape(){return this.tensorShape}get byteLength(){return __(this.dataType,this.tensorShape)}destroy(){me("verbose",()=>"[WebNN] TensorWrapper.destroy"),this.mlTensor.destroy()}write(e){this.mlContext.writeTensor(this.mlTensor,e)}async read(e){if(this.fallbackDataType){let n=await this.mlContext.readTensor(this.mlTensor),t=y_(new Uint8Array(n),this.dataType);if(e){(e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)).set(t);return}else return t.buffer}else return e?this.mlContext.readTensor(this.mlTensor,e):this.mlContext.readTensor(this.mlTensor)}canReuseTensor(e,n,t){return this.mlContext===e&&this.dataType===n&&this.tensorShape.length===t.length&&this.tensorShape.every((o,i)=>o===t[i])}setIsDataConverted(e){this.isDataConverted=e}},ka=class{constructor(e,n){this.tensorManager=e;this.wrapper=n}get tensorWrapper(){return this.wrapper}releaseTensor(){this.tensorWrapper&&(this.tensorManager.releaseTensor(this.tensorWrapper),this.wrapper=void 0)}async ensureTensor(e,n,t,o){let i=this.tensorManager.getMLContext(e),a=this.tensorManager.getMLOpSupportLimits(e),s;if(!a?.input.dataTypes.includes(n)){if(s=b3.get(n),!s||a?.input.dataTypes.includes(s))throw new Error(`WebNN backend does not support data type: ${n}`);me("verbose",()=>`[WebNN] TensorIdTracker.ensureTensor: fallback dataType from ${n} to ${s}`)}if(this.wrapper){if(this.wrapper.canReuseTensor(i,n,t))return this.wrapper.tensor;if(o){if(this.wrapper.byteLength!==__(n,t))throw new Error("Unable to copy data to tensor with different size.");this.activeUpload=new Uint8Array(await this.wrapper.read())}this.tensorManager.releaseTensor(this.wrapper)}let u=typeof MLTensorUsage>"u"?void 0:MLTensorUsage.READ|MLTensorUsage.WRITE;return this.wrapper=await this.tensorManager.getCachedTensor(e,n,t,u,!0,!0,s),o&&this.activeUpload&&(this.wrapper.write(this.activeUpload),this.activeUpload=void 0),this.wrapper.tensor}upload(e){let n=e;if(this.wrapper){if(this.wrapper.fallbackType)if(this.wrapper.fallbackType==="int32")n=hc(e,this.wrapper.type),this.wrapper.setIsDataConverted(!0);else throw new Error(`Unsupported fallback data type: ${this.wrapper.fallbackType}`);if(e.byteLength===this.wrapper.byteLength){this.wrapper.write(n);return}else me("verbose",()=>"Data size does not match tensor size. Releasing tensor."),this.releaseTensor()}this.activeUpload?this.activeUpload.set(n):this.activeUpload=new Uint8Array(n)}async download(e){if(this.activeUpload){let n=this.wrapper?.isDataConverted?y_(this.activeUpload,this.wrapper?.type):this.activeUpload;if(e){e instanceof ArrayBuffer?new Uint8Array(e).set(n):new Uint8Array(e.buffer,e.byteOffset,e.byteLength).set(n);return}else return n.buffer}if(!this.wrapper)throw new Error("Tensor has not been created.");return e?this.wrapper.read(e):this.wrapper.read()}},fc=class{constructor(e){this.backend=e;this.tensorTrackersById=new Map;this.freeTensors=[];this.externalTensors=new Set}getMLContext(e){let n=this.backend.getMLContext(e);if(!n)throw new Error("MLContext not found for session.");return n}getMLOpSupportLimits(e){return this.backend.getMLOpSupportLimits(e)}reserveTensorId(){let e=g_();return this.tensorTrackersById.set(e,new ka(this)),e}releaseTensorId(e){let n=this.tensorTrackersById.get(e);n&&(this.tensorTrackersById.delete(e),n.tensorWrapper&&this.releaseTensor(n.tensorWrapper))}async ensureTensor(e,n,t,o,i){me("verbose",()=>`[WebNN] TensorManager.ensureTensor {tensorId: ${n}, dataType: ${t}, shape: ${o}, copyOld: ${i}}`);let a=this.tensorTrackersById.get(n);if(!a)throw new Error("Tensor not found.");return a.ensureTensor(e,t,o,i)}upload(e,n){let t=this.tensorTrackersById.get(e);if(!t)throw new Error("Tensor not found.");t.upload(n)}async download(e,n){me("verbose",()=>`[WebNN] TensorManager.download {tensorId: ${e}, dstBuffer: ${n?.byteLength}}`);let t=this.tensorTrackersById.get(e);if(!t)throw new Error("Tensor not found.");return t.download(n)}releaseTensorsForSession(e){for(let n of this.freeTensors)n.sessionId===e&&n.destroy();this.freeTensors=this.freeTensors.filter(n=>n.sessionId!==e)}registerTensor(e,n,t,o){let i=this.getMLContext(e),a=g_(),s=new Da({sessionId:e,context:i,tensor:n,dataType:t,shape:o});return this.tensorTrackersById.set(a,new ka(this,s)),this.externalTensors.add(s),a}async getCachedTensor(e,n,t,o,i,a,s){let u=this.getMLContext(e);for(let[d,p]of this.freeTensors.entries())if(p.canReuseTensor(u,n,t)){me("verbose",()=>`[WebNN] Reusing tensor {dataType: ${n}, ${s?`fallbackDataType: ${s},`:""} shape: ${t}`);let h=this.freeTensors.splice(d,1)[0];return h.sessionId=e,h}me("verbose",()=>`[WebNN] MLContext.createTensor {dataType: ${n}, ${s?`fallbackDataType: ${s},`:""} shape: ${t}}`);let l=await u.createTensor({dataType:s??n,shape:t,dimensions:t,usage:o,writable:i,readable:a});return new Da({sessionId:e,context:u,tensor:l,dataType:n,shape:t,fallbackDataType:s})}releaseTensor(e){this.externalTensors.has(e)&&this.externalTensors.delete(e),this.freeTensors.push(e)}},w_=(...r)=>new fc(...r)});var Na,y3,La,x_=N(()=>{"use strict";ue();br();pc();v_();Gn();Na=new Map([[1,"float32"],[10,"float16"],[6,"int32"],[12,"uint32"],[7,"int64"],[13,"uint64"],[22,"int4"],[21,"uint4"],[3,"int8"],[2,"uint8"],[9,"uint8"]]),y3=(r,e)=>{if(r===e)return!0;if(r===void 0||e===void 0)return!1;let n=Object.keys(r).sort(),t=Object.keys(e).sort();return n.length===t.length&&n.every((o,i)=>o===t[i]&&r[o]===e[o])},La=class{constructor(e){this.tensorManager=w_(this);this.mlContextBySessionId=new Map;this.sessionIdsByMLContext=new Map;this.mlContextCache=[];this.sessionGraphInputs=new Map;this.sessionGraphOutputs=new Map;this.temporaryGraphInputs=[];this.temporaryGraphOutputs=[];this.temporarySessionTensorIds=new Map;this.mlOpSupportLimitsBySessionId=new Map;Pa(e.logLevel,!!e.debug)}get currentSessionId(){if(this.activeSessionId===void 0)throw new Error("No active session");return this.activeSessionId}onRunStart(e){me("verbose",()=>`[WebNN] onRunStart {sessionId: ${e}}`),this.activeSessionId=e}onRunEnd(e){me("verbose",()=>`[WebNN] onRunEnd {sessionId: ${e}}`);let n=this.temporarySessionTensorIds.get(e);if(n){for(let t of n)me("verbose",()=>`[WebNN] releasing temporary tensor {tensorId: ${t}}`),this.tensorManager.releaseTensorId(t);this.temporarySessionTensorIds.delete(e),this.activeSessionId=void 0}}async createMLContext(e){if(e instanceof GPUDevice){let t=this.mlContextCache.findIndex(o=>o.gpuDevice===e);if(t!==-1)return this.mlContextCache[t].mlContext;{let o=await navigator.ml.createContext(e);return this.mlContextCache.push({gpuDevice:e,mlContext:o}),o}}else if(e===void 0){let t=this.mlContextCache.findIndex(o=>o.options===void 0&&o.gpuDevice===void 0);if(t!==-1)return this.mlContextCache[t].mlContext;{let o=await navigator.ml.createContext();return this.mlContextCache.push({mlContext:o}),o}}let n=this.mlContextCache.findIndex(t=>y3(t.options,e));if(n!==-1)return this.mlContextCache[n].mlContext;{let t=await navigator.ml.createContext(e);return this.mlContextCache.push({options:e,mlContext:t}),t}}registerMLContext(e,n){this.mlContextBySessionId.set(e,n);let t=this.sessionIdsByMLContext.get(n);t||(t=new Set,this.sessionIdsByMLContext.set(n,t)),t.add(e),this.mlOpSupportLimitsBySessionId.has(e)||this.mlOpSupportLimitsBySessionId.set(e,n.opSupportLimits()),this.temporaryGraphInputs.length>0&&(this.sessionGraphInputs.set(e,this.temporaryGraphInputs),this.temporaryGraphInputs=[]),this.temporaryGraphOutputs.length>0&&(this.sessionGraphOutputs.set(e,this.temporaryGraphOutputs),this.temporaryGraphOutputs=[])}onReleaseSession(e){this.sessionGraphInputs.delete(e),this.sessionGraphOutputs.delete(e);let n=this.mlContextBySessionId.get(e);if(!n)return;this.tensorManager.releaseTensorsForSession(e),this.mlContextBySessionId.delete(e),this.mlOpSupportLimitsBySessionId.delete(e);let t=this.sessionIdsByMLContext.get(n);if(t.delete(e),t.size===0){this.sessionIdsByMLContext.delete(n);let o=this.mlContextCache.findIndex(i=>i.mlContext===n);o!==-1&&this.mlContextCache.splice(o,1)}}getMLContext(e){return this.mlContextBySessionId.get(e)}getMLOpSupportLimits(e){return this.mlOpSupportLimitsBySessionId.get(e)}reserveTensorId(){return this.tensorManager.reserveTensorId()}releaseTensorId(e){me("verbose",()=>`[WebNN] releaseTensorId {tensorId: ${e}}`),this.tensorManager.releaseTensorId(e)}async ensureTensor(e,n,t,o,i){let a=Na.get(t);if(!a)throw new Error(`Unsupported ONNX data type: ${t}`);return this.tensorManager.ensureTensor(e??this.currentSessionId,n,a,o,i)}async createTemporaryTensor(e,n,t){me("verbose",()=>`[WebNN] createTemporaryTensor {onnxDataType: ${n}, shape: ${t}}`);let o=Na.get(n);if(!o)throw new Error(`Unsupported ONNX data type: ${n}`);let i=this.tensorManager.reserveTensorId();await this.tensorManager.ensureTensor(e,i,o,t,!1);let a=this.temporarySessionTensorIds.get(e);return a?a.push(i):this.temporarySessionTensorIds.set(e,[i]),i}uploadTensor(e,n){if(!Me().shouldTransferToMLTensor)throw new Error("Trying to upload to a MLTensor while shouldTransferToMLTensor is false");me("verbose",()=>`[WebNN] uploadTensor {tensorId: ${e}, data: ${n.byteLength}}`),this.tensorManager.upload(e,n)}async downloadTensor(e,n){return this.tensorManager.download(e,n)}createMLTensorDownloader(e,n){return async()=>{let t=await this.tensorManager.download(e);return Ca(t,n)}}registerMLTensor(e,n,t,o){let i=Na.get(t);if(!i)throw new Error(`Unsupported ONNX data type: ${t}`);let a=this.tensorManager.registerTensor(e,n,i,o);return me("verbose",()=>`[WebNN] registerMLTensor {tensor: ${n}, dataType: ${i}, dimensions: ${o}} -> {tensorId: ${a}}`),a}registerMLConstant(e,n,t,o,i,a,s=!1){if(!a)throw new Error("External mounted files are not available.");let u=e;e.startsWith("./")&&(u=e.substring(2));let l=a.get(u);if(!l)throw new Error(`File with name ${u} not found in preloaded files.`);if(n+t>l.byteLength)throw new Error("Out of bounds: data offset and length exceed the external file data size.");let d=l.slice(n,n+t).buffer,p;switch(i.dataType){case"float32":p=new Float32Array(d);break;case"float16":p=typeof Float16Array<"u"&&Float16Array.from?new Float16Array(d):new Uint16Array(d);break;case"int32":p=new Int32Array(d);break;case"uint32":p=new Uint32Array(d);break;case"int64":if(s){let h=hc(new Uint8Array(d),"int64");p=new Int32Array(h.buffer),i.dataType="int32"}else p=new BigInt64Array(d);break;case"uint64":p=new BigUint64Array(d);break;case"int8":p=new Int8Array(d);break;case"int4":case"uint4":case"uint8":p=new Uint8Array(d);break;default:throw new Error(`Unsupported data type: ${i.dataType} in creating WebNN Constant from external data.`)}return me("verbose",()=>`[WebNN] registerMLConstant {dataType: ${i.dataType}, shape: ${i.shape}}} ${s?"(Note: it was int64 data type and registered to int32 as workaround)":""}`),o.constant(i,p)}registerGraphInput(e){this.temporaryGraphInputs.push(e)}registerGraphOutput(e){this.temporaryGraphOutputs.push(e)}isGraphInput(e,n){let t=this.sessionGraphInputs.get(e);return t?t.includes(n):!1}isGraphOutput(e,n){let t=this.sessionGraphOutputs.get(e);return t?t.includes(n):!1}isGraphInputOutputTypeSupported(e,n,t=!0){let o=Na.get(yr(n)),i=this.mlOpSupportLimitsBySessionId.get(e);return typeof o>"u"?!1:t?!!i?.input.dataTypes.includes(o):!!i?.output.dataTypes.includes(o)}flush(){}}});var Ra=N(()=>{"use strict"});var T_,mc,gc,_3,w3,I_,yc,bc,$_,A_=N(()=>{"use strict";Gn();Ra();T_=new Map([[64,250],[128,200],[256,200],[512,200],[2048,230],[4096,200],[8192,50],[16384,50],[32768,50],[65536,50],[131072,50],[262144,50],[524288,50],[1048576,50],[2097152,30],[4194304,20],[8388608,10],[12582912,10],[16777216,10],[26214400,15],[33554432,22],[44236800,2],[58982400,6],[67108864,6],[134217728,6],[167772160,6]]),mc=[],gc=r=>Math.ceil(Number(r)/16)*16,_3=r=>{for(let e=0;ew3++,yc=async(r,e,n,t)=>{let o=gc(n),i=r.device.createBuffer({size:o,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});try{let a=r.getCommandEncoder();r.endComputePass(),a.copyBufferToBuffer(e,0,i,0,o),r.flush(),await i.mapAsync(GPUMapMode.READ);let s=i.getMappedRange();if(t){let u=t();return u.set(new Uint8Array(s,0,n)),u}else return new Uint8Array(s.slice(0,n))}finally{i.destroy()}},bc=class{constructor(e){this.backend=e;this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.buffersPending=[],this.capturedPendingBuffers=new Map;for(let[n]of T_)mc.push(n),this.freeBuffers.set(n,[]),this.freeUniformBuffers.set(n,[]);this.sessionCount=0}upload(e,n){let t=n.buffer,o=n.byteOffset,i=n.byteLength,a=gc(i),s=this.storageCache.get(e);if(!s)throw new Error("gpu data for uploading does not exist");if(Number(s.originalSize)!==i)throw new Error(`inconsistent data size. gpu data size=${s.originalSize}, data size=${i}`);let u=this.backend.device.createBuffer({mappedAtCreation:!0,size:a,usage:GPUBufferUsage.MAP_WRITE|GPUBufferUsage.COPY_SRC}),l=u.getMappedRange();new Uint8Array(l).set(new Uint8Array(t,o,i)),u.unmap();let d=this.backend.device.createCommandEncoder();d.copyBufferToBuffer(u,0,s.gpuData.buffer,0,a),this.backend.device.queue.submit([d.finish()]),u.destroy(),me("verbose",()=>`[WebGPU] GpuDataManager.upload(id=${e})`)}memcpy(e,n){let t=this.storageCache.get(e);if(!t)throw new Error("source gpu data for memcpy does not exist");let o=this.storageCache.get(n);if(!o)throw new Error("destination gpu data for memcpy does not exist");if(t.originalSize!==o.originalSize)throw new Error("inconsistent source and destination gpu data size");let i=gc(t.originalSize),a=this.backend.getCommandEncoder();this.backend.endComputePass(),a.copyBufferToBuffer(t.gpuData.buffer,0,o.gpuData.buffer,0,i)}registerExternalBuffer(e,n,t){let o;if(t){if(o=t[0],e===t[1])return me("verbose",()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${n}) => id=${o}, buffer is the same, skip.`),o;if(this.backend.capturedCommandList.has(this.backend.currentSessionId))throw new Error(`Registering a different external buffer under graph capture mode is not supported yet. Please use the previous external buffer!`)}else o=I_();return this.storageCache.set(o,{gpuData:{id:o,type:0,buffer:e},originalSize:n}),me("verbose",()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${n}) => id=${o}, registered.`),o}unregisterExternalBuffer(e){e!==void 0&&(this.storageCache.delete(e),me("verbose",()=>`[WebGPU] GpuDataManager.unregisterExternalBuffer() => id=${e}`))}create(e,n=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST){let t=_3(e),o,i=(n&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE,a=(n&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM;if(i||a){let l=(i?this.freeBuffers:this.freeUniformBuffers).get(t);l?l.length>0?o=l.pop():o=this.backend.device.createBuffer({size:t,usage:n}):o=this.backend.device.createBuffer({size:t,usage:n})}else o=this.backend.device.createBuffer({size:t,usage:n});let s={id:I_(),type:0,buffer:o};return this.storageCache.set(s.id,{gpuData:s,originalSize:Number(e)}),me("verbose",()=>`[WebGPU] GpuDataManager.create(size=${e}) => id=${s.id}`),s}get(e){return this.storageCache.get(e)?.gpuData}release(e){let n=typeof e=="bigint"?Number(e):e,t=this.storageCache.get(n);if(!t){if(this.storageCache.size===0)return 0;throw new Error("releasing data does not exist")}return me("verbose",()=>`[WebGPU] GpuDataManager.release(id=${n}), gpuDataId=${t.gpuData.id}`),this.storageCache.delete(n),this.buffersPending.push(t.gpuData.buffer),t.originalSize}async download(e,n){let t=this.storageCache.get(Number(e));if(!t)throw new Error("data does not exist");await yc(this.backend,t.gpuData.buffer,t.originalSize,n)}refreshPendingBuffers(){if(this.buffersPending.length!==0)if(this.backend.sessionStatus==="default"){for(let e of this.buffersPending){let n=T_.get(e.size);if((e.usage&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE){let t=this.freeBuffers.get(e.size)||[];n===void 0||t.length>=n?e.destroy():t.push(e)}else if((e.usage&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM){let t=this.freeUniformBuffers.get(e.size)||[];n===void 0||t.length>=n?e.destroy():t.push(e)}else e.destroy()}this.buffersPending=[]}else{let e=this.capturedPendingBuffers.get(this.backend.currentSessionId);e||(e=[],this.capturedPendingBuffers.set(this.backend.currentSessionId,e));for(let n of this.buffersPending)e.push(n);this.buffersPending=[]}}dispose(){this.freeBuffers.forEach(e=>{e.forEach(n=>{n.destroy()})}),this.freeUniformBuffers.forEach(e=>{e.forEach(n=>{n.destroy()})}),this.storageCache.forEach(e=>{e.gpuData.buffer.destroy()}),this.capturedPendingBuffers.forEach(e=>{e.forEach(n=>{n.destroy()})}),this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.capturedPendingBuffers=new Map}onCreateSession(){this.sessionCount+=1}onReleaseSession(e){let n=this.capturedPendingBuffers.get(e);n&&(n.forEach(t=>{t.destroy()}),this.capturedPendingBuffers.delete(e)),this.sessionCount-=1,this.sessionCount===0&&(me("warning",()=>"[WebGPU] Clearing webgpu buffer cache"),this.storageCache.forEach(t=>{t.gpuData.buffer.destroy()}),this.storageCache=new Map)}},$_=(...r)=>new bc(...r)});var _c,le,Ye=N(()=>{"use strict";_c=class{constructor(e){Object.assign(this,e)}get cacheKey(){return this.key||(this.key=Object.getOwnPropertyNames(this).sort().map(e=>`${this[e]}`).join(";")),this.key}},le=r=>new _c(r)});var Ur,vc,Fe,ut,W,Pe,xc,Wr,Zt,Q,za,L,V,O_,Ma,wc,P_,he=N(()=>{"use strict";ue();pe();Ur=64,vc=(r,e)=>{if(e===3)throw new Error("vec3 has same alignment as vec4, use vec4 instead");switch(Number(r)){case 10:return e>1?`vec${e}`:"f16";case 1:return e>1?`vec${e}`:"f32";case 6:return e>1?`vec${e}`:"i32";case 12:return e>1?`vec${e}`:"u32";case 7:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2","i32"];case 13:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2","u32"];case 9:if(e!==4)throw new Error("bool must be vec4");return["u32","vec4"];case 22:return"i32";case 21:return"u32";default:throw new Error(`Unknown data type: ${r}`)}},Fe=(r,e=1)=>{let n=vc(r,e);return typeof n=="string"?n:n[0]},ut=(r,e=1)=>{let n=vc(r,e);return typeof n=="string"?n:n[1]},W=(...r)=>{let e=[];return r.forEach(n=>{n.length!==0&&e.push({type:12,data:n},{type:12,data:D.computeStrides(n)})}),e},Pe=r=>r%4===0?4:r%2===0?2:1,xc=(r="f32",e,n="0")=>!e||e===1?`${r}(${n})`:`vec${e}<${r}>(${n})`,Wr=(r,e,n)=>r==="f32"?n:e===1?`f32(${n})`:`vec${e}(${n})`,Zt=(r,e)=>e===4?`(${r}.x + ${r}.y + ${r}.z + ${r}.w)`:e===2?`(${r}.x + ${r}.y)`:e===3?`(${r}.x + ${r}.y + ${r}.z)`:r,Q=(r,e,n,t)=>r.startsWith("uniforms.")&&n>4?typeof e=="string"?t==="f16"?`${r}[(${e}) / 8][(${e}) % 8 / 4][(${e}) % 8 % 4]`:`${r}[(${e}) / 4][(${e}) % 4]`:t==="f16"?`${r}[${Math.floor(e/8)}][${Math.floor(e%8/4)}][${e%8%4}]`:`${r}[${Math.floor(e/4)}][${e%4}]`:n>1?`${r}[${e}]`:r,za=(r,e,n,t,o)=>{let i=typeof n=="number",a=i?n:n.length,s=[...new Array(a).keys()],u=a<2?"u32":a<=4?`vec${a}`:`array`,l=vc(e,o),d=typeof l=="string"?l:l[1],p=typeof l=="string"?l:l[0],h={indices:u,value:d,storage:p,tensor:e},g=F=>typeof F=="string"?F:`${F}u`,b={offsetToIndices:!1,indicesToOffset:!1,broadcastedIndicesToOffset:!1,set:!1,setByIndices:!1,get:!1,getByIndices:!1},_=i?"uniforms.":"",I=`${_}${r}_shape`,w=`${_}${r}_strides`,v="";for(let F=0;F ${h.indices} { var indices: ${h.indices}; var current = offset; ${v} return indices; }`,A=F=>(b.offsetToIndices=!0,a<2?F:`o2i_${r}(${F})`),P=[];if(a>=2)for(let F=a-1;F>=0;F--)P.push(`${Q(w,F,a)} * (indices[${F}])`);let C=a<2?"":` fn i2o_${r}(indices: ${h.indices}) -> u32 { return ${P.join("+")}; }`,R=F=>(b.indicesToOffset=!0,a<2?F:`i2o_${r}(${F})`),x=(...F)=>a===0?"0u":`${h.indices}(${F.map(g).join(",")})`,B=(F,q)=>a<2?`${F}`:`${Q(F,q,a)}`,G=(F,q,Ne)=>a<2?`${F}=${Ne};`:`${Q(F,q,a)}=${Ne};`,Z={},J=(F,q)=>{b.broadcastedIndicesToOffset=!0;let Ne=`${q.name}broadcastedIndicesTo${r}Offset`;if(Ne in Z)return`${Ne}(${F})`;let rt=[];for(let Ge=a-1;Ge>=0;Ge--){let at=q.indicesGet("outputIndices",Ge+q.rank-a);rt.push(`${B(w,Ge)} * (${at} % ${B(I,Ge)})`)}return Z[Ne]=`fn ${Ne}(outputIndices: ${q.type.indices}) -> u32 { return ${rt.length>0?rt.join("+"):"0u"}; }`,`${Ne}(${F})`},ie=(F,q)=>(()=>{if(h.storage===h.value)return`${r}[${F}]=${q};`;if(h.storage==="vec2"&&h.value==="i32")return`${r}[${F}]=vec2(u32(${q}), select(0u, 0xFFFFFFFFu, ${q} < 0));`;if(h.storage==="vec2"&&h.value==="u32")return`${r}[${F}]=vec2(u32(${q}), 0u);`;if(h.storage==="u32"&&h.value==="vec4")return`${r}[${F}]=dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(${q}));`;throw new Error(`not supported combination of storage type ${h.storage} and value type ${h.value} yet`)})(),z=F=>(()=>{if(h.storage===h.value)return`${r}[${F}]`;if(h.storage==="vec2"&&h.value==="i32")return`i32(${r}[${F}].x)`;if(h.storage==="vec2"&&h.value==="u32")return`u32(${r}[${F}].x)`;if(h.storage==="u32"&&h.value==="vec4")return`vec4(bool(${r}[${F}] & 0xFFu), bool(${r}[${F}] & 0xFF00u), bool(${r}[${F}] & 0xFF0000u), bool(${r}[${F}] & 0xFF000000u))`;throw new Error(`not supported combination of storage type ${h.storage} and value type ${h.value} yet`)})(),U=a<2?"":` fn get_${r}ByIndices(indices: ${h.indices}) -> ${d} { return ${z(`i2o_${r}(indices)`)}; }`,te=a<2?"":(()=>{let F=s.map(Ne=>`d${Ne}: u32`).join(", "),q=s.map(Ne=>`d${Ne}`).join(", ");return` fn get_${r}(${F}) -> ${d} { return get_${r}ByIndices(${x(q)}); }`})(),oe=(...F)=>{if(F.length!==a)throw new Error(`indices length must be ${a}`);let q=F.map(g).join(",");return a===0?z("0u"):a===1?z(q[0]):(b.get=!0,b.getByIndices=!0,b.indicesToOffset=!0,`get_${r}(${q})`)},ee=F=>a<2?z(F):(b.getByIndices=!0,b.indicesToOffset=!0,`get_${r}ByIndices(${F})`),de=a<2?"":` fn set_${r}ByIndices(indices: ${h.indices}, value: ${d}) { ${ie(`i2o_${r}(indices)`,"value")} }`,ge=a<2?"":(()=>{let F=s.map(Ne=>`d${Ne}: u32`).join(", "),q=s.map(Ne=>`d${Ne}`).join(", ");return` fn set_${r}(${F}, value: ${d}) { set_${r}ByIndices(${x(q)}, value); }`})();return{impl:()=>{let F=[],q=!1;return b.offsetToIndices&&(F.push(S),q=!0),b.indicesToOffset&&(F.push(C),q=!0),b.broadcastedIndicesToOffset&&(Object.values(Z).forEach(Ne=>F.push(Ne)),q=!0),b.set&&(F.push(ge),q=!0),b.setByIndices&&(F.push(de),q=!0),b.get&&(F.push(te),q=!0),b.getByIndices&&(F.push(U),q=!0),!i&&q&&F.unshift(`const ${I} = ${h.indices}(${n.join(",")});`,`const ${w} = ${h.indices}(${D.computeStrides(n).join(",")});`),F.join(` `)},type:h,offsetToIndices:A,indicesToOffset:R,broadcastedIndicesToOffset:J,indices:x,indicesGet:B,indicesSet:G,set:(...F)=>{if(F.length!==a+1)throw new Error(`indices length must be ${a}`);let q=F[a];if(typeof q!="string")throw new Error("value must be string");let Ne=F.slice(0,a).map(g).join(",");return a===0?ie("0u",q):a===1?ie(Ne[0],q):(b.set=!0,b.setByIndices=!0,b.indicesToOffset=!0,`set_${r}(${Ne}, ${q})`)},setByOffset:ie,setByIndices:(F,q)=>a<2?ie(F,q):(b.setByIndices=!0,b.indicesToOffset=!0,`set_${r}ByIndices(${F}, ${q});`),get:oe,getByOffset:z,getByIndices:ee,usage:t,name:r,strides:w,shape:I,rank:a}},L=(r,e,n,t=1)=>za(r,e,n,"input",t),V=(r,e,n,t=1)=>za(r,e,n,"output",t),O_=(r,e,n)=>za(r,e,n,"atomicOutput",1),Ma=(r,e,n,t=1)=>za(r,e,n,"internal",t),wc=class{constructor(e,n){this.normalizedDispatchGroup=e;this.limits=n;this.internalVariables=[];this.variables=[];this.uniforms=[];this.variableIndex=0}guardAgainstOutOfBoundsWorkgroupSizes(e){return`if (global_idx >= ${typeof e=="number"?`${e}u`:e}) { return; }`}mainStart(e=Ur){let n=typeof e=="number"?e:e[0],t=typeof e=="number"?1:e[1],o=typeof e=="number"?1:e[2];if(n>this.limits.maxComputeWorkgroupSizeX||t>this.limits.maxComputeWorkgroupSizeY||o>this.limits.maxComputeWorkgroupSizeZ)throw new Error(`workgroup size [${n}, ${t}, ${o}] exceeds the maximum workgroup size [${this.limits.maxComputeWorkgroupSizeX}, ${this.limits.maxComputeWorkgroupSizeY}, ${this.limits.maxComputeWorkgroupSizeZ}].`);if(n*t*o>this.limits.maxComputeInvocationsPerWorkgroup)throw new Error(`workgroup size [${n}, ${t}, ${o}] exceeds the maximum workgroup invocations ${this.limits.maxComputeInvocationsPerWorkgroup}.`);let i=this.normalizedDispatchGroup[1]===1&&this.normalizedDispatchGroup[2]===1,a=i?`@builtin(global_invocation_id) global_id : vec3, @builtin(workgroup_id) workgroup_id : vec3, @builtin(local_invocation_index) local_idx : u32, @builtin(local_invocation_id) local_id : vec3`:`@builtin(global_invocation_id) global_id : vec3, @builtin(local_invocation_id) local_id : vec3, @builtin(local_invocation_index) local_idx : u32, @builtin(workgroup_id) workgroup_id : vec3, @builtin(num_workgroups) num_workgroups : vec3`,s=i?`let global_idx = global_id.x; let workgroup_index = workgroup_id.x;`:`let workgroup_index = workgroup_id.z * num_workgroups[0] * num_workgroups[1] + workgroup_id.y * num_workgroups[0] + workgroup_id.x; let global_idx = workgroup_index * ${n*t*o}u + local_idx;`;return`@compute @workgroup_size(${n}, ${t}, ${o}) fn main(${a}) { ${s} `}appendVariableUniforms(e){e.rank!==0&&(e.shape.startsWith("uniforms.")&&this.uniforms.push({name:e.shape.replace("uniforms.",""),type:"u32",length:e.rank}),e.strides.startsWith("uniforms.")&&this.uniforms.push({name:e.strides.replace("uniforms.",""),type:"u32",length:e.rank}))}declareVariable(e,n){if(e.usage==="internal")throw new Error("cannot use internal variable with declareVariable(). use registerInternalVariables() instead.");this.variables.push(e),this.appendVariableUniforms(e);let t=e.usage==="input"?"read":"read_write",o=e.usage==="atomicOutput"?"atomic":e.type.storage;return`@group(0) @binding(${n}) var ${e.name}: array<${o}>;`}declareVariables(...e){return e.map(n=>this.declareVariable(n,this.variableIndex++)).join(` `)}registerInternalVariable(e){if(e.usage!=="internal")throw new Error("cannot use input or output variable with registerInternalVariable(). use declareVariables() instead.");this.internalVariables.push(e),this.appendVariableUniforms(e)}registerInternalVariables(...e){return e.forEach(n=>this.registerInternalVariable(n)),this}registerUniform(e,n,t=1){return this.uniforms.push({name:e,type:n,length:t}),this}registerUniforms(e){return this.uniforms=this.uniforms.concat(e),this}uniformDeclaration(){if(this.uniforms.length===0)return"";let e=[];for(let{name:n,type:t,length:o}of this.uniforms)if(o&&o>4)t==="f16"?e.push(`@align(16) ${n}:array, ${Math.ceil(o/8)}>`):e.push(`${n}:array, ${Math.ceil(o/4)}>`);else{let i=o==null||o===1?t:`vec${o}<${t}>`;e.push(`${n}:${i}`)}return` struct Uniforms { ${e.join(", ")} }; @group(0) @binding(${this.variableIndex}) var uniforms: Uniforms;`}get additionalImplementations(){return this.uniformDeclaration()+this.variables.map(e=>e.impl()).join(` `)+this.internalVariables.map(e=>e.impl()).join(` `)}get variablesInfo(){if(this.uniforms.length===0)return;let e=n=>[12,10,1,6][["u32","f16","f32","i32"].indexOf(n)];return this.uniforms.map(n=>[e(n.type),n.length??1])}},P_=(r,e)=>new wc(r,e)});var v3,E_,x3,T3,I3,S3,lt,C_,D_,Qn=N(()=>{"use strict";ue();pe();Ye();he();v3=(r,e)=>{if(!r||r.length!==1)throw new Error("Transpose requires 1 input.");if(e.length!==0&&e.length!==r[0].dims.length)throw new Error(`perm size ${e.length} does not match input rank ${r[0].dims.length}`)},E_=(r,e)=>e.length!==0?e:[...new Array(r).keys()].reverse(),x3=(r,e)=>D.sortBasedOnPerm(r,E_(r.length,e)),T3=(r,e,n,t)=>{let o=`fn perm(i: ${t.type.indices}) -> ${n.type.indices} { var a: ${n.type.indices};`;for(let i=0;i{let n=[],t=[];for(let o=0;o{let n=0;for(let t=0;t{let n=r.dataType,t=r.dims.length,o=E_(t,e),i=x3(r.dims,o),a=r.dims,s=i,u=t<2||S3(o,r.dims),l;if(u)return l=_=>{let I=L("input",n,a,4),w=V("output",n,s,4);return` ${_.registerUniform("output_size","u32").declareVariables(I,w)} ${_.mainStart()} ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} output[global_idx] = input[global_idx]; }`},{name:"TransposeCopy",shaderCache:{inputDependencies:["type"]},getRunData:()=>{let _=D.size(i);return{outputs:[{dims:i,dataType:r.dataType}],dispatchGroup:{x:Math.ceil(_/64/4)},programUniforms:[{type:12,data:Math.ceil(_/4)}]}},getShaderSource:l};let{newShape:d,newPerm:p}=I3(r.dims,o),h=D.areEqual(p,[2,3,1]),g=D.areEqual(p,[3,1,2]);if(d.length===2||h||g){a=h?[d[0],d[1]*d[2]]:g?[d[0]*d[1],d[2]]:d,s=[a[1],a[0]];let _=16;return l=I=>{let w=L("a",n,a.length),v=V("output",n,s.length);return` ${I.registerUniform("output_size","u32").declareVariables(w,v)} var tile : array, ${_}>; ${I.mainStart([_,_,1])} let stride = (uniforms.output_shape[1] - 1) / ${_} + 1; let workgroup_id_x = workgroup_index % stride; let workgroup_id_y = workgroup_index / stride; let input_col = workgroup_id_y * ${_}u + local_id.x; let input_row = workgroup_id_x * ${_}u + local_id.y; if (input_row < uniforms.a_shape[0] && input_col < uniforms.a_shape[1]) { tile[local_id.y][local_id.x] = ${w.getByIndices(`${w.type.indices}(input_row, input_col)`)}; } workgroupBarrier(); let output_col = workgroup_id_x * ${_}u + local_id.x; let output_row = workgroup_id_y * ${_}u + local_id.y; if (output_row < uniforms.output_shape[0] && output_col < uniforms.output_shape[1]) { ${v.setByIndices(`${v.type.indices}(output_row, output_col)`,"tile[local_id.x][local_id.y]")} } }`},{name:"TransposeShared",shaderCache:{inputDependencies:["type"]},getRunData:()=>{let I=D.size(i);return{outputs:[{dims:i,dataType:r.dataType}],dispatchGroup:{x:Math.ceil(s[1]/_),y:Math.ceil(s[0]/_)},programUniforms:[{type:12,data:I},...W(a,s)]}},getShaderSource:l}}return l=_=>{let I=L("a",n,a.length),w=V("output",n,s.length);return` ${_.registerUniform("output_size","u32").declareVariables(I,w)} ${T3(o,t,I,w)} ${_.mainStart()} ${_.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let indices = ${w.offsetToIndices("global_idx")}; let aIndices = perm(indices); ${w.setByOffset("global_idx",I.getByIndices("aIndices"))} }`},{name:"Transpose",shaderCache:{hint:`${e}`,inputDependencies:["rank"]},getRunData:()=>{let _=D.size(i);return{outputs:[{dims:i,dataType:r.dataType}],dispatchGroup:{x:Math.ceil(_/64)},programUniforms:[{type:12,data:_},...W(a,s)]}},getShaderSource:l}},C_=(r,e)=>{v3(r.inputs,e.perm),r.compute(lt(r.inputs[0],e.perm))},D_=r=>le({perm:r.perm})});var $3,A3,O3,P3,E3,C3,D3,k3,N3,L3,Wn,k_,N_,L_,R_,z_,M_,B_,F_,V_,G_,U_=N(()=>{"use strict";ue();pe();he();Ba();Qn();$3={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate * candidate",logSumExp:"bestValue + exp(candidate)",l1:"bestValue + abs(candidate)",l2:"bestValue + candidate * candidate",logSum:"bestValue + candidate"},A3={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate",logSumExp:"bestValue + candidate",l1:"bestValue + candidate",l2:"bestValue + candidate",logSum:"bestValue + candidate"},O3={max:"_A[offset]",min:"_A[offset]",mean:"0",sum:"0",prod:"1",sumSquare:"0",logSumExp:"0",l1:"0",l2:"0",logSum:"0"},P3={max:"bestValue",min:"bestValue",sum:"bestValue",prod:"bestValue",sumSquare:"bestValue",logSumExp:"log(bestValue)",l1:"bestValue",l2:"sqrt(bestValue)",logSum:"log(bestValue)"},E3=(r,e)=>{let n=[];for(let t=e-r;t{let n=[],t=r.length;for(let i=0;ir[i]);return[n,o]},D3=(r,e)=>{let n=r.length+e.length,t=[],o=0;for(let i=0;i{for(let n=0;n{let n=[];if(!k3(r,e)){for(let t=0;tn.push(t))}return n},L3=(r,e,n,t,o,i,a)=>{let s=n[0].dims,u=D.size(i),l=D.size(a),d=L("_A",n[0].dataType,s),p=V("output",o,i),h=64;u===1&&(h=256);let g=` var aBestValues : array; `,b=_=>` ${_.registerUniform("reduceSize","u32").declareVariables(d,p)} ${g} fn DIV_CEIL(a : u32, b : u32) -> u32 { return ((a - 1u) / b + 1u); } ${_.mainStart(h)} let outputIndex = global_idx / ${h}; let offset = outputIndex * uniforms.reduceSize; var bestValue = f32(${O3[t]}); let Length = uniforms.reduceSize; for (var k = local_idx; k < Length; k = k + ${h}) { let candidate = f32(${d.getByOffset("offset + k")}); bestValue = ${$3[t]}; } aBestValues[local_idx] = bestValue; workgroupBarrier(); var reduceSize = min(Length, ${h}u); for (var currentSize = reduceSize / 2u; reduceSize > 1u; currentSize = reduceSize / 2u) { let interval = DIV_CEIL(reduceSize, 2u); if (local_idx < currentSize) { let candidate = aBestValues[local_idx + interval]; bestValue = ${A3[t]}; aBestValues[local_idx] = bestValue; } reduceSize = interval; workgroupBarrier(); } if (local_idx == 0u) { ${p.setByOffset("outputIndex",`${t==="mean"?`${p.type.storage}(bestValue / f32(uniforms.reduceSize))`:`${p.type.storage}(${P3[t]})`}`)}; } }`;return{name:r,shaderCache:{hint:`${e};${h}`,inputDependencies:["type"]},getShaderSource:b,getRunData:()=>({outputs:[{dims:i,dataType:o}],dispatchGroup:{x:u},programUniforms:[{type:12,data:l}]})}},Wn=(r,e,n,t)=>{let o=r.inputs.length===1?n:Tc(r.inputs,n),i=o.axes;i.length===0&&!o.noopWithEmptyAxes&&(i=r.inputs[0].dims.map((g,b)=>b));let a=D.normalizeAxes(i,r.inputs[0].dims.length),s=a,u=r.inputs[0],l=N3(s,r.inputs[0].dims.length);l.length>0&&(u=r.compute(lt(r.inputs[0],l),{inputs:[0],outputs:[-1]})[0],s=E3(s.length,u.dims.length));let[d,p]=C3(u.dims,s),h=d;o.keepDims&&(h=D3(d,a)),r.compute(L3(e,o.cacheKey,[u],t,r.inputs[0].dataType,h,p),{inputs:[u]})},k_=(r,e)=>{Wn(r,"ReduceMeanShared",e,"mean")},N_=(r,e)=>{Wn(r,"ReduceL1Shared",e,"l1")},L_=(r,e)=>{Wn(r,"ReduceL2Shared",e,"l2")},R_=(r,e)=>{Wn(r,"ReduceLogSumExpShared",e,"logSumExp")},z_=(r,e)=>{Wn(r,"ReduceMaxShared",e,"max")},M_=(r,e)=>{Wn(r,"ReduceMinShared",e,"min")},B_=(r,e)=>{Wn(r,"ReduceProdShared",e,"prod")},F_=(r,e)=>{Wn(r,"ReduceSumShared",e,"sum")},V_=(r,e)=>{Wn(r,"ReduceSumSquareShared",e,"sumSquare")},G_=(r,e)=>{Wn(r,"ReduceLogSumShared",e,"logSum")}});var Hn,R3,Fa,Tc,qn,z3,M3,B3,F3,V3,G3,U3,W3,H3,q3,jn,W_,H_,q_,j_,K_,X_,Z_,J_,Y_,Q_,Ba=N(()=>{"use strict";ue();pe();Ye();he();U_();Hn=r=>{if(!r||r.length===0||r.length>2)throw new Error("Reduce op requires 1 or 2 inputs.");if(r.length===2&&r[1].dims.length!==1)throw new Error("Invalid axes input dims.")},R3=r=>["","",`var value = ${r.getByIndices("input_indices")};`,""],Fa=(r,e,n,t,o,i,a=!1,s=!1)=>{let u=[],l=n[0].dims,d=l.length,p=D.normalizeAxes(o,d),h=!s&&p.length===0;l.forEach((I,w)=>{h||p.indexOf(w)>=0?a&&u.push(1):u.push(I)});let g=u.length,b=D.size(u);return{name:r,shaderCache:e,getShaderSource:I=>{let w=[],v=L("_A",n[0].dataType,d),S=V("output",i,g),A=t(v,S,p),P=A[2];for(let C=0,R=0;C=0?(a&&R++,P=`for(var j${C}: u32 = 0; j${C} < ${l[C]}; j${C}++) { ${A[2].includes("last_index")?`let last_index = j${C};`:""} ${v.indicesSet("input_indices",C,`j${C}`)} ${P} }`):(w.push(`${v.indicesSet("input_indices",C,S.indicesGet("output_indices",R))};`),R++);return` ${I.registerUniform("output_size","u32").declareVariables(v,S)} ${I.mainStart()} ${I.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} var input_indices: ${v.type.indices}; let output_indices = ${S.offsetToIndices("global_idx")}; ${w.join(` `)} ${A[0]} // init ops for reduce max/min ${A[1]} ${P} ${A[3]} ${A.length===4?S.setByOffset("global_idx","value"):A.slice(4).join(` `)} }`},getRunData:()=>({outputs:[{dims:u,dataType:i}],dispatchGroup:{x:Math.ceil(b/64)},programUniforms:[{type:12,data:b},...W(l,u)]})}},Tc=(r,e)=>{let n=[];return r[1].dims[0]>0&&r[1].getBigInt64Array().forEach(t=>n.push(Number(t))),le({axes:n,keepDims:e.keepDims,noopWithEmptyAxes:e.noopWithEmptyAxes})},qn=(r,e,n,t)=>{let o=r.inputs,i=o.length===1?n:Tc(o,n);r.compute(Fa(e,{hint:i.cacheKey,inputDependencies:["rank"]},[o[0]],i.noopWithEmptyAxes&&i.axes.length===0?R3:t,i.axes,o[0].dataType,i.keepDims,i.noopWithEmptyAxes),{inputs:[0]})},z3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceLogSum",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,"value = log(value);"])},M3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceL1",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += abs(${t.getByIndices("input_indices")});`,""])},B3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceL2",e,(t,o)=>[`var t = ${o.type.value}(0); var value = ${o.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += (t * t);`,"value = sqrt(value);"])},F3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceLogSumExp",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += exp(${t.getByIndices("input_indices")});`,"value = log(value);"])},V3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceMax",e,(t,o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(t.indicesSet("input_indices",s,0));return[`${a.join(` `)}`,`var value = ${t.getByIndices("input_indices")};`,`value = max(value, ${t.getByIndices("input_indices")});`,""]})},G3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceMean",e,(t,o,i)=>{let a=1;for(let s=0;s=0||i.length===0)&&(a*=r.inputs[0].dims[s]);return["var sum = f32(0);","",`sum += f32(${t.getByIndices("input_indices")});`,`let value = ${o.type.value}(sum / ${a});`]})},U3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceMin",e,(t,o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(`input_indices[${s}] = 0;`);return[`${a.join(` `)}`,`var value = ${t.getByIndices("input_indices")};`,`value = min(value, ${t.getByIndices("input_indices")});`,""]})},W3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceProd",e,(t,o)=>[`var value = ${o.type.storage}(1);`,"",`value *= ${t.getByIndices("input_indices")};`,""])},H3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceSum",e,(t,o)=>[`var value = ${o.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,""])},q3=(r,e)=>{Hn(r.inputs),qn(r,"ReduceSumSquare",e,(t,o)=>[`var t = ${o.type.value}(0); var value = ${o.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += t * t;`,""])},jn=(r,e,n)=>{if(e.length===0)return n;let t=1,o=1;for(let i=0;i1024},W_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?G3(r,e):k_(r,e)},H_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?M3(r,e):N_(r,e)},q_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?B3(r,e):L_(r,e)},j_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?F3(r,e):R_(r,e)},K_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?V3(r,e):z_(r,e)},X_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?U3(r,e):M_(r,e)},Z_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?W3(r,e):B_(r,e)},J_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?H3(r,e):F_(r,e)},Y_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?q3(r,e):V_(r,e)},Q_=(r,e)=>{jn(r.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?z3(r,e):G_(r,e)}});var e0,t0,n0,Ic,r0=N(()=>{"use strict";ue();Ye();Ba();e0=r=>{if(!r||r.length===0||r.length>2)throw new Error("ArgMinMaxOp op requires 1 or 2 inputs.");if(r[0].dataType!==1)throw new Error("Invalid input type.")},t0=(r,e)=>{e0(r.inputs);let n=(t,o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(`input_indices[${s}] = 0;`);return[`${a.join(` `)}`,`var value = ${t.getByIndices("input_indices")}; var best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?"<=":"<"} value) { value = ${t.getByIndices("input_indices")}; best_index = i32(last_index); }`,"",o.setByOffset("global_idx","best_index")]};r.compute(Fa("ArgMin",{hint:e.cacheKey,inputDependencies:["rank"]},[r.inputs[0]],n,[e.axis],7,e.keepDims),{inputs:[0]})},n0=(r,e)=>{e0(r.inputs);let n=(t,o,i)=>{let a=[];for(let s=0;s=0||i.length===0)&&a.push(`input_indices[${s}] = 0;`);return[`${a.join(` `)}`,`var value = ${t.getByIndices("input_indices")}; var best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?">=":">"} value) { value = ${t.getByIndices("input_indices")}; best_index = i32(last_index); }`,"",o.setByOffset("global_idx","best_index")]};r.compute(Fa("argMax",{hint:e.cacheKey,inputDependencies:["rank"]},[r.inputs[0]],n,[e.axis],7,e.keepDims),{inputs:[0]})},Ic=r=>le(r)});var j3,Sc,K3,X3,Z3,co,J3,o0,Va=N(()=>{"use strict";ue();pe();Ra();he();j3=(r,e)=>{let n=r[0],t=r[1],o=r[2],i=r[3],a=r[4],s=r[5];if(a&&s)throw new Error("Attention cannot have both past and attention_bias");if(n.dims.length!==3)throw new Error('Input "input" must have 3 dimensions');let u=n.dims[0],l=n.dims[1],d=n.dims[2];if(o.dims.length!==1)throw new Error('Input "bias" is expected to have 1 dimensions');if(t.dims.length!==2)throw new Error('Input "weights" is expected to have 2 dimensions');if(t.dims[0]!==d)throw new Error("Input 1 dimension 0 should have same length as dimension 2 of input 0");if(o.dims[0]!==t.dims[1])throw new Error('Input "bias" dimension 0 should have same length as dimension 1 of input "weights"');let p=o.dims[0]/3,h=p,g=h;if(e.qkvHiddenSizes.length>0){if(e.qkvHiddenSizes.length!==3)throw new Error("qkv_hidden_sizes attribute should have 3 elements");for(let S of e.qkvHiddenSizes)if(S%e.numHeads!==0)throw new Error("qkv_hidden_sizes should be divisible by num_heads");p=e.qkvHiddenSizes[0],h=e.qkvHiddenSizes[1],g=e.qkvHiddenSizes[2]}let b=l;if(p!==h)throw new Error("qkv_hidden_sizes first element should be same as the second");if(o.dims[0]!==p+h+g)throw new Error('Input "bias" dimension 0 should have same length as sum of Q/K/V hidden sizes');let _=0;if(a){if(h!==g)throw new Error('Input "past" expect k_hidden_size == v_hidden_size');if(a.dims.length!==5)throw new Error('Input "past" must have 5 dimensions');if(a.dims[0]!==2)throw new Error('Input "past" first dimension must be 2');if(a.dims[1]!==u)throw new Error('Input "past" second dimension must be batch_size');if(a.dims[2]!==e.numHeads)throw new Error('Input "past" third dimension must be num_heads');if(a.dims[4]!==h/e.numHeads)throw new Error('Input "past" fifth dimension must be k_hidden_size / num_heads');e.pastPresentShareBuffer||(_=a.dims[3])}let I=b+_,w=-1,v=0;if(i)throw new Error("Mask not supported");if(a)throw new Error("past is not supported");if(s){if(s.dims.length!==4)throw new Error('Input "attention_bias" must have 4 dimensions');if(s.dims[0]!==u||s.dims[1]!==e.numHeads||s.dims[2]!==l||s.dims[3]!==I)throw new Error('Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)')}return{batchSize:u,sequenceLength:l,pastSequenceLength:_,kvSequenceLength:b,totalSequenceLength:I,maxSequenceLength:w,inputHiddenSize:d,hiddenSize:p,vHiddenSize:g,headSize:Math.floor(p/e.numHeads),vHeadSize:Math.floor(g/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:v,scale:e.scale,broadcastResPosBias:!1,passPastInKv:!1,qkvFormat:1}},Sc=(r,e,n)=>e&&r?` let total_sequence_length_input = u32(${e.getByOffset("0")}); let present_sequence_length = max(total_sequence_length_input, uniforms.past_sequence_length); let is_subsequent_prompt: bool = sequence_length > 1 && sequence_length != total_sequence_length_input; let is_first_prompt: bool = is_subsequent_prompt == false && sequence_length == total_sequence_length_input; total_sequence_length = u32(${r?.getByOffset("batchIdx")}) + 1; var past_sequence_length: u32 = 0; if (is_first_prompt == false) { past_sequence_length = total_sequence_length - sequence_length; } `:` ${n?"let past_sequence_length = uniforms.past_sequence_length":""}; let present_sequence_length = total_sequence_length; `,K3=(r,e,n,t,o,i,a,s)=>{let u=Pe(a?1:i),l=64,d=i/u;d{let v=V("x",r.dataType,r.dims,u),S=[v],A=a?L("seq_lens",a.dataType,a.dims):void 0;A&&S.push(A);let P=s?L("total_sequence_length_input",s.dataType,s.dims):void 0;P&&S.push(P);let C=ut(r.dataType),R=[{name:"batch_size",type:"u32"},{name:"num_heads",type:"u32"},{name:"past_sequence_length",type:"u32"},{name:"sequence_length",type:"u32"},{name:"total_sequence_length",type:"u32"},{name:"elements_per_thread",type:"u32"}];return` var thread_max: array; var thread_sum: array; ${w.registerUniforms(R).declareVariables(...S)} ${w.mainStart([l,1,1])} let batchIdx = workgroup_id.z / uniforms.num_heads; let headIdx = workgroup_id.z % uniforms.num_heads; let sequence_length = uniforms.sequence_length; var total_sequence_length = uniforms.total_sequence_length; ${Sc(A,P,!1)} let local_offset = local_idx * uniforms.elements_per_thread; let offset = (global_idx / ${l}) * uniforms.total_sequence_length + local_offset; let seq_causal_length = ${a?"u32(past_sequence_length + workgroup_id.y + 1)":"total_sequence_length"}; var thread_max_vector = ${b}(-3.4028234663852886e+38f); for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { thread_max_vector = max(${b}(x[offset + i]), thread_max_vector); } thread_max[local_idx] = ${(()=>{switch(u){case 1:return"thread_max_vector";case 2:return"max(thread_max_vector.x, thread_max_vector.y)";case 4:return"max(max(thread_max_vector.x, thread_max_vector.y), max(thread_max_vector.z, thread_max_vector.w))";default:throw new Error(`Unsupported components: ${u}`)}})()}; workgroupBarrier(); var max_value = f32(-3.4028234663852886e+38f); for (var i = 0u; i < ${l}; i++) { max_value = max(thread_max[i], max_value); } var sum_vector = ${b}(0); for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { sum_vector += exp(${b}(x[offset + i]) - max_value); } thread_sum[local_idx] = ${(()=>{switch(u){case 1:return"sum_vector";case 2:return"sum_vector.x + sum_vector.y";case 4:return"sum_vector.x + sum_vector.y + sum_vector.z + sum_vector.w";default:throw new Error(`Unsupported components: ${u}`)}})()}; workgroupBarrier(); var sum: f32 = 0; for (var i = 0u; i < ${l}; i++) { sum += thread_sum[i]; } if (sum == 0) { for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { x[offset + i] = ${v.type.value}(${C}(1.0) / ${C}(seq_causal_length)); } } else { for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < seq_causal_length; i++) { var f32input = ${b}(x[offset + i]); x[offset + i] = ${v.type.value}(exp(f32input - max_value) / sum); } } ${a?` for (var total_seq_id: u32 = seq_causal_length; total_seq_id + local_offset < uniforms.total_sequence_length; total_seq_id++) { x[offset + total_seq_id] = ${v.type.value}(${C}(0)); }`:""}; }`};return{name:"AttentionProbsSoftmax",shaderCache:{hint:`${l};${g};${u}`,inputDependencies:_},getShaderSource:I,getRunData:()=>({outputs:[],dispatchGroup:{x:1,y:o,z:e*n},programUniforms:h})}},X3=(r,e,n,t,o,i,a,s,u)=>{let l=a+i.kvSequenceLength,d=[i.batchSize,i.numHeads,i.sequenceLength,l],p=r>1&&t,h=i.kvNumHeads?i.kvNumHeads:i.numHeads,g=p?[i.batchSize,h,l,i.headSize]:void 0,b=i.nReps?i.nReps:1,_=i.scale===0?1/Math.sqrt(i.headSize):i.scale,I=Pe(i.headSize),w=i.headSize/I,v=12,S={x:Math.ceil(l/v),y:Math.ceil(i.sequenceLength/v),z:i.batchSize*i.numHeads},A=[{type:12,data:i.sequenceLength},{type:12,data:w},{type:12,data:l},{type:12,data:i.numHeads},{type:12,data:i.headSize},{type:1,data:_},{type:12,data:a},{type:12,data:i.kvSequenceLength},{type:12,data:b}],P=p&&t&&D.size(t.dims)>0,C=["type","type"];P&&C.push("type"),o&&C.push("type"),s&&C.push("type"),u&&C.push("type");let R=[{dims:d,dataType:e.dataType,gpuDataType:0}];p&&R.push({dims:g,dataType:e.dataType,gpuDataType:0});let x=B=>{let G=L("q",e.dataType,e.dims,I),Z=L("key",n.dataType,n.dims,I),J=[G,Z];if(P){let de=L("past_key",t.dataType,t.dims,I);J.push(de)}o&&J.push(L("attention_bias",o.dataType,o.dims));let ie=s?L("seq_lens",s.dataType,s.dims):void 0;ie&&J.push(ie);let z=u?L("total_sequence_length_input",u.dataType,u.dims):void 0;z&&J.push(z);let U=V("output",e.dataType,d),te=[U];p&&te.push(V("present_key",e.dataType,g,I));let oe=ut(1,I),ee=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"alpha",type:"f32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"},{name:"n_reps",type:"u32"}];return` const TILE_SIZE = ${v}u; var tileQ: array<${G.type.storage}, ${v*v}>; var tileK: array<${G.type.storage}, ${v*v}>; ${B.registerUniforms(ee).declareVariables(...J,...te)} ${B.mainStart([v,v,1])} // x holds the N and y holds the M let headIdx = workgroup_id.z % uniforms.num_heads; let kvHeadIdx = ${b===1?"headIdx":"headIdx / uniforms.n_reps"}; let kv_num_heads = ${b===1?"uniforms.num_heads":"uniforms.num_heads / uniforms.n_reps"}; let batchIdx = workgroup_id.z / uniforms.num_heads; let m = workgroup_id.y * TILE_SIZE; let n = workgroup_id.x * TILE_SIZE; let sequence_length = uniforms.M; var total_sequence_length = uniforms.N; ${Sc(ie,z,!0)} let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx; let qOffset = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K; ${P&&p?"let pastKeyOffset = absKvHeadIdx * uniforms.past_sequence_length * uniforms.K;":""}; let kOffset = absKvHeadIdx * uniforms.kv_sequence_length * uniforms.K; ${p?"let presentKeyOffset = absKvHeadIdx * uniforms.N * uniforms.K;":""} var value = ${oe}(0); for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { if (global_id.y < uniforms.M && w + local_id.x < uniforms.K) { tileQ[TILE_SIZE * local_id.y + local_id.x] = q[qOffset + local_id.y * uniforms.K + w + local_id.x]; } if (n + local_id.y < uniforms.N && w + local_id.x < uniforms.K) { var idx = TILE_SIZE * local_id.y + local_id.x; ${P&&p?` if (n + local_id.y < past_sequence_length) { tileK[idx] = past_key[pastKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x]; } else if (n + local_id.y - past_sequence_length < uniforms.kv_sequence_length) { tileK[idx] = key[kOffset + (n + local_id.y - past_sequence_length) * uniforms.K + w + local_id.x]; }`:` if (n + local_id.y < uniforms.kv_sequence_length) { tileK[idx] = key[kOffset + (n + local_id.y) * uniforms.K + w + local_id.x]; }`} ${p?`if (n + local_id.y < present_sequence_length) { present_key[presentKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x] = tileK[idx]; }`:""} } workgroupBarrier(); for (var k: u32 = 0u; k < TILE_SIZE && w+k < uniforms.K; k++) { value += ${oe}(tileQ[TILE_SIZE * local_id.y + k] * tileK[TILE_SIZE * local_id.x + k]); } workgroupBarrier(); } if (global_id.y < uniforms.M && global_id.x < total_sequence_length) { let headOffset = workgroup_id.z * uniforms.M * uniforms.N; let outputIdx = headOffset + global_id.y * uniforms.N + global_id.x; var sum: f32 = ${(()=>{switch(I){case 1:return"value";case 2:return"value.x + value.y";case 4:return"value.x + value.y + value.z + value.w";default:throw new Error(`Unsupported components: ${I}`)}})()}; output[outputIdx] = ${U.type.value} (sum * uniforms.alpha) + ${o?"attention_bias[outputIdx]":"0.0"}; } }`};return{name:"AttentionProbs",shaderCache:{hint:`${I};${o!==void 0};${t!==void 0};${r}`,inputDependencies:C},getRunData:()=>({outputs:R,dispatchGroup:S,programUniforms:A}),getShaderSource:x}},Z3=(r,e,n,t,o,i,a=void 0,s=void 0)=>{let u=i+o.kvSequenceLength,l=o.nReps?o.nReps:1,d=o.vHiddenSize*l,p=r>1&&t,h=o.kvNumHeads?o.kvNumHeads:o.numHeads,g=p?[o.batchSize,h,u,o.headSize]:void 0,b=[o.batchSize,o.sequenceLength,d],_=12,I={x:Math.ceil(o.vHeadSize/_),y:Math.ceil(o.sequenceLength/_),z:o.batchSize*o.numHeads},w=[{type:12,data:o.sequenceLength},{type:12,data:u},{type:12,data:o.vHeadSize},{type:12,data:o.numHeads},{type:12,data:o.headSize},{type:12,data:d},{type:12,data:i},{type:12,data:o.kvSequenceLength},{type:12,data:l}],v=p&&t&&D.size(t.dims)>0,S=["type","type"];v&&S.push("type"),a&&S.push("type"),s&&S.push("type");let A=[{dims:b,dataType:e.dataType,gpuDataType:0}];p&&A.push({dims:g,dataType:e.dataType,gpuDataType:0});let P=C=>{let R=L("probs",e.dataType,e.dims),x=L("v",n.dataType,n.dims),B=[R,x];v&&B.push(L("past_value",t.dataType,t.dims));let G=a?L("seq_lens",a.dataType,a.dims):void 0;a&&B.push(G);let Z=s?L("total_sequence_length_input",s.dataType,s.dims):void 0;s&&B.push(Z);let ie=[V("output",e.dataType,b)];p&&ie.push(V("present_value",e.dataType,g));let z=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"v_hidden_size",type:"u32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"},{name:"n_reps",type:"u32"}];return` const TILE_SIZE = ${_}u; var tileQ: array<${R.type.value}, ${_*_}>; var tileV: array<${R.type.value}, ${_*_}>; ${C.registerUniforms(z).declareVariables(...B,...ie)} ${C.mainStart([_,_,1])} let headIdx = workgroup_id.z % uniforms.num_heads; let batchIdx = workgroup_id.z / uniforms.num_heads; let kvHeadIdx = ${l===1?"headIdx":"headIdx / uniforms.n_reps"}; let kv_num_heads = ${l===1?"uniforms.num_heads":"uniforms.num_heads / uniforms.n_reps"}; let m = global_id.y; let n = global_id.x; let sequence_length = uniforms.M; var total_sequence_length = uniforms.K; ${Sc(G,Z,!0)} let offsetA = workgroup_id.z * uniforms.M * uniforms.K + m * uniforms.K; let absKvHeadIdx = batchIdx * kv_num_heads + kvHeadIdx; // kvHeadIdx is relative to the batch ${v&&p?"let pastValueOffset = absKvHeadIdx * uniforms.N * uniforms.past_sequence_length + n;":""}; let vOffset = absKvHeadIdx * uniforms.N * uniforms.kv_sequence_length + n; ${p?"let presentValueOffset = absKvHeadIdx * uniforms.N * uniforms.K + n;":""} var value = ${R.type.storage}(0); for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { if (m < uniforms.M && w + local_id.x < uniforms.K) { tileQ[TILE_SIZE * local_id.y + local_id.x] = probs[offsetA + w + local_id.x]; } if (n < uniforms.N && w + local_id.y < uniforms.K) { var idx = TILE_SIZE * local_id.y + local_id.x; ${v&&p?` if (w + local_id.y < past_sequence_length) { tileV[idx] = past_value[pastValueOffset + (w + local_id.y) * uniforms.N]; } else if (w + local_id.y - past_sequence_length < uniforms.kv_sequence_length) { tileV[idx] = v[vOffset + (w + local_id.y - past_sequence_length) * uniforms.N]; } `:` if (w + local_id.y < uniforms.kv_sequence_length) { tileV[idx] = v[vOffset + (w + local_id.y) * uniforms.N]; }`} ${p?` if (w + local_id.y < present_sequence_length) { present_value[presentValueOffset + (w + local_id.y) * uniforms.N] = tileV[idx]; }`:""} } workgroupBarrier(); for (var k: u32 = 0u; k < TILE_SIZE && w+k < total_sequence_length; k++) { value += tileQ[TILE_SIZE * local_id.y + k] * tileV[TILE_SIZE * k + local_id.x]; } workgroupBarrier(); } // we need to transpose output from BNSH_v to BSND_v if (m < uniforms.M && n < uniforms.N) { let outputIdx = batchIdx * uniforms.M * uniforms.v_hidden_size + m * uniforms.v_hidden_size + headIdx * uniforms.N + n; output[outputIdx] = value; } }`};return{name:"AttentionScore",shaderCache:{hint:`${t!==void 0};${r}`,inputDependencies:S},getRunData:()=>({outputs:A,dispatchGroup:I,programUniforms:w}),getShaderSource:P}},co=(r,e,n,t,o,i,a,s,u,l,d=void 0,p=void 0)=>{let h=Math.min(r.outputCount,1+(a?1:0)+(s?1:0)),g=h>1?a:void 0,b=h>1?s:void 0,_=h>1?l.pastSequenceLength:0,I=_+l.kvSequenceLength,w=u&&D.size(u.dims)>0?u:void 0,v=[e,n];g&&D.size(g.dims)>0&&v.push(g),w&&v.push(w),d&&v.push(d),p&&v.push(p);let S=r.compute(X3(h,e,n,g,w,l,_,d,p),{inputs:v,outputs:h>1?[-1,1]:[-1]})[0];r.compute(K3(S,l.batchSize,l.numHeads,_,l.sequenceLength,I,d,p),{inputs:d&&p?[S,d,p]:[S],outputs:[]});let A=[S,t];b&&D.size(b.dims)>0&&A.push(b),d&&A.push(d),p&&A.push(p),r.compute(Z3(h,S,t,b,l,_,d,p),{inputs:A,outputs:h>1?[0,2]:[0]})},J3=(r,e)=>{let n=[e.batchSize,e.numHeads,e.sequenceLength,e.headSize],t=e.sequenceLength,o=e.inputHiddenSize,i=e.headSize,a=12,s={x:Math.ceil(e.headSize/a),y:Math.ceil(e.sequenceLength/a),z:e.batchSize*e.numHeads},u=[r.inputs[0],r.inputs[1],r.inputs[2]],l=[{type:12,data:t},{type:12,data:o},{type:12,data:i},{type:12,data:e.numHeads},{type:12,data:e.headSize},{type:12,data:e.hiddenSize},{type:12,data:e.hiddenSize+e.hiddenSize+e.vHiddenSize}],d=p=>{let h=V("output_q",u[0].dataType,n),g=V("output_k",u[0].dataType,n),b=V("output_v",u[0].dataType,n),_=L("input",u[0].dataType,u[0].dims),I=L("weight",u[1].dataType,u[1].dims),w=L("bias",u[2].dataType,u[2].dims),v=_.type.storage,S=[{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"hidden_size",type:"u32"},{name:"ldb",type:"u32"}];return` const TILE_SIZE = ${a}u; var tileInput: array<${v}, ${a*a}>; var tileWeightQ: array<${v}, ${a*a}>; var tileWeightK: array<${v}, ${a*a}>; var tileWeightV: array<${v}, ${a*a}>; ${p.registerUniforms(S).declareVariables(_,I,w,h,g,b)} ${p.mainStart([a,a,1])} let batchIndex = workgroup_id.z / uniforms.num_heads; let headNumber = workgroup_id.z % uniforms.num_heads; let m = global_id.y; let n = global_id.x; let inputOffset = batchIndex * (uniforms.M * uniforms.K) + m * uniforms.K; let biasOffsetQ = headNumber * uniforms.head_size; let biasOffsetK = uniforms.hidden_size + biasOffsetQ; let biasOffsetV = uniforms.hidden_size + biasOffsetK; var valueQ = ${v}(0); var valueK = ${v}(0); var valueV = ${v}(0); for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) { if (m < uniforms.M && w + local_id.x < uniforms.K) { tileInput[TILE_SIZE * local_id.y + local_id.x] = input[inputOffset + w + local_id.x]; } if (n < uniforms.N && w + local_id.y < uniforms.K) { let offset = n + (w + local_id.y) * uniforms.ldb; tileWeightQ[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetQ + offset]; tileWeightK[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetK + offset]; tileWeightV[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetV + offset]; } workgroupBarrier(); for (var k: u32 = 0u; k({outputs:[{dims:n,dataType:r.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:r.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:r.inputs[0].dataType,gpuDataType:0}],dispatchGroup:s,programUniforms:l}),getShaderSource:d},{inputs:u,outputs:[-1,-1,-1]})},o0=(r,e)=>{let n=j3(r.inputs,e),[t,o,i]=J3(r,n);return co(r,t,o,i,r.inputs[4],void 0,void 0,void 0,r.inputs[5],n)}});var Y3,Q3,eE,i0,a0=N(()=>{"use strict";ft();ue();pe();Ye();he();Y3=(r,e)=>{if(!r||r.length!==5)throw new Error("BatchNormalization requires 5 inputs");let n=(t,o,i)=>{let a=o.length;if(a!==t.length)throw new Error(`${i}: num dimensions != ${a}`);o.forEach((s,u)=>{if(s!==t[u])throw new Error(`${i}: dim[${u}] do not match`)})};if(r[0].dims.length>1){let t=e.format==="NHWC"?e.spatial?r[0].dims.slice(-1):r[0].dims.slice(-1).concat(r[0].dims.slice(1,r[0].dims.length-1)):r[0].dims.slice(1,e.spatial?2:void 0);n(r[1].dims,t,"Invalid input scale"),n(r[2].dims,t,"Invalid input B"),n(r[3].dims,t,"Invalid input mean"),n(r[4].dims,t,"Invalid input var")}else n(r[1].dims,[1],"Invalid input scale"),n(r[2].dims,[1],"Invalid input B"),n(r[3].dims,[1],"Invalid input mean"),n(r[4].dims,[1],"Invalid input var")},Q3=(r,e)=>{let{epsilon:n,spatial:t,format:o}=e,i=r[0].dims,a=t?Pe(i[i.length-1]):1,s=o==="NHWC"&&i.length>1?a:1,u=D.size(i)/a,l=t,d=l?i.length:i,p=L("x",r[0].dataType,r[0].dims,a),h=L("scale",r[1].dataType,r[1].dims,s),g=L("bias",r[2].dataType,r[2].dims,s),b=L("inputMean",r[3].dataType,r[3].dims,s),_=L("inputVar",r[4].dataType,r[4].dims,s),I=V("y",r[0].dataType,d,a),w=()=>{let S="";if(t)S=`let cOffset = ${i.length===1?"0u":o==="NHWC"?`outputIndices[${i.length-1}] / ${a}`:"outputIndices[1]"};`;else if(o==="NCHW")S=` ${I.indicesSet("outputIndices","0","0")} let cOffset = ${I.indicesToOffset("outputIndices")};`;else{S=`var cIndices = ${h.type.indices}(0); cIndices[0] = outputIndices[${i.length-1}];`;for(let A=1;A` const epsilon = ${n}; ${S.registerUniform("outputSize","u32").declareVariables(p,h,g,b,_,I)} ${S.mainStart()} ${S.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} var outputIndices = ${I.offsetToIndices(`global_idx * ${a}`)}; ${w()} let scale = ${h.getByOffset("cOffset")}; let bias = ${g.getByOffset("cOffset")}; let inputMean = ${b.getByOffset("cOffset")}; let inputVar = ${_.getByOffset("cOffset")}; let x = ${p.getByOffset("global_idx")}; let value = (x - inputMean) * inverseSqrt(inputVar + epsilon) * scale + bias; ${I.setByOffset("global_idx","value")} }`;return{name:"BatchNormalization",shaderCache:{hint:`${e.epsilon}_${e.format}_${t}_${a}`,inputDependencies:l?["rank","type","type","type","type"]:void 0},getShaderSource:v,getRunData:()=>({outputs:[{dims:r[0].dims,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:l?[{type:12,data:u},...W(i)]:[{type:12,data:u}]})}},eE=r=>le(r),i0=(r,e)=>{let{inputs:n,outputCount:t}=r,o=eE({...e,outputCount:t});if(ce.webgpu.validateInputContent&&Y3(n,o),e.trainingMode)throw new Error("BatchNormalization trainingMode is not supported yet.");r.compute(Q3(n,o))}});var tE,nE,s0,u0=N(()=>{"use strict";pe();he();tE=r=>{if(r[0].dims.length!==3)throw new Error("input should have 3 dimensions");if(![320,640,1280].includes(r[0].dims[2]))throw new Error("number of channels should be 320, 640 or 1280");if(r[1].dims.length!==1)throw new Error("bias is expected to have 1 dimensions");if(r[0].dims[2]!==r[1].dims[0])throw new Error("last dimension of input and bias are not the same")},nE=r=>{let e=r[0].dims,n=r[0].dims[2],t=D.size(e)/4,o=r[0].dataType,i=L("input",o,e,4),a=L("bias",o,[n],4),s=L("residual",o,e,4),u=V("output",o,e,4);return{name:"BiasAdd",getRunData:()=>({outputs:[{dims:e,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(t/64)}}),getShaderSource:d=>` const channels = ${n}u / 4; ${d.declareVariables(i,a,s,u)} ${d.mainStart()} ${d.guardAgainstOutOfBoundsWorkgroupSizes(t)} let value = ${i.getByOffset("global_idx")} + ${a.getByOffset("global_idx % channels")} + ${s.getByOffset("global_idx")}; ${u.setByOffset("global_idx","value")} }`}},s0=r=>{tE(r.inputs),r.compute(nE(r.inputs))}});var rE,ke,l0,c0,d0,p0,f0,h0,m0,g0,b0,oE,y0,_0,w0,v0,Wo,x0,Ga,T0,I0,S0,$0,A0,O0,P0,E0,C0,D0,k0,N0,L0,R0,z0,M0,B0,F0,$c,Ac,V0,G0,U0,iE,aE,W0,Ua=N(()=>{"use strict";ue();pe();Ye();he();rE=(r,e,n,t,o,i,a)=>{let s=Math.ceil(e/4),u="";typeof o=="string"?u=`${o}(a)`:u=o("a");let l=L("inputData",n,[s],4),d=V("outputData",t,[s],4),p=[{name:"vec_size",type:"u32"}];return a&&p.push(...a),` ${r.registerUniforms(p).declareVariables(l,d)} ${i??""} ${r.mainStart()} ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} let a = ${l.getByOffset("global_idx")}; ${d.setByOffset("global_idx",u)} }`},ke=(r,e,n,t,o,i=r.dataType,a,s)=>{let u=[{type:12,data:Math.ceil(D.size(r.dims)/4)}];return a&&u.push(...a),{name:e,shaderCache:{hint:o,inputDependencies:["type"]},getShaderSource:l=>rE(l,D.size(r.dims),r.dataType,i,n,t,s),getRunData:l=>({outputs:[{dims:r.dims,dataType:i}],dispatchGroup:{x:Math.ceil(D.size(l[0].dims)/64/4)},programUniforms:u})}},l0=r=>{r.compute(ke(r.inputs[0],"Abs","abs"))},c0=r=>{r.compute(ke(r.inputs[0],"Acos","acos"))},d0=r=>{r.compute(ke(r.inputs[0],"Acosh","acosh"))},p0=r=>{r.compute(ke(r.inputs[0],"Asin","asin"))},f0=r=>{r.compute(ke(r.inputs[0],"Asinh","asinh"))},h0=r=>{r.compute(ke(r.inputs[0],"Atan","atan"))},m0=r=>{r.compute(ke(r.inputs[0],"Atanh","atanh"))},g0=r=>le(r),b0=(r,e)=>{let n;switch(e.to){case 10:n="vec4";break;case 1:n="vec4";break;case 12:n="vec4";break;case 6:n="vec4";break;case 9:n="vec4";break;default:throw new RangeError(`not supported type (specified in attribute 'to' from 'Cast' operator): ${e.to}`)}r.compute(ke(r.inputs[0],"Cast",n,void 0,e.cacheKey,e.to))},oE=r=>{let e,n,t=r.length>=2&&r[1].data!==0,o=r.length>=3&&r[2].data!==0;switch(r[0].dataType){case 1:e=t?r[1].getFloat32Array()[0]:-34028234663852886e22,n=o?r[2].getFloat32Array()[0]:34028234663852886e22;break;case 10:e=t?r[1].getUint16Array()[0]:64511,n=o?r[2].getUint16Array()[0]:31743;break;default:throw new Error("Unsupport data type")}return le({min:e,max:n})},y0=(r,e)=>{let n=e||oE(r.inputs),t=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"Clip",o=>`clamp(${o}, vec4<${t}>(uniforms.min), vec4<${t}>(uniforms.max))`,void 0,n.cacheKey,void 0,[{type:r.inputs[0].dataType,data:n.min},{type:r.inputs[0].dataType,data:n.max}],[{name:"min",type:t},{name:"max",type:t}]),{inputs:[0]})},_0=r=>{r.compute(ke(r.inputs[0],"Ceil","ceil"))},w0=r=>{r.compute(ke(r.inputs[0],"Cos","cos"))},v0=r=>{r.compute(ke(r.inputs[0],"Cosh","cosh"))},Wo=r=>le(r),x0=(r,e)=>{let n=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"Elu",t=>`elu_vf32(${t})`,` const elu_alpha_ = ${n}(${e.alpha}); fn elu_f32(a: ${n}) -> ${n} { return select((exp(a) - 1.0) * elu_alpha_, a, a >= 0.0); } fn elu_vf32(v: vec4<${n}>) -> vec4<${n}> { return vec4(elu_f32(v.x), elu_f32(v.y), elu_f32(v.z), elu_f32(v.w)); }`,e.cacheKey))},Ga=(r="f32")=>` const r0: ${r} = 0.3275911; const r1: ${r} = 0.254829592; const r2: ${r} = -0.284496736; const r3: ${r} = 1.421413741; const r4: ${r} = -1.453152027; const r5: ${r} = 1.061405429; fn erf_vf32(v: vec4<${r}>) -> vec4<${r}> { let absv = abs(v); let x = 1.0 / (1.0 + r0 * absv); return sign(v) * (1.0 - ((((r5 * x + r4) * x + r3) * x + r2) * x + r1) * x * exp(-absv * absv)); }`,T0=r=>{let e=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"Erf",n=>`erf_vf32(${n})`,Ga(e)))},I0=r=>{r.compute(ke(r.inputs[0],"Exp","exp"))},S0=r=>{r.compute(ke(r.inputs[0],"Floor","floor"))},$0=r=>{let e=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"Gelu",n=>`0.5 * ${n} * (1.0 + erf_vf32(${n} * 0.7071067811865475))`,Ga(e)))},A0=(r,e)=>{let n=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"LeakyRelu",t=>`select(leaky_relu_alpha_ * ${t}, ${t}, ${t} >= vec4<${n}>(0.0))`,`const leaky_relu_alpha_ = ${n}(${e.alpha});`,e.cacheKey))},O0=r=>{r.compute(ke(r.inputs[0],"Not",e=>`!${e}`))},P0=r=>{r.compute(ke(r.inputs[0],"Neg",e=>`-${e}`))},E0=r=>{r.compute(ke(r.inputs[0],"Reciprocal",e=>`1.0/${e}`))},C0=r=>{let e=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"Relu",n=>`select(vec4<${e}>(0.0), ${n}, ${n} > vec4<${e}>(0.0))`))},D0=r=>{r.compute(ke(r.inputs[0],"Sigmoid",e=>`(1.0 / (1.0 + exp(-${e})))`))},k0=r=>le(r),N0=(r,e)=>{let n=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"HardSigmoid",t=>`max(vec4<${n}>(0.0), min(vec4<${n}>(1.0), ${e.alpha} * ${t} + vec4<${n}>(${e.beta})))`,void 0,e.cacheKey))},L0=r=>{r.compute(ke(r.inputs[0],"Sin","sin"))},R0=r=>{r.compute(ke(r.inputs[0],"Sinh","sinh"))},z0=r=>{r.compute(ke(r.inputs[0],"Sqrt","sqrt"))},M0=r=>{r.compute(ke(r.inputs[0],"Tan","tan"))},B0=r=>`sign(${r}) * (1 - exp(-2 * abs(${r}))) / (1 + exp(-2 * abs(${r})))`,F0=r=>{r.compute(ke(r.inputs[0],"Tanh",B0))},$c=(r="f32")=>` const fast_gelu_a: ${r} = 0.5; const fast_gelu_b: ${r} = 0.7978845608028654; const fast_gelu_c: ${r} = 0.035677408136300125; fn tanh_v(v: vec4<${r}>) -> vec4<${r}> { return ${B0("v")}; } `,Ac=r=>`(fast_gelu_a + fast_gelu_a * tanh_v(${r} * (fast_gelu_c * ${r} * ${r} + fast_gelu_b))) * ${r}`,V0=r=>{let e=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"FastGelu",Ac,$c(e),void 0,r.inputs[0].dataType))},G0=(r,e)=>{let n=ut(r.inputs[0].dataType);return r.compute(ke(r.inputs[0],"ThresholdedRelu",t=>`select(vec4<${n}>(0.0), ${t}, ${t} > thresholded_relu_alpha_)`,`const thresholded_relu_alpha_ = vec4<${n}>(${e.alpha});`,e.cacheKey)),0},U0=r=>{r.compute(ke(r.inputs[0],"Log","log"))},iE=(r,e)=>` const alpha = vec4<${r}>(${e}); const one = ${r}(1.0); const zero = ${r}(0.0); fn quick_gelu_impl(x: vec4<${r}>) -> vec4<${r}> { let v = x *alpha; var x1 : vec4<${r}>; for (var i = 0; i < 4; i = i + 1) { if (v[i] >= zero) { x1[i] = one / (one + exp(-v[i])); } else { x1[i] = one - one / (one + exp(v[i])); } } return x * x1; } `,aE=r=>`quick_gelu_impl(${r})`,W0=(r,e)=>{let n=ut(r.inputs[0].dataType);r.compute(ke(r.inputs[0],"QuickGelu",aE,iE(n,e.alpha),e.cacheKey,r.inputs[0].dataType))}});var sE,uE,q0,j0=N(()=>{"use strict";pe();he();Ua();sE=r=>{if(r[0].dims.length!==3)throw new Error("input should have 3 dimensions");if(![2560,5120,10240].includes(r[0].dims[2]))throw new Error("hidden state should be 2560, 5120 or 10240");if(r[1].dims.length!==1)throw new Error("bias is expected to have 1 dimensions");if(r[0].dims[2]!==r[1].dims[0])throw new Error("last dimension of input and bias are not the same")},uE=r=>{let e=r[0].dims.slice();e[2]=e[2]/2;let n=L("input",r[0].dataType,r[0].dims,4),t=L("bias",r[0].dataType,[r[0].dims[2]],4),o=V("output",r[0].dataType,e,4),i=D.size(e)/4,a=Fe(r[0].dataType);return{name:"BiasSplitGelu",getRunData:()=>({outputs:[{dims:e,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(i/64)}}),getShaderSource:u=>` const M_SQRT2 = sqrt(2.0); const halfChannels = ${r[0].dims[2]/4/2}u; ${u.declareVariables(n,t,o)} ${Ga(a)} ${u.mainStart()} ${u.guardAgainstOutOfBoundsWorkgroupSizes(i)} let biasIdx = global_idx % halfChannels; let batchIndex = global_idx / halfChannels; let inputOffset = biasIdx + batchIndex * halfChannels * 2; let valueLeft = input[inputOffset] + bias[biasIdx]; let valueRight = input[inputOffset + halfChannels] + bias[biasIdx + halfChannels]; let geluRight = valueRight * 0.5 * (erf_vf32(valueRight / M_SQRT2) + 1); ${o.setByOffset("global_idx","valueLeft * geluRight")} }`}},q0=r=>{sE(r.inputs),r.compute(uE(r.inputs))}});var lE,cE,Kn,K0,X0,Z0,J0,Y0,Q0,ew,tw,nw,rw,ow=N(()=>{"use strict";ue();pe();he();lE=(r,e,n,t,o,i,a,s,u,l,d,p)=>{let h,g;typeof s=="string"?h=g=(v,S)=>`${s}((${v}),(${S}))`:typeof s=="function"?h=g=s:(h=s.scalar,g=s.vector);let b=V("outputData",d,t.length,4),_=L("aData",u,e.length,4),I=L("bData",l,n.length,4),w;if(o)if(i){let v=D.size(e)===1,S=D.size(n)===1,A=e.length>0&&e[e.length-1]%4===0,P=n.length>0&&n[n.length-1]%4===0;v||S?w=b.setByOffset("global_idx",g(v?`${_.type.value}(${_.getByOffset("0")}.x)`:_.getByOffset("global_idx"),S?`${I.type.value}(${I.getByOffset("0")}.x)`:I.getByOffset("global_idx"))):w=` let outputIndices = ${b.offsetToIndices("global_idx * 4u")}; let offsetA = ${_.broadcastedIndicesToOffset("outputIndices",b)}; let offsetB = ${I.broadcastedIndicesToOffset("outputIndices",b)}; ${b.setByOffset("global_idx",g(a||A?_.getByOffset("offsetA / 4u"):`${_.type.value}(${_.getByOffset("offsetA / 4u")}[offsetA % 4u])`,a||P?I.getByOffset("offsetB / 4u"):`${I.type.value}(${I.getByOffset("offsetB / 4u")}[offsetB % 4u])`))} `}else w=b.setByOffset("global_idx",g(_.getByOffset("global_idx"),I.getByOffset("global_idx")));else{if(!i)throw new Error("no necessary to use scalar implementation for element-wise binary op implementation.");let v=(S,A,P="")=>{let C=`aData[indexA${A}][componentA${A}]`,R=`bData[indexB${A}][componentB${A}]`;return` let outputIndices${A} = ${b.offsetToIndices(`global_idx * 4u + ${A}u`)}; let offsetA${A} = ${_.broadcastedIndicesToOffset(`outputIndices${A}`,b)}; let offsetB${A} = ${I.broadcastedIndicesToOffset(`outputIndices${A}`,b)}; let indexA${A} = offsetA${A} / 4u; let indexB${A} = offsetB${A} / 4u; let componentA${A} = offsetA${A} % 4u; let componentB${A} = offsetB${A} % 4u; ${S}[${A}] = ${P}(${h(C,R)}); `};d===9?w=` var data = vec4(0); ${v("data",0,"u32")} ${v("data",1,"u32")} ${v("data",2,"u32")} ${v("data",3,"u32")} outputData[global_idx] = dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(data));`:w=` ${v("outputData[global_idx]",0)} ${v("outputData[global_idx]",1)} ${v("outputData[global_idx]",2)} ${v("outputData[global_idx]",3)} `}return` ${r.registerUniform("vec_size","u32").declareVariables(_,I,b)} ${p??""} ${r.mainStart()} ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} ${w} }`},cE=(r,e,n,t,o,i,a=n.dataType)=>{let s=n.dims.map(Number),u=t.dims.map(Number),l=!D.areEqual(s,u),d=s,p=D.size(s),h=!1,g=!1,b=[l];if(l){let _=Un.calcShape(s,u,!1);if(!_)throw new Error("Can't perform binary op on the given tensors");d=_.slice(),p=D.size(d);let I=D.size(s)===1,w=D.size(u)===1,v=s.length>0&&s[s.length-1]%4===0,S=u.length>0&&u[u.length-1]%4===0;b.push(I),b.push(w),b.push(v),b.push(S);let A=1;for(let P=1;P_.toString()).join("_"),inputDependencies:["rank","rank"]},getShaderSource:_=>lE(_,s,u,d,h,l,g,o,n.dataType,t.dataType,a,i),getRunData:()=>({outputs:[{dims:d,dataType:a}],dispatchGroup:{x:Math.ceil(p/64/4)},programUniforms:[{type:12,data:Math.ceil(D.size(d)/4)},...W(s,u,d)]})}},Kn=(r,e,n,t,o,i)=>{r.compute(cE(e,o??"",r.inputs[0],r.inputs[1],n,t,i))},K0=r=>{Kn(r,"Add",(e,n)=>`${e}+${n}`)},X0=r=>{Kn(r,"Div",(e,n)=>`${e}/${n}`)},Z0=r=>{Kn(r,"Equal",{scalar:(e,n)=>`u32(${e}==${n})`,vector:(e,n)=>`vec4(${e}==${n})`},void 0,void 0,9)},J0=r=>{Kn(r,"Mul",(e,n)=>`${e}*${n}`)},Y0=r=>{let e=L("input",r.inputs[0].dataType,r.inputs[0].dims).type.value;Kn(r,"Pow",{scalar:(t,o)=>`pow_custom(${t},${o})`,vector:(t,o)=>`pow_vector_custom(${t},${o})`},` fn pow_custom(a : ${e}, b : ${e}) -> ${e} { if (b == ${e}(0.0)) { return ${e}(1.0); } else if (a < ${e}(0.0) && f32(b) != floor(f32(b))) { return ${e}(pow(f32(a), f32(b))); // NaN } return select(sign(a), ${e}(1.0), round(f32(abs(b) % ${e}(2.0))) != 1.0) * ${e}(${e==="i32"?"round":""}(pow(f32(abs(a)), f32(b)))); } fn pow_vector_custom(a : vec4<${e}>, b : vec4<${e}>) -> vec4<${e}> { // TODO: implement vectorized pow return vec4<${e}>(pow_custom(a.x, b.x), pow_custom(a.y, b.y), pow_custom(a.z, b.z), pow_custom(a.w, b.w)); } `)},Q0=r=>{Kn(r,"Sub",(e,n)=>`${e}-${n}`)},ew=r=>{Kn(r,"Greater",{scalar:(e,n)=>`u32(${e}>${n})`,vector:(e,n)=>`vec4(${e}>${n})`},void 0,void 0,9)},tw=r=>{Kn(r,"Less",{scalar:(e,n)=>`u32(${e}<${n})`,vector:(e,n)=>`vec4(${e}<${n})`},void 0,void 0,9)},nw=r=>{Kn(r,"GreaterOrEqual",{scalar:(e,n)=>`u32(${e}>=${n})`,vector:(e,n)=>`vec4(${e}>=${n})`},void 0,void 0,9)},rw=r=>{Kn(r,"LessOrEqual",{scalar:(e,n)=>`u32(${e}<=${n})`,vector:(e,n)=>`vec4(${e}<=${n})`},void 0,void 0,9)}});var pE,fE,hE,mE,iw,aw,sw=N(()=>{"use strict";ue();pe();Ye();he();pE=(r,e)=>{if(!r||r.length<1)throw new Error("too few inputs");let n=0,t=r[n],o=t.dataType,i=t.dims.length;r.forEach((a,s)=>{if(s!==n){if(a.dataType!==o)throw new Error("input tensors should be one type");if(a.dims.length!==i)throw new Error("input tensors should have the same shape");a.dims.forEach((u,l)=>{if(l!==e&&u!==t.dims[l])throw new Error("non concat dimensions must match")})}})},fE=(r,e)=>` fn calculateInputIndex(index: u32) -> u32 { let sizeInConcatAxis = array(${e}); for (var i: u32 = 0u; i < ${r}; i += 1u ) { if (index < sizeInConcatAxis[i]) { return i; } } return ${r}u; }`,hE=(r,e)=>{let n=r.length,t=[];for(let o=0;o{let o=D.size(n),i=new Array(r.length),a=new Array(r.length),s=0,u=[],l=[],d=[{type:12,data:o}];for(let _=0;_`uniforms.sizeInConcatAxis${_}`).join(","),b=_=>` ${(()=>{_.registerUniform("outputSize","u32");for(let I=0;I(${g}); ${h} -= sizeInConcatAxis[inputIndex - 1u]; } ${hE(a,p)} }`;return{name:"Concat",shaderCache:{hint:`${e}`,inputDependencies:u},getRunData:()=>({outputs:[{dims:n,dataType:t}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:d}),getShaderSource:b}},iw=(r,e)=>{let n=r.inputs,t=n[0].dims,o=D.normalizeAxis(e.axis,t.length);pE(n,o);let i=t.slice();i[o]=n.reduce((s,u)=>s+(u.dims.length>o?u.dims[o]:0),0);let a=n.filter(s=>D.size(s.dims)>0);r.compute(mE(a,o,i,n[0].dataType),{inputs:a})},aw=r=>le({axis:r.axis})});var Jt,Yt,Qt,Wa,wr=N(()=>{"use strict";ue();pe();Jt=(r,e,n="f32")=>{switch(r.activation){case"Relu":return`value = max(value, ${e}(0.0));`;case"Sigmoid":return`value = (${e}(1.0) / (${e}(1.0) + exp(-value)));`;case"Clip":return`value = clamp(value, ${e}(${n}(uniforms.clip_min)), ${e}(${n}(uniforms.clip_max)));`;case"HardSigmoid":return`value = max(${e}(0.0), min(${e}(1.0), ${n}(uniforms.alpha) * value + ${n}(uniforms.beta)));`;case"LeakyRelu":return`value = select(${n}(uniforms.alpha) * value, value, value >= ${e}(0.0));`;case"Tanh":return`let e2x = exp(-2.0 * abs(value)); value = sign(value) * (1.0 - e2x) / (1.0 + e2x); `;case"":return"";default:throw new Error(`Unsupported activation ${r.activation}`)}},Yt=(r,e)=>{r.activation==="Clip"?e.push({type:1,data:r.clipMax},{type:1,data:r.clipMin}):r.activation==="HardSigmoid"?e.push({type:1,data:r.alpha},{type:1,data:r.beta}):r.activation==="LeakyRelu"&&e.push({type:1,data:r.alpha})},Qt=(r,e)=>{r.activation==="Clip"?e.push({name:"clip_max",type:"f32"},{name:"clip_min",type:"f32"}):r.activation==="HardSigmoid"?e.push({name:"alpha",type:"f32"},{name:"beta",type:"f32"}):r.activation==="LeakyRelu"&&e.push({name:"alpha",type:"f32"})},Wa=r=>{let e=r?.activation||"";if(e==="HardSigmoid"){let[n,t]=r?.activation_params||[.2,.5];return{activation:e,alpha:n,beta:t}}else if(e==="Clip"){let[n,t]=r?.activation_params||[h_,m_];return{activation:e,clipMax:t,clipMin:n}}else if(e==="LeakyRelu"){let[n]=r?.activation_params||[.01];return{activation:e,alpha:n}}return{activation:e}}});var it,uw,Ha=N(()=>{"use strict";it=(r,e)=>{switch(r){case 1:return e;case 2:return`vec2<${e}>`;case 3:return`vec3<${e}>`;case 4:return`vec4<${e}>`;default:throw new Error(`${r}-component is not supported.`)}},uw=r=>` ${r?"value = value + getBiasByOutputCoords(coords);":""} `});var lw,cw=N(()=>{"use strict";lw=r=>` fn getIndexFromCoords4D(coords : vec4, shape : vec4) -> i32 { return dot(coords, vec4( shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1)); } fn getOutputIndexFromCoords(coords : vec4) -> i32 { return dot(coords, vec4( i32(${r}.x), i32(${r}.y), i32(${r}.z), 1)); } `});var Ho,qa,ja=N(()=>{"use strict";ue();pe();he();wr();Ho=(r,e,n,t,o)=>{let i=t-n;return` ${Array.from({length:n}).map((a,s)=>` if (${Q(e.shape,s,e.rank)} != 1) { ${e.indicesSet(r,s,Q(o,s+i,t))} } else { ${e.indicesSet(r,s,0)} }`).join("")} `},qa=(r,e,n,t,o=!1,i)=>{let a=r[0].dims,s=r[1].dims,u=a[a.length-2],l=s[s.length-1],d=a[a.length-1],p=Pe(l),h=Pe(d),g=Pe(u),b=D.size(n)/p/g,_=r.length>2,I=t?t.slice(0,-2):n.slice(0,-2),v=[D.size(I),u,l],S=[{type:12,data:b},{type:12,data:u},{type:12,data:l},{type:12,data:d}];Yt(e,S),S.push(...W(I,a,s)),_&&S.push(...W(r[2].dims)),S.push(...W(v));let A=P=>{let C=Ma("batch_dims",r[0].dataType,I.length),R=L("a",r[0].dataType,a.length,h),x=L("b",r[1].dataType,s.length,p),B=V("output",r[0].dataType,v.length,p),G=Fe(B.type.tensor),Z=Jt(e,B.type.value,G),J=[R,x],ie="";if(_){let te=o?p:1;J.push(L("bias",r[2].dataType,r[2].dims.length,te)),ie=`${o?`value += bias[col / ${te}];`:`value += ${B.type.value}(bias[row + i]);`}`}let z=[{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"}];Qt(e,z);let U=()=>{let te=`var a_data: ${R.type.value};`;for(let oe=0;oe; for (var k: u32 = 0u; k < uniforms.K; k = k + ${h}) { ${U()} } for (var i = 0u; i < ${g}u; i++) { var value = values[i]; ${ie} ${Z} let cur_indices = ${B.type.indices}(batch, row + i, col); let offset = ${B.indicesToOffset("cur_indices")}; ${B.setByOffset(`offset / ${p}`,"value")}; } } `};return{name:"MatMulNaive",shaderCache:{hint:`${e.activation};${p};${h};${g};${o}`,inputDependencies:_?["rank","rank","rank"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:i?i(n):n,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(b/64)},programUniforms:S}),getShaderSource:A}}});var gE,bE,Oc,dw,yE,Pc,_E,qo,Ka=N(()=>{"use strict";ue();pe();he();wr();ja();Ha();gE=(r,e)=>r?` mm_Asub[inputRow][inputCol] = mm_readA(batch, kStart + inputRow, globalRowStart / innerElementSize + inputCol${e?", batchIndices":""}); `:` mm_Asub[inputRow][inputCol] = mm_readA(batch, globalRow + innerRow, kStart / innerElementSize + inputCol${e?", batchIndices":""}); `,bE=(r,e)=>r?` let ACached0 = mm_Asub[k * innerElementSize][localRow]; let ACached1 = mm_Asub[k * innerElementSize + 1][localRow]; let ACached2 = mm_Asub[k * innerElementSize + 2][localRow]; ${e===3?"":"let ACached3 = mm_Asub[k * innerElementSize + 3][localRow];"} for (var i = 0; i < rowPerThread; i = i + 1) { acc[i] = BCached0 * ACached0[i] + acc[i]; acc[i] = BCached1 * ACached1[i] + acc[i]; acc[i] = BCached2 * ACached2[i] + acc[i]; ${e===3?"":"acc[i] = BCached3 * ACached3[i] + acc[i];"} }`:` for (var i = 0; i < rowPerThread; i = i + 1) { let ACached = mm_Asub[tileRow + i][k]; acc[i] = BCached0 * ACached.x + acc[i]; acc[i] = BCached1 * ACached.y + acc[i]; acc[i] = BCached2 * ACached.z + acc[i]; ${e===3?"":"acc[i] = BCached3 * ACached.w + acc[i];"} }`,Oc=(r,e,n="f32",t,o=!1,i=32,a=!1,s=32)=>{let u=e[1]*r[1],l=e[0]*r[0],d=o?u:i,p=o?i:u,h=d/e[0],g=i/e[1];if(!((o&&h===4&&r[1]===4||!o&&(h===3||h===4))&&d%e[0]===0&&i%e[1]===0&&r[0]===4))throw new Error(`If transposeA ${o} is true, innerElementSize ${h} and workPerThread[1] ${r[1]} must be 4. Otherwise, innerElementSize ${h} must be 3 or 4. tileAWidth ${d} must be divisible by workgroupSize[0]${e[0]}. tileInner ${i} must be divisible by workgroupSize[1] ${e[1]}. colPerThread ${r[0]} must be 4.`);return` var mm_Asub: array, ${d/h}>, ${p}>; var mm_Bsub: array, ${l/r[0]}>, ${i}>; const rowPerThread = ${r[1]}; const colPerThread = ${r[0]}; const innerElementSize = ${h}; const tileInner = ${i}; @compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]}) fn main(@builtin(local_invocation_id) localId : vec3, @builtin(global_invocation_id) globalId : vec3, @builtin(workgroup_id) workgroupId : vec3) { let localRow = i32(localId.y); let tileRow = localRow * rowPerThread; let tileCol = i32(localId.x); let globalRow =i32(globalId.y) * rowPerThread; let globalCol = i32(globalId.x); let batch = ${a?"0":"i32(globalId.z)"}; ${t?`let batchIndices = ${t.offsetToIndices("u32(batch)")};`:""} let globalRowStart = i32(workgroupId.y) * ${u}; let num_tiles = ${a?`${Math.ceil(s/i)}`:"(uniforms.dim_inner - 1) / tileInner + 1"}; var kStart = ${a?`i32(globalId.z) * ${s}`:"0"}; var acc: array, rowPerThread>; // Loop over shared dimension. let tileRowB = localRow * ${g}; for (var t = 0; t < num_tiles; t = t + 1) { // Load one tile of A into local memory. for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { let inputRow = tileRow + innerRow; let inputCol = tileCol; ${gE(o,t)} } // Load one tile of B into local memory. for (var innerRow = 0; innerRow < ${g}; innerRow = innerRow + 1) { let inputRow = tileRowB + innerRow; let inputCol = tileCol; mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalCol${t?", batchIndices":""}); } kStart = kStart + tileInner; workgroupBarrier(); // Compute acc values for a single thread. for (var k = 0; k < tileInner / innerElementSize; k = k + 1) { let BCached0 = mm_Bsub[k * innerElementSize][tileCol]; let BCached1 = mm_Bsub[k * innerElementSize + 1][tileCol]; let BCached2 = mm_Bsub[k * innerElementSize + 2][tileCol]; ${h===3?"":"let BCached3 = mm_Bsub[k * innerElementSize + 3][tileCol];"} ${bE(o,h)} } workgroupBarrier(); } for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { mm_write(batch, globalRow + innerRow, globalCol, acc[innerRow]); } }`},dw=(r,e)=>r?` mm_Asub[inputRow][inputCol] = mm_readA(batch, kStart + inputRow, globalRowStart + inputCol${e?", batchIndices":""}); `:` mm_Asub[inputRow][inputCol] = mm_readA(batch, globalRowStart + inputRow, kStart + inputCol${e?", batchIndices":""}); `,yE=r=>r?"let ACached = mm_Asub[k][tileRow + innerRow];":"let ACached = mm_Asub[tileRow + innerRow][k];",Pc=(r,e,n="f32",t,o=!1,i=32,a=!1,s=32,u=!1)=>{let l=r[1]*e[1],d=r[0]*e[0],p=o?l:i,h=o?i:l;if(!(h%e[1]===0&&p%e[0]===0&&i%e[1]===0))throw new Error(`tileAHight ${h} must be divisible by workgroupSize[1]${e[1]}, tileAWidth ${p} must be divisible by workgroupSize[0]${e[0]}, tileInner ${i} must be divisible by workgroupSize[1]${e[1]}`);let g=h/e[1],b=p/e[0],_=i/e[1],I=u?` let localRow = i32(localId.y); let localCol = i32(localId.x); let globalRowStart = i32(workgroupId.y) * ${l}; let globalColStart = i32(workgroupId.x) * ${d}; // Loop over shared dimension. for (var t = 0; t < num_tiles; t = t + 1) { // Load one tile of A into local memory. for (var inputRow = localRow; inputRow < ${h}; inputRow = inputRow + ${e[1]}) { for (var inputCol = localCol; inputCol < ${p}; inputCol = inputCol + ${e[0]}) { ${dw(o,t)} } } // Load one tile of B into local memory. for (var inputRow = localRow; inputRow < ${i}; inputRow = inputRow + ${e[1]}) { for (var inputCol = localCol; inputCol < ${d}; inputCol = inputCol + ${e[0]}) { mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalColStart + inputCol${t?", batchIndices":""}); } } kStart = kStart + tileInner; workgroupBarrier(); // Compute acc values for a single thread. var BCached : array<${n}, colPerThread>; for (var k = 0; k < tileInner; k = k + 1) { for (var inner = 0; inner < colPerThread; inner = inner + 1) { BCached[inner] = mm_Bsub[k][localCol + inner * ${e[0]}]; } for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { let ACached = ${o?`mm_Asub[k][localRow + innerRow * ${e[1]}];`:`mm_Asub[localRow + innerRow * ${e[1]}][k];`} for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol]; } } } workgroupBarrier(); } for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { let gRow = globalRowStart + localRow + innerRow * ${e[1]}; for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { let gCol = globalColStart + localCol + innerCol * ${e[0]}; mm_write(batch, gRow, gCol, acc[innerRow][innerCol]); } } `:` let tileRow = i32(localId.y) * rowPerThread; let tileCol = i32(localId.x) * colPerThread; let globalRow = i32(globalId.y) * rowPerThread; let globalCol = i32(globalId.x) * colPerThread; let globalRowStart = i32(workgroupId.y) * ${l}; let tileRowA = i32(localId.y) * ${g}; let tileColA = i32(localId.x) * ${b}; let tileRowB = i32(localId.y) * ${_}; // Loop over shared dimension. for (var t = 0; t < num_tiles; t = t + 1) { // Load one tile of A into local memory. for (var innerRow = 0; innerRow < ${g}; innerRow = innerRow + 1) { for (var innerCol = 0; innerCol < ${b}; innerCol = innerCol + 1) { let inputRow = tileRowA + innerRow; let inputCol = tileColA + innerCol; ${dw(o,t)} } } // Load one tile of B into local memory. for (var innerRow = 0; innerRow < ${_}; innerRow = innerRow + 1) { for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { let inputRow = tileRowB + innerRow; let inputCol = tileCol + innerCol; mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalCol + innerCol${t?", batchIndices":""}); } } kStart = kStart + tileInner; workgroupBarrier(); // Compute acc values for a single thread. var BCached : array<${n}, colPerThread>; for (var k = 0; k < tileInner; k = k + 1) { for (var inner = 0; inner < colPerThread; inner = inner + 1) { BCached[inner] = mm_Bsub[k][tileCol + inner]; } for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { ${yE(o)} for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol]; } } } workgroupBarrier(); } for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) { for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) { mm_write(batch, globalRow + innerRow, globalCol + innerCol, acc[innerRow][innerCol]); } } `;return` var mm_Asub : array, ${h}>; var mm_Bsub : array, ${i}>; const rowPerThread = ${r[1]}; const colPerThread = ${r[0]}; const tileInner = ${i}; @compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]}) fn main(@builtin(local_invocation_id) localId : vec3, @builtin(global_invocation_id) globalId : vec3, @builtin(workgroup_id) workgroupId : vec3) { let batch = ${a?"0":"i32(globalId.z)"}; ${t?`let batchIndices = ${t.offsetToIndices("u32(batch)")};`:""} let num_tiles = ${a?`${Math.ceil(s/i)}`:"(uniforms.dim_inner - 1) / tileInner + 1"}; var kStart = ${a?`i32(globalId.z) * ${s}`:"0"}; var acc : array, rowPerThread>; ${I} } `},_E=(r,e,n,t,o=!1)=>{let[i,a,s,u]=t,l=Fe(t[0].type.tensor);return` fn mm_readA(batch: i32, row: i32, colIn: i32, batchIndices: ${i.type.indices}) -> ${it(r,l)} { var value = ${it(r,l)}(0.0); let col = colIn * ${r}; if(row < uniforms.dim_a_outer && col < uniforms.dim_inner) { var aIndices: ${a.type.indices}; ${Ho("aIndices",a,a.rank-2,i.rank,"batchIndices")} ${a.indicesSet("aIndices",a.rank-2,"u32(row)")} ${a.indicesSet("aIndices",a.rank-1,"u32(colIn)")} value = ${a.getByIndices("aIndices")}; } return value; } fn mm_readB(batch: i32, row: i32, colIn: i32, batchIndices: ${i.type.indices}) -> ${it(r,l)} { var value = ${it(r,l)}(0.0); let col = colIn * ${r}; if(row < uniforms.dim_inner && col < uniforms.dim_b_outer) { var bIndices: ${s.type.indices}; ${Ho("bIndices",s,s.rank-2,i.rank,"batchIndices")} ${s.indicesSet("bIndices",s.rank-2,"u32(row)")} ${s.indicesSet("bIndices",s.rank-1,"u32(colIn)")} value = ${s.getByIndices("bIndices")}; } return value; } fn mm_write(batch: i32, row: i32, colIn: i32, valueIn: ${it(r,l)}) { let col = colIn * ${r}; if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) { var value = valueIn; let coords = vec3(batch, row, colIn); ${e?`value = value + ${o?"bias[colIn]":`${it(r,l)}(bias[row])`};`:""} ${n} ${u.setByIndices("vec3(coords)","value")} } } `},qo=(r,e,n,t,o=!1,i)=>{let a=r[0].dims,s=r[1].dims,u=a.slice(0,-2),l=s.slice(0,-2),d=t?t.slice(0,-2):n.slice(0,-2),p=D.size(d),h=a[a.length-2],g=a[a.length-1],b=s[s.length-1],_=g%4===0&&b%4===0,I=h<=8?[4,1,1]:[4,4,1],w=[8,8,1],v=[Math.ceil(b/w[0]/I[0]),Math.ceil(h/w[1]/I[1]),Math.ceil(p/w[2]/I[2])],S=_?4:1,A=[...u,h,g/S],P=A.length,C=[...l,g,b/S],R=C.length,x=[p,h,b/S],B=[{type:6,data:h},{type:6,data:b},{type:6,data:g}];Yt(e,B),B.push(...W(d,A,C));let G=["rank","rank"],Z=r.length>2;Z&&(B.push(...W(r[2].dims)),G.push("rank")),B.push(...W(x));let J=ie=>{let z=d.length,U=Ma("batchDims",r[0].dataType,z,1),te=Fe(r[0].dataType),oe=L("a",r[0].dataType,P,S),ee=L("b",r[1].dataType,R,S),de=V("result",r[0].dataType,x.length,S),ge=[oe,ee];if(Z){let q=o?S:1;ge.push(L("bias",r[2].dataType,r[2].dims.length,q))}let Te=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"}];Qt(e,Te);let mt=Fe(de.type.tensor),Ve=Jt(e,de.type.value,mt),F=_E(S,Z,Ve,[U,oe,ee,de],o);return` ${ie.registerUniforms(Te).registerInternalVariables(U).declareVariables(...ge,de)} ${F} ${_?Oc(I,w,te,U):Pc(I,w,te,U)} `};return{name:"MatMul",shaderCache:{hint:`${I};${e.activation};${_};${o}`,inputDependencies:G},getRunData:()=>({outputs:[{dims:i?i(n):n,dataType:r[0].dataType}],dispatchGroup:{x:v[0],y:v[1],z:v[2]},programUniforms:B}),getShaderSource:J}}});var wE,pw,fw=N(()=>{"use strict";ue();Gn();he();wr();Ha();cw();Ka();wE=(r,e,n,t,o=!1,i,a=4,s=4,u=4,l="f32")=>{let d=G=>{switch(G){case 1:return"resData = x[xIndex];";case 3:return`resData = vec3<${l}>(x[xIndex], x[xIndex + 1], x[xIndex + 2]);`;case 4:return"resData = x[xIndex / 4];";default:throw new Error(`innerElementSize ${G} is not supported.`)}},p=G=>{switch(G){case 1:return"return w[row * i32(uniforms.w_shape[3]) + colIn];";case 4:return"return w[row * i32(uniforms.w_shape[3]) / 4 + colIn];";default:throw new Error(`innerElementSize ${G} is not supported.`)}},h=r?` let coord = vec4(batch, xRow, xCol, xCh); `:` let coord = vec4(batch, xCh, xRow, xCol); `,g=r?` let coords = vec4( batch, row / outWidth, row % outWidth, col); `:` let coords = vec4( batch, row, col / outWidth, col % outWidth); `,b=r?"i32(uniforms.x_shape[1])":"i32(uniforms.x_shape[2])",_=r?"i32(uniforms.x_shape[2])":"i32(uniforms.x_shape[3])",I=r?"row":"col",w=r?"col":"row",v=` let inChannels = i32(uniforms.w_shape[2]); let outWidth = ${r?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"}; let outRow = ${I} / outWidth; let outCol = ${I} % outWidth; let WRow = ${w} / (i32(uniforms.w_shape[1]) * inChannels); let WCol = ${w} / inChannels % i32(uniforms.w_shape[1]); let xRow = outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0]; let xCol = outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1]; let xCh = ${w} % inChannels; var resData = ${it(a,l)}(0.0); // The bounds checking is always needed since we use it to pad zero for // the 'same' padding type. if (xRow >= 0 && xRow < ${b} && xCol >= 0 && xCol < ${_}) { ${h} let xIndex = getIndexFromCoords4D(coord, vec4(uniforms.x_shape)); ${d(a)} } return resData;`,S=r?e&&t?` let col = colIn * ${a}; ${v}`:` let col = colIn * ${a}; if (row < uniforms.dim_a_outer && col < uniforms.dim_inner) { ${v} } return ${it(a,l)}(0.0);`:t&&n?` let col = colIn * ${a}; ${v}`:` let col = colIn * ${a}; if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) { ${v} } return ${it(a,l)}(0.0);`,A=r?t&&n?p(s):` let col = colIn * ${s}; if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) { ${p(s)} } return ${it(s,l)}(0.0);`:` let col = colIn * ${s}; if (row < uniforms.dim_inner && col < uniforms.dim_a_outer) { ${p(s)} } return ${it(s,l)}(0.0);`,P=it(u,l),C=r?it(a,l):it(s,l),R=r?it(s,l):it(a,l),x=Jt(i,P,l);return` fn mm_readA(batch: i32, row : i32, colIn : i32) -> ${C} { ${r?S:A} } fn mm_readB(batch: i32, row : i32, colIn : i32) -> ${R} { ${r?A:S} } fn mm_write(batch: i32, row : i32, colIn : i32, valueIn : ${P}) { let col = colIn * ${u}; if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) { var value = valueIn; let outWidth = ${r?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"}; ${g} ${uw(o)} ${x} setOutputAtCoords(coords[0], coords[1], coords[2], coords[3], value); } }`},pw=(r,e,n,t,o,i,a,s,u)=>{let l=e.format==="NHWC",d=l?r[0].dims[3]:r[0].dims[1],p=n[0],h=l?n[2]:n[3],g=l?n[1]:n[2],b=l?n[3]:n[1],_=l&&(d%4===0||d%3===0)&&b%4===0,I=l?b:h*g,w=l?h*g:b,v=[8,8,1],S=t<=8?[4,1,1]:[4,4,1],A=[Math.ceil(I/v[0]/S[0]),Math.ceil(w/v[1]/S[1]),Math.ceil(p/v[2]/S[2])];me("verbose",()=>`[conv2d_mm_webgpu] dispatch = ${A}`);let P=_?l&&d%4!==0?3:4:1,C=v[1]*S[1],R=v[0]*S[0],x=Math.max(v[0]*P,v[1]),B=t%C===0,G=o%R===0,Z=i%x===0,J=_?[P,4,4]:[1,1,1],ie=[{type:6,data:t},{type:6,data:o},{type:6,data:i},{type:6,data:[e.pads[0],e.pads[1]]},{type:6,data:e.strides},{type:6,data:e.dilations}];Yt(e,ie),ie.push(...W(r[0].dims,r[1].dims));let z=["rank","rank"];a&&(ie.push(...W(r[2].dims)),z.push("rank")),ie.push(...W(n));let U=te=>{let oe=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"},{name:"pad",type:"i32",length:2},{name:"stride",type:"i32",length:2},{name:"dilation",type:"i32",length:2}];Qt(e,oe);let ee=_?4:1,de=Fe(r[0].dataType),ge=` fn setOutputAtIndex(flatIndex : i32, value : ${_?`vec4<${de}>`:de}) { result[flatIndex] = ${_?`vec4<${de}>`:de}(value); } fn setOutputAtCoords(d0 : i32, d1 : i32, d2 : i32, d3 : i32, value : ${_?`vec4<${de}>`:de}) { let flatIndex = getOutputIndexFromCoords(vec4(d0, d1, d2, d3)); setOutputAtIndex(flatIndex ${_?"/ 4":""}, value); }`,Te=L("x",r[0].dataType,r[0].dims.length,P===3?1:P),mt=L("w",r[1].dataType,r[1].dims.length,ee),Ve=[Te,mt],F=V("result",r[0].dataType,n.length,ee);if(a){let q=L("bias",r[2].dataType,r[2].dims.length,ee);Ve.push(q),ge+=` fn getBiasByOutputCoords(coords : vec4) -> ${_?`vec4<${de}>`:de} { return bias[coords.${l?"w":"y"}${_?"/ 4":""}]; }`}return` ${lw("uniforms.result_strides")} //struct Uniforms { xShape : vec4, wShape : vec4, outShape : vec4, // outShapeStrides: vec3, filterDims : vec2, pad : vec2, stride : vec2, // dilation : vec2, dimAOuter : i32, dimBOuter : i32, dimInner : i32 }; ${te.registerUniforms(oe).declareVariables(...Ve,F)} ${ge} ${wE(l,B,G,Z,a,e,J[0],J[1],J[2],de)} ${_?Oc(S,v,de,void 0,!l,x):Pc(S,v,de,void 0,!l,x,!1,void 0,s)}`};return{name:"Conv2DMatMul",shaderCache:{hint:`${e.cacheKey};${P};${_};${B};${G};${Z};${C};${R};${x}`,inputDependencies:z},getRunData:()=>({outputs:[{dims:u?u(n):n,dataType:r[0].dataType}],dispatchGroup:{x:A[0],y:A[1],z:A[2]},programUniforms:ie}),getShaderSource:U}}});var vE,hw,Xa,xE,mw,TE,gw,bw,yw=N(()=>{"use strict";ue();Gn();pe();he();wr();Ha();vE=r=>{let e=1;for(let n=0;ntypeof r=="number"?[r,r,r]:r,Xa=(r,e)=>e<=1?r:r+(r-1)*(e-1),xE=(r,e,n,t=1)=>{let o=Xa(e,t);return Math.floor((r[0]*(n-1)-n+o)/2)},mw=(r,e,n,t,o)=>{o==null&&(o=xE(r,e[0],t[0]));let i=[0,0,0,n];for(let a=0;a<3;a++)r[a]+2*o>=e[a]&&(i[a]=Math.trunc((r[a]-e[a]+2*o)/t[a]+1));return i},TE=(r,e,n,t,o,i,a,s,u,l)=>{let d,p,h,g;if(r==="VALID"&&(r=0),typeof r=="number"){d={top:r,bottom:r,left:r,right:r,front:r,back:r};let b=mw([e,n,t,1],[s,u,l],1,[o,i,a],r);p=b[0],h=b[1],g=b[2]}else if(Array.isArray(r)){if(!r.every((_,I,w)=>_===w[0]))throw Error(`Unsupported padding parameter: ${r}`);d={top:r[0],bottom:r[1],left:r[2],right:r[3],front:r[4],back:r[5]};let b=mw([e,n,t,1],[s,u,l],1,[o,i,a],r[0]);p=b[0],h=b[1],g=b[2]}else if(r==="SAME_UPPER"){p=Math.ceil(e/o),h=Math.ceil(n/i),g=Math.ceil(t/a);let b=(p-1)*o+s-e,_=(h-1)*i+u-n,I=(g-1)*a+l-t,w=Math.floor(b/2),v=b-w,S=Math.floor(_/2),A=_-S,P=Math.floor(I/2),C=I-P;d={top:S,bottom:A,left:P,right:C,front:w,back:v}}else throw Error(`Unknown padding parameter: ${r}`);return{padInfo:d,outDepth:p,outHeight:h,outWidth:g}},gw=(r,e,n,t,o,i=!1,a="channelsLast")=>{let s,u,l,d,p;if(a==="channelsLast")[s,u,l,d,p]=r;else if(a==="channelsFirst")[s,p,u,l,d]=r;else throw new Error(`Unknown dataFormat ${a}`);let[h,,g,b,_]=e,[I,w,v]=hw(n),[S,A,P]=hw(t),C=Xa(g,S),R=Xa(b,A),x=Xa(_,P),{padInfo:B,outDepth:G,outHeight:Z,outWidth:J}=TE(o,u,l,d,I,w,v,C,R,x),ie=i?h*p:h,z=[0,0,0,0,0];return a==="channelsFirst"?z=[s,ie,G,Z,J]:a==="channelsLast"&&(z=[s,G,Z,J,ie]),{batchSize:s,dataFormat:a,inDepth:u,inHeight:l,inWidth:d,inChannels:p,outDepth:G,outHeight:Z,outWidth:J,outChannels:ie,padInfo:B,strideDepth:I,strideHeight:w,strideWidth:v,filterDepth:g,filterHeight:b,filterWidth:_,effectiveFilterDepth:C,effectiveFilterHeight:R,effectiveFilterWidth:x,dilationDepth:S,dilationHeight:A,dilationWidth:P,inShape:r,outShape:z,filterShape:e}},bw=(r,e,n,t,o,i)=>{let a=i==="channelsLast",s=a?r[0].dims[3]:r[0].dims[1],u=!1,l=[64,1,1],d={x:n.map((v,S)=>S)},p=[Math.ceil(vE(d.x.map(v=>n[v]))/l[0]),1,1];me("verbose",()=>`[conv3d_naive_webgpu] dispatch = ${p}`);let h=u?a&&s%4!==0?3:4:1,g=D.size(n),b=[{type:12,data:g},{type:12,data:t},{type:12,data:o},{type:12,data:e.strides},{type:12,data:e.dilations}];Yt(e,b),b.push(...W(r[0].dims,r[1].dims));let _=["rank","rank"],I=r.length===3;I&&(b.push(...W(r[2].dims)),_.push("rank")),b.push(...W(n));let w=v=>{let S=[{name:"output_size",type:"u32"},{name:"filter_dims",type:"u32",length:t.length},{name:"pads",type:"u32",length:o.length},{name:"strides",type:"u32",length:e.strides.length},{name:"dilations",type:"u32",length:e.dilations.length}];Qt(e,S);let A=u?4:1,P=Fe(r[0].dataType),C=L("x",r[0].dataType,r[0].dims.length,h===3?1:h),R=L("W",r[1].dataType,r[1].dims.length,A),x=[C,R],B=V("result",r[0].dataType,n.length,A),G="";if(I){let ie=L("bias",r[2].dataType,r[2].dims.length,A);x.push(ie),G+=` fn getBiasByOutputCoords(coords : array) -> ${u?`vec4<${P}>`:P} { return bias[${a?Q("coords",4,5):Q("coords",1,5)}${u?"/ 4":""}]; }`}let Z=it(h,P),J=Jt(e,Z,P);return` ${G} fn getX(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 { let aIndices = array(d0, d1, d2, d3, d4); return ${C.getByIndices("aIndices")}; } fn getW(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 { let aIndices = array(d0, d1, d2, d3, d4); return ${R.getByIndices("aIndices")}; } ${v.registerUniforms(S).declareVariables(...x,B)} ${v.mainStart()} ${v.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let coords = ${B.offsetToIndices("global_idx")}; let batch = ${Q("coords",0,C.rank)}; let d2 = ${a?Q("coords",C.rank-1,C.rank):Q("coords",1,C.rank)}; let xFRCCorner = vec3(${a?Q("coords",1,C.rank):Q("coords",2,C.rank)}, ${a?Q("coords",2,C.rank):Q("coords",3,C.rank)}, ${a?Q("coords",3,C.rank):Q("coords",4,C.rank)}) * uniforms.strides - uniforms.pads; let xFCorner = xFRCCorner.x; let xRCorner = xFRCCorner.y; let xCCorner = xFRCCorner.z; let xShapeY = ${a?Q("uniforms.x_shape",1,C.rank):Q("uniforms.x_shape",2,C.rank)}; let xShapeZ = ${a?Q("uniforms.x_shape",2,C.rank):Q("uniforms.x_shape",3,C.rank)}; let xShapeW = ${a?Q("uniforms.x_shape",3,C.rank):Q("uniforms.x_shape",4,C.rank)}; let xShapeU = ${a?Q("uniforms.x_shape",4,C.rank):Q("uniforms.x_shape",1,C.rank)}; let inputDepthNearestVec4 = (xShapeU / 4) * 4; let inputDepthVec4Remainder = xShapeU % 4; var value = 0.0; for (var wF = 0u; wF < uniforms.filter_dims[0]; wF++) { let xF = xFCorner + wF * uniforms.dilations[0]; if (xF < 0 || xF >= xShapeY) { continue; } for (var wR = 0u; wR < uniforms.filter_dims[1]; wR++) { let xR = xRCorner + wR * uniforms.dilations[1]; if (xR < 0 || xR >= xShapeZ) { continue; } for (var wC = 0u; wC < uniforms.filter_dims[2]; wC++) { let xC = xCCorner + wC * uniforms.dilations[2]; if (xC < 0 || xC >= xShapeW) { continue; } for (var d1 = 0u; d1 < inputDepthNearestVec4; d1 += 4) { ${a?`let xValues = vec4( getX(batch, xF, xR, xC, d1), getX(batch, xF, xR, xC, d1 + 1), getX(batch, xF, xR, xC, d1 + 2), getX(batch, xF, xR, xC, d1 + 3)); `:`let xValues = vec4( getX(batch, d1, xF, xR, xC), getX(batch, d1 + 1, xF, xR, xC), getX(batch, d1 + 2, xF, xR, xC), getX(batch, d1 + 3, xF, xR, xC)); `} let wValues = vec4( getW(d2, d1, wF, wR, wC), getW(d2, d1 + 1, wF, wR, wC), getW(d2, d1 + 2, wF, wR, wC), getW(d2, d1 + 3, wF, wR, wC)); value += dot(xValues, wValues); } if (inputDepthVec4Remainder == 1) { ${a?`value += getX(batch, xF, xR, xC, inputDepthNearestVec4) * getW(d2, inputDepthNearestVec4, wF, wR, wC);`:`value += getX(batch, inputDepthNearestVec4, xF, xR, xC) * getW(d2, inputDepthNearestVec4, wF, wR, wC);`} } else if (inputDepthVec4Remainder == 2) { ${a?`let xValues = vec2( getX(batch, xF, xR, xC, inputDepthNearestVec4), getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1)); `:`let xValues = vec2( getX(batch, inputDepthNearestVec4, xF, xR, xC), getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC)); `} let wValues = vec2( getW(d2, inputDepthNearestVec4, wF, wR, wC), getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC)); value += dot(xValues, wValues); } else if (inputDepthVec4Remainder == 3) { ${a?`let xValues = vec3( getX(batch, xF, xR, xC, inputDepthNearestVec4), getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1), getX(batch, xF, xR, xC, inputDepthNearestVec4 + 2)); `:`let xValues = vec3( getX(batch, inputDepthNearestVec4, xF, xR, xC), getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC), getX(batch, inputDepthNearestVec4 + 2, xF, xR, xC)); `} let wValues = vec3( getW(d2, inputDepthNearestVec4, wF, wR, wC), getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC), getW(d2, inputDepthNearestVec4 + 2, wF, wR, wC)); value += dot(xValues, wValues); } } } } ${I?"value = value + getBiasByOutputCoords(coords)":""}; ${J} result[global_idx] = f32(value); }`};return{name:"Conv3DNaive",shaderCache:{hint:`${e.cacheKey};${a};${h};${I}`,inputDependencies:_},getRunData:()=>({outputs:[{dims:n,dataType:r[0].dataType}],dispatchGroup:{x:p[0],y:p[1],z:p[2]},programUniforms:b}),getShaderSource:w}}});var _w,ww,vw=N(()=>{"use strict";ue();pe();he();wr();_w=(r,e,n,t)=>{let o=r.length>2,i=o?"value += b[output_channel];":"",a=r[0].dims,s=r[1].dims,u=e.format==="NHWC",l=u?n[3]:n[1],d=l/e.group,p=u&&d>=4?Pe(l):1,h=D.size(n)/p,g=[{type:12,data:h},{type:12,data:e.dilations},{type:12,data:[e.strides[0],e.strides[1]]},{type:12,data:[e.pads[0],e.pads[1]]},{type:12,data:d}];Yt(e,g),g.push(...W(a,[s[0],s[1],s[2],s[3]/p]));let b=o?["rank","rank","rank"]:["rank","rank"];g.push(...W([n[0],n[1],n[2],n[3]/p]));let _=I=>{let w=V("output",r[0].dataType,n.length,p),v=Fe(w.type.tensor),S=Jt(e,w.type.value,v),A=L("x",r[0].dataType,a.length),P=L("w",r[1].dataType,s.length,p),C=[A,P];o&&C.push(L("b",r[2].dataType,r[2].dims,p));let R=[{name:"output_size",type:"u32"},{name:"dilations",type:"u32",length:e.dilations.length},{name:"strides",type:"u32",length:2},{name:"pads",type:"u32",length:2},{name:"output_channels_per_group",type:"u32"}];Qt(e,R);let x=u?` for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[0]; wHeight++) { let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0]; if (xHeight < 0u || xHeight >= uniforms.x_shape[1]) { continue; } for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[1]; wWidth++) { let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1]; if (xWidth < 0u || xWidth >= uniforms.x_shape[2]) { continue; } for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[2]; wInChannel++) { let input_channel = in_channel_offset + wInChannel; let xVal = ${A.get("batch","xHeight","xWidth","input_channel")}; let wVal = ${P.get("wHeight","wWidth","wInChannel","output_channel")}; value += xVal * wVal; } } } `:` for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[1]; wInChannel++) { let input_channel = in_channel_offset + wInChannel; for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[2]; wHeight++) { let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0]; if (xHeight < 0u || xHeight >= uniforms.x_shape[2]) { continue; } for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[3]; wWidth++) { let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1]; if (xWidth < 0u || xWidth >= uniforms.x_shape[3]) { continue; } let xVal = ${A.get("batch","input_channel","xHeight","xWidth")}; let wVal = ${P.get("output_channel","wInChannel","wHeight","wWidth")}; value += xVal * wVal; } } } `;return` ${I.registerUniforms(R).declareVariables(...C,w)} ${I.mainStart()} ${I.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let outputIndices = ${w.offsetToIndices("global_idx")}; let batch: u32 = outputIndices[0]; let output_channel: u32 = outputIndices[${u?3:1}]; let xRCCorner: vec2 = vec2(outputIndices[${u?1:2}], outputIndices[${u?2:3}]) * uniforms.strides - uniforms.pads; let group_id: u32 = output_channel * ${p} / uniforms.output_channels_per_group; var in_channel_offset = group_id * uniforms.w_shape[${u?2:1}]; var value: ${w.type.value} = ${w.type.value}(0); ${x} ${i} ${S} ${w.setByOffset("global_idx","value")} }`};return{name:"GroupedConv",shaderCache:{hint:`${e.cacheKey}_${p}`,inputDependencies:b},getRunData:()=>({outputs:[{dims:t?t(n):n,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:g}),getShaderSource:_}},ww=(r,e,n,t)=>{let o=r.length>2,i=Pe(n[3]),a=Pe(n[2]),s=D.size(n)/i/a,u=[r[0].dims[0],r[0].dims[1],r[0].dims[2],r[0].dims[3]/i],l=[r[1].dims[0],r[1].dims[1],r[1].dims[2],r[1].dims[3]/i],d=[n[0],n[1],n[2],n[3]/i],p=[{type:12,data:s},{type:6,data:[e.strides[0],e.strides[1]]},{type:6,data:[e.pads[0],e.pads[1]]}];Yt(e,p),p.push(...W(u,l,d));let h=(a-1)*e.strides[1]+l[1],g=b=>{let _=V("output",r[0].dataType,d.length,i),I=Fe(_.type.tensor),w=Jt(e,_.type.value,I),v=L("x",r[0].dataType,u.length,i),S=L("w",r[1].dataType,l.length,i),A=[v,S];o&&A.push(L("b",r[2].dataType,r[2].dims,i));let P=o?"value += b[output_channel];":"",C=[{name:"output_size",type:"u32"},{name:"strides",type:"i32",length:2},{name:"pads",type:"i32",length:2}];return Qt(e,C),` ${b.registerUniforms(C).declareVariables(...A,_)} ${b.mainStart()} ${b.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let width0 = uniforms.output_shape[3]; let output_channel = global_idx % width0; var index1 = global_idx / width0; let width1 = uniforms.output_shape[2] / ${a}u; let col = (index1 % width1) * ${a}u; index1 = index1 / width1; let row = index1 % uniforms.output_shape[1]; let batch = index1 / uniforms.output_shape[1]; let x_corner = vec2(i32(row), i32(col)) * uniforms.strides - uniforms.pads; var x_vals: array<${v.type.value}, ${h}>; var values: array<${_.type.value}, ${a}>; let input_channel = output_channel; // Use constant instead of uniform can give better performance for w's height/width. for (var w_height: u32 = 0u; w_height < ${l[0]}; w_height++) { let x_height = x_corner.x + i32(w_height); if (x_height >= 0 && u32(x_height) < uniforms.x_shape[1]) { for (var i = 0; i < ${h}; i++) { let x_width = x_corner.y + i; if (x_width >= 0 && u32(x_width) < uniforms.x_shape[2]) { x_vals[i] = ${v.get("batch","u32(x_height)","u32(x_width)","input_channel")}; } else { x_vals[i] = ${v.type.value}(0); } } for (var w_width: u32 = 0u; w_width < ${l[1]}; w_width++) { let w_val = ${S.get("w_height","w_width","0","output_channel")}; for (var i = 0u; i < ${a}u; i++) { values[i] = fma(x_vals[i * u32(uniforms.strides[1]) + w_width], w_val, values[i]); } } } } for (var i = 0u; i < ${a}u; i++) { var value = values[i]; ${P} ${w} ${_.set("batch","row","col + i","output_channel","value")}; } }`};return{name:"GroupedConv-Vectorize",shaderCache:{hint:`${e.cacheKey};${i};${a};${h};${l[0]};${l[1]}`,inputDependencies:o?["rank","rank","type"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:t?t(n):n,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(s/64)},programUniforms:p}),getShaderSource:g}}});var IE,Ec,SE,Cc,Dc,xw,$E,AE,kc,Tw=N(()=>{"use strict";pe();fw();yw();Ka();vw();wr();ja();Qn();IE=(r,e,n,t,o,i)=>{let a=r[0],s=r.slice(i?1:2,i?3:4),u=s.length,l=e[0],p=e.slice(2).map((b,_)=>b+(b-1)*(n[_]-1)),g=s.map((b,_)=>b+t[_]+t[_+u]).map((b,_)=>Math.floor((b-p[_]+o[_])/o[_]));return g.splice(0,0,a),g.splice(i?3:1,0,l),g},Ec=[2,3,1,0],SE=(r,e)=>{if(!r||r.length!==2&&r.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(r[0].dims.length>5)throw new Error("greater than 5D is not supported");if(r[0].dims.length!==r[1].dims.length)throw new Error("filter does not have same dimension as input");let n=r[0].dims[e.format==="NHWC"?r[0].dims.length-1:1],t=r[1].dims[1]*e.group;if(n!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(r.length===3&&(r[2].dims.length!==1||r[1].dims[0]!==r[2].dims[0]))throw new Error("invalid bias");let o=r[0].dims.length-2;if(e.dilations.length!==o)throw new Error(`dilations should be ${o}D`);if(e.strides.length!==o)throw new Error(`strides should be ${o}D`);if(e.pads.length!==o*2)throw new Error(`pads should be ${o*2}D`);if(e.kernelShape.length!==0&&e.kernelShape.length!==r[1].dims.length-2)throw new Error("invalid kernel shape")},Cc=(r,e)=>{let n=r.kernelShape.slice();n.length{let e=Wa(r),n=r.format,t=["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][r.auto_pad],o=r.dilations,i=r.group,a=r.kernel_shape,s=r.pads,u=r.strides,l=r.w_is_const();return{autoPad:t,format:n,dilations:o,group:i,kernelShape:a,pads:s,strides:u,wIsConst:l,...e,cacheKey:`${r.format};${e.activation};`}},xw=(r,e,n,t)=>{let o=n.format==="NHWC",i=IE(e[0].dims,e[1].dims,n.dilations,n.pads,n.strides,o);if(n.group!==1){let C=[e[0]];if(o){let x=r.kernelCustomData.wT??r.compute(lt(e[1],Ec),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!r.kernelCustomData.wT&&(r.kernelCustomData.wT=x),C.push(x)}else C.push(e[1]);e.length===3&&C.push(e[2]),!r.adapterInfo.isArchitecture("ampere")&&o&&e[1].dims[0]===n.group&&e[1].dims[1]===1&&n.dilations[0]===1&&n.dilations[1]===1?r.compute(ww(C,n,i,t),{inputs:C}):r.compute(_w(C,n,i,t),{inputs:C});return}let a=e.length===3,s=e[0].dims[o?1:2],u=e[0].dims[o?2:3],l=e[0].dims[o?3:1],d=e[1].dims[2],p=e[1].dims[3],h=i[o?1:2],g=i[o?2:3],b=i[o?3:1],_=o&&d===s&&p===u&&n.pads[0]===0&&n.pads[1]===0;if(_||d===1&&p===1&&n.dilations[0]===1&&n.dilations[1]===1&&n.strides[0]===1&&n.strides[1]===1&&n.pads[0]===0&&n.pads[1]===0){let C=i[0],R,x,B,G=[];if(o){let ie=r.kernelCustomData.wT??r.compute(lt(e[1],Ec),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];if(n.wIsConst&&!r.kernelCustomData.wT&&(r.kernelCustomData.wT=ie),_){let z=s*u*l;R=e[0].reshape([1,C,z]),x=ie.reshape([1,z,b]),B=[1,C,b]}else R=e[0].reshape([C,s*u,l]),x=ie.reshape([1,l,b]),B=[C,h*g,b];G.push(R),G.push(x)}else R=e[0].reshape([C,l,s*u]),x=e[1].reshape([1,b,l]),B=[C,b,h*g],G.push(x),G.push(R);a&&G.push(e[2]);let Z=B[2],J=G[0].dims[G[0].dims.length-1];Z<8&&J<8?r.compute(qa(G,n,i,B,o,t),{inputs:G}):r.compute(qo(G,n,i,B,o,t),{inputs:G});return}let I=!0,w=r.kernelCustomData.wT??r.compute(lt(e[1],Ec),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!r.kernelCustomData.wT&&(r.kernelCustomData.wT=w);let v=[e[0],w];a&&v.push(e[2]);let S=o?h*g:b,A=o?b:h*g,P=d*p*l;r.compute(pw(v,n,i,S,A,P,a,I,t),{inputs:v})},$E=(r,e)=>{let n=e.format==="NHWC",t=[r.inputs[0].reshape(n?[r.inputs[0].dims[0],1,r.inputs[0].dims[1],r.inputs[0].dims[2]]:[r.inputs[0].dims[0],r.inputs[0].dims[1],1,r.inputs[0].dims[2]]),r.inputs[1].reshape([r.inputs[1].dims[0],r.inputs[1].dims[1],1,r.inputs[1].dims[2]])];r.inputs.length===3&&t.push(r.inputs[2]);let o=[0,e.pads[0],0,e.pads[1]],i=[1].concat(e.strides),a=[1].concat(e.dilations),s=[1].concat(e.kernelShape),u=Cc({...e,pads:o,strides:i,dilations:a,kernelShape:s},t);xw(r,t,u,l=>n?[l[0],l[2],l[3]]:[l[0],l[1],l[3]])},AE=(r,e,n)=>{let t=n.format==="NHWC"?"channelsLast":"channelsFirst",o=Cc(n,e),i=n.autoPad==="NOTSET"?n.pads:n.autoPad,a=gw(e[0].dims,e[1].dims,n.strides,n.dilations,i,!1,t);r.compute(bw(e,o,a.outShape,[a.filterDepth,a.filterHeight,a.filterWidth],[a.padInfo.front,a.padInfo.top,a.padInfo.left],t))},kc=(r,e)=>{if(SE(r.inputs,e),r.inputs[0].dims.length===3)$E(r,e);else if(r.inputs[0].dims.length===5)AE(r,r.inputs,e);else{let n=Cc(e,r.inputs);xw(r,r.inputs,n)}}});var Iw,Sw=N(()=>{"use strict";ue();Gn();pe();he();Iw=(r,e,n)=>{let t=r.length>2,o=e.outputShape,i=e.format==="NHWC",a=e.group,s=r[1].dims,u=s[2]/a,l=s[3],d=i?Pe(u):1,p=i&&l===1&&u>=4,h=p?Math.floor(u/4)*4:Math.floor(u/d)*d,g=u-h,b=i?Pe(l):1,_=i?l===1?d:b:1,I=D.size(o)/b,w=[Math.ceil(I/64),1,1];me("verbose",()=>`[conv2d_backprop_webgpu] dispatch = ${w}`);let v=["rank","rank"],S=[e.strides[0],e.strides[1]],A=[e.kernelShape[i?1:2],e.kernelShape[i?2:3]],P=[e.dilations[0],e.dilations[1]],C=[A[0]+(e.dilations[0]<=1?0:(e.kernelShape[i?1:2]-1)*(e.dilations[0]-1)),A[1]+(e.dilations[1]<=1?0:(e.kernelShape[i?2:3]-1)*(e.dilations[1]-1))],R=[C[0]-1-Math.floor((e.pads[0]+e.pads[2])/2),C[1]-1-Math.floor((e.pads[1]+e.pads[3])/2)],x=[{type:12,data:I},{type:12,data:S},{type:12,data:A},{type:12,data:P},{type:12,data:C},{type:6,data:R},{type:12,data:h},{type:12,data:u},{type:12,data:l},...W(r[0].dims,r[1].dims)];t&&(x.push(...W(r[2].dims)),v.push("rank")),x.push(...W(o));let B=G=>{let Z=[{name:"output_size",type:"u32"},{name:"strides",type:"u32",length:S.length},{name:"filter_dims",type:"u32",length:A.length},{name:"dilations",type:"u32",length:A.length},{name:"effective_filter_dims",type:"u32",length:C.length},{name:"pads",type:"i32",length:R.length},{name:"input_channels_per_group_int",type:"u32"},{name:"input_channels_per_group",type:"u32"},{name:"output_channels_per_group",type:"u32"}],J=Fe(r[0].dataType),ie=i?1:2,z=i?2:3,U=i?3:1,te=L("W",r[1].dataType,r[1].dims.length,_),oe=L("Dy",r[0].dataType,r[0].dims.length,d),ee=[oe,te];t&&ee.push(L("bias",r[2].dataType,[o[U]].length,b));let de=V("result",r[0].dataType,o.length,b),ge=()=>{let Ve="";if(p)d===4?Ve+=` let xValue = ${oe.getByOffset("x_offset")}; let wValue = ${te.getByOffset("w_offset")}; dotProd = dotProd + dot(xValue, wValue); x_offset += 1u; w_offset += 1u;`:d===2?Ve+=` dotProd = dotProd + dot(vec4<${J}>(${oe.getByOffset("x_offset")}, ${oe.getByOffset("x_offset + 1u")}), vec4<${J}>(${te.getByOffset("w_offset")}, ${te.getByOffset("w_offset + 1u")})); x_offset += 2u; w_offset += 2u;`:d===1&&(Ve+=` dotProd = dotProd + dot(vec4<${J}>(${oe.getByOffset("x_offset")}, ${oe.getByOffset("x_offset + 1u")}, ${oe.getByOffset("x_offset + 2u")}, ${oe.getByOffset("x_offset + 3u")}), vec4<${J}>(${te.getByOffset("w_offset")}, ${te.getByOffset("w_offset + 1u")}, ${te.getByOffset("w_offset + 2u")}, ${te.getByOffset("w_offset + 3u")})); x_offset += 4u; w_offset += 4u;`);else if(Ve+=` let xValue = ${i?oe.getByOffset(`${oe.indicesToOffset(`${oe.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${d}`):oe.get("batch","inputChannel","idyR","idyC")}; `,d===1)Ve+=` let w_offset = ${te.indicesToOffset(`${te.type.indices}(u32(wRPerm), u32(wCPerm), inputChannel, wOutChannel)`)}; let wValue = ${te.getByOffset(`w_offset / ${_}`)}; dotProd = dotProd + xValue * wValue;`;else for(let F=0;F{if(g===0)return"";if(!p)throw new Error(`packInputAs4 ${p} is not true.`);let Ve="";if(d===1){Ve+="dotProd = dotProd";for(let F=0;F(i32(r), i32(c)) - uniforms.pads; let dyRCorner = dyCorner.x; let dyCCorner = dyCorner.y; let groupId = d1 / uniforms.output_channels_per_group; let wOutChannel = d1 - groupId * uniforms.output_channels_per_group; // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1). // ? = to be determined. : = across all values in that axis. var dotProd = ${de.type.value}(0.0); var wR: u32 = 0; if (uniforms.dilations.x == 1) { // Minimum wR >= 0 that satisfies (dyRCorner + wR) % (uniforms.strides.x) == 0 wR = u32(((dyRCorner + i32(uniforms.strides.x) - 1) / i32(uniforms.strides.x)) * i32(uniforms.strides.x) - dyRCorner); } for (; wR < uniforms.effective_filter_dims.x; wR = wR + 1) { if (wR % uniforms.dilations.x != 0) { continue; } let dyR = (${J}(dyRCorner) + ${J}(wR)) / ${J}(uniforms.strides[0]); let wRPerm = uniforms.filter_dims.x - 1 - wR / uniforms.dilations.x; if (dyR < 0.0 || dyR >= ${J}(uniforms.Dy_shape[${ie}]) || fract(dyR) > 0.0 || wRPerm < 0) { continue; } let idyR: u32 = u32(dyR); var wC: u32 = 0; if (uniforms.dilations.y == 1) { // Minimum wC >= 0 that satisfies (dyCCorner + wC) % (uniforms.strides.y) == 0 wC = u32(((dyCCorner + i32(uniforms.strides.y) - 1) / i32(uniforms.strides.y)) * i32(uniforms.strides.y) - dyCCorner); } for (; wC < uniforms.effective_filter_dims.y; wC = wC + 1) { if (wC % uniforms.dilations.y != 0) { continue; } let dyC = (${J}(dyCCorner) + ${J}(wC)) / ${J}(uniforms.strides.y); let wCPerm = uniforms.filter_dims.y - 1 - wC / uniforms.dilations.y; if (dyC < 0.0 || dyC >= ${J}(uniforms.Dy_shape[${z}]) || fract(dyC) > 0.0 || wCPerm < 0) { continue; } let idyC: u32 = u32(dyC); var inputChannel = groupId * uniforms.input_channels_per_group; ${p?` var x_offset = ${oe.indicesToOffset(`${oe.type.indices}(batch, idyR, idyC, inputChannel)`)} / ${d}; var w_offset = ${te.indicesToOffset(`${te.type.indices}(wRPerm, wCPerm, inputChannel, wOutChannel)`)} / ${_}; `:""} for (var d2: u32 = 0; d2 < uniforms.input_channels_per_group_int; d2 = d2 + ${p?4:d}) { ${ge()} inputChannel = inputChannel + ${p?4:d}; } ${Te()} wC = wC + uniforms.strides.y - 1; } wR = wR + uniforms.strides[0] - 1; } let value = dotProd${t?` + bias[d1 / ${b}]`:""}; ${de.setByOffset("global_idx","value")}; `;return` ${G.registerUniforms(Z).declareVariables(...ee,de)} ${G.mainStart()} ${G.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}; ${mt}}`};return{name:"ConvTranspose2D",shaderCache:{hint:`${e.cacheKey};${d}${_}${b}${p}${g}`,inputDependencies:v},getRunData:()=>({dispatchGroup:{x:w[0],y:w[1],z:w[2]},outputs:[{dims:n?n(o):o,dataType:r[0].dataType}],programUniforms:x}),getShaderSource:B}}});var OE,PE,EE,$w,Aw,CE,Ow,DE,Pw,Ew=N(()=>{"use strict";Sw();wr();Qn();OE=(r,e,n,t,o,i)=>(r-1)*e+n+(t-1)*o+1-i,PE=(r,e,n,t,o)=>{let i=Math.floor(r/2);e==="SAME_UPPER"?(n[t]=i,n[o]=r-i):e==="SAME_LOWER"&&(n[t]=r-i,n[o]=i)},EE=(r,e,n,t,o,i,a,s,u,l)=>{let d=r.length-2,p=l.length===0;u.length{let n=r.kernelShape.slice();if(r.kernelShape.length===0||r.kernelShape.reduce((p,h)=>p*h,1)===0){n.length=0;for(let p=2;pp+h,0)===0){let p=e[0].dims.length-2;u=new Array(p).fill(1)}let l=r.strides.slice();if(l.reduce((p,h)=>p+h,0)===0){let p=e[0].dims.length-2;l=new Array(p).fill(1)}EE(s,n,u,r.autoPad,r.group,o,l,t,a,i);let d=Object.assign({},r);return Object.assign(d,{kernelShape:n,pads:o,outputPadding:a,outputShape:i,dilations:u,strides:l}),d},Aw=r=>{let e=Wa(r),n=r.format,t=["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][typeof r.autoPad>"u"?0:r.autoPad],o=r.dilations,i=r.group??1,a=r.kernelShape,s=r.pads,u=r.strides,l=r.wIsConst(),d=r.outputPadding,p=r.outputShape;return{autoPad:t,format:n,dilations:o,group:i,kernelShape:a,outputPadding:d,outputShape:p,pads:s,strides:u,wIsConst:l,...e,cacheKey:`${r.format};${e.activation};`}},CE=(r,e)=>{if(!r||r.length!==2&&r.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(r[0].dims.length!==4&&r[0].dims.length!==3)throw new Error("currently only support 2-dimensional conv");if(r[0].dims.length!==r[1].dims.length)throw new Error("filter does not have same dimension as input");let n=r[0].dims[e.format==="NHWC"?r[0].dims.length-1:1],t=r[1].dims[0];if(n!==t)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");let o=r[1].dims[1]*e.group;if(r.length===3&&(r[2].dims.length!==1||r[2].dims[0]!==o))throw new Error("invalid bias");let i=r[0].dims.length-2;if(e.dilations.reduce((d,p)=>d+p,0)>0&&e.dilations.length!==i)throw new Error(`dilations should be ${i}D`);if(e.strides.reduce((d,p)=>d+p,0)>0&&e.strides.length!==i)throw new Error(`strides should be ${i}D`);if(e.pads.reduce((d,p)=>d+p,0)>0&&e.pads.length!==i*2)throw new Error(`pads should be ${i*2}D`);if(e.outputPadding.length!==i&&e.outputPadding.length!==0)throw new Error(`output_padding should be ${i}D`);if(e.kernelShape.reduce((d,p)=>d+p,0)>0&&e.kernelShape.length!==0&&e.kernelShape.length!==r[1].dims.length-2)throw new Error("invalid kernel shape");if(e.outputShape.length!==0&&e.outputShape.length!==r[0].dims.length-2)throw new Error("invalid output shape")},Ow=(r,e,n,t)=>{let o=r.kernelCustomData.wT??r.compute(lt(e[1],[2,3,0,1]),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!r.kernelCustomData.wT&&(r.kernelCustomData.wT=o);let i=[e[0],o];e.length===3&&i.push(e[2]),r.compute(Iw(i,n,t),{inputs:i})},DE=(r,e)=>{let n=e.format==="NHWC",t=[r.inputs[0].reshape(n?[r.inputs[0].dims[0],1,r.inputs[0].dims[1],r.inputs[0].dims[2]]:[r.inputs[0].dims[0],r.inputs[0].dims[1],1,r.inputs[0].dims[2]]),r.inputs[1].reshape([r.inputs[1].dims[0],r.inputs[1].dims[1],1,r.inputs[1].dims[2]])];r.inputs.length===3&&t.push(r.inputs[2]);let o=e.kernelShape;(o.length===0||o[0]===0)&&(o=[r.inputs[1].dims[2]]);let i=e.dilations;(i.length===0||i[0]===0)&&(i=[1]);let a=e.strides;(a.length===0||a[0]===0)&&(a=[1]);let s=e.pads;s.length===0&&(s=[0,0]),s=[0,s[0],0,s[1]],a=[1].concat(a),i=[1].concat(i),o=[1].concat(o);let u=e.outputPadding;u=[0].concat(u);let l=$w({...e,pads:s,strides:a,dilations:i,kernelShape:o,outputPadding:u},t);Ow(r,t,l,d=>n?[d[0],d[2],d[3]]:[d[0],d[1],d[3]])},Pw=(r,e)=>{if(CE(r.inputs,e),r.inputs[0].dims.length===3)DE(r,e);else{let n=$w(e,r.inputs);Ow(r,r.inputs,n)}}});var kE,Cw,Dw,kw=N(()=>{"use strict";ue();pe();Ye();he();kE=(r,e,n,t)=>{let o=D.size(e),i=e.length,a=L("input",r,i),s=V("output",r,i),u=n.dataType===6?n.getInt32Array()[0]:Number(n.getBigInt64Array()[0]),l=D.normalizeAxis(u,i),d=p=>{let h=` i32(${a.indicesGet("inputIndices","uniforms.axis")}) `,g=Q("uniforms.input_shape","uniforms.axis",i),b=t.reverse?h+(t.exclusive?" + 1":""):"0",_=t.reverse?g:h+(t.exclusive?"":" + 1");return` ${p.registerUniform("outputSize","u32").registerUniform("axis","u32").declareVariables(a,s)} ${p.mainStart()} ${p.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} var inputIndices = ${s.offsetToIndices("global_idx")}; var sum = ${s.type.value}(0); let first : i32 = ${b}; let last : i32 = ${_}; for (var i : i32 = first; i < last; i++) { ${a.indicesSet("inputIndices","uniforms.axis","u32(i)")}; sum = sum + ${a.getByIndices("inputIndices")}; } ${s.setByOffset("global_idx","sum")}; }`};return{name:"CumSum",shaderCache:{hint:t.cacheKey,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:e,dataType:r}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:[{type:12,data:o},{type:12,data:l},...W(e,e)]}),getShaderSource:d}},Cw=(r,e)=>{let n=r.inputs[0].dims,t=r.inputs[0].dataType,o=r.inputs[1];r.compute(kE(t,n,o,e),{inputs:[0]})},Dw=r=>{let e=r.exclusive===1,n=r.reverse===1;return le({exclusive:e,reverse:n})}});var NE,LE,RE,Nw,Lw,Rw=N(()=>{"use strict";ue();pe();Ye();he();NE=r=>{if(!r||r.length!==1)throw new Error("DepthToSpace requires 1 input.");if(r[0].dims.length!==4)throw new Error("DepthToSpace requires 4D input.")},LE=(r,e,n,t)=>{let o=[];o.push(`fn perm(i: ${t.type.indices}) -> ${n.type.indices} { var a: ${n.type.indices};`);for(let i=0;i{let n,t,o,i,a,s,u=e.format==="NHWC",l=e.blocksize,d=e.mode==="DCR";u?([n,t,o,i]=r.dims,a=d?[n,t,o,l,l,i/l**2]:[n,t,o,i/l**2,l,l],s=d?[0,1,3,2,4,5]:[0,1,4,2,5,3]):([n,t,o,i]=[r.dims[0],r.dims[2],r.dims[3],r.dims[1]],a=d?[n,l,l,i/l**2,t,o]:[n,i/l**2,l,l,t,o],s=d?[0,3,4,1,5,2]:[0,1,4,2,5,3]);let p=r.reshape(a),h=p.dims.length,g=r.dataType,b=L("a",g,h),_=V("output",g,h),I=w=>` ${w.registerUniform("output_size","u32").declareVariables(b,_)} ${LE(s,h,b,_)} ${w.mainStart()} ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let indices = ${_.offsetToIndices("global_idx")}; let aIndices = perm(indices); ${_.setByOffset("global_idx",b.getByIndices("aIndices"))} }`;return{name:"DepthToSpace",shaderCache:{hint:`${r.dims};${e.blocksize};${e.mode}`,inputDependencies:["rank"]},getRunData:w=>{let v=u?[n,t*l,o*l,i/l**2]:[n,i/l**2,t*l,o*l],S=D.size(v),A=p.dims,P=D.sortBasedOnPerm(A,s);return{outputs:[{dims:v,dataType:w[0].dataType}],dispatchGroup:{x:Math.ceil(S/64)},programUniforms:[{type:12,data:S},...W(A,P)]}},getShaderSource:I}},Nw=(r,e)=>{NE(r.inputs),r.compute(RE(r.inputs[0],e))},Lw=r=>le({blocksize:r.blocksize,mode:r.mode,format:r.format})});var Nc,Za,zw,zE,ME,Lc,Rc,Mw,BE,Bw,Fw,Vw=N(()=>{"use strict";ue();pe();Ye();he();Nc="[a-zA-Z]|\\.\\.\\.",Za="("+Nc+")+",zw="^"+Za+"$",zE="("+Za+",)*"+Za,ME="^"+zE+"$",Lc=class{constructor(e=-1){this.symbolToIndices=new Map,this.inputIndex=e}addSymbol(e,n){let t=this.symbolToIndices.get(e);t===void 0?t=[n]:t.push(n),this.symbolToIndices.set(e,t)}},Rc=class{constructor(e,n){this.equation=n;this.hasEllipsis=!1,this.symbolToInfo=new Map,this.lhs=new Array,this.outputDims=[];let[t,o]=n.includes("->")?n.split("->",2):[n,""];if(!t.match(RegExp(ME)))throw new Error("Invalid LHS term");if(t.split(",").forEach((s,u)=>{let l=e[u].dims.slice();if(!s.match(RegExp(zw)))throw new Error("Invalid LHS term");let d=this.processTerm(s,!0,l,u);this.lhs.push(d)}),o==="")o+=[...this.symbolToInfo.entries()].filter(([s,u])=>u.count===1||s==="...").map(([s])=>s).join("");else if(!o.match(RegExp(Za)))throw new Error("Invalid RHS");o.match(RegExp(Nc,"g"))?.forEach(s=>{if(s==="...")this.outputDims=this.outputDims.concat(this.ellipsisDims);else{let u=this.symbolToInfo.get(s);if(u===void 0)throw new Error("Invalid RHS symbol");this.outputDims.push(u.dimValue)}}),this.rhs=this.processTerm(o,!1,this.outputDims)}addSymbol(e,n,t){let o=this.symbolToInfo.get(e);if(o!==void 0){if(o.dimValue!==n&&o.count!==1)throw new Error("Dimension mismatch");o.count++,o.inputIndices.push(t)}else o={count:1,dimValue:n,inputIndices:[t]};this.symbolToInfo.set(e,o)}processTerm(e,n,t,o=-1){let i=t.length,a=!1,s=[],u=0;if(!e.match(RegExp(zw))&&!n&&e!=="")throw new Error("Invalid LHS term");let l=e.match(RegExp(Nc,"g")),d=new Lc(o);return l?.forEach((p,h)=>{if(p==="..."){if(a)throw new Error("Only one ellipsis is allowed per input term");a=!0;let g=i-l.length+1;if(g<0)throw new Error("Ellipsis out of bounds");if(s=t.slice(u,u+g),this.hasEllipsis){if(this.ellipsisDims.length!==s.length||this.ellipsisDims.toString()!==s.toString())throw new Error("Ellipsis dimensions mismatch")}else if(n)this.hasEllipsis=!0,this.ellipsisDims=s;else throw new Error("Ellipsis must be specified in the LHS");for(let b=0;br+"_max",BE=(r,e,n,t)=>{let i=r.map(d=>d.length).map((d,p)=>L(`input${p}`,e,d)),a=D.size(t),s=V("output",e,t.length),u=[...n.symbolToInfo.keys()].filter(d=>!n.rhs.symbolToIndices.has(d)),l=d=>{let p=[],h="var prod = 1.0;",g="var sum = 0.0;",b="sum += prod;",_=[],I=[],w=[],v=[],S=n.symbolToInfo.size===n.rhs.symbolToIndices.size;n.symbolToInfo.forEach((P,C)=>{if(n.rhs.symbolToIndices.has(C)){let R=n.rhs.symbolToIndices.get(C)?.[0];R!==void 0&&n.lhs.forEach((x,B)=>{if(P.inputIndices.includes(B)){let G=x.symbolToIndices.get(C);if(G===void 0)throw new Error("Invalid symbol error");G.forEach(Z=>{p.push(`${i[B].indicesSet(`input${B}Indices`,Z,s.indicesGet("outputIndices",R))}`)})}})}else n.lhs.forEach((R,x)=>{if(P.inputIndices.includes(x)){let B=R.symbolToIndices.get(C);if(B===void 0)throw new Error("Invalid symbol error");B.forEach(G=>{_.push(`${i[x].indicesSet(`input${x}Indices`,G,`${C}`)}`)}),v.push(`prod *= ${i[x].getByIndices(`input${x}Indices`)};`)}}),I.push(`for(var ${C}: u32 = 0; ${C} < uniforms.${Mw(C)}; ${C}++) {`),w.push("}")});let A=S?[...p,`let sum = ${i.map((P,C)=>P.getByIndices(`input${C}Indices`)).join(" * ")};`]:[...p,g,...I,..._,h,...v,b,...w];return` ${d.registerUniforms(u.map(P=>({name:`${Mw(P)}`,type:"u32"}))).registerUniform("outputSize","u32").declareVariables(...i,s)} ${d.mainStart()} ${d.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} var outputIndices = ${s.offsetToIndices("global_idx")}; ${i.map((P,C)=>`var input${C}Indices: ${i[C].type.indices};`).join(` `)} ${A.join(` `)}; ${s.setByOffset("global_idx","sum")}; }`};return{name:"Einsum",shaderCache:{hint:n.equation,inputDependencies:r.map(()=>"rank")},getRunData:()=>{let d=u.filter(h=>n.symbolToInfo.has(h)).map(h=>({type:12,data:n.symbolToInfo.get(h)?.dimValue||0}));d.push({type:12,data:a});let p=r.map((h,g)=>[...W(h)]).reduce((h,g)=>h.concat(g),d);return p.push(...W(t)),{outputs:[{dims:t,dataType:e}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:p}},getShaderSource:l}},Bw=(r,e)=>{let n=new Rc(r.inputs,e.equation),t=n.outputDims,o=r.inputs.map((i,a)=>i.dims);r.compute(BE(o,r.inputs[0].dataType,n,t))},Fw=r=>{let e=r.equation.replace(/\s+/g,"");return le({equation:e})}});var FE,Gw,VE,GE,Uw,Ww=N(()=>{"use strict";ue();pe();he();FE=r=>{if(!r||r.length!==2)throw new Error("Expand requires 2 input.");let e=r[0].dims,n=Array.from(r[1].getBigInt64Array(),Number),t=n.length{let n=r.length-e.length,t=[];for(let o=0;or.length>e.length?Gw(r,e):Gw(e,r),GE=r=>{let e=r[0].dims,n=Array.from(r[1].getBigInt64Array(),Number),t=VE(e,n),o=r[0].dataType,i=o===9||D.size(e)===1,a=o===9||e.length>0&&e[e.length-1]%4===0?4:1,s=i||t.length>0&&t[t.length-1]%4===0?4:1,u=Math.ceil(D.size(t)/s),l=p=>{let h=L("input",o,e.length,a),g=V("output",o,t.length,s),b;if(o===9){let _=(I,w,v="")=>` let outputIndices${w} = ${g.offsetToIndices(`outputOffset + ${w}u`)}; let offset${w} = ${h.broadcastedIndicesToOffset(`outputIndices${w}`,g)}; let index${w} = offset${w} / 4u; let component${w} = offset${w} % 4u; ${I}[${w}] = ${v}(${h.getByOffset(`index${w}`)}[component${w}]); `;b=` let outputOffset = global_idx * ${s}; var data = vec4(0); ${_("data",0,"u32")} ${_("data",1,"u32")} ${_("data",2,"u32")} ${_("data",3,"u32")} ${g.setByOffset("global_idx","data")} }`}else b=` let outputIndices = ${g.offsetToIndices(`global_idx * ${s}`)}; let inputOffset = ${h.broadcastedIndicesToOffset("outputIndices",g)}; let data = ${g.type.value}(${h.getByOffset(`inputOffset / ${a}`)}); ${g.setByOffset("global_idx","data")} }`;return` ${p.registerUniform("vec_size","u32").declareVariables(h,g)} ${p.mainStart()} ${p.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} ${b}`},d=[{type:12,data:u},...W(e,t)];return{name:"Expand",shaderCache:{hint:`${t.length};${a}${s}`,inputDependencies:["rank"]},getShaderSource:l,getRunData:()=>({outputs:[{dims:t,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:d})}},Uw=r=>{FE(r.inputs),r.compute(GE(r.inputs),{inputs:[0]})}});var UE,Hw,qw=N(()=>{"use strict";ue();pe();he();Ua();UE=r=>{let e=r[0].dataType,n=D.size(r[0].dims),t=D.size(r[1].dims),o=t%4===0,i=a=>{let s=L("x",e,[1],4),u=L("bias",e,[1],4),l=V("y",e,[1],4),d=[{name:"output_vec_size",type:"u32"},{name:"bias_size",type:"u32"}],p=g=>` let bias${g}_offset: u32 = (global_idx * 4 + ${g}) % uniforms.bias_size; let bias${g} = ${u.getByOffset(`bias${g}_offset / 4`)}[bias${g}_offset % 4];`,h=o?` let bias = ${u.getByOffset("global_idx % (uniforms.bias_size / 4)")};`:`${p(0)}${p(1)}${p(2)}${p(3)} let bias = ${s.type.value}(bias0, bias1, bias2, bias3);`;return`${a.registerUniforms(d).declareVariables(s,u,l)} ${$c(ut(e))} ${a.mainStart(Ur)} ${a.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_vec_size")} let x = ${s.getByOffset("global_idx")}; ${h} let x_in = x + bias; ${l.setByOffset("global_idx",Ac("x_in"))} }`};return{name:"FastGeluWithBias",shaderCache:{hint:`${o}`,inputDependencies:["type","type"]},getShaderSource:i,getRunData:a=>({outputs:[{dims:a[0].dims,dataType:a[0].dataType}],programUniforms:[{type:12,data:Math.ceil(n/4)},{type:12,data:t}],dispatchGroup:{x:Math.ceil(n/Ur/4)}})}},Hw=r=>{r.inputs.length<2||D.size(r.inputs[1].dims)===0?V0(r):r.compute(UE(r.inputs))}});var WE,HE,jw,Kw,Xw=N(()=>{"use strict";ue();pe();Ye();he();WE=r=>{if(!r||r.length!==2)throw new Error("Gather requires 2 inputs.")},HE=(r,e)=>{let n=r[0].dims,t=r[1].dims,o=n.length,i=D.normalizeAxis(e.axis,o),a=n.slice(0);a.splice(i,1,...t);let s=n[i],u=r[0].dataType===9?4:1,l=Math.ceil(D.size(a)/u),d=[{type:12,data:l},{type:6,data:s},{type:12,data:i},...W(r[0].dims,r[1].dims,a)],p=h=>{let g=L("data",r[0].dataType,r[0].dims.length,u),b=L("inputIndices",r[1].dataType,r[1].dims.length),_=V("output",r[0].dataType,a.length,u),I=v=>{let S=t.length,A=`var indicesIndices${v} = ${b.type.indices}(0);`;for(let P=0;P1?`indicesIndices${v}[${P}]`:`indicesIndices${v}`} = ${a.length>1?`outputIndices${v}[uniforms.axis + ${P}]`:`outputIndices${v}`};`;A+=` var idx${v} = ${b.getByIndices(`indicesIndices${v}`)}; if (idx${v} < 0) { idx${v} = idx${v} + uniforms.axisDimLimit; } var dataIndices${v} : ${g.type.indices}; `;for(let P=0,C=0;P1?`dataIndices${v}[${P}]`:`dataIndices${v}`} = u32(idx${v});`,C+=S):(A+=`${o>1?`dataIndices${v}[${P}]`:`dataIndices${v}`} = ${a.length>1?`outputIndices${v}[${C}]`:`outputIndices${v}`};`,C++);return A},w;if(r[0].dataType===9){let v=(S,A,P="")=>` let outputIndices${A} = ${_.offsetToIndices(`outputOffset + ${A}u`)}; ${I(A)}; let offset${A} = ${g.indicesToOffset(`dataIndices${A}`)}; let index${A} = offset${A} / 4u; let component${A} = offset${A} % 4u; ${S}[${A}] = ${P}(${g.getByOffset(`index${A}`)}[component${A}]); `;w=` let outputOffset = global_idx * ${u}; var value = vec4(0); ${v("value",0,"u32")} ${v("value",1,"u32")} ${v("value",2,"u32")} ${v("value",3,"u32")} ${_.setByOffset("global_idx","value")} `}else w=` let outputIndices = ${_.offsetToIndices("global_idx")}; ${I("")}; let value = ${g.getByIndices("dataIndices")}; ${_.setByOffset("global_idx","value")}; `;return` ${h.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(g,b,_)} ${h.mainStart()} ${h.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} ${w} }`};return{name:"Gather",shaderCache:{hint:e.cacheKey,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:a,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:d}),getShaderSource:p}},jw=r=>le({axis:r.axis}),Kw=(r,e)=>{let n=r.inputs;WE(n),r.compute(HE(r.inputs,e))}});var qE,Zw,Jw,Yw=N(()=>{"use strict";ue();pe();he();qE=(r,e,n,t,o,i,a,s,u)=>{let l=[{type:12,data:i},{type:12,data:t},{type:12,data:o},{type:12,data:n},{type:12,data:a},{type:12,data:s},{type:12,data:u}],d=[i];l.push(...W(e.dims,d));let p=h=>{let g=L("indices_data",e.dataType,e.dims.length),b=V("input_slice_offsets_data",12,1,1),_=[g,b],I=[{name:"output_size",type:"u32"},{name:"batch_dims",type:"u32"},{name:"input_dims",type:"u32",length:o.length},{name:"sizes_from_slice_dims_data",type:"u32",length:n.length},{name:"num_slices_per_batch",type:"u32"},{name:"input_batch_stride",type:"u32"},{name:"num_slice_dims",type:"u32"}];return` ${h.registerUniforms(I).declareVariables(..._)} ${h.mainStart()} ${h.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let batch_idx = global_idx / uniforms.num_slices_per_batch; let base_offset = batch_idx * uniforms.input_batch_stride; let slice_indices_base_offset = global_idx * uniforms.num_slice_dims; var relative_slice_offset = 0; for (var dim_idx = 0u; dim_idx < uniforms.num_slice_dims; dim_idx ++) { var index = i32(indices_data[dim_idx + slice_indices_base_offset].x); let input_dim_idx = uniforms.batch_dims + dim_idx; if (index < 0) { ${o.length===1?"index += i32(uniforms.input_dims);":"index += i32(uniforms.input_dims[input_dim_idx]);"} } ${n.length===1?"relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data);":"relative_slice_offset += index * i32(uniforms.sizes_from_slice_dims_data[dim_idx]);"} } input_slice_offsets_data[global_idx] = base_offset + u32(relative_slice_offset); }`};return r.compute({name:"computeSliceOffsets",shaderCache:{hint:`${o.length}_${n.length}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:d,dataType:r.inputs[1].dataType}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:l}),getShaderSource:p},{inputs:[e],outputs:[-1]})[0]},Zw=(r,e)=>{let n=r.inputs,t=n[0].dims,o=n[0].dataType,i=n[1].dims,a=i[i.length-1],s=D.sizeToDimension(i,i.length-1),u=D.sizeFromDimension(t,e.batchDims+a),l=D.sizeToDimension(t,e.batchDims),d=D.sizeFromDimension(t,e.batchDims),p=s/l,h=new Array(a),g=u;for(let A=0;At.length)throw new Error("last dimension of indices must not be larger than rank of input tensor");let I=i.slice(0,-1).concat(t.slice(_)),w=D.size(I),v=[{type:12,data:w},{type:12,data:u},...W(n[0].dims,b.dims,I)],S=A=>{let P=L("data",n[0].dataType,n[0].dims.length),C=L("slice_offsets",12,b.dims.length),R=V("output",n[0].dataType,I.length);return` ${A.registerUniform("output_size","u32").registerUniform("slice_size","u32").declareVariables(P,C,R)} ${A.mainStart()} ${A.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let slice_offset = slice_offsets[global_idx / uniforms.slice_size]; output[global_idx] = data[u32(slice_offset) + global_idx % uniforms.slice_size]; }`};r.compute({name:"GatherND",shaderCache:{hint:e.cacheKey,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:I,dataType:o}],dispatchGroup:{x:Math.ceil(w/64)},programUniforms:v}),getShaderSource:S},{inputs:[n[0],b]})},Jw=r=>({batchDims:r.batch_dims,cacheKey:""})});var jE,KE,Qw,ev,tv=N(()=>{"use strict";ue();pe();Ye();he();jE=(r,e)=>{if(r.length<3||r.length>4)throw new Error("GatherBlockQuantized requires 3 or 4 inputs.");let n=D.normalizeAxis(e.quantizeAxis,r[0].dims.length),t=e.blockSize,o=r[0],i=r[2],a=r.length===4?r[3]:void 0;if(i.dims.length!==o.dims.length||!o.dims.map((s,u)=>u===n?Math.ceil(s/t)===i.dims[u]:s===i.dims[u]).reduce((s,u)=>s&&u,!0))throw new Error("Scales must have the same rank as the input tensor and the dims should match except on gatherAxis.");if(a){if(a.dataType!==o.dataType)throw new Error("Zero point must have the same data type as the input tensor.");if(a.dims.length!==i.dims.length||!a.dims.map((s,u)=>s===i.dims[u]).reduce((s,u)=>s&&u,!0))throw new Error("Zero point must have the same rank as the input tensor and the dims should match except on quantizeAxis.")}},KE=(r,e)=>{let n=r[0].dims,t=r[1].dims,o=n.length,i=D.normalizeAxis(e.gatherAxis,o),a=D.normalizeAxis(e.quantizeAxis,o),s=n.slice(0);s.splice(i,1,...t);let u=D.size(s),l=r[2].dataType,p=r[0].dataType===22,h=[{type:12,data:u},{type:12,data:a},{type:12,data:i},{type:12,data:e.blockSize},...W(...r.map((b,_)=>b.dims),s)],g=b=>{let _=L("data",r[0].dataType,r[0].dims.length),I=L("inputIndices",r[1].dataType,r[1].dims.length),w=L("scales",r[2].dataType,r[2].dims.length),v=r.length>3?L("zeroPoint",r[3].dataType,r[3].dims.length):void 0,S=V("output",l,s.length),A=[_,I,w];v&&A.push(v);let P=[{name:"output_size",type:"u32"},{name:"quantize_axis",type:"u32"},{name:"gather_axis",type:"u32"},{name:"block_size",type:"u32"}];return` ${b.registerUniforms(P).declareVariables(...A,S)} ${b.mainStart()} let output_indices = ${S.offsetToIndices("global_idx")}; var indices_indices = ${I.type.indices}(0); ${t.length>1?` for (var i: u32 = 0; i < ${t.length}; i++) { let index = ${S.indicesGet("output_indices","uniforms.gather_axis + i")}; ${I.indicesSet("indices_indices","i","index")}; }`:`indices_indices = ${S.indicesGet("output_indices","uniforms.gather_axis")};`}; var data_indices = ${_.type.indices}(0); for (var i: u32 = 0; i < uniforms.gather_axis; i++) { let index = ${S.indicesGet("output_indices","i")}; ${_.indicesSet("data_indices","i","index")}; } var index_from_indices = ${I.getByIndices("indices_indices")}; if (index_from_indices < 0) { index_from_indices += ${n[i]}; } ${_.indicesSet("data_indices","uniforms.gather_axis","u32(index_from_indices)")}; for (var i = uniforms.gather_axis + 1; i < ${s.length}; i++) { let index = ${S.indicesGet("output_indices",`i + ${t.length} - 1`)}; ${_.indicesSet("data_indices","i","index")}; } let data_offset = ${_.indicesToOffset("data_indices")}; let data_index = data_offset % 8; // Convert 4-bit packed data to 8-bit packed data. let packed_4bit_quantized_data = ${_.getByOffset("data_offset / 8")}; let packed_8bit_quantized_data = (packed_4bit_quantized_data >> (4 * (data_index % 2))) & 0x0f0f0f0f; let quantized_data_vec = ${p?"unpack4xI8":"unpack4xU8"}(u32(packed_8bit_quantized_data)); let quantized_data = quantized_data_vec[data_index / 2]; var scale_indices = data_indices; let quantize_axis_index = ${w.indicesGet("data_indices","uniforms.quantize_axis")} / uniforms.block_size; ${w.indicesSet("scale_indices","uniforms.quantize_axis","quantize_axis_index")}; var scale = ${w.getByIndices("scale_indices")}; ${v?` let zero_point_indices = scale_indices; let zero_point_offset = ${v.indicesToOffset("zero_point_indices")}; let zero_point_index = zero_point_offset % 8; let packed_4bit_zero_points = ${v.getByOffset("zero_point_offset / 8")}; let packed_8bit_zero_points = (packed_4bit_zero_points >> (4 * (zero_point_index % 2))) & 0x0f0f0f0f; let zero_point_vec = ${p?"unpack4xI8":"unpack4xU8"}(u32(packed_8bit_zero_points)); let zero_point = zero_point_vec[zero_point_index / 2];`:"var zero_point = 0"}; let dequantized_data = ${ut(l)}(quantized_data - zero_point) * scale; ${S.setByOffset("global_idx","dequantized_data")}; }`};return{name:"GatherBlockQuantized",shaderCache:{hint:`${e.cacheKey};${r.filter((b,_)=>_!==1).map(b=>b.dims.join("_")).join(";")}`,inputDependencies:Array.from({length:r.length},(b,_)=>"rank")},getRunData:()=>({outputs:[{dims:s,dataType:l}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:h}),getShaderSource:g}},Qw=(r,e)=>{let n=r.inputs;jE(n,e),r.compute(KE(r.inputs,e))},ev=r=>le({blockSize:r.blockSize,gatherAxis:r.gatherAxis,quantizeAxis:r.quantizeAxis})});var XE,ZE,nv,rv,ov=N(()=>{"use strict";ue();pe();Ye();he();XE=r=>{if(!r||r.length!==2)throw new Error("GatherElements requires 2 inputs.");if(r[0].dims.length<1)throw new Error("GatherElements requires that the data input be rank >= 1.");if(r[0].dims.length!==r[1].dims.length)throw new Error(`GatherElements requires that the data input and indices input tensors be of same rank.`)},ZE=(r,e)=>{let n=r[0].dims,t=r[0].dataType,o=n.length,i=r[1].dims,a=r[1].dataType,s=D.normalizeAxis(e.axis,o),u=n[s],l=i.slice(0),d=D.size(l),p=L("input",t,o),h=L("indicesInput",a,i.length),g=V("output",t,l.length),b=[{type:12,data:d},{type:6,data:u},{type:12,data:s}];return b.push(...W(n,i,l)),{name:"GatherElements",shaderCache:{inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:l,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:b}),getShaderSource:w=>` ${w.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(p,h,g)} ${w.mainStart()} ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} let outputIndices = ${g.offsetToIndices("global_idx")}; var idx = ${h.getByOffset("global_idx")}; if (idx < 0) { idx = idx + uniforms.axisDimLimit; } var inputIndices = ${p.type.indices}(outputIndices); ${p.indicesSet("inputIndices","uniforms.axis","u32(idx)")}; let value = ${p.getByIndices("inputIndices")}; ${g.setByOffset("global_idx","value")}; }`}},nv=r=>le({axis:r.axis}),rv=(r,e)=>{let n=r.inputs;XE(n),r.compute(ZE(r.inputs,e))}});var JE,YE,iv,av,sv=N(()=>{"use strict";ue();pe();he();JE=r=>{if(!r)throw new Error("Input is missing");if(r.length<2||r.length>3)throw new Error("Invaid input number.");if(r.length===3&&r[2].dims.length>2)throw new Error("Invalid input shape of C");if(r[0].dataType!==r[1].dataType||r.length===3&&r[0].dataType!==r[2].dataType)throw new Error("Input types are mismatched")},YE=(r,e)=>{let n=r[0].dims.slice(),t=r[1].dims.slice(),[o,i,a]=Ea.getShapeOfGemmResult(n,e.transA,t,e.transB,r.length===3?r[2].dims:void 0),s=[o,i];if(!s)throw new Error("Can't use gemm on the given tensors");let u=16,l=Math.ceil(i/u),d=Math.ceil(o/u),p=!0,h=D.size(s),g=[{type:12,data:p?l:h},{type:12,data:o},{type:12,data:i},{type:12,data:a},{type:1,data:e.alpha},{type:1,data:e.beta}],b=["type","type"];r.length===3&&(g.push(...W(r[2].dims)),b.push("rank")),g.push(...W(s));let _=w=>{let v="";e.transA&&e.transB?v="value += a[k * uniforms.M + m] * b[n * uniforms.K + k];":e.transA&&!e.transB?v="value += a[k * uniforms.M + m] * b[k * uniforms.N + n];":!e.transA&&e.transB?v="value += a[m * uniforms.K + k] * b[n * uniforms.K + k];":!e.transA&&!e.transB&&(v="value += a[m * uniforms.K + k] * b[k * uniforms.N + n];");let S=e.alpha===1?"":"value *= uniforms.alpha;",A=L("a",r[0].dataType,r[0].dims),P=L("b",r[1].dataType,r[1].dims),C=A.type.value,R=null,x=[A,P];r.length===3&&(R=L("c",r[2].dataType,r[2].dims.length),x.push(R));let B=V("output",r[0].dataType,s.length);x.push(B);let G=[{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"},{name:"alpha",type:"f32"},{name:"beta",type:"f32"}];return` ${w.registerUniforms(G).declareVariables(...x)} ${w.mainStart()} ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let m = global_idx / uniforms.N; let n = global_idx % uniforms.N; var value = ${C}(0); for (var k: u32 = 0u; k < uniforms.K; k++) { ${v} } ${S} ${R!=null?`let cOffset = ${R.broadcastedIndicesToOffset("vec2(m, n)",B)}; value += ${C}(uniforms.beta) * ${R.getByOffset("cOffset")};`:""} output[global_idx] = value; }`},I=w=>{let v=L("a",r[0].dataType,r[0].dims),S=L("b",r[1].dataType,r[1].dims),A=null,P=[v,S];r.length===3&&(A=L("c",r[2].dataType,r[2].dims.length),P.push(A));let C=V("output",r[0].dataType,s.length);P.push(C);let R=[{name:"num_tile_n",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"},{name:"alpha",type:"f32"},{name:"beta",type:"f32"}],x="",B="";e.transA&&e.transB?(B=` var col = tile_row_start + local_id.x; var row = k_start + local_id.y; if (col < uniforms.M && row < uniforms.K) { tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col]; } else { tile_a[local_id.y][local_id.x] = ${v.type.value}(0); } col = k_start + local_id.x; row = tile_col_start + local_id.y; if (col < uniforms.K && row < uniforms.N) { tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col]; } else { tile_b[local_id.y][local_id.x] = ${S.type.value}(0); } `,x="value += tile_a[k][local_id.y] * tile_b[local_id.x][k];"):e.transA&&!e.transB?(B=` var col = tile_row_start + local_id.x; var row = k_start + local_id.y; if (col < uniforms.M && row < uniforms.K) { tile_a[local_id.y][local_id.x] = a[row * uniforms.M + col]; } else { tile_a[local_id.y][local_id.x] = ${v.type.value}(0); } col = tile_col_start + local_id.x; row = k_start + local_id.y; if (col < uniforms.N && row < uniforms.K) { tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col]; } else { tile_b[local_id.y][local_id.x] = ${S.type.value}(0); } `,x="value += tile_a[k][local_id.y] * tile_b[k][local_id.x];"):!e.transA&&e.transB?(B=` var col = k_start + local_id.x; var row = tile_row_start + local_id.y; if (col < uniforms.K && row < uniforms.M) { tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col]; } else { tile_a[local_id.y][local_id.x] = ${v.type.value}(0); } col = k_start + local_id.x; row = tile_col_start + local_id.y; if (col < uniforms.K && row < uniforms.N) { tile_b[local_id.y][local_id.x] = b[row * uniforms.K + col]; } else { tile_b[local_id.y][local_id.x] = ${S.type.value}(0); } `,x="value += tile_a[local_id.y][k] * tile_b[local_id.x][k];"):!e.transA&&!e.transB&&(B=` var col = k_start + local_id.x; var row = tile_row_start + local_id.y; if (col < uniforms.K && row < uniforms.M) { tile_a[local_id.y][local_id.x] = a[row * uniforms.K + col]; } else { tile_a[local_id.y][local_id.x] = ${v.type.value}(0); } col = tile_col_start + local_id.x; row = k_start + local_id.y; if (col < uniforms.N && row < uniforms.K) { tile_b[local_id.y][local_id.x] = b[row * uniforms.N + col]; } else { tile_b[local_id.y][local_id.x] = ${S.type.value}(0); } `,x="value += tile_a[local_id.y][k] * tile_b[k][local_id.x];");let G=e.alpha===1?"":"value *= uniforms.alpha;";return` ${w.registerUniforms(R).declareVariables(...P)} var tile_a: array, ${u}>; var tile_b: array, ${u}>; ${w.mainStart([u,u,1])} let tile_col_start = (workgroup_index % uniforms.num_tile_n) * ${u}; let tile_row_start = (workgroup_index / uniforms.num_tile_n) * ${u}; let num_tiles = (uniforms.K - 1) / ${u} + 1; var k_start = 0u; var value = ${C.type.value}(0); for (var t: u32 = 0u; t < num_tiles; t++) { ${B} k_start = k_start + ${u}; workgroupBarrier(); for (var k: u32 = 0u; k < ${u}; k++) { ${x} } workgroupBarrier(); } ${G} let m = tile_row_start + local_id.y; let n = tile_col_start + local_id.x; ${A!=null?`let cOffset = ${A.broadcastedIndicesToOffset("vec2(m, n)",C)}; value += ${C.type.value}(uniforms.beta) * ${A.getByOffset("cOffset")};`:""} if (m < uniforms.M && n < uniforms.N) { output[m * uniforms.N + n] = value; } }`};return p?{name:"GemmShared",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:b},getRunData:()=>({outputs:[{dims:s,dataType:r[0].dataType}],dispatchGroup:{x:l*d},programUniforms:g}),getShaderSource:I}:{name:"Gemm",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:b},getRunData:()=>({outputs:[{dims:s,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:g}),getShaderSource:_}},iv=r=>{let e=r.transA,n=r.transB,t=r.alpha,o=r.beta;return{transA:e,transB:n,alpha:t,beta:o,cacheKey:`${r.transA};${r.transB};${r.alpha===1}`}},av=(r,e)=>{JE(r.inputs),r.compute(YE(r.inputs,e))}});var er,vr,po,fo,QE,eC,tC,nC,rC,oC,iC,aC,uv,lv,cv=N(()=>{"use strict";ue();pe();Ye();he();[er,vr,po,fo]=[0,1,2,3],QE=r=>{if(r[0].dims.length!==4)throw new Error("only 4-D tensor is supported.");if(r[0].dims.length!==r[1].dims.length)throw new Error("input dimensions must be equal to grid dimensions");if(r[0].dims.length-2!==r[1].dims[r[1].dims.length-1])throw new Error(`last dimension of grid must be equal to ${r[0].dims.length-2}`);if(r[0].dims[0]!==r[1].dims[0])throw new Error("grid batch size must match input batch size")},eC=` fn gs_get_cubic_coeffs(x: f32) -> vec4 { let cubic_alpha = -0.75f; let x_abs = abs(x); var coeffs: vec4; coeffs[0] = (((cubic_alpha * (x_abs + 1) - 5 * cubic_alpha) * (x_abs + 1) + 8 * cubic_alpha) * (x_abs + 1) - 4 * cubic_alpha); coeffs[1] = (((cubic_alpha + 2) * x_abs - (cubic_alpha + 3)) * x_abs * x_abs + 1); coeffs[2] = (((cubic_alpha + 2) * (1 - x_abs) - (cubic_alpha + 3)) * (1 - x_abs) * (1 - x_abs) + 1); coeffs[3] = (((cubic_alpha * (2 - x_abs) - 5 * cubic_alpha) * (2 - x_abs) + 8 * cubic_alpha) * (2 - x_abs) - 4 * cubic_alpha); return coeffs; } `,tC=r=>` fn gs_bicubic_interpolate(p: mat4x4<${r}>, x: f32, y: f32) -> ${r} { var v: vec4; var coeffs = gs_get_cubic_coeffs(x); for (var i = 0; i < 4; i++) { v[i] = coeffs[0] * p[i][0] + coeffs[1] * p[i][1] + coeffs[2] * p[i][2] + coeffs[3] * p[i][3]; } coeffs = gs_get_cubic_coeffs(y); let pixel = ${r}(coeffs[0] * v[0] + coeffs[1] * v[1] + coeffs[2] * v[2] + coeffs[3] * v[3]); return pixel; } `,nC=r=>` fn gs_denormalize(n: f32, length: i32) -> f32 { ${r.alignCorners===0?` // alignCorners: false => [-1, 1] to [-0.5, length - 0.5] return ((n + 1.0) * f32(length) - 1.0) / 2.0; `:` // alignCorners: true => [-1, 1] to [0, length - 1] return (n + 1.0) / 2.0 * (f32(length - 1)); `} } `,rC=r=>` ${r.paddingMode==="reflection"?` fn gs_reflect(x: i32, x_min: f32, x_max: f32) -> u32 { var dx = 0.0; var fx = f32(x); let range = x_max - x_min; if (fx < x_min) { dx = x_min - fx; let n = u32(dx / range); let r = dx - f32(n) * range; if (n % 2 == 0) { fx = x_min + r; } else { fx = x_max - r; } } else if (fx > x_max) { dx = fx - x_max; let n = u32(dx / range); let r = dx - f32(n) * range; if (n % 2 == 0) { fx = x_max - r; } else { fx = x_min + r; } } return u32(fx); }`:""} `,oC=(r,e,n)=>` fn pixel_at_grid(r: i32, c: i32, H: i32, W: i32, batch: u32, channel: u32, border: vec4) -> ${e} { var pixel = ${e}(0); var indices = vec4(0); indices[${er}] = batch; indices[${vr}] = channel;`+(()=>{switch(n.paddingMode){case"zeros":return` if (r >= 0 && r < H && c >=0 && c < W) { indices[${po}] = u32(r); indices[${fo}] = u32(c); } else { return ${e}(0); } `;case"border":return` indices[${po}] = u32(clamp(r, 0, H - 1)); indices[${fo}] = u32(clamp(c, 0, W - 1)); `;case"reflection":return` indices[${po}] = gs_reflect(r, border[1], border[3]); indices[${fo}] = gs_reflect(c, border[0], border[2]); `;default:throw new Error(`padding mode ${n.paddingMode} is not supported`)}})()+` return ${r.getByIndices("indices")}; } `,iC=(r,e,n)=>(()=>{switch(n.mode){case"nearest":return` let result = pixel_at_grid(i32(round(y)), i32(round(x)), H_in, W_in, indices[${er}], indices[${vr}], border); `;case"bilinear":return` let x1 = i32(floor(x)); let y1 = i32(floor(y)); let x2 = x1 + 1; let y2 = y1 + 1; let p11 = pixel_at_grid(y1, x1, H_in, W_in, indices[${er}], indices[${vr}], border); let p12 = pixel_at_grid(y1, x2, H_in, W_in, indices[${er}], indices[${vr}], border); let p21 = pixel_at_grid(y2, x1, H_in, W_in, indices[${er}], indices[${vr}], border); let p22 = pixel_at_grid(y2, x2, H_in, W_in, indices[${er}], indices[${vr}], border); let dx2 = ${e}(f32(x2) - x); let dx1 = ${e}(x - f32(x1)); let dy2 = ${e}(f32(y2) - y); let dy1 = ${e}(y - f32(y1)); let result = dy2 * (dx2 * p11 + dx1 * p12) + dy1 * (dx2 * p21 + dx1 * p22); `;case"bicubic":return` let x0 = i32(floor(x)) - 1; let y0 = i32(floor(y)) - 1; var p: mat4x4<${e}>; for (var h = 0; h < 4; h++) { for (var w = 0; w < 4; w++) { p[h][w] = pixel_at_grid(h + y0, w + x0, H_in, W_in, indices[${er}], indices[${vr}], border); } } let dx = x - f32(x0 + 1); let dy = y - f32(y0 + 1); let result = gs_bicubic_interpolate(p, dx, dy); `;default:throw new Error(`mode ${n.mode} is not supported`)}})()+`${r.setByOffset("global_idx","result")}`,aC=(r,e)=>{let n=L("x",r[0].dataType,r[0].dims.length),t=[r[1].dims[0],r[1].dims[1],r[1].dims[2]],o=L("grid",r[1].dataType,t.length,2),i=[r[0].dims[0],r[0].dims[1],r[1].dims[1],r[1].dims[2]];e.format==="NHWC"&&(i=[r[0].dims[0],r[1].dims[1],r[1].dims[2],r[0].dims[3]],[er,vr,po,fo]=[0,3,1,2]);let a=V("output",r[0].dataType,i.length),s=n.type.value,u=D.size(i),l=[{type:12,data:u},...W(r[0].dims,t,i)],d=p=>` ${p.registerUniform("output_size","u32").declareVariables(n,o,a)} ${eC} ${tC(s)} ${nC(e)} ${rC(e)} ${oC(n,s,e)} ${p.mainStart()} ${p.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let H_in = i32(uniforms.x_shape[${po}]); let W_in = i32(uniforms.x_shape[${fo}]); ${e.alignCorners===0?` let x_min = -0.5; let x_max = f32(W_in) - 0.5; let y_min = -0.5; let y_max = f32(H_in) - 0.5; `:` let x_min = 0.0; let x_max = f32(W_in) - 1.0; let y_min = 0.0; let y_max = f32(H_in) - 1.0; `}; let border = vec4(x_min, y_min, x_max, y_max); let indices = ${a.offsetToIndices("global_idx")}; var grid_indices = vec3(indices[${er}], indices[${po}], indices[${fo}]); let nxy = ${o.getByIndices("grid_indices")}; var x = gs_denormalize(f32(nxy[0]), W_in); var y = gs_denormalize(f32(nxy[1]), H_in); ${iC(a,s,e)} }`;return{name:"GridSample",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:["type","type"]},getRunData:p=>{let h=D.size(i);return{outputs:[{dims:i,dataType:p[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:l}},getShaderSource:d}},uv=(r,e)=>{QE(r.inputs),r.compute(aC(r.inputs,e))},lv=r=>le({alignCorners:r.align_corners,mode:r.mode,paddingMode:r.padding_mode,format:r.format})});var It,lC,pv,dv,cC,jo,fv,zc=N(()=>{"use strict";ue();pe();Ye();Ra();Va();he();Qn();It=(r,e)=>r.length>e&&r[e].dims.length>0?r[e]:void 0,lC=(r,e)=>{let n=r[0],t=It(r,1),o=It(r,2),i=It(r,3),a=It(r,4),s=It(r,5),u=It(r,6),l=It(r,7);if(n.dims.length!==3&&n.dims.length!==5)throw new Error("Input query is expected to have 3 or 5 dimensions");let d=n.dims[0],p=n.dims[1],h=n.dims.length===3?n.dims[2]:e.numHeads*n.dims[4],g=p,b=0,_=0,I=Math.floor(h/e.numHeads);if(u&&l&&D.size(u.dims)&&D.size(l.dims)){if(u.dims.length!==4)throw new Error('Input "past_key" is expected to have 4 dimensions');if(u.dims[0]!==d||u.dims[1]!==e.numHeads||u.dims[3]!==I)throw new Error('Input "past_key" shape (batch_size, num_heads, past_sequence_length, head_size)');if(l.dims[0]!==d||l.dims[1]!==e.numHeads||l.dims[3]!==I)throw new Error('Input "past_value" shape (batch_size, num_heads, past_sequence_length, head_size)');if(u.dims[2]!==l.dims[2])throw new Error('Input "past_key" and "past_value" shall have same dim 2 (past_sequence_length)');if(l.dims.length!==4)throw new Error('Input "past_value" is expected to have 4 dimensions');b=u.dims[2],_=u.dims[2]}else if(u&&D.size(u.dims)||l&&D.size(l.dims))throw new Error('Input "past_key" and "past_value" shall be both present or both absent');let w;if(t&&D.size(t.dims)>0){if(n.dims.length!==3)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(t.dims.length<3||t.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(n.dims[0]!==t.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(t.dims.length===3){if(t.dims[2]!==n.dims[2])throw new Error('Input "query" and "key" shall have same dim 2 (hidden_size)');w=2,g=t.dims[1]}else if(t.dims.length===5){if(t.dims[2]!==e.numHeads||t.dims[3]!==2||t.dims[4]!==I)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(o)throw new Error('Expect "value" be none when "key" has packed kv format.');w=5,g=t.dims[1]}else{if(t.dims[1]!==e.numHeads||t.dims[3]!==I)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');w=0,g=t.dims[2]}}else{if(n.dims.length!==5)throw new Error('Input "query" is expected to have 5 dimensions when key is empty');if(n.dims[2]!==e.numHeads||n.dims[3]!==3)throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');w=3}if(i&&D.size(i.dims)>0){if(i.dims.length!==1)throw new Error('Input "bias" is expected to have 1 dimension');if(t&&t.dims.length===5&&t.dims[3]===2)throw new Error("bias is not allowed for packed kv.")}let v=b+g,S=0;if(a&&D.size(a.dims)>0){S=8;let R=a.dims;throw R.length===1?R[0]===d?S=1:R[0]===3*d+2&&(S=3):R.length===2&&R[0]===d&&R[1]===v&&(S=5),S===8?new Error('Input "key_padding_mask" shape shall be (batch_size) or (batch_size, total_sequence_length)'):new Error("Mask not supported")}let A=!1,P=h;if(o&&D.size(o.dims)>0){if(o.dims.length!==3&&o.dims.length!==4)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(n.dims[0]!==o.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(o.dims.length===3){if(g!==o.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');P=o.dims[2]}else{if(g!==o.dims[2])throw new Error('Input "key" and "value" shall have the same dim 2 (kv_sequence_length)');P=o.dims[1]*o.dims[3],A=!0}}let C=!1;if(a&&D.size(a.dims)>0)throw new Error("Key padding mask is not supported");if(s&&D.size(s.dims)>0){if(s.dims.length!==4)throw new Error('Input "attention_bias" is expected to have 4 dimensions');if(s.dims[0]!==d||s.dims[1]!==e.numHeads||s.dims[2]!==p||s.dims[3]!==v)throw new Error('Expect "attention_bias" shape (batch_size, num_heads, sequence_length, total_sequence_length)')}return{batchSize:d,sequenceLength:p,pastSequenceLength:b,kvSequenceLength:g,totalSequenceLength:v,maxSequenceLength:_,inputHiddenSize:0,hiddenSize:h,vHiddenSize:P,headSize:I,vHeadSize:Math.floor(P/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:S,scale:e.scale,broadcastResPosBias:C,passPastInKv:A,qkvFormat:w}},pv=r=>le({...r}),dv=le({perm:[0,2,1,3]}),cC=(r,e,n,t,o,i,a)=>{let s=[t,o,i],u=D.size(s),l=[{type:12,data:u},{type:12,data:a},{type:12,data:i}],d=p=>{let h=V("qkv_with_bias",e.dataType,s),g=L("qkv",e.dataType,s),b=L("bias",n.dataType,s),_=[{name:"output_size",type:"u32"},{name:"bias_offset",type:"u32"},{name:"hidden_size",type:"u32"}];return` ${p.registerUniforms(_).declareVariables(g,b,h)} ${p.mainStart()} ${p.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let bias_offset_idx = (global_idx % uniforms.hidden_size) + uniforms.bias_offset; qkv_with_bias[global_idx] = qkv[global_idx] + bias[bias_offset_idx]; }`};return r.compute({name:"MultiHeadAttentionAddBias",shaderCache:{inputDependencies:["type","type"]},getRunData:()=>({outputs:[{dims:s,dataType:e.dataType,gpuDataType:0}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:l}),getShaderSource:d},{inputs:[e,n],outputs:[-1]})[0]},jo=(r,e,n,t,o,i,a,s)=>{let u=i;if(a&&D.size(a.dims)>0){if(t===1)throw new Error("AddBiasReshape is not implemented. Please export your model with packed QKV or KV");return u=cC(r,i,a,e,t,n*o,s),u=u.reshape([e,t,n,o]),n===1||t===1?u:r.compute(lt(u,dv.perm),{inputs:[u],outputs:[-1]})[0]}else return i.dims.length===3&&(u=i.reshape([e,t,n,o])),n===1||t===1?u:r.compute(lt(u,dv.perm),{inputs:[u],outputs:[-1]})[0]},fv=(r,e)=>{let n=lC(r.inputs,e),t=r.inputs[0],o=It(r.inputs,1),i=It(r.inputs,2),a=It(r.inputs,3),s=It(r.inputs,4),u=It(r.inputs,5),l=It(r.inputs,6),d=It(r.inputs,7);if(t.dims.length===5)throw new Error("Packed QKV is not implemented");if(o?.dims.length===5)throw new Error("Packed KV is not implemented");let p=o&&i&&o.dims.length===4&&i.dims.length===4,h=jo(r,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,t,a,0);if(p)return co(r,h,o,i,s,void 0,l,d,u,n);if(!o||!i)throw new Error("key and value must be provided");let g=jo(r,n.batchSize,n.numHeads,n.kvSequenceLength,n.headSize,o,a,n.hiddenSize),b=jo(r,n.batchSize,n.numHeads,n.kvSequenceLength,n.vHeadSize,i,a,2*n.hiddenSize);co(r,h,g,b,s,void 0,l,d,u,n)}});var dC,pC,fC,hC,Mc,hv,mv,Bc=N(()=>{"use strict";ue();pe();Ye();he();dC=r=>{if(!r||r.length<1)throw new Error("too few inputs")},pC=(r,e)=>{let n=[],t=e.numOutputs;return r[1].dims[0]>0&&(r[1].getBigInt64Array().forEach(o=>n.push(Number(o))),t=n.length),le({numOutputs:t,axis:e.axis,splitSizes:n})},fC=r=>` fn calculateOutputIndex(index: u32) -> u32 { for (var i: u32 = 0u; i < ${r}u; i += 1u ) { if (index < ${Q("uniforms.size_in_split_axis","i",r)}) { return i; } } return ${r}u; }`,hC=r=>{let e=r.length,n=[];for(let t=0;t{let n=r[0].dims,t=D.size(n),o=r[0].dataType,i=D.normalizeAxis(e.axis,n.length),a=new Array(e.numOutputs),s=L("input",o,n.length),u=new Array(e.numOutputs),l=[],d=[],p=0,h=[{type:12,data:t}];for(let b=0;b` ${b.registerUniform("input_size","u32").registerUniform("size_in_split_axis","u32",u.length).declareVariables(s,...a)} ${fC(u.length)} ${hC(a)} ${b.mainStart()} ${b.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.input_size")} var indices = ${s.offsetToIndices("global_idx")}; var index = ${s.indicesGet("indices",i)}; let output_number = calculateOutputIndex(index); if (output_number != 0) { index -= ${Q("uniforms.size_in_split_axis","output_number - 1u",u.length)}; ${s.indicesSet("indices",i,"index")}; } writeBufferData(output_number, indices, global_idx); }`;return{name:"Split",shaderCache:{hint:e.cacheKey,inputDependencies:["rank"]},getShaderSource:g,getRunData:()=>({outputs:l,dispatchGroup:{x:Math.ceil(t/64)},programUniforms:h})}},hv=(r,e)=>{dC(r.inputs);let n=r.inputs.length===1?e:pC(r.inputs,e);r.compute(Mc(r.inputs,n),{inputs:[0]})},mv=r=>{let e=r.axis,n=r.splitSizes,t=r.numOutputs<0?n.length:r.numOutputs;if(t!==n.length)throw new Error("numOutputs and splitSizes length must be equal");return le({axis:e,numOutputs:t,splitSizes:n})}});var mC,Ja,gv,Fc=N(()=>{"use strict";ue();pe();Ye();he();mC=(r,e)=>{let[n,t,o,i]=r,{numHeads:a,rotaryEmbeddingDim:s}=e;if(n.dims.length!==3&&n.dims.length!==4)throw new Error(`Input 'x' is expected to have 3 or 4 dimensions, got ${n.dims.length}`);if(!D.areEqual(t.dims,[])&&!D.areEqual(t.dims,[1])&&t.dims.length!==2)throw new Error(`Input 'position_ids' is expected to have 0, 1, or 2 dimensions, got ${t.dims.length}`);if(o.dims.length!==2)throw new Error(`Input 'cos_cache' is expected to have 2 dimensions, got ${o.dims.length}`);if(i.dims.length!==2)throw new Error(`Input 'sin_cache' is expected to have 2 dimensions, got ${i.dims.length}`);if(!D.areEqual(o.dims,i.dims))throw new Error("Inputs 'cos_cache' and 'sin_cache' are expected to have the same shape");if(s>0&&a===0)throw new Error("num_heads must be provided if rotary_embedding_dim is specified");let u=n.dims[0],l=n.dims[n.dims.length-2],d=o.dims[0],p=D.sizeFromDimension(n.dims,1)/l,h=s===0?o.dims[1]*2:p/a;if(s>h)throw new Error("rotary_embedding_dim must be less than or equal to head_size");if(t.dims.length===2){if(u!==t.dims[0])throw new Error(`Input 'position_ids' dimension 0 should be of size batch_size, got ${t.dims[0]}`);if(l!==t.dims[1])throw new Error(`Input 'position_ids' dimension 1 should be of size sequence_length, got ${t.dims[1]}`)}if(l>d)throw new Error("Updating cos_cache and sin_cache in RotaryEmbedding is not currently supported");if(h/2!==o.dims[1]&&s/2!==o.dims[1])throw new Error(`Input 'cos_cache' dimension 1 should be same as head_size / 2 or rotary_embedding_dim / 2, got ${o.dims[1]}`)},Ja=(r,e)=>{let{interleaved:n,numHeads:t,rotaryEmbeddingDim:o,scale:i}=e,a=r[0].dims[0],s=D.sizeFromDimension(r[0].dims,1),u=r[0].dims[r[0].dims.length-2],l=s/u,d=r[2].dims[1],p=o===0?d*2:l/t,h=new Array(a,u,l/p,p-d),g=D.computeStrides(h),b=[{type:1,data:i},{type:12,data:h},{type:12,data:g},...r[0].dims.length===3?new Array({type:12,data:[s,l,p,1]}):[],...r[0].dims.length===4?new Array({type:12,data:[s,p,u*p,1]}):[],...W(r[0].dims,r[1].dims,r[2].dims,r[3].dims,r[0].dims)],_=I=>{let w=L("input",r[0].dataType,r[0].dims.length),v=L("position_ids",r[1].dataType,r[1].dims.length),S=L("cos_cache",r[2].dataType,r[2].dims.length),A=L("sin_cache",r[3].dataType,r[3].dims.length),P=V("output",r[0].dataType,r[0].dims.length);return I.registerUniforms([{name:"scale",type:"f32"},{name:"global_shape",type:"u32",length:h.length},{name:"global_strides",type:"u32",length:g.length},{name:"input_output_strides",type:"u32",length:g.length}]),` ${I.declareVariables(w,v,S,A,P)} ${I.mainStart(Ur)} let half_rotary_emb_dim = uniforms.${S.name}_shape[1]; let bsnh = global_idx / uniforms.global_strides % uniforms.global_shape; let size = uniforms.global_shape[0] * uniforms.global_strides[0]; ${I.guardAgainstOutOfBoundsWorkgroupSizes("size")} if (bsnh[3] < half_rotary_emb_dim) { let position_ids_idx = ${v.broadcastedIndicesToOffset("bsnh.xy",V("",v.type.tensor,2))}; let position_id = u32(${v.getByOffset("position_ids_idx")}) + select(0, bsnh[1], position_ids_idx == 0); let i = dot(bsnh, uniforms.input_output_strides) + select(0, bsnh[3], ${n}); let j = i + select(half_rotary_emb_dim, 1, ${n}); let re = ${w.getByOffset("i")} * ${S.get("position_id","bsnh[3]")} - ${w.getByOffset("j")} * ${A.get("position_id","bsnh[3]")}; ${P.setByOffset("i","re")} let im = ${w.getByOffset("i")} * ${A.get("position_id","bsnh[3]")} + ${w.getByOffset("j")} * ${S.get("position_id","bsnh[3]")}; ${P.setByOffset("j","im")} } else { let k = dot(bsnh, uniforms.input_output_strides) + half_rotary_emb_dim; ${P.setByOffset("k",w.getByOffset("k"))} } }`};return{name:"RotaryEmbedding",shaderCache:{hint:le({interleaved:n}).cacheKey,inputDependencies:["rank","rank","rank","rank"]},getShaderSource:_,getRunData:()=>({outputs:[{dims:r[0].dims,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(D.size(h)/Ur)},programUniforms:b})}},gv=(r,e)=>{mC(r.inputs,e),r.compute(Ja(r.inputs,e))}});var gC,bC,bv,yC,yv,_v=N(()=>{"use strict";Ye();ue();Va();zc();Bc();Qn();Fc();he();gC=(r,e)=>{if(e.doRotary&&r.length<=7)throw new Error("cos_cache and sin_cache inputs are required if do_rotary is specified");let n=r[0],t=r[1],o=r[2],i=r[3],a=r[4];if(e.doRotary!==0&&r.length<=7)throw new Error("cos_cast and sin_cache are expected if do_rotary attribute is non-zero");if(e.localWindowSize!==-1)throw new Error("Local attention is not supported");if(e.softcap!==0)throw new Error("Softcap is not supported");if(e.rotaryInterleaved!==0)throw new Error("Rotary interleaved is not supported");if(e.smoothSoftmax)throw new Error("Smooth softmax is not supported");if(n.dims.length!==3&&n.dims.length!==5)throw new Error("Input query is expected to have 3 or 5 dimensions");let s=!1,u=n.dims[0],l=n.dims[1],d=n.dims.length===3?s?n.dims[2]/3:n.dims[2]:e.numHeads*n.dims[4],p=l,h=0,g=!t||t.dims.length===0,b=Math.floor(g?d/(e.numHeads+2*e.kvNumHeads):d/e.numHeads);g&&(d=b*e.numHeads);let _=i&&i.dims.length!==0,I=a&&a.dims.length!==0;if(_&&i.dims.length===4&&i.dims[0]===u&&i.dims[1]!==e.kvNumHeads&&i.dims[2]===e.kvNumHeads&&i.dims[3]===b)throw new Error("BSNH pastKey/pastValue is not supported");if(_&&I){if(i.dims.length!==4)throw new Error('Input "past_key" is expected to have 4 dimensions');if(a.dims.length!==4)throw new Error('Input "past_value" is expected to have 4 dimensions');h=i.dims[2]}else if(_||I)throw new Error('Input "past_key" and "past_value" shall be both present or both absent');let v=1;if(t&&t.dims.length>0){if(n.dims.length!==3)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(t.dims.length<3||t.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(n.dims[0]!==t.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(t.dims.length===3){if(n.dims[2]%t.dims[2]!==0)throw new Error('Dimension 2 of "query" should be a multiple of "key"');p=t.dims[1]}else if(t.dims.length===5){if(t.dims[2]!==e.numHeads||t.dims[3]!==2||t.dims[4]!==b)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(o)throw new Error('Expect "value" be none when "key" has packed kv format.');p=t.dims[1]}else{if(t.dims[1]!==e.numHeads||t.dims[3]!==b)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');p=t.dims[2]}}else{if(n.dims.length!==3&&n.dims.length!==5)throw new Error('Input "query" is expected to have 3 or 5 dimensions when key is empty');if(n.dims.length===5&&(n.dims[2]!==e.numHeads||n.dims[3]!==3))throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');v=3}let S=0,A=!1,P=e.kvNumHeads?b*e.kvNumHeads:d;if(o&&o.dims.length>0){if(o.dims.length!==3&&o.dims.length!==4)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(n.dims[0]!==o.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(o.dims.length===3){if(p!==o.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');P=o.dims[2]}else{if(p!==o.dims[2])throw new Error('Input "past_key" and "past_value" shall have the same dim 2 (kv_sequence_length)');P=o.dims[1]*o.dims[3],A=!0}}let C=r.length>4?r[5]:void 0;if(C){if(C.dims.length===0)throw new Error("seqlens_k must be at least 1D, got scalar.");let G=C.dims.reduce((Z,J)=>Z*J,1);if(G!==u)throw new Error(`seqlens_k must have batch_size (${u}) elements, got ${G}.`);for(let Z=0;Z{let t=e,o=n.kvNumHeads;return e.dims.length===3&&n.kvSequenceLength!==0&&(t=e.reshape([n.batchSize,n.kvSequenceLength,o,n.headSize]),t=r.compute(lt(t,bC.perm),{inputs:[t],outputs:[-1]})[0]),t},yC=(r,e,n,t)=>{let o=7,i=["type","type"],a=[r*e],s=r*e,u=[{type:12,data:s},{type:12,data:e},{type:12,data:r}],l=d=>{let p=L("seq_lens",n.dataType,n.dims),h=L("total_seq_lens",t.dataType,t.dims),g=V("pos_ids",o,a),b=[{name:"output_size",type:"u32"},{name:"sequence_length",type:"u32"},{name:"batch_size",type:"u32"}];return` ${d.registerUniforms(b).declareVariables(p,h,g)} ${d.mainStart()} ${d.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let total_sequence_length = u32(${h.getByOffset("0")}); let is_subsequent_prompt = uniforms.sequence_length > 1 && uniforms.sequence_length != total_sequence_length; let is_first_prompt = !is_subsequent_prompt && uniforms.sequence_length == total_sequence_length; let batch_idx = global_idx / uniforms.sequence_length; let sequence_idx = i32(global_idx % uniforms.sequence_length); var pos_id: i32 = 0; let seqlen = ${p.getByOffset("batch_idx")}; let total_seqlen = seqlen + 1; if (is_first_prompt) { if (sequence_idx < total_seqlen) { pos_id = sequence_idx; } else { pos_id = 1; } ${g.setByOffset("global_idx","pos_id")} } else if (is_subsequent_prompt) { let past_seqlen = total_seqlen - i32(uniforms.sequence_length); if (past_seqlen + sequence_idx < total_seqlen) { pos_id = past_seqlen + sequence_idx; } else { pos_id = 1; } ${g.setByOffset("global_idx","pos_id")} } else if (global_idx < uniforms.batch_size) { ${g.setByOffset("global_idx","seqlen")} }; } `};return{name:"GeneratePositionIds",shaderCache:{hint:`${r};${e}`,inputDependencies:i},getRunData:()=>({outputs:[{dims:a,dataType:o}],dispatchGroup:{x:Math.ceil(s/64)},programUniforms:u}),getShaderSource:l}},yv=(r,e)=>{let n=gC(r.inputs,e);if(r.inputs[0].dims.length===5)throw new Error("Packed QKV is not implemented");if(r.inputs[1]?.dims.length===5)throw new Error("Packed KV is not implemented");let t=r.inputs[0],o=r.inputs[1]&&r.inputs[1].dims.length>0?r.inputs[1]:void 0,i=r.inputs[2]&&r.inputs[2].dims.length>0?r.inputs[2]:void 0,a=r.inputs[3]&&r.inputs[3].dims.length!==0?r.inputs[3]:void 0,s=r.inputs[4]&&r.inputs[4].dims.length!==0?r.inputs[4]:void 0,u=r.inputs.length>4?r.inputs[5]:void 0,l=r.inputs.length>5?r.inputs[6]:void 0,d=n.kvNumHeads?n.kvNumHeads:n.numHeads,p=le({axis:2,numOutputs:3,splitSizes:[n.numHeads*n.headSize,d*n.headSize,d*n.headSize]}),[h,g,b]=!o&&!i?r.compute(Mc([t],p),{inputs:[t],outputs:[-1,-1,-1]}):[t,o,i],_,I;if(e.doRotary){let A=r.compute(yC(n.batchSize,n.sequenceLength,u,l),{inputs:[u,l],outputs:[-1]})[0],P=r.inputs[7],C=r.inputs[8],R=le({interleaved:e.rotaryInterleaved!==0,numHeads:n.numHeads,rotaryEmbeddingDim:0,scale:e.scale}),x=[h,A,P,C],B=[-1];_=r.compute(Ja(x,R),{inputs:x,outputs:B})[0],x.splice(0,1,g);let G=le({interleaved:e.rotaryInterleaved!==0,numHeads:n.kvNumHeads,rotaryEmbeddingDim:0,scale:e.scale});I=r.compute(Ja(x,G),{inputs:x,outputs:B})[0]}let w=jo(r,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,e.doRotary?_:h,void 0,0),v=bv(r,e.doRotary?I:g,n),S=bv(r,b,n);co(r,w,v,S,void 0,void 0,a,s,void 0,n,u,l)}});var wv,_C,wC,vv,xv=N(()=>{"use strict";ue();pe();Qn();he();wv=(r,e,n,t,o,i,a,s)=>{let u=Pe(i),l=u===1?"f32":`vec${u}f`,d=u===1?"vec2f":`mat2x${u}f`,p=o*a,h=64;p===1&&(h=256);let g=[o,a,i/u],b=[o,a,2],_=["rank","type","type"],I=[];I.push(...W(g,b));let w=v=>{let S=L("x",e.dataType,3,u),A=L("scale",n.dataType,n.dims),P=L("bias",t.dataType,t.dims),C=V("output",1,3,2),R=[S,A,P,C];return` var workgroup_shared : array<${d}, ${h}>; const workgroup_size = ${h}u; ${v.declareVariables(...R)} ${v.mainStart(h)} let batch = workgroup_index / uniforms.x_shape[1]; let channel = workgroup_index % uniforms.x_shape[1]; let hight = uniforms.x_shape[2]; // initialize workgroup memory var sum = ${l}(0); var squared_sum = ${l}(0); for (var h = local_idx; h < hight; h += workgroup_size) { let value = ${l}(${S.get("batch","channel","h")}); sum += value; squared_sum += value * value; } workgroup_shared[local_idx] = ${d}(sum, squared_sum); workgroupBarrier(); for (var currSize = workgroup_size >> 1; currSize > 0; currSize = currSize >> 1) { if (local_idx < currSize) { workgroup_shared[local_idx] = workgroup_shared[local_idx] + workgroup_shared[local_idx + currSize]; } workgroupBarrier(); } if (local_idx == 0) { let sum_final = ${Zt("workgroup_shared[0][0]",u)} / f32(hight * ${u}); let squared_sum_final = ${Zt("workgroup_shared[0][1]",u)} / f32(hight * ${u}); let inv_std_dev = inverseSqrt(squared_sum_final - sum_final * sum_final + f32(${s})); let channel_scale = inv_std_dev * f32(scale[channel]); let channel_shift = f32(bias[channel]) - sum_final * channel_scale; output[workgroup_index] = vec2f(channel_scale, channel_shift); } }`};return r.compute({name:"InstanceNormComputeChannelScaleShift",shaderCache:{hint:`${u};${s};${h}`,inputDependencies:_},getRunData:()=>({outputs:[{dims:b,dataType:1}],dispatchGroup:{x:p},programUniforms:I}),getShaderSource:w},{inputs:[e,n,t],outputs:[-1]})[0]},_C=(r,e,n)=>{let t=e[0].dims,o=t,i=2,a=t[0],s=t[1],u=D.sizeFromDimension(t,i),l=Pe(u),d=D.size(o)/l,p=wv(r,e[0],e[1],e[2],a,u,s,n.epsilon),h=[a,s,u/l],g=[a,s],b=["type","none"],_=I=>{let w=L("x",e[0].dataType,h.length,l),v=L("scale_shift",1,g.length,2),S=V("output",e[0].dataType,h.length,l),A=[w,v,S];return` ${I.registerUniform("output_size","u32").declareVariables(...A)} ${I.mainStart()} ${I.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let outputIndices = ${S.offsetToIndices("global_idx")}; let batch = outputIndices[0]; let channel = outputIndices[1]; let scale_shift = ${v.getByIndices("vec2(batch, channel)")}; let value = ${w.getByOffset("global_idx")} * ${S.type.value}(scale_shift.x) + ${S.type.value}(scale_shift.y); ${S.setByOffset("global_idx","value")}; }`};r.compute({name:"InstanceNormalization",shaderCache:{hint:`${l}`,inputDependencies:b},getRunData:()=>({outputs:[{dims:o,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:[{type:12,data:d},...W(h,g,h)]}),getShaderSource:_},{inputs:[e[0],p]})},wC=(r,e,n)=>{let t=e[0].dims,o=t,i=t[0],a=t[t.length-1],s=D.sizeFromDimension(t,1)/a,u=Pe(a),l=D.size(o)/u,d=[{type:12,data:s},{type:12,data:Math.floor(a/u)}],p=["type","type"],h=!1,g=[0,t.length-1];for(let w=0;wt[g[v]])),_=wv(r,b,e[1],e[2],i,s,a,n.epsilon),I=w=>{let v=Fe(e[0].dataType),S=u===1?"vec2f":`mat${u}x2f`,A=R=>{let x=R===0?"x":"y",B=u===1?"f32":`vec${u}f`;switch(u){case 1:return`${v}(${B}(scale.${x}))`;case 2:return`vec2<${v}>(${B}(scale[0].${x}, scale[1].${x}))`;case 4:return`vec4<${v}>(${B}(scale[0].${x}, scale[1].${x}, scale[2].${x}, scale[3].${x}))`;default:throw new Error(`Not supported compoents ${u}`)}},P=L("input",e[0].dataType,e[0].dims,u),C=V("output",e[0].dataType,o,u);return` @group(0) @binding(0) var input : array<${P.type.storage}>; @group(0) @binding(1) var scale_input : array<${S}>; @group(0) @binding(2) var output : array<${C.type.storage}>; struct Uniforms {H: u32, C : u32}; @group(0) @binding(3) var uniforms: Uniforms; ${w.mainStart()} let current_image_number = global_idx / (uniforms.C * uniforms.H); let current_channel_number = global_idx % uniforms.C; let scale_offset = current_image_number * uniforms.C + current_channel_number; let scale = scale_input[scale_offset]; output[global_idx] = fma(input[global_idx], ${A(0)}, ${A(1)}); }`};r.compute({name:"InstanceNormalizationNHWC",shaderCache:{hint:`${u}`,inputDependencies:p},getRunData:()=>({outputs:[{dims:o,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:d}),getShaderSource:I},{inputs:[e[0],_]})},vv=(r,e)=>{e.format==="NHWC"?wC(r,r.inputs,e):_C(r,r.inputs,e)}});var vC,xC,Tv,Iv=N(()=>{"use strict";ue();pe();he();vC=r=>{if(!r||r.length<2)throw new Error("layerNorm requires at least 2 inputs.")},xC=(r,e,n)=>{let t=e.simplified,o=r[0].dims,i=r[1],a=!t&&r[2],s=o,u=D.normalizeAxis(e.axis,o.length),l=D.sizeToDimension(o,u),d=D.sizeFromDimension(o,u),p=D.size(i.dims),h=a?D.size(a.dims):0;if(p!==d||a&&h!==d)throw new Error(`Size of X.shape()[axis:] == ${d}. Size of scale and bias (if provided) must match this. Got scale size of ${p} and bias size of ${h}`);let g=[];for(let P=0;P1,v=n>2,S=P=>{let C=Fe(r[0].dataType),R=[L("x",r[0].dataType,r[0].dims,b),L("scale",i.dataType,i.dims,b)];a&&R.push(L("bias",a.dataType,a.dims,b)),R.push(V("output",r[0].dataType,s,b)),w&&R.push(V("mean_data_output",1,g)),v&&R.push(V("inv_std_output",1,g));let x=[{name:"norm_count",type:"u32"},{name:"norm_size",type:"f32"},{name:"norm_size_vectorized",type:"u32"},{name:"epsilon",type:"f32"}];return` ${P.registerUniforms(x).declareVariables(...R)} ${P.mainStart()} ${P.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.norm_count")} let offset = global_idx * uniforms.norm_size_vectorized; var mean_vector = ${xc("f32",b)}; var mean_square_vector = ${xc("f32",b)}; for (var h: u32 = 0u; h < uniforms.norm_size_vectorized; h++) { let value = ${Wr(C,b,"x[h + offset]")}; mean_vector += value; mean_square_vector += value * value; } let mean = ${Zt("mean_vector",b)} / uniforms.norm_size; let inv_std_dev = inverseSqrt(${Zt("mean_square_vector",b)} / uniforms.norm_size ${t?"":"- mean * mean"} + uniforms.epsilon); for (var j: u32 = 0; j < uniforms.norm_size_vectorized; j++) { let f32input = ${Wr(C,b,"x[j + offset]")}; let f32scale = ${Wr(C,b,"scale[j]")}; output[j + offset] = ${R[0].type.value}((f32input ${t?"":"- mean"}) * inv_std_dev * f32scale ${a?`+ ${Wr(C,b,"bias[j]")}`:""} ); } ${w?"mean_data_output[global_idx] = mean":""}; ${v?"inv_std_output[global_idx] = inv_std_dev":""}; }`},A=[{dims:s,dataType:r[0].dataType}];return w&&A.push({dims:g,dataType:1}),v&&A.push({dims:g,dataType:1}),{name:"LayerNormalization",shaderCache:{hint:`${b};${n};${t}`,inputDependencies:_},getRunData:()=>({outputs:A,dispatchGroup:{x:Math.ceil(l/64)},programUniforms:I}),getShaderSource:S}},Tv=(r,e)=>{vC(r.inputs),r.compute(xC(r.inputs,e,r.outputCount))}});var TC,Sv,$v=N(()=>{"use strict";pe();ja();Ka();TC=r=>{if(!r||r.length!==2)throw new Error("MatMul requires 2 inputs.");if(r[0].dims[r[0].dims.length-1]!==r[1].dims[r[1].dims.length-2])throw new Error("shared dimension does not match.")},Sv=r=>{TC(r.inputs);let e=Un.calcShape(r.inputs[0].dims,r.inputs[1].dims,!0);if(!e)throw new Error("Can't use matmul on the given tensors");let n=e[e.length-1],t=r.inputs[0].dims[r.inputs[0].dims.length-1];if(n<8&&t<8)r.compute(qa(r.inputs,{activation:""},e));else{let o=e[e.length-2],i=D.size(r.inputs[0].dims.slice(0,-2)),a=D.size(r.inputs[1].dims.slice(0,-2));if(i!==1&&o===1&&a===1){let s=r.inputs[0].reshape([1,i,t]),u=r.inputs[1].reshape([1,t,n]),l=[1,i,n],d=[s,u];r.compute(qo(d,{activation:""},e,l),{inputs:d})}else r.compute(qo(r.inputs,{activation:""},e))}}});var IC,SC,$C,Av,Ov,Pv=N(()=>{"use strict";ue();pe();Ye();he();IC=(r,e)=>{if(r.length<3||r.length>4)throw new Error("MatMulNBits requires 3 or 4 inputs");let n=r[0],t=n.dims.length;if(n.dims[t-1]!==e.k)throw new Error("The last dim of input shape does not match the k value");let o=Math.floor((e.k+e.blockSize-1)/e.blockSize),i=e.blockSize/8*e.bits,a=r[1];if(!D.areEqual(a.dims,[e.n,o,i]))throw new Error("The second inputs must be 3D tensor with shape N X nBlocksPerCol X blobSize");let u=r[2].dims;if(D.size(u)!==e.n*o)throw new Error("scales input size error.");if(r.length===4){let d=r[3].dims,p=e.n*(e.bits===8?o:Math.floor((o*e.bits+7)/8));if(D.size(d)!==p)throw new Error("zeroPoints input size error.")}},SC=(r,e)=>{let n=r[0].dims,t=n.length,o=n[t-2],i=e.k,a=e.n,s=n.slice(0,t-2),u=D.size(s),d=r[1].dims[2]/4,p=r[0].dataType,h=Pe(e.k),g=Pe(d),b=Pe(a),_=s.concat([o,a]),I=o>1&&a/b%2===0?2:1,w=D.size(_)/b/I,v=64,S=[],A=[u,o,i/h],P=D.convertShape(r[1].dims).slice();P.splice(-1,1,d/g),S.push(...W(A)),S.push(...W(P)),S.push(...W(r[2].dims)),r.length===4&&S.push(...W(D.convertShape(r[3].dims)));let C=[u,o,a/b];S.push(...W(C));let R=x=>{let B=A.length,G=L("a",r[0].dataType,B,h),Z=L("b",12,P.length,g),J=L("scales",r[2].dataType,r[2].dims.length),ie=[G,Z,J],z=r.length===4?L("zero_points",12,r[3].dims.length):void 0;z&&ie.push(z);let U=C.length,te=V("output",r[0].dataType,U,b),oe=Fe(r[0].dataType),ee=(()=>{switch(h){case 1:return`array<${oe}, 8>`;case 2:return`mat4x2<${oe}>`;case 4:return`mat2x4<${oe}>`;default:throw new Error(`${h}-component is not supported.`)}})(),de=Math.floor(32/e.bits),ge=Math.floor(de/8),Te=()=>{let F="";for(let q=0;q0?q:""} = ${q===0?G.indicesToOffset(`${G.type.indices}(batch, row, word_offset)`):"input_offset"}; var a_data${q>0?q:""}: ${ee}; for (var j${q>0?q:""}: u32 = 0; j${q>0?q:""} < ${8/h}; j${q>0?q:""}++) { a_data${q>0?q:""}[j${q>0?q:""}] = ${G.getByOffset(`input_offset${q>0?q:""}`)}; input_offset${q>0?q:""}++; } `;for(let Ge=0;Ge> ${q*16}u; let byte_lo = half_word & 0xFFu; let byte_hi = (half_word >> 8u) & 0xFFu; let spread_word = (byte_lo & 0xFu) | ((byte_lo >> 4u) << 8u) | ((byte_hi & 0xFu) << 16u) | ((byte_hi >> 4u) << 24u); b_value_lower = unpack4xU8(spread_word & b_mask); b_value_upper = unpack4xU8((spread_word >> 2u) & b_mask); }`:`b_value_lower = unpack4xU8((b_value >> ${Ne}u) & b_mask); b_value_upper = unpack4xU8((b_value >> ${rt}u) & b_mask);`} b_quantized_values = ${ee}(${Array.from({length:4},(at,Ee)=>`${oe}(b_value_lower[${Ee}]), ${oe}(b_value_upper[${Ee}])`).join(", ")}); b_dequantized_values = ${h===1?`${ee}(${Array.from({length:8},(at,Ee)=>`(b_quantized_values[${Ee}] - ${z?`zero_point${Ge}`:"zero_point"}) * scale${Ge}`).join(", ")});`:`(b_quantized_values - ${ee}(${Array(8).fill(`${z?`zero_point${Ge}`:"zero_point"}`).join(",")})) * scale${Ge};`}; workgroup_shared[local_id.x * ${I} + ${Math.floor(Ge/b)}]${b>1?`[${Ge%b}]`:""} += ${Array.from({length:8/h},(at,Ee)=>`${h===1?`a_data${q>0?q:""}[${Ee}] * b_dequantized_values[${Ee}]`:`dot(a_data${q>0?q:""}[${Ee}], b_dequantized_values[${Ee}])`}`).join(" + ")}; `}return F},mt=()=>{let F=` var col_index = col * ${b}; ${z?` let zero_point_values_per_byte: u32 = ${Math.floor(8/e.bits)}u; let zero_point_bytes_per_col = (nBlocksPerCol + zero_point_values_per_byte - 1u) / zero_point_values_per_byte; var zero_point_byte_count: u32; var zero_point_word_index: u32; var zero_point_byte_offset: u32; let zero_point_sub_offset: u32 = block % zero_point_values_per_byte; var zero_point_bits_offset: u32; var zero_point_word: u32;`:` // The default zero point is ${Math.pow(2,e.bits-1)} for unsigned ${e.bits}-bit quantization. let zero_point = ${oe}(${Math.pow(2,e.bits-1).toFixed(1)});`} `;for(let q=0;q> 0x2u; zero_point_byte_offset = zero_point_byte_count & 0x3u; zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_sub_offset * ${e.bits}u); zero_point_word = ${z.getByOffset("zero_point_word_index")} >> zero_point_bits_offset; let zero_point${q} = ${oe}((zero_point_word) & ${e.bits===2?"0x3u":"0xFu"});`:""} col_index += 1;`;return F},Ve=()=>{let F=`col_index = col * ${b};`;for(let q=0;q; var b_value_upper: vec4; var b_quantized_values: ${ee}; var b_dequantized_values: ${ee};`,F};return` var workgroup_shared: array<${te.type.value}, ${I*v}>; ${x.declareVariables(...ie,te)} ${x.mainStart([v,1,1])} let output_indices = ${te.offsetToIndices(`(global_idx / ${v}) * ${I}`)}; let col = output_indices[2]; let row = output_indices[1]; let batch = output_indices[0]; let nBlocksPerCol = uniforms.b_shape[1]; for (var block = local_id.x; block < nBlocksPerCol; block += ${v}) { //process one block var word_offset: u32 = block * ${e.blockSize/h}; ${mt()} for (var word: u32 = 0; word < ${d}; word += ${g}) { ${Ve()} for (var i: u32 = 0; i < ${g}; i++) { ${Te()} word_offset += ${de/h}; } } } workgroupBarrier(); if (local_id.x < ${I}) { var output_value: ${te.type.value} = ${te.type.value}(0); var workgroup_shared_offset: u32 = local_id.x; for (var b: u32 = 0u; b < ${v}u; b++) { output_value += workgroup_shared[workgroup_shared_offset]; workgroup_shared_offset += ${I}; } ${te.setByIndices(`${te.type.indices}(batch, row, col + local_id.x)`,"output_value")}; } }`};return{name:"MatMulNBits",shaderCache:{hint:`${e.blockSize};${e.bits};${h};${g};${b};${I};${v}`,inputDependencies:Array(r.length).fill("rank")},getRunData:()=>({outputs:[{dims:_,dataType:p}],dispatchGroup:{x:w},programUniforms:S}),getShaderSource:R}},$C=(r,e)=>{let n=r[0].dims,t=n.length,o=n[t-2],i=e.k,a=e.n,s=n.slice(0,t-2),u=D.size(s),d=r[1].dims[2]/4,p=r[0].dataType,h=Pe(e.k),g=Pe(d),b=s.concat([o,a]),_=128,I=a%8===0?8:a%4===0?4:1,w=_/I,v=Math.floor(32/e.bits),S=w*g*v,A=S/h,P=S/e.blockSize,C=D.size(b)/I,R=[],x=[u,o,i/h],B=D.convertShape(r[1].dims).slice();B.splice(-1,1,d/g),R.push(...W(x)),R.push(...W(B)),R.push(...W(r[2].dims)),r.length===4&&R.push(...W(D.convertShape(r[3].dims)));let G=[u,o,a];R.push(...W(G));let Z=J=>{let ie=x.length,z=L("a",r[0].dataType,ie,h),U=L("b",12,B.length,g),te=L("scales",r[2].dataType,r[2].dims.length),oe=[z,U,te],ee=r.length===4?L("zero_points",12,r[3].dims.length):void 0;ee&&oe.push(ee);let de=G.length,ge=V("output",r[0].dataType,de),Te=Fe(r[0].dataType),mt=()=>{switch(h){case 1:return` let a_data0 = vec4<${Te}>(sub_a[word_offset], sub_a[word_offset + 1], sub_a[word_offset + 2], sub_a[word_offset + 3]); let a_data1 = vec4<${Te}>(sub_a[word_offset + 4], sub_a[word_offset + 5], sub_a[word_offset + 6], sub_a[word_offset + 7]);`;case 2:return` let a_data0 = vec4<${Te}>(sub_a[word_offset], sub_a[word_offset + 1]); let a_data1 = vec4<${Te}>(sub_a[word_offset + 2], sub_a[word_offset + 3]);`;case 4:return` let a_data0 = sub_a[word_offset]; let a_data1 = sub_a[word_offset + 1];`;default:throw new Error(`${h}-component is not supported.`)}};return` var sub_a: array<${z.type.value}, ${A}>; var inter_results: array, ${I}>; ${J.declareVariables(...oe,ge)} ${J.mainStart([w,I,1])} let output_indices = ${ge.offsetToIndices(`workgroup_index * ${I}`)}; let col = output_indices[2]; let row = output_indices[1]; let batch = output_indices[0]; let n_blocks_per_col = uniforms.b_shape[1]; let num_tiles = (n_blocks_per_col - 1) / ${P} + 1; // Loop over shared dimension. for (var tile: u32 = 0; tile < num_tiles; tile += 1) { let a_col_start = tile * ${A}; // load one tile A data into shared memory. for (var a_offset = local_idx; a_offset < ${A}; a_offset += ${_}) { let a_col = a_col_start + a_offset; if (a_col < uniforms.a_shape[2]) { sub_a[a_offset] = ${z.getByIndices(`${z.type.indices}(batch, row, a_col)`)}; } else { sub_a[a_offset] = ${z.type.value}(0); } } workgroupBarrier(); // each thread process one block let b_row = col + local_id.y; let block = tile * ${P} + local_id.x; ${ee?` let zero_point_values_per_byte: u32 = ${Math.floor(8/e.bits)}u; let zero_point_bytes_per_col = (n_blocks_per_col + zero_point_values_per_byte - 1u) / zero_point_values_per_byte; let zero_point_byte_count = b_row * zero_point_bytes_per_col + (block / zero_point_values_per_byte); let zero_point_word_index = zero_point_byte_count >> 0x2u; let zero_point_byte_offset = zero_point_byte_count & 0x3u; let zero_point_sub_offset: u32 = block % zero_point_values_per_byte; let zero_point_bits_offset = (zero_point_byte_offset << 3) + (zero_point_sub_offset * ${e.bits}u); let zero_point_word = ${ee.getByOffset("zero_point_word_index")} >> zero_point_bits_offset; let zero_point = ${Te}((zero_point_word) & ${e.bits===2?"0x3u":"0xFu"});`:` // The default zero point is ${Math.pow(2,e.bits-1)} for unsigned ${e.bits}-bit quantization. let zero_point = ${Te}(${Math.pow(2,e.bits-1).toFixed(1)});`} let scale = ${te.getByOffset("b_row * n_blocks_per_col + block")}; let b_data = ${U.getByIndices(`${U.type.indices}(b_row, block, 0)`)}; var word_offset = local_id.x * ${e.blockSize/h}; for (var i: u32 = 0; i < ${g}; i++) { let b_value = ${g===1?"b_data":"b_data[i]"}; ${(()=>{let Ve=Math.floor(v/8),F="";for(let q=0;q> ${q*16}u; let byte_lo = half_word & 0xFFu; let byte_hi = (half_word >> 8u) & 0xFFu; let spread_word = (byte_lo & 0xFu) | ((byte_lo >> 4u) << 8u) | ((byte_hi & 0xFu) << 16u) | ((byte_hi >> 4u) << 24u); let b_value_lower = unpack4xU8(spread_word & 0x03030303u); let b_value_upper = unpack4xU8((spread_word >> 2u) & 0x03030303u);`:` let b_value_lower = unpack4xU8((b_value >> ${Ne}u) & 0x0F0F0F0Fu); let b_value_upper = unpack4xU8((b_value >> ${rt}u) & 0x0F0F0F0Fu);`} let b_quantized_values = mat2x4<${Te}>(${Array.from({length:4},(Ge,at)=>`${Te}(b_value_lower[${at}]), ${Te}(b_value_upper[${at}])`).join(", ")}); let b_dequantized_values = (b_quantized_values - mat2x4<${Te}>(${Array(8).fill("zero_point").join(",")})) * scale; inter_results[local_id.y][local_id.x] += ${Array.from({length:2},(Ge,at)=>`${`dot(a_data${at}, b_dequantized_values[${at}])`}`).join(" + ")}; } word_offset += ${8/h};`}return F})()} } workgroupBarrier(); } if (local_idx < ${I}) { var output_value: ${ge.type.value} = ${ge.type.value}(0); for (var b = 0u; b < ${w}; b++) { output_value += inter_results[local_idx][b]; } if (col + local_idx < uniforms.output_shape[2]) { ${ge.setByIndices(`${ge.type.indices}(batch, row, col + local_idx)`,"output_value")} } } }`};return{name:"BlockwiseMatMulNBits32",shaderCache:{hint:`${e.blockSize};${h};${g};${w};${I}`,inputDependencies:Array(r.length).fill("rank")},getRunData:()=>({outputs:[{dims:b,dataType:p}],dispatchGroup:{x:C},programUniforms:R}),getShaderSource:Z}},Av=(r,e)=>{IC(r.inputs,e),e.blockSize===32&&r.adapterInfo.isVendor("intel")&&r.adapterInfo.isArchitecture("gen-12lp")?r.compute($C(r.inputs,e)):r.compute(SC(r.inputs,e))},Ov=r=>le(r)});var AC,OC,PC,EC,CC,DC,kC,NC,Ev,Cv=N(()=>{"use strict";ue();pe();he();AC=r=>{if(!r||r.length<1)throw new Error("Too few inputs");if(r[0].dataType!==1&&r[0].dataType!==10)throw new Error("Input type must be float or float16.");if(r.length>=2){let e=r[0].dims.length*2===r[1].dims[0];if(r.length===4&&(e=r[3].dims[0]*2===r[1].dims[0]),!e)throw new Error("The pads should be a 1D tensor of shape [2 * input_rank] or [2 * num_axes].")}},OC=(r,e,n)=>{let t="";for(let o=e-1;o>=0;--o)t+=` k = i32(${r.indicesGet("indices",o)}) - ${Q("uniforms.pads",o,n)}; if (k < 0) { break; } if (k >= i32(${Q("uniforms.x_shape",o,e)})) { break; } offset += k * i32(${Q("uniforms.x_strides",o,e)}); `;return` value = ${r.type.value}(uniforms.constant_value); for (var i = 0; i < 1; i++) { var offset = 0; var k = 0; ${t} value = x[offset]; } `},PC=(r,e,n)=>{let t="";for(let o=e-1;o>=0;--o)t+=` k = i32(${r.indicesGet("indices",o)}) - ${Q("uniforms.pads",o,n)}; if (k < 0) { k = -k; } { let _2n_1 = 2 * (i32(${Q("uniforms.x_shape",o,e)}) - 1); k = k % _2n_1; if(k >= i32(${Q("uniforms.x_shape",o,e)})) { k = _2n_1 - k; } } offset += k * i32(${Q("uniforms.x_strides",o,e)}); `;return` var offset = 0; var k = 0; ${t} value = x[offset]; `},EC=(r,e,n)=>{let t="";for(let o=e-1;o>=0;--o)t+=` k = i32(${r.indicesGet("indices",o)}) - ${Q("uniforms.pads",o,n)}; if (k < 0) { k = 0; } if (k >= i32(${Q("uniforms.x_shape",o,e)})) { k = i32(${Q("uniforms.x_shape",o,e)}) - 1; } offset += k * i32(${Q("uniforms.x_strides",o,e)}); `;return` var offset = 0; var k = 0; ${t} value = x[offset]; `},CC=(r,e,n)=>{let t="";for(let o=e-1;o>=0;--o)t+=` k = i32(${r.indicesGet("indices",o)}) - ${Q("uniforms.pads",o,n)}; if (k < 0) { k += i32(${Q("uniforms.x_shape",o,e)}]); } if (k >= i32(${Q("uniforms.x_shape",o,e)})) { k -= i32(${Q("uniforms.x_shape",o,e)}); } offset += k * i32(${Q("uniforms.x_strides",o,e)}); `;return` var offset = 0; var k = 0; ${t} value = x[offset]; `},DC=(r,e,n)=>{switch(n.mode){case 0:return OC(r,e,n.pads.length);case 1:return PC(r,e,n.pads.length);case 2:return EC(r,e,n.pads.length);case 3:return CC(r,e,n.pads.length);default:throw new Error("Invalid mode")}},kC=(r,e)=>{let n=D.padShape(r[0].dims.slice(),e.pads),t=r[0].dims,o=D.size(n),i=[{type:12,data:o},{type:6,data:e.pads}],a=r.length>=3&&r[2].data;e.mode===0&&i.push({type:a?r[2].dataType:1,data:e.value}),i.push(...W(r[0].dims,n));let s=["rank"],u=l=>{let d=V("output",r[0].dataType,n.length),p=L("x",r[0].dataType,t.length),h=p.type.value,g=DC(d,t.length,e),b=[{name:"output_size",type:"u32"},{name:"pads",type:"i32",length:e.pads.length}];return e.mode===0&&b.push({name:"constant_value",type:a?h:"f32"}),` ${l.registerUniforms(b).declareVariables(p,d)} ${l.mainStart()} ${l.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let indices = ${d.offsetToIndices("global_idx")}; var value = ${h}(0); ${g} output[global_idx] = value; }`};return{name:"Pad",shaderCache:{hint:`${e.mode}${a}`,inputDependencies:s},getRunData:()=>({outputs:[{dims:n,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(D.size(n)/64)},programUniforms:i}),getShaderSource:u}},NC=(r,e)=>{if(r.length>1){let n=r[1].getBigInt64Array(),t=r.length>=3&&r[2].data?r[2].dataType===10?r[2].getUint16Array()[0]:r[2].getFloat32Array()[0]:0,o=r[0].dims.length,i=new Int32Array(2*o).fill(0);if(r.length>=4){let s=r[3].getBigInt64Array();for(let u=0;ui[Number(u)]=Number(s));let a=[];return i.forEach(s=>a.push(s)),{mode:e.mode,value:t,pads:a}}else return e},Ev=(r,e)=>{AC(r.inputs);let n=NC(r.inputs,e);r.compute(kC(r.inputs,n),{inputs:[0]})}});var Ya,Dv,kv,Nv,Lv,LC,RC,Rv,zv,Mv,Bv,Fv,Vv,Gv,Uv,Wv,Hv,qv,jv,Kv=N(()=>{"use strict";ft();ue();pe();he();Ya=r=>{if(ce.webgpu.validateInputContent&&(!r||r.length!==1))throw new Error("Pool ops requires 1 input.")},Dv=(r,e,n)=>{let t=e.format==="NHWC",o=r.dims.slice();t&&o.splice(1,0,o.pop());let i=Object.hasOwnProperty.call(e,"dilations"),a=e.kernelShape.slice(),s=e.strides.slice(),u=i?e.dilations.slice():[],l=e.pads.slice();Gr.adjustPoolAttributes(n,o,a,s,u,l);let d=Gr.computePoolOutputShape(n,o,s,u,a,l,e.autoPad),p=Object.assign({},e);i?Object.assign(p,{kernelShape:a,strides:s,pads:l,dilations:u,cacheKey:e.cacheKey}):Object.assign(p,{kernelShape:a,strides:s,pads:l,cacheKey:e.cacheKey});let h=d.slice();return h.push(h.splice(1,1)[0]),[p,t?h:d]},kv=(r,e)=>{let n=e.format==="NHWC",t=D.size(r),o=D.size(e.kernelShape),i=[{type:12,data:t},{type:12,data:o}],a=[{name:"outputSize",type:"u32"},{name:"kernelSize",type:"u32"}];if(e.kernelShape.length<=2){let s=e.kernelShape[e.kernelShape.length-1],u=e.strides[e.strides.length-1],l=e.pads[e.pads.length/2-1],d=e.pads[e.pads.length-1],p=!!(l+d);i.push({type:12,data:s},{type:12,data:u},{type:12,data:l},{type:12,data:d}),a.push({name:"kw",type:"u32"},{name:"sw",type:"u32"},{name:"pwStart",type:"u32"},{name:"pwEnd",type:"u32"});let h=!1;if(e.kernelShape.length===2){let g=e.kernelShape[e.kernelShape.length-2],b=e.strides[e.strides.length-2],_=e.pads[e.pads.length/2-2],I=e.pads[e.pads.length-2];h=!!(_+I),i.push({type:12,data:g},{type:12,data:b},{type:12,data:_},{type:12,data:I}),a.push({name:"kh",type:"u32"},{name:"sh",type:"u32"},{name:"phStart",type:"u32"},{name:"phEnd",type:"u32"})}return[i,a,!0,p,h]}else{if(n)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let s=D.computeStrides(e.kernelShape);i.push({type:12,data:s},{type:12,data:e.pads},{type:12,data:e.strides}),a.push({name:"kernelStrides",type:"u32",length:s.length},{name:"pads",type:"u32",length:e.pads.length},{name:"strides",type:"u32",length:e.strides.length});let u=e.pads.reduce((l,d)=>l+d);return[i,a,!!u,!1,!1]}},Nv=(r,e,n,t,o,i,a,s,u,l,d,p)=>{let h=o.format==="NHWC",g=e.type.value,b=V("output",e.type.tensor,t);if(o.kernelShape.length<=2){let _="",I="",w="",v=n-(h?2:1);if(d?_=` for (var i: u32 = 0u; i < uniforms.kw; i++) { xIndices[${v}] = indices[${v}] * uniforms.sw - uniforms.pwStart + i; if (xIndices[${v}] < 0 || xIndices[${v}] >= uniforms.x_shape[${v}]) { pad++; continue; } let x_val = x[${e.indicesToOffset("xIndices")}]; ${i} }`:_=` for (var i: u32 = 0u; i < uniforms.kw; i++) { xIndices[${v}] = indices[${v}] * uniforms.sw - uniforms.pwStart + i; let x_val = x[${e.indicesToOffset("xIndices")}]; ${i} }`,o.kernelShape.length===2){let A=n-(h?3:2);p?I=` for (var j: u32 = 0u; j < uniforms.kh; j++) { xIndices[${A}] = indices[${A}] * uniforms.sh - uniforms.phStart + j; if (xIndices[${A}] < 0 || xIndices[${A}] >= uniforms.x_shape[${A}]) { pad += i32(uniforms.kw); continue; } `:I=` for (var j: u32 = 0u; j < uniforms.kh; j++) { xIndices[${A}] = indices[${A}] * uniforms.sh - uniforms.phStart + j; `,w=` } `}return` ${r.registerUniforms(u).declareVariables(e,b)} ${r.mainStart()} ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} let indices = ${b.offsetToIndices("global_idx")}; var xIndices = ${b.offsetToIndices("global_idx")}; var value = ${g}(${s}); var pad = 0; ${I} ${_} ${w} ${a} output[global_idx] = value; }`}else{if(h)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let _=o.kernelShape.length,I=o.pads.length,w="";return l?w=` if (xIndices[j] >= uniforms.x_shape[j]) { pad++; isPad = true; break; } } if (!isPad) { let x_val = x[${e.indicesToOffset("xIndices")}]; ${i} }`:w=` } let x_val = x[${e.indicesToOffset("xIndices")}]; ${i} `,` ${r.registerUniforms(u).declareVariables(e,b)} ${r.mainStart()} ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} let indices = ${b.offsetToIndices("global_idx")}; var xIndices = ${b.offsetToIndices("global_idx")}; var offsets: array; var value = ${g}(${s}); var pad = 0; var isPad = false; for (var i: u32 = 0u; i < uniforms.kernelSize; i++) { var offset = i; for (var j = 0u; j < ${_-1}u; j++) { offsets[j] = offset / ${Q("uniforms.kernelStrides","j",_)}; offset -= offsets[j] * ${Q("uniforms.kernelStrides","j",_)}; } offsets[${_-1}] = offset; isPad = false; for (var j = ${n-_}u; j < ${n}u; j++) { xIndices[j] = indices[j] * ${Q("uniforms.strides",`j - ${n-_}u`,_)} + offsets[j - ${n-_}u] - ${Q("uniforms.pads","j - 2u",I)}; ${w} } ${a} output[global_idx] = value; }`}},Lv=r=>`${r.format};${r.ceilMode};${r.autoPad};${r.kernelShape.length}`,LC=r=>`${Lv(r)};${r.countIncludePad}`,RC=r=>`${Lv(r)};${r.storageOrder};${r.dilations}`,Rv=r=>({format:r.format,autoPad:["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][r.auto_pad],ceilMode:r.ceil_mode,kernelShape:r.kernel_shape,strides:r.strides,pads:r.pads}),zv=(r,e,n,t)=>{let[o,i]=Dv(e,t,n),a=L("x",e.dataType,e.dims.length),s=a.type.value,u="value += x_val;",l="";o.countIncludePad?l+=`value /= ${s}(uniforms.kernelSize);`:l+=`value /= ${s}(i32(uniforms.kernelSize) - pad);`;let[d,p,h,g,b]=kv(i,o);d.push(...W(e.dims,i));let _=["rank"];return{name:r,shaderCache:{hint:`${t.cacheKey};${h};${g};${b}`,inputDependencies:_},getRunData:()=>({outputs:[{dims:i,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(D.size(i)/64)},programUniforms:d}),getShaderSource:I=>Nv(I,a,e.dims.length,i.length,o,u,l,0,p,h,g,b)}},Mv=r=>{let e=r.count_include_pad!==0,n=Rv(r);if(n.ceilMode!==0)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");let t={countIncludePad:e,...n,cacheKey:""};return{...t,cacheKey:LC(t)}},Bv=(r,e)=>{Ya(r.inputs),r.compute(zv("AveragePool",r.inputs[0],!1,e))},Fv={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[]},Vv=r=>{let e=r.format;return{format:e,...Fv,cacheKey:e}},Gv=(r,e)=>{Ya(r.inputs),r.compute(zv("GlobalAveragePool",r.inputs[0],!0,e))},Uv=(r,e,n,t)=>{let[o,i]=Dv(e,t,n),a=` value = max(x_val, value); `,s="",u=L("x",e.dataType,e.dims.length),l=["rank"],[d,p,h,g,b]=kv(i,o);return d.push(...W(e.dims,i)),{name:r,shaderCache:{hint:`${t.cacheKey};${h};${g};${b}`,inputDependencies:l},getRunData:()=>({outputs:[{dims:i,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(D.size(i)/64)},programUniforms:d}),getShaderSource:_=>Nv(_,u,e.dims.length,i.length,o,a,s,e.dataType===10?-65504:-1e5,p,h,g,b)}},Wv=(r,e)=>{Ya(r.inputs),r.compute(Uv("MaxPool",r.inputs[0],!1,e))},Hv=r=>{let e=r.storage_order,n=r.dilations,t=Rv(r);if(e!==0)throw new Error("column major storage order is not yet supported for MaxPool");if(t.ceilMode!==0)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");let o={storageOrder:e,dilations:n,...t,cacheKey:""};return{...o,cacheKey:RC(o)}},qv=r=>{let e=r.format;return{format:e,...Fv,cacheKey:e}},jv=(r,e)=>{Ya(r.inputs),r.compute(Uv("GlobalMaxPool",r.inputs[0],!0,e))}});var MC,BC,Xv,Zv,Jv=N(()=>{"use strict";ue();pe();Ye();he();MC=(r,e)=>{if(r.length<2||r.length>3)throw new Error("DequantizeLinear requires 2 or 3 inputs.");if(r.length===3&&r[1].dims===r[2].dims)throw new Error("x-scale and x-zero-point must have the same shape.");if(r.length===3&&r[0].dataType!==r[2].dataType)throw new Error("x and x-zero-point must have the same data type.");if(r[1].dims.length!==0&&r[1].dims.length!==1&&r[1].dims.length!==r[0].dims.length)throw new Error("scale input must be a scalar, a 1D tensor, or have the same rank as the input tensor.");if(r.length>2){if(r[0].dataType!==r[2].dataType)throw new Error("x and x-zero-point must have the same data type.");if(r[1].dims.length!==r[2].dims.length)throw new Error("scale and zero-point inputs must have the same rank.");if(!r[1].dims.map((n,t)=>n===r[2].dims[t]).reduce((n,t)=>n&&t,!0))throw new Error("scale and zero-point inputs must have the same shape.")}if(e.blockSize>0){if(r[1].dims.length===0||r[1].dims.length===1&&r[1].dims[0]===1)throw new Error("blockSize must be set only for block quantization.");if(!r[1].dims.map((o,i)=>i===e.axis||o===r[0].dims[i]).reduce((o,i)=>o&&i,!0))throw new Error("For block qunatization, scale input shape to match the input shape except for the axis");if(r[1].dims.length!==r[0].dims.length)throw new Error("For block qunatization the scale input rank must be the same as the x rank.");let n=r[0].dims[e.axis],t=r[1].dims[e.axis];if(e.blockSizeMath.ceil(n/(t-1)-1))throw new Error("blockSize must be with in the range [ceil(dI / Si), ceil(dI / (Si - 1) - 1)].")}},BC=(r,e)=>{let n=D.normalizeAxis(e.axis,r[0].dims.length),t=r[0].dataType,o=t===3,i=r[0].dims,a=r[1].dataType,s=D.size(i),u=t===3||t===2,l=u?[Math.ceil(D.size(r[0].dims)/4)]:r[0].dims,d=r[1].dims,p=r.length>2?r[2]:void 0,h=p?u?[Math.ceil(D.size(p.dims)/4)]:p.dims:void 0,g=d.length===0||d.length===1&&d[0]===1,b=g===!1&&d.length===1,_=Pe(s),I=g&&(!u||_===4),w=I?_:1,v=I&&!u?_:1,S=L("input",u?12:t,l.length,v),A=L("scale",a,d.length),P=p?L("zero_point",u?12:t,h.length):void 0,C=V("output",a,i.length,w),R=[S,A];P&&R.push(P);let x=[l,d];p&&x.push(h);let B=[{type:12,data:s/w},{type:12,data:n},{type:12,data:e.blockSize},...W(...x,i)],G=Z=>{let J=[{name:"output_size",type:"u32"},{name:"axis",type:"u32"},{name:"block_size",type:"u32"}];return` ${Z.registerUniforms(J).declareVariables(...R,C)} ${Z.mainStart()} ${Z.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let output_indices = ${C.offsetToIndices("global_idx")}; // Set input x ${u?` let input = ${S.getByOffset("global_idx / 4")}; let x_vec = ${o?"unpack4xI8(input)":"unpack4xU8(input)"}; let x_value = ${w===1?"x_vec[global_idx % 4]":"x_vec"};`:`let x_value = ${S.getByOffset("global_idx")};`}; // Set scale input ${g?`let scale_value= ${A.getByOffset("0")}`:b?` let scale_index = ${C.indicesGet("output_indices","uniforms.axis")}; let scale_value= ${A.getByOffset("scale_index")};`:` var scale_indices: ${A.type.indices} = output_indices; let index = ${A.indicesGet("scale_indices","uniforms.axis")} / uniforms.block_size; ${A.indicesSet("scale_indices","uniforms.axis","index")}; let scale_value= ${A.getByIndices("scale_indices")};`}; // Set zero-point input ${P?g?u?` let zero_point_input = ${P.getByOffset("0")}; let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; let zero_point_value= zero_point_vec[0]`:`let zero_point_value = ${P.getByOffset("0")}`:b?u?` let zero_point_index = ${C.indicesGet("output_indices","uniforms.axis")}; let zero_point_input = ${P.getByOffset("zero_point_index / 4")}; let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; let zero_point_value = zero_point_vec[zero_point_index % 4]`:` let zero_point_index = ${C.indicesGet("output_indices","uniforms.axis")}; let zero_point_value = ${P.getByOffset("zero_point_index")};`:u?` let zero_point_offset = ${A.indicesToOffset("scale_indices")}; let zero_point_input = ${P.getByOffset("zero_point_offset / 4")}; let zero_point_vec = ${o?"unpack4xI8(zero_point_input)":"unpack4xU8(zero_point_input)"}; let zero_point_value = zero_point_vec[zero_point_offset % 4];`:`let zero_point_value = ${P.getByIndices("scale_indices")};`:`let zero_point_value = ${u?o?"i32":"u32":S.type.value}(0);`}; // Compute and write output ${C.setByOffset("global_idx",`${C.type.value}(x_value - zero_point_value) * scale_value`)}; }`};return{name:"DequantizeLinear",shaderCache:{hint:e.cacheKey,inputDependencies:P?["rank","rank","rank"]:["rank","rank"]},getShaderSource:G,getRunData:()=>({outputs:[{dims:i,dataType:a}],dispatchGroup:{x:Math.ceil(s/w/64),y:1,z:1},programUniforms:B})}},Xv=(r,e)=>{MC(r.inputs,e),r.compute(BC(r.inputs,e))},Zv=r=>le({axis:r.axis,blockSize:r.blockSize})});var FC,VC,Yv,Qv=N(()=>{"use strict";ft();ue();he();FC=(r,e,n)=>{let t=r===e,o=re&&n>0;if(t||o||i)throw new Error("Range these inputs' contents are invalid.")},VC=(r,e,n,t)=>{let o=Math.abs(Math.ceil((e-r)/n)),i=[o],a=o,s=[{type:12,data:a},{type:t,data:r},{type:t,data:n},...W(i)],u=l=>{let d=V("output",t,i.length),p=d.type.value,h=[{name:"outputSize",type:"u32"},{name:"start",type:p},{name:"delta",type:p}];return` ${l.registerUniforms(h).declareVariables(d)} ${l.mainStart()} ${l.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} output[global_idx] = uniforms.start + ${p}(global_idx) * uniforms.delta; }`};return{name:"Range",shaderCache:{hint:`${t}`},getShaderSource:u,getRunData:()=>({outputs:[{dims:i,dataType:t}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:s})}},Yv=r=>{let e=0,n=0,t=0;r.inputs[0].dataType===6?(e=r.inputs[0].getInt32Array()[0],n=r.inputs[1].getInt32Array()[0],t=r.inputs[2].getInt32Array()[0]):r.inputs[0].dataType===1&&(e=r.inputs[0].getFloat32Array()[0],n=r.inputs[1].getFloat32Array()[0],t=r.inputs[2].getFloat32Array()[0]),ce.webgpu.validateInputContent&&FC(e,n,t),r.compute(VC(e,n,t,r.inputs[0].dataType),{inputs:[]})}});var GC,UC,ex,tx,nx=N(()=>{"use strict";ue();pe();Ye();he();GC=(r,e,n,t)=>{if(r!=="none"&&t!=="i32"&&t!=="u32"&&t!=="f32")throw new Error(`Input ${t} is not supported with reduction ${r}.`);let o=`{ var oldValue = 0; loop { let newValueF32 =`,i=`; let newValue = bitcast(newValueF32); let res = atomicCompareExchangeWeak(&${e}, oldValue, newValue); if res.exchanged { break; } oldValue = res.old_value; } }`;switch(r){case"none":return`${e}=${n};`;case"add":return t==="i32"||t==="u32"?`atomicAdd(&${e}, bitcast<${t}>(${n}));`:` ${o}bitcast<${t}>(oldValue) + (${n})${i}`;case"max":return t==="i32"||t==="u32"?`atomicMax(&${e}, bitcast<${t}>(${n}));`:` ${o}max(bitcast(oldValue), (${n}))${i}`;case"min":return t==="i32"||t==="u32"?`atomicMin(&${e}, bitcast<${t}>(${n}));`:`${o}min(bitcast<${t}>(oldValue), (${n}))${i}`;case"mul":return`${o}(bitcast<${t}>(oldValue) * (${n}))${i}`;default:throw new Error(`Reduction ${r} is not supported.`)}},UC=(r,e)=>{let n=r[0].dims,t=r[1].dims,o=n,i=1,a=Math.ceil(D.sizeToDimension(t,t.length-1)/i),s=t[t.length-1],u=D.sizeFromDimension(n,s),l=[{type:12,data:a},{type:12,data:s},{type:12,data:u},...W(r[1].dims,r[2].dims,o)],d=p=>{let h=L("indices",r[1].dataType,r[1].dims.length),g=L("updates",r[2].dataType,r[2].dims.length,i),b=e.reduction!=="none"&&e.reduction!==""?O_("output",r[0].dataType,o.length):V("output",r[0].dataType,o.length,i);return` ${p.registerUniform("output_size","u32").registerUniform("last_index_dimension","u32").registerUniform("num_updates_elements","u32").declareVariables(h,g,b)} ${p.mainStart()} ${p.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} var data_offset = 0u; let indices_start = uniforms.last_index_dimension * global_idx; let indices_end = indices_start + uniforms.last_index_dimension; for (var i = indices_start; i < indices_end; i++) { var index = i32(indices[i].x); ${r[0].dims.length===1?` let element_count_dim = uniforms.output_strides; let dim_value = uniforms.output_shape;`:` let element_count_dim = uniforms.output_strides[i - indices_start]; let dim_value = uniforms.output_shape[i - indices_start];`} if (index >= 0) { if (index >= i32(dim_value)) { index = i32(dim_value - 1); } } else { if (index < -i32(dim_value)) { index = 0; } else { index += i32(dim_value); } } data_offset += u32((u32(index) * element_count_dim)); } for (var i = 0u; i < uniforms.num_updates_elements; i++) { let value = updates[uniforms.num_updates_elements * global_idx + i]; ${GC(e.reduction,"output[data_offset + i]","value",b.type.value)} } }`};return{name:"ScatterND",shaderCache:{hint:`${e.cacheKey}_${e.reduction}`,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:o,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(a/64)},programUniforms:l}),getShaderSource:d}},ex=r=>le({reduction:r.reduction}),tx=(r,e)=>{r.compute(UC(r.inputs,e),{inputs:[r.inputs[1],r.inputs[2]],outputs:[]})}});var WC,HC,qC,rx,jC,KC,XC,ZC,JC,YC,QC,eD,ox,tD,nD,rD,oD,iD,ix,ax,sx=N(()=>{"use strict";ue();pe();Ye();he();WC=(r,e)=>{if(r.every(n=>n>0||(()=>{throw new Error("Resize requires scales input values to be positive")})),r.length>0){if(e.mode==="linear"){if(!(r.length===2||r.length===3||r.length===4&&r[0]===1&&r[1]===1||r.length===4&&r[0]===1&&r[3]===1||r.length===5&&r[0]===1&&r[1]===1))throw new Error(`For linear mode, Resize requires scales to be 2D, 3D, 4D with either two outermost or one innermost and one outermost scale values equal to 1, or 5D with two outermost scale values equal to 1`)}else if(e.mode==="cubic"&&!(r.length===2||r.length===4&&r[0]===1&&r[1]===1||r.length===4&&r[0]===1&&r[3]===1))throw new Error("Resize requires scales input size to be 2 or 4 for cubic mode")}},HC=(r,e,n)=>{e.every(o=>o>=0&&o{throw new Error("Resize requires axes input values to be positive and less than rank")}));let t=new Array(n).fill(1);return e.forEach((o,i)=>t[o]=r[i]),t},qC=(r,e,n,t,o,i)=>{let[a,s,u]=n>10?[1,2,3]:[-1,r.length>1?1:-1,-1],l=r[0].dims.length;if(a>0&&r.length>a&&r[a].dims.length>0)r[a].getFloat32Array().forEach(d=>i.push(d));else if(e.coordinateTransformMode==="tf_crop_and_resize")throw new Error("Resize requires RoI input to be specified when coordinateTransformMode is tfCropAndResize");if(s>0&&r.length>s&&r[s].dims.length===1&&r[s].dims[0]>0){if(r[s].getFloat32Array().forEach(d=>t.push(d)),t.length!==0&&t.length!==l&&n>=18&&t.length!==e.axes.length)throw new Error("Resize requires scales input size to be same as input rank or axes size for opset 18 and up");WC(t,e),e.axes.length>0&&HC(t,e.axes,l).forEach((d,p)=>t[p]=d)}if(u>0&&r.length>u&&r[u].dims.length===1&&r[u].dims[0]>0&&(r[u].getBigInt64Array().forEach(d=>o.push(Number(d))),o.length!==0&&o.length!==l&&n>=18&&o.length!==e.axes.length))throw new Error("Resize requires sizes input size to be same as input rank or axes size for opset 18 and up");if(e.axes.length>0){if(t.length!==0&&t.length!==e.axes.length)throw new Error('Resize requires "scales" input size to be of axes rank when axes attributes is specified');if(o.length!==0&&o.length!==e.axes.length)throw new Error('Resize requires "sizes" input size to be of rank axes rank when axes attributes is specified')}if(typeof t<"u"&&typeof o<"u"&&t.length>0&&o.length>l)throw new Error("Resize requires only of scales or sizes to be specified")},rx=(r,e,n,t)=>` // The whole part and the fractional part are calculated separately due to inaccuracy of floating // point division. As an example, f32(21) / f32(7) may evaluate to 2.99... instead of 3, causing an // offset-by-one error later in floor(). let big = (${r}) * (${e}); let whole = ${t}(big / (${n})); let fract = ${t}(big % (${n})) / ${t}(${n}); return whole + fract; `,jC=(r,e)=>`fn getOriginalCoordinateFromResizedCoordinate(xResized: u32, xScale: f32, lengthResized: u32, lengthOriginal: u32, roiStart: f32, roiEnd: f32) -> ${e} { `+(()=>{switch(r){case"asymmetric":return` if (xScale < 1.0 || floor(xScale) != xScale) { return ${e}(xResized) / ${e}(xScale); } else { ${rx("xResized","lengthOriginal","lengthResized",e)} } `;case"pytorch_half_pixel":return`if (lengthResized > 1) { return (${e}(xResized) + 0.5) / ${e}(xScale) - 0.5; } else { return 0.0; }`;case"tf_half_pixel_for_nn":return`return (${e}(xResized) + 0.5) / ${e}(xScale);`;case"align_corners":return`if (lengthResized == 1) { return 0.0; } else { ${rx("xResized","lengthOriginal - 1","lengthResized - 1",e)} }`;case"tf_crop_and_resize":return`if (lengthResized > 1) { return ${e}(roiStart) * ${e}(lengthOriginal - 1) + (${e}(xResized) * ${e}(roiEnd - roiStart) * ${e}(lengthOriginal - 1)) / ${e}(lengthResized - 1); } else { return 0.5 * ${e}(roiStart + roiEnd) * ${e}(lengthOriginal - 1); }`;case"half_pixel_symmetric":return`const outputWidth = ${e}xScale * ${e}(lengthResized); const adjustment = ${e}(lengthResized) / outputWidth; const center = ${e}(lengthOriginal) / 2; const offset = center * (1 - adjustment); return offset + ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;case"half_pixel":return`return ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;default:throw new Error(`Coordinate transform mode ${r} is not supported`)}})()+"}",KC=(r,e,n)=>`fn getNearestPixelFromOriginal(xOriginal: ${n}, isDownSample: bool) -> ${n} {`+(()=>{switch(r){case"round_prefer_ceil":return"if (fract(xOriginal) == 0.5) { return ceil(xOriginal); } else { return round(xOriginal); }";case"floor":return"return floor(xOriginal);";case"ceil":return"return ceil(xOriginal);";case"round_prefer_floor":return"if (fract(xOriginal) == 0.5) { return floor(xOriginal); } else { return round(xOriginal); }";case"simple":default:if(e<11)return"if (isDownSample) { return ceil(xOriginal); } else { return xOriginal; }";throw new Error(`Nearest mode ${r} is not supported`)}})()+"}",XC=(r,e,n)=>{let t=new Array(n).fill(0).concat(new Array(n).fill(1)),o=r.length===0?t:r.slice();return e.length>0?(e.forEach((i,a)=>{t[i]=o[a],t[a+n]=o[e.length+a]}),t):o},ZC=(r,e,n,t)=>{let o=[];if(n.length>0)if(t.length>0){if(r.forEach(i=>o.push(i)),Math.max(...t)>r.length)throw new Error("axes is out of bound");t.forEach((i,a)=>o[i]=n[a])}else n.forEach(i=>o.push(i));else{if(e.length===0)throw new Error("Resize requires either scales or sizes.");o=r.map((i,a)=>Math.round(i*e[a]))}return o},JC=(r,e,n)=>{let t=(()=>{switch(n.keepAspectRatioPolicy){case"not_larger":return n.axes.length>0?Math.min(...n.axes.map(i=>e[i]),Number.MAX_VALUE):Math.min(...e,Number.MAX_VALUE);case"not_smaller":return n.axes.length>0?Math.max(...n.axes.map(i=>e[i]),Number.MIN_VALUE):Math.max(...e,Number.MIN_VALUE);default:throw new Error(`Keep aspect ratio policy ${n.keepAspectRatioPolicy} is not supported`)}})();e.fill(1,0,e.length);let o=r.slice();return n.axes.length>0?(n.axes.forEach(i=>e[i]=t),n.axes.forEach(i=>o[i]=Math.round(r[i]*e[i]))):(e.fill(t,0,e.length),o.forEach((i,a)=>o[a]=Math.round(i*e[a]))),o},YC=(r,e,n,t,o)=>` fn calculateOriginalIndicesFromOutputIndices(output_indices: ${r.type.indices}) -> array<${r.type.value}, ${n.length}> { var original_indices: array<${r.type.value}, ${n.length}>; for (var i:u32 = 0; i < ${n.length}; i++) { var output_index = ${r.indicesGet("output_indices","i")}; var scale = ${Q("uniforms.scales","i",t)}; var roi_low = ${Q("uniforms.roi","i",o)}; var roi_hi = ${Q("uniforms.roi",`i + ${e.length}`,o)}; if (scale == 1.0) { original_indices[i] = ${r.type.value}(output_index); } else { var input_shape_i = ${Q("uniforms.input_shape","i",e.length)}; var output_shape_i = ${Q("uniforms.output_shape","i",n.length)}; original_indices[i] = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i, input_shape_i, roi_low, roi_hi); } } return original_indices; }`,QC=(r,e,n,t,o,i,a)=>` fn calculateInputIndicesFromOutputIndices(output_indices: ${e.type.indices}) -> ${r.type.indices} { var input_indices: ${r.type.indices}; for (var i:u32 = 0; i < ${t.length}; i++) { var output_index = ${e.indicesGet("output_indices","i")}; var input_index: u32; var scale = ${Q("uniforms.scales","i",o)}; if (scale == 1.0) { input_index = output_index; } else { var roi_low = ${Q("uniforms.roi","i",i)}; var roi_hi = ${Q("uniforms.roi",`i + ${n.length}`,i)}; var input_shape_i = ${Q("uniforms.input_shape","i",n.length)}; var output_shape_i = ${Q("uniforms.output_shape","i",t.length)}; var original_idx = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i, input_shape_i, roi_low, roi_hi); if (!${a} || (original_idx >= 0 && original_idx < ${e.type.value}(input_shape_i))) { if (original_idx < 0) { input_index = 0; } else if (original_idx > ${e.type.value}(input_shape_i - 1)) { input_index = input_shape_i - 1; } else { input_index = u32(getNearestPixelFromOriginal(original_idx, scale < 1)); } } else { input_index = u32(original_idx); } } ${r.indicesSet("input_indices","i","input_index")} } return input_indices; }`,eD=(r,e)=>` fn checkInputIndices(input_indices: ${r.type.indices}) -> bool { for (var i:u32 = 0; i < ${e.length}; i++) { var input_index = ${r.indicesGet("input_indices","i")}; if (input_index < 0 || input_index >= ${Q("uniforms.input_shape","i",e.length)}) { return false; } } return true; }`,ox=(r,e,n,t)=>r.rank>t?` ${r.indicesSet("input_indices",e,"channel")}; ${r.indicesSet("input_indices",n,"batch")}; `:"",tD=(r,e,n,t,o)=>{let[a,s,u,l]=n.length===2?[-1,0,1,-1]:[0,2,3,1],d=r.type.value;return` fn getInputValue(batch: u32, channel: u32, row: u32, col: u32) -> ${d} { var input_indices: ${r.type.indices}; ${r.indicesSet("input_indices",s,`max(0, min(row, ${n[s]} - 1))`)}; ${r.indicesSet("input_indices",u,`max(0, min(col, ${n[u]} - 1))`)}; ${ox(r,l,a,2)} return ${r.getByIndices("input_indices")}; } fn bilinearInterpolation(output_indices: ${e.type.indices}) -> ${d} { var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices); var row:${d} = originalIndices[${s}]; var col:${d} = originalIndices[${u}]; ${t?`if (row < 0 || row > (${n[s]} - 1) || col < 0 || col > (${n[u]} - 1)) { return ${o}; }`:""}; row = max(0, min(row, ${n[s]} - 1)); col = max(0, min(col, ${n[u]} - 1)); var row1: u32 = u32(row); var col1: u32 = u32(col); var row2: u32 = u32(row + 1); var col2: u32 = u32(col + 1); var channel: u32 = ${n.length>2?`u32(originalIndices[${l}])`:"0"}; var batch: u32 = ${n.length>2?`u32(originalIndices[${a}])`:"0"}; var x11: ${d} = getInputValue(batch, channel, row1, col1); var x12: ${d} = getInputValue(batch, channel, row1, col2); var x21: ${d} = getInputValue(batch, channel, row2, col1); var x22: ${d} = getInputValue(batch, channel, row2, col2); var dx1: ${d} = abs(row - ${d}(row1)); var dx2: ${d} = abs(${d}(row2) - row); var dy1: ${d} = abs(col - ${d}(col1)); var dy2: ${d} = abs(${d}(col2) - col); if (row1 == row2) { dx1 = 0.5; dx2 = 0.5; } if (col1 == col2) { dy1 = 0.5; dy2 = 0.5; } return (x11 * dx2 * dy2 + x12 * dx2 * dy1 + x21 * dx1 * dy2 + x22 * dx1 * dy1); }`},nD=(r,e,n,t,o,i,a,s,u,l)=>{let d=n.length===2,p=!0,[h,g]=d?[0,1]:p?[2,3]:[1,2],b=r.type.value,_=I=>{let w=I===h?"row":"col";return` fn ${w}CubicInterpolation(input_indices: ${r.type.indices}, output_indices: ${e.type.indices}) -> ${b} { var output_index = ${e.indicesGet("output_indices",I)}; var originalIdx: ${b} = getOriginalCoordinateFromResizedCoordinate(output_index, ${o[I]}, ${t[I]}, ${n[I]}, ${i[I]}, ${i[I]} + ${n.length}); var fractOriginalIdx: ${b} = originalIdx - floor(originalIdx); var coefs = getCubicInterpolationCoefs(fractOriginalIdx); if (${s} && (originalIdx < 0 || originalIdx > (${n[I]} - 1))) { return ${u}; } var data: array<${b}, 4> = array<${b}, 4>(0.0, 0.0, 0.0, 0.0); for (var i: i32 = -1; i < 3; i++) { var ${w}: ${b} = originalIdx + ${b}(i); if (${w} < 0 || ${w} >= ${n[I]}) { ${l?`coefs[i + 1] = 0.0; continue;`:s?`return ${u};`:`${w} = max(0, min(${w}, ${n[I]} - 1));`}; } var input_indices_copy: ${r.type.indices} = input_indices; ${r.indicesSet("input_indices_copy",I,`u32(${w})`)}; data[i + 1] = ${I===h?r.getByIndices("input_indices_copy"):"rowCubicInterpolation(input_indices_copy, output_indices)"}; } return cubicInterpolation1D(data, coefs); }`};return` ${_(h)}; ${_(g)}; fn getCubicInterpolationCoefs(s: ${b}) -> array<${b}, 4> { var absS = abs(s); var coeffs: array<${b}, 4> = array<${b}, 4>(0.0, 0.0, 0.0, 0.0); var oneMinusAbsS: ${b} = 1.0 - absS; var twoMinusAbsS: ${b} = 2.0 - absS; var onePlusAbsS: ${b} = 1.0 + absS; coeffs[0] = ((${a} * onePlusAbsS - 5 * ${a}) * onePlusAbsS + 8 * ${a}) * onePlusAbsS - 4 * ${a}; coeffs[1] = ((${a} + 2) * absS - (${a} + 3)) * absS * absS + 1; coeffs[2] = ((${a} + 2) * oneMinusAbsS - (${a} + 3)) * oneMinusAbsS * oneMinusAbsS + 1; coeffs[3] = ((${a} * twoMinusAbsS - 5 * ${a}) * twoMinusAbsS + 8 * ${a}) * twoMinusAbsS - 4 * ${a}; return coeffs; } fn cubicInterpolation1D(x: array<${b}, 4>, coefs: array<${b}, 4>) -> ${b} { var coefsSum: ${b} = coefs[0] + coefs[1] + coefs[2] + coefs[3]; return (x[0] * coefs[0] + x[1] * coefs[1]+ x[2] * coefs[2]+ x[3] * coefs[3]) / coefsSum; } fn bicubicInterpolation(output_indices: ${e.type.indices}) -> ${b} { var input_indices: ${r.type.indices} = output_indices; return colCubicInterpolation(input_indices, output_indices); } `},rD=(r,e,n,t,o)=>{let[a,s,u,l,d]=n.length===3?[-1,0,1,2,-1]:[0,2,3,4,1],p=r.type.value;return` fn getInputValue(batch: u32, channel: u32, depth:u32, height: u32, width: u32) -> ${p} { var input_indices: ${r.type.indices}; ${r.indicesSet("input_indices",s,`max(0, min(depth, ${n[s]} - 1))`)}; ${r.indicesSet("input_indices",u,`max(0, min(height, ${n[u]} - 1))`)}; ${r.indicesSet("input_indices",l,`max(0, min(width, ${n[l]} - 1))`)}; ${ox(r,d,a,3)} return ${r.getByIndices("input_indices")}; } fn trilinearInterpolation(output_indices: ${e.type.indices}) -> ${p} { var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices); var depth:${p} = originalIndices[${s}]; var height:${p} = originalIndices[${u}]; var width:${p} = originalIndices[${l}]; ${t?`if (depth < 0 || depth > (${n[s]} - 1) || height < 0 || height > (${n[u]} - 1) || width < 0 || (width > ${n[l]} - 1)) { return ${o}; }`:""}; depth = max(0, min(depth, ${n[s]} - 1)); height = max(0, min(height, ${n[u]} - 1)); width = max(0, min(width, ${n[l]} - 1)); var depth1: u32 = u32(depth); var height1: u32 = u32(height); var width1: u32 = u32(width); var depth2: u32 = u32(depth + 1); var height2: u32 = u32(height + 1); var width2: u32 = u32(width + 1); var channel: u32 = ${n.length>3?`u32(originalIndices[${d}])`:"0"}; var batch: u32 = ${n.length>3?`u32(originalIndices[${a}])`:"0"}; var x111: ${p} = getInputValue(batch, channel, depth1, height1, width1); var x112: ${p} = getInputValue(batch, channel, depth1, height1, width2); var x121: ${p} = getInputValue(batch, channel, depth1, height2, width1); var x122: ${p} = getInputValue(batch, channel, depth1, height2, width2); var x211: ${p} = getInputValue(batch, channel, depth2, height1, width1); var x212: ${p} = getInputValue(batch, channel, depth2, height1, width2); var x221: ${p} = getInputValue(batch, channel, depth2, height2, width1); var x222: ${p} = getInputValue(batch, channel, depth2, height2, width2); var dx1: ${p} = abs(depth - ${p}(depth1)); var dx2: ${p} = abs(${p}(depth2) - depth); var dy1: ${p} = abs(height - ${p}(height1)); var dy2: ${p} = abs(${p}(height2) - height); var dz1: ${p} = abs(width - ${p}(width1)); var dz2: ${p} = abs(${p}(width2) - width); if (depth1 == depth2) { dx1 = 0.5; dx2 = 0.5; } if (height1 == height2) { dy1 = 0.5; dy2 = 0.5; } if (width1 == width2) { dz1 = 0.5; dz2 = 0.5; } return (x111 * dx2 * dy2 * dz2 + x112 * dx2 * dy2 * dz1 + x121 * dx2 * dy1 *dz2 + x122 * dx2 * dy1 * dz1 + x211 * dx1 * dy2 * dz2 + x212 * dx1 * dy2 * dz1 + x221 * dx1 * dy1 *dz2 + x222 * dx1 * dy1 * dz1); }`},oD=(r,e,n,t,o,i)=>{let a=r.dims,s=XC(i,e.axes,a.length),u=ZC(a,t,o,e.axes),l=t.slice();t.length===0&&(l=a.map((v,S)=>v===0?1:u[S]/v),e.keepAspectRatioPolicy!=="stretch"&&(u=JC(a,l,e)));let d=V("output",r.dataType,u.length),p=L("input",r.dataType,a.length),h=D.size(u),g=a.length===u.length&&a.every((v,S)=>v===u[S]),b=e.coordinateTransformMode==="tf_crop_and_resize",_=e.extrapolationValue,I=p.type.value,w=v=>` ${g?"":` ${jC(e.coordinateTransformMode,I)}; ${(()=>{switch(e.mode){case"nearest":return` ${eD(p,a)}; ${KC(e.nearestMode,n,I)}; ${QC(p,d,a,u,l.length,s.length,b)}; `;case"linear":return` ${YC(d,a,u,l.length,s.length)}; ${(()=>{if(a.length===2||a.length===4)return`${tD(p,d,a,b,_)}`;if(a.length===3||a.length===5)return`${rD(p,d,a,b,_)}`;throw Error("Linear mode only supports input dims 2, 3, 4 and 5 are supported in linear mode.")})()}; `;case"cubic":return` ${(()=>{if(a.length===2||a.length===4)return`${nD(p,d,a,u,l,s,e.cubicCoeffA,b,e.extrapolationValue,e.excludeOutside)}`;throw Error("Cubic mode only supports input dims 2 and 4 are supported in linear mode.")})()}; `;default:throw Error("Invalid resize mode")}})()}; `} ${v.registerUniform("output_size","u32").registerUniform("scales","f32",l.length).registerUniform("roi","f32",s.length).declareVariables(p,d)} ${v.mainStart()} ${v.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} ${g?"output[global_idx] = input[global_idx];":` let output_indices = ${d.offsetToIndices("global_idx")}; var input_indices: ${p.type.indices}; ${(()=>{switch(e.mode){case"nearest":return`input_indices = calculateInputIndicesFromOutputIndices(output_indices); if (checkInputIndices(input_indices)) { output[global_idx] = ${p.getByIndices("input_indices")}; } else { output[global_idx] = ${e.extrapolationValue}; }`;case"linear":return`output[global_idx] = ${a.length===2||a.length===4?"bilinearInterpolation":"trilinearInterpolation"}(output_indices);`;case"cubic":return"output[global_idx] = bicubicInterpolation(output_indices);";default:throw Error(`Unsupported resize mode: ${e.mode}`)}})()}; `} }`;return{name:"Resize",shaderCache:{hint:`${e.cacheKey}|${n}|${l.length>0?e.mode==="cubic"?l:l.length:""}|${o.length>0?o:""}|${s.length>0?s:""}|${g}|${e.mode==="nearest"?a.length:a}`,inputDependencies:["rank"]},getShaderSource:w,getRunData:()=>({outputs:[{dims:u,dataType:r.dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:[{type:12,data:h},{type:1,data:l},{type:1,data:s},...W(a,u)]})}},iD=r=>{let e=r.customDataBuffer;return new Uint32Array(e,e.byteOffset,1)[0]},ix=(r,e)=>{let n=[],t=[],o=[],i=iD(r);if(e.antialias!==0)throw Error("Only default value (0) for Antialias attribute is supported");qC(r.inputs,e,i,n,t,o),r.compute(oD(r.inputs[0],e,i,n,t,o),{inputs:[0]})},ax=r=>{let e=r.antialias,n=r.axes,t=r.coordinateTransformMode,o=r.cubicCoeffA,i=r.excludeOutside!==0,a=r.extrapolationValue,s=r.keepAspectRatioPolicy,u=r.mode,l=r.nearestMode===""?"simple":r.nearestMode;return le({antialias:e,axes:n,coordinateTransformMode:t,cubicCoeffA:o,excludeOutside:i,extrapolationValue:a,keepAspectRatioPolicy:s,mode:u,nearestMode:l})}});var aD,sD,ux,lx=N(()=>{"use strict";ue();pe();he();aD=r=>{if(!r||r.length<3)throw new Error("layerNorm requires at least 3 inputs.");let e=r[0],n=r[1],t=r[2];if(e.dataType!==n.dataType||e.dataType!==t.dataType)throw new Error("All inputs must have the same data type");if(e.dims.length!==3&&e.dims.length!==2)throw new Error("Input must be 2D or 3D");if(n.dims.length!==3&&n.dims.length!==2)throw new Error("Skip must be 2D or 3D");let o=e.dims[e.dims.length-1],i=e.dims[e.dims.length-2];if(n.dims[n.dims.length-1]!==o)throw new Error("Skip must have the same hidden size as input");if(n.dims[n.dims.length-2]!==i)throw new Error("Skip must have the same sequence length as input");if(t.dims.length!==1)throw new Error("Gamma must be 1D");if(t.dims[t.dims.length-1]!==o)throw new Error("Gamma must have the same hidden size as input");if(r.length>3){let a=r[3];if(a.dims.length!==1)throw new Error("Beta must be 1D");if(a.dims[a.dims.length-1]!==o)throw new Error("Beta must have the same hidden size as input")}if(r.length>4){let a=r[4];if(a.dims.length!==1)throw new Error("Bias must be 1D");if(a.dims[a.dims.length-1]!==o)throw new Error("Bias must have the same hidden size as input")}},sD=(r,e,n,t)=>{let o=e.simplified,i=r[0].dims,a=D.size(i),s=i,u=a,l=i.slice(-1)[0],d=t?i.slice(0,-1).concat(1):[],p=!o&&r.length>3,h=r.length>4,g=t&&n>1,b=t&&n>2,_=n>3,I=64,w=Pe(l),v=[{type:12,data:u},{type:12,data:w},{type:12,data:l},{type:1,data:e.epsilon}],S=P=>{let C=[{name:"output_size",type:"u32"},{name:"components",type:"u32"},{name:"hidden_size",type:"u32"},{name:"epsilon",type:"f32"}],R=[L("x",r[0].dataType,r[0].dims,w),L("skip",r[1].dataType,r[1].dims,w),L("gamma",r[2].dataType,r[2].dims,w)];p&&R.push(L("beta",r[3].dataType,r[3].dims,w)),h&&R.push(L("bias",r[4].dataType,r[4].dims,w)),R.push(V("output",r[0].dataType,s,w)),g&&R.push(V("mean_output",1,d)),b&&R.push(V("inv_std_output",1,d)),_&&R.push(V("input_skip_bias_sum",r[0].dataType,s,w));let x=Fe(r[0].dataType),B=Fe(1,w);return` ${P.registerUniforms(C).declareVariables(...R)} var sum_shared : array<${B}, ${I}>; var sum_squared_shared : array<${B}, ${I}>; ${P.mainStart([I,1,1])} let ix = local_id.x; let iy = global_id.x / ${I}; let hidden_size_vectorized: u32 = uniforms.hidden_size / uniforms.components; var stride = hidden_size_vectorized / ${I}; let offset = ix * stride + iy * hidden_size_vectorized; let offset1d = stride * ix; if (ix == ${I-1}) { stride = hidden_size_vectorized - stride * ix; } for (var i: u32 = 0; i < stride; i++) { let skip_value = skip[offset + i]; let bias_value = ${h?"bias[offset1d + i]":x+"(0.0)"}; let input_value = x[offset + i]; let value = input_value + skip_value + bias_value; ${_?"input_skip_bias_sum[offset + i] = value;":""} output[offset + i] = value; let f32_value = ${Wr(x,w,"value")}; sum_shared[ix] += f32_value; sum_squared_shared[ix] += f32_value * f32_value; } workgroupBarrier(); var reduce_size : u32 = ${I}; for (var curr_size = reduce_size >> 1; curr_size > 0; curr_size = reduce_size >> 1) { reduce_size = curr_size + (reduce_size & 1); if (ix < curr_size) { sum_shared[ix] += sum_shared[ix + reduce_size]; sum_squared_shared[ix] += sum_squared_shared[ix + reduce_size]; } workgroupBarrier(); } let sum = sum_shared[0]; let square_sum = sum_squared_shared[0]; let mean = ${Zt("sum",w)} / f32(uniforms.hidden_size); let inv_std_dev = inverseSqrt(${Zt("square_sum",w)} / f32(uniforms.hidden_size) ${o?"":"- mean * mean"} + uniforms.epsilon); ${g?"mean_output[global_idx] = mean;":""} ${b?"inv_std_output[global_idx] = inv_std_dev;":""} for (var i: u32 = 0; i < stride; i++) { output[offset + i] = (output[offset + i] ${o?"":`- ${x}(mean)`}) * ${x}(inv_std_dev) * gamma[offset1d + i] ${p?"+ beta[offset1d + i]":""}; } }`},A=[{dims:s,dataType:r[0].dataType}];return n>1&&A.push({dims:d,dataType:1}),n>2&&A.push({dims:d,dataType:1}),n>3&&A.push({dims:i,dataType:r[0].dataType}),{name:"SkipLayerNormalization",shaderCache:{hint:`${w};${g};${b};${_}`,inputDependencies:r.map((P,C)=>"type")},getShaderSource:S,getRunData:()=>({outputs:A,dispatchGroup:{x:Math.ceil(u/l)},programUniforms:v})}},ux=(r,e)=>{aD(r.inputs);let t=[0];r.outputCount>1&&t.push(-3),r.outputCount>2&&t.push(-3),r.outputCount>3&&t.push(3),r.compute(sD(r.inputs,e,r.outputCount,!1),{outputs:t})}});var uD,Qa,lD,cx,cD,dD,dx,px,fx=N(()=>{"use strict";ue();pe();Ye();he();uD=(r,e)=>{if(!r||r.length<1)throw new Error("too few inputs");if(e.axes.length!==0){if(e.axes.length!==e.starts.length||e.axes.length!==e.ends.length)throw new Error("axes, starts and ends must have the same length")}else if(e.starts.length!==e.ends.length)throw new Error("starts and ends must have the same length");r.slice(1).forEach((n,t)=>{if(r[t+1].dataType!==6&&r[t+1].dataType!==7)throw new Error(`Input ${t} must be an array of int32 or int64`)})},Qa=(r,e)=>{let n=[];if(r.length>e)if(r[e].dataType===7)r[e].getBigInt64Array().forEach(t=>n.push(Number(t)));else if(r[e].dataType===6)r[e].getInt32Array().forEach(t=>n.push(Number(t)));else throw new Error(`Input ${e} must be an array of int32 or int64`);return n},lD=(r,e)=>{if(r.length>1){let n=Qa(r,1),t=Qa(r,2),o=Qa(r,3);return o.length===0&&(o=[...Array(r[0].dims.length).keys()]),le({starts:n,ends:t,axes:o})}else return e},cx=(r,e,n,t,o)=>{let i=r;return r<0&&(i+=n[t[e]]),o[e]<0?Math.max(0,Math.min(i,n[t[e]]-1)):Math.max(0,Math.min(i,n[t[e]]))},cD=(r,e,n)=>`fn calculateInputIndices(output_indices: ${e.type.indices}) -> ${r.type.indices} { var input_indices: ${r.type.indices}; var carry = 0u; for (var i = ${n.length-1}; i >= 0; i--) { let input_shape_i = ${Q("uniforms.input_shape","i",n.length)}; let steps_i = ${Q("uniforms.steps","i",n.length)}; let signs_i = ${Q("uniforms.signs","i",n.length)}; let starts_i = ${Q("uniforms.starts","i",n.length)}; var output_index = ${e.indicesGet("output_indices","i")}; var input_index = output_index * steps_i + starts_i + carry; carry = input_index / input_shape_i; input_index = input_index % input_shape_i; if (signs_i < 0) { input_index = input_shape_i - input_index - 1u + starts_i; } ${r.indicesSet("input_indices","i","input_index")}; } return input_indices; }`,dD=(r,e)=>{let n=r[0].dims,t=D.size(n),o=e.axes.length>0?D.normalizeAxes(e.axes,n.length):[...Array(n.length).keys()],i=Qa(r,4);i.forEach(w=>w!==0||(()=>{throw new Error("step cannot be 0")})),i.length===0&&(i=Array(o.length).fill(1));let a=e.starts.map((w,v)=>cx(w,v,n,o,i)),s=e.ends.map((w,v)=>cx(w,v,n,o,i));if(o.length!==a.length||o.length!==s.length)throw new Error("start, ends and axes should have the same number of elements");if(o.length!==n.length)for(let w=0;wMath.sign(w));i.forEach((w,v,S)=>{if(w<0){let A=(s[v]-a[v])/w,P=a[v],C=P+A*i[v];a[v]=C,s[v]=P,S[v]=-w}});let l=n.slice(0);o.forEach((w,v)=>{l[w]=Math.ceil((s[w]-a[w])/i[w])});let d={dims:l,dataType:r[0].dataType},p=V("output",r[0].dataType,l.length),h=L("input",r[0].dataType,r[0].dims.length),g=D.size(l),b=[{name:"outputSize",type:"u32"},{name:"starts",type:"u32",length:a.length},{name:"signs",type:"i32",length:u.length},{name:"steps",type:"u32",length:i.length}],_=[{type:12,data:g},{type:12,data:a},{type:6,data:u},{type:12,data:i},...W(r[0].dims,l)],I=w=>` ${w.registerUniforms(b).declareVariables(h,p)} ${cD(h,p,n)} ${w.mainStart()} ${w.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")} let output_indices = ${p.offsetToIndices("global_idx")}; let input_indices = calculateInputIndices(output_indices); ${p.setByOffset("global_idx",h.getByIndices("input_indices"))} }`;return{name:"Slice",shaderCache:{hint:`${u.length}_${a.length}_${i.length}`,inputDependencies:["rank"]},getShaderSource:I,getRunData:()=>({outputs:[d],dispatchGroup:{x:Math.ceil(t/64)},programUniforms:_})}},dx=(r,e)=>{uD(r.inputs,e);let n=lD(r.inputs,e);r.compute(dD(r.inputs,n),{inputs:[0]})},px=r=>{let e=r.starts,n=r.ends,t=r.axes;return le({starts:e,ends:n,axes:t})}});var pD,fD,hx,mx,gx=N(()=>{"use strict";ue();pe();Ye();Qn();he();pD=r=>{if(!r||r.length!==1)throw new Error("Softmax op requires 1 input.")},fD=(r,e)=>{let n=r.inputs[0],t=n.dims,o=D.size(t),i=t.length,a=D.normalizeAxis(e.axis,i),s=ax),l[a]=i-1,l[i-1]=a,u=r.compute(lt(n,l),{inputs:[n],outputs:[-1]})[0]):u=n;let d=u.dims,p=d[i-1],h=o/p,g=Pe(p),b=p/g,_=64;h===1&&(_=256);let I=(R,x)=>x===4?`max(max(${R}.x, ${R}.y), max(${R}.z, ${R}.w))`:x===2?`max(${R}.x, ${R}.y)`:x===3?`max(max(${R}.x, ${R}.y), ${R}.z)`:R,w=L("x",u.dataType,u.dims,g),v=V("result",u.dataType,u.dims,g),S=w.type.value,A=Fe(u.dataType)==="f32"?`var threadMax = ${S}(-3.4028234663852886e+38f);`:`var threadMax = ${S}(-65504.0h);`,P=R=>` var rowMaxShared : ${S}; var rowSumShared : ${S}; var threadShared : array<${S}, ${_}>; fn getValue(row: i32, col: i32, row_stride: i32) -> ${S} { let index = row * row_stride + col; return x[index]; } fn setValue(row: i32, col: i32, row_stride: i32, value: ${S}) { let index = row * row_stride + col; result[index] = value; } ${R.registerUniform("packedCols","i32").declareVariables(w,v)} ${R.mainStart(_)} let gindex = i32(global_idx); let lindex = i32(local_idx); const wg = ${_}; let row = gindex / wg; let cols = uniforms.packedCols; let row_stride : i32 = uniforms.packedCols; // find the rows max ${A} for (var col = lindex; col < cols; col += wg) { let value = getValue(row, col, row_stride); threadMax = max(threadMax, value); } if (lindex < cols) { threadShared[lindex] = threadMax; } workgroupBarrier(); var reduceSize = min(cols, wg); for (var currSize = reduceSize >> 1; currSize > 0; currSize = reduceSize >> 1) { reduceSize = currSize + (reduceSize & 1); if (lindex < currSize) { threadShared[lindex] = max(threadShared[lindex], threadShared[lindex + reduceSize]); } workgroupBarrier(); } if (lindex == 0) { rowMaxShared = ${S}(${I("threadShared[0]",g)}); } workgroupBarrier(); // find the rows sum var threadSum = ${S}(0.0); for (var col = lindex; col < cols; col += wg) { let subExp = exp(getValue(row, col, row_stride) - rowMaxShared); threadSum += subExp; } threadShared[lindex] = threadSum; workgroupBarrier(); for (var currSize = wg >> 1; currSize > 0; currSize = currSize >> 1) { if (lindex < currSize) { threadShared[lindex] = threadShared[lindex] + threadShared[lindex + currSize]; } workgroupBarrier(); } if (lindex == 0) { rowSumShared = ${S}(${Zt("threadShared[0]",g)}); } workgroupBarrier(); // calculate final value for each element in the row for (var col = lindex; col < cols; col += wg) { var value = exp(getValue(row, col, row_stride) - rowMaxShared) / rowSumShared; // max operation protects against NaN since all values should be >=0 value = max(value, ${S}(0.0)); setValue(row, col, row_stride, value); } }`,C=r.compute({name:"Softmax",shaderCache:{hint:`${g};${_}`,inputDependencies:["type"]},getRunData:()=>({outputs:[{dims:d,dataType:u.dataType}],dispatchGroup:{x:h},programUniforms:[{type:6,data:b}]}),getShaderSource:P},{inputs:[u],outputs:[s?-1:0]})[0];s&&r.compute(lt(C,l),{inputs:[C]})},hx=(r,e)=>{pD(r.inputs),fD(r,e)},mx=r=>le({axis:r.axis})});var bx,hD,mD,gD,yx,_x=N(()=>{"use strict";ue();pe();he();bx=r=>Array.from(r.getBigInt64Array(),Number),hD=r=>{if(!r||r.length!==2)throw new Error("Tile requires 2 inputs.");if(r[0].dataType!==1&&r[0].dataType!==10&&r[0].dataType!==6&&r[0].dataType!==12)throw new Error("Tile only support float, float16, int32, and uint32 data types");if(r[1].dataType!==7)throw new Error("Tile `repeats` input should be of int64 data type");if(r[1].dims.length!==1)throw new Error("Tile `repeats` input should be 1-D");if(bx(r[1]).length!==r[0].dims.length)throw new Error("Tile `repeats` input should have same number of elements as rank of input data tensor")},mD=(r,e)=>{let n=[];for(let t=0;t{let n=r[0].dims,t=e??bx(r[1]),o=mD(n,t),i=D.size(o),a=r[0].dataType,s=L("input",a,n.length),u=V("output",a,o.length),l=d=>` const inputShape = ${s.indices(...n)}; ${d.registerUniform("output_size","u32").declareVariables(s,u)} ${d.mainStart()} ${d.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")} let output_indices = ${u.offsetToIndices("global_idx")}; var input_indices: ${s.type.indices}; for (var i = 0; i < ${n.length}; i++) { let input_dim_i = ${s.indicesGet("uniforms.input_shape","i")}; let input_dim_value = ${u.indicesGet("output_indices","i")} % input_dim_i; ${s.indicesSet("input_indices","i","input_dim_value")} } ${u.setByOffset("global_idx",s.getByIndices("input_indices"))} }`;return{name:"Tile",shaderCache:{hint:`${t}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:o,dataType:r[0].dataType}],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:[{type:12,data:i},...W(r[0].dims,o)]}),getShaderSource:l}},yx=r=>{hD(r.inputs),r.compute(gD(r.inputs),{inputs:[0]})}});var bD,yD,wx,vx=N(()=>{"use strict";ue();pe();he();bD=(r,e,n,t,o)=>{let i=V("output_data",o,n.length,4),a=L("a_data",e[1].dataType,e[1].dims.length,4),s=L("b_data",e[2].dataType,e[2].dims.length,4),u=L("c_data",e[0].dataType,e[0].dims.length,4),l,d=(p,h,g)=>`select(${h}, ${p}, ${g})`;if(!t)l=i.setByOffset("global_idx",d(a.getByOffset("global_idx"),s.getByOffset("global_idx"),u.getByOffset("global_idx")));else{let p=(h,g,b="")=>{let _=`a_data[index_a${g}][component_a${g}]`,I=`b_data[index_b${g}][component_b${g}]`,w=`bool(c_data[index_c${g}] & (0xffu << (component_c${g} * 8)))`;return` let output_indices${g} = ${i.offsetToIndices(`global_idx * 4u + ${g}u`)}; let offset_a${g} = ${a.broadcastedIndicesToOffset(`output_indices${g}`,i)}; let offset_b${g} = ${s.broadcastedIndicesToOffset(`output_indices${g}`,i)}; let offset_c${g} = ${u.broadcastedIndicesToOffset(`output_indices${g}`,i)}; let index_a${g} = offset_a${g} / 4u; let index_b${g} = offset_b${g} / 4u; let index_c${g} = offset_c${g} / 4u; let component_a${g} = offset_a${g} % 4u; let component_b${g} = offset_b${g} % 4u; let component_c${g} = offset_c${g} % 4u; ${h}[${g}] = ${b}(${d(_,I,w)}); `};o===9?l=` var data = vec4(0); ${p("data",0,"u32")} ${p("data",1,"u32")} ${p("data",2,"u32")} ${p("data",3,"u32")} output_data[global_idx] = dot(vec4(0x1, 0x100, 0x10000, 0x1000000), vec4(data));`:l=` ${p("output_data[global_idx]",0)} ${p("output_data[global_idx]",1)} ${p("output_data[global_idx]",2)} ${p("output_data[global_idx]",3)} `}return` ${r.registerUniform("vec_size","u32").declareVariables(u,a,s,i)} ${r.mainStart()} ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")} ${l} }`},yD=r=>{let e=r[1].dims,n=r[2].dims,t=r[0].dims,o=r[1].dataType,i=!(D.areEqual(e,n)&&D.areEqual(n,t)),a=e,s=D.size(e);if(i){let l=Un.calcShape(Un.calcShape(e,n,!1),t,!1);if(!l)throw new Error("Can't perform where op on the given tensors");a=l,s=D.size(a)}let u=Math.ceil(s/4);return{name:"Where",shaderCache:{inputDependencies:["rank","rank","rank"]},getShaderSource:l=>bD(l,r,a,i,o),getRunData:()=>({outputs:[{dims:a,dataType:o}],dispatchGroup:{x:Math.ceil(s/64/4)},programUniforms:[{type:12,data:u},...W(t,e,n,a)]})}},wx=r=>{r.compute(yD(r.inputs))}});var xx,Tx=N(()=>{"use strict";r0();Va();a0();u0();j0();ow();sw();Tw();Ew();kw();Rw();Vw();Ww();qw();Xw();Yw();tv();ov();sv();cv();_v();xv();Iv();$v();Pv();zc();Cv();Kv();Jv();Qv();nx();Ba();sx();Fc();lx();fx();gx();Bc();_x();Qn();Ua();vx();xx=new Map([["Abs",[l0]],["Acos",[c0]],["Acosh",[d0]],["Add",[K0]],["ArgMax",[n0,Ic]],["ArgMin",[t0,Ic]],["Asin",[p0]],["Asinh",[f0]],["Atan",[h0]],["Atanh",[m0]],["Attention",[o0]],["AveragePool",[Bv,Mv]],["BatchNormalization",[i0]],["BiasAdd",[s0]],["BiasSplitGelu",[q0]],["Cast",[b0,g0]],["Ceil",[_0]],["Clip",[y0]],["Concat",[iw,aw]],["Conv",[kc,Dc]],["ConvTranspose",[Pw,Aw]],["Cos",[w0]],["Cosh",[v0]],["CumSum",[Cw,Dw]],["DepthToSpace",[Nw,Lw]],["DequantizeLinear",[Xv,Zv]],["Div",[X0]],["Einsum",[Bw,Fw]],["Elu",[x0,Wo]],["Equal",[Z0]],["Erf",[T0]],["Exp",[I0]],["Expand",[Uw]],["FastGelu",[Hw]],["Floor",[S0]],["FusedConv",[kc,Dc]],["Gather",[Kw,jw]],["GatherElements",[rv,nv]],["GatherBlockQuantized",[Qw,ev]],["GatherND",[Zw,Jw]],["Gelu",[$0]],["Gemm",[av,iv]],["GlobalAveragePool",[Gv,Vv]],["GlobalMaxPool",[jv,qv]],["Greater",[ew]],["GreaterOrEqual",[nw]],["GridSample",[uv,lv]],["GroupQueryAttention",[yv]],["HardSigmoid",[N0,k0]],["InstanceNormalization",[vv]],["LayerNormalization",[Tv]],["LeakyRelu",[A0,Wo]],["Less",[tw]],["LessOrEqual",[rw]],["Log",[U0]],["MatMul",[Sv]],["MatMulNBits",[Av,Ov]],["MaxPool",[Wv,Hv]],["Mul",[J0]],["MultiHeadAttention",[fv,pv]],["Neg",[P0]],["Not",[O0]],["Pad",[Ev]],["Pow",[Y0]],["QuickGelu",[W0,Wo]],["Range",[Yv]],["Reciprocal",[E0]],["ReduceMin",[X_]],["ReduceMean",[W_]],["ReduceMax",[K_]],["ReduceSum",[J_]],["ReduceProd",[Z_]],["ReduceL1",[H_]],["ReduceL2",[q_]],["ReduceLogSum",[Q_]],["ReduceLogSumExp",[j_]],["ReduceSumSquare",[Y_]],["Relu",[C0]],["Resize",[ix,ax]],["RotaryEmbedding",[gv]],["ScatterND",[tx,ex]],["Sigmoid",[D0]],["Sin",[L0]],["Sinh",[R0]],["Slice",[dx,px]],["SkipLayerNormalization",[ux]],["Split",[hv,mv]],["Sqrt",[z0]],["Softmax",[hx,mx]],["Sub",[Q0]],["Tan",[M0]],["Tanh",[F0]],["ThresholdedRelu",[G0,Wo]],["Tile",[yx]],["Transpose",[C_,D_]],["Where",[wx]]])});var es,Ix=N(()=>{"use strict";ft();Gn();he();es=class{constructor(e){this.backend=e;this.repo=new Map,this.attributesBound=!1}getArtifact(e){return this.repo.get(e)}setArtifact(e,n){this.repo.set(e,n)}run(e,n,t,o,i){At(e.programInfo.name);let a=this.backend.device,s=this.backend.getComputePassEncoder();this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2);let u=[];for(let d of n)u.push({binding:u.length,resource:{buffer:d.buffer}});for(let d of t)u.push({binding:u.length,resource:{buffer:d.buffer}});i&&u.push({binding:u.length,resource:i});let l=a.createBindGroup({layout:e.computePipeline.getBindGroupLayout(0),entries:u,label:e.programInfo.name});if(this.backend.sessionStatus==="capturing"){let d={kernelId:this.backend.currentKernelId,computePipeline:e.computePipeline,bindGroup:l,dispatchGroup:o};this.backend.capturedCommandList.get(this.backend.currentSessionId).push(d)}s.setPipeline(e.computePipeline),s.setBindGroup(0,l),s.dispatchWorkgroups(...o),this.backend.writeTimestamp(this.backend.pendingDispatchNumber*2+1),this.backend.pendingDispatchNumber++,(this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber||this.backend.queryType==="at-passes")&&this.backend.endComputePass(),this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber&&this.backend.flush(),_t(e.programInfo.name)}dispose(){}build(e,n){At(e.name);let t=this.backend.device,o=[];[{feature:"shader-f16",extension:"f16"},{feature:"subgroups",extension:"subgroups"}].forEach(p=>{t.features.has(p.feature)&&o.push(`enable ${p.extension};`)});let a=P_(n,this.backend.device.limits),s=e.getShaderSource(a),u=`${o.join(` `)} ${a.additionalImplementations} ${s}`,l=t.createShaderModule({code:u,label:e.name});me("verbose",()=>`[WebGPU] ${e.name} shader code: ${u}`);let d=t.createComputePipeline({compute:{module:l,entryPoint:"main"},layout:"auto",label:e.name});return _t(e.name),{programInfo:e,computePipeline:d,uniformVariablesInfo:a.variablesInfo}}normalizeDispatchGroupSize(e){let n=typeof e=="number"?e:e.x,t=typeof e=="number"?1:e.y||1,o=typeof e=="number"?1:e.z||1,i=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(n<=i&&t<=i&&o<=i)return[n,t,o];let a=n*t*o,s=Math.ceil(Math.sqrt(a));if(s>i){if(s=Math.ceil(Math.cbrt(a)),s>i)throw new Error("Total dispatch size exceeds WebGPU maximum.");return[s,s,s]}else return[s,s,1]}}});var Sx={};Sr(Sx,{WebGpuBackend:()=>Gc});var _D,wD,Vc,Gc,$x=N(()=>{"use strict";ft();ue();Gn();pc();A_();Tx();Ix();_D=(r,e)=>{if(e.length!==r.length)throw new Error(`inputDependencies length ${e.length} is not equal to inputTensors length ${r.length}.`);let n=[];for(let t=0;t{let t=r.name;return r.shaderCache?.hint&&(t+="["+r.shaderCache.hint+"]"),t+=":"+n+`:${_D(e,r.shaderCache?.inputDependencies??new Array(e.length).fill("dims"))}`,t},Vc=class{constructor(e){e&&(this.architecture=e.architecture,this.vendor=e.vendor)}isArchitecture(e){return this.architecture===e}isVendor(e){return this.vendor===e}},Gc=class{constructor(){this.currentSessionId=null;this.currentKernelId=null;this.commandEncoder=null;this.computePassEncoder=null;this.maxDispatchNumber=16;this.pendingDispatchNumber=0;this.pendingKernels=[];this.pendingQueries=new Map;this.sessionStatus="default";this.capturedCommandList=new Map;this.capturedPendingKernels=new Map;this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(this.currentKernelId===null)throw new Error("currentKernelCustomData(): currentKernelId is null. (should not happen)");let e=this.kernelCustomData.get(this.currentKernelId);return e||(e={},this.kernelCustomData.set(this.currentKernelId,e)),e}async initialize(e,n){this.env=e;let t=[],o={requiredLimits:{maxComputeWorkgroupStorageSize:n.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:n.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:n.limits.maxStorageBufferBindingSize,maxBufferSize:n.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:n.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:n.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:n.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:n.limits.maxComputeWorkgroupSizeZ},requiredFeatures:t},i=a=>n.features.has(a)&&t.push(a)&&!0;i("chromium-experimental-timestamp-query-inside-passes")||i("timestamp-query"),i("shader-f16"),i("subgroups"),this.device=await n.requestDevice(o),this.adapterInfo=new Vc(n.info||await n.requestAdapterInfo()),this.gpuDataManager=$_(this),this.programManager=new es(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,Pa(e.logLevel,!!e.debug),this.device.onuncapturederror=a=>{a.error instanceof GPUValidationError&&console.error(`An uncaught WebGPU validation error was raised: ${a.error.message}`)},Object.defineProperty(this.env.webgpu,"device",{value:this.device,writable:!1,enumerable:!0,configurable:!0}),Object.defineProperty(this.env.webgpu,"adapter",{value:n,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<"u"&&this.querySet.destroy(),this.gpuDataManager.dispose(),this.device&&this.env?.webgpu&&this.device.lost.then(()=>{delete this.env.webgpu.device})}getCommandEncoder(){return this.commandEncoder||(this.commandEncoder=this.device.createCommandEncoder()),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let e=this.getCommandEncoder(),n={};this.queryType==="at-passes"&&(n.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:this.pendingDispatchNumber*2,endOfPassWriteIndex:this.pendingDispatchNumber*2+1}),this.computePassEncoder=e.beginComputePass(n)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&(this.computePassEncoder.end(),this.computePassEncoder=null)}flush(){if(!this.commandEncoder)return;At(),this.endComputePass();let e;this.queryType!=="none"&&(this.commandEncoder.resolveQuerySet(this.querySet,0,this.pendingDispatchNumber*2,this.queryResolveBuffer,0),e=this.device.createBuffer({size:this.pendingDispatchNumber*2*8,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(e,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,e,0,this.pendingDispatchNumber*2*8)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,this.queryType!=="none"&&e.mapAsync(GPUMapMode.READ).then(()=>{let n=new BigUint64Array(e.getMappedRange()),t=this.pendingQueries.get(e);for(let o=0;o"u"&&(this.queryTimeBase=g);let _=Number(g-this.queryTimeBase),I=Number(b-this.queryTimeBase);if(!Number.isSafeInteger(_)||!Number.isSafeInteger(I))throw new RangeError("incorrect timestamp range");if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:p.map(w=>({dims:w.dims,dataType:Vn(w.dataType)})),outputsMetadata:h.map(w=>({dims:w.dims,dataType:Vn(w.dataType)})),kernelId:a,kernelType:u,kernelName:l,programName:d,startTime:_,endTime:I});else{let w="";p.forEach((S,A)=>{w+=`input[${A}]: [${S.dims}] | ${Vn(S.dataType)}, `});let v="";h.forEach((S,A)=>{v+=`output[${A}]: [${S.dims}] | ${Vn(S.dataType)}, `}),console.log(`[profiling] kernel "${a}|${u}|${l}|${d}" ${w}${v}start time: ${_} ns, execution time: ${I-_} ns`)}pi("GPU",`${d}::${g}::${b}`)}e.unmap(),this.pendingQueries.delete(e)}),_t()}run(e,n,t,o,i,a){At(e.name);let s=[];for(let S=0;SA):t;if(p.length!==u.length)throw new Error(`Output size ${p.length} must be equal to ${u.length}.`);let h=[],g=[];for(let S=0;S=a)throw new Error(`Invalid output index: ${p[S]}`);if(p[S]===-3)continue;let A=p[S]===-1,P=p[S]===-2,C=A||P?i(u[S].dataType,u[S].dims):o(p[S],u[S].dataType,u[S].dims);if(h.push(C),C.data===0)continue;let R=this.gpuDataManager.get(C.data);if(!R)throw new Error(`no GPU data for output: ${C.data}`);if(A&&this.temporaryData.push(R),P){let x=this.kernelPersistentData.get(this.currentKernelId);x||(x=[],this.kernelPersistentData.set(this.currentKernelId,x)),x.push(R)}g.push(R)}if(s.length!==n.length||g.length!==h.length){if(g.length===0)return _t(e.name),h;throw new Error(`Program ${e.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}let b;if(d){let S=0,A=[];d.forEach(x=>{let B=typeof x.data=="number"?[x.data]:x.data;if(B.length===0)return;let G=x.type===10?2:4,Z,J;x.type===10?(J=B.length>4?16:B.length>2?8:B.length*G,Z=B.length>4?16:G*B.length):(J=B.length<=2?B.length*G:16,Z=16),S=Math.ceil(S/J)*J,A.push(S);let ie=x.type===10?8:4;S+=B.length>4?Math.ceil(B.length/ie)*Z:B.length*G});let P=16;S=Math.ceil(S/P)*P;let C=new ArrayBuffer(S);d.forEach((x,B)=>{let G=A[B],Z=typeof x.data=="number"?[x.data]:x.data;if(x.type===6)new Int32Array(C,G,Z.length).set(Z);else if(x.type===12)new Uint32Array(C,G,Z.length).set(Z);else if(x.type===10)new Uint16Array(C,G,Z.length).set(Z);else if(x.type===1)new Float32Array(C,G,Z.length).set(Z);else throw new Error(`Unsupported uniform type: ${Vn(x.type)}`)});let R=this.gpuDataManager.create(S,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(R.buffer,0,C,0,S),this.gpuDataManager.release(R.id),b={offset:0,size:S,buffer:R.buffer}}let _=this.programManager.normalizeDispatchGroupSize(l),I=_[1]===1&&_[2]===1,w=wD(e,n,I),v=this.programManager.getArtifact(w);if(v||(v=this.programManager.build(e,_),this.programManager.setArtifact(w,v),me("info",()=>`[artifact] key: ${w}, programName: ${e.name}`)),d&&v.uniformVariablesInfo){if(d.length!==v.uniformVariablesInfo.length)throw new Error(`Uniform variables count mismatch: expect ${v.uniformVariablesInfo.length}, got ${d.length} in program "${v.programInfo.name}".`);for(let S=0;S`[ProgramManager] run "${e.name}" (key=${w}) with ${_[0]}x${_[1]}x${_[2]}`),this.queryType!=="none"||this.sessionStatus==="capturing"){let S={kernelId:this.currentKernelId,programName:v.programInfo.name,inputTensorViews:n,outputTensorViews:h};this.pendingKernels.push(S),this.sessionStatus==="capturing"&&this.capturedPendingKernels.get(this.currentSessionId).push(S)}return this.programManager.run(v,s,g,_,b),_t(e.name),h}upload(e,n){this.gpuDataManager.upload(e,n)}memcpy(e,n){this.gpuDataManager.memcpy(e,n)}async download(e,n){await this.gpuDataManager.download(e,n)}alloc(e){return this.gpuDataManager.create(e).id}free(e){return this.gpuDataManager.release(e)}createKernel(e,n,t,o){let i=xx.get(e);if(!i)throw new Error(`kernel not implemented: ${e}`);let a={kernelType:e,kernelName:o,kernelEntry:i[0],attributes:[i[1],t]};this.kernels.set(n,a)}releaseKernel(e){let n=this.kernelPersistentData.get(e);if(n){for(let t of n)this.gpuDataManager.release(t.id);this.kernelPersistentData.delete(e)}this.kernelCustomData.delete(e),this.kernels.delete(e)}computeKernel(e,n,t){let o=this.kernels.get(e);if(!o)throw new Error(`kernel not created: ${e}`);let i=o.kernelType,a=o.kernelName,s=o.kernelEntry,u=o.attributes;if(this.currentKernelId!==null)throw new Error(`kernel "[${i}] ${a}" is not allowed to be called recursively`);this.currentKernelId=e,u[0]&&(u[1]=u[0](u[1]),u[0]=void 0),me("info",()=>`[WebGPU] Start to run kernel "[${i}] ${a}"...`);let l=this.env.debug;this.temporaryData=[];try{return l&&this.device.pushErrorScope("validation"),s(n,u[1]),0}catch(d){return t.push(Promise.resolve(`[WebGPU] Kernel "[${i}] ${a}" failed. ${d}`)),1}finally{l&&t.push(this.device.popErrorScope().then(d=>d?`GPU validation error for kernel "[${i}] ${a}": ${d.message}`:null));for(let d of this.temporaryData)this.gpuDataManager.release(d.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(e,n,t,o){let i=this.sessionExternalDataMapping.get(e);i||(i=new Map,this.sessionExternalDataMapping.set(e,i));let a=i.get(n),s=this.gpuDataManager.registerExternalBuffer(t,o,a);return i.set(n,[s,t]),s}unregisterBuffers(e){let n=this.sessionExternalDataMapping.get(e);n&&(n.forEach(t=>this.gpuDataManager.unregisterExternalBuffer(t[0])),this.sessionExternalDataMapping.delete(e))}getBuffer(e){let n=this.gpuDataManager.get(e);if(!n)throw new Error(`no GPU data for buffer: ${e}`);return n.buffer}createDownloader(e,n,t){return async()=>{let o=await yc(this,e,n);return Ca(o.buffer,t)}}writeTimestamp(e){this.queryType==="inside-passes"&&this.computePassEncoder.writeTimestamp(this.querySet,e)}setQueryType(){this.queryType="none",(this.env.webgpu.profiling?.mode==="default"||(typeof this.env.trace>"u"?this.env.wasm.trace:this.env.trace))&&(this.device.features.has("chromium-experimental-timestamp-query-inside-passes")?this.queryType="inside-passes":this.device.features.has("timestamp-query")&&(this.queryType="at-passes"),this.queryType!=="none"&&typeof this.querySet>"u"&&(this.querySet=this.device.createQuerySet({type:"timestamp",count:this.maxDispatchNumber*2}),this.queryResolveBuffer=this.device.createBuffer({size:this.maxDispatchNumber*2*8,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){me("info","captureBegin"),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus="capturing"}captureEnd(){me("info","captureEnd"),this.flush(),this.sessionStatus="default"}replay(){me("info","replay"),this.sessionStatus="replaying";let e=this.capturedCommandList.get(this.currentSessionId),n=this.capturedPendingKernels.get(this.currentSessionId),t=e.length;this.pendingKernels=[];for(let o=0;o=this.maxDispatchNumber||this.queryType==="at-passes")&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus="default"}onCreateSession(){this.gpuDataManager.onCreateSession()}onReleaseSession(e){this.unregisterBuffers(e),this.capturedCommandList.has(e)&&this.capturedCommandList.delete(e),this.capturedPendingKernels.has(e)&&this.capturedPendingKernels.delete(e),this.gpuDataManager.onReleaseSession(e)}onRunStart(e){this.currentSessionId=e,this.setQueryType()}}});var Ax={};Sr(Ax,{init:()=>vD});var Ko,Uc,vD,Ox=N(()=>{"use strict";ue();Gn();pe();x_();Ko=class r{constructor(e,n,t,o){this.module=e;this.dataType=n;this.data=t;this.dims=o}getFloat32Array(){if(this.dataType!==1)throw new Error("Invalid data type");let e=D.size(this.dims);return e===0?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,e)}getBigInt64Array(){if(this.dataType!==7)throw new Error("Invalid data type");let e=D.size(this.dims);return e===0?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,e)}getInt32Array(){if(this.dataType!==6)throw new Error("Invalid data type");let e=D.size(this.dims);return e===0?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,e)}getUint16Array(){if(this.dataType!==10&&this.dataType!==4)throw new Error("Invalid data type");let e=D.size(this.dims);return e===0?new Uint16Array:new Uint16Array(this.module.HEAP8.buffer,this.data,e)}reshape(e){if(D.size(e)!==D.size(this.dims))throw new Error("Invalid new shape");return new r(this.module,this.dataType,this.data,e)}},Uc=class{constructor(e,n,t){this.module=e;this.backend=n;this.customDataOffset=0;this.customDataSize=0;this.adapterInfo=n.adapterInfo;let o=e.PTR_SIZE,i=t/e.PTR_SIZE,a=o===4?"i32":"i64";this.opKernelContext=Number(e.getValue(o*i++,a));let s=Number(e.getValue(o*i++,a));this.outputCount=Number(e.getValue(o*i++,a)),this.customDataOffset=Number(e.getValue(o*i++,"*")),this.customDataSize=Number(e.getValue(o*i++,a));let u=[];for(let l=0;ltypeof s=="number"?this.inputs[s]:s)??this.inputs,o=n?.outputs??[],i=(s,u,l)=>new Ko(this.module,u,this.output(s,l),l),a=(s,u)=>{let l=_r(s,u);if(!l)throw new Error(`Unsupported data type: ${s}`);let d=l>0?this.backend.gpuDataManager.create(l).id:0;return new Ko(this.module,s,d,u)};return this.backend.run(e,t,o,i,a,this.outputCount)}output(e,n){let t=this.module.stackSave();try{let o=this.module.PTR_SIZE,i=o===4?"i32":"i64",a=this.module.stackAlloc((1+n.length)*o);this.module.setValue(a,n.length,i);for(let s=0;s{let o=e.jsepInit;if(!o)throw new Error("Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.");if(r==="webgpu"){let i=($x(),Xr(Sx)).WebGpuBackend,a=new i;await a.initialize(n,t),o("webgpu",[a,s=>a.alloc(Number(s)),s=>a.free(s),(s,u,l,d=!1)=>{if(d)me("verbose",()=>`[WebGPU] jsepCopyGpuToGpu: src=${Number(s)}, dst=${Number(u)}, size=${Number(l)}`),a.memcpy(Number(s),Number(u));else{me("verbose",()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${Number(s)}, gpuDataId=${Number(u)}, size=${Number(l)}`);let p=e.HEAPU8.subarray(Number(s>>>0),Number(s>>>0)+Number(l));a.upload(Number(u),p)}},async(s,u,l)=>{me("verbose",()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${s}, dataOffset=${u}, size=${l}`),await a.download(Number(s),()=>e.HEAPU8.subarray(Number(u)>>>0,Number(u+l)>>>0))},(s,u,l)=>a.createKernel(s,Number(u),l,e.UTF8ToString(e._JsepGetNodeName(Number(u)))),s=>a.releaseKernel(s),(s,u,l,d)=>{me("verbose",()=>`[WebGPU] jsepRun: sessionHandle=${l}, kernel=${s}, contextDataOffset=${u}`);let p=new Uc(e,a,Number(u));return a.computeKernel(Number(s),p,d)},()=>a.captureBegin(),()=>a.captureEnd(),()=>a.replay()])}else{let i=new La(n);o("webnn",[i,()=>i.reserveTensorId(),a=>i.releaseTensorId(a),async(a,s,u,l,d)=>i.ensureTensor(a,s,u,l,d),(a,s)=>{i.uploadTensor(a,s)},async(a,s)=>i.downloadTensor(a,s),(a,s)=>i.registerMLContext(a,s),!!n.trace])}}});var xD,ya,_a,Hr,TD,Px,Fo,wa,va,Ex,xa,Ta,Ia,oc=N(()=>{"use strict";ft();l_();d_();ue();br();$a();cc();xD=(r,e)=>{Me()._OrtInit(r,e)!==0&&Oe("Can't initialize onnxruntime.")},ya=async r=>{xD(r.wasm.numThreads,Go(r.logLevel))},_a=async(r,e)=>{Me().asyncInit?.();let n=r.webgpu.adapter;if(e==="webgpu"){if(typeof navigator>"u"||!navigator.gpu)throw new Error("WebGPU is not supported in current environment");if(n){if(typeof n.limits!="object"||typeof n.features!="object"||typeof n.requestDevice!="function")throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let t=r.webgpu.powerPreference;if(t!==void 0&&t!=="low-power"&&t!=="high-performance")throw new Error(`Invalid powerPreference setting: "${t}"`);let o=r.webgpu.forceFallbackAdapter;if(o!==void 0&&typeof o!="boolean")throw new Error(`Invalid forceFallbackAdapter setting: "${o}"`);if(n=await navigator.gpu.requestAdapter({powerPreference:t,forceFallbackAdapter:o}),!n)throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.')}}if(e==="webnn"&&(typeof navigator>"u"||!navigator.ml))throw new Error("WebNN is not supported in current environment");{let t=(Ox(),Xr(Ax)).init;e==="webgpu"&&await t("webgpu",Me(),r,n),e==="webnn"&&await t("webnn",Me(),r)}},Hr=new Map,TD=r=>{let e=Me(),n=e.stackSave();try{let t=e.PTR_SIZE,o=e.stackAlloc(2*t);e._OrtGetInputOutputCount(r,o,o+t)!==0&&Oe("Can't get session input/output count.");let a=t===4?"i32":"i64";return[Number(e.getValue(o,a)),Number(e.getValue(o+t,a))]}finally{e.stackRestore(n)}},Px=(r,e)=>{let n=Me(),t=n.stackSave(),o=0;try{let i=n.PTR_SIZE,a=n.stackAlloc(2*i);n._OrtGetInputOutputMetadata(r,e,a,a+i)!==0&&Oe("Can't get session input/output metadata.");let u=Number(n.getValue(a,"*"));o=Number(n.getValue(a+i,"*"));let l=n.HEAP32[o/4];if(l===0)return[u,0];let d=n.HEAPU32[o/4+1],p=[];for(let h=0;h{let e=Me(),n=e._malloc(r.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${r.byteLength}.`);return e.HEAPU8.set(r,n),[n,r.byteLength]},wa=async(r,e)=>{let n,t,o=Me();Array.isArray(r)?[n,t]=r:r.buffer===o.HEAPU8.buffer?[n,t]=[r.byteOffset,r.byteLength]:[n,t]=Fo(r);let i=0,a=0,s=0,u=[],l=[],d=[];try{if([a,u]=await c_(e),e?.externalData&&o.mountExternalData){let A=[];for(let P of e.externalData){let C=typeof P=="string"?P:P.path;A.push(Uo(typeof P=="string"?P:P.data).then(R=>{o.mountExternalData(C,R)}))}await Promise.all(A)}for(let A of e?.executionProviders??[])if((typeof A=="string"?A:A.name)==="webnn"){if(o.shouldTransferToMLTensor=!1,typeof A!="string"){let C=A,R=C?.context,x=C?.gpuDevice,B=C?.deviceType,G=C?.powerPreference;R?o.currentContext=R:x?o.currentContext=await o.webnnCreateMLContext(x):o.currentContext=await o.webnnCreateMLContext({deviceType:B,powerPreference:G})}else o.currentContext=await o.webnnCreateMLContext();break}i=await o._OrtCreateSession(n,t,a),o.webgpuOnCreateSession?.(i),i===0&&Oe("Can't create a session."),o.jsepOnCreateSession?.(),o.currentContext&&(o.webnnRegisterMLContext(i,o.currentContext),o.currentContext=void 0,o.shouldTransferToMLTensor=!0);let[p,h]=TD(i),g=!!e?.enableGraphCapture,b=[],_=[],I=[],w=[],v=[];for(let A=0;AA==="gpu-buffer"||A==="ml-tensor"||A==="ml-tensor-cpu-output")&&(s=o._OrtCreateBinding(i),s===0&&Oe("Can't create IO binding."),S={handle:s,outputPreferredLocations:v,outputPreferredLocationsEncoded:v.map(A=>A==="ml-tensor-cpu-output"?"ml-tensor":A).map(A=>lc(A))}),Hr.set(i,[i,l,d,S,g,!1]),[i,b,_,I,w]}catch(p){throw l.forEach(h=>o._OrtFree(h)),d.forEach(h=>o._OrtFree(h)),s!==0&&o._OrtReleaseBinding(s)!==0&&Oe("Can't release IO binding."),i!==0&&o._OrtReleaseSession(i)!==0&&Oe("Can't release session."),p}finally{o._free(n),a!==0&&o._OrtReleaseSessionOptions(a)!==0&&Oe("Can't release session options."),u.forEach(p=>o._free(p)),o.unmountExternalData?.()}},va=r=>{let e=Me(),n=Hr.get(r);if(!n)throw new Error(`cannot release session. invalid session id: ${r}`);let[t,o,i,a,s]=n;a&&(s&&e._OrtClearBoundOutputs(a.handle)!==0&&Oe("Can't clear bound outputs."),e._OrtReleaseBinding(a.handle)!==0&&Oe("Can't release IO binding.")),e.jsepOnReleaseSession?.(r),e.webnnOnReleaseSession?.(r),e.webgpuOnReleaseSession?.(r),o.forEach(u=>e._OrtFree(u)),i.forEach(u=>e._OrtFree(u)),e._OrtReleaseSession(t)!==0&&Oe("Can't release session."),Hr.delete(r)},Ex=async(r,e,n,t,o,i,a=!1)=>{if(!r){e.push(0);return}let s=Me(),u=s.PTR_SIZE,l=r[0],d=r[1],p=r[3],h=p,g,b;if(l==="string"&&(p==="gpu-buffer"||p==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&p!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${i} when enableGraphCapture is true.`);if(p==="gpu-buffer"){let w=r[2].gpuBuffer;b=_r(yr(l),d);{let v=s.jsepRegisterBuffer;if(!v)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');g=v(t,i,w,b)}}else if(p==="ml-tensor"){let w=r[2].mlTensor;b=_r(yr(l),d);let v=s.webnnRegisterMLTensor;if(!v)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');g=v(t,w,yr(l),d)}else{let w=r[2];if(Array.isArray(w)){b=u*w.length,g=s._malloc(b),n.push(g);for(let v=0;vs.setValue(I+S*u,v,u===4?"i32":"i64"));let w=s._OrtCreateTensor(yr(l),g,b,I,d.length,lc(h));w===0&&Oe(`Can't create tensor for input/output. session=${t}, index=${i}.`),e.push(w)}finally{s.stackRestore(_)}},xa=async(r,e,n,t,o,i)=>{let a=Me(),s=a.PTR_SIZE,u=Hr.get(r);if(!u)throw new Error(`cannot run inference. invalid session id: ${r}`);let l=u[0],d=u[1],p=u[2],h=u[3],g=u[4],b=u[5],_=e.length,I=t.length,w=0,v=[],S=[],A=[],P=[],C=[],R=a.stackSave(),x=a.stackAlloc(_*s),B=a.stackAlloc(_*s),G=a.stackAlloc(I*s),Z=a.stackAlloc(I*s);try{[w,v]=u_(i),sr("wasm prepareInputOutputTensor");for(let U=0;U<_;U++)await Ex(n[U],S,P,r,d[e[U]],e[U],g);for(let U=0;UEe*He,1);ge=Vn(F);let at=h?.outputPreferredLocations[t[U]];if(ge==="string"){if(at==="gpu-buffer"||at==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let Ee=[];for(let He=0;He0){let Ee=a.jsepGetBuffer;if(!Ee)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let He=Ee(Te),Gt=_r(F,Ge);if(Gt===void 0||!Aa(ge))throw new Error(`Unsupported data type: ${ge}`);de=!0,ie.push([ge,rt,{gpuBuffer:He,download:a.jsepCreateDownloader(He,Gt,ge),dispose:()=>{a._OrtReleaseTensor(te)!==0&&Oe("Can't release tensor.")}},"gpu-buffer"])}else if(at==="ml-tensor"&&Ge>0){let Ee=a.webnnEnsureTensor,He=a.webnnIsGraphInputOutputTypeSupported;if(!Ee||!He)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(_r(F,Ge)===void 0||!Oa(ge))throw new Error(`Unsupported data type: ${ge}`);if(!He(r,ge,!1))throw new Error(`preferredLocation "ml-tensor" for ${ge} output is not supported by current WebNN Context.`);let St=await Ee(r,Te,F,rt,!1);de=!0,ie.push([ge,rt,{mlTensor:St,download:a.webnnCreateMLTensorDownloader(Te,ge),dispose:()=>{a.webnnReleaseTensorId(Te),a._OrtReleaseTensor(te)}},"ml-tensor"])}else if(at==="ml-tensor-cpu-output"&&Ge>0){let Ee=a.webnnCreateMLTensorDownloader(Te,ge)(),He=ie.length;de=!0,z.push((async()=>{let Gt=[He,await Ee];return a.webnnReleaseTensorId(Te),a._OrtReleaseTensor(te),Gt})()),ie.push([ge,rt,[],"cpu"])}else{let Ee=lo(ge),He=new Ee(Ge);new Uint8Array(He.buffer,He.byteOffset,He.byteLength).set(a.HEAPU8.subarray(Te,Te+He.byteLength)),ie.push([ge,rt,He,"cpu"])}}finally{a.stackRestore(oe),ge==="string"&&Te&&a._free(Te),de||a._OrtReleaseTensor(te)}}h&&!g&&(a._OrtClearBoundOutputs(h.handle)!==0&&Oe("Can't clear bound outputs."),Hr.set(r,[l,d,p,h,g,!1]));for(let[U,te]of await Promise.all(z))ie[U][2]=te;return ur("wasm ProcessOutputTensor"),ie}finally{a.webnnOnRunEnd?.(l),a.stackRestore(R),S.forEach(J=>a._OrtReleaseTensor(J)),A.forEach(J=>a._OrtReleaseTensor(J)),P.forEach(J=>a._free(J)),w!==0&&a._OrtReleaseRunOptions(w),v.forEach(J=>a._free(J))}},Ta=r=>{let e=Me(),n=Hr.get(r);if(!n)throw new Error("invalid session id");let t=n[0],o=e._OrtEndProfiling(t);o===0&&Oe("Can't get an profile file name."),e._OrtFree(o)},Ia=r=>{let e=[];for(let n of r){let t=n[2];!Array.isArray(t)&&"buffer"in t&&e.push(t.buffer)}return e}});var qr,Vt,Xo,ns,rs,ts,Wc,Hc,ho,mo,SD,Cx,Dx,kx,Nx,Lx,Rx,zx,qc=N(()=>{"use strict";ft();oc();br();ga();qr=()=>!!ce.wasm.proxy&&typeof document<"u",Xo=!1,ns=!1,rs=!1,Hc=new Map,ho=(r,e)=>{let n=Hc.get(r);n?n.push(e):Hc.set(r,[e])},mo=()=>{if(Xo||!ns||rs||!Vt)throw new Error("worker not ready")},SD=r=>{switch(r.data.type){case"init-wasm":Xo=!1,r.data.err?(rs=!0,Wc[1](r.data.err)):(ns=!0,Wc[0]()),ts&&(URL.revokeObjectURL(ts),ts=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=Hc.get(r.data.type);r.data.err?e.shift()[1](r.data.err):e.shift()[0](r.data.out);break}default:}},Cx=async()=>{if(!ns){if(Xo)throw new Error("multiple calls to 'initWasm()' detected.");if(rs)throw new Error("previous call to 'initWasm()' failed.");if(Xo=!0,qr())return new Promise((r,e)=>{Vt?.terminate(),i_().then(([n,t])=>{try{Vt=t,Vt.onerror=i=>e(i),Vt.onmessage=SD,Wc=[r,e];let o={type:"init-wasm",in:ce};!o.in.wasm.wasmPaths&&(n||ac)&&(o.in.wasm.wasmPaths={wasm:new URL("ort-wasm-simd-threaded.jsep.wasm",import.meta.url).href}),Vt.postMessage(o),ts=n}catch(o){e(o)}},e)});try{await ba(ce.wasm),await ya(ce),ns=!0}catch(r){throw rs=!0,r}finally{Xo=!1}}},Dx=async r=>{if(qr())return mo(),new Promise((e,n)=>{ho("init-ep",[e,n]);let t={type:"init-ep",in:{epName:r,env:ce}};Vt.postMessage(t)});await _a(ce,r)},kx=async r=>qr()?(mo(),new Promise((e,n)=>{ho("copy-from",[e,n]);let t={type:"copy-from",in:{buffer:r}};Vt.postMessage(t,[r.buffer])})):Fo(r),Nx=async(r,e)=>{if(qr()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return mo(),new Promise((n,t)=>{ho("create",[n,t]);let o={type:"create",in:{model:r,options:{...e}}},i=[];r instanceof Uint8Array&&i.push(r.buffer),Vt.postMessage(o,i)})}else return wa(r,e)},Lx=async r=>{if(qr())return mo(),new Promise((e,n)=>{ho("release",[e,n]);let t={type:"release",in:r};Vt.postMessage(t)});va(r)},Rx=async(r,e,n,t,o,i)=>{if(qr()){if(n.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(o.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return mo(),new Promise((a,s)=>{ho("run",[a,s]);let u=n,l={type:"run",in:{sessionId:r,inputIndices:e,inputs:u,outputIndices:t,options:i}};Vt.postMessage(l,Ia(u))})}else return xa(r,e,n,t,o,i)},zx=async r=>{if(qr())return mo(),new Promise((e,n)=>{ho("end-profiling",[e,n]);let t={type:"end-profiling",in:r};Vt.postMessage(t)});Ta(r)}});var Mx,$D,os,Bx=N(()=>{"use strict";ft();qc();ue();ma();cc();Mx=(r,e)=>{switch(r.location){case"cpu":return[r.type,r.dims,r.data,"cpu"];case"gpu-buffer":return[r.type,r.dims,{gpuBuffer:r.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[r.type,r.dims,{mlTensor:r.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${r.location} for ${e()}`)}},$D=r=>{switch(r[3]){case"cpu":return new $t(r[0],r[2],r[1]);case"gpu-buffer":{let e=r[0];if(!Aa(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:n,download:t,dispose:o}=r[2];return $t.fromGpuBuffer(n,{dataType:e,dims:r[1],download:t,dispose:o})}case"ml-tensor":{let e=r[0];if(!Oa(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:n,download:t,dispose:o}=r[2];return $t.fromMLTensor(n,{dataType:e,dims:r[1],download:t,dispose:o})}default:throw new Error(`invalid data location: ${r[3]}`)}},os=class{async fetchModelAndCopyToWasmMemory(e){return kx(await Uo(e))}async loadModel(e,n){At();let t;typeof e=="string"?t=await this.fetchModelAndCopyToWasmMemory(e):t=e,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await Nx(t,n),_t()}async dispose(){return Lx(this.sessionId)}async run(e,n,t){At();let o=[],i=[];Object.entries(e).forEach(h=>{let g=h[0],b=h[1],_=this.inputNames.indexOf(g);if(_===-1)throw new Error(`invalid input '${g}'`);o.push(b),i.push(_)});let a=[],s=[];Object.entries(n).forEach(h=>{let g=h[0],b=h[1],_=this.outputNames.indexOf(g);if(_===-1)throw new Error(`invalid output '${g}'`);a.push(b),s.push(_)});let u=o.map((h,g)=>Mx(h,()=>`input "${this.inputNames[i[g]]}"`)),l=a.map((h,g)=>h?Mx(h,()=>`output "${this.outputNames[s[g]]}"`):null),d=await Rx(this.sessionId,i,u,s,l,t),p={};for(let h=0;his,initializeFlags:()=>Fx,wasmBackend:()=>AD});var Fx,is,AD,Gx=N(()=>{"use strict";ft();qc();Bx();Fx=()=>{(typeof ce.wasm.initTimeout!="number"||ce.wasm.initTimeout<0)&&(ce.wasm.initTimeout=0);let r=ce.wasm.simd;if(typeof r!="boolean"&&r!==void 0&&r!=="fixed"&&r!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${r}". Reset it to \`false\` and ignore SIMD feature checking.`),ce.wasm.simd=!1),typeof ce.wasm.proxy!="boolean"&&(ce.wasm.proxy=!1),typeof ce.wasm.trace!="boolean"&&(ce.wasm.trace=!1),typeof ce.wasm.numThreads!="number"||!Number.isInteger(ce.wasm.numThreads)||ce.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)ce.wasm.numThreads=1;else{let e=typeof navigator>"u"?Ps("node:os").cpus().length:navigator.hardwareConcurrency;ce.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},is=class{async init(e){Fx(),await Cx(),await Dx(e)}async createInferenceSessionHandler(e,n){let t=new os;return await t.loadModel(e,n),t}},AD=new is});ft();ft();ft();var mf="1.26.0";var sK=Ls;{let r=(qy(),Xr(Hy)).onnxjsBackend;ar("webgl",r,-10)}{let r=(Gx(),Xr(Vx)).wasmBackend;ar("webgpu",r,5),ar("webnn",r,5),ar("cpu",r,10),ar("wasm",r,10)}Object.defineProperty(ce.versions,"web",{value:mf,enumerable:!0});export{iI as InferenceSession,pi as TRACE,sr as TRACE_EVENT_BEGIN,ur as TRACE_EVENT_END,At as TRACE_FUNC_BEGIN,_t as TRACE_FUNC_END,$t as Tensor,sK as default,ce as env,ar as registerBackend}; /** * @license * Copyright 2021 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ /** * @license * Copyright 2019 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ /*! Bundled license information: long/index.js: (** * @license * Copyright 2009 The Closure Library Authors * Copyright 2020 Daniel Wirtz / The long.js Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0 *) */ //# sourceMappingURL=ort.all.bundle.min.mjs.map