@huggingface/transformers 4.0.0-next.2 → 4.0.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/dist/ort-wasm-simd-threaded.jsep.mjs +23 -23
  3. package/dist/transformers.js +32 -18
  4. package/dist/transformers.min.js +18 -18
  5. package/dist/transformers.node.cjs +23 -9
  6. package/dist/transformers.node.min.cjs +4 -4
  7. package/dist/transformers.node.min.mjs +4 -4
  8. package/dist/transformers.node.mjs +23 -9
  9. package/dist/transformers.web.js +16 -2
  10. package/dist/transformers.web.min.js +15 -15
  11. package/package.json +2 -2
  12. package/src/env.js +1 -1
  13. package/src/generation/parameters.js +1 -1
  14. package/src/generation/streamers.js +21 -0
  15. package/src/models/modeling_utils.js +1 -1
  16. package/src/pipelines/automatic-speech-recognition.js +1 -1
  17. package/src/pipelines/document-question-answering.js +1 -1
  18. package/src/pipelines/image-to-text.js +2 -2
  19. package/src/pipelines/summarization.js +1 -1
  20. package/src/pipelines/text-generation.js +1 -1
  21. package/src/pipelines/text2text-generation.js +1 -1
  22. package/src/pipelines/translation.js +1 -1
  23. package/types/generation/parameters.d.ts +1 -1
  24. package/types/generation/parameters.d.ts.map +1 -1
  25. package/types/generation/streamers.d.ts +1 -0
  26. package/types/generation/streamers.d.ts.map +1 -1
  27. package/types/models/modeling_utils.d.ts +2 -2
  28. package/types/models/modeling_utils.d.ts.map +1 -1
  29. package/types/pipelines/automatic-speech-recognition.d.ts +2 -2
  30. package/types/pipelines/automatic-speech-recognition.d.ts.map +1 -1
  31. package/types/pipelines/document-question-answering.d.ts +2 -2
  32. package/types/pipelines/document-question-answering.d.ts.map +1 -1
  33. package/types/pipelines/image-to-text.d.ts +4 -4
  34. package/types/pipelines/image-to-text.d.ts.map +1 -1
  35. package/types/pipelines/summarization.d.ts +2 -2
  36. package/types/pipelines/summarization.d.ts.map +1 -1
  37. package/types/pipelines/text-generation.d.ts +2 -2
  38. package/types/pipelines/text-generation.d.ts.map +1 -1
  39. package/types/pipelines/text2text-generation.d.ts +3 -3
  40. package/types/pipelines/text2text-generation.d.ts.map +1 -1
  41. package/types/pipelines/translation.d.ts +2 -2
  42. package/types/pipelines/translation.d.ts.map +1 -1
@@ -1,4 +1,4 @@
1
- var HT=Object.defineProperty;var Jr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ps=(t,e)=>{for(var r in e)HT(t,r,{get:e[r],enumerable:!0})};import XT from"fs";import zs from"path";import KT from"url";var YT="4.0.0-next.2",J1=typeof process<"u",Z1=J1&&process?.release?.name==="node",Pn=!sv(XT),ev=!sv(zs),QT=typeof globalThis.Deno<"u",sz=typeof globalThis.Bun<"u",tv=typeof window<"u"&&typeof window.document<"u",rv=typeof self<"u"&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),pp=typeof self<"u"&&"caches"in self,JT=Z1||typeof navigator<"u"&&"gpu"in navigator,ZT=typeof navigator<"u"&&"ml"in navigator,eS=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,r=(navigator.vendor||"").indexOf("Apple")>-1,s=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return r&&s},tS=eS(),be=Object.freeze({IS_BROWSER_ENV:tv,IS_WEBWORKER_ENV:rv,IS_WEB_CACHE_AVAILABLE:pp,IS_WEBGPU_AVAILABLE:JT,IS_WEBNN_AVAILABLE:ZT,IS_SAFARI:tS,IS_PROCESS_AVAILABLE:J1,IS_NODE_ENV:Z1,IS_FS_AVAILABLE:Pn,IS_PATH_AVAILABLE:ev}),dp=Pn&&ev,zi="./";if(dp){let t=Object(import.meta).url;t?zi=zs.dirname(zs.dirname(KT.fileURLToPath(t))):typeof __dirname<"u"&&(zi=zs.dirname(__dirname))}var rS=dp?zs.join(zi,"/.cache/"):null,Q1="/models/",sS=dp?zs.join(zi,Q1):Q1,De={version:YT,backends:{onnx:{}},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(tv||rv),localModelPath:sS,useFS:Pn,useBrowserCache:pp&&!QT,useFSCache:Pn,cacheDir:rS,useCustomCache:!1,customCache:null,useWasmCache:pp||Pn,cacheKey:"transformers-cache"};function sv(t){return Object.keys(t).length===0}var nS=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let r of t){let s=e;for(let n=0;n<r.length;++n){let o=r[n];s=s[o]??=Object.create(null)}s.end=r}return e}split(t){let e=[],r=t.length,s=0,n=0;for(;n<r;){let o=this.trie,a=null,i=n;for(;i<r&&(o=o[t[i]]);)o.end&&(a=o.end),++i;a?(n>s&&e.push(t.slice(s,n)),e.push(a),n+=a.length,s=n):++n}return s<r&&e.push(t.slice(s)),e}},nv=nS,oS=class{constructor(t){this.content=t.content,this.id=t.id,this.single_word=t.single_word??!1,this.lstrip=t.lstrip??!1,this.rstrip=t.rstrip??!1,this.special=t.special??!1,this.normalized=t.normalized??!this.special}},aS=oS,pv=(()=>{let t=[...Array.from({length:94},(n,o)=>o+33),...Array.from({length:12},(n,o)=>o+161),...Array.from({length:82},(n,o)=>o+174)],e=t.slice(),r=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+r),r+=1);let s=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,s[o]]))})(),iS=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),lS=iS(pv),ov=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",cS=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],[` ?[^(\\s|[${ov}])]+`,` ?[^\\s${ov}]+`]]),Li="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",mp=t=>t.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n't/g,"n't").replace(/ 'm/g,"'m").replace(/ 's/g,"'s").replace(/ 've/g,"'ve").replace(/ 're/g,"'re"),Ni=(t,e=!0)=>{if(t.Regex!==void 0){let r=t.Regex.replace(/\\([#&~])/g,"$1");for(let[s,n]of cS)r=r.replaceAll(s,n);try{return new RegExp(r,"gu")}catch(s){if(!(s instanceof SyntaxError)||!s.message.toLowerCase().includes("invalid property name"))throw s;let n=!1,o=r.replace(/(\\[pP])\{([^}=]+)\}/g,(a,i,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${i}{${l}}`}catch{return n=!0,`${i}{Script=${l}}`}});if(!n)throw s;try{return new RegExp(o,"gu")}catch{throw s}}}else if(t.String!==void 0){let r=uS(t.String);return new RegExp(e?r:`(${r})`,"gu")}else return console.warn("Unknown pattern type:",t),null},uS=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),pS=(t,e,r)=>{let s=[],n=0;for(;n<t.length;){if(s.push(t[n]),(e.get(t[n])??r)!==r){++n;continue}for(;++n<t.length&&(e.get(t[n])??r)===r;)e.get(s.at(-1))!==r&&(s[s.length-1]+=t[n])}return s},dS=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,fS=t=>Number.isInteger(t)||typeof t=="bigint",mS=t=>{let e=0;for(let r of t)++e;return e},hS=t=>dv(t.toLowerCase()),Wt=(...t)=>Array.prototype.concat.apply([],t),hp=t=>new Map(Object.entries(t)),_S=(t,e)=>{let r=[],s=0;for(let n of t.matchAll(e)){let o=n[0];s<n.index&&r.push(t.slice(s,n.index)),o.length>0&&r.push(o),s=n.index+o.length}return s<t.length&&r.push(t.slice(s)),r},dv=t=>t.replace(/\p{M}/gu,""),av=(t,e,r=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let s of r)if(!(s in t))return`${e} must contain a "${s}" property`;return null},gS=t=>t.match(/\S+/g)||[],wS=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},zn=wS,xS=class extends zn{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},mr=xS,yS=class extends mr{tokenize_chinese_chars(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r],n=s.charCodeAt(0);dS(n)?(e.push(" "),e.push(s),e.push(" ")):e.push(s)}return e.join("")}strip_accents(t){return t.normalize("NFD").replace(/\p{Mn}/gu,"")}is_control(t){switch(t){case" ":case`
1
+ var HT=Object.defineProperty;var Jr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ps=(t,e)=>{for(var r in e)HT(t,r,{get:e[r],enumerable:!0})};import XT from"fs";import zs from"path";import KT from"url";var YT="4.0.0-next.3",J1=typeof process<"u",Z1=J1&&process?.release?.name==="node",Pn=!sv(XT),ev=!sv(zs),QT=typeof globalThis.Deno<"u",sz=typeof globalThis.Bun<"u",tv=typeof window<"u"&&typeof window.document<"u",rv=typeof self<"u"&&["DedicatedWorkerGlobalScope","ServiceWorkerGlobalScope","SharedWorkerGlobalScope"].includes(self.constructor?.name),pp=typeof self<"u"&&"caches"in self,JT=Z1||typeof navigator<"u"&&"gpu"in navigator,ZT=typeof navigator<"u"&&"ml"in navigator,eS=()=>{if(typeof navigator>"u")return!1;let t=navigator.userAgent,r=(navigator.vendor||"").indexOf("Apple")>-1,s=!t.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i)&&!t.includes("Chrome")&&!t.includes("Android");return r&&s},tS=eS(),be=Object.freeze({IS_BROWSER_ENV:tv,IS_WEBWORKER_ENV:rv,IS_WEB_CACHE_AVAILABLE:pp,IS_WEBGPU_AVAILABLE:JT,IS_WEBNN_AVAILABLE:ZT,IS_SAFARI:tS,IS_PROCESS_AVAILABLE:J1,IS_NODE_ENV:Z1,IS_FS_AVAILABLE:Pn,IS_PATH_AVAILABLE:ev}),dp=Pn&&ev,zi="./";if(dp){let t=Object(import.meta).url;t?zi=zs.dirname(zs.dirname(KT.fileURLToPath(t))):typeof __dirname<"u"&&(zi=zs.dirname(__dirname))}var rS=dp?zs.join(zi,"/.cache/"):null,Q1="/models/",sS=dp?zs.join(zi,Q1):Q1,De={version:YT,backends:{onnx:{}},allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!(tv||rv),localModelPath:sS,useFS:Pn,useBrowserCache:pp&&!QT,useFSCache:Pn,cacheDir:rS,useCustomCache:!1,customCache:null,useWasmCache:pp||Pn,cacheKey:"transformers-cache"};function sv(t){return Object.keys(t).length===0}var nS=class{constructor(t){this.trie=this._build_trie(t)}_build_trie(t){let e=Object.create(null);for(let r of t){let s=e;for(let n=0;n<r.length;++n){let o=r[n];s=s[o]??=Object.create(null)}s.end=r}return e}split(t){let e=[],r=t.length,s=0,n=0;for(;n<r;){let o=this.trie,a=null,i=n;for(;i<r&&(o=o[t[i]]);)o.end&&(a=o.end),++i;a?(n>s&&e.push(t.slice(s,n)),e.push(a),n+=a.length,s=n):++n}return s<r&&e.push(t.slice(s)),e}},nv=nS,oS=class{constructor(t){this.content=t.content,this.id=t.id,this.single_word=t.single_word??!1,this.lstrip=t.lstrip??!1,this.rstrip=t.rstrip??!1,this.special=t.special??!1,this.normalized=t.normalized??!this.special}},aS=oS,pv=(()=>{let t=[...Array.from({length:94},(n,o)=>o+33),...Array.from({length:12},(n,o)=>o+161),...Array.from({length:82},(n,o)=>o+174)],e=t.slice(),r=0;for(let n=0;n<256;++n)t.includes(n)||(t.push(n),e.push(256+r),r+=1);let s=e.map(n=>String.fromCharCode(n));return Object.fromEntries(t.map((n,o)=>[n,s[o]]))})(),iS=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),lS=iS(pv),ov=".,!?\u2026\u3002\uFF0C\u3001\u0964\u06D4\u060C",cS=new Map([["(?i:'s|'t|'re|'ve|'m|'ll|'d)","(?:'([sS]|[tT]|[rR][eE]|[vV][eE]|[mM]|[lL][lL]|[dD]))"],["(?i:[sdmt]|ll|ve|re)","(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])"],["[^\\r\\n\\p{L}\\p{N}]?+","[^\\r\\n\\p{L}\\p{N}]?"],["[^\\s\\p{L}\\p{N}]++","[^\\s\\p{L}\\p{N}]+"],[` ?[^(\\s|[${ov}])]+`,` ?[^\\s${ov}]+`]]),Li="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",mp=t=>t.replace(/ \./g,".").replace(/ \?/g,"?").replace(/ \!/g,"!").replace(/ ,/g,",").replace(/ \' /g,"'").replace(/ n't/g,"n't").replace(/ 'm/g,"'m").replace(/ 's/g,"'s").replace(/ 've/g,"'ve").replace(/ 're/g,"'re"),Ni=(t,e=!0)=>{if(t.Regex!==void 0){let r=t.Regex.replace(/\\([#&~])/g,"$1");for(let[s,n]of cS)r=r.replaceAll(s,n);try{return new RegExp(r,"gu")}catch(s){if(!(s instanceof SyntaxError)||!s.message.toLowerCase().includes("invalid property name"))throw s;let n=!1,o=r.replace(/(\\[pP])\{([^}=]+)\}/g,(a,i,l)=>{try{return new RegExp(`\\p{${l}}`,"u"),`${i}{${l}}`}catch{return n=!0,`${i}{Script=${l}}`}});if(!n)throw s;try{return new RegExp(o,"gu")}catch{throw s}}}else if(t.String!==void 0){let r=uS(t.String);return new RegExp(e?r:`(${r})`,"gu")}else return console.warn("Unknown pattern type:",t),null},uS=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),pS=(t,e,r)=>{let s=[],n=0;for(;n<t.length;){if(s.push(t[n]),(e.get(t[n])??r)!==r){++n;continue}for(;++n<t.length&&(e.get(t[n])??r)===r;)e.get(s.at(-1))!==r&&(s[s.length-1]+=t[n])}return s},dS=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,fS=t=>Number.isInteger(t)||typeof t=="bigint",mS=t=>{let e=0;for(let r of t)++e;return e},hS=t=>dv(t.toLowerCase()),Wt=(...t)=>Array.prototype.concat.apply([],t),hp=t=>new Map(Object.entries(t)),_S=(t,e)=>{let r=[],s=0;for(let n of t.matchAll(e)){let o=n[0];s<n.index&&r.push(t.slice(s,n.index)),o.length>0&&r.push(o),s=n.index+o.length}return s<t.length&&r.push(t.slice(s)),r},dv=t=>t.replace(/\p{M}/gu,""),av=(t,e,r=[])=>{if(!t||Array.isArray(t)||typeof t!="object")return`${e} must be a valid object`;for(let s of r)if(!(s in t))return`${e} must contain a "${s}" property`;return null},gS=t=>t.match(/\S+/g)||[],wS=class{constructor(){let t=function(...e){return t._call(...e)};return Object.setPrototypeOf(t,new.target.prototype)}},zn=wS,xS=class extends zn{constructor(t){super(),this.config=t}_call(t){return this.normalize(t)}},mr=xS,yS=class extends mr{tokenize_chinese_chars(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r],n=s.charCodeAt(0);dS(n)?(e.push(" "),e.push(s),e.push(" ")):e.push(s)}return e.join("")}strip_accents(t){return t.normalize("NFD").replace(/\p{Mn}/gu,"")}is_control(t){switch(t){case" ":case`
2
2
  `:case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(t)}}clean_text(t){let e=[];for(let r of t){let s=r.charCodeAt(0);s===0||s===65533||this.is_control(r)||(/^\s$/.test(r)?e.push(" "):e.push(r))}return e.join("")}normalize(t){return this.config.clean_text&&(t=this.clean_text(t)),this.config.handle_chinese_chars&&(t=this.tokenize_chinese_chars(t)),this.config.lowercase?(t=t.toLowerCase(),this.config.strip_accents!==!1&&(t=this.strip_accents(t))):this.config.strip_accents&&(t=this.strip_accents(t)),t}},bS=yS,vS=class extends mr{constructor(t){super(t),this.charsmap=t.precompiled_charsmap??null}normalize(t){return t=t.replace(/[\u0001-\u0008\u000B\u000E-\u001F\u007F\u008F\u009F]/gm,""),t=t.replace(/[\u0009\u000A\u000C\u000D\u00A0\u1680\u2000-\u200F\u2028\u2029\u202F\u205F\u2581\u3000\uFEFF\uFFFD]/gm," "),t.includes("\uFF5E")?t=t.split("\uFF5E").map(r=>r.normalize("NFKC")).join("\uFF5E"):t=t.normalize("NFKC"),t}},kS=vS,ES=class extends mr{constructor(t){super(t),this.normalizers=(t.normalizers??[]).map(e=>fv(e))}normalize(t){return this.normalizers.reduce((e,r)=>r?r.normalize(e):e,t)}},AS=ES,MS=class extends mr{normalize(t){let e=Ni(this.config.pattern??{});return e===null?t:t.replaceAll(e,this.config.content??"")}},TS=MS,SS=class extends mr{constructor(){super(...arguments),this.form="NFC"}normalize(t){return t=t.normalize(this.form),t}},$i=SS,OS=class extends $i{constructor(){super(...arguments),this.form="NFC"}},IS=OS,CS=class extends $i{constructor(){super(...arguments),this.form="NFD"}},PS=CS,zS=class extends $i{constructor(){super(...arguments),this.form="NFKC"}},LS=zS,NS=class extends $i{constructor(){super(...arguments),this.form="NFKD"}},$S=NS,RS=class extends mr{normalize(t){return this.config.strip_left&&this.config.strip_right?t=t.trim():(this.config.strip_left&&(t=t.trimStart()),this.config.strip_right&&(t=t.trimEnd())),t}},US=RS,BS=class extends mr{normalize(t){return dv(t)}},DS=BS,FS=class extends mr{normalize(t){return t.toLowerCase()}},jS=FS,GS=class extends mr{normalize(t){return t=this.config.prepend+t,t}},qS=GS;function WS(t){if(t===null)return null;switch(t.type){case"BertNormalizer":return new bS(t);case"Precompiled":return new kS(t);case"Sequence":return new AS(t);case"Replace":return new TS(t);case"NFC":return new IS(t);case"NFD":return new PS(t);case"NFKC":return new LS(t);case"NFKD":return new $S(t);case"Strip":return new US(t);case"StripAccents":return new DS(t);case"Lowercase":return new jS(t);case"Prepend":return new qS(t);default:throw new Error(`Unknown Normalizer type: ${t.type}`)}}var fv=WS,VS=class extends zn{pre_tokenize(t,e){return(Array.isArray(t)?t.map(r=>this.pre_tokenize_text(r,e)):this.pre_tokenize_text(t,e)).flat()}_call(t,e){return this.pre_tokenize(t,e)}},Vt=VS,HS=class extends Vt{constructor(t){super(),this.config=t,this.add_prefix_space=this.config.add_prefix_space??!1,this.trim_offsets=this.config.trim_offsets??!1,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=pv,this.text_encoder=new TextEncoder}pre_tokenize_text(t,e){return this.add_prefix_space&&!t.startsWith(" ")&&(t=" "+t),(this.use_regex?t.match(this.pattern)||[]:[t]).map(s=>Array.from(this.text_encoder.encode(s),n=>this.byte_encoder[n]).join(""))}},XS=HS,KS=class extends Vt{pre_tokenize_text(t,e){return t.match(/\w+|[^\w\s]+/g)||[]}},YS=KS,QS=class extends Vt{constructor(t){super(),this.replacement=t.replacement??"\u2581",this.str_rep=t.str_rep||this.replacement,this.prepend_scheme=t.prepend_scheme??"always"}pre_tokenize_text(t,e){let{section_index:r=void 0}=e??{},s=t.replaceAll(" ",this.str_rep);return!s.startsWith(this.replacement)&&(this.prepend_scheme==="always"||this.prepend_scheme==="first"&&r===0)&&(s=this.str_rep+s),[s]}},JS=QS,ZS=class extends Vt{constructor(t){super(),this.config=t,this.pattern=Ni(this.config.pattern??{},this.config.invert??!0)}pre_tokenize_text(t){return this.pattern===null?[]:this.config.invert?t.match(this.pattern)||[]:this.config.behavior?.toLowerCase()==="removed"?t.split(this.pattern).filter(e=>e):_S(t,this.pattern)}},eO=ZS,tO=class extends Vt{constructor(t){super(),this.config=t,this.pattern=new RegExp(`[^${Li}]+|[${Li}]+`,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},rO=tO,sO=class extends Vt{constructor(t){super(),this.config=t;let e=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=new RegExp(e,"gu")}pre_tokenize_text(t){return t.match(this.pattern)||[]}},nO=sO,oO=class extends Vt{constructor(){super(),this.pattern=new RegExp(`[^\\s${Li}]+|[${Li}]`,"gu")}pre_tokenize_text(t,e){return t.trim().match(this.pattern)||[]}},aO=oO,iO=class extends Vt{constructor(t){super(),this.config=t,this.pattern=Ni(this.config.pattern??{}),this.content=this.config.content??""}pre_tokenize_text(t){return this.pattern===null?[t]:[t.replaceAll(this.pattern,this.config.content??"")]}},lO=iO,cO=class extends Vt{constructor(t){super(),this.tokenizers=(t.pretokenizers??[]).map(e=>mv(e))}pre_tokenize_text(t,e){return this.tokenizers.reduce((r,s)=>s?s.pre_tokenize(r,e):r,[t])}},uO=cO,pO=class extends Vt{pre_tokenize_text(t){return gS(t)}},dO=pO,fO=class extends Vt{constructor(t){super(),this.config=t,this._length=t.length}pre_tokenize_text(t){let e=[];for(let r=0;r<t.length;r+=this._length)e.push(t.slice(r,r+this._length));return e}},mO=fO;function hO(t){if(t===null)return null;switch(t.type){case"BertPreTokenizer":return new aO;case"Sequence":return new uO(t);case"Whitespace":return new YS;case"WhitespaceSplit":return new dO;case"Metaspace":return new JS(t);case"ByteLevel":return new XS(t);case"Split":return new eO(t);case"Punctuation":return new rO(t);case"Digits":return new nO(t);case"Replace":return new lO(t);case"FixedLength":return new mO(t);default:throw new Error(`Unknown PreTokenizer type: ${t.type}`)}}var mv=hO,_O=class extends zn{constructor(t){super(),this.config=t,this.vocab=[],this.tokens_to_ids=new Map,this.unk_token_id=void 0,this.unk_token=void 0,this.end_of_word_suffix=void 0,this.fuse_unk=this.config.fuse_unk??!1}_call(t){let e=this.encode(t);return this.fuse_unk&&(e=pS(e,this.tokens_to_ids,this.unk_token_id)),e}},Ri=_O,gO=class extends Ri{constructor(t){super(t),this.max_input_chars_per_word=100,this.tokens_to_ids=hp(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.max_input_chars_per_word=t.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(let[e,r]of this.tokens_to_ids)this.vocab[r]=e}encode(t){let e=[];for(let r of t){let s=[...r];if(s.length>this.max_input_chars_per_word){e.push(this.unk_token);continue}let n=!1,o=0,a=[];for(;o<s.length;){let i=s.length,l=null;for(;o<i;){let u=s.slice(o,i).join("");if(o>0&&(u=this.config.continuing_subword_prefix+u),this.tokens_to_ids.has(u)){l=u;break}--i}if(l===null){n=!0;break}a.push(l),o=i}n?e.push(this.unk_token):e.push(...a)}return e}},iv=gO,lv=class hv{constructor(e,r){this.is_leaf=e,this.children=r}static default(){return new hv(!1,new Map)}},wO=class{constructor(){this.root=lv.default()}extend(t){for(let e of t)this.push(e)}push(t){let e=this.root;for(let r of t){let s=e.children.get(r);s===void 0&&(s=lv.default(),e.children.set(r,s)),e=s}e.is_leaf=!0}*common_prefix_search(t){let e=this.root;if(e===void 0)return;let r="";for(let s of t){if(r+=s,e=e.children.get(s),e===void 0)return;e.is_leaf&&(yield r)}}},xO=wO,fp=class _v{constructor(e,r,s,n,o){this.token_id=e,this.node_id=r,this.pos=s,this.length=n,this.score=o,this.prev=null,this.backtrace_score=0}clone(){let e=new _v(this.token_id,this.node_id,this.pos,this.length,this.score);return e.prev=this.prev,e.backtrace_score=this.backtrace_score,e}},yO=class{constructor(t,e,r){this.chars=Array.from(t),this.len=this.chars.length,this.bos_token_id=e,this.eos_token_id=r,this.nodes=[],this.begin_nodes=Array.from({length:this.len+1},()=>[]),this.end_nodes=Array.from({length:this.len+1},()=>[]);let s=new fp(this.bos_token_id??0,0,0,0,0),n=new fp(this.eos_token_id??0,1,this.len,0,0);this.nodes.push(s.clone()),this.nodes.push(n.clone()),this.begin_nodes[this.len].push(n),this.end_nodes[0].push(s)}insert(t,e,r,s){let n=this.nodes.length,o=new fp(s,n,t,e,r);this.begin_nodes[t].push(o),this.end_nodes[t+e].push(o),this.nodes.push(o)}viterbi(){let t=this.len,e=0;for(;e<=t;){if(this.begin_nodes[e].length==0)return[];for(let a of this.begin_nodes[e]){a.prev=null;let i=0,l=null;for(let u of this.end_nodes[e]){let d=u.backtrace_score+a.score;(l===null||d>i)&&(l=u.clone(),i=d)}if(l!==null)a.prev=l,a.backtrace_score=i;else return[]}++e}let r=[],n=this.begin_nodes[t][0].prev;if(n===null)return[];let o=n.clone();for(;o.prev!==null;)r.push(o.clone()),o=o.clone().prev.clone();return r.reverse(),r}piece(t){return this.chars.slice(t.pos,t.pos+t.length).join("")}tokens(){return this.viterbi().map(e=>this.piece(e))}token_ids(){return this.viterbi().map(e=>e.token_id)}},bO=yO;function vO(t){if(t.length===0)throw new Error("Array must not be empty");let e=t[0],r=0;for(let s=1;s<t.length;++s)t[s]<e&&(e=t[s],r=s);return[e,r]}var kO=class extends Ri{constructor(t,e){super(t);let r=t.vocab.length;this.vocab=new Array(r),this.scores=new Array(r);for(let s=0;s<r;++s)[this.vocab[s],this.scores[s]]=t.vocab[s];this.unk_token_id=t.unk_id,this.unk_token=this.vocab[t.unk_id],this.tokens_to_ids=new Map(this.vocab.map((s,n)=>[s,n])),this.bos_token=" ",this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.unk_token=this.vocab[this.unk_token_id],this.min_score=vO(this.scores)[0],this.unk_score=this.min_score-10,this.scores[this.unk_token_id]=this.unk_score,this.trie=new xO,this.trie.extend(this.vocab),this.fuse_unk=!0}populate_nodes(t){let e=t.chars,r=1,s=0;for(;s<e.length;){let n=!1,o=[],a=e.slice(s).join(""),i=this.trie.common_prefix_search(a);for(let l of i){o.push(l);let u=this.tokens_to_ids.get(l),d=this.scores[u],f=mS(l);t.insert(s,f,d,u),!n&&f===r&&(n=!0)}n||t.insert(s,r,this.unk_score,this.unk_token_id),s+=r}}tokenize(t){let e=new bO(t,this.bos_token_id,this.eos_token_id);return this.populate_nodes(e),e.tokens()}encode(t){let e=[];for(let r of t){let s=this.tokenize(r);e.push(...s)}return e}},cv=kO,EO=class{constructor(t=(r,s)=>r>s,e=1/0){this._heap=[],this._comparator=t,this._max_size=e}get size(){return this._heap.length}is_empty(){return this.size===0}peek(){return this._heap[0]}push(...t){return this.extend(t)}extend(t){for(let e of t)if(this.size<this._max_size)this._heap.push(e),this._sift_up();else{let r=this._smallest();this._comparator(e,this._heap[r])&&(this._heap[r]=e,this._sift_up_from(r))}return this.size}pop(){let t=this.peek(),e=this.size-1;return e>0&&this._swap(0,e),this._heap.pop(),this._sift_down(),t}replace(t){let e=this.peek();return this._heap[0]=t,this._sift_down(),e}_parent(t){return(t+1>>>1)-1}_left(t){return(t<<1)+1}_right(t){return t+1<<1}_greater(t,e){return this._comparator(this._heap[t],this._heap[e])}_swap(t,e){let r=this._heap[t];this._heap[t]=this._heap[e],this._heap[e]=r}_sift_up(){this._sift_up_from(this.size-1)}_sift_up_from(t){for(;t>0&&this._greater(t,this._parent(t));)this._swap(t,this._parent(t)),t=this._parent(t)}_sift_down(){let t=0;for(;this._left(t)<this.size&&this._greater(this._left(t),t)||this._right(t)<this.size&&this._greater(this._right(t),t);){let e=this._right(t)<this.size&&this._greater(this._right(t),this._left(t))?this._right(t):this._left(t);this._swap(t,e),t=e}}_smallest(){return 2**Math.floor(Math.log2(this.size))-1}},AO=EO,MO=class{constructor(t){this.capacity=t,this.cache=new Map}get(t){if(!this.cache.has(t))return;let e=this.cache.get(t);return this.cache.delete(t),this.cache.set(t,e),e}put(t,e){this.cache.has(t)&&this.cache.delete(t),this.cache.set(t,e),this.cache.size>this.capacity&&this.cache.delete(this.cache.keys().next().value)}clear(){this.cache.clear()}},TO=MO,SO=class extends Ri{constructor(t){super(t),this.tokens_to_ids=hp(t.vocab),this.unk_token_id=this.tokens_to_ids.get(t.unk_token),this.unk_token=t.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(let[r,s]of this.tokens_to_ids)this.vocab[s]=r;let e=Array.isArray(t.merges[0]);this.merges=e?t.merges:t.merges.map(r=>r.split(" ",2)),this.bpe_ranks=new Map(this.merges.map((r,s)=>[JSON.stringify(r),s])),this.end_of_word_suffix=t.end_of_word_suffix,this.continuing_subword_suffix=t.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.ignore_merges=this.config.ignore_merges??!1,this.max_length_to_cache=256,this.cache_capacity=1e4,this.cache=new TO(this.cache_capacity)}clear_cache(){this.cache.clear()}bpe(t){if(t.length===0)return[];let e=this.cache.get(t);if(e!==void 0)return e;let r=Array.from(t);this.end_of_word_suffix&&(r[r.length-1]+=this.end_of_word_suffix);let s=[];if(r.length>1){let n=new AO((i,l)=>i.score<l.score),o={token:r[0],bias:0,prev:null,next:null},a=o;for(let i=1;i<r.length;++i){let l={bias:i/r.length,token:r[i],prev:a,next:null};a.next=l,this.add_node(n,a),a=l}for(;!n.is_empty();){let i=n.pop();if(i.deleted||!i.next||i.next.deleted)continue;if(i.deleted=!0,i.next.deleted=!0,i.prev){let u={...i.prev};i.prev.deleted=!0,i.prev=u,u.prev?u.prev.next=u:o=u}let l={token:i.token+i.next.token,bias:i.bias,prev:i.prev,next:i.next.next};l.prev?(l.prev.next=l,this.add_node(n,l.prev)):o=l,l.next&&(l.next.prev=l,this.add_node(n,l))}for(let i=o;i!==null;i=i.next)s.push(i.token)}else s=r;if(this.continuing_subword_suffix)for(let n=0;n<s.length-1;++n)s[n]+=this.continuing_subword_suffix;return t.length<this.max_length_to_cache&&this.cache.put(t,s),s}add_node(t,e){let r=this.bpe_ranks.get(JSON.stringify([e.token,e.next.token]));r!==void 0&&(e.score=r+e.bias,t.push(e))}encode(t){let e=[];for(let r of t){if(this.ignore_merges&&this.tokens_to_ids.has(r)){e.push(r);continue}let s=this.bpe(r);for(let n of s)if(this.tokens_to_ids.has(n))e.push(n);else if(this.byte_fallback){let o=Array.from(this.text_encoder.encode(n)).map(a=>`<0x${a.toString(16).toUpperCase().padStart(2,"0")}>`);o.every(a=>this.tokens_to_ids.has(a))?e.push(...o):e.push(this.unk_token)}else e.push(this.unk_token)}return e}},uv=SO,OO=class extends Ri{constructor(t,e){super(t);let r=t.vocab;this.tokens_to_ids=hp(e.target_lang?r[e.target_lang]:r),this.bos_token=e.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=e.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=e.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=e.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(let[s,n]of this.tokens_to_ids)this.vocab[n]=s}encode(t){return t}},IO=OO;function CO(t,e){switch(t.type){case"WordPiece":return new iv(t);case"Unigram":return new cv(t,e.eos_token);case"BPE":return new uv(t);default:if(t.vocab)return Array.isArray(t.vocab)?new cv(t,e.eos_token):Object.hasOwn(t,"continuing_subword_prefix")&&Object.hasOwn(t,"unk_token")?Object.hasOwn(t,"merges")?new uv(t):new iv(t):new IO(t,{target_lang:e.target_lang,bos_token:e.bos_token,eos_token:e.eos_token,pad_token:e.pad_token,unk_token:e.unk_token});throw new Error(`Unknown TokenizerModel type: ${t?.type}`)}}var PO=CO,zO=class extends zn{constructor(t){super(),this.config=t}_call(t,...e){return this.post_process(t,...e)}},Ln=zO,LO=class extends Ln{post_process(t,e=null,r=!0){let s=e===null?this.config.single:this.config.pair,n=[],o=[];for(let a of s)"SpecialToken"in a?r&&(n.push(a.SpecialToken.id),o.push(a.SpecialToken.type_id)):"Sequence"in a&&(a.Sequence.id==="A"?(n=Wt(n,t),o=Wt(o,new Array(t.length).fill(a.Sequence.type_id))):a.Sequence.id==="B"&&(n=Wt(n,e),o=Wt(o,new Array(e.length).fill(a.Sequence.type_id))));return{tokens:n,token_type_ids:o}}},NO=LO,$O=class extends Ln{post_process(t,e=null){return{tokens:t,tokens_pair:e}}},RO=$O,UO=class extends Ln{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e=null,r=!0){r&&(t=Wt([this.cls[0]],t,[this.sep[0]]));let s=new Array(t.length).fill(0);if(e){let n=[],o=r?[this.sep[0]]:[];t=Wt(t,n,e,o),s=Wt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},BO=UO,DO=class extends Ln{constructor(t){super(t),this.sep=t.sep,this.cls=t.cls}post_process(t,e,r=!0){r&&(t=Wt([this.cls[0]],t,[this.sep[0]]));let s=new Array(t.length).fill(0);if(e){let n=r?[this.sep[0]]:[],o=r?[this.sep[0]]:[];t=Wt(t,n,e,o),s=Wt(s,new Array(e.length+n.length+o.length).fill(1))}return{tokens:t,token_type_ids:s}}},FO=DO,jO=class extends Ln{constructor(t){super(t),this.processors=(t.processors??[]).map(e=>gv(e))}post_process(t,e=null,r=!0){let s={tokens:t,tokens_pair:e};for(let n of this.processors)s=n.post_process(s.tokens,s.tokens_pair,r);return s}},GO=jO;function qO(t){if(t===null)return null;switch(t.type){case"TemplateProcessing":return new NO(t);case"ByteLevel":return new RO(t);case"BertProcessing":return new BO(t);case"RobertaProcessing":return new FO(t);case"Sequence":return new GO(t);default:throw new Error(`Unknown PostProcessor type: ${t.type}`)}}var gv=qO,WO=class extends zn{constructor(t){super(),this.config=t,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets="trim_offsets"in t?t.trim_offsets:!1}_call(t){return this.decode(t)}decode(t){return this.decode_chain(t).join("")}},$t=WO,VO=class extends $t{constructor(t){super(t),this.byte_decoder=lS,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(t){let e=t.join(""),r=new Uint8Array([...e].map(s=>this.byte_decoder[s]));return this.text_decoder.decode(r)}decode_chain(t){let e=[],r=[];for(let s of t)this.added_tokens.find(n=>n.content===s)!==void 0?(r.length>0&&(e.push(this.convert_tokens_to_string(r)),r=[]),e.push(s)):r.push(s);return r.length>0&&e.push(this.convert_tokens_to_string(r)),e}},HO=VO,XO=class extends $t{constructor(t){super(t),this.cleanup=t.cleanup}decode_chain(t){return t.map((e,r)=>{if(r!==0){let s=this.config.prefix;s&&e.startsWith(s)?e=e.replace(s,""):e=" "+e}return this.cleanup&&(e=mp(e)),e})}},KO=XO,YO=class extends $t{constructor(t){super(t),this.replacement=t.replacement??"\u2581"}decode_chain(t){let e=[];for(let r=0;r<t.length;++r){let s=t[r].replaceAll(this.replacement," ");r==0&&s.startsWith(" ")&&(s=s.substring(1)),e.push(s)}return e}},QO=YO,JO=class extends $t{constructor(t){super(t),this.suffix=t.suffix??""}decode_chain(t){return t.map((e,r)=>e.replaceAll(this.suffix,r===t.length-1?"":" "))}},ZO=JO,eI=class extends $t{constructor(t){super(t),this.pad_token=t.pad_token??"",this.word_delimiter_token=t.word_delimiter_token??"",this.cleanup=t.cleanup}convert_tokens_to_string(t){if(t.length===0)return"";let e=[t[0]];for(let n=1;n<t.length;++n)t[n]!==e.at(-1)&&e.push(t[n]);let s=e.filter(n=>n!==this.pad_token).join("");return this.cleanup&&(s=mp(s).replaceAll(this.word_delimiter_token," ").trim()),s}decode_chain(t){return[this.convert_tokens_to_string(t)]}},tI=eI,rI=class extends $t{constructor(t){super(t),this.decoders=(t.decoders??[]).map(e=>wv(e))}decode_chain(t){return this.decoders.reduce((e,r)=>r.decode_chain(e),t)}},sI=rI,nI=class extends $t{decode_chain(t){let e=Ni(this.config.pattern),r=this.config.content??"";return e===null?t:t.map(s=>s.replaceAll(e,r))}},oI=nI,aI=class extends $t{decode_chain(t){return[t.join("")]}},iI=aI,lI=class extends $t{constructor(t){super(t),this.content=t.content??"",this.start=t.start??0,this.stop=t.stop??0}decode_chain(t){return t.map(e=>{let r=0;for(let n=0;n<this.start&&e[n]===this.content;++n){r=n+1;continue}let s=e.length;for(let n=0;n<this.stop;++n){let o=e.length-n-1;if(e[o]===this.content){s=o;continue}else break}return e.slice(r,s)})}},cI=lI,uI=class extends $t{constructor(t){super(t),this.text_decoder=new TextDecoder}decode_chain(t){let e=[],r=[];for(let s of t){let n=null;if(s.length===6&&s.startsWith("<0x")&&s.endsWith(">")){let o=parseInt(s.slice(3,5),16);isNaN(o)||(n=o)}if(n!==null)r.push(n);else{if(r.length>0){let o=this.text_decoder.decode(Uint8Array.from(r));e.push(o),r=[]}e.push(s)}}if(r.length>0){let s=this.text_decoder.decode(Uint8Array.from(r));e.push(s),r=[]}return e}},pI=uI;function dI(t){if(t===null)return null;switch(t.type){case"ByteLevel":return new HO(t);case"WordPiece":return new KO(t);case"Metaspace":return new QO(t);case"BPEDecoder":return new ZO(t);case"CTC":return new tI(t);case"Sequence":return new sI(t);case"Replace":return new oI(t);case"Fuse":return new iI(t);case"Strip":return new cI(t);case"ByteFallback":return new pI(t);default:throw new Error(`Unknown Decoder type: ${t.type}`)}}var wv=dI,fI=class{constructor(t,e){let r=av(t,"Tokenizer",["model","decoder","post_processor","pre_tokenizer","normalizer"]);if(r)throw new Error(r);let s=av(e,"Config");if(s)throw new Error(s);this.tokenizer=t,this.config=e,this.normalizer=fv(this.tokenizer.normalizer),this.pre_tokenizer=mv(this.tokenizer.pre_tokenizer),this.model=PO(this.tokenizer.model,this.config),this.post_processor=gv(this.tokenizer.post_processor),this.decoder=wv(this.tokenizer.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];let n=[],o=[];this.added_tokens_map=new Map;for(let a of this.tokenizer.added_tokens){let i=new aS(a);if(this.added_tokens.push(i),this.model.tokens_to_ids.set(i.content,i.id),this.model.vocab[i.id]=i.content,i.special&&(this.special_tokens.push(i.content),this.all_special_ids.push(i.id)),this.added_tokens_map.set(i.content,i),i.normalized&&this.normalizer!==null){let l=this.normalizer(i.content);o.push(l),this.added_tokens_map.set(l,i)}else n.push(i.content)}(this.config.additional_special_tokens??[]).forEach(a=>{this.special_tokens.includes(a)||this.special_tokens.push(a)}),this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.splitter_unnormalized=new nv(n),this.splitter_normalized=new nv(o),this.remove_space=this.config.remove_space,this.clean_up_tokenization_spaces=this.config.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=this.config.do_lowercase_and_remove_accent??!1}encode(t,{text_pair:e=null,add_special_tokens:r=!0,return_token_type_ids:s=null}={}){let{tokens:n,token_type_ids:o}=this.tokenize_helper(t,{text_pair:e,add_special_tokens:r}),a=n.map(l=>this.added_tokens_map.get(l)?.id??this.model.tokens_to_ids.get(l)??this.model.unk_token_id),i={ids:a,tokens:n,attention_mask:new Array(a.length).fill(1)};return s&&o&&(i.token_type_ids=o),i}decode(t,e={}){if(!Array.isArray(t)||t.length===0||!fS(t[0]))throw Error("token_ids must be a non-empty array of integers.");let r=t.map(n=>this.model.vocab[Number(n)]??this.model.unk_token);e.skip_special_tokens&&(r=r.filter(n=>!this.special_tokens.includes(n)));let s=this.decoder?this.decoder(r):r.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(s=s.replaceAll(this.decoder.end_of_word_suffix," "),e.skip_special_tokens&&(s=s.trim())),(e.clean_up_tokenization_spaces??this.clean_up_tokenization_spaces)&&(s=mp(s)),s}tokenize(t,{text_pair:e=null,add_special_tokens:r=!1}={}){return this.tokenize_helper(t,{text_pair:e,add_special_tokens:r}).tokens}encode_text(t){if(t===null)return null;let e=this.splitter_unnormalized.split(t);return e.forEach((r,s)=>{let n=this.added_tokens_map.get(r);n&&(n.lstrip&&s>0&&(e[s-1]=e[s-1].trimEnd()),n.rstrip&&s<e.length-1&&(e[s+1]=e[s+1].trimStart()))}),e.flatMap((r,s)=>{if(r.length===0)return[];if(this.added_tokens_map.has(r))return[r];if(this.remove_space===!0&&(r=r.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(r=hS(r)),this.normalizer!==null&&(r=this.normalizer(r)),r.length===0)return[];let n=this.splitter_normalized.split(r);return n.forEach((o,a)=>{let i=this.added_tokens_map.get(o);i&&(i.lstrip&&a>0&&(n[a-1]=n[a-1].trimEnd()),i.rstrip&&a<n.length-1&&(n[a+1]=n[a+1].trimStart()))}),n.flatMap(o=>{if(o.length===0)return[];if(this.added_tokens_map.has(o))return[o];let a=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:s}):[o];return this.model(a)})})}tokenize_helper(t,{text_pair:e=null,add_special_tokens:r=!0}){let s=this.encode_text(t),n=this.encode_text(e||null);return this.post_processor?this.post_processor(s,n,r):{tokens:Wt(s??[],n??[])}}token_to_id(t){return this.model.tokens_to_ids.get(t)}id_to_token(t){return this.model.vocab[t]}get_added_tokens_decoder(){let t=new Map;for(let e of this.added_tokens)t.set(e.id,e);return t}get_vocab(t=!0){let e=new Map;for(let r=0;r<this.model.vocab.length;++r){let s=this.model.vocab[r];(t||!this.added_tokens_map.has(s))&&e.set(s,r)}return e}},xv=fI;var $=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",OpenCurlyBracket:"OpenCurlyBracket",CloseCurlyBracket:"CloseCurlyBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Comment:"Comment"}),Rt=class{constructor(t,e){this.value=t,this.type=e}};function yv(t){return/\w/.test(t)}function Nn(t){return/[0-9]/.test(t)}function bv(t){return/\s/.test(t)}var mI=[["{%",$.OpenStatement],["%}",$.CloseStatement],["{{",$.OpenExpression],["}}",$.CloseExpression],["(",$.OpenParen],[")",$.CloseParen],["{",$.OpenCurlyBracket],["}",$.CloseCurlyBracket],["[",$.OpenSquareBracket],["]",$.CloseSquareBracket],[",",$.Comma],[".",$.Dot],[":",$.Colon],["|",$.Pipe],["<=",$.ComparisonBinaryOperator],[">=",$.ComparisonBinaryOperator],["==",$.ComparisonBinaryOperator],["!=",$.ComparisonBinaryOperator],["<",$.ComparisonBinaryOperator],[">",$.ComparisonBinaryOperator],["+",$.AdditiveBinaryOperator],["-",$.AdditiveBinaryOperator],["~",$.AdditiveBinaryOperator],["*",$.MultiplicativeBinaryOperator],["/",$.MultiplicativeBinaryOperator],["%",$.MultiplicativeBinaryOperator],["=",$.Equals]],hI=new Map([["n",`
3
3
  `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function _I(t,e={}){return t.endsWith(`
4
4
  `)&&(t=t.slice(0,-1)),e.lstrip_blocks&&(t=t.replace(/^[ \t]*({[#%-])/gm,"$1")),e.trim_blocks&&(t=t.replace(/([#%-]})\n/g,"$1")),t.replace(/{%\s*(end)?generation\s*%}/gs,"")}function gI(t,e={}){let r=[],s=_I(t,e),n=0,o=0,a=u=>{let d="";for(;u(s[n]);){if(s[n]==="\\"){if(++n,n>=s.length)throw new SyntaxError("Unexpected end of input");let f=s[n++],m=hI.get(f);if(m===void 0)throw new SyntaxError(`Unexpected escaped character: ${f}`);d+=m;continue}if(d+=s[n++],n>=s.length)throw new SyntaxError("Unexpected end of input")}return d},i=()=>{let u=r.at(-1);u&&u.type===$.Text&&(u.value=u.value.trimEnd(),u.value===""&&r.pop())},l=()=>{for(;n<s.length&&bv(s[n]);)++n};e:for(;n<s.length;){let u=r.at(-1)?.type;if(u===void 0||u===$.CloseStatement||u===$.CloseExpression||u===$.Comment){let f="";for(;n<s.length&&!(s[n]==="{"&&(s[n+1]==="%"||s[n+1]==="{"||s[n+1]==="#"));)f+=s[n++];if(f.length>0){r.push(new Rt(f,$.Text));continue}}if(s[n]==="{"&&s[n+1]==="#"){n+=2;let f=s[n]==="-";f&&++n;let m="";for(;s[n]!=="#"||s[n+1]!=="}";){if(n+2>=s.length)throw new SyntaxError("Missing end of comment tag");m+=s[n++]}let _=m.endsWith("-");_&&(m=m.slice(0,-1)),f&&i(),r.push(new Rt(m,$.Comment)),n+=2,_&&l();continue}if(s.slice(n,n+3)==="{%-"){i(),r.push(new Rt("{%",$.OpenStatement)),n+=3;continue}if(s.slice(n,n+3)==="{{-"){i(),r.push(new Rt("{{",$.OpenExpression)),o=0,n+=3;continue}if(a(bv),s.slice(n,n+3)==="-%}"){r.push(new Rt("%}",$.CloseStatement)),n+=3,l();continue}if(s.slice(n,n+3)==="-}}"){r.push(new Rt("}}",$.CloseExpression)),n+=3,l();continue}let d=s[n];if(d==="-"||d==="+"){let f=r.at(-1)?.type;if(f===$.Text||f===void 0)throw new SyntaxError(`Unexpected character: ${d}`);switch(f){case $.Identifier:case $.NumericLiteral:case $.StringLiteral:case $.CloseParen:case $.CloseSquareBracket:break;default:{++n;let m=a(Nn);r.push(new Rt(`${d}${m}`,m.length>0?$.NumericLiteral:$.UnaryOperator));continue}}}for(let[f,m]of mI){if(f==="}}"&&o>0)continue;if(s.slice(n,n+f.length)===f){r.push(new Rt(f,m)),m===$.OpenExpression?o=0:m===$.OpenCurlyBracket?++o:m===$.CloseCurlyBracket&&--o,n+=f.length;continue e}}if(d==="'"||d==='"'){++n;let f=a(m=>m!==d);r.push(new Rt(f,$.StringLiteral)),++n;continue}if(Nn(d)){let f=a(Nn);if(s[n]==="."&&Nn(s[n+1])){++n;let m=a(Nn);f=`${f}.${m}`}r.push(new Rt(f,$.NumericLiteral));continue}if(yv(d)){let f=a(yv);r.push(new Rt(f,$.Identifier));continue}throw new SyntaxError(`Unexpected character: ${d}`)}return r}var Xt=class{type="Statement"},wI=class extends Xt{constructor(t){super(),this.body=t}type="Program"},xI=class extends Xt{constructor(t,e,r){super(),this.test=t,this.body=e,this.alternate=r}type="If"},yI=class extends Xt{constructor(t,e,r,s){super(),this.loopvar=t,this.iterable=e,this.body=r,this.defaultBlock=s}type="For"},bI=class extends Xt{type="Break"},vI=class extends Xt{type="Continue"},kI=class extends Xt{constructor(t,e,r){super(),this.assignee=t,this.value=e,this.body=r}type="Set"},EI=class extends Xt{constructor(t,e,r){super(),this.name=t,this.args=e,this.body=r}type="Macro"},AI=class extends Xt{constructor(t){super(),this.value=t}type="Comment"},St=class extends Xt{type="Expression"},MI=class extends St{constructor(t,e,r){super(),this.object=t,this.property=e,this.computed=r}type="MemberExpression"},vv=class extends St{constructor(t,e){super(),this.callee=t,this.args=e}type="CallExpression"},Ls=class extends St{constructor(t){super(),this.value=t}type="Identifier"},Ns=class extends St{constructor(t){super(),this.value=t}type="Literal"},TI=class extends Ns{type="IntegerLiteral"},SI=class extends Ns{type="FloatLiteral"},kv=class extends Ns{type="StringLiteral"},OI=class extends Ns{type="ArrayLiteral"},Ev=class extends Ns{type="TupleLiteral"},II=class extends Ns{type="ObjectLiteral"},$n=class extends St{constructor(t,e,r){super(),this.operator=t,this.left=e,this.right=r}type="BinaryExpression"},CI=class extends St{constructor(t,e){super(),this.operand=t,this.filter=e}type="FilterExpression"},PI=class extends Xt{constructor(t,e){super(),this.filter=t,this.body=e}type="FilterStatement"},zI=class extends St{constructor(t,e){super(),this.lhs=t,this.test=e}type="SelectExpression"},LI=class extends St{constructor(t,e,r){super(),this.operand=t,this.negate=e,this.test=r}type="TestExpression"},NI=class extends St{constructor(t,e){super(),this.operator=t,this.argument=e}type="UnaryExpression"},$I=class extends St{constructor(t=void 0,e=void 0,r=void 0){super(),this.start=t,this.stop=e,this.step=r}type="SliceExpression"},RI=class extends St{constructor(t,e){super(),this.key=t,this.value=e}type="KeywordArgumentExpression"},UI=class extends St{constructor(t){super(),this.argument=t}type="SpreadExpression"},BI=class extends Xt{constructor(t,e,r){super(),this.call=t,this.callerArgs=e,this.body=r}type="CallStatement"},DI=class extends St{constructor(t,e,r){super(),this.condition=t,this.trueExpr=e,this.falseExpr=r}type="Ternary"};function FI(t){let e=new wI([]),r=0;function s(S,L){let R=t[r++];if(!R||R.type!==S)throw new Error(`Parser Error: ${L}. ${R.type} !== ${S}.`);return R}function n(S){if(!l(S))throw new SyntaxError(`Expected ${S}`);++r}function o(){switch(t[r].type){case $.Comment:return new AI(t[r++].value);case $.Text:return u();case $.OpenStatement:return d();case $.OpenExpression:return f();default:throw new SyntaxError(`Unexpected token type: ${t[r].type}`)}}function a(...S){return r+S.length<=t.length&&S.every((L,R)=>L===t[r+R].type)}function i(...S){return t[r]?.type===$.OpenStatement&&t[r+1]?.type===$.Identifier&&S.includes(t[r+1]?.value)}function l(...S){return r+S.length<=t.length&&S.every((L,R)=>t[r+R].type==="Identifier"&&L===t[r+R].value)}function u(){return new kv(s($.Text,"Expected text token").value)}function d(){if(s($.OpenStatement,"Expected opening statement token"),t[r].type!==$.Identifier)throw new SyntaxError(`Unknown statement, got ${t[r].type}`);let S=t[r].value,L;switch(S){case"set":++r,L=m();break;case"if":++r,L=_(),s($.OpenStatement,"Expected {% token"),n("endif"),s($.CloseStatement,"Expected %} token");break;case"macro":++r,L=w(),s($.OpenStatement,"Expected {% token"),n("endmacro"),s($.CloseStatement,"Expected %} token");break;case"for":++r,L=k(),s($.OpenStatement,"Expected {% token"),n("endfor"),s($.CloseStatement,"Expected %} token");break;case"call":{++r;let R=null;a($.OpenParen)&&(R=V());let te=ie();if(te.type!=="Identifier")throw new SyntaxError("Expected identifier following call statement");let ue=V();s($.CloseStatement,"Expected closing statement token");let Be=[];for(;!i("endcall");)Be.push(o());s($.OpenStatement,"Expected '{%'"),n("endcall"),s($.CloseStatement,"Expected closing statement token");let Ce=new vv(te,ue);L=new BI(Ce,R,Be);break}case"break":++r,s($.CloseStatement,"Expected closing statement token"),L=new bI;break;case"continue":++r,s($.CloseStatement,"Expected closing statement token"),L=new vI;break;case"filter":{++r;let R=ie();R instanceof Ls&&a($.OpenParen)&&(R=X(R)),s($.CloseStatement,"Expected closing statement token");let te=[];for(;!i("endfilter");)te.push(o());s($.OpenStatement,"Expected '{%'"),n("endfilter"),s($.CloseStatement,"Expected '%}'"),L=new PI(R,te);break}default:throw new SyntaxError(`Unknown statement type: ${S}`)}return L}function f(){s($.OpenExpression,"Expected opening expression token");let S=E();return s($.CloseExpression,"Expected closing expression token"),S}function m(){let S=x(),L=null,R=[];if(a($.Equals))++r,L=x();else{for(s($.CloseStatement,"Expected %} token");!i("endset");)R.push(o());s($.OpenStatement,"Expected {% token"),n("endset")}return s($.CloseStatement,"Expected closing statement token"),new kI(S,L,R)}function _(){let S=E();s($.CloseStatement,"Expected closing statement token");let L=[],R=[];for(;!i("elif","else","endif");)L.push(o());if(i("elif")){++r,++r;let te=_();R.push(te)}else if(i("else"))for(++r,++r,s($.CloseStatement,"Expected closing statement token");!i("endif");)R.push(o());return new xI(S,L,R)}function w(){let S=ie();if(S.type!=="Identifier")throw new SyntaxError("Expected identifier following macro statement");let L=V();s($.CloseStatement,"Expected closing statement token");let R=[];for(;!i("endmacro");)R.push(o());return new EI(S,L,R)}function x(S=!1){let L=S?ie:E,R=[L()],te=a($.Comma);for(;te&&(++r,R.push(L()),!!a($.Comma)););return te?new Ev(R):R[0]}function k(){let S=x(!0);if(!(S instanceof Ls||S instanceof Ev))throw new SyntaxError(`Expected identifier/tuple for the loop variable, got ${S.type} instead`);if(!l("in"))throw new SyntaxError("Expected `in` keyword following loop variable");++r;let L=E();s($.CloseStatement,"Expected closing statement token");let R=[];for(;!i("endfor","else");)R.push(o());let te=[];if(i("else"))for(++r,++r,s($.CloseStatement,"Expected closing statement token");!i("endfor");)te.push(o());return new yI(S,L,R,te)}function E(){return M()}function M(){let S=I();if(l("if")){++r;let L=I();if(l("else")){++r;let R=M();return new DI(L,S,R)}else return new zI(S,L)}return S}function I(){let S=T();for(;l("or");){let L=t[r];++r;let R=T();S=new $n(L,S,R)}return S}function T(){let S=z();for(;l("and");){let L=t[r];++r;let R=z();S=new $n(L,S,R)}return S}function z(){let S;for(;l("not");){let L=t[r];++r;let R=z();S=new NI(L,R)}return S??C()}function C(){let S=v();for(;;){let L;if(l("not","in"))L=new Rt("not in",$.Identifier),r+=2;else if(l("in"))L=t[r++];else if(a($.ComparisonBinaryOperator))L=t[r++];else break;let R=v();S=new $n(L,S,R)}return S}function v(){let S=B();for(;a($.AdditiveBinaryOperator);){let L=t[r];++r;let R=B();S=new $n(L,S,R)}return S}function G(){let S=Y(ie());return a($.OpenParen)?X(S):S}function X(S){let L=new vv(S,V());return L=Y(L),a($.OpenParen)&&(L=X(L)),L}function V(){s($.OpenParen,"Expected opening parenthesis for arguments list");let S=Q();return s($.CloseParen,"Expected closing parenthesis for arguments list"),S}function Q(){let S=[];for(;!a($.CloseParen);){let L;if(t[r].type===$.MultiplicativeBinaryOperator&&t[r].value==="*"){++r;let R=E();L=new UI(R)}else if(L=E(),a($.Equals)){if(++r,!(L instanceof Ls))throw new SyntaxError("Expected identifier for keyword argument");let R=E();L=new RI(L,R)}S.push(L),a($.Comma)&&++r}return S}function K(){let S=[],L=!1;for(;!a($.CloseSquareBracket);)a($.Colon)?(S.push(void 0),++r,L=!0):(S.push(E()),a($.Colon)&&(++r,L=!0));if(S.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(L){if(S.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new $I(...S)}return S[0]}function Y(S){for(;a($.Dot)||a($.OpenSquareBracket);){let L=t[r];++r;let R,te=L.type===$.OpenSquareBracket;if(te)R=K(),s($.CloseSquareBracket,"Expected closing square bracket");else if(R=ie(),R.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");S=new MI(S,R,te)}return S}function B(){let S=P();for(;a($.MultiplicativeBinaryOperator);){let L=t[r++],R=P();S=new $n(L,S,R)}return S}function P(){let S=se();for(;l("is");){++r;let L=l("not");L&&++r;let R=ie();if(!(R instanceof Ls))throw new SyntaxError("Expected identifier for the test");S=new LI(S,L,R)}return S}function se(){let S=G();for(;a($.Pipe);){++r;let L=ie();if(!(L instanceof Ls))throw new SyntaxError("Expected identifier for the filter");a($.OpenParen)&&(L=X(L)),S=new CI(S,L)}return S}function ie(){let S=t[r++];switch(S.type){case $.NumericLiteral:{let L=S.value;return L.includes(".")?new SI(Number(L)):new TI(Number(L))}case $.StringLiteral:{let L=S.value;for(;a($.StringLiteral);)L+=t[r++].value;return new kv(L)}case $.Identifier:return new Ls(S.value);case $.OpenParen:{let L=x();return s($.CloseParen,"Expected closing parenthesis, got ${tokens[current].type} instead."),L}case $.OpenSquareBracket:{let L=[];for(;!a($.CloseSquareBracket);)L.push(E()),a($.Comma)&&++r;return++r,new OI(L)}case $.OpenCurlyBracket:{let L=new Map;for(;!a($.CloseCurlyBracket);){let R=E();s($.Colon,"Expected colon between key and value in object literal");let te=E();L.set(R,te),a($.Comma)&&++r}return++r,new II(L)}default:throw new SyntaxError(`Unexpected token: ${S.type}`)}}for(;r<t.length;)e.body.push(o());return e}function jI(t,e,r=1){if(e===void 0&&(e=t,t=0),r===0)throw new Error("range() step must not be zero");let s=[];if(r>0)for(let n=t;n<e;n+=r)s.push(n);else for(let n=t;n>e;n+=r)s.push(n);return s}function Av(t,e,r,s=1){let n=Math.sign(s);n>=0?(e=(e??=0)<0?Math.max(t.length+e,0):Math.min(e,t.length),r=(r??=t.length)<0?Math.max(t.length+r,0):Math.min(r,t.length)):(e=(e??=t.length-1)<0?Math.max(t.length+e,-1):Math.min(e,t.length-1),r=(r??=-1)<-1?Math.max(t.length+r,-1):Math.min(r,t.length-1));let o=[];for(let a=e;n*a<n*r;a+=s)o.push(t[a]);return o}function GI(t){return t.replace(/\b\w/g,e=>e.toUpperCase())}function qI(t){return WI(new Date,t)}function WI(t,e){let r=new Intl.DateTimeFormat(void 0,{month:"long"}),s=new Intl.DateTimeFormat(void 0,{month:"short"}),n=o=>o<10?"0"+o:o.toString();return e.replace(/%[YmdbBHM%]/g,o=>{switch(o){case"%Y":return t.getFullYear().toString();case"%m":return n(t.getMonth()+1);case"%d":return n(t.getDate());case"%b":return s.format(t);case"%B":return r.format(t);case"%H":return n(t.getHours());case"%M":return n(t.getMinutes());case"%%":return"%";default:return o}})}function VI(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function HI(t,e,r,s){if(s===0)return t;let n=s==null||s<0?1/0:s,o=e.length===0?new RegExp("(?=)","gu"):new RegExp(VI(e),"gu");return t.replaceAll(o,a=>n>0?(--n,r):a)}var Mv=class extends Error{},Tv=class extends Error{},sr=class{type="RuntimeValue";value;builtins=new Map;constructor(t=void 0){this.value=t}__bool__(){return new le(!!this.value)}toString(){return String(this.value)}},de=class extends sr{type="IntegerValue"},Ke=class extends sr{type="FloatValue";toString(){return this.value%1===0?this.value.toFixed(1):this.value.toString()}},Z=class extends sr{type="StringValue";builtins=new Map([["upper",new je(()=>new Z(this.value.toUpperCase()))],["lower",new je(()=>new Z(this.value.toLowerCase()))],["strip",new je(()=>new Z(this.value.trim()))],["title",new je(()=>new Z(GI(this.value)))],["capitalize",new je(()=>new Z(this.value.charAt(0).toUpperCase()+this.value.slice(1)))],["length",new de(this.value.length)],["rstrip",new je(()=>new Z(this.value.trimEnd()))],["lstrip",new je(()=>new Z(this.value.trimStart()))],["startswith",new je(t=>{if(t.length===0)throw new Error("startswith() requires at least one argument");let e=t[0];if(e instanceof Z)return new le(this.value.startsWith(e.value));if(e instanceof ve){for(let r of e.value){if(!(r instanceof Z))throw new Error("startswith() tuple elements must be strings");if(this.value.startsWith(r.value))return new le(!0)}return new le(!1)}throw new Error("startswith() argument must be a string or tuple of strings")})],["endswith",new je(t=>{if(t.length===0)throw new Error("endswith() requires at least one argument");let e=t[0];if(e instanceof Z)return new le(this.value.endsWith(e.value));if(e instanceof ve){for(let r of e.value){if(!(r instanceof Z))throw new Error("endswith() tuple elements must be strings");if(this.value.endsWith(r.value))return new le(!0)}return new le(!1)}throw new Error("endswith() argument must be a string or tuple of strings")})],["split",new je(t=>{let e=t[0]??new qe;if(!(e instanceof Z||e instanceof qe))throw new Error("sep argument must be a string or null");let r=t[1]??new de(-1);if(!(r instanceof de))throw new Error("maxsplit argument must be a number");let s=[];if(e instanceof qe){let n=this.value.trimStart();for(let{0:o,index:a}of n.matchAll(/\S+/g)){if(r.value!==-1&&s.length>=r.value&&a!==void 0){s.push(o+n.slice(a+o.length));break}s.push(o)}}else{if(e.value==="")throw new Error("empty separator");s=this.value.split(e.value),r.value!==-1&&s.length>r.value&&s.push(s.splice(r.value).join(e.value))}return new ve(s.map(n=>new Z(n)))})],["replace",new je(t=>{if(t.length<2)throw new Error("replace() requires at least two arguments");let e=t[0],r=t[1];if(!(e instanceof Z&&r instanceof Z))throw new Error("replace() arguments must be strings");let s;if(t.length>2?t[2].type==="KeywordArgumentsValue"?s=t[2].value.get("count")??new qe:s=t[2]:s=new qe,!(s instanceof de||s instanceof qe))throw new Error("replace() count argument must be a number or null");return new Z(HI(this.value,e.value,r.value,s.value))})]])},le=class extends sr{type="BooleanValue"},XI=/[\x7f-\uffff]/g;function Sv(t){return t.replace(XI,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0"))}function es(t,e={},r=0,s=!0){let{indent:n=null,ensureAscii:o=!1,separators:a=null,sortKeys:i=!1}=e,l,u;switch(a?[l,u]=a:n?(l=",",u=": "):(l=", ",u=": "),t.type){case"NullValue":return"null";case"UndefinedValue":return s?"null":"undefined";case"IntegerValue":case"FloatValue":case"BooleanValue":return JSON.stringify(t.value);case"StringValue":{let d=JSON.stringify(t.value);return o&&(d=Sv(d)),d}case"ArrayValue":case"ObjectValue":{let d=n?" ".repeat(n):"",f=`
@@ -11,8 +11,8 @@ var HT=Object.defineProperty;var Jr=(t=>typeof require<"u"?require:typeof Proxy<
11
11
  ${N}
12
12
  }`,h=new Function(Object.keys(O),N)(...Object.values(O)),N=`methodCaller<(${b.map(D=>D.name)}) => ${g.name}>`,C2(Object.defineProperty(h,"name",{value:N}))}function $2(c,p){return p>>>=0,(c=zt(c>>>0))==zt(p)}function R2(c){return(c>>>=0)?(c=Ai(c),qt(globalThis[c])):qt(globalThis)}function U2(c){return c=Ai(c>>>0),qt(e[c])}function B2(c,p){return p>>>=0,c=zt(c>>>0),p=zt(p),qt(c[p])}function D2(c){9<(c>>>=0)&&(Kr[c+1]+=1)}function bb(c,p,h,g,b){return Xu[c>>>0](p>>>0,h>>>0,g>>>0,b>>>0)}function F2(c,p,h,g,b){return bb(c>>>0,p>>>0,h>>>0,g>>>0,b>>>0)}function j2(){return qt([])}function G2(c){c=zt(c>>>0);for(var p=Array(c.length),h=0;h<c.length;h++)p[h]=c[h];return qt(p)}function q2(c){return qt(Ai(c>>>0))}function W2(){return qt({})}function V2(c){for(var p=zt(c>>>=0);p.length;){var h=p.pop();p.pop()(h)}ju(c)}function H2(c,p,h){p>>>=0,h>>>=0,c=zt(c>>>0),p=zt(p),h=zt(h),c[p]=h}function X2(c,p){c=wt(c),p>>>=0,c=new Date(1e3*c),(v(),B)[p>>>2>>>0]=c.getUTCSeconds(),(v(),B)[p+4>>>2>>>0]=c.getUTCMinutes(),(v(),B)[p+8>>>2>>>0]=c.getUTCHours(),(v(),B)[p+12>>>2>>>0]=c.getUTCDate(),(v(),B)[p+16>>>2>>>0]=c.getUTCMonth(),(v(),B)[p+20>>>2>>>0]=c.getUTCFullYear()-1900,(v(),B)[p+24>>>2>>>0]=c.getUTCDay(),c=(c.getTime()-Date.UTC(c.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,(v(),B)[p+28>>>2>>>0]=c}var vb=c=>c%4==0&&(c%100!=0||c%400==0),kb=[0,31,60,91,121,152,182,213,244,274,305,335],Eb=[0,31,59,90,120,151,181,212,243,273,304,334];function K2(c,p){c=wt(c),p>>>=0,c=new Date(1e3*c),(v(),B)[p>>>2>>>0]=c.getSeconds(),(v(),B)[p+4>>>2>>>0]=c.getMinutes(),(v(),B)[p+8>>>2>>>0]=c.getHours(),(v(),B)[p+12>>>2>>>0]=c.getDate(),(v(),B)[p+16>>>2>>>0]=c.getMonth(),(v(),B)[p+20>>>2>>>0]=c.getFullYear()-1900,(v(),B)[p+24>>>2>>>0]=c.getDay();var h=(vb(c.getFullYear())?kb:Eb)[c.getMonth()]+c.getDate()-1|0;(v(),B)[p+28>>>2>>>0]=h,(v(),B)[p+36>>>2>>>0]=-60*c.getTimezoneOffset(),h=new Date(c.getFullYear(),6,1).getTimezoneOffset();var g=new Date(c.getFullYear(),0,1).getTimezoneOffset();c=0|(h!=g&&c.getTimezoneOffset()==Math.min(g,h)),(v(),B)[p+32>>>2>>>0]=c}function Y2(c){c>>>=0;var p=new Date((v(),B)[c+20>>>2>>>0]+1900,(v(),B)[c+16>>>2>>>0],(v(),B)[c+12>>>2>>>0],(v(),B)[c+8>>>2>>>0],(v(),B)[c+4>>>2>>>0],(v(),B)[c>>>2>>>0],0),h=(v(),B)[c+32>>>2>>>0],g=p.getTimezoneOffset(),b=new Date(p.getFullYear(),6,1).getTimezoneOffset(),A=new Date(p.getFullYear(),0,1).getTimezoneOffset(),O=Math.min(A,b);return 0>h?(v(),B)[c+32>>>2>>>0]=+(b!=A&&O==g):0<h!=(O==g)&&(b=Math.max(A,b),p.setTime(p.getTime()+6e4*((0<h?O:b)-g))),(v(),B)[c+24>>>2>>>0]=p.getDay(),h=(vb(p.getFullYear())?kb:Eb)[p.getMonth()]+p.getDate()-1|0,(v(),B)[c+28>>>2>>>0]=h,(v(),B)[c>>>2>>>0]=p.getSeconds(),(v(),B)[c+4>>>2>>>0]=p.getMinutes(),(v(),B)[c+8>>>2>>>0]=p.getHours(),(v(),B)[c+12>>>2>>>0]=p.getDate(),(v(),B)[c+16>>>2>>>0]=p.getMonth(),(v(),B)[c+20>>>2>>>0]=p.getYear(),c=p.getTime(),BigInt(isNaN(c)?-1:c/1e3)}function Ab(c,p,h,g,b,A,O){return n?Le(16,1,c,p,h,g,b,A,O):-52}function Mb(c,p,h,g,b,A){if(n)return Le(17,1,c,p,h,g,b,A)}var On={},Q2=()=>performance.timeOrigin+performance.now();function Tb(c,p){if(n)return Le(18,1,c,p);if(On[c]&&(clearTimeout(On[c].id),delete On[c]),!p)return 0;var h=setTimeout(()=>{delete On[c],bi(()=>n1(c,performance.timeOrigin+performance.now()))},p);return On[c]={id:h,Ne:p},0}function J2(c,p,h,g){c>>>=0,p>>>=0,h>>>=0,g>>>=0;var b=new Date().getFullYear(),A=new Date(b,0,1).getTimezoneOffset();b=new Date(b,6,1).getTimezoneOffset();var O=Math.max(A,b);(v(),P)[c>>>2>>>0]=60*O,(v(),B)[p>>>2>>>0]=+(A!=b),c=(p=N=>{var D=Math.abs(N);return`UTC${0<=N?"-":"+"}${String(Math.floor(D/60)).padStart(2,"0")}${String(D%60).padStart(2,"0")}`})(A),p=p(b),b<A?(ur(c,h,17),ur(p,g,17)):(ur(c,g,17),ur(p,h,17))}var Z2=()=>Date.now(),eM=1;function tM(c,p,h){if(h>>>=0,!(0<=c&&3>=c))return 28;if(c===0)c=Date.now();else{if(!eM)return 52;c=performance.timeOrigin+performance.now()}return c=Math.round(1e6*c),(v(),S)[h>>>3>>>0]=BigInt(c),0}var Ku=[],Sb=(c,p)=>{Ku.length=0;for(var h;h=(v(),Q)[c++>>>0];){var g=h!=105;p+=(g&=h!=112)&&p%8?4:0,Ku.push(h==112?(v(),P)[p>>>2>>>0]:h==106?(v(),S)[p>>>3>>>0]:h==105?(v(),B)[p>>>2>>>0]:(v(),ie)[p>>>3>>>0]),p+=g?8:4}return Ku};function rM(c,p,h){return c>>>=0,p=Sb(p>>>0,h>>>0),up[c](...p)}function sM(c,p,h){return c>>>=0,p=Sb(p>>>0,h>>>0),up[c](...p)}var nM=()=>{};function oM(c,p){return T(Ts(c>>>0,p>>>0))}var aM=()=>{throw ge+=1,"unwind"};function iM(){return 4294901760}var lM=()=>1,cM=()=>navigator.hardwareConcurrency,Yr={},Ob=c=>{var p=pr(c)+1,h=Cs(p);return h&&ur(c,h,p),h},Mi=c=>{var p;return(p=/\bwasm-function\[\d+\]:(0x[0-9a-f]+)/.exec(c))?+p[1]:(p=/:(\d+):\d+(?:\)|$)/.exec(c))?2147483648|+p[1]:0},Ib=c=>{for(var p of c)(c=Mi(p))&&(Yr[c]=p)};function uM(){var c=Error().stack.toString().split(`
13
13
  `);return c[0]=="Error"&&c.shift(),Ib(c),Yr.Xd=Mi(c[3]),Yr.re=c,Yr.Xd}function Ti(c){if(!(c=Yr[c>>>0]))return 0;var p;if(p=/^\s+at .*\.wasm\.(.*) \(.*\)$/.exec(c))c=p[1];else if(p=/^\s+at (.*) \(.*\)$/.exec(c))c=p[1];else{if(!(p=/^(.+?)@/.exec(c)))return 0;c=p[1]}return Lt(Ti.ae??0),Ti.ae=Ob(c),Ti.ae}function pM(c){c>>>=0;var p=(v(),Q).length;if(c<=p||4294901760<c)return!1;for(var h=1;4>=h;h*=2){var g=p*(1+.2/h);g=Math.min(g,c+100663296);e:{g=(Math.min(4294901760,65536*Math.ceil(Math.max(c,g)/65536))-yr.buffer.byteLength+65535)/65536|0;try{yr.grow(g),ue();var b=1;break e}catch{}b=void 0}if(b)return!0}return!1}function dM(c,p,h){if(c>>>=0,p>>>=0,Yr.Xd==c)var g=Yr.re;else(g=Error().stack.toString().split(`
14
- `))[0]=="Error"&&g.shift(),Ib(g);for(var b=3;g[b]&&Mi(g[b])!=c;)++b;for(c=0;c<h&&g[c+b];++c)(v(),B)[p+4*c>>>2>>>0]=Mi(g[c+b]);return c}var tr=c=>{var p=pr(c)+1,h=Ci(p);return ur(c,h,p),h},Yu=[],xt=(c,p)=>{Yu[c>>>=0]=p},rr=[],Si=[],Os=(c,p)=>{Si[c]=new Promise(h=>p.finally(()=>h(c)))},re=c=>{if(c)return Yu[c>>>0]},Oi=(c,p,h)=>{(v(),P)[c>>>2>>>0]=p,(v(),P)[c+4>>>2>>>0]=h},Cb=c=>{var p=(v(),P)[c>>>2>>>0];return c=(v(),P)[c+4>>>2>>>0],Ts(p,c)},dr=c=>{var p=(v(),P)[c>>>2>>>0];return c=(v(),P)[c+4>>>2>>>0],p?Ts(p,c):c===0?"":void 0},fM=c=>{var p=dr(c+4),h=(h=(v(),P)[c+12>>>2>>>0])?re(h):"auto";if(c+=16){var g=re((v(),P)[c+4>>>2>>>0]),b=(v(),P)[c+16>>>2>>>0],A=(v(),P)[c+20>>>2>>>0];if(b){for(var O={},N=0;N<b;++N){var D=A+24*N;O[Cb(D+4)]=(v(),ie)[D+16>>>3>>>0]}b=O}else b=void 0;c={module:g,constants:b,entryPoint:dr(c+8)}}else c=void 0;return{label:p,layout:h,compute:c}},Pb=(c,p)=>{function h(b,A){b=c[b],(v(),B)[p+A>>>2>>>0]=b}function g(b,A){b=c[b],(v(),S)[p+A>>>3>>>0]=BigInt(b)}h("maxTextureDimension1D",4),h("maxTextureDimension2D",8),h("maxTextureDimension3D",12),h("maxTextureArrayLayers",16),h("maxBindGroups",20),h("maxBindGroupsPlusVertexBuffers",24),h("maxBindingsPerBindGroup",28),h("maxDynamicUniformBuffersPerPipelineLayout",32),h("maxDynamicStorageBuffersPerPipelineLayout",36),h("maxSampledTexturesPerShaderStage",40),h("maxSamplersPerShaderStage",44),h("maxStorageBuffersPerShaderStage",48),h("maxStorageTexturesPerShaderStage",52),h("maxUniformBuffersPerShaderStage",56),h("minUniformBufferOffsetAlignment",80),h("minStorageBufferOffsetAlignment",84),g("maxUniformBufferBindingSize",64),g("maxStorageBufferBindingSize",72),h("maxVertexBuffers",88),g("maxBufferSize",96),h("maxVertexAttributes",104),h("maxVertexBufferArrayStride",108),h("maxInterStageShaderVariables",112),h("maxColorAttachments",116),h("maxColorAttachmentBytesPerSample",120),h("maxComputeWorkgroupStorageSize",124),h("maxComputeInvocationsPerWorkgroup",128),h("maxComputeWorkgroupSizeX",132),h("maxComputeWorkgroupSizeY",136),h("maxComputeWorkgroupSizeZ",140),h("maxComputeWorkgroupsPerDimension",144),c.Le!==void 0&&h("maxImmediateSize",148)},mM=[,"validation","out-of-memory","internal"],hM=[,"compatibility","core"],zb={1:"core-features-and-limits",2:"depth-clip-control",3:"depth32float-stencil8",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"timestamp-query",10:"indirect-first-instance",11:"shader-f16",12:"rg11b10ufloat-renderable",13:"bgra8unorm-storage",14:"float32-filterable",15:"float32-blendable",16:"clip-distances",17:"dual-source-blending",18:"subgroups",19:"texture-formats-tier1",20:"texture-formats-tier2",21:"primitive-index",327692:"chromium-experimental-unorm16-texture-formats",327693:"chromium-experimental-snorm16-texture-formats",327732:"chromium-experimental-multi-draw-indirect"},_M=[,"low-power","high-performance"],gM=[,"occlusion","timestamp"],wM={undefined:1,unknown:1,destroyed:2};function xM(c,p,h,g,b,A){p=wt(p),h=wt(h),g>>>=0,b>>>=0,A>>>=0;var O=re(c>>>0);if(c={},A){var N=(v(),P)[A+12>>>2>>>0];if(N){var D=(v(),P)[A+16>>>2>>>0];c.requiredFeatures=Array.from((v(),P).subarray(D>>>2>>>0,D+4*N>>>2>>>0),ee=>zb[ee])}var q=(v(),P)[A+20>>>2>>>0];if(q){let ee=function(Nt,st,Qr=!1){st=q+st,(st=(v(),P)[st>>>2>>>0])==4294967295||Qr&&st==0||(Re[Nt]=st)},lt=function(Nt,st){st=q+st;var Qr=(v(),P)[st>>>2>>>0],VT=(v(),P)[st+4>>>2>>>0];Qr==4294967295&&VT==4294967295||(Re[Nt]=4294967296*(v(),P)[st+4>>>2>>>0]+(v(),P)[st>>>2>>>0])};var fe=ee,me=lt,Re={};ee("maxTextureDimension1D",4),ee("maxTextureDimension2D",8),ee("maxTextureDimension3D",12),ee("maxTextureArrayLayers",16),ee("maxBindGroups",20),ee("maxBindGroupsPlusVertexBuffers",24),ee("maxDynamicUniformBuffersPerPipelineLayout",32),ee("maxDynamicStorageBuffersPerPipelineLayout",36),ee("maxSampledTexturesPerShaderStage",40),ee("maxSamplersPerShaderStage",44),ee("maxStorageBuffersPerShaderStage",48),ee("maxStorageTexturesPerShaderStage",52),ee("maxUniformBuffersPerShaderStage",56),ee("minUniformBufferOffsetAlignment",80),ee("minStorageBufferOffsetAlignment",84),lt("maxUniformBufferBindingSize",64),lt("maxStorageBufferBindingSize",72),ee("maxVertexBuffers",88),lt("maxBufferSize",96),ee("maxVertexAttributes",104),ee("maxVertexBufferArrayStride",108),ee("maxInterStageShaderVariables",112),ee("maxColorAttachments",116),ee("maxColorAttachmentBytesPerSample",120),ee("maxComputeWorkgroupStorageSize",124),ee("maxComputeInvocationsPerWorkgroup",128),ee("maxComputeWorkgroupSizeX",132),ee("maxComputeWorkgroupSizeY",136),ee("maxComputeWorkgroupSizeZ",140),ee("maxComputeWorkgroupsPerDimension",144),ee("maxImmediateSize",148,!0),c.requiredLimits=Re}(N=(v(),P)[A+24>>>2>>>0])&&(N={label:dr(N+4)},c.defaultQueue=N),c.label=dr(A+4)}ge+=1,Os(p,O.requestDevice(c).then(ee=>{--ge,xt(b,ee.queue),xt(g,ee),h&&(ge+=1,Os(h,ee.lost.then(lt=>{--ge,ee.onuncapturederror=()=>{};var Nt=ae(),st=tr(lt.message);tp(h,wM[lt.reason],st),oe(Nt)}))),ee.onuncapturederror=lt=>{var Nt=5;lt.error instanceof GPUValidationError?Nt=2:lt.error instanceof GPUOutOfMemoryError?Nt=3:lt.error instanceof GPUInternalError&&(Nt=4);var st=ae();lt=tr(lt.error.message),e1(g,Nt,lt),oe(st)},"adapterInfo"in ee||(ee.adapterInfo=O.info),np(p,1,g,0)},ee=>{--ge;var lt=ae();ee=tr(ee.message),np(p,3,g,ee),h&&tp(h,4,ee),oe(lt)}))}function yM(c){var p=re(c>>>=0),h=rr[c];if(h){for(var g=0;g<h.length;++g)h[g]();delete rr[c]}p.destroy()}var Is=()=>{var c="getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE";Is.ed||(Is.ed={}),Is.ed[c]||(Is.ed[c]=1,T(c))};function bM(c,p,h){p>>>=0,h>>>=0;var g=re(c>>>=0);h===0&&Is(),h==4294967295&&(h=void 0);try{var b=g.getMappedRange(p,h)}catch{return 0}var A=ip(16,b.byteLength);return(v(),Q).set(new Uint8Array(b),A>>>0),rr[c].push(()=>Lt(A)),A}function vM(c,p,h){p>>>=0,h>>>=0;var g=re(c>>>=0);h===0&&Is(),h==4294967295&&(h=void 0);try{var b=g.getMappedRange(p,h)}catch{return 0}var A=ip(16,b.byteLength);return(v(),Q).fill(0,A,b.byteLength),rr[c].push(()=>{new Uint8Array(b).set((v(),Q).subarray(A>>>0,A+b.byteLength>>>0)),Lt(A)}),A}function kM(c,p,h,g,b){c>>>=0,p=wt(p),h=wt(h),b>>>=0;var A=re(c);rr[c]=[],b==4294967295&&(b=void 0),ge+=1,Os(p,A.mapAsync(h,g>>>0,b).then(()=>{--ge,rp(p,1,0)},O=>{--ge,ae();var N=tr(O.message);rp(p,O.name==="AbortError"?4:O.name==="OperationError"?3:0,N),delete rr[c]}))}function EM(c){var p=re(c>>>=0),h=rr[c];if(h){for(var g=0;g<h.length;++g)h[g]();delete rr[c],p.unmap()}}function AM(c){delete Yu[c>>>0]}function MM(c,p,h){c>>>=0,p>>>=0,h>>>=0;var g=!!(v(),P)[p+32>>>2>>>0];p={label:dr(p+4),usage:(v(),P)[p+16>>>2>>>0],size:4294967296*(v(),P)[p+28>>>2>>>0]+(v(),P)[p+24>>>2>>>0],mappedAtCreation:g},c=re(c);try{var b=c.createBuffer(p)}catch{return!1}return xt(h,b),g&&(rr[h]=[]),!0}function TM(c,p,h,g){c>>>=0,p=wt(p),g>>>=0,h=fM(h>>>0),c=re(c),ge+=1,Os(p,c.createComputePipelineAsync(h).then(b=>{--ge,xt(g,b),ep(p,1,g,0)},b=>{--ge;var A=ae(),O=tr(b.message);ep(p,b.reason==="validation"?3:b.reason==="internal"?4:0,g,O),oe(A)}))}function SM(c,p,h){c>>>=0,p>>>=0,h>>>=0;var g=(v(),P)[p>>>2>>>0],b=(v(),P)[g+4>>>2>>>0];p={label:dr(p+4),code:""},b===2&&(p.code=Cb(g+8)),xt(h,re(c).createShaderModule(p))}var OM=c=>{(c=re(c)).onuncapturederror=null,c.destroy()};function IM(c,p){p=wt(p),c=re(c>>>0),ge+=1,Os(p,c.popErrorScope().then(h=>{--ge;var g=5;h?h instanceof GPUValidationError?g=2:h instanceof GPUOutOfMemoryError?g=3:h instanceof GPUInternalError&&(g=4):g=1;var b=ae();h=h?tr(h.message):0,sp(p,1,g,h),oe(b)},h=>{--ge;var g=ae();h=tr(h.message),sp(p,1,5,h),oe(g)}))}function CM(c,p,h,g){if(p=wt(p),g>>>=0,h>>>=0){var b=(v(),P)[h+4>>>2>>>0];b={featureLevel:hM[b],powerPreference:_M[(v(),P)[h+8>>>2>>>0]],forceFallbackAdapter:!!(v(),P)[h+12>>>2>>>0]},(h=(v(),P)[h>>>2>>>0])!==0&&(v(),b.Qe=!!(v(),P)[h+8>>>2>>>0])}"gpu"in navigator?(ge+=1,Os(p,navigator.gpu.requestAdapter(b).then(A=>{if(--ge,A)xt(g,A),In(p,1,g,0);else{A=ae();var O=tr("WebGPU not available on this browser (requestAdapter returned null)");In(p,3,g,O),oe(A)}},A=>{--ge;var O=ae();A=tr(A.message),In(p,4,g,A),oe(O)}))):(h=ae(),b=tr("WebGPU not available on this browser (navigator.gpu is not available)"),In(p,3,g,b),oe(h))}function PM(c,p,h){return c>>>=0,p>>>=0,h>>>=0,yb(async()=>{var g=[];if(h){var b=(v(),B)[h>>>2>>>0];g.length=p+1,g[p]=new Promise(N=>setTimeout(N,b,0))}else g.length=p;for(var A=0;A<p;++A){var O=4294967296*(v(),P)[c+8*A+4>>>2>>>0]+(v(),P)[c+8*A>>>2>>>0];if(!(O in Si))return O;g[A]=Si[O]}return g=await Promise.race(g),delete Si[g],g})}var Qu,Ju={},Lb=()=>{if(!Qu){var c,p={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 Ju)Ju[c]===void 0?delete p[c]:p[c]=Ju[c];var h=[];for(c in p)h.push(`${c}=${p[c]}`);Qu=h}return Qu};function Nb(c,p){if(n)return Le(19,1,c,p);c>>>=0,p>>>=0;var h,g=0,b=0;for(h of Lb()){var A=p+g;(v(),P)[c+b>>>2>>>0]=A,g+=ur(h,A,1/0)+1,b+=4}return 0}function $b(c,p){if(n)return Le(20,1,c,p);c>>>=0,p>>>=0;var h=Lb();for(var g of((v(),P)[c>>>2>>>0]=h.length,c=0,h))c+=pr(g)+1;return(v(),P)[p>>>2>>>0]=c,0}function Rb(c){return n?Le(21,1,c):52}function Ub(c,p,h,g){return n?Le(22,1,c,p,h,g):52}function Bb(c,p,h,g){return n?Le(23,1,c,p,h,g):70}var zM=[null,[],[]];function Db(c,p,h,g){if(n)return Le(24,1,c,p,h,g);p>>>=0,h>>>=0,g>>>=0;for(var b=0,A=0;A<h;A++){var O=(v(),P)[p>>>2>>>0],N=(v(),P)[p+4>>>2>>>0];p+=8;for(var D=0;D<N;D++){var q=c,fe=(v(),Q)[O+D>>>0],me=zM[q];fe===0||fe===10?((q===1?I:T)(eb(me)),me.length=0):me.push(fe)}b+=N}return(v(),P)[g>>>2>>>0]=b,0}function LM(c){return c>>>0}function NM(c,p){return Pb(re(c>>>0).limits,p>>>0),1}function $M(c,p){return re(c>>>0).features.has(zb[p])}function RM(c){return BigInt(re(c>>>0).size)}function UM(c){return BigInt(re(c>>>0).usage)}function BM(c,p){if(c>>>=0,p>>>=0){var h=dr(p+4);h={label:h,timestampWrites:p=(p=(v(),P)[p+12>>>2>>>0])!==0?{querySet:re((v(),P)[p+4>>>2>>>0]),beginningOfPassWriteIndex:(v(),P)[p+8>>>2>>>0],endOfPassWriteIndex:(v(),P)[p+12>>>2>>>0]}:void 0}}return c=re(c),p=Kb(0),xt(p,c.beginComputePass(h)),p}function DM(c,p,h,g,b,A){h=wt(h),b=wt(b),A=wt(A),re(c>>>0).copyBufferToBuffer(re(p>>>0),h,re(g>>>0),b,A)}function FM(c){c=re(c>>>0);var p=Hb(0);return xt(p,c.finish()),p}function jM(c,p,h,g,b,A){A=wt(A),re(c>>>0).resolveQuerySet(re(p>>>0),h,g,re(b>>>0),A)}function GM(c,p,h,g){re(c>>>0).dispatchWorkgroups(p,h,g)}function qM(c,p,h){h=wt(h),re(c>>>0).dispatchWorkgroupsIndirect(re(p>>>0),h)}function WM(c){re(c>>>0).end()}function VM(c,p,h,g,b){g>>>=0,b>>>=0,c=re(c>>>0),h=re(h>>>0),g==0?c.setBindGroup(p,h):c.setBindGroup(p,h,(v(),P),b>>>2,g)}function HM(c,p){re(c>>>0).setPipeline(re(p>>>0))}function XM(c,p,h){re(c>>>0).Pe(re(p>>>0),h)}function KM(c,p){c=re(c>>>0);var h=Vb(0);return xt(h,c.getBindGroupLayout(p)),h}function YM(c,p){c>>>=0;var h=dr(4+(p>>>=0)),g=re((v(),P)[p+12>>>2>>>0]),b=(v(),P)[p+16>>>2>>>0];p=(v(),P)[p+20>>>2>>>0];for(var A=[],O=0;O<b;++O){var N=A,D=N.push,q=p+40*O,fe=(v(),P)[q+8>>>2>>>0],me=(v(),P)[q+32>>>2>>>0],Re=(v(),P)[q+36>>>2>>>0],ee=(v(),P)[q+4>>>2>>>0];fe?(me=q+24,(me=(v(),P)[me>>>2>>>0]+4294967296*(v(),B)[me+4>>>2>>>0])==-1&&(me=void 0),q={binding:ee,resource:{buffer:re(fe),offset:4294967296*(v(),P)[q+4+16>>>2>>>0]+(v(),P)[q+16>>>2>>>0],size:me}}):q=me?{binding:ee,resource:re(me)}:{binding:ee,resource:re(Re)},D.call(N,q)}return h={label:h,layout:g,entries:A},c=re(c),g=Wb(0),xt(g,c.createBindGroup(h)),g}function QM(c,p){var h;return c>>>=0,(p>>>=0)&&(h={label:dr(p+4)}),c=re(c),p=Xb(0),xt(p,c.createCommandEncoder(h)),p}function JM(c,p){c>>>=0,p>>>=0,p={type:gM[(v(),P)[p+12>>>2>>>0]],count:(v(),P)[p+16>>>2>>>0]},c=re(c);var h=Yb(0);return xt(h,c.createQuerySet(p)),h}function ZM(c,p){c=re(c>>>0).adapterInfo,p>>>=0,(v(),B)[p+52>>>2>>>0]=c.subgroupMinSize,(v(),B)[p+56>>>2>>>0]=c.subgroupMaxSize;var h=Ob(c.vendor+c.architecture+c.device+c.description),g=pr(c.vendor);return Oi(p+4,h,g),h+=g,g=pr(c.architecture),Oi(p+12,h,g),h+=g,g=pr(c.device),Oi(p+20,h,g),Oi(p+28,h+g,pr(c.description)),(v(),B)[p+36>>>2>>>0]=2,c=c.isFallbackAdapter?3:4,(v(),B)[p+40>>>2>>>0]=c,(v(),B)[p+44>>>2>>>0]=0,(v(),B)[p+48>>>2>>>0]=0,1}var eT={"core-features-and-limits":1,"depth-clip-control":2,"depth32float-stencil8":3,"texture-compression-bc":4,"texture-compression-bc-sliced-3d":5,"texture-compression-etc2":6,"texture-compression-astc":7,"texture-compression-astc-sliced-3d":8,"timestamp-query":9,"indirect-first-instance":10,"shader-f16":11,"rg11b10ufloat-renderable":12,"bgra8unorm-storage":13,"float32-filterable":14,"float32-blendable":15,"clip-distances":16,"dual-source-blending":17,subgroups:18,"texture-formats-tier1":19,"texture-formats-tier2":20,"primitive-index":21,"chromium-experimental-unorm16-texture-formats":327692,"chromium-experimental-snorm16-texture-formats":327693,"chromium-experimental-multi-draw-indirect":327732};function tT(c,p){p>>>=0,c=re(c>>>0);var h=Cs(4*c.features.size),g=0,b=0;c.features.forEach(A=>{0<=(A=eT[A])&&((v(),B)[h+g>>>2>>>0]=A,g+=4,b++)}),(v(),P)[p+4>>>2>>>0]=h,(v(),P)[p>>>2>>>0]=b}function rT(c,p){return Pb(re(c>>>0).limits,p>>>0),1}function sT(c,p){re(c>>>0).pushErrorScope(mM[p])}function nT(c,p,h){p>>>=0,h>>>=0,c=re(c>>>0),p=Array.from((v(),B).subarray(h>>>2>>>0,h+4*p>>>2>>>0),g=>re(g)),c.submit(p)}function oT(c,p,h,g,b){h=wt(h),g>>>=0,b>>>=0,c=re(c>>>0),p=re(p>>>0),g=(v(),Q).subarray(g>>>0,g+b>>>0),c.writeBuffer(p,h,g,0,b)}n||(function(){for(var c=e.numThreads-1;c--;)H0();Me.push(async()=>{var p=(async function(){if(!n)return Promise.all(et.map(V0))})();xe++,await p,--xe==0&&Ge&&(p=Ge,Ge=null,p())})})(),n||(yr=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),ue()),e.wasmBinary&&(f=e.wasmBinary),e.stackSave=()=>ae(),e.stackRestore=c=>oe(c),e.stackAlloc=c=>Ci(c),e.setValue=function(c,p,h="i8"){switch(h.endsWith("*")&&(h="*"),h){case"i1":case"i8":(v(),V)[c>>>0]=p;break;case"i16":(v(),K)[c>>>1>>>0]=p;break;case"i32":(v(),B)[c>>>2>>>0]=p;break;case"i64":(v(),S)[c>>>3>>>0]=BigInt(p);break;case"float":(v(),se)[c>>>2>>>0]=p;break;case"double":(v(),ie)[c>>>3>>>0]=p;break;case"*":(v(),P)[c>>>2>>>0]=p;break;default:Ce(`invalid type for setValue: ${h}`)}},e.getValue=function(c,p="i8"){switch(p.endsWith("*")&&(p="*"),p){case"i1":case"i8":return(v(),V)[c>>>0];case"i16":return(v(),K)[c>>>1>>>0];case"i32":return(v(),B)[c>>>2>>>0];case"i64":return(v(),S)[c>>>3>>>0];case"float":return(v(),se)[c>>>2>>>0];case"double":return(v(),ie)[c>>>3>>>0];case"*":return(v(),P)[c>>>2>>>0];default:Ce(`invalid type for getValue: ${p}`)}},e.UTF8ToString=Ts,e.stringToUTF8=ur,e.lengthBytesUTF8=pr;var Fb,jb,Zu,Ii,Lt,Cs,Gb,qb,Wb,Vb,Hb,Xb,Kb,Yb,Qb,Jb,Zb,ep,tp,rp,sp,In,np,e1,op,t1,r1,s1,ap,n1,o1,ip,he,Cn,a1,oe,Ci,ae,i1,lp,l1,c1,u1,cp,p1,d1,f1,m1,h1,_1,g1,w1,x1,y1,b1,v1,k1,E1,A1,M1,T1,S1,O1,I1,C1,P1,z1,L1,N1,$1,R1,U1,B1,D1,F1,j1,G1,q1,W1,V1,H1,X1,K1,Y1,fr,aT=[xr,Hr,Y0,tb,rb,sb,nb,ob,ab,ib,lb,cb,ub,pb,db,fb,Ab,Mb,Tb,Nb,$b,Rb,Ub,Bb,Db],up={1116828:(c,p,h,g,b)=>{if(e===void 0||!e.Zc)return 1;if((c=Ts(Number(c>>>0))).startsWith("./")&&(c=c.substring(2)),!(c=e.Zc.get(c)))return 2;if(p=Number(p>>>0),h=Number(h>>>0),g=Number(g>>>0),p+h>c.byteLength)return 3;try{let A=c.subarray(p,p+h);switch(b){case 0:(v(),Q).set(A,g>>>0);break;case 1:e.ie?e.ie(g,A):e.Ke(g,A);break;default:return 4}return 0}catch{return 4}},1117652:(c,p,h)=>{e.ke(c,(v(),Q).subarray(p>>>0,p+h>>>0))},1117716:()=>e.Ie(),1117758:c=>{e.je(c)},1117795:()=>typeof wasmOffsetConverter<"u"};function iT(){return typeof wasmOffsetConverter<"u"}function lT(c,p,h,g){var b=ae();try{return w1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function cT(c,p,h){var g=ae();try{return h1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function uT(c,p,h){var g=ae();try{u1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function pT(c,p){var h=ae();try{return cp(c,p)}catch(g){if(oe(h),g!==g+0)throw g;he(1,0)}}function dT(c){var p=ae();try{p1(c)}catch(h){if(oe(p),h!==h+0)throw h;he(1,0)}}function fT(c,p,h,g,b,A,O){var N=ae();try{return m1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function mT(c,p){var h=ae();try{x1(c,p)}catch(g){if(oe(h),g!==g+0)throw g;he(1,0)}}function hT(c,p,h,g,b,A){var O=ae();try{d1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function _T(c,p,h,g){var b=ae();try{g1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function gT(c,p,h,g,b,A,O){var N=ae();try{b1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function wT(c,p,h,g,b,A,O){var N=ae();try{v1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function xT(c,p,h,g,b,A,O,N){var D=ae();try{P1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function yT(c,p,h,g,b){var A=ae();try{f1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function bT(c,p,h,g,b){var A=ae();try{return y1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function vT(c,p,h,g,b,A,O,N){var D=ae();try{z1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function kT(c,p,h,g,b,A,O,N,D,q,fe,me){var Re=ae();try{k1(c,p,h,g,b,A,O,N,D,q,fe,me)}catch(ee){if(oe(Re),ee!==ee+0)throw ee;he(1,0)}}function ET(c,p,h,g,b,A){var O=ae();try{return I1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function AT(c,p,h){var g=ae();try{return T1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;return he(1,0),0n}}function MT(c,p,h,g,b,A,O,N,D){var q=ae();try{_1(c,p,h,g,b,A,O,N,D)}catch(fe){if(oe(q),fe!==fe+0)throw fe;he(1,0)}}function TT(c){var p=ae();try{return A1(c)}catch(h){if(oe(p),h!==h+0)throw h;he(1,0)}}function ST(c,p,h){var g=ae();try{return L1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function OT(c,p){var h=ae();try{return V1(c,p)}catch(g){if(oe(h),g!==g+0)throw g;return he(1,0),0n}}function IT(c,p,h,g,b){var A=ae();try{N1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function CT(c){var p=ae();try{return E1(c)}catch(h){if(oe(p),h!==h+0)throw h;return he(1,0),0n}}function PT(c,p,h,g,b,A){var O=ae();try{return U1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function zT(c,p,h,g,b,A){var O=ae();try{return B1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function LT(c,p,h,g,b,A,O,N){var D=ae();try{return C1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function NT(c,p,h,g,b){var A=ae();try{return D1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;return he(1,0),0n}}function $T(c,p,h,g){var b=ae();try{return F1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function RT(c,p,h,g){var b=ae();try{return j1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function UT(c,p,h,g,b,A,O,N,D,q,fe,me){var Re=ae();try{return G1(c,p,h,g,b,A,O,N,D,q,fe,me)}catch(ee){if(oe(Re),ee!==ee+0)throw ee;he(1,0)}}function BT(c,p,h,g,b,A,O,N,D,q,fe){var me=ae();try{$1(c,p,h,g,b,A,O,N,D,q,fe)}catch(Re){if(oe(me),Re!==Re+0)throw Re;he(1,0)}}function DT(c,p,h,g,b,A,O,N,D,q,fe,me,Re,ee,lt,Nt){var st=ae();try{R1(c,p,h,g,b,A,O,N,D,q,fe,me,Re,ee,lt,Nt)}catch(Qr){if(oe(st),Qr!==Qr+0)throw Qr;he(1,0)}}function FT(c,p,h,g){var b=ae();try{return q1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function jT(c,p,h,g,b){var A=ae();try{return W1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function GT(c,p,h){var g=ae();try{return M1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function qT(c,p,h){var g=ae();try{return S1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function WT(c,p,h,g){var b=ae();try{O1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function Pi(){if(0<xe)Ge=Pi;else if(n)w?.(e),Be();else{for(var c=Me;0<c.length;)c.shift()(e);0<xe?Ge=Pi:(e.calledRun=!0,z||(Be(),w?.(e)))}}return n||(fr=await Qe(),Pi()),e.PTR_SIZE=4,e.webgpuInit=c=>{let p=new WeakMap,h,g,b=1;e.webgpuRegisterDevice=N=>{if(g!==void 0)throw Error("another WebGPU EP inference session is being created.");if(N){var D=p.get(N);if(!D){let q=((fe,me=0)=>{var Re=Zb(me);return me=Jb(me,Re),xt(Re,fe.queue),xt(me,fe),me})(N,D=qb(0));D=[b++,D,q],p.set(N,D)}return h=N,g=D[0],D}h=void 0,g=0};let A=new Map;e.webgpuOnCreateSession=N=>{if(g!==void 0){var D=g;if(g=void 0,N){let q=Zu(D);A.set(N,q),D===0&&c(h??re(q))}h=void 0}},e.webgpuOnReleaseSession=N=>{A.delete(N)};let O=Symbol("gpuBufferMetadata");e.webgpuRegisterBuffer=(N,D,q)=>{if(q)return N[O]=[q,NaN],q;if(q=N[O])return q[1]++,q[0];if((D=A.get(D))===void 0)throw Error("Invalid session handle passed to webgpuRegisterBuffer");return D=((fe,me=0)=>(fe.mapState!="pending"||Ce(),me=Qb(me,fe.mapState=="mapped"?3:1),xt(me,fe),fe.mapState=="mapped"&&(rr[me]=[]),me))(N,D),N[O]=[D,1],D},e.webgpuUnregisterBuffer=N=>{let D=N[O];if(!D)throw Error("Buffer is not registered");D[1]--,D[1]===0&&(Gb(D[0]),delete N[O])},e.webgpuGetBuffer=N=>re(N),e.webgpuCreateDownloader=(N,D,q)=>{if((q=A.get(q))===void 0)throw Error("Invalid session handle passed to webgpuRegisterBuffer");let fe=re(q),me=16*Math.ceil(Number(D)/16);return async()=>{let Re=fe.createBuffer({size:me,usage:9});try{let ee=fe.createCommandEncoder();return ee.copyBufferToBuffer(N,0,Re,0,me),fe.queue.submit([ee.finish()]),await Re.mapAsync(GPUMapMode.READ),Re.getMappedRange().slice(0,D)}finally{Re.destroy()}}},e.ie=(N,D)=>{var q=D.buffer;let fe=D.byteOffset,me=D.byteLength;if(D=16*Math.ceil(Number(me)/16),N=re(N),!h){var Re=Zu(g);h=re(Re)}let ee=(Re=h.createBuffer({mappedAtCreation:!0,size:D,usage:6})).getMappedRange();new Uint8Array(ee).set(new Uint8Array(q,fe,me)),Re.unmap(),(q=h.createCommandEncoder()).copyBufferToBuffer(Re,0,N,0,D),h.queue.submit([q.finish()]),Re.destroy()}},e.webnnInit=c=>{let p=c[0];[e.Ie,e.je,e.webnnEnsureTensor,e.ke,e.webnnDownloadTensor,e.He,e.webnnEnableTraceEvent]=c.slice(1),e.webnnReleaseTensorId=e.je,e.webnnUploadTensor=e.ke,e.webnnRegisterMLContext=e.He,e.webnnOnRunStart=h=>p.onRunStart(h),e.webnnOnRunEnd=p.onRunEnd.bind(p),e.webnnOnReleaseSession=h=>{p.onReleaseSession(h)},e.webnnCreateMLTensorDownloader=(h,g)=>p.createMLTensorDownloader(h,g),e.webnnRegisterMLTensor=(h,g,b,A)=>p.registerMLTensor(h,g,b,A),e.webnnCreateMLContext=h=>p.createMLContext(h),e.webnnRegisterMLConstant=(h,g,b,A,O,N)=>p.registerMLConstant(h,g,b,A,O,e.Zc,N),e.webnnRegisterGraphInput=p.registerGraphInput.bind(p),e.webnnIsGraphInput=p.isGraphInput.bind(p),e.webnnRegisterGraphOutput=p.registerGraphOutput.bind(p),e.webnnIsGraphOutput=p.isGraphOutput.bind(p),e.webnnCreateTemporaryTensor=p.createTemporaryTensor.bind(p),e.webnnIsGraphInputOutputTypeSupported=p.isGraphInputOutputTypeSupported.bind(p)},te?e:new Promise((c,p)=>{w=c,x=p})}var Wk,Jv,zC=ye(()=>{"use strict";Wk=Qv,Jv=globalThis.self?.name?.startsWith("em-pthread"),Jv&&Qv()}),Sp,qp,Zv,Ot,Vk,qi,ek,tk,Op,rk,Ip,Hk,Cp,Xk,Zp=ye(()=>{"use strict";Jp(),Sp=typeof location>"u"?void 0:location.origin,qp=import.meta.url>"file:"&&import.meta.url<"file;",Zv=()=>{if(qp){let t=URL;return new URL(new t("ort.webgpu.bundle.min.mjs",import.meta.url).href,Sp).href}return import.meta.url},Ot=Zv(),Vk=()=>{if(Ot&&!Ot.startsWith("blob:"))return Ot.substring(0,Ot.lastIndexOf("/")+1)},qi=(t,e)=>{try{let r=e??Ot;return(r?new URL(t,r):new URL(t)).origin===Sp}catch{return!1}},ek=(t,e)=>{let r=e??Ot;try{return(r?new URL(t,r):new URL(t)).href}catch{return}},tk=(t,e)=>`${e??"./"}${t}`,Op=async t=>{let e=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(e)},rk=async t=>(await import(t)).default,Ip=(PC(),Yi(jk)).default,Hk=async()=>{if(!Ot)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(qi(Ot))return[void 0,Ip()];let t=await Op(Ot);return[t,Ip(t)]},Cp=(zC(),Yi(qk)).default,Xk=async(t,e,r,s)=>{let n=Cp&&!(t||e);if(n)if(Ot)n=qi(Ot);else if(s&&!r)n=!0;else throw new Error("cannot determine the script source URL.");if(n)return[void 0,Cp];{let o="ort-wasm-simd-threaded.asyncify.mjs",a=t??ek(o,e),i=r&&a&&!qi(a,e),l=i?await Op(a):a??tk(o,e);return[i?l:void 0,await rk(l)]}}}),Pp,Wi,jn,zp,sk,nk,ok,ed,Ue,ps=ye(()=>{"use strict";Zp(),Wi=!1,jn=!1,zp=!1,sk=()=>{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}},nk=()=>{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}},ok=()=>{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}},ed=async t=>{if(Wi)return Promise.resolve();if(jn)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(zp)throw new Error("previous call to 'initializeWebAssembly()' failed.");jn=!0;let e=t.initTimeout,r=t.numThreads;if(t.simd!==!1){if(t.simd==="relaxed"){if(!ok())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!nk())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let s=sk();r>1&&!s&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", 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."),t.numThreads=r=1);let n=t.wasmPaths,o=typeof n=="string"?n:void 0,a=n?.mjs,i=a?.href??a,l=n?.wasm,u=l?.href??l,d=t.wasmBinary,[f,m]=await Xk(i,o,r>1,!!d||!!u),_=!1,w=[];if(e>0&&w.push(new Promise(x=>{setTimeout(()=>{_=!0,x()},e)})),w.push(new Promise((x,k)=>{let E={numThreads:r};if(d)E.wasmBinary=d;else if(u||o)E.locateFile=M=>u??o+M;else if(i&&i.indexOf("blob:")!==0)E.locateFile=M=>new URL(M,i).href;else if(f){let M=Vk();M&&(E.locateFile=I=>M+I)}m(E).then(M=>{jn=!1,Wi=!0,Pp=M,x(),f&&URL.revokeObjectURL(f)},M=>{jn=!1,zp=!0,k(M)})})),await Promise.race(w),_)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},Ue=()=>{if(Wi&&Pp)return Pp;throw new Error("WebAssembly is not initialized yet.")}}),It,Ji,Oe,td=ye(()=>{"use strict";ps(),It=(t,e)=>{let r=Ue(),s=r.lengthBytesUTF8(t)+1,n=r._malloc(s);return r.stringToUTF8(t,n,s),e.push(n),n},Ji=(t,e,r,s)=>{if(typeof t=="object"&&t!==null){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach(([n,o])=>{let a=e?e+n:n;if(typeof o=="object")Ji(o,a+".",r,s);else if(typeof o=="string"||typeof o=="number")s(a,o.toString());else if(typeof o=="boolean")s(a,o?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof o}`)})},Oe=t=>{let e=Ue(),r=e.stackSave();try{let s=e.PTR_SIZE,n=e.stackAlloc(2*s);e._OrtGetLastError(n,n+s);let o=Number(e.getValue(n,s===4?"i32":"i64")),a=e.getValue(n+s,"*"),i=a?e.UTF8ToString(a):"";throw new Error(`${t} ERROR_CODE: ${o}, ERROR_MESSAGE: ${i}`)}finally{e.stackRestore(r)}}}),Kk,LC=ye(()=>{"use strict";ps(),td(),Kk=t=>{let e=Ue(),r=0,s=[],n=t||{};try{if(t?.logSeverityLevel===void 0)n.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log severity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)n.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(n.terminate=!1);let o=0;return t?.tag!==void 0&&(o=It(t.tag,s)),r=e._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,o),r===0&&Oe("Can't create run options."),t?.extra!==void 0&&Ji(t.extra,"",new WeakSet,(a,i)=>{let l=It(a,s),u=It(i,s);e._OrtAddRunConfigEntry(r,l,u)!==0&&Oe(`Can't set a run config entry: ${a} - ${i}.`)}),[r,s]}catch(o){throw r!==0&&e._OrtReleaseRunOptions(r),s.forEach(a=>e._free(a)),o}}}),ak,ik,lk,Vi,kr,ck,Yk,NC=ye(()=>{"use strict";ps(),td(),ak=t=>{switch(t){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: ${t}`)}},ik=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},lk=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(t.enableMemPattern=!1)},Vi=(t,e,r,s)=>{let n=It(e,s),o=It(r,s);Ue()._OrtAddSessionConfigEntry(t,n,o)!==0&&Oe(`Can't set a session config entry: ${e} - ${r}.`)},kr=(t,e,r,s)=>{let n=It(e,s),o=It(r,s);t.push([n,o])},ck=async(t,e,r)=>{let s=e.executionProviders;for(let n of s){let o=typeof n=="string"?n:n.name,a=[];switch(o){case"webnn":if(o="WEBNN",typeof n!="string"){let f=n?.deviceType;f&&Vi(t,"deviceType",f,r)}break;case"webgpu":{o="WebGPU";let f;if(typeof n!="string"){let _=n;if(_.device)if(typeof GPUDevice<"u"&&_.device instanceof GPUDevice)f=_.device;else throw new Error("Invalid GPU device set in WebGPU EP options.");let{enableGraphCapture:w}=e;if(typeof w=="boolean"&&w&&kr(a,"enableGraphCapture","1",r),typeof _.preferredLayout=="string"&&kr(a,"preferredLayout",_.preferredLayout,r),_.forceCpuNodeNames){let x=Array.isArray(_.forceCpuNodeNames)?_.forceCpuNodeNames:[_.forceCpuNodeNames];kr(a,"forceCpuNodeNames",x.join(`
15
- `),r)}_.validationMode&&kr(a,"validationMode",_.validationMode,r)}let m=Ue().webgpuRegisterDevice(f);if(m){let[_,w,x]=m;kr(a,"deviceId",_.toString(),r),kr(a,"webgpuInstance",w.toString(),r),kr(a,"webgpuDevice",x.toString(),r)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${o}`)}let i=It(o,r),l=a.length,u=0,d=0;if(l>0){u=Ue()._malloc(l*Ue().PTR_SIZE),r.push(u),d=Ue()._malloc(l*Ue().PTR_SIZE),r.push(d);for(let f=0;f<l;f++)Ue().setValue(u+f*Ue().PTR_SIZE,a[f][0],"*"),Ue().setValue(d+f*Ue().PTR_SIZE,a[f][1],"*")}await Ue()._OrtAppendExecutionProvider(t,i,u,d,l)!==0&&Oe(`Can't append execution provider: ${o}.`)}},Yk=async t=>{let e=Ue(),r=0,s=[],n=t||{};lk(n);try{let o=ak(n.graphOptimizationLevel??"all"),a=ik(n.executionMode??"sequential"),i=typeof n.logId=="string"?It(n.logId,s):0,l=n.logSeverityLevel??2;if(!Number.isInteger(l)||l<0||l>4)throw new Error(`log severity level is not valid: ${l}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let d=typeof n.optimizedModelFilePath=="string"?It(n.optimizedModelFilePath,s):0;if(r=e._OrtCreateSessionOptions(o,!!n.enableCpuMemArena,!!n.enableMemPattern,a,!!n.enableProfiling,0,i,l,u,d),r===0&&Oe("Can't create session options."),n.executionProviders&&await ck(r,n,s),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);Vi(r,"enableGraphCapture",n.enableGraphCapture.toString(),s)}if(n.freeDimensionOverrides)for(let[f,m]of Object.entries(n.freeDimensionOverrides)){if(typeof f!="string")throw new Error(`free dimension override name must be a string: ${f}`);if(typeof m!="number"||!Number.isInteger(m)||m<0)throw new Error(`free dimension override value must be a non-negative integer: ${m}`);let _=It(f,s);e._OrtAddFreeDimensionOverride(r,_,m)!==0&&Oe(`Can't set a free dimension override: ${f} - ${m}.`)}return n.extra!==void 0&&Ji(n.extra,"",new WeakSet,(f,m)=>{Vi(r,f,m,s)}),[r,s]}catch(o){throw r!==0&&e._OrtReleaseSessionOptions(r)!==0&&Oe("Can't release session options."),s.forEach(a=>e._free(a)),o}}}),as,Ki,Fs,Hn,Zi,rd,sd,Wp,js=ye(()=>{"use strict";as=t=>{switch(t){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: ${t}`)}},Ki=t=>{switch(t){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: ${t}`)}},Fs=(t,e)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],s=typeof e=="number"?e:e.reduce((n,o)=>n*o,1);return r>0?Math.ceil(s*r):void 0},Hn=t=>{switch(t){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: ${t}`)}},Zi=t=>{switch(t){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: ${t}`)}},rd=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",sd=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint64"||t==="int8"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",Wp=t=>{switch(t){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: ${t}`)}}}),nd,Qk=ye(()=>{"use strict";Jp(),nd=async t=>{if(typeof t=="string"){let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let r=e.headers.get("Content-Length"),s=r?parseInt(r,10):0;if(s<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n=e.body.getReader(),o;try{o=new ArrayBuffer(s)}catch(i){if(i instanceof RangeError){let l=Math.ceil(s/65536);o=new WebAssembly.Memory({initial:l,maximum:l}).buffer}else throw i}let a=0;for(;;){let{done:i,value:l}=await n.read();if(i)break;let u=l.byteLength;new Uint8Array(o,a,u).set(l),a+=u}return new Uint8Array(o,0,s)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}}),Jk,$C=ye(()=>{"use strict";js(),Jk=(t,e)=>new(Hn(e))(t)}),uk,pk,dk,fk,Zk,mk,_t,eE=ye(()=>{"use strict";js(),uk=["V","I","W","E","F"],pk=(t,e)=>{console.log(`[${uk[t]},${new Date().toISOString()}]${e}`)},Zk=(t,e)=>{dk=t,fk=e},mk=(t,e)=>{let r=Zi(t),s=Zi(dk);r>=s&&pk(r,typeof e=="function"?e():e)},_t=(...t)=>{fk&&mk(...t)}}),Lp,Vp,Np,hk,$p,_k,Rp,Up,Bp,gk,tE,RC=ye(()=>{"use strict";js(),eE(),Lp=new Map([["float32",32],["float16",16],["int32",32],["uint32",32],["int64",64],["uint64",64],["int8",8],["uint8",8],["int4",4],["uint4",4]]),Vp=(t,e)=>{if(e==="int32")return t;let r=Lp.get(e);if(!r)throw new Error(`WebNN backend does not support data type: ${e}`);let s=r/8;if(t.byteLength%s!==0)throw new Error(`Invalid Uint8Array length - must be a multiple of ${s}.`);let n=t.byteLength/s,o=new(Hn(e))(t.buffer,t.byteOffset,n);switch(e){case"int64":case"uint64":{let a=new Int32Array(n);for(let i=0;i<n;i++){let l=o[i];if(l>2147483647n||l<-2147483648n)throw new Error("Can not convert int64 data to int32 - value out of range.");a[i]=Number(l)}return new Uint8Array(a.buffer)}case"int8":case"uint8":case"uint32":{if(e==="uint32"&&o.some(i=>i>2147483647))throw new Error("Can not convert uint32 data to int32 - value out of range.");let a=Int32Array.from(o,Number);return new Uint8Array(a.buffer)}default:throw new Error(`Unsupported data conversion from ${e} to 'int32'`)}},Np=(t,e)=>{if(e==="int32")return t;if(t.byteLength%4!==0)throw new Error("Invalid Uint8Array length - must be a multiple of 4 (int32).");let r=t.byteLength/4,s=new Int32Array(t.buffer,t.byteOffset,r);switch(e){case"int64":{let n=BigInt64Array.from(s,BigInt);return new Uint8Array(n.buffer)}case"uint64":{if(s.some(o=>o<0))throw new Error("Can not convert int32 data to uin64 - negative value found.");let n=BigUint64Array.from(s,BigInt);return new Uint8Array(n.buffer)}case"int8":{if(s.some(o=>o<-128||o>127))throw new Error("Can not convert int32 data to int8 - value out of range.");let n=Int8Array.from(s,Number);return new Uint8Array(n.buffer)}case"uint8":{if(s.some(n=>n<0||n>255))throw new Error("Can not convert int32 data to uint8 - value out of range.");return Uint8Array.from(s,Number)}case"uint32":{if(s.some(o=>o<0))throw new Error("Can not convert int32 data to uint32 - negative value found.");let n=Uint32Array.from(s,Number);return new Uint8Array(n.buffer)}default:throw new Error(`Unsupported data conversion from 'int32' to ${e}`)}},hk=1,$p=()=>hk++,_k=new Map([["int8","int32"],["uint8","int32"],["uint32","int32"],["int64","int32"]]),Rp=(t,e)=>{let r=Lp.get(t);if(!r)throw new Error(`WebNN backend does not support data type: ${t}`);return e.length>0?Math.ceil(e.reduce((s,n)=>s*n)*r/8):0},Up=class{constructor(t){this.isDataConverted=!1;let{sessionId:e,context:r,tensor:s,dataType:n,shape:o,fallbackDataType:a}=t;this.sessionId=e,this.mlContext=r,this.mlTensor=s,this.dataType=n,this.tensorShape=o,this.fallbackDataType=a}get tensor(){return this.mlTensor}get type(){return this.dataType}get fallbackType(){return this.fallbackDataType}get shape(){return this.tensorShape}get byteLength(){return Rp(this.dataType,this.tensorShape)}destroy(){_t("verbose",()=>"[WebNN] TensorWrapper.destroy"),this.mlTensor.destroy()}write(t){this.mlContext.writeTensor(this.mlTensor,t)}async read(t){if(this.fallbackDataType){let e=await this.mlContext.readTensor(this.mlTensor),r=Np(new Uint8Array(e),this.dataType);if(t){(t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)).set(r);return}else return r.buffer}else return t?this.mlContext.readTensor(this.mlTensor,t):this.mlContext.readTensor(this.mlTensor)}canReuseTensor(t,e,r){return this.mlContext===t&&this.dataType===e&&this.tensorShape.length===r.length&&this.tensorShape.every((s,n)=>s===r[n])}setIsDataConverted(t){this.isDataConverted=t}},Bp=class{constructor(t,e){this.tensorManager=t,this.wrapper=e}get tensorWrapper(){return this.wrapper}releaseTensor(){this.tensorWrapper&&(this.tensorManager.releaseTensor(this.tensorWrapper),this.wrapper=void 0)}async ensureTensor(t,e,r,s){let n=this.tensorManager.getMLContext(t),o=this.tensorManager.getMLOpSupportLimits(t),a;if(!o?.input.dataTypes.includes(e)){if(a=_k.get(e),!a||o?.input.dataTypes.includes(a))throw new Error(`WebNN backend does not support data type: ${e}`);_t("verbose",()=>`[WebNN] TensorIdTracker.ensureTensor: fallback dataType from ${e} to ${a}`)}if(this.wrapper){if(this.wrapper.canReuseTensor(n,e,r))return this.wrapper.tensor;if(s){if(this.wrapper.byteLength!==Rp(e,r))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 i=typeof MLTensorUsage>"u"?void 0:MLTensorUsage.READ|MLTensorUsage.WRITE;return this.wrapper=await this.tensorManager.getCachedTensor(t,e,r,i,!0,!0,a),s&&this.activeUpload&&(this.wrapper.write(this.activeUpload),this.activeUpload=void 0),this.wrapper.tensor}upload(t){let e=t;if(this.wrapper){if(this.wrapper.fallbackType)if(this.wrapper.fallbackType==="int32")e=Vp(t,this.wrapper.type),this.wrapper.setIsDataConverted(!0);else throw new Error(`Unsupported fallback data type: ${this.wrapper.fallbackType}`);if(t.byteLength===this.wrapper.byteLength){this.wrapper.write(e);return}else _t("verbose",()=>"Data size does not match tensor size. Releasing tensor."),this.releaseTensor()}this.activeUpload?this.activeUpload.set(e):this.activeUpload=new Uint8Array(e)}async download(t){if(this.activeUpload){let e=this.wrapper?.isDataConverted?Np(this.activeUpload,this.wrapper?.type):this.activeUpload;if(t){t instanceof ArrayBuffer?new Uint8Array(t).set(e):new Uint8Array(t.buffer,t.byteOffset,t.byteLength).set(e);return}else return e.buffer}if(!this.wrapper)throw new Error("Tensor has not been created.");return t?this.wrapper.read(t):this.wrapper.read()}},gk=class{constructor(t){this.backend=t,this.tensorTrackersById=new Map,this.freeTensors=[],this.externalTensors=new Set}getMLContext(t){let e=this.backend.getMLContext(t);if(!e)throw new Error("MLContext not found for session.");return e}getMLOpSupportLimits(t){return this.backend.getMLOpSupportLimits(t)}reserveTensorId(){let t=$p();return this.tensorTrackersById.set(t,new Bp(this)),t}releaseTensorId(t){let e=this.tensorTrackersById.get(t);e&&(this.tensorTrackersById.delete(t),e.tensorWrapper&&this.releaseTensor(e.tensorWrapper))}async ensureTensor(t,e,r,s,n){_t("verbose",()=>`[WebNN] TensorManager.ensureTensor {tensorId: ${e}, dataType: ${r}, shape: ${s}, copyOld: ${n}}`);let o=this.tensorTrackersById.get(e);if(!o)throw new Error("Tensor not found.");return o.ensureTensor(t,r,s,n)}upload(t,e){let r=this.tensorTrackersById.get(t);if(!r)throw new Error("Tensor not found.");r.upload(e)}async download(t,e){_t("verbose",()=>`[WebNN] TensorManager.download {tensorId: ${t}, dstBuffer: ${e?.byteLength}}`);let r=this.tensorTrackersById.get(t);if(!r)throw new Error("Tensor not found.");return r.download(e)}releaseTensorsForSession(t){for(let e of this.freeTensors)e.sessionId===t&&e.destroy();this.freeTensors=this.freeTensors.filter(e=>e.sessionId!==t)}registerTensor(t,e,r,s){let n=this.getMLContext(t),o=$p(),a=new Up({sessionId:t,context:n,tensor:e,dataType:r,shape:s});return this.tensorTrackersById.set(o,new Bp(this,a)),this.externalTensors.add(a),o}async getCachedTensor(t,e,r,s,n,o,a){let i=this.getMLContext(t);for(let[u,d]of this.freeTensors.entries())if(d.canReuseTensor(i,e,r)){_t("verbose",()=>`[WebNN] Reusing tensor {dataType: ${e}, ${a?`fallbackDataType: ${a},`:""} shape: ${r}`);let f=this.freeTensors.splice(u,1)[0];return f.sessionId=t,f}_t("verbose",()=>`[WebNN] MLContext.createTensor {dataType: ${e}, ${a?`fallbackDataType: ${a},`:""} shape: ${r}}`);let l=await i.createTensor({dataType:a??e,shape:r,dimensions:r,usage:s,writable:n,readable:o});return new Up({sessionId:t,context:i,tensor:l,dataType:e,shape:r,fallbackDataType:a})}releaseTensor(t){this.externalTensors.has(t)&&this.externalTensors.delete(t),this.freeTensors.push(t)}},tE=(...t)=>new gk(...t)}),rE={};Xn(rE,{WebNNBackend:()=>sE});var Gn,wk,sE,UC=ye(()=>{"use strict";js(),ps(),$C(),RC(),eE(),Gn=new Map([[1,"float32"],[10,"float16"],[6,"int32"],[12,"uint32"],[7,"int64"],[13,"uint64"],[22,"int4"],[21,"uint4"],[3,"int8"],[2,"uint8"],[9,"uint8"]]),wk=(t,e)=>{if(t===e)return!0;if(t===void 0||e===void 0)return!1;let r=Object.keys(t).sort(),s=Object.keys(e).sort();return r.length===s.length&&r.every((n,o)=>n===s[o]&&t[n]===e[n])},sE=class{constructor(t){this.tensorManager=tE(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,Zk(t.logLevel,!!t.debug)}get currentSessionId(){if(this.activeSessionId===void 0)throw new Error("No active session");return this.activeSessionId}onRunStart(t){_t("verbose",()=>`[WebNN] onRunStart {sessionId: ${t}}`),this.activeSessionId=t}onRunEnd(t){_t("verbose",()=>`[WebNN] onRunEnd {sessionId: ${t}}`);let e=this.temporarySessionTensorIds.get(t);if(e){for(let r of e)_t("verbose",()=>`[WebNN] releasing temporary tensor {tensorId: ${r}}`),this.tensorManager.releaseTensorId(r);this.temporarySessionTensorIds.delete(t),this.activeSessionId=void 0}}async createMLContext(t){if(t instanceof GPUDevice){let r=this.mlContextCache.findIndex(s=>s.gpuDevice===t);if(r!==-1)return this.mlContextCache[r].mlContext;{let s=await navigator.ml.createContext(t);return this.mlContextCache.push({gpuDevice:t,mlContext:s}),s}}else if(t===void 0){let r=this.mlContextCache.findIndex(s=>s.options===void 0&&s.gpuDevice===void 0);if(r!==-1)return this.mlContextCache[r].mlContext;{let s=await navigator.ml.createContext();return this.mlContextCache.push({mlContext:s}),s}}let e=this.mlContextCache.findIndex(r=>wk(r.options,t));if(e!==-1)return this.mlContextCache[e].mlContext;{let r=await navigator.ml.createContext(t);return this.mlContextCache.push({options:t,mlContext:r}),r}}registerMLContext(t,e){this.mlContextBySessionId.set(t,e);let r=this.sessionIdsByMLContext.get(e);r||(r=new Set,this.sessionIdsByMLContext.set(e,r)),r.add(t),this.mlOpSupportLimitsBySessionId.has(t)||this.mlOpSupportLimitsBySessionId.set(t,e.opSupportLimits()),this.temporaryGraphInputs.length>0&&(this.sessionGraphInputs.set(t,this.temporaryGraphInputs),this.temporaryGraphInputs=[]),this.temporaryGraphOutputs.length>0&&(this.sessionGraphOutputs.set(t,this.temporaryGraphOutputs),this.temporaryGraphOutputs=[])}onReleaseSession(t){this.sessionGraphInputs.delete(t),this.sessionGraphOutputs.delete(t);let e=this.mlContextBySessionId.get(t);if(!e)return;this.tensorManager.releaseTensorsForSession(t),this.mlContextBySessionId.delete(t),this.mlOpSupportLimitsBySessionId.delete(t);let r=this.sessionIdsByMLContext.get(e);if(r.delete(t),r.size===0){this.sessionIdsByMLContext.delete(e);let s=this.mlContextCache.findIndex(n=>n.mlContext===e);s!==-1&&this.mlContextCache.splice(s,1)}}getMLContext(t){return this.mlContextBySessionId.get(t)}getMLOpSupportLimits(t){return this.mlOpSupportLimitsBySessionId.get(t)}reserveTensorId(){return this.tensorManager.reserveTensorId()}releaseTensorId(t){_t("verbose",()=>`[WebNN] releaseTensorId {tensorId: ${t}}`),this.tensorManager.releaseTensorId(t)}async ensureTensor(t,e,r,s,n){let o=Gn.get(r);if(!o)throw new Error(`Unsupported ONNX data type: ${r}`);return this.tensorManager.ensureTensor(t??this.currentSessionId,e,o,s,n)}async createTemporaryTensor(t,e,r){_t("verbose",()=>`[WebNN] createTemporaryTensor {onnxDataType: ${e}, shape: ${r}}`);let s=Gn.get(e);if(!s)throw new Error(`Unsupported ONNX data type: ${e}`);let n=this.tensorManager.reserveTensorId();await this.tensorManager.ensureTensor(t,n,s,r,!1);let o=this.temporarySessionTensorIds.get(t);return o?o.push(n):this.temporarySessionTensorIds.set(t,[n]),n}uploadTensor(t,e){if(!Ue().shouldTransferToMLTensor)throw new Error("Trying to upload to a MLTensor while shouldTransferToMLTensor is false");_t("verbose",()=>`[WebNN] uploadTensor {tensorId: ${t}, data: ${e.byteLength}}`),this.tensorManager.upload(t,e)}async downloadTensor(t,e){return this.tensorManager.download(t,e)}createMLTensorDownloader(t,e){return async()=>{let r=await this.tensorManager.download(t);return Jk(r,e)}}registerMLTensor(t,e,r,s){let n=Gn.get(r);if(!n)throw new Error(`Unsupported ONNX data type: ${r}`);let o=this.tensorManager.registerTensor(t,e,n,s);return _t("verbose",()=>`[WebNN] registerMLTensor {tensor: ${e}, dataType: ${n}, dimensions: ${s}} -> {tensorId: ${o}}`),o}registerMLConstant(t,e,r,s,n,o,a=!1){if(!o)throw new Error("External mounted files are not available.");let i=t;t.startsWith("./")&&(i=t.substring(2));let l=o.get(i);if(!l)throw new Error(`File with name ${i} not found in preloaded files.`);if(e+r>l.byteLength)throw new Error("Out of bounds: data offset and length exceed the external file data size.");let u=l.slice(e,e+r).buffer,d;switch(n.dataType){case"float32":d=new Float32Array(u);break;case"float16":d=typeof Float16Array<"u"&&Float16Array.from?new Float16Array(u):new Uint16Array(u);break;case"int32":d=new Int32Array(u);break;case"uint32":d=new Uint32Array(u);break;case"int64":if(a){let f=Vp(new Uint8Array(u),"int64");d=new Int32Array(f.buffer),n.dataType="int32"}else d=new BigInt64Array(u);break;case"uint64":d=new BigUint64Array(u);break;case"int8":d=new Int8Array(u);break;case"int4":case"uint4":case"uint8":d=new Uint8Array(u);break;default:throw new Error(`Unsupported data type: ${n.dataType} in creating WebNN Constant from external data.`)}return _t("verbose",()=>`[WebNN] registerMLConstant {dataType: ${n.dataType}, shape: ${n.shape}}} ${a?"(Note: it was int64 data type and registered to int32 as workaround)":""}`),s.constant(n,d)}registerGraphInput(t){this.temporaryGraphInputs.push(t)}registerGraphOutput(t){this.temporaryGraphOutputs.push(t)}isGraphInput(t,e){let r=this.sessionGraphInputs.get(t);return r?r.includes(e):!1}isGraphOutput(t,e){let r=this.sessionGraphOutputs.get(t);return r?r.includes(e):!1}isGraphInputOutputTypeSupported(t,e,r=!0){let s=Gn.get(as(e)),n=this.mlOpSupportLimitsBySessionId.get(t);return typeof s>"u"?!1:r?!!n?.input.dataTypes.includes(s):!!n?.output.dataTypes.includes(s)}flush(){}}}),xk,od,ad,Er,yk,Dp,el,id,ld,Fp,cd,ud,pd,nE=ye(()=>{"use strict";us(),LC(),NC(),js(),ps(),td(),Qk(),xk=(t,e)=>{Ue()._OrtInit(t,e)!==0&&Oe("Can't initialize onnxruntime.")},od=async t=>{xk(t.wasm.numThreads,Zi(t.logLevel))},ad=async(t,e)=>{Ue().asyncInit?.();let r=t.webgpu.adapter;if(e==="webgpu"){if(typeof navigator>"u"||!navigator.gpu)throw new Error("WebGPU is not supported in current environment");if(r){if(typeof r.limits!="object"||typeof r.features!="object"||typeof r.requestDevice!="function")throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let s=t.webgpu.powerPreference;if(s!==void 0&&s!=="low-power"&&s!=="high-performance")throw new Error(`Invalid powerPreference setting: "${s}"`);let n=t.webgpu.forceFallbackAdapter;if(n!==void 0&&typeof n!="boolean")throw new Error(`Invalid forceFallbackAdapter setting: "${n}"`);if(r=await navigator.gpu.requestAdapter({powerPreference:s,forceFallbackAdapter:n}),!r)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");if(e==="webgpu"&&Ue().webgpuInit(s=>{t.webgpu.device=s}),e==="webnn"){let s=new(UC(),Yi(rE)).WebNNBackend(t);Ue().webnnInit([s,()=>s.reserveTensorId(),n=>s.releaseTensorId(n),async(n,o,a,i,l)=>s.ensureTensor(n,o,a,i,l),(n,o)=>{s.uploadTensor(n,o)},async(n,o)=>s.downloadTensor(n,o),(n,o)=>s.registerMLContext(n,o),!!t.trace])}},Er=new Map,yk=t=>{let e=Ue(),r=e.stackSave();try{let s=e.PTR_SIZE,n=e.stackAlloc(2*s);e._OrtGetInputOutputCount(t,n,n+s)!==0&&Oe("Can't get session input/output count.");let o=s===4?"i32":"i64";return[Number(e.getValue(n,o)),Number(e.getValue(n+s,o))]}finally{e.stackRestore(r)}},Dp=(t,e)=>{let r=Ue(),s=r.stackSave(),n=0;try{let o=r.PTR_SIZE,a=r.stackAlloc(2*o);r._OrtGetInputOutputMetadata(t,e,a,a+o)!==0&&Oe("Can't get session input/output metadata.");let i=Number(r.getValue(a,"*"));n=Number(r.getValue(a+o,"*"));let l=r.HEAP32[n/4];if(l===0)return[i,0];let u=r.HEAPU32[n/4+1],d=[];for(let f=0;f<u;f++){let m=Number(r.getValue(n+8+f*o,"*"));d.push(m!==0?r.UTF8ToString(m):Number(r.getValue(n+8+(f+u)*o,"*")))}return[i,l,d]}finally{r.stackRestore(s),n!==0&&r._OrtFree(n)}},el=t=>{let e=Ue(),r=e._malloc(t.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,r),[r,t.byteLength]},id=async(t,e)=>{let r,s,n=Ue();Array.isArray(t)?[r,s]=t:t.buffer===n.HEAPU8.buffer?[r,s]=[t.byteOffset,t.byteLength]:[r,s]=el(t);let o=0,a=0,i=0,l=[],u=[],d=[];try{if([a,l]=await Yk(e),e?.externalData&&n.mountExternalData){let T=[];for(let z of e.externalData){let C=typeof z=="string"?z:z.path;T.push(nd(typeof z=="string"?z:z.data).then(v=>{n.mountExternalData(C,v)}))}await Promise.all(T)}for(let T of e?.executionProviders??[])if((typeof T=="string"?T:T.name)==="webnn"){if(n.shouldTransferToMLTensor=!1,typeof T!="string"){let z=T,C=z?.context,v=z?.gpuDevice,G=z?.deviceType,X=z?.powerPreference;C?n.currentContext=C:v?n.currentContext=await n.webnnCreateMLContext(v):n.currentContext=await n.webnnCreateMLContext({deviceType:G,powerPreference:X})}else n.currentContext=await n.webnnCreateMLContext();break}o=await n._OrtCreateSession(r,s,a),n.webgpuOnCreateSession?.(o),o===0&&Oe("Can't create a session."),n.jsepOnCreateSession?.(),n.currentContext&&(n.webnnRegisterMLContext(o,n.currentContext),n.currentContext=void 0,n.shouldTransferToMLTensor=!0);let[f,m]=yk(o),_=!!e?.enableGraphCapture,w=[],x=[],k=[],E=[],M=[];for(let T=0;T<f;T++){let[z,C,v]=Dp(o,T);z===0&&Oe("Can't get an input name."),u.push(z);let G=n.UTF8ToString(z);w.push(G),k.push(C===0?{name:G,isTensor:!1}:{name:G,isTensor:!0,type:Ki(C),shape:v})}for(let T=0;T<m;T++){let[z,C,v]=Dp(o,T+f);z===0&&Oe("Can't get an output name."),d.push(z);let G=n.UTF8ToString(z);x.push(G),E.push(C===0?{name:G,isTensor:!1}:{name:G,isTensor:!0,type:Ki(C),shape:v});{if(_&&e?.preferredOutputLocation===void 0){M.push("gpu-buffer");continue}let X=typeof e?.preferredOutputLocation=="string"?e.preferredOutputLocation:e?.preferredOutputLocation?.[G]??"cpu",V=n.webnnIsGraphOutput;if(X==="cpu"&&V&&V(o,G)){M.push("ml-tensor-cpu-output");continue}if(X!=="cpu"&&X!=="cpu-pinned"&&X!=="gpu-buffer"&&X!=="ml-tensor")throw new Error(`Not supported preferred output location: ${X}.`);if(_&&X!=="gpu-buffer")throw new Error(`Not supported preferred output location: ${X}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);M.push(X)}}let I=null;return M.some(T=>T==="gpu-buffer"||T==="ml-tensor"||T==="ml-tensor-cpu-output")&&(i=n._OrtCreateBinding(o),i===0&&Oe("Can't create IO binding."),I={handle:i,outputPreferredLocations:M,outputPreferredLocationsEncoded:M.map(T=>T==="ml-tensor-cpu-output"?"ml-tensor":T).map(T=>Wp(T))}),Er.set(o,[o,u,d,I,_,!1]),[o,w,x,k,E]}catch(f){throw u.forEach(m=>n._OrtFree(m)),d.forEach(m=>n._OrtFree(m)),i!==0&&n._OrtReleaseBinding(i)!==0&&Oe("Can't release IO binding."),o!==0&&n._OrtReleaseSession(o)!==0&&Oe("Can't release session."),f}finally{n._free(r),a!==0&&n._OrtReleaseSessionOptions(a)!==0&&Oe("Can't release session options."),l.forEach(f=>n._free(f)),n.unmountExternalData?.()}},ld=t=>{let e=Ue(),r=Er.get(t);if(!r)throw new Error(`cannot release session. invalid session id: ${t}`);let[s,n,o,a,i]=r;a&&(i&&e._OrtClearBoundOutputs(a.handle)!==0&&Oe("Can't clear bound outputs."),e._OrtReleaseBinding(a.handle)!==0&&Oe("Can't release IO binding.")),e.jsepOnReleaseSession?.(t),e.webnnOnReleaseSession?.(t),e.webgpuOnReleaseSession?.(t),n.forEach(l=>e._OrtFree(l)),o.forEach(l=>e._OrtFree(l)),e._OrtReleaseSession(s)!==0&&Oe("Can't release session."),Er.delete(t)},Fp=async(t,e,r,s,n,o,a=!1)=>{if(!t){e.push(0);return}let i=Ue(),l=i.PTR_SIZE,u=t[0],d=t[1],f=t[3],m=f,_,w;if(u==="string"&&(f==="gpu-buffer"||f==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&f!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${o} when enableGraphCapture is true.`);if(f==="gpu-buffer"){let E=t[2].gpuBuffer;w=Fs(as(u),d);{let M=i.webgpuRegisterBuffer;if(!M)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');_=M(E,s)}}else if(f==="ml-tensor"){let E=t[2].mlTensor;w=Fs(as(u),d);let M=i.webnnRegisterMLTensor;if(!M)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');_=M(s,E,as(u),d)}else{let E=t[2];if(Array.isArray(E)){w=l*E.length,_=i._malloc(w),r.push(_);for(let M=0;M<E.length;M++){if(typeof E[M]!="string")throw new TypeError(`tensor data at index ${M} is not a string`);i.setValue(_+M*l,It(E[M],r),"*")}}else{let M=i.webnnIsGraphInput,I=i.webnnIsGraphOutput;if(u!=="string"&&M&&I){let T=i.UTF8ToString(n);if(M(s,T)||I(s,T)){let z=as(u);w=Fs(z,d),m="ml-tensor";let C=i.webnnCreateTemporaryTensor,v=i.webnnUploadTensor;if(!C||!v)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');let G=await C(s,z,d);v(G,new Uint8Array(E.buffer,E.byteOffset,E.byteLength)),_=G}else w=E.byteLength,_=i._malloc(w),r.push(_),i.HEAPU8.set(new Uint8Array(E.buffer,E.byteOffset,w),_)}else w=E.byteLength,_=i._malloc(w),r.push(_),i.HEAPU8.set(new Uint8Array(E.buffer,E.byteOffset,w),_)}}let x=i.stackSave(),k=i.stackAlloc(4*d.length);try{d.forEach((M,I)=>i.setValue(k+I*l,M,l===4?"i32":"i64"));let E=i._OrtCreateTensor(as(u),_,w,k,d.length,Wp(m));E===0&&Oe(`Can't create tensor for input/output. session=${s}, index=${o}.`),e.push(E)}finally{i.stackRestore(x)}},cd=async(t,e,r,s,n,o)=>{let a=Ue(),i=a.PTR_SIZE,l=Er.get(t);if(!l)throw new Error(`cannot run inference. invalid session id: ${t}`);let u=l[0],d=l[1],f=l[2],m=l[3],_=l[4],w=l[5],x=e.length,k=s.length,E=0,M=[],I=[],T=[],z=[],C=[],v=a.stackSave(),G=a.stackAlloc(x*i),X=a.stackAlloc(x*i),V=a.stackAlloc(k*i),Q=a.stackAlloc(k*i);try{[E,M]=Kk(o),Mr("wasm prepareInputOutputTensor");for(let P=0;P<x;P++)await Fp(r[P],I,z,t,d[e[P]],e[P],_);for(let P=0;P<k;P++)await Fp(n[P],T,z,t,f[s[P]],x+s[P],_);Tr("wasm prepareInputOutputTensor");for(let P=0;P<x;P++)a.setValue(G+P*i,I[P],"*"),a.setValue(X+P*i,d[e[P]],"*");for(let P=0;P<k;P++)a.setValue(V+P*i,T[P],"*"),a.setValue(Q+P*i,f[s[P]],"*");if(m&&!w){let{handle:P,outputPreferredLocations:se,outputPreferredLocationsEncoded:ie}=m;if(d.length!==x)throw new Error(`input count from feeds (${x}) is expected to be always equal to model's input count (${d.length}).`);Mr("wasm bindInputsOutputs");for(let S=0;S<x;S++){let L=e[S];await a._OrtBindInput(P,d[L],I[S])!==0&&Oe(`Can't bind input[${S}] for session=${t}.`)}for(let S=0;S<k;S++){let L=s[S];n[S]?.[3]?(C.push(T[S]),a._OrtBindOutput(P,f[L],T[S],0)!==0&&Oe(`Can't bind pre-allocated output[${S}] for session=${t}.`)):a._OrtBindOutput(P,f[L],0,ie[L])!==0&&Oe(`Can't bind output[${S}] to ${se[S]} for session=${t}.`)}Tr("wasm bindInputsOutputs"),Er.set(t,[u,d,f,m,_,!0])}a.jsepOnRunStart?.(u),a.webnnOnRunStart?.(u);let K;m?K=await a._OrtRunWithBinding(u,m.handle,k,V,E):K=await a._OrtRun(u,X,G,x,Q,k,V,E),K!==0&&Oe("failed to call OrtRun().");let Y=[],B=[];Mr("wasm ProcessOutputTensor");for(let P=0;P<k;P++){let se=Number(a.getValue(V+P*i,"*"));if(se===T[P]||C.includes(T[P])){Y.push(n[P]),se!==T[P]&&a._OrtReleaseTensor(se)!==0&&Oe("Can't release tensor.");continue}let ie=a.stackSave(),S=a.stackAlloc(4*i),L=!1,R,te=0;try{a._OrtGetTensorData(se,S,S+i,S+2*i,S+3*i)!==0&&Oe(`Can't access output tensor data on index ${P}.`);let ue=i===4?"i32":"i64",Be=Number(a.getValue(S,ue));te=a.getValue(S+i,"*");let Ce=a.getValue(S+i*2,"*"),vt=Number(a.getValue(S+i*3,ue)),Qe=[];for(let Me=0;Me<vt;Me++)Qe.push(Number(a.getValue(Ce+Me*i,ue)));a._OrtFree(Ce)!==0&&Oe("Can't free memory for tensor dims.");let Ze=Qe.reduce((Me,xe)=>Me*xe,1);R=Ki(Be);let rt=m?.outputPreferredLocations[s[P]];if(R==="string"){if(rt==="gpu-buffer"||rt==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let Me=[];for(let xe=0;xe<Ze;xe++){let Ge=a.getValue(te+xe*i,"*"),kt=a.getValue(te+(xe+1)*i,"*"),ge=xe===Ze-1?void 0:kt-Ge;Me.push(a.UTF8ToString(Ge,ge))}Y.push([R,Qe,Me,"cpu"])}else if(rt==="gpu-buffer"&&Ze>0){let Me=a.webgpuGetBuffer;if(!Me)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let xe=Me(te),Ge=Fs(Be,Ze);if(Ge===void 0||!rd(R))throw new Error(`Unsupported data type: ${R}`);L=!0;{a.webgpuRegisterBuffer(xe,t,te);let kt=a.webgpuCreateDownloader(xe,Ge,t);Y.push([R,Qe,{gpuBuffer:xe,download:async()=>{let ge=await kt();return new(Hn(R))(ge)},dispose:()=>{a._OrtReleaseTensor(se)!==0&&Oe("Can't release tensor.")}},"gpu-buffer"])}}else if(rt==="ml-tensor"&&Ze>0){let Me=a.webnnEnsureTensor,xe=a.webnnIsGraphInputOutputTypeSupported;if(!Me||!xe)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(Fs(Be,Ze)===void 0||!sd(R))throw new Error(`Unsupported data type: ${R}`);if(!xe(t,R,!1))throw new Error(`preferredLocation "ml-tensor" for ${R} output is not supported by current WebNN Context.`);let Ge=await Me(t,te,Be,Qe,!1);L=!0,Y.push([R,Qe,{mlTensor:Ge,download:a.webnnCreateMLTensorDownloader(te,R),dispose:()=>{a.webnnReleaseTensorId(te),a._OrtReleaseTensor(se)}},"ml-tensor"])}else if(rt==="ml-tensor-cpu-output"&&Ze>0){let Me=a.webnnCreateMLTensorDownloader(te,R)(),xe=Y.length;L=!0,B.push((async()=>{let Ge=[xe,await Me];return a.webnnReleaseTensorId(te),a._OrtReleaseTensor(se),Ge})()),Y.push([R,Qe,[],"cpu"])}else{let Me=Hn(R),xe=new Me(Ze);new Uint8Array(xe.buffer,xe.byteOffset,xe.byteLength).set(a.HEAPU8.subarray(te,te+xe.byteLength)),Y.push([R,Qe,xe,"cpu"])}}finally{a.stackRestore(ie),R==="string"&&te&&a._free(te),L||a._OrtReleaseTensor(se)}}m&&!_&&(a._OrtClearBoundOutputs(m.handle)!==0&&Oe("Can't clear bound outputs."),Er.set(t,[u,d,f,m,_,!1]));for(let[P,se]of await Promise.all(B))Y[P][2]=se;return Tr("wasm ProcessOutputTensor"),Y}finally{a.webnnOnRunEnd?.(u),a.stackRestore(v),r.forEach(K=>{K&&K[3]==="gpu-buffer"&&a.webgpuUnregisterBuffer(K[2].gpuBuffer)}),n.forEach(K=>{K&&K[3]==="gpu-buffer"&&a.webgpuUnregisterBuffer(K[2].gpuBuffer)}),I.forEach(K=>a._OrtReleaseTensor(K)),T.forEach(K=>a._OrtReleaseTensor(K)),z.forEach(K=>a._free(K)),E!==0&&a._OrtReleaseRunOptions(E),M.forEach(K=>a._free(K))}},ud=t=>{let e=Ue(),r=Er.get(t);if(!r)throw new Error("invalid session id");let s=r[0],n=e._OrtEndProfiling(s);n===0&&Oe("Can't get an profile file name."),e._OrtFree(n)},pd=t=>{let e=[];for(let r of t){let s=r[2];!Array.isArray(s)&&"buffer"in s&&e.push(s.buffer)}return e}}),Ar,Ut,Ds,qn,Wn,Hi,jp,Xi,ss,ns,bk,oE,aE,iE,lE,cE,uE,pE,dE=ye(()=>{"use strict";us(),nE(),ps(),Zp(),Ar=()=>!!We.wasm.proxy&&typeof document<"u",Ds=!1,qn=!1,Wn=!1,Xi=new Map,ss=(t,e)=>{let r=Xi.get(t);r?r.push(e):Xi.set(t,[e])},ns=()=>{if(Ds||!qn||Wn||!Ut)throw new Error("worker not ready")},bk=t=>{switch(t.data.type){case"init-wasm":Ds=!1,t.data.err?(Wn=!0,jp[1](t.data.err)):(qn=!0,jp[0]()),Hi&&(URL.revokeObjectURL(Hi),Hi=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=Xi.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},oE=async()=>{if(!qn){if(Ds)throw new Error("multiple calls to 'initWasm()' detected.");if(Wn)throw new Error("previous call to 'initWasm()' failed.");if(Ds=!0,Ar())return new Promise((t,e)=>{Ut?.terminate(),Hk().then(([r,s])=>{try{Ut=s,Ut.onerror=o=>e(o),Ut.onmessage=bk,jp=[t,e];let n={type:"init-wasm",in:We};!n.in.wasm.wasmPaths&&(r||qp)&&(n.in.wasm.wasmPaths={wasm:new URL("ort-wasm-simd-threaded.asyncify.wasm",import.meta.url).href}),Ut.postMessage(n),Hi=r}catch(n){e(n)}},e)});try{await ed(We.wasm),await od(We),qn=!0}catch(t){throw Wn=!0,t}finally{Ds=!1}}},aE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("init-ep",[e,r]);let s={type:"init-ep",in:{epName:t,env:We}};Ut.postMessage(s)});await ad(We,t)},iE=async t=>Ar()?(ns(),new Promise((e,r)=>{ss("copy-from",[e,r]);let s={type:"copy-from",in:{buffer:t}};Ut.postMessage(s,[t.buffer])})):el(t),lE=async(t,e)=>{if(Ar()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return ns(),new Promise((r,s)=>{ss("create",[r,s]);let n={type:"create",in:{model:t,options:{...e}}},o=[];t instanceof Uint8Array&&o.push(t.buffer),Ut.postMessage(n,o)})}else return id(t,e)},cE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("release",[e,r]);let s={type:"release",in:t};Ut.postMessage(s)});ld(t)},uE=async(t,e,r,s,n,o)=>{if(Ar()){if(r.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return ns(),new Promise((a,i)=>{ss("run",[a,i]);let l=r,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:l,outputIndices:s,options:o}};Ut.postMessage(u,pd(l))})}else return cd(t,e,r,s,n,o)},pE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("end-profiling",[e,r]);let s={type:"end-profiling",in:t};Ut.postMessage(s)});ud(t)}}),Gp,vk,fE,BC=ye(()=>{"use strict";us(),dE(),js(),Jp(),Qk(),Gp=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[t.type,t.dims,{mlTensor:t.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},vk=t=>{switch(t[3]){case"cpu":return new Kt(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!rd(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:s,dispose:n}=t[2];return Kt.fromGpuBuffer(r,{dataType:e,dims:t[1],download:s,dispose:n})}case"ml-tensor":{let e=t[0];if(!sd(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:r,download:s,dispose:n}=t[2];return Kt.fromMLTensor(r,{dataType:e,dims:t[1],download:s,dispose:n})}default:throw new Error(`invalid data location: ${t[3]}`)}},fE=class{async fetchModelAndCopyToWasmMemory(t){return iE(await nd(t))}async loadModel(t,e){ls();let r;typeof t=="string"?r=await this.fetchModelAndCopyToWasmMemory(t):r=t,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await lE(r,e),cs()}async dispose(){return cE(this.sessionId)}async run(t,e,r){ls();let s=[],n=[];Object.entries(t).forEach(f=>{let m=f[0],_=f[1],w=this.inputNames.indexOf(m);if(w===-1)throw new Error(`invalid input '${m}'`);s.push(_),n.push(w)});let o=[],a=[];Object.entries(e).forEach(f=>{let m=f[0],_=f[1],w=this.outputNames.indexOf(m);if(w===-1)throw new Error(`invalid output '${m}'`);o.push(_),a.push(w)});let i=s.map((f,m)=>Gp(f,()=>`input "${this.inputNames[n[m]]}"`)),l=o.map((f,m)=>f?Gp(f,()=>`output "${this.outputNames[a[m]]}"`):null),u=await uE(this.sessionId,n,i,a,l,r),d={};for(let f=0;f<u.length;f++)d[this.outputNames[a[f]]]=o[f]??vk(u[f]);return cs(),d}startProfiling(){}endProfiling(){pE(this.sessionId)}}}),mE={};Xn(mE,{OnnxruntimeWebAssemblyBackend:()=>Xp,initializeFlags:()=>Hp,wasmBackend:()=>hE});var Hp,Xp,hE,DC=ye(()=>{"use strict";us(),dE(),BC(),Hp=()=>{(typeof We.wasm.initTimeout!="number"||We.wasm.initTimeout<0)&&(We.wasm.initTimeout=0);let t=We.wasm.simd;if(typeof t!="boolean"&&t!==void 0&&t!=="fixed"&&t!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${t}". Reset it to \`false\` and ignore SIMD feature checking.`),We.wasm.simd=!1),typeof We.wasm.proxy!="boolean"&&(We.wasm.proxy=!1),typeof We.wasm.trace!="boolean"&&(We.wasm.trace=!1),typeof We.wasm.numThreads!="number"||!Number.isInteger(We.wasm.numThreads)||We.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)We.wasm.numThreads=1;else{let e=typeof navigator>"u"?gC("node:os").cpus().length:navigator.hardwareConcurrency;We.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},Xp=class{async init(t){Hp(),await oE(),await aE(t)}async createInferenceSessionHandler(t,e){let r=new fE;return await r.loadModel(t,e),r}},hE=new Xp});us();us();us();var FC="1.25.0-dev.20260209-a3749f1353",jC=Fk;{let t=(DC(),Yi(mE)).wasmBackend;is("webgpu",t,5),is("webnn",t,5),is("cpu",t,10),is("wasm",t,10)}Object.defineProperty(We.versions,"web",{value:FC,enumerable:!0});async function _E(t){let e=t.split("/").pop(),r;try{if(r=await Di(),r){let n=await r.match(t);if(n)return n}}catch(n){console.warn(`Failed to load ${e} from cache:`,n)}let s=await fetch(t);if(!s.ok)throw new Error(`Failed to fetch ${e}: ${s.status} ${s.statusText}`);if(r)try{await r.put(t,s.clone())}catch(n){console.warn(`Failed to cache ${e}:`,n)}return s}async function gE(t){let e=await _E(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(r){return console.warn("Failed to read WASM binary:",r),null}}async function wE(t){let e=await _E(t);if(!e||typeof e=="string")return null;try{let r=await e.text(),s=t.split("/").slice(0,-1).join("/");r=r.replace(/import\.meta\.url/g,`"${s}"`);let n=new Blob([r],{type:"text/javascript"});return URL.createObjectURL(n)}catch(r){return console.warn("Failed to read WASM binary:",r),null}}function fd(t){return Us(t,["blob:"])}function md(t){let e;if(typeof location<"u"&&location.href)e=location.href;else if(typeof import.meta<"u"&&import.meta.url)e=import.meta.url;else return t;return new URL(t,e).href}import{Tensor as AE}from"onnxruntime-common";var qC=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}}),WC=["verbose","info","warning","error","fatal"],vE=4,Bt=[],hd,qs,xE=Symbol.for("onnxruntime");if(xE in globalThis)qs=globalThis[xE];else if(be.IS_NODE_ENV){switch(qs=GC,process.platform){case"win32":Bt.push("dml");break;case"linux":process.arch==="x64"&&Bt.push("cuda");break;case"darwin":Bt.push("coreml");break}Bt.push("webgpu"),Bt.push("cpu"),hd=["cpu"]}else qs=dd,be.IS_WEBNN_AVAILABLE&&Bt.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),be.IS_WEBGPU_AVAILABLE&&Bt.push("webgpu"),Bt.push("wasm"),hd=["wasm"];var VC=qs.InferenceSession;function kE(t=null){if(!t)return hd;switch(t){case"auto":return Bt;case"gpu":return Bt.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(Bt.includes(t))return[qC[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${Bt.join(", ")}.`)}var EE=be.IS_BROWSER_ENV||be.IS_WEBWORKER_ENV,yE=Promise.resolve(),Gs=null;async function HC(){return Gs||(De.useWasmCache&&typeof ft?.wasm?.wasmPaths=="object"&&ft?.wasm?.wasmPaths?.wasm&&ft?.wasm?.wasmPaths?.mjs?(Gs=(async()=>{let e=ft.wasm.wasmPaths;await Promise.all([e.wasm&&!fd(e.wasm)?(async()=>{try{let r=await gE(md(e.wasm));r&&(ft.wasm.wasmBinary=r)}catch(r){console.warn("Failed to pre-load WASM binary:",r)}})():Promise.resolve(),e.mjs&&!fd(e.mjs)?(async()=>{try{let r=await wE(md(e.mjs));r&&(ft.wasm.wasmPaths.mjs=r)}catch(r){console.warn("Failed to pre-load WASM factory:",r)}})():Promise.resolve()])})(),Gs):(Gs=Promise.resolve(),Gs))}async function tl(t,e,r){await HC();let s=()=>VC.create(t,{logSeverityLevel:vE,...e}),n=await(EE?yE=yE.then(s):s());return n.config=r,n}var bE=Promise.resolve();async function rl(t,e){let r=()=>t.run(e);return await(EE?bE=bE.then(r):r())}function sl(t){return t instanceof qs.Tensor}var ft=qs?.env;ft.logLevel=WC[vE];if(ft?.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&ft.versions?.web&&!ft.wasm.wasmPaths){let t=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${ft.versions.web}/dist/`;ft.wasm.wasmPaths=be.IS_SAFARI?{mjs:`${t}ort-wasm-simd-threaded.mjs`,wasm:`${t}ort-wasm-simd-threaded.wasm`}:{mjs:`${t}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${t}ort-wasm-simd-threaded.asyncify.wasm`}}ft.wasm.proxy=!1}ft?.webgpu&&(ft.webgpu.powerPreference="high-performance");function Kn(){return ft?.wasm?.proxy}De.backends.onnx=ft;var Sr=async(t,e,r)=>{let s=await tl(new Uint8Array(t),e);return(async n=>{let o=Kn(),a=Object.fromEntries(Object.entries(n).map(([l,u])=>[l,(o?u.clone():u).ort_tensor])),i=await rl(s,a);return Array.isArray(r)?r.map(l=>new U(i[l])):new U(i[r])})},nr=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=Sr([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,"y")),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=Sr([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=Sr([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=Sr([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=Sr([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=Sr([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=Sr([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}static get slice(){return this._slice||(this._slice=Sr([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,"y")),this._slice}};var ME=Object.freeze({auto:"auto",gpu:"gpu",cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:"webnn","webnn-npu":"webnn-npu","webnn-gpu":"webnn-gpu","webnn-cpu":"webnn-cpu"});var TE=(function(){let t;return async function(){if(t===void 0)if(!be.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),mt=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),_d=Object.freeze({[ME.wasm]:mt.q8}),gd=Object.freeze({[mt.fp32]:"",[mt.fp16]:"_fp16",[mt.int8]:"_int8",[mt.uint8]:"_uint8",[mt.q8]:"_quantized",[mt.q4]:"_q4",[mt.q4f16]:"_q4f16",[mt.bnb4]:"_bnb4"}),Ws=Object.freeze({float32:Float32Array,float16:typeof Float16Array<"u"?Float16Array:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array,uint4:Uint8Array,int4:Int8Array});var U=class t{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return sl(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new AE(e[0],e[1],e[2]),new Proxy(this,{get:(r,s)=>{if(typeof s=="string"){let n=Number(s);if(Number.isInteger(n))return r._getitem(n)}return r[s]},set:(r,s,n)=>r[s]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){let[e,...r]=this.dims;if(r.length>0){let s=r.reduce((n,o)=>n*o);for(let n=0;n<e;++n)yield this._subarray(n,s,r)}else yield*this.data}_getitem(e){let[r,...s]=this.dims;if(e=or(e,r),s.length>0){let n=s.reduce((o,a)=>o*a);return this._subarray(e,n,s)}else return new t(this.type,[this.data[e]],s)}indexOf(e){let r=this.data;for(let s=0;s<r.length;++s)if(r[s]==e)return s;return-1}_subarray(e,r,s){let n=e*r,o=(e+1)*r,a="subarray"in this.data?this.data.subarray(n,o):this.data.slice(n,o);return new t(this.type,a,s)}item(){let e=this.data;if(e.length!==1)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return XC(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=1/(1+Math.exp(-e[r]));return this}map(e){return this.clone().map_(e)}map_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]=e(r[s],s,r);return this}mul(e){return this.clone().mul_(e)}mul_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]*=e;return this}div(e){return this.clone().div_(e)}div_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]/=e;return this}add(e){return this.clone().add_(e)}add_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]-=e;return this}clone(){return new t(this.type,this.data.slice(),this.dims.slice())}slice(...e){let r=[],s=[];for(let d=0;d<this.dims.length;++d){let f=e[d];if(f==null)s.push([0,this.dims[d]]),r.push(this.dims[d]);else if(typeof f=="number")f=or(f,this.dims[d],d),s.push([f,f+1]);else if(Array.isArray(f)&&f.length===2){let[m,_]=f;if(m=m===null?0:or(m,this.dims[d],d,!1),_=_===null?this.dims[d]:or(_,this.dims[d],d,!1),m>_)throw new Error(`Invalid slice: ${f}`);let w=[Math.max(m,0),Math.min(_,this.dims[d])];s.push(w),r.push(w[1]-w[0])}else throw new Error(`Invalid slice: ${f}`)}let n=s.map(([d,f])=>f-d),o=n.reduce((d,f)=>d*f),a=this.data,i=new a.constructor(o),l=this.stride(),u=!0;for(let d=1;d<n.length;++d)if(s[d][0]!==0||s[d][1]!==this.dims[d]){u=!1;break}if(u){let d=s[0][0]*l[0],f=s[0][1]*l[0];if(ArrayBuffer.isView(a))i.set(a.subarray(d,f));else if(Array.isArray(a)){let m=a.slice(d,f);for(let _=0;_<m.length;++_)i[_]=m[_]}else throw new Error("Unsupported data type for slicing")}else for(let d=0;d<o;++d){let f=0;for(let m=n.length-1,_=d;m>=0;--m){let w=n[m];f+=(_%w+s[m][0])*l[m],_=Math.floor(_/w)}i[d]=a[f]}return new t(this.type,i,r)}permute(...e){return KC(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,r=!1){return this.norm(1,e,r)}norm(e="fro",r=null,s=!1){if(e==="fro")e=2;else if(typeof e=="string")throw Error(`Unsupported norm: ${e}`);let n=this.data,o=(u,d)=>u+d**e;if(r===null){let u=n.reduce(o,0)**(1/e);return new t(this.type,[u],[])}let[a,i,l]=Yn(o,this,r,s);if(e!==1)for(let u=0;u<i.length;++u)i[u]=i[u]**(1/e);return new t(a,i,l)}normalize_(e=2,r=1){r=or(r,this.dims.length);let s=this.norm(e,r,!0),n=this.data,o=s.data;for(let a=0;a<n.length;++a){let i=0;for(let l=this.dims.length-1,u=a,d=1;l>=0;--l){let f=this.dims[l];if(l!==r){let m=u%f;i+=m*d,d*=this.dims[l]}u=Math.floor(u/f)}n[a]/=o[i]}return this}normalize(e=2,r=1){return this.clone().normalize_(e,r)}stride(){return wd(this.dims)}squeeze(e=null){return new t(this.type,this.data,SE(this.dims,e))}squeeze_(e=null){return this.dims=SE(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,OE(this.dims,e))}unsqueeze_(e){return this.dims=OE(this.dims,e),this}flatten_(e=0,r=-1){r=(r+this.dims.length)%this.dims.length;let s=this.dims.slice(0,e),n=this.dims.slice(e,r+1),o=this.dims.slice(r+1);return this.dims=[...s,n.reduce((a,i)=>a*i,1),...o],this}flatten(e=0,r=-1){return this.clone().flatten_(e,r)}view(...e){let r=-1;for(let n=0;n<e.length;++n)if(e[n]===-1){if(r!==-1)throw new Error("Only one dimension can be inferred");r=n}let s=this.data;if(r!==-1){let n=e.reduce((o,a,i)=>i!==r?o*a:o,1);e[r]=s.length/n}return new t(this.type,s,e)}neg_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=-e[r];return this}neg(){return this.clone().neg_()}gt(e){let r=new Uint8Array(this.data.length),s=this.data;for(let n=0;n<s.length;++n)r[n]=s[n]>e?1:0;return new t("bool",r,this.dims)}lt(e){let r=new Uint8Array(this.data.length),s=this.data;for(let n=0;n<s.length;++n)r[n]=s[n]<e?1:0;return new t("bool",r,this.dims)}clamp_(e,r){let s=this.data;for(let n=0;n<s.length;++n)s[n]=Math.min(Math.max(s[n],e),r);return this}clamp(e,r){return this.clone().clamp_(e,r)}round_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=Math.round(e[r]);return this}round(){return this.clone().round_()}mean(e=null,r=!1){return al(this,e,r)}min(e=null,r=!1){if(e===null){let a=Dn(this.data)[0];return new t(this.type,[a],[])}let[s,n,o]=Yn((a,i)=>Math.min(a,i),this,e,r,1/0);return new t(s,n,o)}max(e=null,r=!1){if(e===null){let a=Te(this.data)[0];return new t(this.type,[a],[])}let[s,n,o]=Yn((a,i)=>Math.max(a,i),this,e,r,-1/0);return new t(s,n,o)}argmin(e=null,r=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let s=Dn(this.data)[1];return new t("int64",[BigInt(s)],[])}argmax(e=null,r=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let s=Te(this.data)[1];return new t("int64",[BigInt(s)],[])}repeat(...e){if(e.length<this.dims.length)throw new Error(`Number of dimensions of repeat dims (${e.length}) cannot be smaller than number of dimensions of tensor (${this.dims.length})`);if(e.every(d=>d===1)){if(e.length===this.dims.length)return this.clone();let d=e.length-this.dims.length,f=Array(d).fill(1).concat(this.dims);return new t(this.type,this.data.slice(),f)}let r=e.length-this.dims.length,s=Array(r).fill(1).concat(this.dims),n=s.map((d,f)=>d*e[f]),o=n.reduce((d,f)=>d*f,1),a=this.data,i=new a.constructor(o),l=wd(s),u=wd(n);for(let d=0;d<o;++d){let f=d,m=0;for(let _=0;_<n.length;++_){let w=Math.floor(f/u[_]);f=f%u[_];let x=w%s[_];m+=x*l[_]}i[d]=a[m]}return new t(this.type,i,n)}tile(...e){if(e.length<this.dims.length){let r=this.dims.length-e.length;e=Array(r).fill(1).concat(e)}return this.repeat(...e)}to(e){if(this.type===e)return this;if(!Ws.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);let r,s=["int64","uint64"].includes(this.type),n=["int64","uint64"].includes(e);if(s&&!n)r=Number;else if(!s&&n)["float16","float32","float64"].includes(this.type)?r=o=>BigInt(Math.floor(o)):r=BigInt;else if(this.type==="float16"&&e=="float32"&&this.data instanceof Uint16Array)return new t(e,Kv(this.data),this.dims);return new t(e,Ws[e].from(this.data,r),this.dims)}};function XC(t,e){let r=t.length,s=e.reduce((o,a)=>o*a);if(r!==s)throw Error(`cannot reshape array of size ${r} into shape (${e})`);let n=t;for(let o=e.length-1;o>=0;o--)n=n.reduce((a,i)=>{let l=a[a.length-1];return l.length<e[o]?l.push(i):a.push([i]),a},[[]]);return n[0]}function KC(t,e){let[r,s]=Gv(t.data,t.dims,e);return new U(t.type,r,s)}function xd(t,[e,r],s="bilinear",n=!1){let o=t.dims.at(-3)??1,a=t.dims.at(-2),i=t.dims.at(-1),l=jv(t.data,[o,a,i],[e,r],s,n);return new U(t.type,l,[o,e,r])}async function Dt(t,{size:e=null,mode:r="bilinear"}={}){if(t.dims.length!==4)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!e)throw new Error("`interpolate_4d` requires a `size` argument.");let s;if(e.length===2)s=[...t.dims.slice(0,2),...e];else if(e.length===3)s=[t.dims[0],...e];else if(e.length===4)s=e;else throw new Error("`size` must be of length 2, 3, or 4.");let n;if(r==="nearest")n=await nr.nearest_interpolate_4d;else if(r==="bilinear")n=await nr.bilinear_interpolate_4d;else if(r==="bicubic")n=await nr.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${r}`);let o=new U("int64",new BigInt64Array(s.map(BigInt)),[s.length]);return await n({x:t,s:o})}async function IE(t,e){return await(await nr.matmul)({a:t,b:e})}async function QN(t,e){return await(await nr.rfft)({x:t,a:e})}async function Yt(t,e){let r=await nr.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await r({x:t,k:new U("int64",[BigInt(e)],[1])})}var nl=t=>new U("int64",t,[t.length]);async function ol(t,e,r,s,n){return await(await nr.slice)({x:t,s:nl(e),e:nl(r),a:nl(s),t:nl(n??new Array(s.length).fill(1))})}function CE(t,e){let r=t.data,s=e.data,n=[t.dims[0],t.dims[2]],o=new r.constructor(n[0]*n[1]),[a,i,l]=t.dims,u=0;for(let d=0;d<a;++d){let f=d*l*i;for(let m=0;m<l;++m){let _=0,w=0,x=d*i,k=f+m;for(let M=0;M<i;++M){let I=Number(s[x+M]);w+=I,_+=r[k+M*l]*I}let E=_/w;o[u++]=E}}return new U(t.type,o,n)}function JN(t,e,{eps:r=1e-5}={}){if(t.dims.length!==2)throw new Error("`layer_norm` currently only supports 2D input.");let[s,n]=t.dims;if(e.length!==1&&e[0]!==n)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");let[o,a]=yd(t,1,0,!0),i=o.data,l=a.data,u=t.data,d=new u.constructor(u.length);for(let f=0;f<s;++f){let m=f*n;for(let _=0;_<n;++_){let w=m+_;d[w]=(u[w]-l[f])/(i[f]+r)}}return new U(t.type,d,t.dims)}function SE(t,e){return t=t.slice(),e===null?t=t.filter(r=>r!==1):typeof e=="number"?t[e]===1&&t.splice(e,1):Array.isArray(e)&&(t=t.filter((r,s)=>r!==1||!e.includes(s))),t}function OE(t,e){return e=or(e,t.length+1),t=t.slice(),t.splice(e,0,1),t}function or(t,e,r=null,s=!0){if(t<-e||t>=e){if(s)throw new Error(`IndexError: index ${t} is out of bounds for dimension${r===null?"":" "+r} with size ${e}`);return t<-e?0:e}return t<0&&(t=(t%e+e)%e),t}function Ee(t,e=0){e=or(e,t[0].dims.length);let r=t[0].dims.slice();r[e]=t.reduce((a,i)=>a+i.dims[e],0);let s=r.reduce((a,i)=>a*i,1),n=new t[0].data.constructor(s),o=t[0].type;if(e===0){let a=0;for(let i of t){let l=i.data;n.set(l,a),a+=l.length}}else{let a=0;for(let i=0;i<t.length;++i){let{data:l,dims:u}=t[i];for(let d=0;d<l.length;++d){let f=0;for(let m=u.length-1,_=d,w=1;m>=0;--m){let x=u[m],k=_%x;m===e&&(k+=a),f+=k*w,w*=r[m],_=Math.floor(_/x)}n[f]=l[d]}a+=u[e]}}return new U(o,n,r)}function Ft(t,e=0){return Ee(t.map(r=>r.unsqueeze(e)),e)}function Yn(t,e,r,s=!1,n=null){let o=e.data,a=e.dims;r=or(r,a.length);let i=a.slice();i[r]=1;let l=new o.constructor(o.length/a[r]);n!==null&&l.fill(n);for(let u=0;u<o.length;++u){let d=0;for(let f=a.length-1,m=u,_=1;f>=0;--f){let w=a[f];if(f!==r){let x=m%w;d+=x*_,_*=i[f]}m=Math.floor(m/w)}l[d]=t(l[d],o[u],u,d)}return s||i.splice(r,1),[e.type,l,i]}function yd(t,e=null,r=1,s=!1){let n=t.data,o=t.dims;if(e===null){let _=n.reduce((E,M)=>E+M,0)/n.length,w=Math.sqrt(n.reduce((E,M)=>E+(M-_)**2,0)/(n.length-r)),x=new U(t.type,[_],[]);return[new U(t.type,[w],[]),x]}e=or(e,o.length);let a=al(t,e,s),i=a.data,[l,u,d]=Yn((m,_,w,x)=>m+(_-i[x])**2,t,e,s);for(let m=0;m<u.length;++m)u[m]=Math.sqrt(u[m]/(o[e]-r));return[new U(l,u,d),a]}function al(t,e=null,r=!1){let s=t.dims,n=t.data;if(e===null){let l=n.reduce((u,d)=>u+d,0);return new U(t.type,[l/n.length],[])}e=or(e,s.length);let[o,a,i]=Yn((l,u)=>l+u,t,e,r);if(s[e]!==1)for(let l=0;l<a.length;++l)a[l]/=s[e];return new U(o,a,i)}function wd(t){let e=new Array(t.length);for(let r=t.length-1,s=1;r>=0;--r)e[r]=s,s*=t[r];return e}function bd(t,e,r,s){let n=t.reduce((o,a)=>o*a,1);return new U(r,new s(n).fill(e),t)}function Ve(t,e){let r,s;if(typeof e=="number")r="float32",s=Float32Array;else if(typeof e=="bigint")r="int64",s=BigInt64Array;else if(typeof e=="boolean")r="bool",s=Uint8Array;else throw new Error(`Unsupported data type: ${typeof e}`);return bd(t,e,r,s)}function Qn(t,e){return Ve(t.dims,e)}function it(t){return bd(t,1n,"int64",BigInt64Array)}function il(t){return it(t.dims)}function vd(t){return bd(t,0n,"int64",BigInt64Array)}function kd(t){return vd(t.dims)}function ZN(t){let e=t.reduce((r,s)=>r*s,1);return new U("float32",Float32Array.from({length:e},()=>Math.random()),t)}function PE(t){let e=t.reduce((s,n)=>s*n,1),r=new Float32Array(e);for(let s=0;s<e;s+=2){let n=1-Math.random(),o=Math.random(),a=Math.sqrt(-2*Math.log(n)),i=2*Math.PI*o;r[s]=a*Math.cos(i),s+1<e&&(r[s+1]=a*Math.sin(i))}return new U("float32",r,t)}function zE(t,e){if(t.dims.length!==2)throw new Error("The tensor must have 2 dimensions");if(t.dims.at(-1)%8!==0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(e))throw new Error("The precision must be either 'binary' or 'ubinary'");let r=e==="binary",s=r?"int8":"uint8",n=r?Int8Array:Uint8Array,o=t.data,a=new n(o.length/8);for(let i=0;i<o.length;++i){let l=o[i]>0?1:0,u=Math.floor(i/8),d=i%8;a[u]|=l<<7-d,r&&d===0&&(a[u]-=128)}return new U(s,a,[t.dims[0],t.dims[1]/8])}async function Ed(t,e){return await Promise.all([at(t,"tokenizer.json",!0,e),at(t,"tokenizer_config.json",!0,e)])}function Ad(t){let e=t.dims;switch(e.length){case 1:return t.tolist();case 2:if(e[0]!==1)throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return t.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${e.length}.`)}}var YC=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function QC(t,e,r,s){for(let n of Object.keys(t)){let o=e-t[n].length,a=r(n),i=new Array(o).fill(a);t[n]=s==="right"?dt(t[n],i):dt(i,t[n])}}function JC(t,e){for(let r of Object.keys(t))t[r].length=e}function ds(t,...e){for(let r of e){if(!Object.hasOwn(t,r))continue;let s=t[r];if(s)if(typeof s=="object"){if(s.__type==="AddedToken")return s.content;throw Error(`Unknown token: ${s}`)}else return s}return null}function ZC(t){let e=[];for(let r of t.get_added_tokens_decoder().values())r.special&&e.push(r);return e}var j=class extends Je{return_token_type_ids=!1;padding_side="right";constructor(e,r){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=r,this._tokenizer=new xv(e,r),this.config=r,this.padding_side=r.padding_side??this.padding_side,this.mask_token=ds(r,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=ds(r,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=ds(r,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=ds(r,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=ds(r,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=ds(r,"eos_token"),this.eos_token_id=this._tokenizer.token_to_id(this.eos_token),this.chat_template=r.chat_template??null,Array.isArray(this.chat_template)){let n=Object.create(null);for(let{name:o,template:a}of this.chat_template){if(typeof o!="string"||typeof a!="string")throw new Error('Chat template must be a list of objects with "name" and "template" properties');n[o]=a}this.chat_template=n}this._compiled_template_cache=new Map;let s=ZC(this._tokenizer);this.all_special_ids=s.map(n=>n.id),this.all_special_tokens=s.map(n=>n.content)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){let i=await Ed(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a});return new this(...i)}get_vocab(){return this._tokenizer.get_vocab()}get model_max_length(){return this._tokenizerConfig.model_max_length??1/0}get add_eos_token(){return this._tokenizerConfig.add_eos_token}get add_bos_token(){return this._tokenizerConfig.add_bos_token}convert_tokens_to_ids(e){return typeof e=="string"?this._tokenizer.token_to_id(e):e.map(r=>this._tokenizer.token_to_id(r))}_call(e,{text_pair:r=null,add_special_tokens:s=!0,padding:n=!1,truncation:o=null,max_length:a=null,return_tensor:i=!0,return_token_type_ids:l=null}={}){let u=Array.isArray(e),d;if(u){if(e.length===0)throw Error("text array must be non-empty");if(r!==null){if(Array.isArray(r)){if(e.length!==r.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");d=e.map((m,_)=>this._encode_plus(m,{text_pair:r[_],add_special_tokens:s,return_token_type_ids:l}))}else d=e.map(m=>this._encode_plus(m,{add_special_tokens:s,return_token_type_ids:l}))}else{if(e==null)throw Error("text may not be null or undefined");if(Array.isArray(r))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");d=[this._encode_plus(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:l})]}if(a===null?a=this.model_max_length:o===null&&(n===!0?(console.warn("`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."),a=this.model_max_length):n===!1&&(console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."),o=!0)),n===!0&&(a=Math.min(Te(d.map(m=>m.input_ids.length))[0],a??1/0)),a=Math.min(a,this.model_max_length??1/0),n||o)for(let m=0;m<d.length;++m)d[m].input_ids.length!==a&&(d[m].input_ids.length>a?o&&JC(d[m],a):n&&QC(d[m],a,_=>_==="input_ids"?this.pad_token_id:0,this.padding_side));let f={};if(i){if(!(n&&o)&&d.some(_=>{for(let w of Object.keys(_))if(_[w].length!==d[0][w]?.length)return!0;return!1}))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");let m=[d.length,d[0].input_ids.length];for(let _ of Object.keys(d[0]))f[_]=new U("int64",BigInt64Array.from(d.flatMap(w=>w[_]).map(BigInt)),m)}else{for(let m of Object.keys(d[0]))f[m]=d.map(_=>_[m]);if(!u)for(let m of Object.keys(f))f[m]=f[m][0]}return f}_encode_text(e){return e===null?null:this._tokenizer.encode(e).tokens}_encode_plus(e,{text_pair:r=null,add_special_tokens:s=!0,return_token_type_ids:n=null}={}){let{ids:o,attention_mask:a,token_type_ids:i}=this._tokenizer.encode(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:n??this.return_token_type_ids});return{input_ids:o,attention_mask:a,...i?{token_type_ids:i}:{}}}tokenize(e,{pair:r=null,add_special_tokens:s=!1}={}){return this._tokenizer.tokenize(e,{text_pair:r,add_special_tokens:s})}encode(e,{text_pair:r=null,add_special_tokens:s=!0,return_token_type_ids:n=null}={}){return this._tokenizer.encode(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:n}).ids}batch_decode(e,r={}){return e instanceof U&&(e=e.tolist()),e.map(s=>this.decode(s,r))}decode(e,r={}){if(e instanceof U&&(e=Ad(e)),!Array.isArray(e)||e.length===0||!Pv(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,r)}decode_single(e,{skip_special_tokens:r=!1,clean_up_tokenization_spaces:s=null}){return this._tokenizer.decode(e,{skip_special_tokens:r,clean_up_tokenization_spaces:s})}get_chat_template({chat_template:e=null,tools:r=null}={}){if(this.chat_template&&typeof this.chat_template=="object"){let s=this.chat_template;if(e!==null&&Object.hasOwn(s,e))e=s[e];else if(e===null)if(r!==null&&"tool_use"in s)e=s.tool_use;else if("default"in s)e=s.default;else throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(s).sort()}.`)}else if(e===null)if(this.chat_template)e=this.chat_template;else throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");return e}apply_chat_template(e,{tools:r=null,documents:s=null,chat_template:n=null,add_generation_prompt:o=!1,tokenize:a=!0,padding:i=!1,truncation:l=!1,max_length:u=null,return_tensor:d=!0,return_dict:f=!0,tokenizer_kwargs:m={},..._}={}){if(n=this.get_chat_template({chat_template:n,tools:r}),typeof n!="string")throw Error(`chat_template must be a string, but got ${typeof n}`);let w=this._compiled_template_cache.get(n);w===void 0&&(w=new Cv(n),this._compiled_template_cache.set(n,w));let x=Object.create(null);for(let E of YC){let M=ds(this.config,E);M&&(x[E]=M)}let k=w.render({messages:e,add_generation_prompt:o,tools:r,documents:s,...x,..._});if(a){let E=this._call(k,{add_special_tokens:!1,padding:i,truncation:l,max_length:u,return_tensor:d,...m});return f?E:E.input_ids}return k}};function Vs(t,e,r,s){if(!("language_codes"in t)||!Array.isArray(t.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in t)||!(t.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in t)||typeof t.lang_to_token!="function")throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");let n=s.src_lang,o=s.tgt_lang;if(!t.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);if(n!==void 0){if(!t.language_codes.includes(n))throw new Error(`Source language code "${n}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);for(let a of t._tokenizer.post_processor.config.single)if("SpecialToken"in a&&t.languageRegex.test(a.SpecialToken.id)){a.SpecialToken.id=t.lang_to_token(n);break}}return s.forced_bos_token_id=t._tokenizer.token_to_id(t.lang_to_token(o)),t._call(e,r)}var gf={};Ps(gf,{AlbertTokenizer:()=>Md,AutoTokenizer:()=>J,BartTokenizer:()=>Td,BertTokenizer:()=>Sd,BlenderbotSmallTokenizer:()=>Od,BlenderbotTokenizer:()=>Id,BloomTokenizer:()=>Cd,CLIPTokenizer:()=>zd,CamembertTokenizer:()=>Pd,CodeGenTokenizer:()=>Nd,CodeLlamaTokenizer:()=>Ld,CohereTokenizer:()=>$d,ConvBertTokenizer:()=>Rd,DebertaTokenizer:()=>Bd,DebertaV2Tokenizer:()=>Ud,DistilBertTokenizer:()=>Dd,ElectraTokenizer:()=>Fd,EsmTokenizer:()=>jd,FalconTokenizer:()=>Gd,GPT2Tokenizer:()=>Vd,GPTNeoXTokenizer:()=>Wd,GemmaTokenizer:()=>qd,HerbertTokenizer:()=>Hd,LlamaTokenizer:()=>Xd,M2M100Tokenizer:()=>Kd,MBart50Tokenizer:()=>Qd,MBartTokenizer:()=>Jn,MPNetTokenizer:()=>ef,MarianTokenizer:()=>Yd,MgpstrTokenizer:()=>Jd,MobileBertTokenizer:()=>Zd,NllbTokenizer:()=>tf,NougatTokenizer:()=>rf,PreTrainedTokenizer:()=>j,Qwen2Tokenizer:()=>sf,RoFormerTokenizer:()=>of,RobertaTokenizer:()=>nf,SiglipTokenizer:()=>af,SpeechT5Tokenizer:()=>lf,SqueezeBertTokenizer:()=>cf,T5Tokenizer:()=>uf,TokenizersBackend:()=>j,VitsTokenizer:()=>df,Wav2Vec2CTCTokenizer:()=>ff,WhisperTokenizer:()=>mf,XLMRobertaTokenizer:()=>hf,XLMTokenizer:()=>_f});var Md=class extends j{return_token_type_ids=!0};var Td=class extends j{};var Sd=class extends j{return_token_type_ids=!0};var Od=class extends j{};var Id=class extends j{};var Cd=class extends j{};var Pd=class extends j{};var zd=class extends j{};var Ld=class extends j{};var Nd=class extends j{};var $d=class extends j{};var Rd=class extends j{return_token_type_ids=!0};var Ud=class extends j{return_token_type_ids=!0};var Bd=class extends j{return_token_type_ids=!0};var Dd=class extends j{};var Fd=class extends j{return_token_type_ids=!0};var jd=class extends j{};var Gd=class extends j{};var qd=class extends j{};var Wd=class extends j{};var Vd=class extends j{};var Hd=class extends j{return_token_type_ids=!0};var Xd=class extends j{padding_side="left"};var Kd=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)).map(s=>s.slice(2,-2)),this.lang_to_token=s=>`__${s}__`}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var Yd=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=Array.from(this.get_vocab().keys()).filter(s=>this.languageRegex.test(s)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;let[r,...s]=e.trim().split(this.languageRegex);if(s.length===0)return super._encode_text(r);if(s.length===2){let[n,o]=s;return this.supported_language_codes.includes(n)||console.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),dt([n],super._encode_text(o))}}};var Jn=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)).map(s=>s),this.lang_to_token=s=>s}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var Qd=class extends Jn{};var Jd=class extends j{};var Zd=class extends j{return_token_type_ids=!0};var ef=class extends j{};var tf=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)),this.lang_to_token=s=>s}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var rf=class extends j{};var sf=class extends j{};var nf=class extends j{};var of=class extends j{return_token_type_ids=!0};var af=class extends j{};var lf=class extends j{};var cf=class extends j{return_token_type_ids=!0};var uf=class extends j{};var pf=class extends $t{decode_chain(e){let r="";for(let s=1;s<e.length;s+=2)r+=e[s];return[r]}},df=class extends j{constructor(e,r){super(e,r),this._tokenizer.decoder=new pf({type:"VitsDecoder"})}};var ff=class extends j{};var LE=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],Zn=new Map(LE),eP=new Map([...LE.map(([t,e])=>[e,t]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function NE(t){t=t.toLowerCase();let e=eP.get(t);if(e===void 0){let r=t.match(/^<\|([a-z]{2})\|>$/);if(r&&(t=r[1]),Zn.has(t))e=t;else{let n=t.length===2?Zn.keys():Zn.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var tP="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",$E=new RegExp(`^[${tP}]+$`,"gu"),mf=class extends j{get timestamp_begin(){return this._tokenizer.token_to_id("<|notimestamps|>")+1}_decode_asr(e,{return_timestamps:r=!1,return_language:s=!1,time_precision:n=null,force_full_sequences:o=!0}={}){if(n===null)throw Error("Must specify time_precision");let a=null,i=r==="word";function l(){return{language:a,timestamp:[null,null],text:""}}let u=[],d=l(),f=0,m=this.timestamp_begin,w=m+1500,x=[],k=[],E=!1,M=null,I=new Set(this.all_special_ids);for(let C of e){let v=C.tokens,G=i?C.token_timestamps:null,X=null,V=m;if("stride"in C){let[Y,B,P]=C.stride;if(f-=B,M=Y-P,B&&(V=B/n+m),P)for(let se=v.length-1;se>=0;--se){let ie=Number(v[se]);if(ie>=m){if(X!==null&&(ie-m)*n<M)break;X=ie}}}let Q=[],K=[];for(let Y=0;Y<v.length;++Y){let B=Number(v[Y]);if(I.has(B)){let P=this.decode([B]),se=Zn.get(P.slice(2,-2));if(se!==void 0){if(a!==null&&se!==a&&!r){x.push(Q);let ie=this.findLongestCommonSequence(x)[0],S=this.decode(ie);d.text=S,u.push(d),x=[],Q=[],d=l()}a=d.language=se}}else if(B>=m&&B<=w){let P=(B-m)*n+f,se=rs(P,2);if(X!==null&&B>=X)E=!0;else if(E||x.length>0&&B<V)E=!1;else if(d.timestamp[0]===null)d.timestamp[0]=se;else if(se!==d.timestamp[0]){d.timestamp[1]=se,x.push(Q),i&&k.push(K);let[ie,S]=this.findLongestCommonSequence(x,k),L=this.decode(ie);d.text=L,i&&(d.words=this.collateWordTimestamps(ie,S,a)),u.push(d),x=[],Q=[],k=[],K=[],d=l()}}else if(Q.push(B),i){let P=rs(G[Y]+f,2),se;if(Y+1<G.length){se=rs(G[Y+1]+f,2);let ie=this.decode([B]);$E.test(ie)&&(se=rs(Math.min(P+n,se),2))}else se=null;K.push([P,se])}}if("stride"in C){let[Y,B,P]=C.stride;f+=Y-P}Q.length>0?(x.push(Q),i&&k.push(K)):x.every(Y=>Y.length===0)&&(d=l(),x=[],Q=[],k=[],K=[])}if(x.length>0){if(o&&r)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");let[C,v]=this.findLongestCommonSequence(x,k),G=this.decode(C);d.text=G,i&&(d.words=this.collateWordTimestamps(C,v,a)),u.push(d)}let T=Object.create(null),z=u.map(C=>C.text).join("");if(r||s){for(let C=0;C<u.length;++C){let v=u[C];r||delete v.timestamp,s||delete v.language}if(i){let C=[];for(let v of u)for(let G of v.words)C.push(G);T={chunks:C}}else T={chunks:u}}return[z,T]}findLongestCommonSequence(e,r=null){let s=e[0],n=s.length,o=[],a=Array.isArray(r)&&r.length>0,i=a?[]:null,l=a?r[0]:null;for(let u=1;u<e.length;++u){let d=e[u],f=0,m=[n,n,0,0],_=d.length;for(let T=1;T<n+_;++T){let z=Math.max(0,n-T),C=Math.min(n,n+_-T),v=s.slice(z,C),G=Math.max(0,T-n),X=Math.min(_,T),V=d.slice(G,X);if(v.length!==V.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let Q;a?Q=v.filter((B,P)=>B===V[P]&&l[z+P]<=r[u][G+P]).length:Q=v.filter((B,P)=>B===V[P]).length;let K=T/1e4,Y=Q/T+K;Q>1&&Y>f&&(f=Y,m=[z,C,G,X])}let[w,x,k,E]=m,M=Math.floor((x+w)/2),I=Math.floor((E+k)/2);o.push(...s.slice(0,M)),s=d.slice(I),n=s.length,a&&(i.push(...l.slice(0,M)),l=r[u].slice(I))}return o.push(...s),a?(i.push(...l),[o,i]):[o,[]]}collateWordTimestamps(e,r,s){let[n,o,a]=this.combineTokensIntoWords(e,s),i=[];for(let l=0;l<n.length;++l){let u=a[l];i.push({text:n[l],timestamp:[r[u.at(0)][0],r[u.at(-1)][1]]})}return i}combineTokensIntoWords(e,r,s=`"'\u201C\xA1\xBF([{-`,n=`"'.\u3002,\uFF0C!\uFF01?\uFF1F:\uFF1A\u201D)]}\u3001`){r=r??"english";let o,a,i;return["chinese","japanese","thai","lao","myanmar"].includes(r)?[o,a,i]=this.splitTokensOnUnicode(e):[o,a,i]=this.splitTokensOnSpaces(e),this.mergePunctuations(o,a,i,s,n)}decode(e,r){let s;return r?.decode_with_timestamps?(e instanceof U&&(e=Ad(e)),s=this.decodeWithTimestamps(e,r)):s=super.decode(e,r),s}decodeWithTimestamps(e,r){let s=r?.time_precision??.02,n=this.all_special_ids.at(-1)+1,o=[[]];for(let a of e)if(a=Number(a),a>=n){let i=((a-n)*s).toFixed(2);o.push(`<|${i}|>`),o.push([])}else o[o.length-1].push(a);return o=o.map(a=>typeof a=="string"?a:super.decode(a,r)),o.join("")}splitTokensOnUnicode(e){let r=this.decode(e,{decode_with_timestamps:!0}),s="\uFFFD",n=[],o=[],a=[],i=[],l=[],u=0;for(let d=0;d<e.length;++d){let f=e[d];i.push(f),l.push(d);let m=this.decode(i,{decode_with_timestamps:!0});(!m.includes(s)||r[u+m.indexOf(s)]===s)&&(n.push(m),o.push(i),a.push(l),i=[],l=[],u+=m.length)}return[n,o,a]}splitTokensOnSpaces(e){let[r,s,n]=this.splitTokensOnUnicode(e),o=[],a=[],i=[];for(let l=0;l<r.length;++l){let u=r[l],d=s[l],f=n[l],m=d[0]>=this._tokenizer.token_to_id("<|endoftext|>"),_=u.startsWith(" "),w=u.trim(),x=$E.test(w);if(m||_||x||o.length===0)o.push(u),a.push(d),i.push(f);else{let k=o.length-1;o[k]+=u,a[k].push(...d),i[k].push(...f)}}return[o,a,i]}mergePunctuations(e,r,s,n,o){let a=structuredClone(e),i=structuredClone(r),l=structuredClone(s),u=a.length-2,d=a.length-1;for(;u>=0;)a[u].startsWith(" ")&&n.includes(a[u].trim())?(a[d]=a[u]+a[d],i[d]=dt(i[u],i[d]),l[d]=dt(l[u],l[d]),a[u]="",i[u]=[],l[u]=[]):d=u,--u;for(u=0,d=1;d<a.length;)!a[u].endsWith(" ")&&o.includes(a[d])?(a[u]+=a[d],i[u]=dt(i[u],i[d]),l[u]=dt(l[u],l[d]),a[d]="",i[d]=[],l[d]=[]):u=d,++d;return[a.filter(f=>f),i.filter(f=>f.length>0),l.filter(f=>f.length>0)]}};var hf=class extends j{};var _f=class extends j{return_token_type_ids=!0;constructor(e,r){super(e,r),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var J=class{static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){let[i,l]=await Ed(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a}),u=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",d=gf[u];return d||(console.warn(`Unknown tokenizer class "${u}", attempting to construct from base class.`),d=j),new d(i,l)}};var Hs="https://github.com/huggingface/transformers.js/issues/new/choose";var eo="preprocessor_config.json",Xs=eo,RE="processor_config.json",UE="chat_template.jinja";var ne=class extends Je{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,r,s){super(),this.config=e,this.components=r,this.chat_template=s}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,r={}){if(!this.tokenizer)throw new Error("Unable to apply chat template without a tokenizer.");return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...r})}batch_decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.decode(...e)}async _call(e,...r){for(let s of[this.image_processor,this.feature_extractor,this.tokenizer])if(s)return s(e,...r);throw new Error("No image processor, feature extractor, or tokenizer found.")}static async from_pretrained(e,r={}){let[s,n,o]=await Promise.all([this.uses_processor_config?at(e,RE,!0,r):{},Promise.all(this.classes.filter(a=>a in this).map(async a=>{let i=await this[a].from_pretrained(e,r);return[a.replace(/_class$/,""),i]})).then(Object.fromEntries),this.uses_chat_template_file?yp(e,UE,!0,r):null]);return new this(s,n,o)}};var Cl={};Ps(Cl,{ChatterboxProcessor:()=>Pf,Florence2Processor:()=>km,Gemma3nProcessor:()=>Em,GroundingDinoProcessor:()=>Am,Idefics3Processor:()=>Sl,JinaCLIPProcessor:()=>Tm,LlavaProcessor:()=>Sm,MgpstrProcessor:()=>Om,MoonshineProcessor:()=>Im,OwlViTProcessor:()=>Cm,PaliGemmaProcessor:()=>Pm,Phi3VProcessor:()=>zm,PixtralProcessor:()=>Lm,Processor:()=>ne,PyAnnoteProcessor:()=>Nm,Qwen2VLProcessor:()=>$m,Sam2Processor:()=>Ol,Sam2VideoProcessor:()=>Rm,SamProcessor:()=>io,SmolVLMProcessor:()=>Sl,SpeechT5Processor:()=>Um,UltravoxProcessor:()=>Bm,VLChatProcessor:()=>Mm,VoxtralProcessor:()=>Dm,Wav2Vec2Processor:()=>Fm,Wav2Vec2ProcessorWithLM:()=>jm,WhisperProcessor:()=>Gm});var Ne=class extends Je{constructor(e){super(),this.config=e}static async from_pretrained(e,r={}){let s=await at(e,eo,!0,r);return new this(s)}};function He(t,e){if(!(t instanceof Float32Array||t instanceof Float64Array))throw new Error(`${e} expects input to be a Float32Array or a Float64Array, but got ${t?.constructor?.name??typeof t} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}var oo={};Ps(oo,{ASTFeatureExtractor:()=>yf,ChatterboxFeatureExtractor:()=>bf,ClapFeatureExtractor:()=>vf,DacFeatureExtractor:()=>so,EncodecFeatureExtractor:()=>ro,FeatureExtractor:()=>Ne,Gemma3nAudioFeatureExtractor:()=>kf,MoonshineFeatureExtractor:()=>Ef,ParakeetFeatureExtractor:()=>Af,PyAnnoteFeatureExtractor:()=>no,SeamlessM4TFeatureExtractor:()=>Mf,SnacFeatureExtractor:()=>Tf,SpeechT5FeatureExtractor:()=>Sf,Wav2Vec2FeatureExtractor:()=>Of,WeSpeakerFeatureExtractor:()=>If,WhisperFeatureExtractor:()=>Cf});import rP from"fs";import{Readable as sP}from"stream";import{pipeline as nP}from"stream/promises";async function ll(t,e){if(be.IS_BROWSER_ENV){if(be.IS_WEBWORKER_ENV)throw new Error("Unable to save a file from a Web Worker.");let r=URL.createObjectURL(e),s=document.createElement("a");s.href=r,s.download=t,s.click(),s.remove(),URL.revokeObjectURL(r)}else if(be.IS_FS_AVAILABLE){let r=e.stream(),s=sP.fromWeb(r),n=rP.createWriteStream(t);await nP(s,n)}else throw new Error("Unable to save because filesystem is disabled in this environment.")}async function xf(t,e){if(typeof AudioContext>"u")throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");let r=await(await Bs(t)).arrayBuffer(),s=new AudioContext({sampleRate:e});typeof e>"u"&&console.warn(`No sampling rate provided, using default of ${s.sampleRate}Hz.`);let n=await s.decodeAudioData(r),o;if(n.numberOfChannels===2){let a=Math.sqrt(2),i=n.getChannelData(0),l=n.getChannelData(1);o=new Float32Array(i.length);for(let u=0;u<n.length;++u)o[u]=a*(i[u]+l[u])/2}else o=n.getChannelData(0);return o}function FE(t,e){if(t<1)return new Float64Array;if(t===1)return new Float64Array([1]);let r=1-e,s=2*Math.PI/(t-1),n=new Float64Array(t);for(let o=0;o<t;++o)n[o]=e-r*Math.cos(o*s);return n}function BE(t){return FE(t,.5)}function oP(t){return FE(t,.54)}var aP={htk:t=>2595*Math.log10(1+t/700),kaldi:t=>1127*Math.log(1+t/700),slaney:(t,e=1e3,r=15,s=27/Math.log(6.4))=>t>=e?r+Math.log(t/e)*s:3*t/200};function wf(t,e="htk"){let r=aP[e];if(!r)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?r(t):t.map(s=>r(s))}var iP={htk:t=>700*(10**(t/2595)-1),kaldi:t=>700*(Math.exp(t/1127)-1),slaney:(t,e=1e3,r=15,s=Math.log(6.4)/27)=>t>=r?e*Math.exp(s*(t-r)):200*t/3};function lP(t,e="htk"){let r=iP[e];if(!r)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?r(t):t.map(s=>r(s))}function cP(t,e){let r=Float64Array.from({length:e.length-1},(a,i)=>e[i+1]-e[i]),s=Array.from({length:t.length},()=>new Array(e.length));for(let a=0;a<t.length;++a){let i=s[a];for(let l=0;l<e.length;++l)i[l]=e[l]-t[a]}let n=e.length-2,o=Array.from({length:n},()=>new Array(t.length));for(let a=0;a<t.length;++a){let i=s[a];for(let l=0;l<n;++l){let u=-i[l]/r[l],d=i[l+2]/r[l+1];o[l][a]=Math.max(0,Math.min(u,d))}}return o}function DE(t,e,r){let s=(e-t)/(r-1);return Float64Array.from({length:r},(n,o)=>t+s*o)}function yt(t,e,r,s,n,o=null,a="htk",i=!1){if(o!==null&&o!=="slaney")throw new Error('norm must be one of null or "slaney"');if(t<2)throw new Error(`Require num_frequency_bins: ${t} >= 2`);if(r>s)throw new Error(`Require min_frequency: ${r} <= max_frequency: ${s}`);let l=wf(r,a),u=wf(s,a),d=DE(l,u,e+2),f=lP(d,a),m;if(i){let w=n/((t-1)*2);m=wf(Float64Array.from({length:t},(x,k)=>k*w),a),f=d}else m=DE(0,Math.floor(n/2),t);let _=cP(m,f);if(o!==null&&o==="slaney")for(let w=0;w<e;++w){let x=_[w],k=2/(f[w+2]-f[w]);for(let E=0;E<t;++E)x[E]*=k}return _}function uP(t,e,r){let s=new t.constructor(t.length+e+r),n=t.length-1;for(let o=0;o<t.length;++o)s[e+o]=t[o];for(let o=1;o<=e;++o)s[e-o]=t[$s(o,n)];for(let o=1;o<=r;++o)s[n+e+o]=t[$s(n-o,n)];return s}function jE(t,e,r,s,n){if(r<=0)throw new Error("reference must be greater than zero");if(s<=0)throw new Error("min_value must be greater than zero");r=Math.max(s,r);let o=Math.log10(r);for(let a=0;a<t.length;++a)t[a]=e*Math.log10(Math.max(s,t[a])-o);if(n!==null){if(n<=0)throw new Error("db_range must be greater than zero");let a=Te(t)[0]-n;for(let i=0;i<t.length;++i)t[i]=Math.max(t[i],a)}return t}function pP(t,e=1,r=1e-5,s=null){return jE(t,20,e,r,s)}function dP(t,e=1,r=1e-10,s=null){return jE(t,10,e,r,s)}async function At(t,e,r,s,{fft_length:n=null,power:o=1,center:a=!0,pad_mode:i="reflect",onesided:l=!0,preemphasis:u=null,preemphasis_htk_flavor:d=!0,mel_filters:f=null,mel_floor:m=1e-10,log_mel:_=null,reference:w=1,min_value:x=1e-10,db_range:k=null,remove_dc_offset:E=null,min_num_frames:M=null,max_num_frames:I=null,do_pad:T=!0,transpose:z=!1,mel_offset:C=0}={}){let v=e.length;if(n===null&&(n=r),r>n)throw Error(`frame_length (${r}) may not be larger than fft_length (${n})`);if(v!==r)throw new Error(`Length of the window (${v}) must equal frame_length (${r})`);if(s<=0)throw new Error("hop_length must be greater than zero");if(o===null&&f!==null)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(!d)throw new Error("`preemphasis_htk_flavor=false` is not currently supported.");if(a)switch(i){case"reflect":{let L=Math.floor((n-1)/2)+1;t=uP(t,L,L);break}case"constant":{let L=Math.floor(n/2),R=new t.constructor(t.length+2*L);R.set(t,L),t=R;break}default:throw new Error(`pad_mode="${i}" not implemented yet.`)}let G=Math.floor(1+Math.floor((t.length-r)/s));M!==null&&G<M&&(G=M);let X=l?Math.floor(n/2)+1:n,V=G,Q=G;I!==null&&(I>G?T&&(Q=I):Q=V=I);let K=new ji(n),Y=new Float64Array(n),B=new Float64Array(K.outputBufferSize),P=new Float32Array(X*Q);for(let L=0;L<V;++L){let R=L*s,te=Math.min(t.length-R,r);te!==r&&Y.fill(0,0,r);for(let ue=0;ue<te;++ue)Y[ue]=t[R+ue];if(E){let ue=0;for(let Ce=0;Ce<te;++Ce)ue+=Y[Ce];let Be=ue/te;for(let Ce=0;Ce<te;++Ce)Y[Ce]-=Be}if(u!==null){for(let ue=te-1;ue>=1;--ue)Y[ue]-=u*Y[ue-1];Y[0]*=1-u}for(let ue=0;ue<e.length;++ue)Y[ue]*=e[ue];K.realTransform(B,Y);for(let ue=0;ue<X;++ue){let Be=ue<<1;P[ue*Q+L]=B[Be]**2+B[Be+1]**2}}if(o!==null&&o!==2){let L=o/2;for(let R=0;R<P.length;++R)P[R]**=L}let se=f.length,ie=await IE(new U("float32",f.flat(),[se,X]),new U("float32",P,[X,Q]));z&&(ie=ie.transpose(1,0));let S=ie.data;for(let L=0;L<S.length;++L)S[L]=C+Math.max(m,S[L]);if(o!==null&&_!==null){let L=Math.min(S.length,V*se);switch(_){case"log":for(let R=0;R<L;++R)S[R]=Math.log(S[R]);break;case"log10":for(let R=0;R<L;++R)S[R]=Math.log10(S[R]);break;case"dB":if(o===1)pP(S,w,x,k);else if(o===2)dP(S,w,x,k);else throw new Error(`Cannot use log_mel option '${_}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${_}'`)}}return ie}function Mt(t,e,{periodic:r=!0,frame_length:s=null,center:n=!0}={}){let o=r?t+1:t,a;switch(e){case"boxcar":a=new Float64Array(o).fill(1);break;case"hann":case"hann_window":a=BE(o);break;case"hamming":a=oP(o);break;case"povey":a=BE(o).map(i=>Math.pow(i,.85));break;default:throw new Error(`Unknown window type ${e}.`)}if(r&&(a=a.subarray(0,t)),s===null)return a;if(t>s)throw new Error(`Length of the window (${t}) may not be larger than frame_length (${s})`);return a}function fP(t,e){let r=t.reduce((o,a)=>o+a.length,0),s=new ArrayBuffer(44),n=new DataView(s);return cl(n,0,"RIFF"),n.setUint32(4,36+r*4,!0),cl(n,8,"WAVE"),cl(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,3,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*4,!0),n.setUint16(32,4,!0),n.setUint16(34,32,!0),cl(n,36,"data"),n.setUint32(40,r*4,!0),new Blob([s,...t.map(o=>o.buffer)],{type:"audio/wav"})}function cl(t,e,r){for(let s=0;s<r.length;++s)t.setUint8(e+s,r.charCodeAt(s))}var to=class{constructor(e,r){this.audio=e,this.sampling_rate=r}get data(){if(Array.isArray(this.audio)){if(this.audio.length===0)return new Float32Array(0);if(this.audio.length===1)return this.audio[0];let e=this.audio.reduce((n,o)=>n+o.length,0),r=new Float32Array(e),s=0;for(let n of this.audio)r.set(n,s),s+=n.length;return r}else return this.audio}toBlob(){let e=this.audio;return e instanceof Float32Array&&(e=[e]),fP(e,this.sampling_rate)}async save(e){return ll(e,this.toBlob())}};var yf=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,r){return At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:r,transpose:!0})}async _call(e){He(e,"ASTFeatureExtractor");let r=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){let s=this.std*2,n=r.data;for(let o=0;o<n.length;++o)n[o]=(n[o]-this.mean)/s}return{input_values:r.unsqueeze_(0)}}};var ro=class extends Ne{async _call(e){He(e,"EncodecFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=this.config.feature_size;if(e.length%r!==0)throw new Error(`The length of the audio data must be a multiple of the number of channels (${r}).`);let s=[1,r,e.length/r];return{input_values:new U("float32",e,s)}}};var bf=class extends Ne{async _call(e){He(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,e.length];return{input_values:new U("float32",e,r)}}};var vf=class extends Ne{constructor(e){super(e),this.mel_filters=yt(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=yt(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=Mt(this.config.fft_window_size,"hann")}async _get_input_mel(e,r,s,n){let o,a=!1,i=e.length-r;if(i>0)if(s==="rand_trunc"){a=!0;let l=Math.floor(Math.random()*(i+1));e=e.subarray(l,l+r),o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}else throw new Error(`Truncation strategy "${s}" not implemented`);else{if(i<0){let l=new Float64Array(r);if(l.set(e),n==="repeat")for(let u=e.length;u<r;u+=e.length)l.set(e.subarray(0,Math.min(e.length,r-u)),u);else if(n==="repeatpad")for(let u=e.length;u<-i;u+=e.length)l.set(e,u);e=l}if(s==="fusion")throw new Error(`Truncation strategy "${s}" not implemented`);o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return o.unsqueeze_(0)}async _extract_fbank_features(e,r,s=null){return At(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:r,log_mel:"dB",max_num_frames:s,do_pad:!1,transpose:!0})}async _call(e,{max_length:r=null}={}){return He(e,"ClapFeatureExtractor"),{input_features:(await this._get_input_mel(e,r??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}};var so=class extends ro{};var kf=class extends Ne{constructor(e){super(e);let{fft_length:r,feature_size:s,min_frequency:n,max_frequency:o,sampling_rate:a,frame_length:i}=this.config,l=yt(Math.floor(1+r/2),s,n,o,a,null,"htk",!1);this.mel_filters=l,this.window=Mt(i,"hann")}async _extract_fbank_features(e,r){return At(e,this.window,this.config.frame_length,this.config.hop_length,{fft_length:this.config.fft_length,center:!1,onesided:!0,preemphasis:this.config.preemphasis,preemphasis_htk_flavor:this.config.preemphasis_htk_flavor,mel_filters:this.mel_filters,log_mel:"log",mel_floor:this.config.mel_floor,remove_dc_offset:!1,transpose:!0})}async _call(e,{max_length:r=48e4,truncation:s=!0,padding:n=!0,pad_to_multiple_of:o=128}={}){if(He(e,"Gemma3nAudioFeatureExtractor"),s&&e.length>r&&(e=e.slice(0,r)),n&&e.length%o!==0){let l=o-e.length%o,u=new Float64Array(e.length+l);u.set(e),this.config.padding_value!==0&&u.fill(this.config.padding_value,e.length),e=u}let a=await this._extract_fbank_features(e,this.config.max_length),i=Ve([1,a.dims[0]],!0);return{input_features:a.unsqueeze_(0),input_features_mask:i}}};var Ef=class extends Ne{async _call(e){He(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,e.length];return{input_values:new U("float32",e,r)}}};var mP=1e-5,Af=class extends Ne{constructor(e){super(e),this.config.mel_filters??=yt(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,"slaney","slaney");let r=Mt(this.config.win_length,"hann",{periodic:!1});this.window=new Float64Array(this.config.n_fft);let s=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(r,s)}async _extract_fbank_features(e){let r=this.config.preemphasis;e=new Float64Array(e);for(let n=e.length-1;n>=1;--n)e[n]-=r*e[n-1];return await At(e,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:"log",mel_floor:-1/0,pad_mode:"constant",center:!0,transpose:!0,mel_offset:2**-24})}async _call(e){He(e,"ParakeetFeatureExtractor");let r=await this._extract_fbank_features(e),s=Math.floor((e.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),n=r.data;n.fill(0,s*r.dims[1]);let[o,a]=r.dims,i=new Float64Array(a),l=new Float64Array(a);for(let f=0;f<s;++f){let m=f*a;for(let _=0;_<a;++_){let w=n[m+_];i[_]+=w,l[_]+=w*w}}let u=s>1?s-1:1;for(let f=0;f<a;++f){let m=i[f]/s,_=(l[f]-s*m*m)/u,x=1/(Math.sqrt(_)+mP);for(let k=0;k<s;++k){let E=k*a+f;n[E]=(n[E]-m)*x}}let d=new BigInt64Array(o);return d.fill(1n,0,s),{input_features:r.unsqueeze_(0),attention_mask:new U("int64",d,[1,o])}}};var no=class extends Ne{async _call(e){He(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,1,e.length];return{input_values:new U("float32",e,r)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,r){let s=r/this.samples_to_frames(r)/this.config.sampling_rate,n=[];for(let o of e.tolist()){let a=[],i=-1;for(let l=0;l<o.length;++l){let u=Pe(o[l]),[d,f]=Te(u),[m,_]=[l,l+1];f!==i?(i=f,a.push({id:f,start:m,end:_,score:d})):(a.at(-1).end=_,a.at(-1).score+=d)}n.push(a.map(({id:l,start:u,end:d,score:f})=>({id:l,start:u*s,end:d*s,confidence:f/(d-u)})))}return n}};var Mf=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"povey",{periodic:!1})}async _extract_fbank_features(e,r){return e=e.map(s=>s*32768),At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:r,transpose:!0})}async _call(e,{padding:r=!0,pad_to_multiple_of:s=2,do_normalize_per_mel_bins:n=!0,return_attention_mask:o=!0}={}){He(e,"SeamlessM4TFeatureExtractor");let a=await this._extract_fbank_features(e,this.config.max_length);if(n){let[w,x]=a.dims,k=a.data;for(let E=0;E<x;++E){let M=0;for(let C=0;C<w;++C)M+=k[C*x+E];let I=M/w,T=0;for(let C=0;C<w;++C)T+=(k[C*x+E]-I)**2;T/=w-1;let z=Math.sqrt(T+1e-7);for(let C=0;C<w;++C){let v=C*x+E;k[v]=(k[v]-I)/z}}}let i;if(r){let[w,x]=a.dims,k=a.data,E=w%s;if(E>0){let M=new Float32Array(x*(w+E));M.set(k),M.fill(this.config.padding_value,k.length);let I=w+E;a=new U(a.type,M,[I,x]),o&&(i=new U("int64",new BigInt64Array(I),[1,I]),i.data.fill(1n,0,w))}}let[l,u]=a.dims,d=this.config.stride;if(l%d!==0)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${d}).`);let m=a.view(1,Math.floor(l/d),u*d),_={input_features:m};if(o){let w=m.dims[1],x=new BigInt64Array(w);if(i){let k=i.data;for(let E=1,M=0;E<l;E+=d,++M)x[M]=k[E]}else x.fill(1n);_.attention_mask=new U("int64",x,[1,w])}return _}};var Tf=class extends so{};var Sf=class extends Ne{};var Of=class extends Ne{_zero_mean_unit_var_norm(e){let s=e.reduce((o,a)=>o+a,0)/e.length,n=e.reduce((o,a)=>o+(a-s)**2,0)/e.length;return e.map(o=>(o-s)/Math.sqrt(n+1e-7))}async _call(e){He(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=e;this.config.do_normalize&&(r=this._zero_mean_unit_var_norm(r));let s=[1,r.length];return{input_values:new U("float32",r,s),attention_mask:new U("int64",new BigInt64Array(r.length).fill(1n),s)}}};var If=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map(r=>r*32768),At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){He(e,"WeSpeakerFeatureExtractor");let r=(await this._extract_fbank_features(e)).unsqueeze_(0);if(this.config.fbank_centering_span===null){let s=r.mean(1).data,n=r.data,[o,a,i]=r.dims;for(let l=0;l<o;++l){let u=l*a*i,d=l*i;for(let f=0;f<a;++f){let m=u+f*i;for(let _=0;_<i;++_)n[m+_]-=s[d+_]}}}return{input_features:r}}};var Cf=class extends Ne{constructor(e){super(e),this.config.mel_filters??=yt(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Mt(this.config.n_fft,"hann")}async _extract_fbank_features(e){let r=await At(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)}),s=r.data,n=Te(s)[0];for(let o=0;o<s.length;++o)s[o]=(Math.max(s[o],n-8)+4)/4;return r}async _call(e,{max_length:r=null}={}){He(e,"WhisperFeatureExtractor");let s,n=r??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),s=e.slice(0,n)):(s=new Float32Array(n),s.set(e)),{input_features:(await this._extract_fbank_features(s)).unsqueeze_(0)}}};var tt=class{static async from_pretrained(e,r={}){let s=await at(e,eo,!0,r),n=s.feature_extractor_type,o=oo[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${Hs}.`);return new o(s)}};var Pf=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e,r=null){let s=this.tokenizer(e),n=r?await this.feature_extractor(r):{};return{...s,...n}}};import zf from"sharp";var fs,GE,Or,Qt=be.IS_BROWSER_ENV||be.IS_WEBWORKER_ENV;if(Qt)fs=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(t,e)},Or=self.createImageBitmap,GE=self.ImageData;else if(zf)Or=async t=>{let r=(await t.metadata()).channels,{data:s,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new Xe(new Uint8ClampedArray(s),n.width,n.height,n.channels);return r!==void 0&&r!==n.channels&&o.convert(r),o};else throw new Error("Unable to load image processing library.");var hP={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},_P=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),Xe=class t{constructor(e,r,s,n){this.data=e,this.width=r,this.height=s,this.channels=n}get size(){return[this.width,this.height]}static async read(e){if(e instanceof t)return e;if(typeof e=="string"||e instanceof URL)return await this.fromURL(e);if(e instanceof Blob)return await this.fromBlob(e);if(typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)return this.fromCanvas(e);throw new Error(`Unsupported input type: ${typeof e}`)}static fromCanvas(e){if(!Qt)throw new Error("fromCanvas() is only supported in browser environments.");let s=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new t(s,e.width,e.height,4)}static async fromURL(e){let r=await Bs(e);if(r.status!==200)throw new Error(`Unable to read image from "${e}" (${r.status} ${r.statusText})`);let s=await r.blob();return this.fromBlob(s)}static async fromBlob(e){if(Qt){let r=await Or(e),s=fs(r.width,r.height).getContext("2d");return s.drawImage(r,0,0),new this(s.getImageData(0,0,r.width,r.height).data,r.width,r.height,4)}else{let r=zf(await e.arrayBuffer());return await Or(r)}}static fromTensor(e,r="CHW"){if(e.dims.length!==3)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(r==="CHW")e=e.transpose(1,2,0);else if(r!=="HWC")throw new Error(`Unsupported channel format: ${r}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new t(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let r=0,s=0;r<this.data.length;r+=this.channels){let n=this.data[r],o=this.data[r+1],a=this.data[r+2];e[s++]=Math.round(.2989*n+.587*o+.114*a)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(this.channels===3)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let r=0,s=0;r<this.data.length;++r)e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=this.data[r];break;case 4:for(let r=0,s=0;r<this.data.length;r+=4)e[s++]=this.data[r],e[s++]=this.data[r+1],e[s++]=this.data[r+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(this.channels===4)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let r=0,s=0;r<this.data.length;++r)e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=255;break;case 3:for(let r=0,s=0;r<this.data.length;r+=3)e[s++]=this.data[r],e[s++]=this.data[r+1],e[s++]=this.data[r+2],e[s++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}putAlpha(e){if(e.width!==this.width||e.height!==this.height)throw new Error(`Expected mask size to be ${this.width}x${this.height}, but got ${e.width}x${e.height}`);if(e.channels!==1)throw new Error(`Expected mask to have 1 channel, but got ${e.channels}`);let r=this.data,s=e.data,n=this.width*this.height;if(this.channels===3){let o=new Uint8ClampedArray(n*4);for(let a=0,i=0,l=0;a<n;++a)o[l++]=r[i++],o[l++]=r[i++],o[l++]=r[i++],o[l++]=s[a];return this._update(o,this.width,this.height,4)}else if(this.channels===4){for(let o=0;o<n;++o)r[4*o+3]=s[o];return this}throw new Error(`Expected image to have 3 or 4 channels, but got ${this.channels}`)}async resize(e,r,{resample:s=2}={}){if(this.width===e&&this.height===r)return this;let n=hP[s]??s,o=gp(e),a=gp(r);if(o&&a)return this;if(o?e=r/this.height*this.width:a&&(r=e/this.width*this.height),Qt){let i=this.channels,l=this.toCanvas(),u=fs(e,r).getContext("2d");return u.drawImage(l,0,0,e,r),new t(u.getImageData(0,0,e,r).data,e,r,4).convert(i)}else{let i=this.toSharp();switch(n){case"box":case"hamming":(n==="box"||n==="hamming")&&(console.warn(`Resampling method ${n} is not yet supported. Using bilinear instead.`),n="bilinear");case"nearest":case"bilinear":case"bicubic":i=i.affine([e/this.width,0,0,r/this.height],{interpolator:n});break;case"lanczos":i=i.resize({width:e,height:r,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${n} is not supported.`)}return await Or(i)}}async pad([e,r,s,n]){if(e=Math.max(e,0),r=Math.max(r,0),s=Math.max(s,0),n=Math.max(n,0),e===0&&r===0&&s===0&&n===0)return this;if(Qt){let o=this.channels,a=this.toCanvas(),i=this.width+e+r,l=this.height+s+n,u=fs(i,l).getContext("2d");return u.drawImage(a,0,0,this.width,this.height,e,s,this.width,this.height),new t(u.getImageData(0,0,i,l).data,i,l,4).convert(o)}else{let o=this.toSharp().extend({left:e,right:r,top:s,bottom:n});return await Or(o)}}async crop([e,r,s,n]){if(e=Math.max(e,0),r=Math.max(r,0),s=Math.min(s,this.width-1),n=Math.min(n,this.height-1),e===0&&r===0&&s===this.width-1&&n===this.height-1)return this;let o=s-e+1,a=n-r+1;if(Qt){let i=this.channels,l=this.toCanvas(),u=fs(o,a).getContext("2d");return u.drawImage(l,e,r,o,a,0,0,o,a),new t(u.getImageData(0,0,o,a).data,o,a,4).convert(i)}else{let i=this.toSharp().extract({left:e,top:r,width:o,height:a});return await Or(i)}}async center_crop(e,r){if(this.width===e&&this.height===r)return this;let s=(this.width-e)/2,n=(this.height-r)/2;if(Qt){let o=this.channels,a=this.toCanvas(),i=fs(e,r).getContext("2d"),l=0,u=0,d=0,f=0;return s>=0?l=s:d=-s,n>=0?u=n:f=-n,i.drawImage(a,l,u,e,r,d,f,e,r),new t(i.getImageData(0,0,e,r).data,e,r,4).convert(o)}else{let o=this.toSharp();if(s>=0&&n>=0)o=o.extract({left:Math.floor(s),top:Math.floor(n),width:e,height:r});else if(s<=0&&n<=0){let a=Math.floor(-n),i=Math.floor(-s);o=o.extend({top:a,left:i,right:e-this.width-i,bottom:r-this.height-a})}else{let a=[0,0],i=0;n<0?(a[0]=Math.floor(-n),a[1]=r-this.height-a[0]):i=Math.floor(n);let l=[0,0],u=0;s<0?(l[0]=Math.floor(-s),l[1]=e-this.width-l[0]):u=Math.floor(s),o=o.extend({top:a[0],bottom:a[1],left:l[0],right:l[1]}).extract({left:u,top:i,width:e,height:r})}return await Or(o)}}async toBlob(e="image/png",r=1){if(!Qt)throw new Error("toBlob() is only supported in browser environments.");return await this.toCanvas().convertToBlob({type:e,quality:r})}toTensor(e="CHW"){let r=new U("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if(e!=="HWC")if(e==="CHW")r=r.permute(2,0,1);else throw new Error(`Unsupported channel format: ${e}`);return r}toCanvas(){if(!Qt)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),r=fs(e.width,e.height),s=new GE(e.data,e.width,e.height);return r.getContext("2d").putImageData(s,0,0),r}split(){let{data:e,width:r,height:s,channels:n}=this,o=e.constructor,a=e.length/n,i=Array.from({length:n},()=>new o(a));for(let l=0;l<a;++l){let u=n*l;for(let d=0;d<n;++d)i[d][l]=e[u+d]}return i.map(l=>new t(l,r,s,1))}_update(e,r,s,n=null){return this.data=e,this.width=r,this.height=s,n!==null&&(this.channels=n),this}clone(){return new t(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(Qt){if(be.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let r=e.split(".").pop().toLowerCase(),s=_P.get(r)??"image/png",n=await this.toBlob(s);return ll(e,n)}else if(be.IS_FS_AVAILABLE)await this.toSharp().toFile(e);else throw new Error("Unable to save the image because filesystem is disabled in this environment.")}toSharp(){if(Qt)throw new Error("toSharp() is only supported in server-side environments.");return zf(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},gP=Xe.read.bind(Xe);function qE(t,e,r=0,s=null){let n=t/e,o=Hv(n)*e;return s!==null&&o>s&&(o=Math.floor(n)*e),o<r&&(o=Math.ceil(n)*e),o}function Lf([t,e],r){return[Math.max(Math.floor(t/r),1)*r,Math.max(Math.floor(e/r),1)*r]}function Nf([t,e,r,s]){return[t-r/2,e-s/2,t+r/2,e+s/2]}function Ir(t,e=.5,r=null,s=!1){let n=t.logits,o=t.pred_boxes,[a,i,l]=n.dims;if(r!==null&&r.length!==a)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let u=[];for(let d=0;d<a;++d){let f=r!==null?r[d]:null,m={boxes:[],classes:[],scores:[]},_=n[d],w=o[d];for(let x=0;x<i;++x){let k=_[x],E=[],M;if(s){M=k.sigmoid().data;for(let I=0;I<M.length;++I)M[I]>e&&E.push(I)}else{let I=Te(k.data)[1];if(I===l-1||(M=Pe(k.data),M[I]<e))continue;E.push(I)}for(let I of E){let T=w[x].data;T=Nf(T),f!==null&&(T=T.map((z,C)=>z*f[(C+1)%2])),m.boxes.push(T),m.classes.push(I),m.scores.push(M[I])}}u.push(m)}return u}function ul(t,e=null){let r=t.logits,s=r.dims[0];if(e!==null&&e.length!==s)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let n=[];for(let o=0;o<s;++o){let a=e!==null?e[o]:null,i=r[o];a!==null&&(i=xd(i,a,"bilinear",!1));let[l,u]=a??i.dims.slice(-2),d=new U("int32",new Int32Array(l*u),[l,u]),f=i[0].data,m=d.data;for(let x=1;x<i.dims[0];++x){let k=i[x].data;for(let E=0;E<k.length;++E)k[E]>f[E]&&(f[E]=k[E],m[E]=x)}let _=new Array(i.dims[0]);for(let x=0;x<m.length;++x){let k=m[x];_[k]=k}let w=_.filter(x=>x!==void 0);n.push({segmentation:d,labels:w})}return n}function wP(t,e,r,s){let n=[],o=[],a=[];for(let i=0;i<t.dims[0];++i){let l=t[i],u=e[i],d=Te(l.data)[1];if(d===s)continue;let m=Pe(l.data)[d];m>r&&(n.push(u),o.push(m),a.push(d))}return[n,o,a]}function xP(t,e,r,s=.5,n=.8){let o=[],a=0,i=0,l=e[r].data;for(let d=0;d<t.length;++d)t[d]===r&&(o.push(d),++a),l[d]>=s&&++i;let u=a>0&&i>0;return u&&(u=a/i>n),[u,o]}function yP(t,e,r,s,n,o=null,a=null){let[i,l]=a??t[0].dims,u=new U("int32",new Int32Array(i*l),[i,l]),d=[];if(a!==null)for(let x=0;x<t.length;++x)t[x]=xd(t[x],a,"bilinear",!1);let f=new Int32Array(t[0].data.length),m=new Float32Array(t[0].data.length);for(let x=0;x<t.length;++x){let k=e[x],E=t[x].data;for(let M=0;M<E.length;++M)E[M]*=k,E[M]>m[M]&&(f[M]=x,m[M]=E[M])}let _=0,w=u.data;for(let x=0;x<r.length;++x){let k=r[x],[E,M]=xP(f,t,x,s,n);if(E){++_;for(let I of M)w[I]=_;d.push({id:_,label_id:k,score:e[x]})}}return[u,d]}function bP(t,e,r=28,s=3136,n=784*1280){if(t<r||e<r)throw new Error(`height:${t} or width:${e} must be larger than factor:${r}`);if(Math.max(t,e)/Math.min(t,e)>200)throw new Error(`absolute aspect ratio must be smaller than 200, got ${Math.max(t,e)/Math.min(t,e)}`);let o=Math.round(t/r)*r,a=Math.round(e/r)*r;if(o*a>n){let i=Math.sqrt(t*e/n);o=Math.floor(t/i/r)*r,a=Math.floor(e/i/r)*r}else if(o*a<s){let i=Math.sqrt(s/(t*e));o=Math.ceil(t*i/r)*r,a=Math.ceil(e*i/r)*r}return[o,a]}function pl(t,e=.5,r=.5,s=.8,n=null,o=null){n===null&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);let a=t.class_queries_logits??t.logits,l=(t.masks_queries_logits??t.pred_masks).sigmoid(),[u,d,f]=a.dims;if(f-=1,o!==null&&o.length!==u)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let m=[];for(let _=0;_<u;++_){let w=o!==null?o[_]:null,x=a[_],k=l[_],[E,M,I]=wP(x,k,e,f);if(I.length===0){let[C,v]=w??k.dims.slice(-2),G=new U("int32",new Int32Array(C*v).fill(-1),[C,v]);m.push({segmentation:G,segments_info:[]});continue}let[T,z]=yP(E,M,I,r,s,n,w);m.push({segmentation:T,segments_info:z})}return m}function dl(t,e=.5,r=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var W=class extends Je{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??this.size!==void 0,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&this.size.width!==void 0&&this.size.height!==void 0&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,r,s=2){let n=e.height,o=e.width,a=r.height,i=r.width,l=Math.min(n,a),u=Math.min(o,i);return l===n&&u===o?e:(n>o?u=Math.floor(o*l/n):o>n&&(l=Math.floor(n*u/o)),await e.resize(u,l,{resample:s}))}async crop_margin(e,r=200){let s=e.clone().grayscale(),n=Dn(s.data)[0],a=Te(s.data)[0]-n;if(a===0)return e;let i=r/255,l=s.width,u=s.height,d=0,f=0,m=s.data;for(let _=0;_<s.height;++_){let w=_*s.width;for(let x=0;x<s.width;++x)(m[w+x]-n)/a<i&&(l=Math.min(l,x),u=Math.min(u,_),d=Math.max(d,x),f=Math.max(f,_))}return e=await e.crop([l,u,d,f]),e}pad_image(e,r,s,{mode:n="constant",center:o=!1,constant_values:a=0}={}){let[i,l,u]=r,d,f;if(typeof s=="number"?(d=s,f=s):s==="square"?d=f=Math.max(i,l):(d=s.width,f=s.height),d!==l||f!==i){let m=new Float32Array(d*f*u);if(Array.isArray(a))for(let x=0;x<m.length;++x)m[x]=a[x%u];else a!==0&&m.fill(a);let[_,w]=o?[Math.floor((d-l)/2),Math.floor((f-i)/2)]:[0,0];for(let x=0;x<i;++x){let k=(x+w)*d,E=x*l;for(let M=0;M<l;++M){let I=(k+M+_)*u,T=(E+M)*u;for(let z=0;z<u;++z)m[I+z]=e[T+z]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let x=i-1,k=l-1;for(let E=0;E<f;++E){let M=E*d,I=$s(E,x)*l;for(let T=0;T<d;++T){if(E<i&&T<l)continue;let z=(M+T)*u,C=(I+$s(T,k))*u;for(let v=0;v<u;++v)m[z+v]=e[C+v]}}}e=m,r=[f,d,u]}return[e,r]}rescale(e){for(let r=0;r<e.length;++r)e[r]=this.rescale_factor*e[r]}get_resize_output_image_size(e,r){let[s,n]=e.size,o,a;if(this.do_thumbnail){let{height:i,width:l}=r;o=Math.min(i,l)}else Number.isInteger(r)?(o=r,a=this.config.max_size??o):r!==void 0&&(o=r.shortest_edge,a=r.longest_edge);if(o!==void 0||a!==void 0){let i=o===void 0?1:Math.max(o/s,o/n),l=s*i,u=n*i,d=a===void 0?1:Math.min(a/l,a/u),f=Math.floor(Number((l*d).toFixed(2))),m=Math.floor(Number((u*d).toFixed(2)));return this.size_divisibility!==void 0&&([f,m]=Lf([f,m],this.size_divisibility)),[f,m]}else if(r!==void 0&&r.width!==void 0&&r.height!==void 0){let i=r.width,l=r.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let u=l/n,d=i/s;Math.abs(1-d)<Math.abs(1-u)?u=d:d=u,l=qE(u*n,this.config.ensure_multiple_of),i=qE(d*s,this.config.ensure_multiple_of)}return[i,l]}else{if(this.size_divisibility!==void 0)return Lf([s,n],this.size_divisibility);if(this.min_pixels!==void 0&&this.max_pixels!==void 0){let i=this.config.patch_size*this.config.merge_size;return bP(n,s,i,this.min_pixels,this.max_pixels)}else throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(r)}`)}}async resize(e){let[r,s]=this.get_resize_output_image_size(e,this.size);return await e.resize(r,s,{resample:this.resample})}async preprocess(e,{do_normalize:r=null,do_pad:s=null,do_convert_rgb:n=null,do_convert_grayscale:o=null,do_flip_channel_order:a=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));let[i,l]=e.size;if(n??this.do_convert_rgb?e=e.rgb():o&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let _,w;Number.isInteger(this.crop_size)?(_=this.crop_size,w=this.crop_size):(_=this.crop_size.width,w=this.crop_size.height),e=await e.center_crop(_,w)}let u=[e.height,e.width],d=Float32Array.from(e.data),f=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(d),r??this.do_normalize){let _=this.image_mean;Array.isArray(this.image_mean)||(_=new Array(e.channels).fill(_));let w=this.image_std;if(Array.isArray(this.image_std)||(w=new Array(e.channels).fill(w)),_.length!==e.channels||w.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${_.length}) and \`image_std\` (${w.length}) must match the number of channels in the image (${e.channels}).`);for(let x=0;x<d.length;x+=e.channels)for(let k=0;k<e.channels;++k)d[x+k]=(d[x+k]-_[k])/w[k]}if(s??this.do_pad){if(this.pad_size)[d,f]=this.pad_image(d,[e.height,e.width,e.channels],this.pad_size);else if(this.size_divisibility){let[_,w]=Lf([f[1],f[0]],this.size_divisibility);[d,f]=this.pad_image(d,f,{width:_,height:w})}}if(a??this.do_flip_channel_order){if(f[2]!==3)throw new Error("Flipping channel order is only supported for RGB images.");for(let _=0;_<d.length;_+=3){let w=d[_];d[_]=d[_+2],d[_+2]=w}}let m=new U("float32",d,f).permute(2,0,1);return{original_size:[l,i],reshaped_input_size:u,pixel_values:m}}async _call(e,...r){Array.isArray(e)||(e=[e]);let s=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:Ft(s.map(o=>o.pixel_values),0),original_sizes:s.map(o=>o.original_size),reshaped_input_sizes:s.map(o=>o.reshaped_input_size)}}static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r);return new this(s)}};var Zs={};Ps(Zs,{BeitFeatureExtractor:()=>$f,BitImageProcessor:()=>Rf,CLIPFeatureExtractor:()=>Bf,CLIPImageProcessor:()=>fl,ChineseCLIPFeatureExtractor:()=>Uf,ConvNextFeatureExtractor:()=>Df,ConvNextImageProcessor:()=>ml,DINOv3ViTImageProcessor:()=>Gf,DPTFeatureExtractor:()=>Wf,DPTImageProcessor:()=>gl,DeiTFeatureExtractor:()=>Ff,DeiTImageProcessor:()=>hl,DetrFeatureExtractor:()=>jf,DetrImageProcessor:()=>_l,DonutFeatureExtractor:()=>qf,DonutImageProcessor:()=>Ks,EfficientNetImageProcessor:()=>Vf,GLPNFeatureExtractor:()=>Hf,GroundingDinoImageProcessor:()=>Xf,Idefics3ImageProcessor:()=>wl,ImageFeatureExtractor:()=>W,ImageProcessor:()=>W,JinaCLIPImageProcessor:()=>Yf,LlavaOnevisionImageProcessor:()=>Qf,Mask2FormerImageProcessor:()=>Zf,MaskFormerFeatureExtractor:()=>Jf,MaskFormerImageProcessor:()=>Ys,MobileNetV1FeatureExtractor:()=>em,MobileNetV1ImageProcessor:()=>xl,MobileNetV2FeatureExtractor:()=>tm,MobileNetV2ImageProcessor:()=>yl,MobileNetV3FeatureExtractor:()=>rm,MobileNetV3ImageProcessor:()=>bl,MobileNetV4FeatureExtractor:()=>sm,MobileNetV4ImageProcessor:()=>vl,MobileViTFeatureExtractor:()=>nm,MobileViTImageProcessor:()=>kl,NougatImageProcessor:()=>om,OwlViTFeatureExtractor:()=>am,OwlViTImageProcessor:()=>Qs,Owlv2ImageProcessor:()=>im,Phi3VImageProcessor:()=>um,PixtralImageProcessor:()=>pm,PvtImageProcessor:()=>dm,Qwen2VLImageProcessor:()=>fm,RTDetrImageProcessor:()=>mm,Sam2ImageProcessor:()=>ao,Sam3ImageProcessor:()=>ao,SamImageProcessor:()=>ao,SapiensFeatureExtractor:()=>hm,SapiensImageProcessor:()=>El,SegformerFeatureExtractor:()=>_m,SegformerImageProcessor:()=>Al,SiglipImageProcessor:()=>gm,SmolVLMImageProcessor:()=>wl,Swin2SRImageProcessor:()=>wm,VLMImageProcessor:()=>Kf,ViTFeatureExtractor:()=>xm,ViTImageProcessor:()=>Ml,VitMatteImageProcessor:()=>ym,VitPoseImageProcessor:()=>bm,YolosFeatureExtractor:()=>vm,YolosImageProcessor:()=>Tl});var $f=class extends W{};var Rf=class extends W{};var Uf=class extends W{};var fl=class extends W{},Bf=class extends fl{};var ml=class extends W{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){let r=this.size?.shortest_edge;if(r===void 0)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(r<384){let s=Math.floor(r/this.crop_pct),[n,o]=this.get_resize_output_image_size(e,{shortest_edge:s});e=await e.resize(n,o,{resample:this.resample}),e=await e.center_crop(r,r)}else e=await e.resize(r,r,{resample:this.resample});return e}},Df=class extends ml{};var hl=class extends W{},Ff=class extends hl{};var _l=class extends W{async _call(e){let r=await super._call(e),s=[r.pixel_values.dims[0],64,64],n=Ve(s,1n);return{...r,pixel_mask:n}}post_process_object_detection(...e){return Ir(...e)}post_process_panoptic_segmentation(...e){return pl(...e)}post_process_instance_segmentation(...e){return dl(...e)}},jf=class extends _l{};var Gf=class extends W{};var Ks=class extends W{pad_image(e,r,s,n={}){let[o,a,i]=r,l=this.image_mean;Array.isArray(this.image_mean)||(l=new Array(i).fill(l));let u=this.image_std;Array.isArray(u)||(u=new Array(i).fill(l));let d=l.map((f,m)=>-f/u[m]);return super.pad_image(e,r,s,{center:!0,constant_values:d,...n})}},qf=class extends Ks{};var gl=class extends W{},Wf=class extends gl{};var Vf=class extends W{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map(r=>r*r))}};var Hf=class extends W{};var Xf=class extends W{async _call(e){let r=await super._call(e),s=r.pixel_values.dims,n=it([s[0],s[2],s[3]]);return{...r,pixel_mask:n}}};var wl=class extends W{constructor(e){super(e),this.do_image_splitting=e.do_image_splitting??!0,this.max_image_size=e.max_image_size}get_resize_for_vision_encoder(e,r){let[s,n]=e.dims.slice(-2),o=n/s;return n>=s?(n=Math.ceil(n/r)*r,s=Math.floor(n/o),s=Math.ceil(s/r)*r):(s=Math.ceil(s/r)*r,n=Math.floor(s*o),n=Math.ceil(n/r)*r),{height:s,width:n}}async _call(e,{do_image_splitting:r=null,return_row_col_info:s=!1}={}){let n;if(!Array.isArray(e))n=[[e]];else{if(e.length===0||!e[0])throw new Error("No images provided.");Array.isArray(e[0])?n=e:n=[e]}let o=[],a=[],i=[],l=[],u=[];for(let E of n){let M=await Promise.all(E.map(z=>this.preprocess(z)));l.push(...M.map(z=>z.original_size)),u.push(...M.map(z=>z.reshaped_input_size)),M.forEach(z=>z.pixel_values.unsqueeze_(0));let{longest_edge:I}=this.max_image_size,T;if(r??this.do_image_splitting){let z=new Array(M.length),C=new Array(M.length);T=await Promise.all(M.map(async(v,G)=>{let X=this.get_resize_for_vision_encoder(v.pixel_values,I),V=await Dt(v.pixel_values,{size:[X.height,X.width]}),{frames:Q,num_splits_h:K,num_splits_w:Y}=await this.split_image(V,this.max_image_size);return z[G]=K,C[G]=Y,Ee(Q,0)})),a.push(z),i.push(C)}else{let z=[I,I];T=await Promise.all(M.map(C=>Dt(C.pixel_values,{size:z}))),a.push(new Array(M.length).fill(0)),i.push(new Array(M.length).fill(0))}o.push(Ee(T,0))}let d=o.length,[f,m,_,w]=o[0].dims,x,k;if(d===1)x=o[0].unsqueeze_(0),k=Ve([d,f,_,w],!0);else{let E=Math.max(...o.map(T=>T.dims.at(0)));k=Ve([d,E,_,w],!0);let M=k.data,I=E*_*w;for(let T=0;T<d;++T){let z=o[T].dims[0];if(z<E){o[T]=Ee([o[T],Ve([E-z,m,_,w],0)],0);let C=T*I+z*_*w,v=(T+1)*I;M.fill(!1,C,v)}}x=Ft(o,0)}return{pixel_values:x,pixel_attention_mask:k,original_sizes:l,reshaped_input_sizes:u,...s?{rows:a,cols:i}:{}}}async split_image(e,{longest_edge:r}){let s=r,n=r,o=[],[a,i]=e.dims.slice(-2),l=0,u=0;if(a>s||i>n){l=Math.ceil(a/s),u=Math.ceil(i/n);let d=Math.ceil(a/l),f=Math.ceil(i/u);for(let w=0;w<l;++w)for(let x=0;x<u;++x){let k,E,M,I;w===l-1?(E=a-d,I=a):(E=w*d,I=(w+1)*d),x===u-1?(k=i-f,M=i):(k=x*f,M=(x+1)*f);let C=await ol(e,[E,k],[I,M],[2,3]);o.push(C)}let m=s,_=n;(a!==m||i!==_)&&(e=await Dt(e,{size:[m,_]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:u}}};var Kf=class extends W{constructor(e){super({do_pad:!0,pad_size:{width:e.image_size,height:e.image_size},...e}),this.constant_values=this.config.background_color.map(r=>r*this.rescale_factor)}pad_image(e,r,s,n){return super.pad_image(e,r,s,{constant_values:this.constant_values,center:!0,...n})}};var Yf=class extends W{constructor(e){let{resize_mode:r,fill_color:s,interpolation:n,size:o,...a}=e,i=r==="squash"?{width:o,height:o}:r==="shortest"?{shortest_edge:o}:{longest_edge:o},l=n==="bicubic"?3:2;super({...a,size:i,resample:l,do_center_crop:!0,crop_size:o,do_normalize:!0})}};var Qf=class extends W{};var Ys=class extends W{post_process_panoptic_segmentation(...e){return pl(...e)}post_process_instance_segmentation(...e){return dl(...e)}},Jf=class extends Ys{};var Zf=class extends Ys{};var xl=class extends W{},em=class extends xl{};var yl=class extends W{},tm=class extends yl{};var bl=class extends W{},rm=class extends bl{};var vl=class extends W{},sm=class extends vl{};var kl=class extends W{},nm=class extends kl{};var om=class extends Ks{};var Qs=class extends W{post_process_object_detection(...e){return Ir(...e)}},am=class extends Qs{};var im=class extends Qs{};var Pt=336,vP=[2,3],{ceil:lm,floor:Js,sqrt:cm}=Math,um=class extends W{constructor(e){super({...e,do_normalize:!0,do_pad:!0,pad_size:"custom",do_convert_rgb:!0,do_resize:!0}),this._num_crops=e.num_crops}calc_num_image_tokens_from_image_size(e,r){let{num_img_tokens:s}=this.config;return Js((Js(r/Pt)*Js(e/Pt)+1)*s+1+(Js(r/Pt)+1)*cm(s))}get_resize_output_image_size(e,r){let s=this._num_crops,[n,o]=e.size,a=n/o,i=1;for(;i*Math.ceil(i/a)<=s;)i+=1;i-=1;let l=Math.floor(i*336),u=Math.floor(l/a);return[l,u]}pad_image(e,r,s,n={}){let[o,a]=r,i=Pt*lm(o/Pt),l=Pt*lm(a/Pt),u=[1,1,1].map((d,f)=>(d-this.image_mean[f])/this.image_std[f]);return super.pad_image(e,r,{width:l,height:i},{center:!0,constant_values:u,...n})}async _call(e,{num_crops:r=null}={}){if(this._num_crops=r??=this.config.num_crops,r<4||cm(r)%1!==0)throw new Error("num_crops must be a square number >= 4");Array.isArray(e)||(e=[e]);let s=e.length,n=await Promise.all(e.map(m=>this.preprocess(m))),o=n.map(m=>m.original_size),a=n.map(m=>m.reshaped_input_size),i=[];for(let{pixel_values:m}of n){m.unsqueeze_(0);let[_,w]=m.dims.slice(-2),x=await Dt(m,{size:[Pt,Pt],mode:"bicubic"});if(r>0){let k=[],E=cm(r),M=Js(w/E),I=Js(_/E);for(let z=0;z<E;++z)for(let C=0;C<E;++C){let v,G,X,V;z===E-1?(G=_-I,V=_):(G=z*I,V=(z+1)*I),C===E-1?(v=w-M,X=w):(v=C*M,X=(C+1)*M);let Y=await ol(m,[G,v],[V,X],vP);k.push(Y)}let T=await Dt(Ee(k,0),{size:[Pt,Pt],mode:"bicubic"});i.push(Ee([x,T],0))}else i.push(x)}let l=Ft(i,0),u=a.map(m=>m.map(_=>Pt*lm(_/Pt))),d=new U("int64",u.flat(),[s,2]),f=u.map(([m,_])=>this.calc_num_image_tokens_from_image_size(_,m));return{pixel_values:l,original_sizes:o,reshaped_input_sizes:a,image_sizes:d,num_img_tokens:f}}};var pm=class extends W{get_resize_output_image_size(e,r){let{longest_edge:s}=r;if(s===void 0)throw new Error("size must contain 'longest_edge'");let[n,o]=e.size,a=Math.max(n,o)/s,i=n,l=o;a>1&&(i=Math.floor(n/a),l=Math.floor(o/a));let{patch_size:u,spatial_merge_size:d}=this.config;if(!d)throw new Error("config must contain 'spatial_merge_size'");let f=u*d,m=Math.floor((i-1)/f)+1,_=Math.floor((l-1)/f)+1;return[m*f,_*f]}};var dm=class extends W{};var fm=class extends W{async _call(e,...r){let{pixel_values:s,original_sizes:n,reshaped_input_sizes:o}=await super._call(e,...r),a=s,{temporal_patch_size:i,merge_size:l,patch_size:u}=this.config;a.dims[0]===1&&(a=Ee(Array.from({length:i},()=>a),0));let d=a.dims[0]/i,f=a.dims[1],m=Math.floor(a.dims[2]/u),_=Math.floor(a.dims[3]/u),w=a.view(d,i,f,Math.floor(m/l),l,u,Math.floor(_/l),l,u).permute(0,3,6,4,7,2,1,5,8).view(d*m*_,f*i*u*u),x=new U("int64",[d,m,_],[1,3]);return{pixel_values:w,image_grid_thw:x,original_sizes:n,reshaped_input_sizes:o}}};var mm=class extends W{post_process_object_detection(...e){return Ir(...e)}};var ao=class extends W{reshape_input_points(e,r,s,n=!1){e=structuredClone(e);let o=wp(e);if(o.length===3)n||(o=[1,...o]),e=[e];else if(o.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let a=0;a<e.length;++a){let[i,l]=r[a],[u,d]=s[a],f=[d/l,u/i];for(let m=0;m<e[a].length;++m)for(let _=0;_<e[a][m].length;++_)for(let w=0;w<e[a][m][_].length;++w)e[a][m][_][w]*=f[w%2]}return new U("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,r){let s=wp(e);if(s.length===2)s=[1,...s],e=[e];else if(s.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(s.some((n,o)=>n!==r.dims[o]))throw Error(`The first ${s.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new U("int64",e.flat(1/0).map(BigInt),s)}async _call(e,{input_points:r=null,input_labels:s=null,input_boxes:n=null}={}){let o=await super._call(e);if(r&&(o.input_points=this.reshape_input_points(r,o.original_sizes,o.reshaped_input_sizes)),s){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(s,o.input_points)}return n&&(o.input_boxes=this.reshape_input_points(n,o.original_sizes,o.reshaped_input_sizes,!0)),o}async post_process_masks(e,r,s,{mask_threshold:n=0,binarize:o=!0,pad_size:a=null}={}){let i=[];a=a??this.pad_size??this.size;let l=[a.height,a.width];for(let u=0;u<r.length;++u){let d=r[u],f=s[u],m=await Dt(e[u],{mode:"bilinear",size:l});if(m=m.slice(null,null,[0,f[0]],[0,f[1]]),m=await Dt(m,{mode:"bilinear",size:d}),o){let _=m.data,w=new Uint8Array(_.length);for(let x=0;x<_.length;++x)_[x]>n&&(w[x]=1);m=new U("bool",w,m.dims)}i.push(m)}return i}generate_crop_boxes(e,r,{crop_n_layers:s=0,overlap_ratio:n=512/1500,points_per_crop:o=32,crop_n_points_downscale_factor:a=1}={}){}};var El=class extends W{post_process_semantic_segmentation(...e){return ul(...e)}},hm=class extends El{};var Al=class extends W{post_process_semantic_segmentation(...e){return ul(...e)}},_m=class extends Al{};var gm=class extends W{};var wm=class extends W{pad_image(e,r,s,n={}){let[o,a,i]=r;return super.pad_image(e,r,{width:a+(s-a%s)%s,height:o+(s-o%s)%s},{mode:"symmetric",center:!1,constant_values:-1,...n})}};var Ml=class extends W{},xm=class extends Ml{};var ym=class extends W{async _call(e,r){Array.isArray(e)||(e=[e]),Array.isArray(r)||(r=[r]);let s=await Promise.all(e.map(a=>this.preprocess(a))),n=await Promise.all(r.map(a=>this.preprocess(a,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:Ft(s.map((a,i)=>Ee([a.pixel_values,n[i].pixel_values],0)),0),original_sizes:s.map(a=>a.original_size),reshaped_input_sizes:s.map(a=>a.reshaped_input_size)}}};var bm=class extends W{post_process_pose_estimation(e,r,{threshold:s=null}={}){let n=e.tolist(),[o,a,i,l]=e.dims,u=[];for(let d=0;d<o;++d){let f=n[d],m=r[d],_=[];for(let w=0;w<m.length;++w){let x=m[w],k=[],E=[],M=[],I=x.at(-2)/l,T=x.at(-1)/i;for(let z=0;z<f.length;++z){let[C,v]=[0,0],G=0,X=-1/0,V=f[z];for(let K=0;K<V.length;++K){let Y=V[K];for(let B=0;B<Y.length;++B){let P=Y[B];G+=P,X=Math.max(X,P),C+=(B+.5)*P,v+=K*P}}if(s!=null&&X<s)continue;let Q=[I*C/G,T*v/G];k.push(Q),M.push(z),E.push(X)}_.push({bbox:x,scores:E,labels:M,keypoints:k})}u.push(_)}return u}};var Tl=class extends W{post_process_object_detection(...e){return Ir(...e)}},vm=class extends Tl{};var $e=class{static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r),n=s.image_processor_type??s.feature_extractor_type,o=Zs[n?.replace(/Fast$/,"")];return o||(n!==void 0&&console.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${Hs}.`),o=W),new o(s)}};var km=class extends ne{static tokenizer_class=J;static image_processor_class=$e;constructor(e,r,s){super(e,r,s);let{tasks_answer_post_processing_type:n,task_prompts_without_inputs:o,task_prompts_with_input:a}=this.image_processor.config;this.tasks_answer_post_processing_type=new Map(Object.entries(n??{})),this.task_prompts_without_inputs=new Map(Object.entries(o??{})),this.task_prompts_with_input=new Map(Object.entries(a??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){typeof e=="string"&&(e=[e]);let r=[];for(let s of e)if(this.task_prompts_without_inputs.has(s))r.push(this.task_prompts_without_inputs.get(s));else{for(let[n,o]of this.task_prompts_with_input)if(s.includes(n)){r.push(o.replaceAll("{input}",s).replaceAll(n,""));break}r.length!==e.length&&r.push(s)}return r}post_process_generation(e,r,s){let n=this.tasks_answer_post_processing_type.get(r)??"pure_text";e=e.replaceAll("<s>","").replaceAll("</s>","");let o;switch(n){case"pure_text":o=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":let a=n==="ocr"?"quad_boxes":"bboxes",i=e.matchAll(this.regexes[a]),l=[],u=[];for(let[d,f,...m]of i)l.push(f?f.trim():l.at(-1)??""),u.push(m.map((_,w)=>(Number(_)+.5)/this.size_per_bin*s[w%2]));o={labels:l,[a]:u};break;default:throw new Error(`Task "${r}" (of type "${n}") not yet implemented.`)}return{[r]:o}}async _call(e,r=null,s={}){if(!e&&!r)throw new Error("Either text or images must be provided");let n=await this.image_processor(e,s),o=r?this.tokenizer(this.construct_prompts(r),s):{};return{...n,...o}}};var Em=class extends ne{static image_processor_class=$e;static feature_extractor_class=tt;static tokenizer_class=J;static uses_processor_config=!0;static uses_chat_template_file=!0;constructor(e,r,s){super(e,r,s),this.audio_seq_length=this.config.audio_seq_length,this.image_seq_length=this.config.image_seq_length;let{audio_token_id:n,boa_token:o,audio_token:a,eoa_token:i,image_token_id:l,boi_token:u,image_token:d,eoi_token:f}=this.tokenizer.config;this.audio_token_id=n,this.boa_token=o,this.audio_token=a;let m=a.repeat(this.audio_seq_length);this.full_audio_sequence=`
14
+ `))[0]=="Error"&&g.shift(),Ib(g);for(var b=3;g[b]&&Mi(g[b])!=c;)++b;for(c=0;c<h&&g[c+b];++c)(v(),B)[p+4*c>>>2>>>0]=Mi(g[c+b]);return c}var tr=c=>{var p=pr(c)+1,h=Ci(p);return ur(c,h,p),h},Yu=[],xt=(c,p)=>{Yu[c>>>=0]=p},rr=[],Si=[],Os=(c,p)=>{Si[c]=new Promise(h=>p.finally(()=>h(c)))},re=c=>{if(c)return Yu[c>>>0]},Oi=(c,p,h)=>{(v(),P)[c>>>2>>>0]=p,(v(),P)[c+4>>>2>>>0]=h},Cb=c=>{var p=(v(),P)[c>>>2>>>0];return c=(v(),P)[c+4>>>2>>>0],Ts(p,c)},dr=c=>{var p=(v(),P)[c>>>2>>>0];return c=(v(),P)[c+4>>>2>>>0],p?Ts(p,c):c===0?"":void 0},fM=c=>{var p=dr(c+4),h=(h=(v(),P)[c+12>>>2>>>0])?re(h):"auto";if(c+=16){var g=re((v(),P)[c+4>>>2>>>0]),b=(v(),P)[c+16>>>2>>>0],A=(v(),P)[c+20>>>2>>>0];if(b){for(var O={},N=0;N<b;++N){var D=A+24*N;O[Cb(D+4)]=(v(),ie)[D+16>>>3>>>0]}b=O}else b=void 0;c={module:g,constants:b,entryPoint:dr(c+8)}}else c=void 0;return{label:p,layout:h,compute:c}},Pb=(c,p)=>{function h(b,A){b=c[b],(v(),B)[p+A>>>2>>>0]=b}function g(b,A){b=c[b],(v(),S)[p+A>>>3>>>0]=BigInt(b)}h("maxTextureDimension1D",4),h("maxTextureDimension2D",8),h("maxTextureDimension3D",12),h("maxTextureArrayLayers",16),h("maxBindGroups",20),h("maxBindGroupsPlusVertexBuffers",24),h("maxBindingsPerBindGroup",28),h("maxDynamicUniformBuffersPerPipelineLayout",32),h("maxDynamicStorageBuffersPerPipelineLayout",36),h("maxSampledTexturesPerShaderStage",40),h("maxSamplersPerShaderStage",44),h("maxStorageBuffersPerShaderStage",48),h("maxStorageTexturesPerShaderStage",52),h("maxUniformBuffersPerShaderStage",56),h("minUniformBufferOffsetAlignment",80),h("minStorageBufferOffsetAlignment",84),g("maxUniformBufferBindingSize",64),g("maxStorageBufferBindingSize",72),h("maxVertexBuffers",88),g("maxBufferSize",96),h("maxVertexAttributes",104),h("maxVertexBufferArrayStride",108),h("maxInterStageShaderVariables",112),h("maxColorAttachments",116),h("maxColorAttachmentBytesPerSample",120),h("maxComputeWorkgroupStorageSize",124),h("maxComputeInvocationsPerWorkgroup",128),h("maxComputeWorkgroupSizeX",132),h("maxComputeWorkgroupSizeY",136),h("maxComputeWorkgroupSizeZ",140),h("maxComputeWorkgroupsPerDimension",144),c.Le!==void 0&&h("maxImmediateSize",148)},mM=[,"validation","out-of-memory","internal"],hM=[,"compatibility","core"],zb={1:"core-features-and-limits",2:"depth-clip-control",3:"depth32float-stencil8",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"timestamp-query",10:"indirect-first-instance",11:"shader-f16",12:"rg11b10ufloat-renderable",13:"bgra8unorm-storage",14:"float32-filterable",15:"float32-blendable",16:"clip-distances",17:"dual-source-blending",18:"subgroups",19:"texture-formats-tier1",20:"texture-formats-tier2",21:"primitive-index",327692:"chromium-experimental-unorm16-texture-formats",327693:"chromium-experimental-snorm16-texture-formats",327732:"chromium-experimental-multi-draw-indirect"},_M=[,"low-power","high-performance"],gM=[,"occlusion","timestamp"],wM={undefined:1,unknown:1,destroyed:2};function xM(c,p,h,g,b,A){p=wt(p),h=wt(h),g>>>=0,b>>>=0,A>>>=0;var O=re(c>>>0);if(c={},A){var N=(v(),P)[A+12>>>2>>>0];if(N){var D=(v(),P)[A+16>>>2>>>0];c.requiredFeatures=Array.from((v(),P).subarray(D>>>2>>>0,D+4*N>>>2>>>0),ee=>zb[ee])}var q=(v(),P)[A+20>>>2>>>0];if(q){let ee=function(Nt,st,Qr=!1){st=q+st,(st=(v(),P)[st>>>2>>>0])==4294967295||Qr&&st==0||(Re[Nt]=st)},lt=function(Nt,st){st=q+st;var Qr=(v(),P)[st>>>2>>>0],VT=(v(),P)[st+4>>>2>>>0];Qr==4294967295&&VT==4294967295||(Re[Nt]=4294967296*(v(),P)[st+4>>>2>>>0]+(v(),P)[st>>>2>>>0])};var fe=ee,me=lt,Re={};ee("maxTextureDimension1D",4),ee("maxTextureDimension2D",8),ee("maxTextureDimension3D",12),ee("maxTextureArrayLayers",16),ee("maxBindGroups",20),ee("maxBindGroupsPlusVertexBuffers",24),ee("maxDynamicUniformBuffersPerPipelineLayout",32),ee("maxDynamicStorageBuffersPerPipelineLayout",36),ee("maxSampledTexturesPerShaderStage",40),ee("maxSamplersPerShaderStage",44),ee("maxStorageBuffersPerShaderStage",48),ee("maxStorageTexturesPerShaderStage",52),ee("maxUniformBuffersPerShaderStage",56),ee("minUniformBufferOffsetAlignment",80),ee("minStorageBufferOffsetAlignment",84),lt("maxUniformBufferBindingSize",64),lt("maxStorageBufferBindingSize",72),ee("maxVertexBuffers",88),lt("maxBufferSize",96),ee("maxVertexAttributes",104),ee("maxVertexBufferArrayStride",108),ee("maxInterStageShaderVariables",112),ee("maxColorAttachments",116),ee("maxColorAttachmentBytesPerSample",120),ee("maxComputeWorkgroupStorageSize",124),ee("maxComputeInvocationsPerWorkgroup",128),ee("maxComputeWorkgroupSizeX",132),ee("maxComputeWorkgroupSizeY",136),ee("maxComputeWorkgroupSizeZ",140),ee("maxComputeWorkgroupsPerDimension",144),ee("maxImmediateSize",148,!0),c.requiredLimits=Re}(N=(v(),P)[A+24>>>2>>>0])&&(N={label:dr(N+4)},c.defaultQueue=N),c.label=dr(A+4)}ge+=1,Os(p,O.requestDevice(c).then(ee=>{--ge,xt(b,ee.queue),xt(g,ee),h&&(ge+=1,Os(h,ee.lost.then(lt=>{--ge,ee.onuncapturederror=()=>{};var Nt=ae(),st=tr(lt.message);tp(h,wM[lt.reason],st),oe(Nt)}))),ee.onuncapturederror=lt=>{var Nt=5;lt.error instanceof GPUValidationError?Nt=2:lt.error instanceof GPUOutOfMemoryError?Nt=3:lt.error instanceof GPUInternalError&&(Nt=4);var st=ae();lt=tr(lt.error.message),e1(g,Nt,lt),oe(st)},"adapterInfo"in ee||(ee.adapterInfo=O.info),np(p,1,g,0)},ee=>{--ge;var lt=ae();ee=tr(ee.message),np(p,3,g,ee),h&&tp(h,4,ee),oe(lt)}))}function yM(c){var p=re(c>>>=0),h=rr[c];if(h){for(var g=0;g<h.length;++g)h[g]();delete rr[c]}p.destroy()}var Is=()=>{var c="getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE";Is.ed||(Is.ed={}),Is.ed[c]||(Is.ed[c]=1,T(c))};function bM(c,p,h){p>>>=0,h>>>=0;var g=re(c>>>=0);h===0&&Is(),h==4294967295&&(h=void 0);try{var b=g.getMappedRange(p,h)}catch{return 0}var A=ip(16,b.byteLength);return(v(),Q).set(new Uint8Array(b),A>>>0),rr[c].push(()=>Lt(A)),A}function vM(c,p,h){p>>>=0,h>>>=0;var g=re(c>>>=0);h===0&&Is(),h==4294967295&&(h=void 0);try{var b=g.getMappedRange(p,h)}catch{return 0}var A=ip(16,b.byteLength);return(v(),Q).fill(0,A,b.byteLength),rr[c].push(()=>{new Uint8Array(b).set((v(),Q).subarray(A>>>0,A+b.byteLength>>>0)),Lt(A)}),A}function kM(c,p,h,g,b){c>>>=0,p=wt(p),h=wt(h),b>>>=0;var A=re(c);rr[c]=[],b==4294967295&&(b=void 0),ge+=1,Os(p,A.mapAsync(h,g>>>0,b).then(()=>{--ge,rp(p,1,0)},O=>{--ge,ae();var N=tr(O.message);rp(p,O.name==="AbortError"?4:O.name==="OperationError"?3:0,N),delete rr[c]}))}function EM(c){var p=re(c>>>=0),h=rr[c];if(h){for(var g=0;g<h.length;++g)h[g]();delete rr[c],p.unmap()}}function AM(c){delete Yu[c>>>0]}function MM(c,p,h){c>>>=0,p>>>=0,h>>>=0;var g=!!(v(),P)[p+32>>>2>>>0];p={label:dr(p+4),usage:(v(),P)[p+16>>>2>>>0],size:4294967296*(v(),P)[p+28>>>2>>>0]+(v(),P)[p+24>>>2>>>0],mappedAtCreation:g},c=re(c);try{var b=c.createBuffer(p)}catch{return!1}return xt(h,b),g&&(rr[h]=[]),!0}function TM(c,p,h,g){c>>>=0,p=wt(p),g>>>=0,h=fM(h>>>0),c=re(c),ge+=1,Os(p,c.createComputePipelineAsync(h).then(b=>{--ge,xt(g,b),ep(p,1,g,0)},b=>{--ge;var A=ae(),O=tr(b.message);ep(p,b.reason==="validation"?3:b.reason==="internal"?4:0,g,O),oe(A)}))}function SM(c,p,h){c>>>=0,p>>>=0,h>>>=0;var g=(v(),P)[p>>>2>>>0],b=(v(),P)[g+4>>>2>>>0];p={label:dr(p+4),code:""},b===2&&(p.code=Cb(g+8)),xt(h,re(c).createShaderModule(p))}var OM=c=>{(c=re(c)).onuncapturederror=null,c.destroy()};function IM(c,p){p=wt(p),c=re(c>>>0),ge+=1,Os(p,c.popErrorScope().then(h=>{--ge;var g=5;h?h instanceof GPUValidationError?g=2:h instanceof GPUOutOfMemoryError?g=3:h instanceof GPUInternalError&&(g=4):g=1;var b=ae();h=h?tr(h.message):0,sp(p,1,g,h),oe(b)},h=>{--ge;var g=ae();h=tr(h.message),sp(p,1,5,h),oe(g)}))}function CM(c,p,h,g){if(p=wt(p),g>>>=0,h>>>=0){var b=(v(),P)[h+4>>>2>>>0];b={featureLevel:hM[b],powerPreference:_M[(v(),P)[h+8>>>2>>>0]],forceFallbackAdapter:!!(v(),P)[h+12>>>2>>>0]},(h=(v(),P)[h>>>2>>>0])!==0&&(v(),b.Qe=!!(v(),P)[h+8>>>2>>>0])}"gpu"in navigator?(ge+=1,Os(p,navigator.gpu.requestAdapter(b).then(A=>{if(--ge,A)xt(g,A),In(p,1,g,0);else{A=ae();var O=tr("WebGPU not available on this browser (requestAdapter returned null)");In(p,3,g,O),oe(A)}},A=>{--ge;var O=ae();A=tr(A.message),In(p,4,g,A),oe(O)}))):(h=ae(),b=tr("WebGPU not available on this browser (navigator.gpu is not available)"),In(p,3,g,b),oe(h))}function PM(c,p,h){return c>>>=0,p>>>=0,h>>>=0,yb(async()=>{var g=[];if(h){var b=(v(),B)[h>>>2>>>0];g.length=p+1,g[p]=new Promise(N=>setTimeout(N,b,0))}else g.length=p;for(var A=0;A<p;++A){var O=4294967296*(v(),P)[c+8*A+4>>>2>>>0]+(v(),P)[c+8*A>>>2>>>0];if(!(O in Si))return O;g[A]=Si[O]}return g=await Promise.race(g),delete Si[g],g})}var Qu,Ju={},Lb=()=>{if(!Qu){var c,p={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 Ju)Ju[c]===void 0?delete p[c]:p[c]=Ju[c];var h=[];for(c in p)h.push(`${c}=${p[c]}`);Qu=h}return Qu};function Nb(c,p){if(n)return Le(19,1,c,p);c>>>=0,p>>>=0;var h,g=0,b=0;for(h of Lb()){var A=p+g;(v(),P)[c+b>>>2>>>0]=A,g+=ur(h,A,1/0)+1,b+=4}return 0}function $b(c,p){if(n)return Le(20,1,c,p);c>>>=0,p>>>=0;var h=Lb();for(var g of((v(),P)[c>>>2>>>0]=h.length,c=0,h))c+=pr(g)+1;return(v(),P)[p>>>2>>>0]=c,0}function Rb(c){return n?Le(21,1,c):52}function Ub(c,p,h,g){return n?Le(22,1,c,p,h,g):52}function Bb(c,p,h,g){return n?Le(23,1,c,p,h,g):70}var zM=[null,[],[]];function Db(c,p,h,g){if(n)return Le(24,1,c,p,h,g);p>>>=0,h>>>=0,g>>>=0;for(var b=0,A=0;A<h;A++){var O=(v(),P)[p>>>2>>>0],N=(v(),P)[p+4>>>2>>>0];p+=8;for(var D=0;D<N;D++){var q=c,fe=(v(),Q)[O+D>>>0],me=zM[q];fe===0||fe===10?((q===1?I:T)(eb(me)),me.length=0):me.push(fe)}b+=N}return(v(),P)[g>>>2>>>0]=b,0}function LM(c){return c>>>0}function NM(c,p){return Pb(re(c>>>0).limits,p>>>0),1}function $M(c,p){return re(c>>>0).features.has(zb[p])}function RM(c){return BigInt(re(c>>>0).size)}function UM(c){return BigInt(re(c>>>0).usage)}function BM(c,p){if(c>>>=0,p>>>=0){var h=dr(p+4);h={label:h,timestampWrites:p=(p=(v(),P)[p+12>>>2>>>0])!==0?{querySet:re((v(),P)[p+4>>>2>>>0]),beginningOfPassWriteIndex:(v(),P)[p+8>>>2>>>0],endOfPassWriteIndex:(v(),P)[p+12>>>2>>>0]}:void 0}}return c=re(c),p=Kb(0),xt(p,c.beginComputePass(h)),p}function DM(c,p,h,g,b,A){h=wt(h),b=wt(b),A=wt(A),re(c>>>0).copyBufferToBuffer(re(p>>>0),h,re(g>>>0),b,A)}function FM(c){c=re(c>>>0);var p=Hb(0);return xt(p,c.finish()),p}function jM(c,p,h,g,b,A){A=wt(A),re(c>>>0).resolveQuerySet(re(p>>>0),h,g,re(b>>>0),A)}function GM(c,p,h,g){re(c>>>0).dispatchWorkgroups(p,h,g)}function qM(c,p,h){h=wt(h),re(c>>>0).dispatchWorkgroupsIndirect(re(p>>>0),h)}function WM(c){re(c>>>0).end()}function VM(c,p,h,g,b){g>>>=0,b>>>=0,c=re(c>>>0),h=re(h>>>0),g==0?c.setBindGroup(p,h):c.setBindGroup(p,h,(v(),P),b>>>2,g)}function HM(c,p){re(c>>>0).setPipeline(re(p>>>0))}function XM(c,p,h){re(c>>>0).Pe(re(p>>>0),h)}function KM(c,p){c=re(c>>>0);var h=Vb(0);return xt(h,c.getBindGroupLayout(p)),h}function YM(c,p){c>>>=0;var h=dr(4+(p>>>=0)),g=re((v(),P)[p+12>>>2>>>0]),b=(v(),P)[p+16>>>2>>>0];p=(v(),P)[p+20>>>2>>>0];for(var A=[],O=0;O<b;++O){var N=A,D=N.push,q=p+40*O,fe=(v(),P)[q+8>>>2>>>0],me=(v(),P)[q+32>>>2>>>0],Re=(v(),P)[q+36>>>2>>>0],ee=(v(),P)[q+4>>>2>>>0];fe?(me=q+24,(me=(v(),P)[me>>>2>>>0]+4294967296*(v(),B)[me+4>>>2>>>0])==-1&&(me=void 0),q={binding:ee,resource:{buffer:re(fe),offset:4294967296*(v(),P)[q+4+16>>>2>>>0]+(v(),P)[q+16>>>2>>>0],size:me}}):q=me?{binding:ee,resource:re(me)}:{binding:ee,resource:re(Re)},D.call(N,q)}return h={label:h,layout:g,entries:A},c=re(c),g=Wb(0),xt(g,c.createBindGroup(h)),g}function QM(c,p){var h;return c>>>=0,(p>>>=0)&&(h={label:dr(p+4)}),c=re(c),p=Xb(0),xt(p,c.createCommandEncoder(h)),p}function JM(c,p){c>>>=0,p>>>=0,p={type:gM[(v(),P)[p+12>>>2>>>0]],count:(v(),P)[p+16>>>2>>>0]},c=re(c);var h=Yb(0);return xt(h,c.createQuerySet(p)),h}function ZM(c,p){c=re(c>>>0).adapterInfo,p>>>=0,(v(),B)[p+52>>>2>>>0]=c.subgroupMinSize,(v(),B)[p+56>>>2>>>0]=c.subgroupMaxSize;var h=Ob(c.vendor+c.architecture+c.device+c.description),g=pr(c.vendor);return Oi(p+4,h,g),h+=g,g=pr(c.architecture),Oi(p+12,h,g),h+=g,g=pr(c.device),Oi(p+20,h,g),Oi(p+28,h+g,pr(c.description)),(v(),B)[p+36>>>2>>>0]=2,c=c.isFallbackAdapter?3:4,(v(),B)[p+40>>>2>>>0]=c,(v(),B)[p+44>>>2>>>0]=0,(v(),B)[p+48>>>2>>>0]=0,1}var eT={"core-features-and-limits":1,"depth-clip-control":2,"depth32float-stencil8":3,"texture-compression-bc":4,"texture-compression-bc-sliced-3d":5,"texture-compression-etc2":6,"texture-compression-astc":7,"texture-compression-astc-sliced-3d":8,"timestamp-query":9,"indirect-first-instance":10,"shader-f16":11,"rg11b10ufloat-renderable":12,"bgra8unorm-storage":13,"float32-filterable":14,"float32-blendable":15,"clip-distances":16,"dual-source-blending":17,subgroups:18,"texture-formats-tier1":19,"texture-formats-tier2":20,"primitive-index":21,"chromium-experimental-unorm16-texture-formats":327692,"chromium-experimental-snorm16-texture-formats":327693,"chromium-experimental-multi-draw-indirect":327732};function tT(c,p){p>>>=0,c=re(c>>>0);var h=Cs(4*c.features.size),g=0,b=0;c.features.forEach(A=>{0<=(A=eT[A])&&((v(),B)[h+g>>>2>>>0]=A,g+=4,b++)}),(v(),P)[p+4>>>2>>>0]=h,(v(),P)[p>>>2>>>0]=b}function rT(c,p){return Pb(re(c>>>0).limits,p>>>0),1}function sT(c,p){re(c>>>0).pushErrorScope(mM[p])}function nT(c,p,h){p>>>=0,h>>>=0,c=re(c>>>0),p=Array.from((v(),B).subarray(h>>>2>>>0,h+4*p>>>2>>>0),g=>re(g)),c.submit(p)}function oT(c,p,h,g,b){h=wt(h),g>>>=0,b>>>=0,c=re(c>>>0),p=re(p>>>0),g=(v(),Q).subarray(g>>>0,g+b>>>0),c.writeBuffer(p,h,g,0,b)}n||(function(){for(var c=e.numThreads-1;c--;)H0();Me.push(async()=>{var p=(async function(){if(!n)return Promise.all(et.map(V0))})();xe++,await p,--xe==0&&Ge&&(p=Ge,Ge=null,p())})})(),n||(yr=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),ue()),e.wasmBinary&&(f=e.wasmBinary),e.stackSave=()=>ae(),e.stackRestore=c=>oe(c),e.stackAlloc=c=>Ci(c),e.setValue=function(c,p,h="i8"){switch(h.endsWith("*")&&(h="*"),h){case"i1":case"i8":(v(),V)[c>>>0]=p;break;case"i16":(v(),K)[c>>>1>>>0]=p;break;case"i32":(v(),B)[c>>>2>>>0]=p;break;case"i64":(v(),S)[c>>>3>>>0]=BigInt(p);break;case"float":(v(),se)[c>>>2>>>0]=p;break;case"double":(v(),ie)[c>>>3>>>0]=p;break;case"*":(v(),P)[c>>>2>>>0]=p;break;default:Ce(`invalid type for setValue: ${h}`)}},e.getValue=function(c,p="i8"){switch(p.endsWith("*")&&(p="*"),p){case"i1":case"i8":return(v(),V)[c>>>0];case"i16":return(v(),K)[c>>>1>>>0];case"i32":return(v(),B)[c>>>2>>>0];case"i64":return(v(),S)[c>>>3>>>0];case"float":return(v(),se)[c>>>2>>>0];case"double":return(v(),ie)[c>>>3>>>0];case"*":return(v(),P)[c>>>2>>>0];default:Ce(`invalid type for getValue: ${p}`)}},e.UTF8ToString=Ts,e.stringToUTF8=ur,e.lengthBytesUTF8=pr;var Fb,jb,Zu,Ii,Lt,Cs,Gb,qb,Wb,Vb,Hb,Xb,Kb,Yb,Qb,Jb,Zb,ep,tp,rp,sp,In,np,e1,op,t1,r1,s1,ap,n1,o1,ip,he,Cn,a1,oe,Ci,ae,i1,lp,l1,c1,u1,cp,p1,d1,f1,m1,h1,_1,g1,w1,x1,y1,b1,v1,k1,E1,A1,M1,T1,S1,O1,I1,C1,P1,z1,L1,N1,$1,R1,U1,B1,D1,F1,j1,G1,q1,W1,V1,H1,X1,K1,Y1,fr,aT=[xr,Hr,Y0,tb,rb,sb,nb,ob,ab,ib,lb,cb,ub,pb,db,fb,Ab,Mb,Tb,Nb,$b,Rb,Ub,Bb,Db],up={1117404:(c,p,h,g,b)=>{if(e===void 0||!e.Zc)return 1;if((c=Ts(Number(c>>>0))).startsWith("./")&&(c=c.substring(2)),!(c=e.Zc.get(c)))return 2;if(p=Number(p>>>0),h=Number(h>>>0),g=Number(g>>>0),p+h>c.byteLength)return 3;try{let A=c.subarray(p,p+h);switch(b){case 0:(v(),Q).set(A,g>>>0);break;case 1:e.ie?e.ie(g,A):e.Ke(g,A);break;default:return 4}return 0}catch{return 4}},1118228:(c,p,h)=>{e.ke(c,(v(),Q).subarray(p>>>0,p+h>>>0))},1118292:()=>e.Ie(),1118334:c=>{e.je(c)},1118371:()=>typeof wasmOffsetConverter<"u"};function iT(){return typeof wasmOffsetConverter<"u"}function lT(c,p,h,g){var b=ae();try{return w1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function cT(c,p,h){var g=ae();try{return h1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function uT(c,p,h){var g=ae();try{u1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function pT(c,p){var h=ae();try{return cp(c,p)}catch(g){if(oe(h),g!==g+0)throw g;he(1,0)}}function dT(c){var p=ae();try{p1(c)}catch(h){if(oe(p),h!==h+0)throw h;he(1,0)}}function fT(c,p,h,g,b,A,O){var N=ae();try{return m1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function mT(c,p){var h=ae();try{x1(c,p)}catch(g){if(oe(h),g!==g+0)throw g;he(1,0)}}function hT(c,p,h,g,b,A){var O=ae();try{d1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function _T(c,p,h,g){var b=ae();try{g1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function gT(c,p,h,g,b,A,O){var N=ae();try{b1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function wT(c,p,h,g,b,A,O){var N=ae();try{v1(c,p,h,g,b,A,O)}catch(D){if(oe(N),D!==D+0)throw D;he(1,0)}}function xT(c,p,h,g,b,A,O,N){var D=ae();try{P1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function yT(c,p,h,g,b){var A=ae();try{f1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function bT(c,p,h,g,b){var A=ae();try{return y1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function vT(c,p,h,g,b,A,O,N){var D=ae();try{z1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function kT(c,p,h,g,b,A,O,N,D,q,fe,me){var Re=ae();try{k1(c,p,h,g,b,A,O,N,D,q,fe,me)}catch(ee){if(oe(Re),ee!==ee+0)throw ee;he(1,0)}}function ET(c,p,h,g,b,A){var O=ae();try{return I1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function AT(c,p,h){var g=ae();try{return T1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;return he(1,0),0n}}function MT(c,p,h,g,b,A,O,N,D){var q=ae();try{_1(c,p,h,g,b,A,O,N,D)}catch(fe){if(oe(q),fe!==fe+0)throw fe;he(1,0)}}function TT(c){var p=ae();try{return A1(c)}catch(h){if(oe(p),h!==h+0)throw h;he(1,0)}}function ST(c,p,h){var g=ae();try{return L1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function OT(c,p){var h=ae();try{return V1(c,p)}catch(g){if(oe(h),g!==g+0)throw g;return he(1,0),0n}}function IT(c,p,h,g,b){var A=ae();try{N1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function CT(c){var p=ae();try{return E1(c)}catch(h){if(oe(p),h!==h+0)throw h;return he(1,0),0n}}function PT(c,p,h,g,b,A){var O=ae();try{return U1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function zT(c,p,h,g,b,A){var O=ae();try{return B1(c,p,h,g,b,A)}catch(N){if(oe(O),N!==N+0)throw N;he(1,0)}}function LT(c,p,h,g,b,A,O,N){var D=ae();try{return C1(c,p,h,g,b,A,O,N)}catch(q){if(oe(D),q!==q+0)throw q;he(1,0)}}function NT(c,p,h,g,b){var A=ae();try{return D1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;return he(1,0),0n}}function $T(c,p,h,g){var b=ae();try{return F1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function RT(c,p,h,g){var b=ae();try{return j1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function UT(c,p,h,g,b,A,O,N,D,q,fe,me){var Re=ae();try{return G1(c,p,h,g,b,A,O,N,D,q,fe,me)}catch(ee){if(oe(Re),ee!==ee+0)throw ee;he(1,0)}}function BT(c,p,h,g,b,A,O,N,D,q,fe){var me=ae();try{$1(c,p,h,g,b,A,O,N,D,q,fe)}catch(Re){if(oe(me),Re!==Re+0)throw Re;he(1,0)}}function DT(c,p,h,g,b,A,O,N,D,q,fe,me,Re,ee,lt,Nt){var st=ae();try{R1(c,p,h,g,b,A,O,N,D,q,fe,me,Re,ee,lt,Nt)}catch(Qr){if(oe(st),Qr!==Qr+0)throw Qr;he(1,0)}}function FT(c,p,h,g){var b=ae();try{return q1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function jT(c,p,h,g,b){var A=ae();try{return W1(c,p,h,g,b)}catch(O){if(oe(A),O!==O+0)throw O;he(1,0)}}function GT(c,p,h){var g=ae();try{return M1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function qT(c,p,h){var g=ae();try{return S1(c,p,h)}catch(b){if(oe(g),b!==b+0)throw b;he(1,0)}}function WT(c,p,h,g){var b=ae();try{O1(c,p,h,g)}catch(A){if(oe(b),A!==A+0)throw A;he(1,0)}}function Pi(){if(0<xe)Ge=Pi;else if(n)w?.(e),Be();else{for(var c=Me;0<c.length;)c.shift()(e);0<xe?Ge=Pi:(e.calledRun=!0,z||(Be(),w?.(e)))}}return n||(fr=await Qe(),Pi()),e.PTR_SIZE=4,e.webgpuInit=c=>{let p=new WeakMap,h,g,b=1;e.webgpuRegisterDevice=N=>{if(g!==void 0)throw Error("another WebGPU EP inference session is being created.");if(N){var D=p.get(N);if(!D){let q=((fe,me=0)=>{var Re=Zb(me);return me=Jb(me,Re),xt(Re,fe.queue),xt(me,fe),me})(N,D=qb(0));D=[b++,D,q],p.set(N,D)}return h=N,g=D[0],D}h=void 0,g=0};let A=new Map;e.webgpuOnCreateSession=N=>{if(g!==void 0){var D=g;if(g=void 0,N){let q=Zu(D);A.set(N,q),D===0&&c(h??re(q))}h=void 0}},e.webgpuOnReleaseSession=N=>{A.delete(N)};let O=Symbol("gpuBufferMetadata");e.webgpuRegisterBuffer=(N,D,q)=>{if(q)return N[O]=[q,NaN],q;if(q=N[O])return q[1]++,q[0];if((D=A.get(D))===void 0)throw Error("Invalid session handle passed to webgpuRegisterBuffer");return D=((fe,me=0)=>(fe.mapState!="pending"||Ce(),me=Qb(me,fe.mapState=="mapped"?3:1),xt(me,fe),fe.mapState=="mapped"&&(rr[me]=[]),me))(N,D),N[O]=[D,1],D},e.webgpuUnregisterBuffer=N=>{let D=N[O];if(!D)throw Error("Buffer is not registered");D[1]--,D[1]===0&&(Gb(D[0]),delete N[O])},e.webgpuGetBuffer=N=>re(N),e.webgpuCreateDownloader=(N,D,q)=>{if((q=A.get(q))===void 0)throw Error("Invalid session handle passed to webgpuRegisterBuffer");let fe=re(q),me=16*Math.ceil(Number(D)/16);return async()=>{let Re=fe.createBuffer({size:me,usage:9});try{let ee=fe.createCommandEncoder();return ee.copyBufferToBuffer(N,0,Re,0,me),fe.queue.submit([ee.finish()]),await Re.mapAsync(GPUMapMode.READ),Re.getMappedRange().slice(0,D)}finally{Re.destroy()}}},e.ie=(N,D)=>{var q=D.buffer;let fe=D.byteOffset,me=D.byteLength;if(D=16*Math.ceil(Number(me)/16),N=re(N),!h){var Re=Zu(g);h=re(Re)}let ee=(Re=h.createBuffer({mappedAtCreation:!0,size:D,usage:6})).getMappedRange();new Uint8Array(ee).set(new Uint8Array(q,fe,me)),Re.unmap(),(q=h.createCommandEncoder()).copyBufferToBuffer(Re,0,N,0,D),h.queue.submit([q.finish()]),Re.destroy()}},e.webnnInit=c=>{let p=c[0];[e.Ie,e.je,e.webnnEnsureTensor,e.ke,e.webnnDownloadTensor,e.He,e.webnnEnableTraceEvent]=c.slice(1),e.webnnReleaseTensorId=e.je,e.webnnUploadTensor=e.ke,e.webnnRegisterMLContext=e.He,e.webnnOnRunStart=h=>p.onRunStart(h),e.webnnOnRunEnd=p.onRunEnd.bind(p),e.webnnOnReleaseSession=h=>{p.onReleaseSession(h)},e.webnnCreateMLTensorDownloader=(h,g)=>p.createMLTensorDownloader(h,g),e.webnnRegisterMLTensor=(h,g,b,A)=>p.registerMLTensor(h,g,b,A),e.webnnCreateMLContext=h=>p.createMLContext(h),e.webnnRegisterMLConstant=(h,g,b,A,O,N)=>p.registerMLConstant(h,g,b,A,O,e.Zc,N),e.webnnRegisterGraphInput=p.registerGraphInput.bind(p),e.webnnIsGraphInput=p.isGraphInput.bind(p),e.webnnRegisterGraphOutput=p.registerGraphOutput.bind(p),e.webnnIsGraphOutput=p.isGraphOutput.bind(p),e.webnnCreateTemporaryTensor=p.createTemporaryTensor.bind(p),e.webnnIsGraphInputOutputTypeSupported=p.isGraphInputOutputTypeSupported.bind(p)},te?e:new Promise((c,p)=>{w=c,x=p})}var Wk,Jv,zC=ye(()=>{"use strict";Wk=Qv,Jv=globalThis.self?.name?.startsWith("em-pthread"),Jv&&Qv()}),Sp,qp,Zv,Ot,Vk,qi,ek,tk,Op,rk,Ip,Hk,Cp,Xk,Zp=ye(()=>{"use strict";Jp(),Sp=typeof location>"u"?void 0:location.origin,qp=import.meta.url>"file:"&&import.meta.url<"file;",Zv=()=>{if(qp){let t=URL;return new URL(new t("ort.webgpu.bundle.min.mjs",import.meta.url).href,Sp).href}return import.meta.url},Ot=Zv(),Vk=()=>{if(Ot&&!Ot.startsWith("blob:"))return Ot.substring(0,Ot.lastIndexOf("/")+1)},qi=(t,e)=>{try{let r=e??Ot;return(r?new URL(t,r):new URL(t)).origin===Sp}catch{return!1}},ek=(t,e)=>{let r=e??Ot;try{return(r?new URL(t,r):new URL(t)).href}catch{return}},tk=(t,e)=>`${e??"./"}${t}`,Op=async t=>{let e=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(e)},rk=async t=>(await import(t)).default,Ip=(PC(),Yi(jk)).default,Hk=async()=>{if(!Ot)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(qi(Ot))return[void 0,Ip()];let t=await Op(Ot);return[t,Ip(t)]},Cp=(zC(),Yi(qk)).default,Xk=async(t,e,r,s)=>{let n=Cp&&!(t||e);if(n)if(Ot)n=qi(Ot);else if(s&&!r)n=!0;else throw new Error("cannot determine the script source URL.");if(n)return[void 0,Cp];{let o="ort-wasm-simd-threaded.asyncify.mjs",a=t??ek(o,e),i=r&&a&&!qi(a,e),l=i?await Op(a):a??tk(o,e);return[i?l:void 0,await rk(l)]}}}),Pp,Wi,jn,zp,sk,nk,ok,ed,Ue,ps=ye(()=>{"use strict";Zp(),Wi=!1,jn=!1,zp=!1,sk=()=>{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}},nk=()=>{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}},ok=()=>{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}},ed=async t=>{if(Wi)return Promise.resolve();if(jn)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(zp)throw new Error("previous call to 'initializeWebAssembly()' failed.");jn=!0;let e=t.initTimeout,r=t.numThreads;if(t.simd!==!1){if(t.simd==="relaxed"){if(!ok())throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!nk())throw new Error("WebAssembly SIMD is not supported in the current environment.")}let s=sk();r>1&&!s&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", 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."),t.numThreads=r=1);let n=t.wasmPaths,o=typeof n=="string"?n:void 0,a=n?.mjs,i=a?.href??a,l=n?.wasm,u=l?.href??l,d=t.wasmBinary,[f,m]=await Xk(i,o,r>1,!!d||!!u),_=!1,w=[];if(e>0&&w.push(new Promise(x=>{setTimeout(()=>{_=!0,x()},e)})),w.push(new Promise((x,k)=>{let E={numThreads:r};if(d)E.wasmBinary=d;else if(u||o)E.locateFile=M=>u??o+M;else if(i&&i.indexOf("blob:")!==0)E.locateFile=M=>new URL(M,i).href;else if(f){let M=Vk();M&&(E.locateFile=I=>M+I)}m(E).then(M=>{jn=!1,Wi=!0,Pp=M,x(),f&&URL.revokeObjectURL(f)},M=>{jn=!1,zp=!0,k(M)})})),await Promise.race(w),_)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},Ue=()=>{if(Wi&&Pp)return Pp;throw new Error("WebAssembly is not initialized yet.")}}),It,Ji,Oe,td=ye(()=>{"use strict";ps(),It=(t,e)=>{let r=Ue(),s=r.lengthBytesUTF8(t)+1,n=r._malloc(s);return r.stringToUTF8(t,n,s),e.push(n),n},Ji=(t,e,r,s)=>{if(typeof t=="object"&&t!==null){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach(([n,o])=>{let a=e?e+n:n;if(typeof o=="object")Ji(o,a+".",r,s);else if(typeof o=="string"||typeof o=="number")s(a,o.toString());else if(typeof o=="boolean")s(a,o?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof o}`)})},Oe=t=>{let e=Ue(),r=e.stackSave();try{let s=e.PTR_SIZE,n=e.stackAlloc(2*s);e._OrtGetLastError(n,n+s);let o=Number(e.getValue(n,s===4?"i32":"i64")),a=e.getValue(n+s,"*"),i=a?e.UTF8ToString(a):"";throw new Error(`${t} ERROR_CODE: ${o}, ERROR_MESSAGE: ${i}`)}finally{e.stackRestore(r)}}}),Kk,LC=ye(()=>{"use strict";ps(),td(),Kk=t=>{let e=Ue(),r=0,s=[],n=t||{};try{if(t?.logSeverityLevel===void 0)n.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log severity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)n.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(n.terminate=!1);let o=0;return t?.tag!==void 0&&(o=It(t.tag,s)),r=e._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,o),r===0&&Oe("Can't create run options."),t?.extra!==void 0&&Ji(t.extra,"",new WeakSet,(a,i)=>{let l=It(a,s),u=It(i,s);e._OrtAddRunConfigEntry(r,l,u)!==0&&Oe(`Can't set a run config entry: ${a} - ${i}.`)}),[r,s]}catch(o){throw r!==0&&e._OrtReleaseRunOptions(r),s.forEach(a=>e._free(a)),o}}}),ak,ik,lk,Vi,kr,ck,Yk,NC=ye(()=>{"use strict";ps(),td(),ak=t=>{switch(t){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: ${t}`)}},ik=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},lk=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(t.enableMemPattern=!1)},Vi=(t,e,r,s)=>{let n=It(e,s),o=It(r,s);Ue()._OrtAddSessionConfigEntry(t,n,o)!==0&&Oe(`Can't set a session config entry: ${e} - ${r}.`)},kr=(t,e,r,s)=>{let n=It(e,s),o=It(r,s);t.push([n,o])},ck=async(t,e,r)=>{let s=e.executionProviders;for(let n of s){let o=typeof n=="string"?n:n.name,a=[];switch(o){case"webnn":if(o="WEBNN",typeof n!="string"){let f=n?.deviceType;f&&Vi(t,"deviceType",f,r)}break;case"webgpu":{o="WebGPU";let f;if(typeof n!="string"){let _=n;if(_.device)if(typeof GPUDevice<"u"&&_.device instanceof GPUDevice)f=_.device;else throw new Error("Invalid GPU device set in WebGPU EP options.");let{enableGraphCapture:w}=e;if(typeof w=="boolean"&&w&&kr(a,"enableGraphCapture","1",r),typeof _.preferredLayout=="string"&&kr(a,"preferredLayout",_.preferredLayout,r),_.forceCpuNodeNames){let x=Array.isArray(_.forceCpuNodeNames)?_.forceCpuNodeNames:[_.forceCpuNodeNames];kr(a,"forceCpuNodeNames",x.join(`
15
+ `),r)}_.validationMode&&kr(a,"validationMode",_.validationMode,r)}let m=Ue().webgpuRegisterDevice(f);if(m){let[_,w,x]=m;kr(a,"deviceId",_.toString(),r),kr(a,"webgpuInstance",w.toString(),r),kr(a,"webgpuDevice",x.toString(),r)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${o}`)}let i=It(o,r),l=a.length,u=0,d=0;if(l>0){u=Ue()._malloc(l*Ue().PTR_SIZE),r.push(u),d=Ue()._malloc(l*Ue().PTR_SIZE),r.push(d);for(let f=0;f<l;f++)Ue().setValue(u+f*Ue().PTR_SIZE,a[f][0],"*"),Ue().setValue(d+f*Ue().PTR_SIZE,a[f][1],"*")}await Ue()._OrtAppendExecutionProvider(t,i,u,d,l)!==0&&Oe(`Can't append execution provider: ${o}.`)}},Yk=async t=>{let e=Ue(),r=0,s=[],n=t||{};lk(n);try{let o=ak(n.graphOptimizationLevel??"all"),a=ik(n.executionMode??"sequential"),i=typeof n.logId=="string"?It(n.logId,s):0,l=n.logSeverityLevel??2;if(!Number.isInteger(l)||l<0||l>4)throw new Error(`log severity level is not valid: ${l}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let d=typeof n.optimizedModelFilePath=="string"?It(n.optimizedModelFilePath,s):0;if(r=e._OrtCreateSessionOptions(o,!!n.enableCpuMemArena,!!n.enableMemPattern,a,!!n.enableProfiling,0,i,l,u,d),r===0&&Oe("Can't create session options."),n.executionProviders&&await ck(r,n,s),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);Vi(r,"enableGraphCapture",n.enableGraphCapture.toString(),s)}if(n.freeDimensionOverrides)for(let[f,m]of Object.entries(n.freeDimensionOverrides)){if(typeof f!="string")throw new Error(`free dimension override name must be a string: ${f}`);if(typeof m!="number"||!Number.isInteger(m)||m<0)throw new Error(`free dimension override value must be a non-negative integer: ${m}`);let _=It(f,s);e._OrtAddFreeDimensionOverride(r,_,m)!==0&&Oe(`Can't set a free dimension override: ${f} - ${m}.`)}return n.extra!==void 0&&Ji(n.extra,"",new WeakSet,(f,m)=>{Vi(r,f,m,s)}),[r,s]}catch(o){throw r!==0&&e._OrtReleaseSessionOptions(r)!==0&&Oe("Can't release session options."),s.forEach(a=>e._free(a)),o}}}),as,Ki,Fs,Hn,Zi,rd,sd,Wp,js=ye(()=>{"use strict";as=t=>{switch(t){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: ${t}`)}},Ki=t=>{switch(t){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: ${t}`)}},Fs=(t,e)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],s=typeof e=="number"?e:e.reduce((n,o)=>n*o,1);return r>0?Math.ceil(s*r):void 0},Hn=t=>{switch(t){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: ${t}`)}},Zi=t=>{switch(t){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: ${t}`)}},rd=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",sd=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint64"||t==="int8"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",Wp=t=>{switch(t){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: ${t}`)}}}),nd,Qk=ye(()=>{"use strict";Jp(),nd=async t=>{if(typeof t=="string"){let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let r=e.headers.get("Content-Length"),s=r?parseInt(r,10):0;if(s<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n=e.body.getReader(),o;try{o=new ArrayBuffer(s)}catch(i){if(i instanceof RangeError){let l=Math.ceil(s/65536);o=new WebAssembly.Memory({initial:l,maximum:l}).buffer}else throw i}let a=0;for(;;){let{done:i,value:l}=await n.read();if(i)break;let u=l.byteLength;new Uint8Array(o,a,u).set(l),a+=u}return new Uint8Array(o,0,s)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}}),Jk,$C=ye(()=>{"use strict";js(),Jk=(t,e)=>new(Hn(e))(t)}),uk,pk,dk,fk,Zk,mk,_t,eE=ye(()=>{"use strict";js(),uk=["V","I","W","E","F"],pk=(t,e)=>{console.log(`[${uk[t]},${new Date().toISOString()}]${e}`)},Zk=(t,e)=>{dk=t,fk=e},mk=(t,e)=>{let r=Zi(t),s=Zi(dk);r>=s&&pk(r,typeof e=="function"?e():e)},_t=(...t)=>{fk&&mk(...t)}}),Lp,Vp,Np,hk,$p,_k,Rp,Up,Bp,gk,tE,RC=ye(()=>{"use strict";js(),eE(),Lp=new Map([["float32",32],["float16",16],["int32",32],["uint32",32],["int64",64],["uint64",64],["int8",8],["uint8",8],["int4",4],["uint4",4]]),Vp=(t,e)=>{if(e==="int32")return t;let r=Lp.get(e);if(!r)throw new Error(`WebNN backend does not support data type: ${e}`);let s=r/8;if(t.byteLength%s!==0)throw new Error(`Invalid Uint8Array length - must be a multiple of ${s}.`);let n=t.byteLength/s,o=new(Hn(e))(t.buffer,t.byteOffset,n);switch(e){case"int64":case"uint64":{let a=new Int32Array(n);for(let i=0;i<n;i++){let l=o[i];if(l>2147483647n||l<-2147483648n)throw new Error("Can not convert int64 data to int32 - value out of range.");a[i]=Number(l)}return new Uint8Array(a.buffer)}case"int8":case"uint8":case"uint32":{if(e==="uint32"&&o.some(i=>i>2147483647))throw new Error("Can not convert uint32 data to int32 - value out of range.");let a=Int32Array.from(o,Number);return new Uint8Array(a.buffer)}default:throw new Error(`Unsupported data conversion from ${e} to 'int32'`)}},Np=(t,e)=>{if(e==="int32")return t;if(t.byteLength%4!==0)throw new Error("Invalid Uint8Array length - must be a multiple of 4 (int32).");let r=t.byteLength/4,s=new Int32Array(t.buffer,t.byteOffset,r);switch(e){case"int64":{let n=BigInt64Array.from(s,BigInt);return new Uint8Array(n.buffer)}case"uint64":{if(s.some(o=>o<0))throw new Error("Can not convert int32 data to uin64 - negative value found.");let n=BigUint64Array.from(s,BigInt);return new Uint8Array(n.buffer)}case"int8":{if(s.some(o=>o<-128||o>127))throw new Error("Can not convert int32 data to int8 - value out of range.");let n=Int8Array.from(s,Number);return new Uint8Array(n.buffer)}case"uint8":{if(s.some(n=>n<0||n>255))throw new Error("Can not convert int32 data to uint8 - value out of range.");return Uint8Array.from(s,Number)}case"uint32":{if(s.some(o=>o<0))throw new Error("Can not convert int32 data to uint32 - negative value found.");let n=Uint32Array.from(s,Number);return new Uint8Array(n.buffer)}default:throw new Error(`Unsupported data conversion from 'int32' to ${e}`)}},hk=1,$p=()=>hk++,_k=new Map([["int8","int32"],["uint8","int32"],["uint32","int32"],["int64","int32"]]),Rp=(t,e)=>{let r=Lp.get(t);if(!r)throw new Error(`WebNN backend does not support data type: ${t}`);return e.length>0?Math.ceil(e.reduce((s,n)=>s*n)*r/8):0},Up=class{constructor(t){this.isDataConverted=!1;let{sessionId:e,context:r,tensor:s,dataType:n,shape:o,fallbackDataType:a}=t;this.sessionId=e,this.mlContext=r,this.mlTensor=s,this.dataType=n,this.tensorShape=o,this.fallbackDataType=a}get tensor(){return this.mlTensor}get type(){return this.dataType}get fallbackType(){return this.fallbackDataType}get shape(){return this.tensorShape}get byteLength(){return Rp(this.dataType,this.tensorShape)}destroy(){_t("verbose",()=>"[WebNN] TensorWrapper.destroy"),this.mlTensor.destroy()}write(t){this.mlContext.writeTensor(this.mlTensor,t)}async read(t){if(this.fallbackDataType){let e=await this.mlContext.readTensor(this.mlTensor),r=Np(new Uint8Array(e),this.dataType);if(t){(t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)).set(r);return}else return r.buffer}else return t?this.mlContext.readTensor(this.mlTensor,t):this.mlContext.readTensor(this.mlTensor)}canReuseTensor(t,e,r){return this.mlContext===t&&this.dataType===e&&this.tensorShape.length===r.length&&this.tensorShape.every((s,n)=>s===r[n])}setIsDataConverted(t){this.isDataConverted=t}},Bp=class{constructor(t,e){this.tensorManager=t,this.wrapper=e}get tensorWrapper(){return this.wrapper}releaseTensor(){this.tensorWrapper&&(this.tensorManager.releaseTensor(this.tensorWrapper),this.wrapper=void 0)}async ensureTensor(t,e,r,s){let n=this.tensorManager.getMLContext(t),o=this.tensorManager.getMLOpSupportLimits(t),a;if(!o?.input.dataTypes.includes(e)){if(a=_k.get(e),!a||o?.input.dataTypes.includes(a))throw new Error(`WebNN backend does not support data type: ${e}`);_t("verbose",()=>`[WebNN] TensorIdTracker.ensureTensor: fallback dataType from ${e} to ${a}`)}if(this.wrapper){if(this.wrapper.canReuseTensor(n,e,r))return this.wrapper.tensor;if(s){if(this.wrapper.byteLength!==Rp(e,r))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 i=typeof MLTensorUsage>"u"?void 0:MLTensorUsage.READ|MLTensorUsage.WRITE;return this.wrapper=await this.tensorManager.getCachedTensor(t,e,r,i,!0,!0,a),s&&this.activeUpload&&(this.wrapper.write(this.activeUpload),this.activeUpload=void 0),this.wrapper.tensor}upload(t){let e=t;if(this.wrapper){if(this.wrapper.fallbackType)if(this.wrapper.fallbackType==="int32")e=Vp(t,this.wrapper.type),this.wrapper.setIsDataConverted(!0);else throw new Error(`Unsupported fallback data type: ${this.wrapper.fallbackType}`);if(t.byteLength===this.wrapper.byteLength){this.wrapper.write(e);return}else _t("verbose",()=>"Data size does not match tensor size. Releasing tensor."),this.releaseTensor()}this.activeUpload?this.activeUpload.set(e):this.activeUpload=new Uint8Array(e)}async download(t){if(this.activeUpload){let e=this.wrapper?.isDataConverted?Np(this.activeUpload,this.wrapper?.type):this.activeUpload;if(t){t instanceof ArrayBuffer?new Uint8Array(t).set(e):new Uint8Array(t.buffer,t.byteOffset,t.byteLength).set(e);return}else return e.buffer}if(!this.wrapper)throw new Error("Tensor has not been created.");return t?this.wrapper.read(t):this.wrapper.read()}},gk=class{constructor(t){this.backend=t,this.tensorTrackersById=new Map,this.freeTensors=[],this.externalTensors=new Set}getMLContext(t){let e=this.backend.getMLContext(t);if(!e)throw new Error("MLContext not found for session.");return e}getMLOpSupportLimits(t){return this.backend.getMLOpSupportLimits(t)}reserveTensorId(){let t=$p();return this.tensorTrackersById.set(t,new Bp(this)),t}releaseTensorId(t){let e=this.tensorTrackersById.get(t);e&&(this.tensorTrackersById.delete(t),e.tensorWrapper&&this.releaseTensor(e.tensorWrapper))}async ensureTensor(t,e,r,s,n){_t("verbose",()=>`[WebNN] TensorManager.ensureTensor {tensorId: ${e}, dataType: ${r}, shape: ${s}, copyOld: ${n}}`);let o=this.tensorTrackersById.get(e);if(!o)throw new Error("Tensor not found.");return o.ensureTensor(t,r,s,n)}upload(t,e){let r=this.tensorTrackersById.get(t);if(!r)throw new Error("Tensor not found.");r.upload(e)}async download(t,e){_t("verbose",()=>`[WebNN] TensorManager.download {tensorId: ${t}, dstBuffer: ${e?.byteLength}}`);let r=this.tensorTrackersById.get(t);if(!r)throw new Error("Tensor not found.");return r.download(e)}releaseTensorsForSession(t){for(let e of this.freeTensors)e.sessionId===t&&e.destroy();this.freeTensors=this.freeTensors.filter(e=>e.sessionId!==t)}registerTensor(t,e,r,s){let n=this.getMLContext(t),o=$p(),a=new Up({sessionId:t,context:n,tensor:e,dataType:r,shape:s});return this.tensorTrackersById.set(o,new Bp(this,a)),this.externalTensors.add(a),o}async getCachedTensor(t,e,r,s,n,o,a){let i=this.getMLContext(t);for(let[u,d]of this.freeTensors.entries())if(d.canReuseTensor(i,e,r)){_t("verbose",()=>`[WebNN] Reusing tensor {dataType: ${e}, ${a?`fallbackDataType: ${a},`:""} shape: ${r}`);let f=this.freeTensors.splice(u,1)[0];return f.sessionId=t,f}_t("verbose",()=>`[WebNN] MLContext.createTensor {dataType: ${e}, ${a?`fallbackDataType: ${a},`:""} shape: ${r}}`);let l=await i.createTensor({dataType:a??e,shape:r,dimensions:r,usage:s,writable:n,readable:o});return new Up({sessionId:t,context:i,tensor:l,dataType:e,shape:r,fallbackDataType:a})}releaseTensor(t){this.externalTensors.has(t)&&this.externalTensors.delete(t),this.freeTensors.push(t)}},tE=(...t)=>new gk(...t)}),rE={};Xn(rE,{WebNNBackend:()=>sE});var Gn,wk,sE,UC=ye(()=>{"use strict";js(),ps(),$C(),RC(),eE(),Gn=new Map([[1,"float32"],[10,"float16"],[6,"int32"],[12,"uint32"],[7,"int64"],[13,"uint64"],[22,"int4"],[21,"uint4"],[3,"int8"],[2,"uint8"],[9,"uint8"]]),wk=(t,e)=>{if(t===e)return!0;if(t===void 0||e===void 0)return!1;let r=Object.keys(t).sort(),s=Object.keys(e).sort();return r.length===s.length&&r.every((n,o)=>n===s[o]&&t[n]===e[n])},sE=class{constructor(t){this.tensorManager=tE(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,Zk(t.logLevel,!!t.debug)}get currentSessionId(){if(this.activeSessionId===void 0)throw new Error("No active session");return this.activeSessionId}onRunStart(t){_t("verbose",()=>`[WebNN] onRunStart {sessionId: ${t}}`),this.activeSessionId=t}onRunEnd(t){_t("verbose",()=>`[WebNN] onRunEnd {sessionId: ${t}}`);let e=this.temporarySessionTensorIds.get(t);if(e){for(let r of e)_t("verbose",()=>`[WebNN] releasing temporary tensor {tensorId: ${r}}`),this.tensorManager.releaseTensorId(r);this.temporarySessionTensorIds.delete(t),this.activeSessionId=void 0}}async createMLContext(t){if(t instanceof GPUDevice){let r=this.mlContextCache.findIndex(s=>s.gpuDevice===t);if(r!==-1)return this.mlContextCache[r].mlContext;{let s=await navigator.ml.createContext(t);return this.mlContextCache.push({gpuDevice:t,mlContext:s}),s}}else if(t===void 0){let r=this.mlContextCache.findIndex(s=>s.options===void 0&&s.gpuDevice===void 0);if(r!==-1)return this.mlContextCache[r].mlContext;{let s=await navigator.ml.createContext();return this.mlContextCache.push({mlContext:s}),s}}let e=this.mlContextCache.findIndex(r=>wk(r.options,t));if(e!==-1)return this.mlContextCache[e].mlContext;{let r=await navigator.ml.createContext(t);return this.mlContextCache.push({options:t,mlContext:r}),r}}registerMLContext(t,e){this.mlContextBySessionId.set(t,e);let r=this.sessionIdsByMLContext.get(e);r||(r=new Set,this.sessionIdsByMLContext.set(e,r)),r.add(t),this.mlOpSupportLimitsBySessionId.has(t)||this.mlOpSupportLimitsBySessionId.set(t,e.opSupportLimits()),this.temporaryGraphInputs.length>0&&(this.sessionGraphInputs.set(t,this.temporaryGraphInputs),this.temporaryGraphInputs=[]),this.temporaryGraphOutputs.length>0&&(this.sessionGraphOutputs.set(t,this.temporaryGraphOutputs),this.temporaryGraphOutputs=[])}onReleaseSession(t){this.sessionGraphInputs.delete(t),this.sessionGraphOutputs.delete(t);let e=this.mlContextBySessionId.get(t);if(!e)return;this.tensorManager.releaseTensorsForSession(t),this.mlContextBySessionId.delete(t),this.mlOpSupportLimitsBySessionId.delete(t);let r=this.sessionIdsByMLContext.get(e);if(r.delete(t),r.size===0){this.sessionIdsByMLContext.delete(e);let s=this.mlContextCache.findIndex(n=>n.mlContext===e);s!==-1&&this.mlContextCache.splice(s,1)}}getMLContext(t){return this.mlContextBySessionId.get(t)}getMLOpSupportLimits(t){return this.mlOpSupportLimitsBySessionId.get(t)}reserveTensorId(){return this.tensorManager.reserveTensorId()}releaseTensorId(t){_t("verbose",()=>`[WebNN] releaseTensorId {tensorId: ${t}}`),this.tensorManager.releaseTensorId(t)}async ensureTensor(t,e,r,s,n){let o=Gn.get(r);if(!o)throw new Error(`Unsupported ONNX data type: ${r}`);return this.tensorManager.ensureTensor(t??this.currentSessionId,e,o,s,n)}async createTemporaryTensor(t,e,r){_t("verbose",()=>`[WebNN] createTemporaryTensor {onnxDataType: ${e}, shape: ${r}}`);let s=Gn.get(e);if(!s)throw new Error(`Unsupported ONNX data type: ${e}`);let n=this.tensorManager.reserveTensorId();await this.tensorManager.ensureTensor(t,n,s,r,!1);let o=this.temporarySessionTensorIds.get(t);return o?o.push(n):this.temporarySessionTensorIds.set(t,[n]),n}uploadTensor(t,e){if(!Ue().shouldTransferToMLTensor)throw new Error("Trying to upload to a MLTensor while shouldTransferToMLTensor is false");_t("verbose",()=>`[WebNN] uploadTensor {tensorId: ${t}, data: ${e.byteLength}}`),this.tensorManager.upload(t,e)}async downloadTensor(t,e){return this.tensorManager.download(t,e)}createMLTensorDownloader(t,e){return async()=>{let r=await this.tensorManager.download(t);return Jk(r,e)}}registerMLTensor(t,e,r,s){let n=Gn.get(r);if(!n)throw new Error(`Unsupported ONNX data type: ${r}`);let o=this.tensorManager.registerTensor(t,e,n,s);return _t("verbose",()=>`[WebNN] registerMLTensor {tensor: ${e}, dataType: ${n}, dimensions: ${s}} -> {tensorId: ${o}}`),o}registerMLConstant(t,e,r,s,n,o,a=!1){if(!o)throw new Error("External mounted files are not available.");let i=t;t.startsWith("./")&&(i=t.substring(2));let l=o.get(i);if(!l)throw new Error(`File with name ${i} not found in preloaded files.`);if(e+r>l.byteLength)throw new Error("Out of bounds: data offset and length exceed the external file data size.");let u=l.slice(e,e+r).buffer,d;switch(n.dataType){case"float32":d=new Float32Array(u);break;case"float16":d=typeof Float16Array<"u"&&Float16Array.from?new Float16Array(u):new Uint16Array(u);break;case"int32":d=new Int32Array(u);break;case"uint32":d=new Uint32Array(u);break;case"int64":if(a){let f=Vp(new Uint8Array(u),"int64");d=new Int32Array(f.buffer),n.dataType="int32"}else d=new BigInt64Array(u);break;case"uint64":d=new BigUint64Array(u);break;case"int8":d=new Int8Array(u);break;case"int4":case"uint4":case"uint8":d=new Uint8Array(u);break;default:throw new Error(`Unsupported data type: ${n.dataType} in creating WebNN Constant from external data.`)}return _t("verbose",()=>`[WebNN] registerMLConstant {dataType: ${n.dataType}, shape: ${n.shape}}} ${a?"(Note: it was int64 data type and registered to int32 as workaround)":""}`),s.constant(n,d)}registerGraphInput(t){this.temporaryGraphInputs.push(t)}registerGraphOutput(t){this.temporaryGraphOutputs.push(t)}isGraphInput(t,e){let r=this.sessionGraphInputs.get(t);return r?r.includes(e):!1}isGraphOutput(t,e){let r=this.sessionGraphOutputs.get(t);return r?r.includes(e):!1}isGraphInputOutputTypeSupported(t,e,r=!0){let s=Gn.get(as(e)),n=this.mlOpSupportLimitsBySessionId.get(t);return typeof s>"u"?!1:r?!!n?.input.dataTypes.includes(s):!!n?.output.dataTypes.includes(s)}flush(){}}}),xk,od,ad,Er,yk,Dp,el,id,ld,Fp,cd,ud,pd,nE=ye(()=>{"use strict";us(),LC(),NC(),js(),ps(),td(),Qk(),xk=(t,e)=>{Ue()._OrtInit(t,e)!==0&&Oe("Can't initialize onnxruntime.")},od=async t=>{xk(t.wasm.numThreads,Zi(t.logLevel))},ad=async(t,e)=>{Ue().asyncInit?.();let r=t.webgpu.adapter;if(e==="webgpu"){if(typeof navigator>"u"||!navigator.gpu)throw new Error("WebGPU is not supported in current environment");if(r){if(typeof r.limits!="object"||typeof r.features!="object"||typeof r.requestDevice!="function")throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let s=t.webgpu.powerPreference;if(s!==void 0&&s!=="low-power"&&s!=="high-performance")throw new Error(`Invalid powerPreference setting: "${s}"`);let n=t.webgpu.forceFallbackAdapter;if(n!==void 0&&typeof n!="boolean")throw new Error(`Invalid forceFallbackAdapter setting: "${n}"`);if(r=await navigator.gpu.requestAdapter({powerPreference:s,forceFallbackAdapter:n}),!r)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");if(e==="webgpu"&&Ue().webgpuInit(s=>{t.webgpu.device=s}),e==="webnn"){let s=new(UC(),Yi(rE)).WebNNBackend(t);Ue().webnnInit([s,()=>s.reserveTensorId(),n=>s.releaseTensorId(n),async(n,o,a,i,l)=>s.ensureTensor(n,o,a,i,l),(n,o)=>{s.uploadTensor(n,o)},async(n,o)=>s.downloadTensor(n,o),(n,o)=>s.registerMLContext(n,o),!!t.trace])}},Er=new Map,yk=t=>{let e=Ue(),r=e.stackSave();try{let s=e.PTR_SIZE,n=e.stackAlloc(2*s);e._OrtGetInputOutputCount(t,n,n+s)!==0&&Oe("Can't get session input/output count.");let o=s===4?"i32":"i64";return[Number(e.getValue(n,o)),Number(e.getValue(n+s,o))]}finally{e.stackRestore(r)}},Dp=(t,e)=>{let r=Ue(),s=r.stackSave(),n=0;try{let o=r.PTR_SIZE,a=r.stackAlloc(2*o);r._OrtGetInputOutputMetadata(t,e,a,a+o)!==0&&Oe("Can't get session input/output metadata.");let i=Number(r.getValue(a,"*"));n=Number(r.getValue(a+o,"*"));let l=r.HEAP32[n/4];if(l===0)return[i,0];let u=r.HEAPU32[n/4+1],d=[];for(let f=0;f<u;f++){let m=Number(r.getValue(n+8+f*o,"*"));d.push(m!==0?r.UTF8ToString(m):Number(r.getValue(n+8+(f+u)*o,"*")))}return[i,l,d]}finally{r.stackRestore(s),n!==0&&r._OrtFree(n)}},el=t=>{let e=Ue(),r=e._malloc(t.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,r),[r,t.byteLength]},id=async(t,e)=>{let r,s,n=Ue();Array.isArray(t)?[r,s]=t:t.buffer===n.HEAPU8.buffer?[r,s]=[t.byteOffset,t.byteLength]:[r,s]=el(t);let o=0,a=0,i=0,l=[],u=[],d=[];try{if([a,l]=await Yk(e),e?.externalData&&n.mountExternalData){let T=[];for(let z of e.externalData){let C=typeof z=="string"?z:z.path;T.push(nd(typeof z=="string"?z:z.data).then(v=>{n.mountExternalData(C,v)}))}await Promise.all(T)}for(let T of e?.executionProviders??[])if((typeof T=="string"?T:T.name)==="webnn"){if(n.shouldTransferToMLTensor=!1,typeof T!="string"){let z=T,C=z?.context,v=z?.gpuDevice,G=z?.deviceType,X=z?.powerPreference;C?n.currentContext=C:v?n.currentContext=await n.webnnCreateMLContext(v):n.currentContext=await n.webnnCreateMLContext({deviceType:G,powerPreference:X})}else n.currentContext=await n.webnnCreateMLContext();break}o=await n._OrtCreateSession(r,s,a),n.webgpuOnCreateSession?.(o),o===0&&Oe("Can't create a session."),n.jsepOnCreateSession?.(),n.currentContext&&(n.webnnRegisterMLContext(o,n.currentContext),n.currentContext=void 0,n.shouldTransferToMLTensor=!0);let[f,m]=yk(o),_=!!e?.enableGraphCapture,w=[],x=[],k=[],E=[],M=[];for(let T=0;T<f;T++){let[z,C,v]=Dp(o,T);z===0&&Oe("Can't get an input name."),u.push(z);let G=n.UTF8ToString(z);w.push(G),k.push(C===0?{name:G,isTensor:!1}:{name:G,isTensor:!0,type:Ki(C),shape:v})}for(let T=0;T<m;T++){let[z,C,v]=Dp(o,T+f);z===0&&Oe("Can't get an output name."),d.push(z);let G=n.UTF8ToString(z);x.push(G),E.push(C===0?{name:G,isTensor:!1}:{name:G,isTensor:!0,type:Ki(C),shape:v});{if(_&&e?.preferredOutputLocation===void 0){M.push("gpu-buffer");continue}let X=typeof e?.preferredOutputLocation=="string"?e.preferredOutputLocation:e?.preferredOutputLocation?.[G]??"cpu",V=n.webnnIsGraphOutput;if(X==="cpu"&&V&&V(o,G)){M.push("ml-tensor-cpu-output");continue}if(X!=="cpu"&&X!=="cpu-pinned"&&X!=="gpu-buffer"&&X!=="ml-tensor")throw new Error(`Not supported preferred output location: ${X}.`);if(_&&X!=="gpu-buffer")throw new Error(`Not supported preferred output location: ${X}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);M.push(X)}}let I=null;return M.some(T=>T==="gpu-buffer"||T==="ml-tensor"||T==="ml-tensor-cpu-output")&&(i=n._OrtCreateBinding(o),i===0&&Oe("Can't create IO binding."),I={handle:i,outputPreferredLocations:M,outputPreferredLocationsEncoded:M.map(T=>T==="ml-tensor-cpu-output"?"ml-tensor":T).map(T=>Wp(T))}),Er.set(o,[o,u,d,I,_,!1]),[o,w,x,k,E]}catch(f){throw u.forEach(m=>n._OrtFree(m)),d.forEach(m=>n._OrtFree(m)),i!==0&&n._OrtReleaseBinding(i)!==0&&Oe("Can't release IO binding."),o!==0&&n._OrtReleaseSession(o)!==0&&Oe("Can't release session."),f}finally{n._free(r),a!==0&&n._OrtReleaseSessionOptions(a)!==0&&Oe("Can't release session options."),l.forEach(f=>n._free(f)),n.unmountExternalData?.()}},ld=t=>{let e=Ue(),r=Er.get(t);if(!r)throw new Error(`cannot release session. invalid session id: ${t}`);let[s,n,o,a,i]=r;a&&(i&&e._OrtClearBoundOutputs(a.handle)!==0&&Oe("Can't clear bound outputs."),e._OrtReleaseBinding(a.handle)!==0&&Oe("Can't release IO binding.")),e.jsepOnReleaseSession?.(t),e.webnnOnReleaseSession?.(t),e.webgpuOnReleaseSession?.(t),n.forEach(l=>e._OrtFree(l)),o.forEach(l=>e._OrtFree(l)),e._OrtReleaseSession(s)!==0&&Oe("Can't release session."),Er.delete(t)},Fp=async(t,e,r,s,n,o,a=!1)=>{if(!t){e.push(0);return}let i=Ue(),l=i.PTR_SIZE,u=t[0],d=t[1],f=t[3],m=f,_,w;if(u==="string"&&(f==="gpu-buffer"||f==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(a&&f!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${o} when enableGraphCapture is true.`);if(f==="gpu-buffer"){let E=t[2].gpuBuffer;w=Fs(as(u),d);{let M=i.webgpuRegisterBuffer;if(!M)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');_=M(E,s)}}else if(f==="ml-tensor"){let E=t[2].mlTensor;w=Fs(as(u),d);let M=i.webnnRegisterMLTensor;if(!M)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');_=M(s,E,as(u),d)}else{let E=t[2];if(Array.isArray(E)){w=l*E.length,_=i._malloc(w),r.push(_);for(let M=0;M<E.length;M++){if(typeof E[M]!="string")throw new TypeError(`tensor data at index ${M} is not a string`);i.setValue(_+M*l,It(E[M],r),"*")}}else{let M=i.webnnIsGraphInput,I=i.webnnIsGraphOutput;if(u!=="string"&&M&&I){let T=i.UTF8ToString(n);if(M(s,T)||I(s,T)){let z=as(u);w=Fs(z,d),m="ml-tensor";let C=i.webnnCreateTemporaryTensor,v=i.webnnUploadTensor;if(!C||!v)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');let G=await C(s,z,d);v(G,new Uint8Array(E.buffer,E.byteOffset,E.byteLength)),_=G}else w=E.byteLength,_=i._malloc(w),r.push(_),i.HEAPU8.set(new Uint8Array(E.buffer,E.byteOffset,w),_)}else w=E.byteLength,_=i._malloc(w),r.push(_),i.HEAPU8.set(new Uint8Array(E.buffer,E.byteOffset,w),_)}}let x=i.stackSave(),k=i.stackAlloc(4*d.length);try{d.forEach((M,I)=>i.setValue(k+I*l,M,l===4?"i32":"i64"));let E=i._OrtCreateTensor(as(u),_,w,k,d.length,Wp(m));E===0&&Oe(`Can't create tensor for input/output. session=${s}, index=${o}.`),e.push(E)}finally{i.stackRestore(x)}},cd=async(t,e,r,s,n,o)=>{let a=Ue(),i=a.PTR_SIZE,l=Er.get(t);if(!l)throw new Error(`cannot run inference. invalid session id: ${t}`);let u=l[0],d=l[1],f=l[2],m=l[3],_=l[4],w=l[5],x=e.length,k=s.length,E=0,M=[],I=[],T=[],z=[],C=[],v=a.stackSave(),G=a.stackAlloc(x*i),X=a.stackAlloc(x*i),V=a.stackAlloc(k*i),Q=a.stackAlloc(k*i);try{[E,M]=Kk(o),Mr("wasm prepareInputOutputTensor");for(let P=0;P<x;P++)await Fp(r[P],I,z,t,d[e[P]],e[P],_);for(let P=0;P<k;P++)await Fp(n[P],T,z,t,f[s[P]],x+s[P],_);Tr("wasm prepareInputOutputTensor");for(let P=0;P<x;P++)a.setValue(G+P*i,I[P],"*"),a.setValue(X+P*i,d[e[P]],"*");for(let P=0;P<k;P++)a.setValue(V+P*i,T[P],"*"),a.setValue(Q+P*i,f[s[P]],"*");if(m&&!w){let{handle:P,outputPreferredLocations:se,outputPreferredLocationsEncoded:ie}=m;if(d.length!==x)throw new Error(`input count from feeds (${x}) is expected to be always equal to model's input count (${d.length}).`);Mr("wasm bindInputsOutputs");for(let S=0;S<x;S++){let L=e[S];await a._OrtBindInput(P,d[L],I[S])!==0&&Oe(`Can't bind input[${S}] for session=${t}.`)}for(let S=0;S<k;S++){let L=s[S];n[S]?.[3]?(C.push(T[S]),a._OrtBindOutput(P,f[L],T[S],0)!==0&&Oe(`Can't bind pre-allocated output[${S}] for session=${t}.`)):a._OrtBindOutput(P,f[L],0,ie[L])!==0&&Oe(`Can't bind output[${S}] to ${se[S]} for session=${t}.`)}Tr("wasm bindInputsOutputs"),Er.set(t,[u,d,f,m,_,!0])}a.jsepOnRunStart?.(u),a.webnnOnRunStart?.(u);let K;m?K=await a._OrtRunWithBinding(u,m.handle,k,V,E):K=await a._OrtRun(u,X,G,x,Q,k,V,E),K!==0&&Oe("failed to call OrtRun().");let Y=[],B=[];Mr("wasm ProcessOutputTensor");for(let P=0;P<k;P++){let se=Number(a.getValue(V+P*i,"*"));if(se===T[P]||C.includes(T[P])){Y.push(n[P]),se!==T[P]&&a._OrtReleaseTensor(se)!==0&&Oe("Can't release tensor.");continue}let ie=a.stackSave(),S=a.stackAlloc(4*i),L=!1,R,te=0;try{a._OrtGetTensorData(se,S,S+i,S+2*i,S+3*i)!==0&&Oe(`Can't access output tensor data on index ${P}.`);let ue=i===4?"i32":"i64",Be=Number(a.getValue(S,ue));te=a.getValue(S+i,"*");let Ce=a.getValue(S+i*2,"*"),vt=Number(a.getValue(S+i*3,ue)),Qe=[];for(let Me=0;Me<vt;Me++)Qe.push(Number(a.getValue(Ce+Me*i,ue)));a._OrtFree(Ce)!==0&&Oe("Can't free memory for tensor dims.");let Ze=Qe.reduce((Me,xe)=>Me*xe,1);R=Ki(Be);let rt=m?.outputPreferredLocations[s[P]];if(R==="string"){if(rt==="gpu-buffer"||rt==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let Me=[];for(let xe=0;xe<Ze;xe++){let Ge=a.getValue(te+xe*i,"*"),kt=a.getValue(te+(xe+1)*i,"*"),ge=xe===Ze-1?void 0:kt-Ge;Me.push(a.UTF8ToString(Ge,ge))}Y.push([R,Qe,Me,"cpu"])}else if(rt==="gpu-buffer"&&Ze>0){let Me=a.webgpuGetBuffer;if(!Me)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let xe=Me(te),Ge=Fs(Be,Ze);if(Ge===void 0||!rd(R))throw new Error(`Unsupported data type: ${R}`);L=!0;{a.webgpuRegisterBuffer(xe,t,te);let kt=a.webgpuCreateDownloader(xe,Ge,t);Y.push([R,Qe,{gpuBuffer:xe,download:async()=>{let ge=await kt();return new(Hn(R))(ge)},dispose:()=>{a._OrtReleaseTensor(se)!==0&&Oe("Can't release tensor.")}},"gpu-buffer"])}}else if(rt==="ml-tensor"&&Ze>0){let Me=a.webnnEnsureTensor,xe=a.webnnIsGraphInputOutputTypeSupported;if(!Me||!xe)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(Fs(Be,Ze)===void 0||!sd(R))throw new Error(`Unsupported data type: ${R}`);if(!xe(t,R,!1))throw new Error(`preferredLocation "ml-tensor" for ${R} output is not supported by current WebNN Context.`);let Ge=await Me(t,te,Be,Qe,!1);L=!0,Y.push([R,Qe,{mlTensor:Ge,download:a.webnnCreateMLTensorDownloader(te,R),dispose:()=>{a.webnnReleaseTensorId(te),a._OrtReleaseTensor(se)}},"ml-tensor"])}else if(rt==="ml-tensor-cpu-output"&&Ze>0){let Me=a.webnnCreateMLTensorDownloader(te,R)(),xe=Y.length;L=!0,B.push((async()=>{let Ge=[xe,await Me];return a.webnnReleaseTensorId(te),a._OrtReleaseTensor(se),Ge})()),Y.push([R,Qe,[],"cpu"])}else{let Me=Hn(R),xe=new Me(Ze);new Uint8Array(xe.buffer,xe.byteOffset,xe.byteLength).set(a.HEAPU8.subarray(te,te+xe.byteLength)),Y.push([R,Qe,xe,"cpu"])}}finally{a.stackRestore(ie),R==="string"&&te&&a._free(te),L||a._OrtReleaseTensor(se)}}m&&!_&&(a._OrtClearBoundOutputs(m.handle)!==0&&Oe("Can't clear bound outputs."),Er.set(t,[u,d,f,m,_,!1]));for(let[P,se]of await Promise.all(B))Y[P][2]=se;return Tr("wasm ProcessOutputTensor"),Y}finally{a.webnnOnRunEnd?.(u),a.stackRestore(v),r.forEach(K=>{K&&K[3]==="gpu-buffer"&&a.webgpuUnregisterBuffer(K[2].gpuBuffer)}),n.forEach(K=>{K&&K[3]==="gpu-buffer"&&a.webgpuUnregisterBuffer(K[2].gpuBuffer)}),I.forEach(K=>a._OrtReleaseTensor(K)),T.forEach(K=>a._OrtReleaseTensor(K)),z.forEach(K=>a._free(K)),E!==0&&a._OrtReleaseRunOptions(E),M.forEach(K=>a._free(K))}},ud=t=>{let e=Ue(),r=Er.get(t);if(!r)throw new Error("invalid session id");let s=r[0],n=e._OrtEndProfiling(s);n===0&&Oe("Can't get an profile file name."),e._OrtFree(n)},pd=t=>{let e=[];for(let r of t){let s=r[2];!Array.isArray(s)&&"buffer"in s&&e.push(s.buffer)}return e}}),Ar,Ut,Ds,qn,Wn,Hi,jp,Xi,ss,ns,bk,oE,aE,iE,lE,cE,uE,pE,dE=ye(()=>{"use strict";us(),nE(),ps(),Zp(),Ar=()=>!!We.wasm.proxy&&typeof document<"u",Ds=!1,qn=!1,Wn=!1,Xi=new Map,ss=(t,e)=>{let r=Xi.get(t);r?r.push(e):Xi.set(t,[e])},ns=()=>{if(Ds||!qn||Wn||!Ut)throw new Error("worker not ready")},bk=t=>{switch(t.data.type){case"init-wasm":Ds=!1,t.data.err?(Wn=!0,jp[1](t.data.err)):(qn=!0,jp[0]()),Hi&&(URL.revokeObjectURL(Hi),Hi=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=Xi.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},oE=async()=>{if(!qn){if(Ds)throw new Error("multiple calls to 'initWasm()' detected.");if(Wn)throw new Error("previous call to 'initWasm()' failed.");if(Ds=!0,Ar())return new Promise((t,e)=>{Ut?.terminate(),Hk().then(([r,s])=>{try{Ut=s,Ut.onerror=o=>e(o),Ut.onmessage=bk,jp=[t,e];let n={type:"init-wasm",in:We};!n.in.wasm.wasmPaths&&(r||qp)&&(n.in.wasm.wasmPaths={wasm:new URL("ort-wasm-simd-threaded.asyncify.wasm",import.meta.url).href}),Ut.postMessage(n),Hi=r}catch(n){e(n)}},e)});try{await ed(We.wasm),await od(We),qn=!0}catch(t){throw Wn=!0,t}finally{Ds=!1}}},aE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("init-ep",[e,r]);let s={type:"init-ep",in:{epName:t,env:We}};Ut.postMessage(s)});await ad(We,t)},iE=async t=>Ar()?(ns(),new Promise((e,r)=>{ss("copy-from",[e,r]);let s={type:"copy-from",in:{buffer:t}};Ut.postMessage(s,[t.buffer])})):el(t),lE=async(t,e)=>{if(Ar()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return ns(),new Promise((r,s)=>{ss("create",[r,s]);let n={type:"create",in:{model:t,options:{...e}}},o=[];t instanceof Uint8Array&&o.push(t.buffer),Ut.postMessage(n,o)})}else return id(t,e)},cE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("release",[e,r]);let s={type:"release",in:t};Ut.postMessage(s)});ld(t)},uE=async(t,e,r,s,n,o)=>{if(Ar()){if(r.some(a=>a[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(a=>a))throw new Error("pre-allocated output tensor is not supported for proxy.");return ns(),new Promise((a,i)=>{ss("run",[a,i]);let l=r,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:l,outputIndices:s,options:o}};Ut.postMessage(u,pd(l))})}else return cd(t,e,r,s,n,o)},pE=async t=>{if(Ar())return ns(),new Promise((e,r)=>{ss("end-profiling",[e,r]);let s={type:"end-profiling",in:t};Ut.postMessage(s)});ud(t)}}),Gp,vk,fE,BC=ye(()=>{"use strict";us(),dE(),js(),Jp(),Qk(),Gp=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[t.type,t.dims,{mlTensor:t.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},vk=t=>{switch(t[3]){case"cpu":return new Kt(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!rd(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:s,dispose:n}=t[2];return Kt.fromGpuBuffer(r,{dataType:e,dims:t[1],download:s,dispose:n})}case"ml-tensor":{let e=t[0];if(!sd(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:r,download:s,dispose:n}=t[2];return Kt.fromMLTensor(r,{dataType:e,dims:t[1],download:s,dispose:n})}default:throw new Error(`invalid data location: ${t[3]}`)}},fE=class{async fetchModelAndCopyToWasmMemory(t){return iE(await nd(t))}async loadModel(t,e){ls();let r;typeof t=="string"?r=await this.fetchModelAndCopyToWasmMemory(t):r=t,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await lE(r,e),cs()}async dispose(){return cE(this.sessionId)}async run(t,e,r){ls();let s=[],n=[];Object.entries(t).forEach(f=>{let m=f[0],_=f[1],w=this.inputNames.indexOf(m);if(w===-1)throw new Error(`invalid input '${m}'`);s.push(_),n.push(w)});let o=[],a=[];Object.entries(e).forEach(f=>{let m=f[0],_=f[1],w=this.outputNames.indexOf(m);if(w===-1)throw new Error(`invalid output '${m}'`);o.push(_),a.push(w)});let i=s.map((f,m)=>Gp(f,()=>`input "${this.inputNames[n[m]]}"`)),l=o.map((f,m)=>f?Gp(f,()=>`output "${this.outputNames[a[m]]}"`):null),u=await uE(this.sessionId,n,i,a,l,r),d={};for(let f=0;f<u.length;f++)d[this.outputNames[a[f]]]=o[f]??vk(u[f]);return cs(),d}startProfiling(){}endProfiling(){pE(this.sessionId)}}}),mE={};Xn(mE,{OnnxruntimeWebAssemblyBackend:()=>Xp,initializeFlags:()=>Hp,wasmBackend:()=>hE});var Hp,Xp,hE,DC=ye(()=>{"use strict";us(),dE(),BC(),Hp=()=>{(typeof We.wasm.initTimeout!="number"||We.wasm.initTimeout<0)&&(We.wasm.initTimeout=0);let t=We.wasm.simd;if(typeof t!="boolean"&&t!==void 0&&t!=="fixed"&&t!=="relaxed"&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${t}". Reset it to \`false\` and ignore SIMD feature checking.`),We.wasm.simd=!1),typeof We.wasm.proxy!="boolean"&&(We.wasm.proxy=!1),typeof We.wasm.trace!="boolean"&&(We.wasm.trace=!1),typeof We.wasm.numThreads!="number"||!Number.isInteger(We.wasm.numThreads)||We.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)We.wasm.numThreads=1;else{let e=typeof navigator>"u"?gC("node:os").cpus().length:navigator.hardwareConcurrency;We.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}},Xp=class{async init(t){Hp(),await oE(),await aE(t)}async createInferenceSessionHandler(t,e){let r=new fE;return await r.loadModel(t,e),r}},hE=new Xp});us();us();us();var FC="1.25.0-dev.20260212-1a71a5f46e",jC=Fk;{let t=(DC(),Yi(mE)).wasmBackend;is("webgpu",t,5),is("webnn",t,5),is("cpu",t,10),is("wasm",t,10)}Object.defineProperty(We.versions,"web",{value:FC,enumerable:!0});async function _E(t){let e=t.split("/").pop(),r;try{if(r=await Di(),r){let n=await r.match(t);if(n)return n}}catch(n){console.warn(`Failed to load ${e} from cache:`,n)}let s=await fetch(t);if(!s.ok)throw new Error(`Failed to fetch ${e}: ${s.status} ${s.statusText}`);if(r)try{await r.put(t,s.clone())}catch(n){console.warn(`Failed to cache ${e}:`,n)}return s}async function gE(t){let e=await _E(t);if(!e||typeof e=="string")return null;try{return await e.arrayBuffer()}catch(r){return console.warn("Failed to read WASM binary:",r),null}}async function wE(t){let e=await _E(t);if(!e||typeof e=="string")return null;try{let r=await e.text(),s=t.split("/").slice(0,-1).join("/");r=r.replace(/import\.meta\.url/g,`"${s}"`);let n=new Blob([r],{type:"text/javascript"});return URL.createObjectURL(n)}catch(r){return console.warn("Failed to read WASM binary:",r),null}}function fd(t){return Us(t,["blob:"])}function md(t){let e;if(typeof location<"u"&&location.href)e=location.href;else if(typeof import.meta<"u"&&import.meta.url)e=import.meta.url;else return t;return new URL(t,e).href}import{Tensor as AE}from"onnxruntime-common";var qC=Object.freeze({auto:null,gpu:null,cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:{name:"webnn",deviceType:"cpu"},"webnn-npu":{name:"webnn",deviceType:"npu"},"webnn-gpu":{name:"webnn",deviceType:"gpu"},"webnn-cpu":{name:"webnn",deviceType:"cpu"}}),WC=["verbose","info","warning","error","fatal"],vE=4,Bt=[],hd,qs,xE=Symbol.for("onnxruntime");if(xE in globalThis)qs=globalThis[xE];else if(be.IS_NODE_ENV){switch(qs=GC,process.platform){case"win32":Bt.push("dml");break;case"linux":process.arch==="x64"&&Bt.push("cuda");break;case"darwin":Bt.push("coreml");break}Bt.push("webgpu"),Bt.push("cpu"),hd=["cpu"]}else qs=dd,be.IS_WEBNN_AVAILABLE&&Bt.push("webnn-npu","webnn-gpu","webnn-cpu","webnn"),be.IS_WEBGPU_AVAILABLE&&Bt.push("webgpu"),Bt.push("wasm"),hd=["wasm"];var VC=qs.InferenceSession;function kE(t=null){if(!t)return hd;switch(t){case"auto":return Bt;case"gpu":return Bt.filter(e=>["webgpu","cuda","dml","webnn-gpu"].includes(e))}if(Bt.includes(t))return[qC[t]??t];throw new Error(`Unsupported device: "${t}". Should be one of: ${Bt.join(", ")}.`)}var EE=be.IS_BROWSER_ENV||be.IS_WEBWORKER_ENV,yE=Promise.resolve(),Gs=null;async function HC(){return Gs||(De.useWasmCache&&typeof ft?.wasm?.wasmPaths=="object"&&ft?.wasm?.wasmPaths?.wasm&&ft?.wasm?.wasmPaths?.mjs?(Gs=(async()=>{let e=ft.wasm.wasmPaths;await Promise.all([e.wasm&&!fd(e.wasm)?(async()=>{try{let r=await gE(md(e.wasm));r&&(ft.wasm.wasmBinary=r)}catch(r){console.warn("Failed to pre-load WASM binary:",r)}})():Promise.resolve(),e.mjs&&!fd(e.mjs)?(async()=>{try{let r=await wE(md(e.mjs));r&&(ft.wasm.wasmPaths.mjs=r)}catch(r){console.warn("Failed to pre-load WASM factory:",r)}})():Promise.resolve()])})(),Gs):(Gs=Promise.resolve(),Gs))}async function tl(t,e,r){await HC();let s=()=>VC.create(t,{logSeverityLevel:vE,...e}),n=await(EE?yE=yE.then(s):s());return n.config=r,n}var bE=Promise.resolve();async function rl(t,e){let r=()=>t.run(e);return await(EE?bE=bE.then(r):r())}function sl(t){return t instanceof qs.Tensor}var ft=qs?.env;ft.logLevel=WC[vE];if(ft?.wasm){if(!(typeof ServiceWorkerGlobalScope<"u"&&self instanceof ServiceWorkerGlobalScope)&&ft.versions?.web&&!ft.wasm.wasmPaths){let t=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${ft.versions.web}/dist/`;ft.wasm.wasmPaths=be.IS_SAFARI?{mjs:`${t}ort-wasm-simd-threaded.mjs`,wasm:`${t}ort-wasm-simd-threaded.wasm`}:{mjs:`${t}ort-wasm-simd-threaded.asyncify.mjs`,wasm:`${t}ort-wasm-simd-threaded.asyncify.wasm`}}ft.wasm.proxy=!1}ft?.webgpu&&(ft.webgpu.powerPreference="high-performance");function Kn(){return ft?.wasm?.proxy}De.backends.onnx=ft;var Sr=async(t,e,r)=>{let s=await tl(new Uint8Array(t),e);return(async n=>{let o=Kn(),a=Object.fromEntries(Object.entries(n).map(([l,u])=>[l,(o?u.clone():u).ort_tensor])),i=await rl(s,a);return Array.isArray(r)?r.map(l=>new U(i[l])):new U(i[r])})},nr=class{static session_options={};static get nearest_interpolate_4d(){return this._nearest_interpolate_4d||(this._nearest_interpolate_4d=Sr([8,10,18,0,58,129,1,10,41,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,18,10,4,109,111,100,101,34,7,110,101,97,114,101,115,116,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,21],this.session_options,"y")),this._nearest_interpolate_4d}static get bilinear_interpolate_4d(){return this._bilinear_interpolate_4d||(this._bilinear_interpolate_4d=Sr([8,9,18,0,58,128,1,10,40,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,17,10,4,109,111,100,101,34,6,108,105,110,101,97,114,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bilinear_interpolate_4d}static get bicubic_interpolate_4d(){return this._bicubic_interpolate_4d||(this._bicubic_interpolate_4d=Sr([8,9,18,0,58,127,10,39,10,1,120,10,0,10,0,10,1,115,18,1,121,34,6,82,101,115,105,122,101,42,16,10,4,109,111,100,101,34,5,99,117,98,105,99,160,1,3,18,1,114,90,31,10,1,120,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,90,15,10,1,115,18,10,10,8,8,7,18,4,10,2,8,4,98,31,10,1,121,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,99,10,3,18,1,104,10,3,18,1,119,66,2,16,20],this.session_options,"y")),this._bicubic_interpolate_4d}static get matmul(){return this._matmul||(this._matmul=Sr([8,9,18,0,58,55,10,17,10,1,97,10,1,98,18,1,99,34,6,77,97,116,77,117,108,18,1,114,90,9,10,1,97,18,4,10,2,8,1,90,9,10,1,98,18,4,10,2,8,1,98,9,10,1,99,18,4,10,2,8,1,66,2,16,20],this.session_options,"c")),this._matmul}static get stft(){return this._stft||(this._stft=Sr([8,7,18,0,58,148,1,10,38,10,1,115,10,1,106,10,1,119,10,1,108,18,1,111,34,4,83,84,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,115,90,26,10,1,115,18,21,10,19,8,1,18,15,10,3,18,1,98,10,3,18,1,115,10,3,18,1,99,90,11,10,1,106,18,6,10,4,8,7,18,0,90,16,10,1,119,18,11,10,9,8,1,18,5,10,3,18,1,119,90,11,10,1,108,18,6,10,4,8,7,18,0,98,31,10,1,111,18,26,10,24,8,1,18,20,10,3,18,1,98,10,3,18,1,102,10,3,18,1,100,10,3,18,1,99,66,2,16,17],this.session_options,"o")),this._stft}static get rfft(){return this._rfft||(this._rfft=Sr([8,9,18,0,58,97,10,33,10,1,120,10,0,10,1,97,18,1,121,34,3,68,70,84,42,15,10,8,111,110,101,115,105,100,101,100,24,1,160,1,2,18,1,100,90,21,10,1,120,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,90,11,10,1,97,18,6,10,4,8,7,18,0,98,21,10,1,121,18,16,10,14,8,1,18,10,10,3,18,1,115,10,3,18,1,99,66,2,16,20],this.session_options,"y")),this._rfft}static get top_k(){return this._top_k||(this._top_k=Sr([8,10,18,0,58,73,10,18,10,1,120,10,1,107,18,1,118,18,1,105,34,4,84,111,112,75,18,1,116,90,9,10,1,120,18,4,10,2,8,1,90,15,10,1,107,18,10,10,8,8,7,18,4,10,2,8,1,98,9,10,1,118,18,4,10,2,8,1,98,9,10,1,105,18,4,10,2,8,7,66,2,16,21],this.session_options,["v","i"])),this._top_k}static get slice(){return this._slice||(this._slice=Sr([8,7,18,0,58,96,10,25,10,1,120,10,1,115,10,1,101,10,1,97,10,1,116,18,1,121,34,5,83,108,105,99,101,18,1,114,90,9,10,1,120,18,4,10,2,8,1,90,9,10,1,115,18,4,10,2,8,7,90,9,10,1,101,18,4,10,2,8,7,90,9,10,1,97,18,4,10,2,8,7,90,9,10,1,116,18,4,10,2,8,7,98,9,10,1,121,18,4,10,2,8,1,66,2,16,13],this.session_options,"y")),this._slice}};var ME=Object.freeze({auto:"auto",gpu:"gpu",cpu:"cpu",wasm:"wasm",webgpu:"webgpu",cuda:"cuda",dml:"dml",coreml:"coreml",webnn:"webnn","webnn-npu":"webnn-npu","webnn-gpu":"webnn-gpu","webnn-cpu":"webnn-cpu"});var TE=(function(){let t;return async function(){if(t===void 0)if(!be.IS_WEBGPU_AVAILABLE)t=!1;else try{t=(await navigator.gpu.requestAdapter()).features.has("shader-f16")}catch{t=!1}return t}})(),mt=Object.freeze({auto:"auto",fp32:"fp32",fp16:"fp16",q8:"q8",int8:"int8",uint8:"uint8",q4:"q4",bnb4:"bnb4",q4f16:"q4f16"}),_d=Object.freeze({[ME.wasm]:mt.q8}),gd=Object.freeze({[mt.fp32]:"",[mt.fp16]:"_fp16",[mt.int8]:"_int8",[mt.uint8]:"_uint8",[mt.q8]:"_quantized",[mt.q4]:"_q4",[mt.q4f16]:"_q4f16",[mt.bnb4]:"_bnb4"}),Ws=Object.freeze({float32:Float32Array,float16:typeof Float16Array<"u"?Float16Array:Uint16Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array,uint4:Uint8Array,int4:Int8Array});var U=class t{get dims(){return this.ort_tensor.dims}set dims(e){this.ort_tensor.dims=e}get type(){return this.ort_tensor.type}get data(){return this.ort_tensor.data}get size(){return this.ort_tensor.size}get location(){return this.ort_tensor.location}ort_tensor;constructor(...e){return sl(e[0])?this.ort_tensor=e[0]:this.ort_tensor=new AE(e[0],e[1],e[2]),new Proxy(this,{get:(r,s)=>{if(typeof s=="string"){let n=Number(s);if(Number.isInteger(n))return r._getitem(n)}return r[s]},set:(r,s,n)=>r[s]=n})}dispose(){this.ort_tensor.dispose()}*[Symbol.iterator](){let[e,...r]=this.dims;if(r.length>0){let s=r.reduce((n,o)=>n*o);for(let n=0;n<e;++n)yield this._subarray(n,s,r)}else yield*this.data}_getitem(e){let[r,...s]=this.dims;if(e=or(e,r),s.length>0){let n=s.reduce((o,a)=>o*a);return this._subarray(e,n,s)}else return new t(this.type,[this.data[e]],s)}indexOf(e){let r=this.data;for(let s=0;s<r.length;++s)if(r[s]==e)return s;return-1}_subarray(e,r,s){let n=e*r,o=(e+1)*r,a="subarray"in this.data?this.data.subarray(n,o):this.data.slice(n,o);return new t(this.type,a,s)}item(){let e=this.data;if(e.length!==1)throw new Error(`a Tensor with ${e.length} elements cannot be converted to Scalar`);return e[0]}tolist(){return XC(this.data,this.dims)}sigmoid(){return this.clone().sigmoid_()}sigmoid_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=1/(1+Math.exp(-e[r]));return this}map(e){return this.clone().map_(e)}map_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]=e(r[s],s,r);return this}mul(e){return this.clone().mul_(e)}mul_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]*=e;return this}div(e){return this.clone().div_(e)}div_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]/=e;return this}add(e){return this.clone().add_(e)}add_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]+=e;return this}sub(e){return this.clone().sub_(e)}sub_(e){let r=this.data;for(let s=0;s<r.length;++s)r[s]-=e;return this}clone(){return new t(this.type,this.data.slice(),this.dims.slice())}slice(...e){let r=[],s=[];for(let d=0;d<this.dims.length;++d){let f=e[d];if(f==null)s.push([0,this.dims[d]]),r.push(this.dims[d]);else if(typeof f=="number")f=or(f,this.dims[d],d),s.push([f,f+1]);else if(Array.isArray(f)&&f.length===2){let[m,_]=f;if(m=m===null?0:or(m,this.dims[d],d,!1),_=_===null?this.dims[d]:or(_,this.dims[d],d,!1),m>_)throw new Error(`Invalid slice: ${f}`);let w=[Math.max(m,0),Math.min(_,this.dims[d])];s.push(w),r.push(w[1]-w[0])}else throw new Error(`Invalid slice: ${f}`)}let n=s.map(([d,f])=>f-d),o=n.reduce((d,f)=>d*f),a=this.data,i=new a.constructor(o),l=this.stride(),u=!0;for(let d=1;d<n.length;++d)if(s[d][0]!==0||s[d][1]!==this.dims[d]){u=!1;break}if(u){let d=s[0][0]*l[0],f=s[0][1]*l[0];if(ArrayBuffer.isView(a))i.set(a.subarray(d,f));else if(Array.isArray(a)){let m=a.slice(d,f);for(let _=0;_<m.length;++_)i[_]=m[_]}else throw new Error("Unsupported data type for slicing")}else for(let d=0;d<o;++d){let f=0;for(let m=n.length-1,_=d;m>=0;--m){let w=n[m];f+=(_%w+s[m][0])*l[m],_=Math.floor(_/w)}i[d]=a[f]}return new t(this.type,i,r)}permute(...e){return KC(this,e)}transpose(...e){return this.permute(...e)}sum(e=null,r=!1){return this.norm(1,e,r)}norm(e="fro",r=null,s=!1){if(e==="fro")e=2;else if(typeof e=="string")throw Error(`Unsupported norm: ${e}`);let n=this.data,o=(u,d)=>u+d**e;if(r===null){let u=n.reduce(o,0)**(1/e);return new t(this.type,[u],[])}let[a,i,l]=Yn(o,this,r,s);if(e!==1)for(let u=0;u<i.length;++u)i[u]=i[u]**(1/e);return new t(a,i,l)}normalize_(e=2,r=1){r=or(r,this.dims.length);let s=this.norm(e,r,!0),n=this.data,o=s.data;for(let a=0;a<n.length;++a){let i=0;for(let l=this.dims.length-1,u=a,d=1;l>=0;--l){let f=this.dims[l];if(l!==r){let m=u%f;i+=m*d,d*=this.dims[l]}u=Math.floor(u/f)}n[a]/=o[i]}return this}normalize(e=2,r=1){return this.clone().normalize_(e,r)}stride(){return wd(this.dims)}squeeze(e=null){return new t(this.type,this.data,SE(this.dims,e))}squeeze_(e=null){return this.dims=SE(this.dims,e),this}unsqueeze(e){return new t(this.type,this.data,OE(this.dims,e))}unsqueeze_(e){return this.dims=OE(this.dims,e),this}flatten_(e=0,r=-1){r=(r+this.dims.length)%this.dims.length;let s=this.dims.slice(0,e),n=this.dims.slice(e,r+1),o=this.dims.slice(r+1);return this.dims=[...s,n.reduce((a,i)=>a*i,1),...o],this}flatten(e=0,r=-1){return this.clone().flatten_(e,r)}view(...e){let r=-1;for(let n=0;n<e.length;++n)if(e[n]===-1){if(r!==-1)throw new Error("Only one dimension can be inferred");r=n}let s=this.data;if(r!==-1){let n=e.reduce((o,a,i)=>i!==r?o*a:o,1);e[r]=s.length/n}return new t(this.type,s,e)}neg_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=-e[r];return this}neg(){return this.clone().neg_()}gt(e){let r=new Uint8Array(this.data.length),s=this.data;for(let n=0;n<s.length;++n)r[n]=s[n]>e?1:0;return new t("bool",r,this.dims)}lt(e){let r=new Uint8Array(this.data.length),s=this.data;for(let n=0;n<s.length;++n)r[n]=s[n]<e?1:0;return new t("bool",r,this.dims)}clamp_(e,r){let s=this.data;for(let n=0;n<s.length;++n)s[n]=Math.min(Math.max(s[n],e),r);return this}clamp(e,r){return this.clone().clamp_(e,r)}round_(){let e=this.data;for(let r=0;r<e.length;++r)e[r]=Math.round(e[r]);return this}round(){return this.clone().round_()}mean(e=null,r=!1){return al(this,e,r)}min(e=null,r=!1){if(e===null){let a=Dn(this.data)[0];return new t(this.type,[a],[])}let[s,n,o]=Yn((a,i)=>Math.min(a,i),this,e,r,1/0);return new t(s,n,o)}max(e=null,r=!1){if(e===null){let a=Te(this.data)[0];return new t(this.type,[a],[])}let[s,n,o]=Yn((a,i)=>Math.max(a,i),this,e,r,-1/0);return new t(s,n,o)}argmin(e=null,r=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let s=Dn(this.data)[1];return new t("int64",[BigInt(s)],[])}argmax(e=null,r=!1){if(e!==null)throw new Error("`dim !== null` not yet implemented.");let s=Te(this.data)[1];return new t("int64",[BigInt(s)],[])}repeat(...e){if(e.length<this.dims.length)throw new Error(`Number of dimensions of repeat dims (${e.length}) cannot be smaller than number of dimensions of tensor (${this.dims.length})`);if(e.every(d=>d===1)){if(e.length===this.dims.length)return this.clone();let d=e.length-this.dims.length,f=Array(d).fill(1).concat(this.dims);return new t(this.type,this.data.slice(),f)}let r=e.length-this.dims.length,s=Array(r).fill(1).concat(this.dims),n=s.map((d,f)=>d*e[f]),o=n.reduce((d,f)=>d*f,1),a=this.data,i=new a.constructor(o),l=wd(s),u=wd(n);for(let d=0;d<o;++d){let f=d,m=0;for(let _=0;_<n.length;++_){let w=Math.floor(f/u[_]);f=f%u[_];let x=w%s[_];m+=x*l[_]}i[d]=a[m]}return new t(this.type,i,n)}tile(...e){if(e.length<this.dims.length){let r=this.dims.length-e.length;e=Array(r).fill(1).concat(e)}return this.repeat(...e)}to(e){if(this.type===e)return this;if(!Ws.hasOwnProperty(e))throw new Error(`Unsupported type: ${e}`);let r,s=["int64","uint64"].includes(this.type),n=["int64","uint64"].includes(e);if(s&&!n)r=Number;else if(!s&&n)["float16","float32","float64"].includes(this.type)?r=o=>BigInt(Math.floor(o)):r=BigInt;else if(this.type==="float16"&&e=="float32"&&this.data instanceof Uint16Array)return new t(e,Kv(this.data),this.dims);return new t(e,Ws[e].from(this.data,r),this.dims)}};function XC(t,e){let r=t.length,s=e.reduce((o,a)=>o*a);if(r!==s)throw Error(`cannot reshape array of size ${r} into shape (${e})`);let n=t;for(let o=e.length-1;o>=0;o--)n=n.reduce((a,i)=>{let l=a[a.length-1];return l.length<e[o]?l.push(i):a.push([i]),a},[[]]);return n[0]}function KC(t,e){let[r,s]=Gv(t.data,t.dims,e);return new U(t.type,r,s)}function xd(t,[e,r],s="bilinear",n=!1){let o=t.dims.at(-3)??1,a=t.dims.at(-2),i=t.dims.at(-1),l=jv(t.data,[o,a,i],[e,r],s,n);return new U(t.type,l,[o,e,r])}async function Dt(t,{size:e=null,mode:r="bilinear"}={}){if(t.dims.length!==4)throw new Error("`interpolate_4d` currently only supports 4D input.");if(!e)throw new Error("`interpolate_4d` requires a `size` argument.");let s;if(e.length===2)s=[...t.dims.slice(0,2),...e];else if(e.length===3)s=[t.dims[0],...e];else if(e.length===4)s=e;else throw new Error("`size` must be of length 2, 3, or 4.");let n;if(r==="nearest")n=await nr.nearest_interpolate_4d;else if(r==="bilinear")n=await nr.bilinear_interpolate_4d;else if(r==="bicubic")n=await nr.bicubic_interpolate_4d;else throw new Error(`Unsupported mode: ${r}`);let o=new U("int64",new BigInt64Array(s.map(BigInt)),[s.length]);return await n({x:t,s:o})}async function IE(t,e){return await(await nr.matmul)({a:t,b:e})}async function QN(t,e){return await(await nr.rfft)({x:t,a:e})}async function Yt(t,e){let r=await nr.top_k;return e==null?e=t.dims.at(-1):e=Math.min(e,t.dims.at(-1)),await r({x:t,k:new U("int64",[BigInt(e)],[1])})}var nl=t=>new U("int64",t,[t.length]);async function ol(t,e,r,s,n){return await(await nr.slice)({x:t,s:nl(e),e:nl(r),a:nl(s),t:nl(n??new Array(s.length).fill(1))})}function CE(t,e){let r=t.data,s=e.data,n=[t.dims[0],t.dims[2]],o=new r.constructor(n[0]*n[1]),[a,i,l]=t.dims,u=0;for(let d=0;d<a;++d){let f=d*l*i;for(let m=0;m<l;++m){let _=0,w=0,x=d*i,k=f+m;for(let M=0;M<i;++M){let I=Number(s[x+M]);w+=I,_+=r[k+M*l]*I}let E=_/w;o[u++]=E}}return new U(t.type,o,n)}function JN(t,e,{eps:r=1e-5}={}){if(t.dims.length!==2)throw new Error("`layer_norm` currently only supports 2D input.");let[s,n]=t.dims;if(e.length!==1&&e[0]!==n)throw new Error("`normalized_shape` must be a 1D array with shape `[input.dims[1]]`.");let[o,a]=yd(t,1,0,!0),i=o.data,l=a.data,u=t.data,d=new u.constructor(u.length);for(let f=0;f<s;++f){let m=f*n;for(let _=0;_<n;++_){let w=m+_;d[w]=(u[w]-l[f])/(i[f]+r)}}return new U(t.type,d,t.dims)}function SE(t,e){return t=t.slice(),e===null?t=t.filter(r=>r!==1):typeof e=="number"?t[e]===1&&t.splice(e,1):Array.isArray(e)&&(t=t.filter((r,s)=>r!==1||!e.includes(s))),t}function OE(t,e){return e=or(e,t.length+1),t=t.slice(),t.splice(e,0,1),t}function or(t,e,r=null,s=!0){if(t<-e||t>=e){if(s)throw new Error(`IndexError: index ${t} is out of bounds for dimension${r===null?"":" "+r} with size ${e}`);return t<-e?0:e}return t<0&&(t=(t%e+e)%e),t}function Ee(t,e=0){e=or(e,t[0].dims.length);let r=t[0].dims.slice();r[e]=t.reduce((a,i)=>a+i.dims[e],0);let s=r.reduce((a,i)=>a*i,1),n=new t[0].data.constructor(s),o=t[0].type;if(e===0){let a=0;for(let i of t){let l=i.data;n.set(l,a),a+=l.length}}else{let a=0;for(let i=0;i<t.length;++i){let{data:l,dims:u}=t[i];for(let d=0;d<l.length;++d){let f=0;for(let m=u.length-1,_=d,w=1;m>=0;--m){let x=u[m],k=_%x;m===e&&(k+=a),f+=k*w,w*=r[m],_=Math.floor(_/x)}n[f]=l[d]}a+=u[e]}}return new U(o,n,r)}function Ft(t,e=0){return Ee(t.map(r=>r.unsqueeze(e)),e)}function Yn(t,e,r,s=!1,n=null){let o=e.data,a=e.dims;r=or(r,a.length);let i=a.slice();i[r]=1;let l=new o.constructor(o.length/a[r]);n!==null&&l.fill(n);for(let u=0;u<o.length;++u){let d=0;for(let f=a.length-1,m=u,_=1;f>=0;--f){let w=a[f];if(f!==r){let x=m%w;d+=x*_,_*=i[f]}m=Math.floor(m/w)}l[d]=t(l[d],o[u],u,d)}return s||i.splice(r,1),[e.type,l,i]}function yd(t,e=null,r=1,s=!1){let n=t.data,o=t.dims;if(e===null){let _=n.reduce((E,M)=>E+M,0)/n.length,w=Math.sqrt(n.reduce((E,M)=>E+(M-_)**2,0)/(n.length-r)),x=new U(t.type,[_],[]);return[new U(t.type,[w],[]),x]}e=or(e,o.length);let a=al(t,e,s),i=a.data,[l,u,d]=Yn((m,_,w,x)=>m+(_-i[x])**2,t,e,s);for(let m=0;m<u.length;++m)u[m]=Math.sqrt(u[m]/(o[e]-r));return[new U(l,u,d),a]}function al(t,e=null,r=!1){let s=t.dims,n=t.data;if(e===null){let l=n.reduce((u,d)=>u+d,0);return new U(t.type,[l/n.length],[])}e=or(e,s.length);let[o,a,i]=Yn((l,u)=>l+u,t,e,r);if(s[e]!==1)for(let l=0;l<a.length;++l)a[l]/=s[e];return new U(o,a,i)}function wd(t){let e=new Array(t.length);for(let r=t.length-1,s=1;r>=0;--r)e[r]=s,s*=t[r];return e}function bd(t,e,r,s){let n=t.reduce((o,a)=>o*a,1);return new U(r,new s(n).fill(e),t)}function Ve(t,e){let r,s;if(typeof e=="number")r="float32",s=Float32Array;else if(typeof e=="bigint")r="int64",s=BigInt64Array;else if(typeof e=="boolean")r="bool",s=Uint8Array;else throw new Error(`Unsupported data type: ${typeof e}`);return bd(t,e,r,s)}function Qn(t,e){return Ve(t.dims,e)}function it(t){return bd(t,1n,"int64",BigInt64Array)}function il(t){return it(t.dims)}function vd(t){return bd(t,0n,"int64",BigInt64Array)}function kd(t){return vd(t.dims)}function ZN(t){let e=t.reduce((r,s)=>r*s,1);return new U("float32",Float32Array.from({length:e},()=>Math.random()),t)}function PE(t){let e=t.reduce((s,n)=>s*n,1),r=new Float32Array(e);for(let s=0;s<e;s+=2){let n=1-Math.random(),o=Math.random(),a=Math.sqrt(-2*Math.log(n)),i=2*Math.PI*o;r[s]=a*Math.cos(i),s+1<e&&(r[s+1]=a*Math.sin(i))}return new U("float32",r,t)}function zE(t,e){if(t.dims.length!==2)throw new Error("The tensor must have 2 dimensions");if(t.dims.at(-1)%8!==0)throw new Error("The last dimension of the tensor must be a multiple of 8");if(!["binary","ubinary"].includes(e))throw new Error("The precision must be either 'binary' or 'ubinary'");let r=e==="binary",s=r?"int8":"uint8",n=r?Int8Array:Uint8Array,o=t.data,a=new n(o.length/8);for(let i=0;i<o.length;++i){let l=o[i]>0?1:0,u=Math.floor(i/8),d=i%8;a[u]|=l<<7-d,r&&d===0&&(a[u]-=128)}return new U(s,a,[t.dims[0],t.dims[1]/8])}async function Ed(t,e){return await Promise.all([at(t,"tokenizer.json",!0,e),at(t,"tokenizer_config.json",!0,e)])}function Ad(t){let e=t.dims;switch(e.length){case 1:return t.tolist();case 2:if(e[0]!==1)throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");return t.tolist()[0];default:throw new Error(`Expected tensor to have 1-2 dimensions, got ${e.length}.`)}}var YC=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function QC(t,e,r,s){for(let n of Object.keys(t)){let o=e-t[n].length,a=r(n),i=new Array(o).fill(a);t[n]=s==="right"?dt(t[n],i):dt(i,t[n])}}function JC(t,e){for(let r of Object.keys(t))t[r].length=e}function ds(t,...e){for(let r of e){if(!Object.hasOwn(t,r))continue;let s=t[r];if(s)if(typeof s=="object"){if(s.__type==="AddedToken")return s.content;throw Error(`Unknown token: ${s}`)}else return s}return null}function ZC(t){let e=[];for(let r of t.get_added_tokens_decoder().values())r.special&&e.push(r);return e}var j=class extends Je{return_token_type_ids=!1;padding_side="right";constructor(e,r){if(super(),this._tokenizerJSON=e,this._tokenizerConfig=r,this._tokenizer=new xv(e,r),this.config=r,this.padding_side=r.padding_side??this.padding_side,this.mask_token=ds(r,"mask_token"),this.mask_token_id=this._tokenizer.token_to_id(this.mask_token),this.pad_token=ds(r,"pad_token","eos_token"),this.pad_token_id=this._tokenizer.token_to_id(this.pad_token),this.sep_token=ds(r,"sep_token"),this.sep_token_id=this._tokenizer.token_to_id(this.sep_token),this.unk_token=ds(r,"unk_token"),this.unk_token_id=this._tokenizer.token_to_id(this.unk_token),this.bos_token=ds(r,"bos_token"),this.bos_token_id=this._tokenizer.token_to_id(this.bos_token),this.eos_token=ds(r,"eos_token"),this.eos_token_id=this._tokenizer.token_to_id(this.eos_token),this.chat_template=r.chat_template??null,Array.isArray(this.chat_template)){let n=Object.create(null);for(let{name:o,template:a}of this.chat_template){if(typeof o!="string"||typeof a!="string")throw new Error('Chat template must be a list of objects with "name" and "template" properties');n[o]=a}this.chat_template=n}this._compiled_template_cache=new Map;let s=ZC(this._tokenizer);this.all_special_ids=s.map(n=>n.id),this.all_special_tokens=s.map(n=>n.content)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){let i=await Ed(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a});return new this(...i)}get_vocab(){return this._tokenizer.get_vocab()}get model_max_length(){return this._tokenizerConfig.model_max_length??1/0}get add_eos_token(){return this._tokenizerConfig.add_eos_token}get add_bos_token(){return this._tokenizerConfig.add_bos_token}convert_tokens_to_ids(e){return typeof e=="string"?this._tokenizer.token_to_id(e):e.map(r=>this._tokenizer.token_to_id(r))}_call(e,{text_pair:r=null,add_special_tokens:s=!0,padding:n=!1,truncation:o=null,max_length:a=null,return_tensor:i=!0,return_token_type_ids:l=null}={}){let u=Array.isArray(e),d;if(u){if(e.length===0)throw Error("text array must be non-empty");if(r!==null){if(Array.isArray(r)){if(e.length!==r.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");d=e.map((m,_)=>this._encode_plus(m,{text_pair:r[_],add_special_tokens:s,return_token_type_ids:l}))}else d=e.map(m=>this._encode_plus(m,{add_special_tokens:s,return_token_type_ids:l}))}else{if(e==null)throw Error("text may not be null or undefined");if(Array.isArray(r))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");d=[this._encode_plus(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:l})]}if(a===null?a=this.model_max_length:o===null&&(n===!0?(console.warn("`max_length` is ignored when `padding: true` and there is no truncation strategy. To pad to max length, use `padding: 'max_length'`."),a=this.model_max_length):n===!1&&(console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation: true` to explicitly truncate examples to max length."),o=!0)),n===!0&&(a=Math.min(Te(d.map(m=>m.input_ids.length))[0],a??1/0)),a=Math.min(a,this.model_max_length??1/0),n||o)for(let m=0;m<d.length;++m)d[m].input_ids.length!==a&&(d[m].input_ids.length>a?o&&JC(d[m],a):n&&QC(d[m],a,_=>_==="input_ids"?this.pad_token_id:0,this.padding_side));let f={};if(i){if(!(n&&o)&&d.some(_=>{for(let w of Object.keys(_))if(_[w].length!==d[0][w]?.length)return!0;return!1}))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");let m=[d.length,d[0].input_ids.length];for(let _ of Object.keys(d[0]))f[_]=new U("int64",BigInt64Array.from(d.flatMap(w=>w[_]).map(BigInt)),m)}else{for(let m of Object.keys(d[0]))f[m]=d.map(_=>_[m]);if(!u)for(let m of Object.keys(f))f[m]=f[m][0]}return f}_encode_text(e){return e===null?null:this._tokenizer.encode(e).tokens}_encode_plus(e,{text_pair:r=null,add_special_tokens:s=!0,return_token_type_ids:n=null}={}){let{ids:o,attention_mask:a,token_type_ids:i}=this._tokenizer.encode(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:n??this.return_token_type_ids});return{input_ids:o,attention_mask:a,...i?{token_type_ids:i}:{}}}tokenize(e,{pair:r=null,add_special_tokens:s=!1}={}){return this._tokenizer.tokenize(e,{text_pair:r,add_special_tokens:s})}encode(e,{text_pair:r=null,add_special_tokens:s=!0,return_token_type_ids:n=null}={}){return this._tokenizer.encode(e,{text_pair:r,add_special_tokens:s,return_token_type_ids:n}).ids}batch_decode(e,r={}){return e instanceof U&&(e=e.tolist()),e.map(s=>this.decode(s,r))}decode(e,r={}){if(e instanceof U&&(e=Ad(e)),!Array.isArray(e)||e.length===0||!Pv(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,r)}decode_single(e,{skip_special_tokens:r=!1,clean_up_tokenization_spaces:s=null}){return this._tokenizer.decode(e,{skip_special_tokens:r,clean_up_tokenization_spaces:s})}get_chat_template({chat_template:e=null,tools:r=null}={}){if(this.chat_template&&typeof this.chat_template=="object"){let s=this.chat_template;if(e!==null&&Object.hasOwn(s,e))e=s[e];else if(e===null)if(r!==null&&"tool_use"in s)e=s.tool_use;else if("default"in s)e=s.default;else throw Error(`This model has multiple chat templates with no default specified! Please either pass a chat template or the name of the template you wish to use to the 'chat_template' argument. Available template names are ${Object.keys(s).sort()}.`)}else if(e===null)if(this.chat_template)e=this.chat_template;else throw Error("Cannot use apply_chat_template() because tokenizer.chat_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat_template attribute, please see the documentation at https://huggingface.co/docs/transformers/main/en/chat_templating");return e}apply_chat_template(e,{tools:r=null,documents:s=null,chat_template:n=null,add_generation_prompt:o=!1,tokenize:a=!0,padding:i=!1,truncation:l=!1,max_length:u=null,return_tensor:d=!0,return_dict:f=!0,tokenizer_kwargs:m={},..._}={}){if(n=this.get_chat_template({chat_template:n,tools:r}),typeof n!="string")throw Error(`chat_template must be a string, but got ${typeof n}`);let w=this._compiled_template_cache.get(n);w===void 0&&(w=new Cv(n),this._compiled_template_cache.set(n,w));let x=Object.create(null);for(let E of YC){let M=ds(this.config,E);M&&(x[E]=M)}let k=w.render({messages:e,add_generation_prompt:o,tools:r,documents:s,...x,..._});if(a){let E=this._call(k,{add_special_tokens:!1,padding:i,truncation:l,max_length:u,return_tensor:d,...m});return f?E:E.input_ids}return k}};function Vs(t,e,r,s){if(!("language_codes"in t)||!Array.isArray(t.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in t)||!(t.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in t)||typeof t.lang_to_token!="function")throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");let n=s.src_lang,o=s.tgt_lang;if(!t.language_codes.includes(o))throw new Error(`Target language code "${o}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);if(n!==void 0){if(!t.language_codes.includes(n))throw new Error(`Source language code "${n}" is not valid. Must be one of: {${t.language_codes.join(", ")}}`);for(let a of t._tokenizer.post_processor.config.single)if("SpecialToken"in a&&t.languageRegex.test(a.SpecialToken.id)){a.SpecialToken.id=t.lang_to_token(n);break}}return s.forced_bos_token_id=t._tokenizer.token_to_id(t.lang_to_token(o)),t._call(e,r)}var gf={};Ps(gf,{AlbertTokenizer:()=>Md,AutoTokenizer:()=>J,BartTokenizer:()=>Td,BertTokenizer:()=>Sd,BlenderbotSmallTokenizer:()=>Od,BlenderbotTokenizer:()=>Id,BloomTokenizer:()=>Cd,CLIPTokenizer:()=>zd,CamembertTokenizer:()=>Pd,CodeGenTokenizer:()=>Nd,CodeLlamaTokenizer:()=>Ld,CohereTokenizer:()=>$d,ConvBertTokenizer:()=>Rd,DebertaTokenizer:()=>Bd,DebertaV2Tokenizer:()=>Ud,DistilBertTokenizer:()=>Dd,ElectraTokenizer:()=>Fd,EsmTokenizer:()=>jd,FalconTokenizer:()=>Gd,GPT2Tokenizer:()=>Vd,GPTNeoXTokenizer:()=>Wd,GemmaTokenizer:()=>qd,HerbertTokenizer:()=>Hd,LlamaTokenizer:()=>Xd,M2M100Tokenizer:()=>Kd,MBart50Tokenizer:()=>Qd,MBartTokenizer:()=>Jn,MPNetTokenizer:()=>ef,MarianTokenizer:()=>Yd,MgpstrTokenizer:()=>Jd,MobileBertTokenizer:()=>Zd,NllbTokenizer:()=>tf,NougatTokenizer:()=>rf,PreTrainedTokenizer:()=>j,Qwen2Tokenizer:()=>sf,RoFormerTokenizer:()=>of,RobertaTokenizer:()=>nf,SiglipTokenizer:()=>af,SpeechT5Tokenizer:()=>lf,SqueezeBertTokenizer:()=>cf,T5Tokenizer:()=>uf,TokenizersBackend:()=>j,VitsTokenizer:()=>df,Wav2Vec2CTCTokenizer:()=>ff,WhisperTokenizer:()=>mf,XLMRobertaTokenizer:()=>hf,XLMTokenizer:()=>_f});var Md=class extends j{return_token_type_ids=!0};var Td=class extends j{};var Sd=class extends j{return_token_type_ids=!0};var Od=class extends j{};var Id=class extends j{};var Cd=class extends j{};var Pd=class extends j{};var zd=class extends j{};var Ld=class extends j{};var Nd=class extends j{};var $d=class extends j{};var Rd=class extends j{return_token_type_ids=!0};var Ud=class extends j{return_token_type_ids=!0};var Bd=class extends j{return_token_type_ids=!0};var Dd=class extends j{};var Fd=class extends j{return_token_type_ids=!0};var jd=class extends j{};var Gd=class extends j{};var qd=class extends j{};var Wd=class extends j{};var Vd=class extends j{};var Hd=class extends j{return_token_type_ids=!0};var Xd=class extends j{padding_side="left"};var Kd=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)).map(s=>s.slice(2,-2)),this.lang_to_token=s=>`__${s}__`}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var Yd=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=Array.from(this.get_vocab().keys()).filter(s=>this.languageRegex.test(s)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;let[r,...s]=e.trim().split(this.languageRegex);if(s.length===0)return super._encode_text(r);if(s.length===2){let[n,o]=s;return this.supported_language_codes.includes(n)||console.warn(`Unsupported language code "${n}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),dt([n],super._encode_text(o))}}};var Jn=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)).map(s=>s),this.lang_to_token=s=>s}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var Qd=class extends Jn{};var Jd=class extends j{};var Zd=class extends j{return_token_type_ids=!0};var ef=class extends j{};var tf=class extends j{constructor(e,r){super(e,r),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.all_special_tokens.filter(s=>this.languageRegex.test(s)),this.lang_to_token=s=>s}_build_translation_inputs(e,r,s){return Vs(this,e,r,s)}};var rf=class extends j{};var sf=class extends j{};var nf=class extends j{};var of=class extends j{return_token_type_ids=!0};var af=class extends j{};var lf=class extends j{};var cf=class extends j{return_token_type_ids=!0};var uf=class extends j{};var pf=class extends $t{decode_chain(e){let r="";for(let s=1;s<e.length;s+=2)r+=e[s];return[r]}},df=class extends j{constructor(e,r){super(e,r),this._tokenizer.decoder=new pf({type:"VitsDecoder"})}};var ff=class extends j{};var LE=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],Zn=new Map(LE),eP=new Map([...LE.map(([t,e])=>[e,t]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);function NE(t){t=t.toLowerCase();let e=eP.get(t);if(e===void 0){let r=t.match(/^<\|([a-z]{2})\|>$/);if(r&&(t=r[1]),Zn.has(t))e=t;else{let n=t.length===2?Zn.keys():Zn.values();throw new Error(`Language "${t}" is not supported. Must be one of: ${JSON.stringify(Array.from(n))}`)}}return e}var tP="\\p{P}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E",$E=new RegExp(`^[${tP}]+$`,"gu"),mf=class extends j{get timestamp_begin(){return this._tokenizer.token_to_id("<|notimestamps|>")+1}_decode_asr(e,{return_timestamps:r=!1,return_language:s=!1,time_precision:n=null,force_full_sequences:o=!0}={}){if(n===null)throw Error("Must specify time_precision");let a=null,i=r==="word";function l(){return{language:a,timestamp:[null,null],text:""}}let u=[],d=l(),f=0,m=this.timestamp_begin,w=m+1500,x=[],k=[],E=!1,M=null,I=new Set(this.all_special_ids);for(let C of e){let v=C.tokens,G=i?C.token_timestamps:null,X=null,V=m;if("stride"in C){let[Y,B,P]=C.stride;if(f-=B,M=Y-P,B&&(V=B/n+m),P)for(let se=v.length-1;se>=0;--se){let ie=Number(v[se]);if(ie>=m){if(X!==null&&(ie-m)*n<M)break;X=ie}}}let Q=[],K=[];for(let Y=0;Y<v.length;++Y){let B=Number(v[Y]);if(I.has(B)){let P=this.decode([B]),se=Zn.get(P.slice(2,-2));if(se!==void 0){if(a!==null&&se!==a&&!r){x.push(Q);let ie=this.findLongestCommonSequence(x)[0],S=this.decode(ie);d.text=S,u.push(d),x=[],Q=[],d=l()}a=d.language=se}}else if(B>=m&&B<=w){let P=(B-m)*n+f,se=rs(P,2);if(X!==null&&B>=X)E=!0;else if(E||x.length>0&&B<V)E=!1;else if(d.timestamp[0]===null)d.timestamp[0]=se;else if(se!==d.timestamp[0]){d.timestamp[1]=se,x.push(Q),i&&k.push(K);let[ie,S]=this.findLongestCommonSequence(x,k),L=this.decode(ie);d.text=L,i&&(d.words=this.collateWordTimestamps(ie,S,a)),u.push(d),x=[],Q=[],k=[],K=[],d=l()}}else if(Q.push(B),i){let P=rs(G[Y]+f,2),se;if(Y+1<G.length){se=rs(G[Y+1]+f,2);let ie=this.decode([B]);$E.test(ie)&&(se=rs(Math.min(P+n,se),2))}else se=null;K.push([P,se])}}if("stride"in C){let[Y,B,P]=C.stride;f+=Y-P}Q.length>0?(x.push(Q),i&&k.push(K)):x.every(Y=>Y.length===0)&&(d=l(),x=[],Q=[],k=[],K=[])}if(x.length>0){if(o&&r)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");let[C,v]=this.findLongestCommonSequence(x,k),G=this.decode(C);d.text=G,i&&(d.words=this.collateWordTimestamps(C,v,a)),u.push(d)}let T=Object.create(null),z=u.map(C=>C.text).join("");if(r||s){for(let C=0;C<u.length;++C){let v=u[C];r||delete v.timestamp,s||delete v.language}if(i){let C=[];for(let v of u)for(let G of v.words)C.push(G);T={chunks:C}}else T={chunks:u}}return[z,T]}findLongestCommonSequence(e,r=null){let s=e[0],n=s.length,o=[],a=Array.isArray(r)&&r.length>0,i=a?[]:null,l=a?r[0]:null;for(let u=1;u<e.length;++u){let d=e[u],f=0,m=[n,n,0,0],_=d.length;for(let T=1;T<n+_;++T){let z=Math.max(0,n-T),C=Math.min(n,n+_-T),v=s.slice(z,C),G=Math.max(0,T-n),X=Math.min(_,T),V=d.slice(G,X);if(v.length!==V.length)throw new Error("There is a bug within whisper `decode_asr` function, please report it. Dropping to prevent bad inference.");let Q;a?Q=v.filter((B,P)=>B===V[P]&&l[z+P]<=r[u][G+P]).length:Q=v.filter((B,P)=>B===V[P]).length;let K=T/1e4,Y=Q/T+K;Q>1&&Y>f&&(f=Y,m=[z,C,G,X])}let[w,x,k,E]=m,M=Math.floor((x+w)/2),I=Math.floor((E+k)/2);o.push(...s.slice(0,M)),s=d.slice(I),n=s.length,a&&(i.push(...l.slice(0,M)),l=r[u].slice(I))}return o.push(...s),a?(i.push(...l),[o,i]):[o,[]]}collateWordTimestamps(e,r,s){let[n,o,a]=this.combineTokensIntoWords(e,s),i=[];for(let l=0;l<n.length;++l){let u=a[l];i.push({text:n[l],timestamp:[r[u.at(0)][0],r[u.at(-1)][1]]})}return i}combineTokensIntoWords(e,r,s=`"'\u201C\xA1\xBF([{-`,n=`"'.\u3002,\uFF0C!\uFF01?\uFF1F:\uFF1A\u201D)]}\u3001`){r=r??"english";let o,a,i;return["chinese","japanese","thai","lao","myanmar"].includes(r)?[o,a,i]=this.splitTokensOnUnicode(e):[o,a,i]=this.splitTokensOnSpaces(e),this.mergePunctuations(o,a,i,s,n)}decode(e,r){let s;return r?.decode_with_timestamps?(e instanceof U&&(e=Ad(e)),s=this.decodeWithTimestamps(e,r)):s=super.decode(e,r),s}decodeWithTimestamps(e,r){let s=r?.time_precision??.02,n=this.all_special_ids.at(-1)+1,o=[[]];for(let a of e)if(a=Number(a),a>=n){let i=((a-n)*s).toFixed(2);o.push(`<|${i}|>`),o.push([])}else o[o.length-1].push(a);return o=o.map(a=>typeof a=="string"?a:super.decode(a,r)),o.join("")}splitTokensOnUnicode(e){let r=this.decode(e,{decode_with_timestamps:!0}),s="\uFFFD",n=[],o=[],a=[],i=[],l=[],u=0;for(let d=0;d<e.length;++d){let f=e[d];i.push(f),l.push(d);let m=this.decode(i,{decode_with_timestamps:!0});(!m.includes(s)||r[u+m.indexOf(s)]===s)&&(n.push(m),o.push(i),a.push(l),i=[],l=[],u+=m.length)}return[n,o,a]}splitTokensOnSpaces(e){let[r,s,n]=this.splitTokensOnUnicode(e),o=[],a=[],i=[];for(let l=0;l<r.length;++l){let u=r[l],d=s[l],f=n[l],m=d[0]>=this._tokenizer.token_to_id("<|endoftext|>"),_=u.startsWith(" "),w=u.trim(),x=$E.test(w);if(m||_||x||o.length===0)o.push(u),a.push(d),i.push(f);else{let k=o.length-1;o[k]+=u,a[k].push(...d),i[k].push(...f)}}return[o,a,i]}mergePunctuations(e,r,s,n,o){let a=structuredClone(e),i=structuredClone(r),l=structuredClone(s),u=a.length-2,d=a.length-1;for(;u>=0;)a[u].startsWith(" ")&&n.includes(a[u].trim())?(a[d]=a[u]+a[d],i[d]=dt(i[u],i[d]),l[d]=dt(l[u],l[d]),a[u]="",i[u]=[],l[u]=[]):d=u,--u;for(u=0,d=1;d<a.length;)!a[u].endsWith(" ")&&o.includes(a[d])?(a[u]+=a[d],i[u]=dt(i[u],i[d]),l[u]=dt(l[u],l[d]),a[d]="",i[d]=[],l[d]=[]):u=d,++d;return[a.filter(f=>f),i.filter(f=>f.length>0),l.filter(f=>f.length>0)]}};var hf=class extends j{};var _f=class extends j{return_token_type_ids=!0;constructor(e,r){super(e,r),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}};var J=class{static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){let[i,l]=await Ed(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a}),u=l.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer",d=gf[u];return d||(console.warn(`Unknown tokenizer class "${u}", attempting to construct from base class.`),d=j),new d(i,l)}};var Hs="https://github.com/huggingface/transformers.js/issues/new/choose";var eo="preprocessor_config.json",Xs=eo,RE="processor_config.json",UE="chat_template.jinja";var ne=class extends Je{static classes=["image_processor_class","tokenizer_class","feature_extractor_class"];static uses_processor_config=!1;static uses_chat_template_file=!1;constructor(e,r,s){super(),this.config=e,this.components=r,this.chat_template=s}get image_processor(){return this.components.image_processor}get tokenizer(){return this.components.tokenizer}get feature_extractor(){return this.components.feature_extractor}apply_chat_template(e,r={}){if(!this.tokenizer)throw new Error("Unable to apply chat template without a tokenizer.");return this.tokenizer.apply_chat_template(e,{tokenize:!1,chat_template:this.chat_template??void 0,...r})}batch_decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.batch_decode(...e)}decode(...e){if(!this.tokenizer)throw new Error("Unable to decode without a tokenizer.");return this.tokenizer.decode(...e)}async _call(e,...r){for(let s of[this.image_processor,this.feature_extractor,this.tokenizer])if(s)return s(e,...r);throw new Error("No image processor, feature extractor, or tokenizer found.")}static async from_pretrained(e,r={}){let[s,n,o]=await Promise.all([this.uses_processor_config?at(e,RE,!0,r):{},Promise.all(this.classes.filter(a=>a in this).map(async a=>{let i=await this[a].from_pretrained(e,r);return[a.replace(/_class$/,""),i]})).then(Object.fromEntries),this.uses_chat_template_file?yp(e,UE,!0,r):null]);return new this(s,n,o)}};var Cl={};Ps(Cl,{ChatterboxProcessor:()=>Pf,Florence2Processor:()=>km,Gemma3nProcessor:()=>Em,GroundingDinoProcessor:()=>Am,Idefics3Processor:()=>Sl,JinaCLIPProcessor:()=>Tm,LlavaProcessor:()=>Sm,MgpstrProcessor:()=>Om,MoonshineProcessor:()=>Im,OwlViTProcessor:()=>Cm,PaliGemmaProcessor:()=>Pm,Phi3VProcessor:()=>zm,PixtralProcessor:()=>Lm,Processor:()=>ne,PyAnnoteProcessor:()=>Nm,Qwen2VLProcessor:()=>$m,Sam2Processor:()=>Ol,Sam2VideoProcessor:()=>Rm,SamProcessor:()=>io,SmolVLMProcessor:()=>Sl,SpeechT5Processor:()=>Um,UltravoxProcessor:()=>Bm,VLChatProcessor:()=>Mm,VoxtralProcessor:()=>Dm,Wav2Vec2Processor:()=>Fm,Wav2Vec2ProcessorWithLM:()=>jm,WhisperProcessor:()=>Gm});var Ne=class extends Je{constructor(e){super(),this.config=e}static async from_pretrained(e,r={}){let s=await at(e,eo,!0,r);return new this(s)}};function He(t,e){if(!(t instanceof Float32Array||t instanceof Float64Array))throw new Error(`${e} expects input to be a Float32Array or a Float64Array, but got ${t?.constructor?.name??typeof t} instead. If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}var oo={};Ps(oo,{ASTFeatureExtractor:()=>yf,ChatterboxFeatureExtractor:()=>bf,ClapFeatureExtractor:()=>vf,DacFeatureExtractor:()=>so,EncodecFeatureExtractor:()=>ro,FeatureExtractor:()=>Ne,Gemma3nAudioFeatureExtractor:()=>kf,MoonshineFeatureExtractor:()=>Ef,ParakeetFeatureExtractor:()=>Af,PyAnnoteFeatureExtractor:()=>no,SeamlessM4TFeatureExtractor:()=>Mf,SnacFeatureExtractor:()=>Tf,SpeechT5FeatureExtractor:()=>Sf,Wav2Vec2FeatureExtractor:()=>Of,WeSpeakerFeatureExtractor:()=>If,WhisperFeatureExtractor:()=>Cf});import rP from"fs";import{Readable as sP}from"stream";import{pipeline as nP}from"stream/promises";async function ll(t,e){if(be.IS_BROWSER_ENV){if(be.IS_WEBWORKER_ENV)throw new Error("Unable to save a file from a Web Worker.");let r=URL.createObjectURL(e),s=document.createElement("a");s.href=r,s.download=t,s.click(),s.remove(),URL.revokeObjectURL(r)}else if(be.IS_FS_AVAILABLE){let r=e.stream(),s=sP.fromWeb(r),n=rP.createWriteStream(t);await nP(s,n)}else throw new Error("Unable to save because filesystem is disabled in this environment.")}async function xf(t,e){if(typeof AudioContext>"u")throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");let r=await(await Bs(t)).arrayBuffer(),s=new AudioContext({sampleRate:e});typeof e>"u"&&console.warn(`No sampling rate provided, using default of ${s.sampleRate}Hz.`);let n=await s.decodeAudioData(r),o;if(n.numberOfChannels===2){let a=Math.sqrt(2),i=n.getChannelData(0),l=n.getChannelData(1);o=new Float32Array(i.length);for(let u=0;u<n.length;++u)o[u]=a*(i[u]+l[u])/2}else o=n.getChannelData(0);return o}function FE(t,e){if(t<1)return new Float64Array;if(t===1)return new Float64Array([1]);let r=1-e,s=2*Math.PI/(t-1),n=new Float64Array(t);for(let o=0;o<t;++o)n[o]=e-r*Math.cos(o*s);return n}function BE(t){return FE(t,.5)}function oP(t){return FE(t,.54)}var aP={htk:t=>2595*Math.log10(1+t/700),kaldi:t=>1127*Math.log(1+t/700),slaney:(t,e=1e3,r=15,s=27/Math.log(6.4))=>t>=e?r+Math.log(t/e)*s:3*t/200};function wf(t,e="htk"){let r=aP[e];if(!r)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?r(t):t.map(s=>r(s))}var iP={htk:t=>700*(10**(t/2595)-1),kaldi:t=>700*(Math.exp(t/1127)-1),slaney:(t,e=1e3,r=15,s=Math.log(6.4)/27)=>t>=r?e*Math.exp(s*(t-r)):200*t/3};function lP(t,e="htk"){let r=iP[e];if(!r)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof t=="number"?r(t):t.map(s=>r(s))}function cP(t,e){let r=Float64Array.from({length:e.length-1},(a,i)=>e[i+1]-e[i]),s=Array.from({length:t.length},()=>new Array(e.length));for(let a=0;a<t.length;++a){let i=s[a];for(let l=0;l<e.length;++l)i[l]=e[l]-t[a]}let n=e.length-2,o=Array.from({length:n},()=>new Array(t.length));for(let a=0;a<t.length;++a){let i=s[a];for(let l=0;l<n;++l){let u=-i[l]/r[l],d=i[l+2]/r[l+1];o[l][a]=Math.max(0,Math.min(u,d))}}return o}function DE(t,e,r){let s=(e-t)/(r-1);return Float64Array.from({length:r},(n,o)=>t+s*o)}function yt(t,e,r,s,n,o=null,a="htk",i=!1){if(o!==null&&o!=="slaney")throw new Error('norm must be one of null or "slaney"');if(t<2)throw new Error(`Require num_frequency_bins: ${t} >= 2`);if(r>s)throw new Error(`Require min_frequency: ${r} <= max_frequency: ${s}`);let l=wf(r,a),u=wf(s,a),d=DE(l,u,e+2),f=lP(d,a),m;if(i){let w=n/((t-1)*2);m=wf(Float64Array.from({length:t},(x,k)=>k*w),a),f=d}else m=DE(0,Math.floor(n/2),t);let _=cP(m,f);if(o!==null&&o==="slaney")for(let w=0;w<e;++w){let x=_[w],k=2/(f[w+2]-f[w]);for(let E=0;E<t;++E)x[E]*=k}return _}function uP(t,e,r){let s=new t.constructor(t.length+e+r),n=t.length-1;for(let o=0;o<t.length;++o)s[e+o]=t[o];for(let o=1;o<=e;++o)s[e-o]=t[$s(o,n)];for(let o=1;o<=r;++o)s[n+e+o]=t[$s(n-o,n)];return s}function jE(t,e,r,s,n){if(r<=0)throw new Error("reference must be greater than zero");if(s<=0)throw new Error("min_value must be greater than zero");r=Math.max(s,r);let o=Math.log10(r);for(let a=0;a<t.length;++a)t[a]=e*Math.log10(Math.max(s,t[a])-o);if(n!==null){if(n<=0)throw new Error("db_range must be greater than zero");let a=Te(t)[0]-n;for(let i=0;i<t.length;++i)t[i]=Math.max(t[i],a)}return t}function pP(t,e=1,r=1e-5,s=null){return jE(t,20,e,r,s)}function dP(t,e=1,r=1e-10,s=null){return jE(t,10,e,r,s)}async function At(t,e,r,s,{fft_length:n=null,power:o=1,center:a=!0,pad_mode:i="reflect",onesided:l=!0,preemphasis:u=null,preemphasis_htk_flavor:d=!0,mel_filters:f=null,mel_floor:m=1e-10,log_mel:_=null,reference:w=1,min_value:x=1e-10,db_range:k=null,remove_dc_offset:E=null,min_num_frames:M=null,max_num_frames:I=null,do_pad:T=!0,transpose:z=!1,mel_offset:C=0}={}){let v=e.length;if(n===null&&(n=r),r>n)throw Error(`frame_length (${r}) may not be larger than fft_length (${n})`);if(v!==r)throw new Error(`Length of the window (${v}) must equal frame_length (${r})`);if(s<=0)throw new Error("hop_length must be greater than zero");if(o===null&&f!==null)throw new Error("You have provided `mel_filters` but `power` is `None`. Mel spectrogram computation is not yet supported for complex-valued spectrogram. Specify `power` to fix this issue.");if(!d)throw new Error("`preemphasis_htk_flavor=false` is not currently supported.");if(a)switch(i){case"reflect":{let L=Math.floor((n-1)/2)+1;t=uP(t,L,L);break}case"constant":{let L=Math.floor(n/2),R=new t.constructor(t.length+2*L);R.set(t,L),t=R;break}default:throw new Error(`pad_mode="${i}" not implemented yet.`)}let G=Math.floor(1+Math.floor((t.length-r)/s));M!==null&&G<M&&(G=M);let X=l?Math.floor(n/2)+1:n,V=G,Q=G;I!==null&&(I>G?T&&(Q=I):Q=V=I);let K=new ji(n),Y=new Float64Array(n),B=new Float64Array(K.outputBufferSize),P=new Float32Array(X*Q);for(let L=0;L<V;++L){let R=L*s,te=Math.min(t.length-R,r);te!==r&&Y.fill(0,0,r);for(let ue=0;ue<te;++ue)Y[ue]=t[R+ue];if(E){let ue=0;for(let Ce=0;Ce<te;++Ce)ue+=Y[Ce];let Be=ue/te;for(let Ce=0;Ce<te;++Ce)Y[Ce]-=Be}if(u!==null){for(let ue=te-1;ue>=1;--ue)Y[ue]-=u*Y[ue-1];Y[0]*=1-u}for(let ue=0;ue<e.length;++ue)Y[ue]*=e[ue];K.realTransform(B,Y);for(let ue=0;ue<X;++ue){let Be=ue<<1;P[ue*Q+L]=B[Be]**2+B[Be+1]**2}}if(o!==null&&o!==2){let L=o/2;for(let R=0;R<P.length;++R)P[R]**=L}let se=f.length,ie=await IE(new U("float32",f.flat(),[se,X]),new U("float32",P,[X,Q]));z&&(ie=ie.transpose(1,0));let S=ie.data;for(let L=0;L<S.length;++L)S[L]=C+Math.max(m,S[L]);if(o!==null&&_!==null){let L=Math.min(S.length,V*se);switch(_){case"log":for(let R=0;R<L;++R)S[R]=Math.log(S[R]);break;case"log10":for(let R=0;R<L;++R)S[R]=Math.log10(S[R]);break;case"dB":if(o===1)pP(S,w,x,k);else if(o===2)dP(S,w,x,k);else throw new Error(`Cannot use log_mel option '${_}' with power ${o}`);break;default:throw new Error(`log_mel must be one of null, 'log', 'log10' or 'dB'. Got '${_}'`)}}return ie}function Mt(t,e,{periodic:r=!0,frame_length:s=null,center:n=!0}={}){let o=r?t+1:t,a;switch(e){case"boxcar":a=new Float64Array(o).fill(1);break;case"hann":case"hann_window":a=BE(o);break;case"hamming":a=oP(o);break;case"povey":a=BE(o).map(i=>Math.pow(i,.85));break;default:throw new Error(`Unknown window type ${e}.`)}if(r&&(a=a.subarray(0,t)),s===null)return a;if(t>s)throw new Error(`Length of the window (${t}) may not be larger than frame_length (${s})`);return a}function fP(t,e){let r=t.reduce((o,a)=>o+a.length,0),s=new ArrayBuffer(44),n=new DataView(s);return cl(n,0,"RIFF"),n.setUint32(4,36+r*4,!0),cl(n,8,"WAVE"),cl(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,3,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*4,!0),n.setUint16(32,4,!0),n.setUint16(34,32,!0),cl(n,36,"data"),n.setUint32(40,r*4,!0),new Blob([s,...t.map(o=>o.buffer)],{type:"audio/wav"})}function cl(t,e,r){for(let s=0;s<r.length;++s)t.setUint8(e+s,r.charCodeAt(s))}var to=class{constructor(e,r){this.audio=e,this.sampling_rate=r}get data(){if(Array.isArray(this.audio)){if(this.audio.length===0)return new Float32Array(0);if(this.audio.length===1)return this.audio[0];let e=this.audio.reduce((n,o)=>n+o.length,0),r=new Float32Array(e),s=0;for(let n of this.audio)r.set(n,s),s+=n.length;return r}else return this.audio}toBlob(){let e=this.audio;return e instanceof Float32Array&&(e=[e]),fP(e,this.sampling_rate)}async save(e){return ll(e,this.toBlob())}};var yf=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"hann",{periodic:!1}),this.mean=this.config.mean,this.std=this.config.std}async _extract_fbank_features(e,r){return At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:r,transpose:!0})}async _call(e){He(e,"ASTFeatureExtractor");let r=await this._extract_fbank_features(e,this.config.max_length);if(this.config.do_normalize){let s=this.std*2,n=r.data;for(let o=0;o<n.length;++o)n[o]=(n[o]-this.mean)/s}return{input_values:r.unsqueeze_(0)}}};var ro=class extends Ne{async _call(e){He(e,"EncodecFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=this.config.feature_size;if(e.length%r!==0)throw new Error(`The length of the audio data must be a multiple of the number of channels (${r}).`);let s=[1,r,e.length/r];return{input_values:new U("float32",e,s)}}};var bf=class extends Ne{async _call(e){He(e,"ChatterboxFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,e.length];return{input_values:new U("float32",e,r)}}};var vf=class extends Ne{constructor(e){super(e),this.mel_filters=yt(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,null,"htk"),this.mel_filters_slaney=yt(this.config.nb_frequency_bins,this.config.feature_size,this.config.frequency_min,this.config.frequency_max,this.config.sampling_rate,"slaney","slaney"),this.window=Mt(this.config.fft_window_size,"hann")}async _get_input_mel(e,r,s,n){let o,a=!1,i=e.length-r;if(i>0)if(s==="rand_trunc"){a=!0;let l=Math.floor(Math.random()*(i+1));e=e.subarray(l,l+r),o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}else throw new Error(`Truncation strategy "${s}" not implemented`);else{if(i<0){let l=new Float64Array(r);if(l.set(e),n==="repeat")for(let u=e.length;u<r;u+=e.length)l.set(e.subarray(0,Math.min(e.length,r-u)),u);else if(n==="repeatpad")for(let u=e.length;u<-i;u+=e.length)l.set(e,u);e=l}if(s==="fusion")throw new Error(`Truncation strategy "${s}" not implemented`);o=await this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples)}return o.unsqueeze_(0)}async _extract_fbank_features(e,r,s=null){return At(e,this.window,this.config.fft_window_size,this.config.hop_length,{power:2,mel_filters:r,log_mel:"dB",max_num_frames:s,do_pad:!1,transpose:!0})}async _call(e,{max_length:r=null}={}){return He(e,"ClapFeatureExtractor"),{input_features:(await this._get_input_mel(e,r??this.config.nb_max_samples,this.config.truncation,this.config.padding)).unsqueeze_(0)}}};var so=class extends ro{};var kf=class extends Ne{constructor(e){super(e);let{fft_length:r,feature_size:s,min_frequency:n,max_frequency:o,sampling_rate:a,frame_length:i}=this.config,l=yt(Math.floor(1+r/2),s,n,o,a,null,"htk",!1);this.mel_filters=l,this.window=Mt(i,"hann")}async _extract_fbank_features(e,r){return At(e,this.window,this.config.frame_length,this.config.hop_length,{fft_length:this.config.fft_length,center:!1,onesided:!0,preemphasis:this.config.preemphasis,preemphasis_htk_flavor:this.config.preemphasis_htk_flavor,mel_filters:this.mel_filters,log_mel:"log",mel_floor:this.config.mel_floor,remove_dc_offset:!1,transpose:!0})}async _call(e,{max_length:r=48e4,truncation:s=!0,padding:n=!0,pad_to_multiple_of:o=128}={}){if(He(e,"Gemma3nAudioFeatureExtractor"),s&&e.length>r&&(e=e.slice(0,r)),n&&e.length%o!==0){let l=o-e.length%o,u=new Float64Array(e.length+l);u.set(e),this.config.padding_value!==0&&u.fill(this.config.padding_value,e.length),e=u}let a=await this._extract_fbank_features(e,this.config.max_length),i=Ve([1,a.dims[0]],!0);return{input_features:a.unsqueeze_(0),input_features_mask:i}}};var Ef=class extends Ne{async _call(e){He(e,"MoonshineFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,e.length];return{input_values:new U("float32",e,r)}}};var mP=1e-5,Af=class extends Ne{constructor(e){super(e),this.config.mel_filters??=yt(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,this.config.sampling_rate/2,this.config.sampling_rate,"slaney","slaney");let r=Mt(this.config.win_length,"hann",{periodic:!1});this.window=new Float64Array(this.config.n_fft);let s=Math.floor((this.config.n_fft-this.config.win_length)/2);this.window.set(r,s)}async _extract_fbank_features(e){let r=this.config.preemphasis;e=new Float64Array(e);for(let n=e.length-1;n>=1;--n)e[n]-=r*e[n-1];return await At(e,this.window,this.window.length,this.config.hop_length,{fft_length:this.config.n_fft,power:2,mel_filters:this.config.mel_filters,log_mel:"log",mel_floor:-1/0,pad_mode:"constant",center:!0,transpose:!0,mel_offset:2**-24})}async _call(e){He(e,"ParakeetFeatureExtractor");let r=await this._extract_fbank_features(e),s=Math.floor((e.length+Math.floor(this.config.n_fft/2)*2-this.config.n_fft)/this.config.hop_length),n=r.data;n.fill(0,s*r.dims[1]);let[o,a]=r.dims,i=new Float64Array(a),l=new Float64Array(a);for(let f=0;f<s;++f){let m=f*a;for(let _=0;_<a;++_){let w=n[m+_];i[_]+=w,l[_]+=w*w}}let u=s>1?s-1:1;for(let f=0;f<a;++f){let m=i[f]/s,_=(l[f]-s*m*m)/u,x=1/(Math.sqrt(_)+mP);for(let k=0;k<s;++k){let E=k*a+f;n[E]=(n[E]-m)*x}}let d=new BigInt64Array(o);return d.fill(1n,0,s),{input_features:r.unsqueeze_(0),attention_mask:new U("int64",d,[1,o])}}};var no=class extends Ne{async _call(e){He(e,"PyAnnoteFeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=[1,1,e.length];return{input_values:new U("float32",e,r)}}samples_to_frames(e){return(e-this.config.offset)/this.config.step}post_process_speaker_diarization(e,r){let s=r/this.samples_to_frames(r)/this.config.sampling_rate,n=[];for(let o of e.tolist()){let a=[],i=-1;for(let l=0;l<o.length;++l){let u=Pe(o[l]),[d,f]=Te(u),[m,_]=[l,l+1];f!==i?(i=f,a.push({id:f,start:m,end:_,score:d})):(a.at(-1).end=_,a.at(-1).score+=d)}n.push(a.map(({id:l,start:u,end:d,score:f})=>({id:l,start:u*s,end:d*s,confidence:f/(d-u)})))}return n}};var Mf=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"povey",{periodic:!1})}async _extract_fbank_features(e,r){return e=e.map(s=>s*32768),At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,max_num_frames:r,transpose:!0})}async _call(e,{padding:r=!0,pad_to_multiple_of:s=2,do_normalize_per_mel_bins:n=!0,return_attention_mask:o=!0}={}){He(e,"SeamlessM4TFeatureExtractor");let a=await this._extract_fbank_features(e,this.config.max_length);if(n){let[w,x]=a.dims,k=a.data;for(let E=0;E<x;++E){let M=0;for(let C=0;C<w;++C)M+=k[C*x+E];let I=M/w,T=0;for(let C=0;C<w;++C)T+=(k[C*x+E]-I)**2;T/=w-1;let z=Math.sqrt(T+1e-7);for(let C=0;C<w;++C){let v=C*x+E;k[v]=(k[v]-I)/z}}}let i;if(r){let[w,x]=a.dims,k=a.data,E=w%s;if(E>0){let M=new Float32Array(x*(w+E));M.set(k),M.fill(this.config.padding_value,k.length);let I=w+E;a=new U(a.type,M,[I,x]),o&&(i=new U("int64",new BigInt64Array(I),[1,I]),i.data.fill(1n,0,w))}}let[l,u]=a.dims,d=this.config.stride;if(l%d!==0)throw new Error(`The number of frames (${l}) must be a multiple of the stride (${d}).`);let m=a.view(1,Math.floor(l/d),u*d),_={input_features:m};if(o){let w=m.dims[1],x=new BigInt64Array(w);if(i){let k=i.data;for(let E=1,M=0;E<l;E+=d,++M)x[M]=k[E]}else x.fill(1n);_.attention_mask=new U("int64",x,[1,w])}return _}};var Tf=class extends so{};var Sf=class extends Ne{};var Of=class extends Ne{_zero_mean_unit_var_norm(e){let s=e.reduce((o,a)=>o+a,0)/e.length,n=e.reduce((o,a)=>o+(a-s)**2,0)/e.length;return e.map(o=>(o-s)/Math.sqrt(n+1e-7))}async _call(e){He(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let r=e;this.config.do_normalize&&(r=this._zero_mean_unit_var_norm(r));let s=[1,r.length];return{input_values:new U("float32",r,s),attention_mask:new U("int64",new BigInt64Array(r.length).fill(1n),s)}}};var If=class extends Ne{constructor(e){super(e);let r=this.config.sampling_rate,s=yt(257,this.config.num_mel_bins,20,Math.floor(r/2),r,null,"kaldi",!0);this.mel_filters=s,this.window=Mt(400,"hamming",{periodic:!1}),this.min_num_frames=this.config.min_num_frames}async _extract_fbank_features(e){return e=e.map(r=>r*32768),At(e,this.window,400,160,{fft_length:512,power:2,center:!1,preemphasis:.97,mel_filters:this.mel_filters,log_mel:"log",mel_floor:1192092955078125e-22,remove_dc_offset:!0,transpose:!0,min_num_frames:this.min_num_frames})}async _call(e){He(e,"WeSpeakerFeatureExtractor");let r=(await this._extract_fbank_features(e)).unsqueeze_(0);if(this.config.fbank_centering_span===null){let s=r.mean(1).data,n=r.data,[o,a,i]=r.dims;for(let l=0;l<o;++l){let u=l*a*i,d=l*i;for(let f=0;f<a;++f){let m=u+f*i;for(let _=0;_<i;++_)n[m+_]-=s[d+_]}}}return{input_features:r}}};var Cf=class extends Ne{constructor(e){super(e),this.config.mel_filters??=yt(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=Mt(this.config.n_fft,"hann")}async _extract_fbank_features(e){let r=await At(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:Math.min(Math.floor(e.length/this.config.hop_length),this.config.nb_max_frames)}),s=r.data,n=Te(s)[0];for(let o=0;o<s.length;++o)s[o]=(Math.max(s[o],n-8)+4)/4;return r}async _call(e,{max_length:r=null}={}){He(e,"WhisperFeatureExtractor");let s,n=r??this.config.n_samples;return e.length>n?(e.length>this.config.n_samples&&console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),s=e.slice(0,n)):(s=new Float32Array(n),s.set(e)),{input_features:(await this._extract_fbank_features(s)).unsqueeze_(0)}}};var tt=class{static async from_pretrained(e,r={}){let s=await at(e,eo,!0,r),n=s.feature_extractor_type,o=oo[n];if(!o)throw new Error(`Unknown feature_extractor_type: '${n}'. Please report this at ${Hs}.`);return new o(s)}};var Pf=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e,r=null){let s=this.tokenizer(e),n=r?await this.feature_extractor(r):{};return{...s,...n}}};import zf from"sharp";var fs,GE,Or,Qt=be.IS_BROWSER_ENV||be.IS_WEBWORKER_ENV;if(Qt)fs=(t,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(t,e)},Or=self.createImageBitmap,GE=self.ImageData;else if(zf)Or=async t=>{let r=(await t.metadata()).channels,{data:s,info:n}=await t.rotate().raw().toBuffer({resolveWithObject:!0}),o=new Xe(new Uint8ClampedArray(s),n.width,n.height,n.channels);return r!==void 0&&r!==n.channels&&o.convert(r),o};else throw new Error("Unable to load image processing library.");var hP={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},_P=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]),Xe=class t{constructor(e,r,s,n){this.data=e,this.width=r,this.height=s,this.channels=n}get size(){return[this.width,this.height]}static async read(e){if(e instanceof t)return e;if(typeof e=="string"||e instanceof URL)return await this.fromURL(e);if(e instanceof Blob)return await this.fromBlob(e);if(typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas)return this.fromCanvas(e);throw new Error(`Unsupported input type: ${typeof e}`)}static fromCanvas(e){if(!Qt)throw new Error("fromCanvas() is only supported in browser environments.");let s=e.getContext("2d").getImageData(0,0,e.width,e.height).data;return new t(s,e.width,e.height,4)}static async fromURL(e){let r=await Bs(e);if(r.status!==200)throw new Error(`Unable to read image from "${e}" (${r.status} ${r.statusText})`);let s=await r.blob();return this.fromBlob(s)}static async fromBlob(e){if(Qt){let r=await Or(e),s=fs(r.width,r.height).getContext("2d");return s.drawImage(r,0,0),new this(s.getImageData(0,0,r.width,r.height).data,r.width,r.height,4)}else{let r=zf(await e.arrayBuffer());return await Or(r)}}static fromTensor(e,r="CHW"){if(e.dims.length!==3)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(r==="CHW")e=e.transpose(1,2,0);else if(r!=="HWC")throw new Error(`Unsupported channel format: ${r}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new t(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let r=0,s=0;r<this.data.length;r+=this.channels){let n=this.data[r],o=this.data[r+1],a=this.data[r+2];e[s++]=Math.round(.2989*n+.587*o+.114*a)}break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,1)}rgb(){if(this.channels===3)return this;let e=new Uint8ClampedArray(this.width*this.height*3);switch(this.channels){case 1:for(let r=0,s=0;r<this.data.length;++r)e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=this.data[r];break;case 4:for(let r=0,s=0;r<this.data.length;r+=4)e[s++]=this.data[r],e[s++]=this.data[r+1],e[s++]=this.data[r+2];break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,3)}rgba(){if(this.channels===4)return this;let e=new Uint8ClampedArray(this.width*this.height*4);switch(this.channels){case 1:for(let r=0,s=0;r<this.data.length;++r)e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=this.data[r],e[s++]=255;break;case 3:for(let r=0,s=0;r<this.data.length;r+=3)e[s++]=this.data[r],e[s++]=this.data[r+1],e[s++]=this.data[r+2],e[s++]=255;break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this._update(e,this.width,this.height,4)}putAlpha(e){if(e.width!==this.width||e.height!==this.height)throw new Error(`Expected mask size to be ${this.width}x${this.height}, but got ${e.width}x${e.height}`);if(e.channels!==1)throw new Error(`Expected mask to have 1 channel, but got ${e.channels}`);let r=this.data,s=e.data,n=this.width*this.height;if(this.channels===3){let o=new Uint8ClampedArray(n*4);for(let a=0,i=0,l=0;a<n;++a)o[l++]=r[i++],o[l++]=r[i++],o[l++]=r[i++],o[l++]=s[a];return this._update(o,this.width,this.height,4)}else if(this.channels===4){for(let o=0;o<n;++o)r[4*o+3]=s[o];return this}throw new Error(`Expected image to have 3 or 4 channels, but got ${this.channels}`)}async resize(e,r,{resample:s=2}={}){if(this.width===e&&this.height===r)return this;let n=hP[s]??s,o=gp(e),a=gp(r);if(o&&a)return this;if(o?e=r/this.height*this.width:a&&(r=e/this.width*this.height),Qt){let i=this.channels,l=this.toCanvas(),u=fs(e,r).getContext("2d");return u.drawImage(l,0,0,e,r),new t(u.getImageData(0,0,e,r).data,e,r,4).convert(i)}else{let i=this.toSharp();switch(n){case"box":case"hamming":(n==="box"||n==="hamming")&&(console.warn(`Resampling method ${n} is not yet supported. Using bilinear instead.`),n="bilinear");case"nearest":case"bilinear":case"bicubic":i=i.affine([e/this.width,0,0,r/this.height],{interpolator:n});break;case"lanczos":i=i.resize({width:e,height:r,fit:"fill",kernel:"lanczos3"});break;default:throw new Error(`Resampling method ${n} is not supported.`)}return await Or(i)}}async pad([e,r,s,n]){if(e=Math.max(e,0),r=Math.max(r,0),s=Math.max(s,0),n=Math.max(n,0),e===0&&r===0&&s===0&&n===0)return this;if(Qt){let o=this.channels,a=this.toCanvas(),i=this.width+e+r,l=this.height+s+n,u=fs(i,l).getContext("2d");return u.drawImage(a,0,0,this.width,this.height,e,s,this.width,this.height),new t(u.getImageData(0,0,i,l).data,i,l,4).convert(o)}else{let o=this.toSharp().extend({left:e,right:r,top:s,bottom:n});return await Or(o)}}async crop([e,r,s,n]){if(e=Math.max(e,0),r=Math.max(r,0),s=Math.min(s,this.width-1),n=Math.min(n,this.height-1),e===0&&r===0&&s===this.width-1&&n===this.height-1)return this;let o=s-e+1,a=n-r+1;if(Qt){let i=this.channels,l=this.toCanvas(),u=fs(o,a).getContext("2d");return u.drawImage(l,e,r,o,a,0,0,o,a),new t(u.getImageData(0,0,o,a).data,o,a,4).convert(i)}else{let i=this.toSharp().extract({left:e,top:r,width:o,height:a});return await Or(i)}}async center_crop(e,r){if(this.width===e&&this.height===r)return this;let s=(this.width-e)/2,n=(this.height-r)/2;if(Qt){let o=this.channels,a=this.toCanvas(),i=fs(e,r).getContext("2d"),l=0,u=0,d=0,f=0;return s>=0?l=s:d=-s,n>=0?u=n:f=-n,i.drawImage(a,l,u,e,r,d,f,e,r),new t(i.getImageData(0,0,e,r).data,e,r,4).convert(o)}else{let o=this.toSharp();if(s>=0&&n>=0)o=o.extract({left:Math.floor(s),top:Math.floor(n),width:e,height:r});else if(s<=0&&n<=0){let a=Math.floor(-n),i=Math.floor(-s);o=o.extend({top:a,left:i,right:e-this.width-i,bottom:r-this.height-a})}else{let a=[0,0],i=0;n<0?(a[0]=Math.floor(-n),a[1]=r-this.height-a[0]):i=Math.floor(n);let l=[0,0],u=0;s<0?(l[0]=Math.floor(-s),l[1]=e-this.width-l[0]):u=Math.floor(s),o=o.extend({top:a[0],bottom:a[1],left:l[0],right:l[1]}).extract({left:u,top:i,width:e,height:r})}return await Or(o)}}async toBlob(e="image/png",r=1){if(!Qt)throw new Error("toBlob() is only supported in browser environments.");return await this.toCanvas().convertToBlob({type:e,quality:r})}toTensor(e="CHW"){let r=new U("uint8",new Uint8Array(this.data),[this.height,this.width,this.channels]);if(e!=="HWC")if(e==="CHW")r=r.permute(2,0,1);else throw new Error(`Unsupported channel format: ${e}`);return r}toCanvas(){if(!Qt)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),r=fs(e.width,e.height),s=new GE(e.data,e.width,e.height);return r.getContext("2d").putImageData(s,0,0),r}split(){let{data:e,width:r,height:s,channels:n}=this,o=e.constructor,a=e.length/n,i=Array.from({length:n},()=>new o(a));for(let l=0;l<a;++l){let u=n*l;for(let d=0;d<n;++d)i[d][l]=e[u+d]}return i.map(l=>new t(l,r,s,1))}_update(e,r,s,n=null){return this.data=e,this.width=r,this.height=s,n!==null&&(this.channels=n),this}clone(){return new t(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(Qt){if(be.IS_WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");let r=e.split(".").pop().toLowerCase(),s=_P.get(r)??"image/png",n=await this.toBlob(s);return ll(e,n)}else if(be.IS_FS_AVAILABLE)await this.toSharp().toFile(e);else throw new Error("Unable to save the image because filesystem is disabled in this environment.")}toSharp(){if(Qt)throw new Error("toSharp() is only supported in server-side environments.");return zf(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}},gP=Xe.read.bind(Xe);function qE(t,e,r=0,s=null){let n=t/e,o=Hv(n)*e;return s!==null&&o>s&&(o=Math.floor(n)*e),o<r&&(o=Math.ceil(n)*e),o}function Lf([t,e],r){return[Math.max(Math.floor(t/r),1)*r,Math.max(Math.floor(e/r),1)*r]}function Nf([t,e,r,s]){return[t-r/2,e-s/2,t+r/2,e+s/2]}function Ir(t,e=.5,r=null,s=!1){let n=t.logits,o=t.pred_boxes,[a,i,l]=n.dims;if(r!==null&&r.length!==a)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let u=[];for(let d=0;d<a;++d){let f=r!==null?r[d]:null,m={boxes:[],classes:[],scores:[]},_=n[d],w=o[d];for(let x=0;x<i;++x){let k=_[x],E=[],M;if(s){M=k.sigmoid().data;for(let I=0;I<M.length;++I)M[I]>e&&E.push(I)}else{let I=Te(k.data)[1];if(I===l-1||(M=Pe(k.data),M[I]<e))continue;E.push(I)}for(let I of E){let T=w[x].data;T=Nf(T),f!==null&&(T=T.map((z,C)=>z*f[(C+1)%2])),m.boxes.push(T),m.classes.push(I),m.scores.push(M[I])}}u.push(m)}return u}function ul(t,e=null){let r=t.logits,s=r.dims[0];if(e!==null&&e.length!==s)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let n=[];for(let o=0;o<s;++o){let a=e!==null?e[o]:null,i=r[o];a!==null&&(i=xd(i,a,"bilinear",!1));let[l,u]=a??i.dims.slice(-2),d=new U("int32",new Int32Array(l*u),[l,u]),f=i[0].data,m=d.data;for(let x=1;x<i.dims[0];++x){let k=i[x].data;for(let E=0;E<k.length;++E)k[E]>f[E]&&(f[E]=k[E],m[E]=x)}let _=new Array(i.dims[0]);for(let x=0;x<m.length;++x){let k=m[x];_[k]=k}let w=_.filter(x=>x!==void 0);n.push({segmentation:d,labels:w})}return n}function wP(t,e,r,s){let n=[],o=[],a=[];for(let i=0;i<t.dims[0];++i){let l=t[i],u=e[i],d=Te(l.data)[1];if(d===s)continue;let m=Pe(l.data)[d];m>r&&(n.push(u),o.push(m),a.push(d))}return[n,o,a]}function xP(t,e,r,s=.5,n=.8){let o=[],a=0,i=0,l=e[r].data;for(let d=0;d<t.length;++d)t[d]===r&&(o.push(d),++a),l[d]>=s&&++i;let u=a>0&&i>0;return u&&(u=a/i>n),[u,o]}function yP(t,e,r,s,n,o=null,a=null){let[i,l]=a??t[0].dims,u=new U("int32",new Int32Array(i*l),[i,l]),d=[];if(a!==null)for(let x=0;x<t.length;++x)t[x]=xd(t[x],a,"bilinear",!1);let f=new Int32Array(t[0].data.length),m=new Float32Array(t[0].data.length);for(let x=0;x<t.length;++x){let k=e[x],E=t[x].data;for(let M=0;M<E.length;++M)E[M]*=k,E[M]>m[M]&&(f[M]=x,m[M]=E[M])}let _=0,w=u.data;for(let x=0;x<r.length;++x){let k=r[x],[E,M]=xP(f,t,x,s,n);if(E){++_;for(let I of M)w[I]=_;d.push({id:_,label_id:k,score:e[x]})}}return[u,d]}function bP(t,e,r=28,s=3136,n=784*1280){if(t<r||e<r)throw new Error(`height:${t} or width:${e} must be larger than factor:${r}`);if(Math.max(t,e)/Math.min(t,e)>200)throw new Error(`absolute aspect ratio must be smaller than 200, got ${Math.max(t,e)/Math.min(t,e)}`);let o=Math.round(t/r)*r,a=Math.round(e/r)*r;if(o*a>n){let i=Math.sqrt(t*e/n);o=Math.floor(t/i/r)*r,a=Math.floor(e/i/r)*r}else if(o*a<s){let i=Math.sqrt(s/(t*e));o=Math.ceil(t*i/r)*r,a=Math.ceil(e*i/r)*r}return[o,a]}function pl(t,e=.5,r=.5,s=.8,n=null,o=null){n===null&&(console.warn("`label_ids_to_fuse` unset. No instance will be fused."),n=new Set);let a=t.class_queries_logits??t.logits,l=(t.masks_queries_logits??t.pred_masks).sigmoid(),[u,d,f]=a.dims;if(f-=1,o!==null&&o.length!==u)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let m=[];for(let _=0;_<u;++_){let w=o!==null?o[_]:null,x=a[_],k=l[_],[E,M,I]=wP(x,k,e,f);if(I.length===0){let[C,v]=w??k.dims.slice(-2),G=new U("int32",new Int32Array(C*v).fill(-1),[C,v]);m.push({segmentation:G,segments_info:[]});continue}let[T,z]=yP(E,M,I,r,s,n,w);m.push({segmentation:T,segments_info:z})}return m}function dl(t,e=.5,r=null){throw new Error("`post_process_instance_segmentation` is not yet implemented.")}var W=class extends Je{constructor(e){super(),this.image_mean=e.image_mean??e.mean,this.image_std=e.image_std??e.std,this.resample=e.resample??2,this.do_rescale=e.do_rescale??!0,this.rescale_factor=e.rescale_factor??1/255,this.do_normalize=e.do_normalize,this.do_thumbnail=e.do_thumbnail,this.size=e.size??e.image_size,this.do_resize=e.do_resize??this.size!==void 0,this.size_divisibility=e.size_divisibility??e.size_divisor,this.do_center_crop=e.do_center_crop,this.crop_size=e.crop_size,this.do_convert_rgb=e.do_convert_rgb??!0,this.do_crop_margin=e.do_crop_margin,this.pad_size=e.pad_size,this.do_pad=e.do_pad,this.min_pixels=e.min_pixels,this.max_pixels=e.max_pixels,this.do_pad&&!this.pad_size&&this.size&&this.size.width!==void 0&&this.size.height!==void 0&&(this.pad_size=this.size),this.do_flip_channel_order=e.do_flip_channel_order??!1,this.config=e}async thumbnail(e,r,s=2){let n=e.height,o=e.width,a=r.height,i=r.width,l=Math.min(n,a),u=Math.min(o,i);return l===n&&u===o?e:(n>o?u=Math.floor(o*l/n):o>n&&(l=Math.floor(n*u/o)),await e.resize(u,l,{resample:s}))}async crop_margin(e,r=200){let s=e.clone().grayscale(),n=Dn(s.data)[0],a=Te(s.data)[0]-n;if(a===0)return e;let i=r/255,l=s.width,u=s.height,d=0,f=0,m=s.data;for(let _=0;_<s.height;++_){let w=_*s.width;for(let x=0;x<s.width;++x)(m[w+x]-n)/a<i&&(l=Math.min(l,x),u=Math.min(u,_),d=Math.max(d,x),f=Math.max(f,_))}return e=await e.crop([l,u,d,f]),e}pad_image(e,r,s,{mode:n="constant",center:o=!1,constant_values:a=0}={}){let[i,l,u]=r,d,f;if(typeof s=="number"?(d=s,f=s):s==="square"?d=f=Math.max(i,l):(d=s.width,f=s.height),d!==l||f!==i){let m=new Float32Array(d*f*u);if(Array.isArray(a))for(let x=0;x<m.length;++x)m[x]=a[x%u];else a!==0&&m.fill(a);let[_,w]=o?[Math.floor((d-l)/2),Math.floor((f-i)/2)]:[0,0];for(let x=0;x<i;++x){let k=(x+w)*d,E=x*l;for(let M=0;M<l;++M){let I=(k+M+_)*u,T=(E+M)*u;for(let z=0;z<u;++z)m[I+z]=e[T+z]}}if(n==="symmetric"){if(o)throw new Error("`center` padding is not supported when `mode` is set to `symmetric`.");let x=i-1,k=l-1;for(let E=0;E<f;++E){let M=E*d,I=$s(E,x)*l;for(let T=0;T<d;++T){if(E<i&&T<l)continue;let z=(M+T)*u,C=(I+$s(T,k))*u;for(let v=0;v<u;++v)m[z+v]=e[C+v]}}}e=m,r=[f,d,u]}return[e,r]}rescale(e){for(let r=0;r<e.length;++r)e[r]=this.rescale_factor*e[r]}get_resize_output_image_size(e,r){let[s,n]=e.size,o,a;if(this.do_thumbnail){let{height:i,width:l}=r;o=Math.min(i,l)}else Number.isInteger(r)?(o=r,a=this.config.max_size??o):r!==void 0&&(o=r.shortest_edge,a=r.longest_edge);if(o!==void 0||a!==void 0){let i=o===void 0?1:Math.max(o/s,o/n),l=s*i,u=n*i,d=a===void 0?1:Math.min(a/l,a/u),f=Math.floor(Number((l*d).toFixed(2))),m=Math.floor(Number((u*d).toFixed(2)));return this.size_divisibility!==void 0&&([f,m]=Lf([f,m],this.size_divisibility)),[f,m]}else if(r!==void 0&&r.width!==void 0&&r.height!==void 0){let i=r.width,l=r.height;if(this.config.keep_aspect_ratio&&this.config.ensure_multiple_of){let u=l/n,d=i/s;Math.abs(1-d)<Math.abs(1-u)?u=d:d=u,l=qE(u*n,this.config.ensure_multiple_of),i=qE(d*s,this.config.ensure_multiple_of)}return[i,l]}else{if(this.size_divisibility!==void 0)return Lf([s,n],this.size_divisibility);if(this.min_pixels!==void 0&&this.max_pixels!==void 0){let i=this.config.patch_size*this.config.merge_size;return bP(n,s,i,this.min_pixels,this.max_pixels)}else throw new Error(`Could not resize image due to unsupported \`this.size\` option in config: ${JSON.stringify(r)}`)}}async resize(e){let[r,s]=this.get_resize_output_image_size(e,this.size);return await e.resize(r,s,{resample:this.resample})}async preprocess(e,{do_normalize:r=null,do_pad:s=null,do_convert_rgb:n=null,do_convert_grayscale:o=null,do_flip_channel_order:a=null}={}){this.do_crop_margin&&(e=await this.crop_margin(e));let[i,l]=e.size;if(n??this.do_convert_rgb?e=e.rgb():o&&(e=e.grayscale()),this.do_resize&&(e=await this.resize(e)),this.do_thumbnail&&(e=await this.thumbnail(e,this.size,this.resample)),this.do_center_crop){let _,w;Number.isInteger(this.crop_size)?(_=this.crop_size,w=this.crop_size):(_=this.crop_size.width,w=this.crop_size.height),e=await e.center_crop(_,w)}let u=[e.height,e.width],d=Float32Array.from(e.data),f=[e.height,e.width,e.channels];if(this.do_rescale&&this.rescale(d),r??this.do_normalize){let _=this.image_mean;Array.isArray(this.image_mean)||(_=new Array(e.channels).fill(_));let w=this.image_std;if(Array.isArray(this.image_std)||(w=new Array(e.channels).fill(w)),_.length!==e.channels||w.length!==e.channels)throw new Error(`When set to arrays, the length of \`image_mean\` (${_.length}) and \`image_std\` (${w.length}) must match the number of channels in the image (${e.channels}).`);for(let x=0;x<d.length;x+=e.channels)for(let k=0;k<e.channels;++k)d[x+k]=(d[x+k]-_[k])/w[k]}if(s??this.do_pad){if(this.pad_size)[d,f]=this.pad_image(d,[e.height,e.width,e.channels],this.pad_size);else if(this.size_divisibility){let[_,w]=Lf([f[1],f[0]],this.size_divisibility);[d,f]=this.pad_image(d,f,{width:_,height:w})}}if(a??this.do_flip_channel_order){if(f[2]!==3)throw new Error("Flipping channel order is only supported for RGB images.");for(let _=0;_<d.length;_+=3){let w=d[_];d[_]=d[_+2],d[_+2]=w}}let m=new U("float32",d,f).permute(2,0,1);return{original_size:[l,i],reshaped_input_size:u,pixel_values:m}}async _call(e,...r){Array.isArray(e)||(e=[e]);let s=await Promise.all(e.map(o=>this.preprocess(o)));return{pixel_values:Ft(s.map(o=>o.pixel_values),0),original_sizes:s.map(o=>o.original_size),reshaped_input_sizes:s.map(o=>o.reshaped_input_size)}}static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r);return new this(s)}};var Zs={};Ps(Zs,{BeitFeatureExtractor:()=>$f,BitImageProcessor:()=>Rf,CLIPFeatureExtractor:()=>Bf,CLIPImageProcessor:()=>fl,ChineseCLIPFeatureExtractor:()=>Uf,ConvNextFeatureExtractor:()=>Df,ConvNextImageProcessor:()=>ml,DINOv3ViTImageProcessor:()=>Gf,DPTFeatureExtractor:()=>Wf,DPTImageProcessor:()=>gl,DeiTFeatureExtractor:()=>Ff,DeiTImageProcessor:()=>hl,DetrFeatureExtractor:()=>jf,DetrImageProcessor:()=>_l,DonutFeatureExtractor:()=>qf,DonutImageProcessor:()=>Ks,EfficientNetImageProcessor:()=>Vf,GLPNFeatureExtractor:()=>Hf,GroundingDinoImageProcessor:()=>Xf,Idefics3ImageProcessor:()=>wl,ImageFeatureExtractor:()=>W,ImageProcessor:()=>W,JinaCLIPImageProcessor:()=>Yf,LlavaOnevisionImageProcessor:()=>Qf,Mask2FormerImageProcessor:()=>Zf,MaskFormerFeatureExtractor:()=>Jf,MaskFormerImageProcessor:()=>Ys,MobileNetV1FeatureExtractor:()=>em,MobileNetV1ImageProcessor:()=>xl,MobileNetV2FeatureExtractor:()=>tm,MobileNetV2ImageProcessor:()=>yl,MobileNetV3FeatureExtractor:()=>rm,MobileNetV3ImageProcessor:()=>bl,MobileNetV4FeatureExtractor:()=>sm,MobileNetV4ImageProcessor:()=>vl,MobileViTFeatureExtractor:()=>nm,MobileViTImageProcessor:()=>kl,NougatImageProcessor:()=>om,OwlViTFeatureExtractor:()=>am,OwlViTImageProcessor:()=>Qs,Owlv2ImageProcessor:()=>im,Phi3VImageProcessor:()=>um,PixtralImageProcessor:()=>pm,PvtImageProcessor:()=>dm,Qwen2VLImageProcessor:()=>fm,RTDetrImageProcessor:()=>mm,Sam2ImageProcessor:()=>ao,Sam3ImageProcessor:()=>ao,SamImageProcessor:()=>ao,SapiensFeatureExtractor:()=>hm,SapiensImageProcessor:()=>El,SegformerFeatureExtractor:()=>_m,SegformerImageProcessor:()=>Al,SiglipImageProcessor:()=>gm,SmolVLMImageProcessor:()=>wl,Swin2SRImageProcessor:()=>wm,VLMImageProcessor:()=>Kf,ViTFeatureExtractor:()=>xm,ViTImageProcessor:()=>Ml,VitMatteImageProcessor:()=>ym,VitPoseImageProcessor:()=>bm,YolosFeatureExtractor:()=>vm,YolosImageProcessor:()=>Tl});var $f=class extends W{};var Rf=class extends W{};var Uf=class extends W{};var fl=class extends W{},Bf=class extends fl{};var ml=class extends W{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){let r=this.size?.shortest_edge;if(r===void 0)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(r<384){let s=Math.floor(r/this.crop_pct),[n,o]=this.get_resize_output_image_size(e,{shortest_edge:s});e=await e.resize(n,o,{resample:this.resample}),e=await e.center_crop(r,r)}else e=await e.resize(r,r,{resample:this.resample});return e}},Df=class extends ml{};var hl=class extends W{},Ff=class extends hl{};var _l=class extends W{async _call(e){let r=await super._call(e),s=[r.pixel_values.dims[0],64,64],n=Ve(s,1n);return{...r,pixel_mask:n}}post_process_object_detection(...e){return Ir(...e)}post_process_panoptic_segmentation(...e){return pl(...e)}post_process_instance_segmentation(...e){return dl(...e)}},jf=class extends _l{};var Gf=class extends W{};var Ks=class extends W{pad_image(e,r,s,n={}){let[o,a,i]=r,l=this.image_mean;Array.isArray(this.image_mean)||(l=new Array(i).fill(l));let u=this.image_std;Array.isArray(u)||(u=new Array(i).fill(l));let d=l.map((f,m)=>-f/u[m]);return super.pad_image(e,r,s,{center:!0,constant_values:d,...n})}},qf=class extends Ks{};var gl=class extends W{},Wf=class extends gl{};var Vf=class extends W{constructor(e){super(e),this.include_top=this.config.include_top??!0,this.include_top&&(this.image_std=this.image_std.map(r=>r*r))}};var Hf=class extends W{};var Xf=class extends W{async _call(e){let r=await super._call(e),s=r.pixel_values.dims,n=it([s[0],s[2],s[3]]);return{...r,pixel_mask:n}}};var wl=class extends W{constructor(e){super(e),this.do_image_splitting=e.do_image_splitting??!0,this.max_image_size=e.max_image_size}get_resize_for_vision_encoder(e,r){let[s,n]=e.dims.slice(-2),o=n/s;return n>=s?(n=Math.ceil(n/r)*r,s=Math.floor(n/o),s=Math.ceil(s/r)*r):(s=Math.ceil(s/r)*r,n=Math.floor(s*o),n=Math.ceil(n/r)*r),{height:s,width:n}}async _call(e,{do_image_splitting:r=null,return_row_col_info:s=!1}={}){let n;if(!Array.isArray(e))n=[[e]];else{if(e.length===0||!e[0])throw new Error("No images provided.");Array.isArray(e[0])?n=e:n=[e]}let o=[],a=[],i=[],l=[],u=[];for(let E of n){let M=await Promise.all(E.map(z=>this.preprocess(z)));l.push(...M.map(z=>z.original_size)),u.push(...M.map(z=>z.reshaped_input_size)),M.forEach(z=>z.pixel_values.unsqueeze_(0));let{longest_edge:I}=this.max_image_size,T;if(r??this.do_image_splitting){let z=new Array(M.length),C=new Array(M.length);T=await Promise.all(M.map(async(v,G)=>{let X=this.get_resize_for_vision_encoder(v.pixel_values,I),V=await Dt(v.pixel_values,{size:[X.height,X.width]}),{frames:Q,num_splits_h:K,num_splits_w:Y}=await this.split_image(V,this.max_image_size);return z[G]=K,C[G]=Y,Ee(Q,0)})),a.push(z),i.push(C)}else{let z=[I,I];T=await Promise.all(M.map(C=>Dt(C.pixel_values,{size:z}))),a.push(new Array(M.length).fill(0)),i.push(new Array(M.length).fill(0))}o.push(Ee(T,0))}let d=o.length,[f,m,_,w]=o[0].dims,x,k;if(d===1)x=o[0].unsqueeze_(0),k=Ve([d,f,_,w],!0);else{let E=Math.max(...o.map(T=>T.dims.at(0)));k=Ve([d,E,_,w],!0);let M=k.data,I=E*_*w;for(let T=0;T<d;++T){let z=o[T].dims[0];if(z<E){o[T]=Ee([o[T],Ve([E-z,m,_,w],0)],0);let C=T*I+z*_*w,v=(T+1)*I;M.fill(!1,C,v)}}x=Ft(o,0)}return{pixel_values:x,pixel_attention_mask:k,original_sizes:l,reshaped_input_sizes:u,...s?{rows:a,cols:i}:{}}}async split_image(e,{longest_edge:r}){let s=r,n=r,o=[],[a,i]=e.dims.slice(-2),l=0,u=0;if(a>s||i>n){l=Math.ceil(a/s),u=Math.ceil(i/n);let d=Math.ceil(a/l),f=Math.ceil(i/u);for(let w=0;w<l;++w)for(let x=0;x<u;++x){let k,E,M,I;w===l-1?(E=a-d,I=a):(E=w*d,I=(w+1)*d),x===u-1?(k=i-f,M=i):(k=x*f,M=(x+1)*f);let C=await ol(e,[E,k],[I,M],[2,3]);o.push(C)}let m=s,_=n;(a!==m||i!==_)&&(e=await Dt(e,{size:[m,_]}))}return o.push(e),{frames:o,num_splits_h:l,num_splits_w:u}}};var Kf=class extends W{constructor(e){super({do_pad:!0,pad_size:{width:e.image_size,height:e.image_size},...e}),this.constant_values=this.config.background_color.map(r=>r*this.rescale_factor)}pad_image(e,r,s,n){return super.pad_image(e,r,s,{constant_values:this.constant_values,center:!0,...n})}};var Yf=class extends W{constructor(e){let{resize_mode:r,fill_color:s,interpolation:n,size:o,...a}=e,i=r==="squash"?{width:o,height:o}:r==="shortest"?{shortest_edge:o}:{longest_edge:o},l=n==="bicubic"?3:2;super({...a,size:i,resample:l,do_center_crop:!0,crop_size:o,do_normalize:!0})}};var Qf=class extends W{};var Ys=class extends W{post_process_panoptic_segmentation(...e){return pl(...e)}post_process_instance_segmentation(...e){return dl(...e)}},Jf=class extends Ys{};var Zf=class extends Ys{};var xl=class extends W{},em=class extends xl{};var yl=class extends W{},tm=class extends yl{};var bl=class extends W{},rm=class extends bl{};var vl=class extends W{},sm=class extends vl{};var kl=class extends W{},nm=class extends kl{};var om=class extends Ks{};var Qs=class extends W{post_process_object_detection(...e){return Ir(...e)}},am=class extends Qs{};var im=class extends Qs{};var Pt=336,vP=[2,3],{ceil:lm,floor:Js,sqrt:cm}=Math,um=class extends W{constructor(e){super({...e,do_normalize:!0,do_pad:!0,pad_size:"custom",do_convert_rgb:!0,do_resize:!0}),this._num_crops=e.num_crops}calc_num_image_tokens_from_image_size(e,r){let{num_img_tokens:s}=this.config;return Js((Js(r/Pt)*Js(e/Pt)+1)*s+1+(Js(r/Pt)+1)*cm(s))}get_resize_output_image_size(e,r){let s=this._num_crops,[n,o]=e.size,a=n/o,i=1;for(;i*Math.ceil(i/a)<=s;)i+=1;i-=1;let l=Math.floor(i*336),u=Math.floor(l/a);return[l,u]}pad_image(e,r,s,n={}){let[o,a]=r,i=Pt*lm(o/Pt),l=Pt*lm(a/Pt),u=[1,1,1].map((d,f)=>(d-this.image_mean[f])/this.image_std[f]);return super.pad_image(e,r,{width:l,height:i},{center:!0,constant_values:u,...n})}async _call(e,{num_crops:r=null}={}){if(this._num_crops=r??=this.config.num_crops,r<4||cm(r)%1!==0)throw new Error("num_crops must be a square number >= 4");Array.isArray(e)||(e=[e]);let s=e.length,n=await Promise.all(e.map(m=>this.preprocess(m))),o=n.map(m=>m.original_size),a=n.map(m=>m.reshaped_input_size),i=[];for(let{pixel_values:m}of n){m.unsqueeze_(0);let[_,w]=m.dims.slice(-2),x=await Dt(m,{size:[Pt,Pt],mode:"bicubic"});if(r>0){let k=[],E=cm(r),M=Js(w/E),I=Js(_/E);for(let z=0;z<E;++z)for(let C=0;C<E;++C){let v,G,X,V;z===E-1?(G=_-I,V=_):(G=z*I,V=(z+1)*I),C===E-1?(v=w-M,X=w):(v=C*M,X=(C+1)*M);let Y=await ol(m,[G,v],[V,X],vP);k.push(Y)}let T=await Dt(Ee(k,0),{size:[Pt,Pt],mode:"bicubic"});i.push(Ee([x,T],0))}else i.push(x)}let l=Ft(i,0),u=a.map(m=>m.map(_=>Pt*lm(_/Pt))),d=new U("int64",u.flat(),[s,2]),f=u.map(([m,_])=>this.calc_num_image_tokens_from_image_size(_,m));return{pixel_values:l,original_sizes:o,reshaped_input_sizes:a,image_sizes:d,num_img_tokens:f}}};var pm=class extends W{get_resize_output_image_size(e,r){let{longest_edge:s}=r;if(s===void 0)throw new Error("size must contain 'longest_edge'");let[n,o]=e.size,a=Math.max(n,o)/s,i=n,l=o;a>1&&(i=Math.floor(n/a),l=Math.floor(o/a));let{patch_size:u,spatial_merge_size:d}=this.config;if(!d)throw new Error("config must contain 'spatial_merge_size'");let f=u*d,m=Math.floor((i-1)/f)+1,_=Math.floor((l-1)/f)+1;return[m*f,_*f]}};var dm=class extends W{};var fm=class extends W{async _call(e,...r){let{pixel_values:s,original_sizes:n,reshaped_input_sizes:o}=await super._call(e,...r),a=s,{temporal_patch_size:i,merge_size:l,patch_size:u}=this.config;a.dims[0]===1&&(a=Ee(Array.from({length:i},()=>a),0));let d=a.dims[0]/i,f=a.dims[1],m=Math.floor(a.dims[2]/u),_=Math.floor(a.dims[3]/u),w=a.view(d,i,f,Math.floor(m/l),l,u,Math.floor(_/l),l,u).permute(0,3,6,4,7,2,1,5,8).view(d*m*_,f*i*u*u),x=new U("int64",[d,m,_],[1,3]);return{pixel_values:w,image_grid_thw:x,original_sizes:n,reshaped_input_sizes:o}}};var mm=class extends W{post_process_object_detection(...e){return Ir(...e)}};var ao=class extends W{reshape_input_points(e,r,s,n=!1){e=structuredClone(e);let o=wp(e);if(o.length===3)n||(o=[1,...o]),e=[e];else if(o.length!==4)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");for(let a=0;a<e.length;++a){let[i,l]=r[a],[u,d]=s[a],f=[d/l,u/i];for(let m=0;m<e[a].length;++m)for(let _=0;_<e[a][m].length;++_)for(let w=0;w<e[a][m][_].length;++w)e[a][m][_][w]*=f[w%2]}return new U("float32",Float32Array.from(e.flat(1/0)),o)}add_input_labels(e,r){let s=wp(e);if(s.length===2)s=[1,...s],e=[e];else if(s.length!==3)throw Error("The input_points must be a 4D tensor of shape `batch_size`, `point_batch_size`, `nb_points_per_image`, `2`.");if(s.some((n,o)=>n!==r.dims[o]))throw Error(`The first ${s.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new U("int64",e.flat(1/0).map(BigInt),s)}async _call(e,{input_points:r=null,input_labels:s=null,input_boxes:n=null}={}){let o=await super._call(e);if(r&&(o.input_points=this.reshape_input_points(r,o.original_sizes,o.reshaped_input_sizes)),s){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(s,o.input_points)}return n&&(o.input_boxes=this.reshape_input_points(n,o.original_sizes,o.reshaped_input_sizes,!0)),o}async post_process_masks(e,r,s,{mask_threshold:n=0,binarize:o=!0,pad_size:a=null}={}){let i=[];a=a??this.pad_size??this.size;let l=[a.height,a.width];for(let u=0;u<r.length;++u){let d=r[u],f=s[u],m=await Dt(e[u],{mode:"bilinear",size:l});if(m=m.slice(null,null,[0,f[0]],[0,f[1]]),m=await Dt(m,{mode:"bilinear",size:d}),o){let _=m.data,w=new Uint8Array(_.length);for(let x=0;x<_.length;++x)_[x]>n&&(w[x]=1);m=new U("bool",w,m.dims)}i.push(m)}return i}generate_crop_boxes(e,r,{crop_n_layers:s=0,overlap_ratio:n=512/1500,points_per_crop:o=32,crop_n_points_downscale_factor:a=1}={}){}};var El=class extends W{post_process_semantic_segmentation(...e){return ul(...e)}},hm=class extends El{};var Al=class extends W{post_process_semantic_segmentation(...e){return ul(...e)}},_m=class extends Al{};var gm=class extends W{};var wm=class extends W{pad_image(e,r,s,n={}){let[o,a,i]=r;return super.pad_image(e,r,{width:a+(s-a%s)%s,height:o+(s-o%s)%s},{mode:"symmetric",center:!1,constant_values:-1,...n})}};var Ml=class extends W{},xm=class extends Ml{};var ym=class extends W{async _call(e,r){Array.isArray(e)||(e=[e]),Array.isArray(r)||(r=[r]);let s=await Promise.all(e.map(a=>this.preprocess(a))),n=await Promise.all(r.map(a=>this.preprocess(a,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:Ft(s.map((a,i)=>Ee([a.pixel_values,n[i].pixel_values],0)),0),original_sizes:s.map(a=>a.original_size),reshaped_input_sizes:s.map(a=>a.reshaped_input_size)}}};var bm=class extends W{post_process_pose_estimation(e,r,{threshold:s=null}={}){let n=e.tolist(),[o,a,i,l]=e.dims,u=[];for(let d=0;d<o;++d){let f=n[d],m=r[d],_=[];for(let w=0;w<m.length;++w){let x=m[w],k=[],E=[],M=[],I=x.at(-2)/l,T=x.at(-1)/i;for(let z=0;z<f.length;++z){let[C,v]=[0,0],G=0,X=-1/0,V=f[z];for(let K=0;K<V.length;++K){let Y=V[K];for(let B=0;B<Y.length;++B){let P=Y[B];G+=P,X=Math.max(X,P),C+=(B+.5)*P,v+=K*P}}if(s!=null&&X<s)continue;let Q=[I*C/G,T*v/G];k.push(Q),M.push(z),E.push(X)}_.push({bbox:x,scores:E,labels:M,keypoints:k})}u.push(_)}return u}};var Tl=class extends W{post_process_object_detection(...e){return Ir(...e)}},vm=class extends Tl{};var $e=class{static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r),n=s.image_processor_type??s.feature_extractor_type,o=Zs[n?.replace(/Fast$/,"")];return o||(n!==void 0&&console.warn(`Image processor type '${n}' not found, assuming base ImageProcessor. Please report this at ${Hs}.`),o=W),new o(s)}};var km=class extends ne{static tokenizer_class=J;static image_processor_class=$e;constructor(e,r,s){super(e,r,s);let{tasks_answer_post_processing_type:n,task_prompts_without_inputs:o,task_prompts_with_input:a}=this.image_processor.config;this.tasks_answer_post_processing_type=new Map(Object.entries(n??{})),this.task_prompts_without_inputs=new Map(Object.entries(o??{})),this.task_prompts_with_input=new Map(Object.entries(a??{})),this.regexes={quad_boxes:/(.+?)<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm,bboxes:/([^<]+)?<loc_(\d+)><loc_(\d+)><loc_(\d+)><loc_(\d+)>/gm},this.size_per_bin=1e3}construct_prompts(e){typeof e=="string"&&(e=[e]);let r=[];for(let s of e)if(this.task_prompts_without_inputs.has(s))r.push(this.task_prompts_without_inputs.get(s));else{for(let[n,o]of this.task_prompts_with_input)if(s.includes(n)){r.push(o.replaceAll("{input}",s).replaceAll(n,""));break}r.length!==e.length&&r.push(s)}return r}post_process_generation(e,r,s){let n=this.tasks_answer_post_processing_type.get(r)??"pure_text";e=e.replaceAll("<s>","").replaceAll("</s>","");let o;switch(n){case"pure_text":o=e;break;case"description_with_bboxes":case"bboxes":case"phrase_grounding":case"ocr":let a=n==="ocr"?"quad_boxes":"bboxes",i=e.matchAll(this.regexes[a]),l=[],u=[];for(let[d,f,...m]of i)l.push(f?f.trim():l.at(-1)??""),u.push(m.map((_,w)=>(Number(_)+.5)/this.size_per_bin*s[w%2]));o={labels:l,[a]:u};break;default:throw new Error(`Task "${r}" (of type "${n}") not yet implemented.`)}return{[r]:o}}async _call(e,r=null,s={}){if(!e&&!r)throw new Error("Either text or images must be provided");let n=await this.image_processor(e,s),o=r?this.tokenizer(this.construct_prompts(r),s):{};return{...n,...o}}};var Em=class extends ne{static image_processor_class=$e;static feature_extractor_class=tt;static tokenizer_class=J;static uses_processor_config=!0;static uses_chat_template_file=!0;constructor(e,r,s){super(e,r,s),this.audio_seq_length=this.config.audio_seq_length,this.image_seq_length=this.config.image_seq_length;let{audio_token_id:n,boa_token:o,audio_token:a,eoa_token:i,image_token_id:l,boi_token:u,image_token:d,eoi_token:f}=this.tokenizer.config;this.audio_token_id=n,this.boa_token=o,this.audio_token=a;let m=a.repeat(this.audio_seq_length);this.full_audio_sequence=`
16
16
 
17
17
  ${o}${m}${i}
18
18
 
@@ -24,6 +24,6 @@ ${u}${_}${f}
24
24
  `}return a+=`
25
25
  ${s}${o}`+n.repeat(t)+`${s}`,a}function AP(t,e,r,s){return`${e}${s}`+r.repeat(t)+`${e}`}function MP(t,e,r,s,n,o){return t===0&&e===0?AP(r,s,n,o):EP(r,t,e,s,n,o)}var Sl=class extends ne{static image_processor_class=$e;static tokenizer_class=J;static uses_processor_config=!0;fake_image_token="<fake_token_around_image>";image_token="<image>";global_img_token="<global-img>";async _call(e,r=null,s={}){s.return_row_col_info??=!0;let n;r&&(n=await this.image_processor(r,s)),Array.isArray(e)||(e=[e]);let o=n.rows??[new Array(e.length).fill(0)],a=n.cols??[new Array(e.length).fill(0)],i=this.config.image_seq_len,l=[],u=[];for(let f=0;f<e.length;++f){let m=e[f],_=o[f],w=a[f];l.push(Lv(m,this.image_token));let x=_.map((M,I)=>MP(M,w[I],i,this.fake_image_token,this.image_token,this.global_img_token)),k=m.split(this.image_token);if(k.length===0)throw new Error("The image token should be present in the text.");let E=k[0];for(let M=0;M<x.length;++M)E+=x[M]+k[M+1];u.push(E)}return{...this.tokenizer(u),...n}}};var Mm=class extends ne{static image_processor_class=$e;static tokenizer_class=J;static uses_processor_config=!0;constructor(e,r,s){super(e,r,s),this.image_tag=this.config.image_tag,this.image_start_tag=this.config.image_start_tag,this.image_end_tag=this.config.image_end_tag,this.num_image_tokens=this.config.num_image_tokens}async _call(e,{images:r=null,chat_template:s="default"}={}){r?Array.isArray(r)||(r=[r]):r=await Promise.all(e.filter(k=>k.images).flatMap(k=>k.images).map(k=>Xe.read(k)));let n=this.tokenizer,o=n.apply_chat_template(e,{tokenize:!1,add_generation_prompt:!0,chat_template:s}),a=k=>n.encode(k,{add_special_tokens:!1}),i=o.split(this.image_tag),l=i.length-1;if(r.length!==l)throw new Error(`Number of images provided (${r.length}) does not match number of "${this.image_tag}" image tags (${l})`);let[u,d,f]=n.convert_tokens_to_ids([this.image_tag,this.image_start_tag,this.image_end_tag]),m=a(i[0]),_=new Array(m.length).fill(!1);for(let k=1;k<i.length;++k){let E=new Array(this.num_image_tokens).fill(u),M=a(i[k]);m=dt(m,[d],E,[f],M);let I=new Array(this.num_image_tokens).fill(!0);_=dt(_,[!1],I,[!1],new Array(M.length).fill(!1))}let w=[1,m.length],x={input_ids:new U("int64",m,w),attention_mask:new U("int64",new Array(m.length).fill(1),w),images_seq_mask:new U("bool",_,w),images_emb_mask:new U("bool",new Array(l*this.num_image_tokens).fill(!0),[1,l,this.num_image_tokens])};if(r&&r.length>0){let k=await this.image_processor(r);return k.pixel_values.unsqueeze_(0),{...x,...k}}return x}};var Tm=class extends ne{static tokenizer_class=J;static image_processor_class=$e;async _call(e=null,r=null,s={}){if(!e&&!r)throw new Error("Either text or images must be provided");let n=e?this.tokenizer(e,s):{},o=r?await this.image_processor(r,s):{};return{...n,...o}}};var Sm=class extends ne{static tokenizer_class=J;static image_processor_class=$e;static uses_processor_config=!0;async _call(e,r=null,s={}){let n=await this.image_processor(e,s);if(r){let[a,i]=n.pixel_values.dims.slice(-2),{image_token:l,patch_size:u,num_additional_image_tokens:d}=this.config,f=Math.floor(a/u)*Math.floor(i/u)+d;r=structuredClone(r),Array.isArray(r)||(r=[r]);for(let m=0;m<r.length;++m)r[m]=r[m].replace(l,l.repeat(f))}let o=r?this.tokenizer(r,s):{};return{...n,...o}}};var WE={char:["char_decode",1],bpe:["bpe_decode",2],wp:["wp_decode",102]},Om=class extends ne{static tokenizer_class=J;static image_processor_class=$e;get char_tokenizer(){return this.components.char_tokenizer}get bpe_tokenizer(){return this.components.bpe_tokenizer}get wp_tokenizer(){return this.components.wp_tokenizer}_decode_helper(e,r){if(!WE.hasOwnProperty(r))throw new Error(`Format ${r} is not supported.`);let[s,n]=WE[r],o=this[s].bind(this),[a,i]=e.dims,l=[],u=[],d=e.tolist();for(let m=0;m<a;++m){let _=d[m],w=[],x=[];for(let E=1;E<i;++E){let[M,I]=Te(Pe(_[E]));if(x.push(M),I==n)break;w.push(I)}let k=x.length>0?x.reduce((E,M)=>E*M,1):0;u.push(w),l.push(k)}return[o(u),l]}char_decode(e){return this.char_tokenizer.batch_decode(e).map(r=>r.replaceAll(" ",""))}bpe_decode(e){return this.bpe_tokenizer.batch_decode(e)}wp_decode(e){return this.wp_tokenizer.batch_decode(e).map(r=>r.replaceAll(" ",""))}batch_decode([e,r,s]){let[n,o]=this._decode_helper(e,"char"),[a,i]=this._decode_helper(r,"bpe"),[l,u]=this._decode_helper(s,"wp"),d=[],f=[];for(let m=0;m<n.length;++m){let[_,w]=Te([o[m],i[m],u[m]]);d.push([n[m],a[m],l[m]][w]),f.push(_)}return{generated_text:d,scores:f,char_preds:n,bpe_preds:a,wp_preds:l}}static async from_pretrained(...e){let r=await super.from_pretrained(...e),s=await J.from_pretrained("Xenova/gpt2"),n=await J.from_pretrained("Xenova/bert-base-uncased");return r.components={image_processor:r.image_processor,char_tokenizer:r.tokenizer,bpe_tokenizer:s,wp_tokenizer:n},r}async _call(e,r=null){let s=await this.image_processor(e);return r&&(s.labels=this.tokenizer(r).input_ids),s}};var Im=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var Cm=class extends ne{static tokenizer_class=J;static image_processor_class=$e};var en="<image>";function TP(t,e,r,s,n){return`${s.repeat(r*n)}${e}${t}
26
26
  `}var Pm=class extends ne{static tokenizer_class=J;static image_processor_class=$e;static uses_processor_config=!1;async _call(e,r=null,s={}){r||(console.warn("You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."),r=""),Array.isArray(e)||(e=[e]),Array.isArray(r)||(r=[r]);let n=this.tokenizer.bos_token,o=this.image_processor.config.image_seq_length,a;r.some(u=>u.includes(en))?a=r.map(u=>{let d=u.replaceAll(en,en.repeat(o)),f=d.lastIndexOf(en),m=f===-1?0:f+en.length;return d.slice(0,m)+n+d.slice(m)+`
27
- `}):(console.warn("You are passing both `text` and `images` to `PaliGemmaProcessor`. The processor expects special image tokens in the text, as many tokens as there are images per each text. It is recommended to add `<image>` tokens in the very beginning of your text. For this call, we will infer how many images each text has and add special tokens."),a=r.map(u=>TP(u,n,o,en,e.length)));let i=this.tokenizer(a,s);return{...await this.image_processor(e,s),...i}}};var VE="<|image|>",SP=/<\|image_\d+\|>/g,zm=class extends ne{static image_processor_class=$e;static tokenizer_class=J;async _call(e,r=null,{padding:s=!0,truncation:n=!0,num_crops:o=null}={}){Array.isArray(e)||(e=[e]);let a,i;if(r){i=await this.image_processor(r,{num_crops:o});let{num_img_tokens:l}=i,u=e.map((f,m)=>f.split(SP).join(VE.repeat(l[m])));a=this.tokenizer(u,{padding:s,truncation:n});let d=this.tokenizer._tokenizer.token_to_id(VE);a.input_ids.map_(f=>f==d?-f:f)}else a=this.tokenizer(e);return{...a,...i}}};var Lm=class extends ne{static tokenizer_class=J;static image_processor_class=$e;static uses_processor_config=!0;async _call(e,r=null,s={}){let n=await this.image_processor(e,s);if(r){let[a,i]=n.pixel_values.dims.slice(-2),{image_token:l,image_break_token:u,image_end_token:d,patch_size:f,spatial_merge_size:m}=this.config,_=f*m,w=Math.floor(a/_),x=Math.floor(i/_);r=structuredClone(r),Array.isArray(r)||(r=[r]);for(let k=0;k<r.length;++k){let E=l.repeat(x),M=E+u,I=E+d,T=M.repeat(w-1)+I;r[k]=r[k].replace(l,T)}}let o=r?this.tokenizer(r,s):{};return{...n,...o}}};var Nm=class extends ne{static feature_extractor_class=no;async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}};var $m=class extends ne{static image_processor_class=$e;static tokenizer_class=J;async _call(e,r=null,...s){Array.isArray(e)||(e=[e]);let n,o;if(r&&(n=await this.image_processor(r),o=n.image_grid_thw),o){let i=this.image_processor.config.merge_size**2,l=0,u=o.tolist();e=e.map(d=>{for(;d.includes("<|image_pad|>");){let f=Number(u[l++].reduce((m,_)=>m*_,1n));d=d.replace("<|image_pad|>","<|placeholder|>".repeat(Math.floor(f/i)))}return d.replaceAll("<|placeholder|>","<|image_pad|>")})}return{...this.tokenizer(e),...n}}};var io=class extends ne{static image_processor_class=$e;async _call(...e){return await this.image_processor(...e)}post_process_masks(...e){return this.image_processor.post_process_masks(...e)}reshape_input_points(...e){return this.image_processor.reshape_input_points(...e)}};var Ol=class extends io{},Rm=class extends Ol{};var Um=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var Bm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;static uses_processor_config=!0;async _call(e,r=null,s={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(r){let a=r.length,{input_features:i}=await this.feature_extractor(r,{...s,max_length:a}),l=Math.round(a/this.config.encoder_ds_factor+1e-4),u=1+Math.ceil(l/this.config.stack_factor);n.audio_token_len=[u],n.audio_values=i;let d=this.config.audio_placeholder;if(!e.includes(d))throw new Error(`The input text does not contain the image token ${d}.`);e=e.replaceAll(d,d.repeat(u))}return{...this.tokenizer(e,{add_special_tokens:!1,...s}),...n}}};var Il="[AUDIO]",OP="[BEGIN_AUDIO]",IP=375;function CP(t,e){let r=[];for(let s=0;s<t.length;s+=e)r.push(t.subarray(s,Math.min(s+e,t.length)));return r}var Dm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;static uses_processor_config=!1;async _call(e,r=null,s={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(r){if(!e.includes(Il))throw new Error(`The input text does not contain the audio token ${Il}.`);Array.isArray(r)||(r=[r]);let a=e.split(Il),i=a.length-1;if(i!==r.length)throw new Error(`The number of audio inputs (${r.length}) does not match the number of audio tokens in the text (${i}).`);let l=this.feature_extractor.config.n_samples,u=r.map(w=>CP(w,l)),d=u.map(w=>w.length),f=u.flat(),m=(await Promise.all(f.map(w=>this.feature_extractor(w,s)))).map(w=>w.input_features);n.audio_values=m.length>1?Ee(m,0):m[0];let _=a[0];for(let w=0;w<d.length;++w){_+=OP;for(let x=0;x<d[w];++x)_+=Il.repeat(IP);_+=a[w+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...s}),...n}}};var Fm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var jm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var Gm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var ut=class{static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r),{image_processor_type:n,feature_extractor_type:o,processor_class:a}=s;if(a&&Cl[a])return Cl[a].from_pretrained(e,r);if(!n&&!o)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");let i={};if(n){let u=Zs[n.replace(/Fast$/,"")];if(!u)throw new Error(`Unknown image_processor_type: '${n}'.`);i.image_processor=new u(s)}if(o){let u=Zs[o];if(u)i.image_processor=new u(s);else{let d=oo[o];if(!d)throw new Error(`Unknown feature_extractor_type: '${o}'.`);i.feature_extractor=new d(s)}}let l={};return new ne(l,i,null)}};async function PP(t,e){return await at(t,"config.json",!0,e)}function tn(t){let e={},r={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"ultravox":case"voxtral":case"smolvlm":case"gemma3n":case"chatterbox":case"mistral3":r=tn(t.text_config);break;case"moondream1":r=tn(t.phi_config);break;case"musicgen":r=tn(t.decoder);break;case"multi_modality":r=tn(t.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":e.num_heads="num_attention_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size";break;case"gpt_oss":case"llama":case"llama4_text":case"nanochat":case"apertus":case"arcee":case"lfm2":case"lfm2_moe":case"smollm3":case"olmo":case"olmo2":case"olmo3":case"mobilellm":case"granite":case"granitemoehybrid":case"cohere":case"mistral":case"starcoder2":case"qwen2":case"qwen2_vl":case"phi":case"phi3":case"phi3_v":case"llava_qwen2":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size",e.num_attention_heads="num_attention_heads",e.dim_kv="head_dim";break;case"qwen3":case"gemma":case"gemma2":case"vaultgemma":case"gemma3_text":case"gemma3n_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"ministral":case"ministral3":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="head_dim";break;case"openelm":e.num_heads="num_kv_heads",e.num_layers="num_transformer_layers",e.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":e.num_heads="num_heads",e.num_layers="num_layers",e.hidden_size="hidden_size";break;case"bloom":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="hidden_size";break;case"mpt":e.num_heads="n_heads",e.num_layers="n_layers",e.hidden_size="d_model";break;case"exaone":e.num_heads="num_key_value_heads",e.num_layers="num_layers",e.dim_kv="head_dim",e.num_attention_heads="num_attention_heads";break;case"youtu":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="qk_head_dim",e.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":e.num_decoder_layers="num_decoder_layers",e.num_decoder_heads="num_heads",e.decoder_dim_kv="d_kv",e.num_encoder_layers="num_layers",e.num_encoder_heads="num_heads",e.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"lite-whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="d_model",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="d_model";break;case"speecht5":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="hidden_size",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="hidden_size";break;case"trocr":e.num_encoder_layers=e.num_decoder_layers="decoder_layers",e.num_encoder_heads=e.num_decoder_heads="decoder_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="d_model";break;case"musicgen_decoder":e.num_encoder_layers=e.num_decoder_layers="num_hidden_layers",e.num_encoder_heads=e.num_decoder_heads="num_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"moonshine":e.num_decoder_layers="decoder_num_hidden_layers",e.num_decoder_heads="decoder_num_key_value_heads",e.num_encoder_layers="encoder_num_hidden_layers",e.num_encoder_heads="encoder_num_key_value_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":let n=tn(t.decoder),o="num_decoder_layers"in n,a=ot(t,["model_type","is_encoder_decoder"]);return o?(a.num_decoder_layers=n.num_decoder_layers,a.num_decoder_heads=n.num_decoder_heads,a.decoder_hidden_size=n.decoder_hidden_size,a.num_encoder_layers=n.num_encoder_layers,a.num_encoder_heads=n.num_encoder_heads,a.encoder_hidden_size=n.encoder_hidden_size):(a.num_layers=n.num_layers,a.num_heads=n.num_heads,a.hidden_size=n.hidden_size),a}let s={...r,...ot(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)s[n]=t[e[n]];return s}function zl(t,e){if(["lfm2","lfm2_moe"].includes(t.model_type)){let r=e?.prefix??"past_key_values",s=r==="present"?"present":"past",n={},{layer_types:o,num_attention_heads:a,num_key_value_heads:i,hidden_size:l,conv_L_cache:u}=t,d=l/a,f=e?.batch_size??1;for(let m=0;m<o.length;++m)if(o[m]==="full_attention")for(let _ of["key","value"])n[`${r}.${m}.${_}`]=[f,i,0,d];else if(o[m]==="conv")n[`${s}_conv.${m}`]=[f,l,u];else throw new Error(`Unsupported layer type: ${o[m]}`);return n}else if(["granitemoehybrid","falcon_h1"].includes(t.model_type)){let r=e?.prefix??"past_key_values",s=r==="present"?"present":"past",n={},{layer_types:o,num_hidden_layers:a,num_attention_heads:i,num_key_value_heads:l,hidden_size:u,mamba_d_conv:d,mamba_n_heads:f,mamba_d_head:m,mamba_d_state:_,mamba_n_groups:w,mamba_expand:x,mamba_d_ssm:k}=t,E=u/i,M=e?.batch_size??1,I=(k??x*u)+2*w*_;for(let T=0;T<a;++T)if((!o||o[T]==="mamba")&&(n[`${s}_conv.${T}`]=[M,I,d],n[`${s}_ssm.${T}`]=[M,f,m,_]),!o||o[T]==="attention")for(let z of["key","value"])n[`${r}.${T}.${z}`]=[M,l,0,E];return n}return zP(t,e)}function zP(t,{prefix:e="past_key_values",batch_size:r=1}={}){let s={},n=t.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n){let o=n.encoder_dim_kv??n.encoder_hidden_size/n.num_encoder_heads,a=n.decoder_dim_kv??n.decoder_hidden_size/n.num_decoder_heads,i=[r,n.num_encoder_heads,0,o],l=[r,n.num_decoder_heads,0,a];for(let u=0;u<n.num_decoder_layers;++u)s[`${e}.${u}.encoder.key`]=i,s[`${e}.${u}.encoder.value`]=i,s[`${e}.${u}.decoder.key`]=l,s[`${e}.${u}.decoder.value`]=l}else{let o=n.num_heads,a=n.num_layers,i=n.dim_kv??n.hidden_size/(n.num_attention_heads??o);if(n.model_type==="falcon"){let l=[r*o,0,i];for(let u=0;u<a;++u)s[`${e}.${u}.key`]=l,s[`${e}.${u}.value`]=l}else if(n.multi_query){let l=[r*o,0,2*i];for(let u=0;u<a;++u)s[`${e}.${u}.key_value`]=l}else if(n.model_type==="bloom"){let l=[r*o,i,0],u=[r*o,0,i];for(let d=0;d<a;++d)s[`${e}.${d}.key`]=l,s[`${e}.${d}.value`]=u}else if(n.model_type==="openelm")for(let l=0;l<a;++l){let u=[r,o[l],0,i];s[`${e}.${l}.key`]=u,s[`${e}.${l}.value`]=u}else{let l=[r,o,0,i];for(let u=0;u<a;++u)s[`${e}.${u}.key`]=l,s[`${e}.${u}.value`]=l}}return s}var Pl=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=tn(this)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){s&&!(s instanceof t)&&(s=new t(s));let i=s??await PP(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a});return new this(i)}},ms=class{static async from_pretrained(...e){return Pl.from_pretrained(...e)}};async function HE(t,e,r,s){let n=`${e}${s}.onnx`,o=`${r.subfolder??""}/${n}`;return await Bn(t,o,!0,r,be.IS_NODE_ENV)}async function XE(t,e,r,s,n,o={}){let a=`${e}${r}.onnx`,i=be.IS_NODE_ENV,l=[];if(n){let u;typeof n=="object"?n.hasOwnProperty(a)?u=n[a]:n.hasOwnProperty(e)?u=n[e]:u=!1:u=n;let d=+u;if(d>Bi)throw new Error(`The number of external data chunks (${d}) exceeds the maximum allowed value (${Bi}).`);for(let f=0;f<d;++f){let m=`${a}_data${f===0?"":"_"+f}`,_=`${s.subfolder??""}/${m}`;l.push(new Promise(async(w,x)=>{let k=await Bn(t,_,!0,s,i);w(k instanceof Uint8Array?{path:m,data:k}:m)}))}}else o.externalData!==void 0&&(l=o.externalData.map(async u=>{if(typeof u.data=="string"){let d=await Bn(t,u.data,!0,s);return{...u,data:d}}return u}));return Promise.all(l)}async function LP(t,e,r,s=!1){let n=r.config?.["transformers.js_config"]??{},o=r.device??n.device;o&&typeof o!="string"&&(o.hasOwnProperty(e)?o=o[e]:(console.warn(`device not specified for "${e}". Using the default device.`),o=null));let a=o??(be.IS_NODE_ENV?"cpu":"wasm"),i=kE(a),l=n.device_config??{};l.hasOwnProperty(a)&&(n={...n,...l[a]});let u=r.dtype??n.dtype;if(typeof u!="string"&&(u&&u.hasOwnProperty(e)?u=u[e]:(u=_d[a]??mt.fp32,console.warn(`dtype not specified for "${e}". Using the default dtype (${u}) for this device (${a}).`))),u===mt.auto){let z=n.dtype;typeof z!="string"&&(z=z?.[e]),z&&z!==mt.auto&&mt.hasOwnProperty(z)?u=z:u=_d[a]??mt.fp32}let d=u;if(gd.hasOwnProperty(d)){if(a==="webgpu"&&!be.IS_NODE_ENV&&d===mt.fp16&&!await TE())throw new Error(`The device (${a}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${d}. Should be one of: ${Object.keys(mt).join(", ")}`);let f=n.kv_cache_dtype,m=f?typeof f=="string"?f:f[d]??"float32":void 0;if(m&&!["float32","float16"].includes(m))throw new Error(`Invalid kv_cache_dtype: ${m}. Should be one of: float32, float16`);let _=gd[d],w={...r.session_options};w.executionProviders??=i;let x=n.free_dimension_overrides;x?w.freeDimensionOverrides??=x:a.startsWith("webnn")&&!w.freeDimensionOverrides&&console.warn(`WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${a}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);let k=HE(t,e,r,_),E=r.use_external_data_format??n.use_external_data_format,M=await XE(t,e,_,r,E,w);if(M.length>0&&!be.IS_NODE_ENV&&(w.externalData=M),s&&a==="webgpu"&&f!==!1){let z=zl(r.config,{prefix:"present"});if(Object.keys(z).length>0&&!Kn()){let C={};for(let v in z)C[v]="gpu-buffer";w.preferredOutputLocation=C}}return{buffer_or_path:await k,session_options:w,session_config:{dtype:d,kv_cache_dtype:m,device:a}}}async function bt(t,e,r,s=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let{buffer_or_path:o,session_options:a,session_config:i}=await LP(t,e[n],r,n===s),l=await tl(o,a,i);return[n,l]})))}function KE(t){for(let e in t)sl(t[e])?t[e]=new U(t[e]):typeof t[e]=="object"&&KE(t[e]);return t}async function ce(t,e){let r=NP(t,e);try{let s=Object.fromEntries(Object.entries(r).map(([o,a])=>{let i=a.ort_tensor;return be.IS_NODE_ENV&&typeof Float16Array<"u"&&i.cpuData instanceof Float16Array&&(i.cpuData=new Uint16Array(i.cpuData.buffer)),[o,i]})),n=await rl(t,s);return KE(n)}catch(s){let n=Object.fromEntries(Object.entries(r).map(([o,a])=>{let i={type:a.type,dims:a.dims,location:a.location};return i.location!=="gpu-buffer"&&(i.data=a.data),[o,i]}));throw console.error(`An error occurred during model execution: "${s}".`),console.error("Inputs given to model:",n),s}}function NP(t,e){let r=Object.create(null),s=[];for(let a of t.inputNames){let i=e[a];if(!(i instanceof U)){s.push(a);continue}r[a]=Kn()?i.clone():i}if(s.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${s.join(", ")}.`);let n=Object.keys(e).length,o=t.inputNames.length;if(n>o){let a=Object.keys(e).filter(i=>!t.inputNames.includes(i));console.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${a.join(", ")}".`)}return r}var ze=class{};var F=class extends ze{constructor({logits:e,...r}){super(),this.logits=e;let s=Object.values(r);s.length>0&&(this.attentions=s)}},_e=class extends ze{constructor({logits:e}){super(),this.logits=e}},we=class extends ze{constructor({logits:e}){super(),this.logits=e}},Ae=class extends ze{constructor({start_logits:e,end_logits:r}){super(),this.start_logits=e,this.end_logits=r}},gt=class extends ze{constructor({logits:e}){super(),this.logits=e}};var Ll=class extends ze{constructor({alphas:e}){super(),this.alphas=e}};var jt=class extends Je{_call(e,r){throw Error("`_call` should be implemented in a subclass")}},lo=class extends Je{_call(e,r){throw Error("`_call` should be implemented in a subclass")}},hs=class extends Je{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,r){let s=r;for(let n of this.processors)s=n(e,s);return s}[Symbol.iterator](){return this.processors.values()}},Nl=class extends jt{constructor(e){super(),this.bos_token_id=e}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===1){let n=r[s].data;n.fill(-1/0),n[this.bos_token_id]=0}return r}},$l=class extends jt{constructor(e,r){super(),this.max_length=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===this.max_length-1){let n=r[s].data;n.fill(-1/0);for(let o of this.eos_token_id)n[o]=0}return r}},rn=class extends jt{constructor(e,r){super(),this.begin_suppress_tokens=e,this.begin_index=r}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===this.begin_index){let n=r[s].data;for(let o of this.begin_suppress_tokens)n[o]=-1/0}return r}},Rl=class extends jt{constructor(e,r){super(),this.eos_token_id=Array.isArray(e.eos_token_id)?e.eos_token_id[0]:e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=r.length,r.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data;if(n[this.no_timestamps_token_id]=-1/0,e[s].length===this.begin_index-1){n.fill(-1/0),n[this.timestamp_begin]=0;continue}let o=e[s].slice(this.begin_index),a=o.length>=1&&o[o.length-1]>=this.timestamp_begin,i=o.length<2||o[o.length-2]>=this.timestamp_begin;if(a&&(i?n.subarray(this.timestamp_begin).fill(-1/0):n.subarray(0,this.eos_token_id).fill(-1/0)),e[s].length===this.begin_index&&this.max_initial_timestamp_index!==null){let f=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(f+1).fill(-1/0)}let l=vp(n),u=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((f,m)=>f+m)),d=Te(l.subarray(0,this.timestamp_begin))[0];u>d&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return r}},Ul=class extends jt{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let r=e.length,s=[];for(let o=0;o<r+1-this.no_repeat_ngram_size;++o){let a=[];for(let i=0;i<this.no_repeat_ngram_size;++i)a.push(e[o+i]);s.push(a.map(Number))}let n=new Map;for(let o of s){let a=o.slice(0,o.length-1),i=JSON.stringify(a),l=n.get(i)??[];l.push(o[o.length-1]),n.set(i,l)}return n}getGeneratedNgrams(e,r){let s=r.slice(r.length+1-this.no_repeat_ngram_size,r.length);return e.get(JSON.stringify(s.map(Number)))??[]}calcBannedNgramTokens(e){let r=[];if(e.length+1<this.no_repeat_ngram_size)return r;{let s=this.getNgrams(e);return this.getGeneratedNgrams(s,e)}}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data,o=this.calcBannedNgramTokens(e[s]);for(let a of o)n[a]=-1/0}return r}},Bl=class extends jt{constructor(e){super(),this.penalty=e}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data;for(let o of new Set(e[s])){let a=Number(o);n[a]<0?n[a]*=this.penalty:n[a]/=this.penalty}}return r}},Dl=class extends jt{constructor(e,r){super(),this.min_length=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length<this.min_length){let n=r[s].data;for(let o of this.eos_token_id)n[o]=-1/0}return r}},Fl=class extends jt{constructor(e,r,s){super(),this.prompt_length_to_skip=e,this.min_new_tokens=r,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length-this.prompt_length_to_skip<this.min_new_tokens){let o=r[s].data;for(let a of this.eos_token_id)o[a]=-1/0}return r}},jl=class extends jt{constructor(e,r){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data,o=e[s];for(let a of this.bad_words_ids){if(o.length<a.length-1)continue;let i=!0;for(let l=1;l<=a.length-1;++l)if(a.at(-l-1)!=o.at(-l)){i=!1;break}i&&(n[a.at(-1)]=-1/0)}}return r}},Gl=class extends jt{constructor(e){if(super(),e<=1)throw new Error(`Require guidance scale >1 to use the classifier free guidance processor, got guidance scale ${e}.`);this.guidance_scale=e}_call(e,r){if(r.dims[0]!==2*e.length)throw new Error(`Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size ${r.dims[0]} for the logits and ${e.length} for the input ids.`);let s=e.length,n=r.slice([0,s],null),o=r.slice([s,r.dims[0]],null);for(let a=0;a<o.data.length;++a)o.data[a]+=(n.data[a]-o.data[a])*this.guidance_scale;return o}},ql=class extends lo{constructor(e){if(super(),typeof e!="number"||e<=0){let r=`\`temperature\` (=${e}) must be a strictly positive float, otherwise your next token scores will be invalid.`;e===0&&(r+=" If you're looking for greedy decoding strategies, set `do_sample=false`.")}this.temperature=e}_call(e,r){let s=r.data;for(let n=0;n<s.length;++n)s[n]/=this.temperature;return r}},YE=class extends lo{constructor(e,{filter_value:r=-1/0,min_tokens_to_keep:s=1}={}){if(super(),e<0||e>1)throw new Error(`\`top_p\` must be a float > 0 and < 1, but is ${e}`);if(!Number.isInteger(s)||s<1)throw new Error(`\`min_tokens_to_keep\` must be a positive integer, but is ${s}`);this.top_p=e,this.filter_value=r,this.min_tokens_to_keep=s}},QE=class extends lo{constructor(e,{filter_value:r=-1/0,min_tokens_to_keep:s=1}={}){if(super(),!Number.isInteger(e)||e<0)throw new Error(`\`top_k\` must be a positive integer, but is ${e}`);this.top_k=Math.max(e,s),this.filter_value=r}};var sn=class{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;streamer=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,ot(e,Object.getOwnPropertyNames(this)))}};var nn=class extends Je{_call(e,r){throw Error("StoppingCriteria needs to be subclassed")}},Wl=class t extends Je{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof nn&&(e=[e]),this.criteria.push(...e)}_call(e,r){let s=new Array(e.length).fill(!1);for(let n of this.criteria){let o=n(e,r);for(let a=0;a<s.length;++a)s[a]||=o[a]}return s}[Symbol.iterator](){return this.criteria.values()}},Vl=class extends nn{constructor(e,r=null){super(),this.max_length=e,this.max_position_embeddings=r}_call(e){return e.map(r=>r.length>=this.max_length)}},Hl=class extends nn{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,r){return e.map(s=>{let n=s.at(-1);return this.eos_token_id.some(o=>n==o)})}},JE=class extends nn{constructor(){super(),this.interrupted=!1}interrupt(){this.interrupted=!0}reset(){this.interrupted=!1}_call(e,r){return new Array(e.length).fill(this.interrupted)}};var _s=class extends Je{constructor(e){super(),this.generation_config=e}async _call(e){return this.sample(e)}async sample(e){throw Error("sample should be implemented in subclasses.")}getLogits(e,r){let s=e.dims.at(-1),n=e.data;if(r===-1)n=n.slice(-s);else{let o=r*s;n=n.slice(o,o+s)}return n}randomSelect(e){let r=0;for(let n=0;n<e.length;++n)r+=e[n];let s=Math.random()*r;for(let n=0;n<e.length;++n)if(s-=e[n],s<=0)return n;return 0}static getSampler(e){if(e.do_sample)return new Wm(e);if(e.num_beams>1)return new Vm(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new qm(e)}},qm=class extends _s{async sample(e){let r=Te(e.data)[1];return[[BigInt(r),0]]}},Wm=class extends _s{async sample(e){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let[s,n]=await Yt(e,r),o=Pe(s.data);return Array.from({length:this.generation_config.num_beams},()=>{let a=this.randomSelect(o);return[n.data[a],Math.log(o[a])]})}},Vm=class extends _s{async sample(e){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let[s,n]=await Yt(e,r),o=Pe(s.data);return Array.from({length:this.generation_config.num_beams},(a,i)=>[n.data[i],Math.log(o[i])])}};var co=null;function eA(t){co=t}function Hm(t){if(t instanceof U)return t;if(t.length===0)throw Error("items must be non-empty");if(Array.isArray(t[0])){if(t.some(e=>e.length!==t[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new U("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new U("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function Xm(t){return new U("bool",[t],[1])}var H={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,DecoderOnlyWithoutHead:5,MaskGeneration:6,ImageTextToText:7,Musicgen:8,MultiModality:9,Phi3V:10,AudioTextToText:11,AutoEncoder:12,ImageAudioTextToText:13,Supertonic:14,Chatterbox:15},ZE={[H.DecoderOnly]:{can_generate:!0,forward:Tt,prepare_inputs:uo},[H.DecoderOnlyWithoutHead]:{can_generate:!1,forward:Tt,prepare_inputs:uo},[H.Seq2Seq]:{can_generate:!0,forward:Xl,prepare_inputs:po},[H.Vision2Seq]:{can_generate:!0,forward:Xl,prepare_inputs:po},[H.Musicgen]:{can_generate:!0,forward:Xl},[H.EncoderDecoder]:{can_generate:!1,forward:Xl},[H.ImageTextToText]:{can_generate:!0,forward:UP,prepare_inputs:Kl},[H.AudioTextToText]:{can_generate:!0,forward:RP,prepare_inputs:Kl},[H.Phi3V]:{can_generate:!0,prepare_inputs:Kl},[H.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Kl},[H.MultiModality]:{can_generate:!0},[H.AutoEncoder]:{can_generate:!1,forward:$P},[H.Chatterbox]:{can_generate:!0,forward:Gt},default:{can_generate:!1,forward:Gt}},ws=new Map,Yl=new Map,gs=new Map,y=class extends Je{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];_return_dict_in_generate_keys=null;constructor(e,r,s){super(),this.config=e,this.sessions=r,this.configs=s;let n=gs.get(this.constructor),o=ws.get(n),a=ZE[o]??ZE.default;this.can_generate=a.can_generate,this._forward=a.forward,this._prepare_inputs_for_generation=a.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){let e=[];for(let r of Object.values(this.sessions))e.push(r.release?.());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",model_file_name:i=null,subfolder:l="onnx",device:u=null,dtype:d=null,use_external_data_format:f=null,session_options:m={}}={}){let _={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,model_file_name:i,subfolder:l,device:u,dtype:d,use_external_data_format:f,session_options:m},w=gs.get(this),x=ws.get(w);s=_.config=await ms.from_pretrained(e,_);let k;if(x===H.DecoderOnly)k=await Promise.all([bt(e,{model:_.model_file_name??"model"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Seq2Seq||x===H.Vision2Seq)k=await Promise.all([bt(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.MaskGeneration)k=await Promise.all([bt(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},_)]);else if(x===H.EncoderDecoder)k=await Promise.all([bt(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged")]);else if(x===H.ImageTextToText){let E={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};s.is_encoder_decoder&&(E.model="encoder_model"),k=await Promise.all([bt(e,E,_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.AudioTextToText){let E={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"};k=await Promise.all([bt(e,E,_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.ImageAudioTextToText){let E={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};k=await Promise.all([bt(e,E,_),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.Musicgen)k=await Promise.all([bt(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.MultiModality)k=await Promise.all([bt(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"language_model",lm_head:"lm_head",gen_head:"gen_head",gen_img_embeds:"gen_img_embeds",image_decode:"image_decode"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Phi3V)k=await Promise.all([bt(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Chatterbox)k=await Promise.all([bt(e,{embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.AutoEncoder)k=await Promise.all([bt(e,{encoder_model:"encoder_model",decoder_model:"decoder_model"},_)]);else if(x===H.Supertonic)k=await Promise.all([bt(e,{text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"},_)]);else{if(x===void 0){let E=w??s?.model_type;E!=="custom"&&console.warn(`Model type for '${E}' not found, assuming encoder-only architecture. Please report this at ${Hs}.`)}k=await Promise.all([bt(e,{model:_.model_file_name??"model"},_)])}return new this(s,...k)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_processor(e,r,s=null){let n=new hs;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Bl(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Ul(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new jl(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new Dl(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&n.push(new Fl(r,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new Nl(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new $l(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let o=r>1||e.forced_bos_token_id===null?r:r+1;n.push(new rn(e.begin_suppress_tokens,o))}return e.guidance_scale!==null&&e.guidance_scale>1&&n.push(new Gl(e.guidance_scale)),e.temperature===0&&e.do_sample&&(console.warn("`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."),e.do_sample=!1),e.do_sample&&e.temperature!==null&&e.temperature!==1&&n.push(new ql(e.temperature)),s!==null&&n.extend(s),n}_prepare_generation_config(e,r,s=sn){let n={...this.config};for(let a of["decoder","generator","text_config"])a in n&&Object.assign(n,n[a]);let o=new s(n);return Object.assign(o,this.generation_config??{}),e&&Object.assign(o,e),r&&Object.assign(o,ot(r,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,r=null){let s=new Wl;return e.max_length!==null&&s.push(new Vl(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&s.push(new Hl(e.eos_token_id)),r&&s.extend(r),s}_validate_model_class(){if(!this.can_generate){let e=[co.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,co.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,co.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,co.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),r=gs.get(this.constructor),s=new Set,n=this.config.model_type;for(let a of e){let i=a?.get(n);i&&s.add(i)}let o=`The current model class (${r}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw s.size>0&&(o+=` Please use the following class instead: ${[...s].join(", ")}`),Error(o)}}prepare_inputs_for_generation(...e){if(!this._prepare_inputs_for_generation)throw new Error("prepare_inputs_for_generation is not implemented for this model.");return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:r,model_inputs:s,is_encoder_decoder:n}){return s.past_key_values=this.getPastKeyValues(r,s.past_key_values),s.input_ids=new U("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in s:s.attention_mask=Ee([s.attention_mask,it([s.attention_mask.dims[0],1])],1),s.position_ids=null,s}_prepare_model_inputs({inputs:e,bos_token_id:r,model_kwargs:s}){let n=ot(s,this.forward_params),o=this.main_input_name;if(o in n){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else n[o]=e;return{inputs_tensor:n[o],model_inputs:n,model_input_name:o}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:r,model_input_name:s,generation_config:n}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!r.inputs_embeds&&"_prepare_inputs_embeds"in this){let{input_ids:a,pixel_values:i,attention_mask:l,...u}=r,d=await this._prepare_inputs_embeds(r);r={...u,...ot(d,["inputs_embeds","attention_mask"])}}let{last_hidden_state:o}=await Gt(this,r);if(n.guidance_scale!==null&&n.guidance_scale>1)o=Ee([o,Qn(o,0)],0),"attention_mask"in r&&(r.attention_mask=Ee([r.attention_mask,kd(r.attention_mask)],0));else if(r.decoder_input_ids){let a=Hm(r.decoder_input_ids).dims[0];if(a!==o.dims[0]){if(o.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${o.dims[0]}) than the decoder inputs (${a}).`);o=Ee(Array.from({length:a},()=>o),0)}}return r.encoder_outputs=o,r}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:r,model_kwargs:s,decoder_start_token_id:n,bos_token_id:o,generation_config:a}){let{decoder_input_ids:i,...l}=s;if(!(i instanceof U)){if(i)Array.isArray(i[0])||(i=Array.from({length:e},()=>i));else if(n??=o,this.config.model_type==="musicgen")i=Array.from({length:e*this.config.decoder.num_codebooks},()=>[n]);else if(Array.isArray(n)){if(n.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${n.length}`);i=n}else i=Array.from({length:e},()=>[n]);i=Hm(i)}return s.decoder_attention_mask=il(i),{input_ids:i,model_inputs:l}}async generate({inputs:e=null,generation_config:r=null,logits_processor:s=null,stopping_criteria:n=null,streamer:o=null,...a}){this._validate_model_class(),r=this._prepare_generation_config(r,a);let{inputs_tensor:i,model_inputs:l,model_input_name:u}=this._prepare_model_inputs({inputs:e,model_kwargs:a}),d=this.config.is_encoder_decoder;d&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:l,model_input_name:u,generation_config:r})));let f;d?{input_ids:f,model_inputs:l}=this._prepare_decoder_input_ids_for_generation({batch_size:l[u].dims.at(0),model_input_name:u,model_kwargs:l,decoder_start_token_id:r.decoder_start_token_id,bos_token_id:r.bos_token_id,generation_config:r}):f=l[u];let m=f.dims.at(-1);r.max_new_tokens!==null&&(r.max_length=m+r.max_new_tokens);let _=this._get_logits_processor(r,m,s),w=this._get_stopping_criteria(r,n),x=l[u].dims.at(0),k=_s.getSampler(r),E=new Array(x).fill(0),M=f.tolist();o&&o.put(M);let I,T={},z={};for(;;){if(l=this.prepare_inputs_for_generation(M,l,r),I=await this.forward(l),r.return_dict_in_generate)if(r.output_attentions){let K=this.getAttentions(I);for(let Y in K)Y in T||(T[Y]=[]),T[Y].push(K[Y])}else this._return_dict_in_generate_keys&&Object.assign(z,ot(I,this._return_dict_in_generate_keys));let G=I.logits.slice(null,-1,null).to("float32"),X=_(M,G),V=[];for(let K=0;K<X.dims.at(0);++K){let Y=X[K],B=await k(Y);for(let[P,se]of B){let ie=BigInt(P);E[K]+=se,M[K].push(ie),V.push([ie]);break}}if(o&&o.put(V),w(M).every(K=>K))break;l=this._update_model_kwargs_for_generation({generated_input_ids:V,outputs:I,model_inputs:l,is_encoder_decoder:d})}o&&o.end();let C=this.getPastKeyValues(I,l.past_key_values,!0),v=new U("int64",M.flat(),[M.length,M[0].length]);if(r.return_dict_in_generate)return{sequences:v,past_key_values:C,...T,...z};for(let G of Object.values(I))G.location==="gpu-buffer"&&G.dispose();return v}getPastKeyValues(e,r,s=!1){let n=Object.create(null);for(let o in e)if(o.startsWith("present")){let a=o.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present","past_key_values"),i=o.includes("encoder");if(i&&r?n[a]=r[a]:n[a]=e[o],r&&(!i||s)){let l=r[a];l.location==="gpu-buffer"&&l.dispose()}}return n}getAttentions(e){let r={};for(let s of["cross_attentions","encoder_attentions","decoder_attentions"])for(let n in e)n.startsWith(s)&&(s in r||(r[s]=[]),r[s].push(e[n]));return r}addPastKeyValues(e,r){if(r)Object.assign(e,r);else{let s=this.sessions.decoder_model_merged??this.sessions.model,n=(e[this.main_input_name]??e.attention_mask)?.dims?.[0]??1,o=s?.config?.kv_cache_dtype??"float32",a=o==="float16"?Ws.float16:Ws.float32,i=zl(this.config,{batch_size:n});for(let l in i){let u=i[l].reduce((d,f)=>d*f,1);e[l]=new U(o,new a(u),i[l])}}}async encode_image({pixel_values:e}){return(await ce(this.sessions.vision_encoder,{pixel_values:e})).image_features}async encode_text({input_ids:e}){return(await ce(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}async encode_audio({audio_values:e}){return(await ce(this.sessions.audio_encoder,{audio_values:e})).audio_features}};async function Xl(t,e){let{encoder_outputs:r,input_ids:s,decoder_input_ids:n,...o}=e;if(!r){let a=ot(e,t.sessions.model.inputNames);r=(await Gt(t,a)).last_hidden_state}return o.input_ids=n,o.encoder_hidden_states=r,t.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=e.attention_mask),await Tt(t,o,!0)}async function Gt(t,e){let r=t.sessions.model,s=ot(e,r.inputNames);if(r.inputNames.includes("inputs_embeds")&&!s.inputs_embeds){if(!e.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");s.inputs_embeds=await t.encode_text({input_ids:e.input_ids})}if(r.inputNames.includes("token_type_ids")&&!s.token_type_ids){if(!s.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");s.token_type_ids=kd(s.input_ids)}if(r.inputNames.includes("pixel_mask")&&!s.pixel_mask){if(!s.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");let n=s.pixel_values.dims;s.pixel_mask=it([n[0],n[2],n[3]])}return await ce(r,s)}async function $P(t,e){let r=await t.encode(e);return await t.decode(r)}async function Tt(t,e,r=!1){let s=t.sessions[r?"decoder_model_merged":"model"],{past_key_values:n,...o}=e;if(s.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=Xm(!!n)),s.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids){let i=["paligemma","gemma3_text","gemma3"].includes(t.config.model_type)?1:0;o.position_ids=BP(o,n,i)}t.addPastKeyValues(o,n);let a=ot(o,s.inputNames);return await ce(s,a)}async function tA(t,{encode_function:e,merge_function:r,modality_input_name:s,modality_output_name:n,input_ids:o=null,attention_mask:a=null,position_ids:i=null,inputs_embeds:l=null,past_key_values:u=null,generation_config:d=null,logits_processor:f=null,...m}){let _=m[s];if(!l){if(l=await t.encode_text({input_ids:o,...m}),_&&o.dims[1]!==1){let x=await e({[s]:_,...m});({inputs_embeds:l,attention_mask:a}=r({[n]:x,inputs_embeds:l,input_ids:o,attention_mask:a}))}else if(u&&_&&o.dims[1]===1){let x=o.dims[1],k=Object.values(u)[0].dims.at(-2);a=Ee([it([o.dims[0],k]),a.slice(null,[a.dims[1]-x,a.dims[1]])],1)}}if(!i&&t.config.model_type==="qwen2_vl"){let{image_grid_thw:x,video_grid_thw:k}=m;[i]=t.get_rope_index(o,x,k,a)}return await Tt(t,{inputs_embeds:l,past_key_values:u,attention_mask:a,position_ids:i,generation_config:d,logits_processor:f},!0)}async function RP(t,e){return await tA(t,{...e,modality_input_name:"audio_values",modality_output_name:"audio_features",encode_function:t.encode_audio.bind(t),merge_function:t._merge_input_ids_with_audio_features.bind(t)})}async function UP(t,e){return await tA(t,{...e,modality_input_name:"pixel_values",modality_output_name:"image_features",encode_function:t.encode_image.bind(t),merge_function:t._merge_input_ids_with_image_features.bind(t)})}function Km(t,e=0){let[r,s]=t.dims,n=t.data,o=new BigInt64Array(n.length);for(let a=0;a<r;++a){let i=a*s,l=BigInt(e);for(let u=0;u<s;++u){let d=i+u;n[d]===0n?o[d]=BigInt(1):(o[d]=l,l+=n[d])}}return{data:o,dims:t.dims}}function BP(t,e=null,r=0){let{input_ids:s,inputs_embeds:n,attention_mask:o}=t,{data:a,dims:i}=Km(o,r),l=new U("int64",a,i);if(e){let u=-(s??n).dims.at(1);l=l.slice(null,[u,null])}return l}function uo(t,e,r,s){let n=r.past_key_values?Object.values(r.past_key_values)[0].dims.at(-2):0;if(!r.attention_mask){let o;for(let a of["input_ids","inputs_embeds","position_ids"])if(r[a]){o=r[a].dims;break}if(!o)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");r.attention_mask=it([o[0],n+o[1]])}if(r.past_key_values){let{input_ids:o,attention_mask:a}=r;a&&a.dims[1]>o.dims[1]||n<o.dims[1]&&(r.input_ids=o.slice(null,[n,null]))}return r}function po(t,e,r,s){return r.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...r,decoder_input_ids:Hm(e)}}function Kl(t,...e){return t.config.is_encoder_decoder?po(t,...e):uo(t,...e)}function rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n}){let o=s.tolist().map(u=>u.reduce((d,f,m)=>(f==t&&d.push(m),d),[])),a=o.reduce((u,d)=>u+d.length,0),i=r.dims[0];if(a!==i)throw new Error(`Number of tokens and features do not match: tokens: ${a}, features ${i}`);let l=0;for(let u=0;u<o.length;++u){let d=o[u],f=e[u];for(let m=0;m<d.length;++m)f[d[m]].data.set(r[l++].data)}return{inputs_embeds:e,attention_mask:n}}function ar({image_token_id:t,inputs_embeds:e,image_features:r,input_ids:s,attention_mask:n}){return rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n})}function Ql({audio_token_id:t,inputs_embeds:e,audio_features:r,input_ids:s,attention_mask:n}){return rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n})}async function gr(t,e,r){return Object.fromEntries(await Promise.all(Object.keys(e).map(async s=>{let n=await at(t,e[s],!1,r);return[s,n]})))}var di={};Ps(di,{ASTForAudioClassification:()=>oh,ASTModel:()=>nh,ASTPreTrainedModel:()=>ho,AlbertForMaskedLM:()=>Zm,AlbertForQuestionAnswering:()=>Jm,AlbertForSequenceClassification:()=>Qm,AlbertModel:()=>Ym,AlbertPreTrainedModel:()=>xs,ApertusForCausalLM:()=>th,ApertusModel:()=>eh,ApertusPreTrainedModel:()=>fo,ArceeForCausalLM:()=>sh,ArceeModel:()=>rh,ArceePreTrainedModel:()=>mo,BartForConditionalGeneration:()=>ih,BartForSequenceClassification:()=>lh,BartModel:()=>ah,BartPretrainedModel:()=>on,BeitForImageClassification:()=>uh,BeitModel:()=>ch,BeitPreTrainedModel:()=>_o,BertForMaskedLM:()=>dh,BertForQuestionAnswering:()=>hh,BertForSequenceClassification:()=>fh,BertForTokenClassification:()=>mh,BertModel:()=>ph,BertPreTrainedModel:()=>Cr,BlenderbotForConditionalGeneration:()=>gh,BlenderbotModel:()=>_h,BlenderbotPreTrainedModel:()=>go,BlenderbotSmallForConditionalGeneration:()=>xh,BlenderbotSmallModel:()=>wh,BlenderbotSmallPreTrainedModel:()=>wo,BloomForCausalLM:()=>bh,BloomModel:()=>yh,BloomPreTrainedModel:()=>xo,CLIPModel:()=>Oh,CLIPPreTrainedModel:()=>ir,CLIPSegForImageSegmentation:()=>Lh,CLIPSegModel:()=>zh,CLIPSegPreTrainedModel:()=>Eo,CLIPTextModel:()=>Ih,CLIPTextModelWithProjection:()=>ko,CLIPVisionModel:()=>Ch,CLIPVisionModelWithProjection:()=>Ph,CamembertForMaskedLM:()=>kh,CamembertForQuestionAnswering:()=>Mh,CamembertForSequenceClassification:()=>Eh,CamembertForTokenClassification:()=>Ah,CamembertModel:()=>vh,CamembertPreTrainedModel:()=>Pr,ChatterboxModel:()=>yo,ChatterboxPreTrainedModel:()=>Jl,ChineseCLIPModel:()=>Th,ChineseCLIPPreTrainedModel:()=>Zl,ClapAudioModelWithProjection:()=>vo,ClapModel:()=>Sh,ClapPreTrainedModel:()=>an,ClapTextModelWithProjection:()=>bo,CodeGenForCausalLM:()=>$h,CodeGenModel:()=>Nh,CodeGenPreTrainedModel:()=>Ao,CohereForCausalLM:()=>Uh,CohereModel:()=>Rh,CoherePreTrainedModel:()=>Mo,ConvBertForMaskedLM:()=>Dh,ConvBertForQuestionAnswering:()=>Gh,ConvBertForSequenceClassification:()=>Fh,ConvBertForTokenClassification:()=>jh,ConvBertModel:()=>Bh,ConvBertPreTrainedModel:()=>zr,ConvNextForImageClassification:()=>Wh,ConvNextModel:()=>qh,ConvNextPreTrainedModel:()=>To,ConvNextV2ForImageClassification:()=>Hh,ConvNextV2Model:()=>Vh,ConvNextV2PreTrainedModel:()=>So,DFineForObjectDetection:()=>Qh,DFineModel:()=>Yh,DFinePreTrainedModel:()=>Io,DINOv3ConvNextModel:()=>b_,DINOv3ConvNextPreTrainedModel:()=>ac,DINOv3ViTModel:()=>v_,DINOv3ViTPreTrainedModel:()=>ic,DPTForDepthEstimation:()=>I_,DPTModel:()=>O_,DPTPreTrainedModel:()=>$o,DacDecoderModel:()=>Po,DacDecoderOutput:()=>tc,DacEncoderModel:()=>Co,DacEncoderOutput:()=>ec,DacModel:()=>Jh,DacPreTrainedModel:()=>ln,DebertaForMaskedLM:()=>e_,DebertaForQuestionAnswering:()=>s_,DebertaForSequenceClassification:()=>t_,DebertaForTokenClassification:()=>r_,DebertaModel:()=>Zh,DebertaPreTrainedModel:()=>Lr,DebertaV2ForMaskedLM:()=>o_,DebertaV2ForQuestionAnswering:()=>l_,DebertaV2ForSequenceClassification:()=>a_,DebertaV2ForTokenClassification:()=>i_,DebertaV2Model:()=>n_,DebertaV2PreTrainedModel:()=>Nr,DecisionTransformerModel:()=>c_,DecisionTransformerPreTrainedModel:()=>rc,DeiTForImageClassification:()=>p_,DeiTModel:()=>u_,DeiTPreTrainedModel:()=>zo,DepthAnythingForDepthEstimation:()=>d_,DepthAnythingPreTrainedModel:()=>sc,DepthProForDepthEstimation:()=>f_,DepthProPreTrainedModel:()=>nc,DetrForObjectDetection:()=>h_,DetrForSegmentation:()=>__,DetrModel:()=>m_,DetrObjectDetectionOutput:()=>un,DetrPreTrainedModel:()=>cn,DetrSegmentationOutput:()=>oc,Dinov2ForImageClassification:()=>w_,Dinov2Model:()=>g_,Dinov2PreTrainedModel:()=>Lo,Dinov2WithRegistersForImageClassification:()=>y_,Dinov2WithRegistersModel:()=>x_,Dinov2WithRegistersPreTrainedModel:()=>No,DistilBertForMaskedLM:()=>T_,DistilBertForQuestionAnswering:()=>M_,DistilBertForSequenceClassification:()=>E_,DistilBertForTokenClassification:()=>A_,DistilBertModel:()=>k_,DistilBertPreTrainedModel:()=>$r,DonutSwinModel:()=>S_,DonutSwinPreTrainedModel:()=>lc,EdgeTamModel:()=>fy,EfficientNetForImageClassification:()=>P_,EfficientNetModel:()=>C_,EfficientNetPreTrainedModel:()=>Ro,ElectraForMaskedLM:()=>L_,ElectraForQuestionAnswering:()=>R_,ElectraForSequenceClassification:()=>N_,ElectraForTokenClassification:()=>$_,ElectraModel:()=>z_,ElectraPreTrainedModel:()=>Rr,Ernie4_5ForCausalLM:()=>B_,Ernie4_5Model:()=>U_,Ernie4_5PretrainedModel:()=>Uo,EsmForMaskedLM:()=>F_,EsmForSequenceClassification:()=>j_,EsmForTokenClassification:()=>G_,EsmModel:()=>D_,EsmPreTrainedModel:()=>ys,ExaoneForCausalLM:()=>W_,ExaoneModel:()=>q_,ExaonePreTrainedModel:()=>Bo,FalconForCausalLM:()=>H_,FalconH1ForCausalLM:()=>K_,FalconH1Model:()=>X_,FalconH1PreTrainedModel:()=>Fo,FalconModel:()=>V_,FalconPreTrainedModel:()=>Do,FastViTForImageClassification:()=>Q_,FastViTModel:()=>Y_,FastViTPreTrainedModel:()=>jo,Florence2ForConditionalGeneration:()=>J_,Florence2PreTrainedModel:()=>cc,GLPNForDepthEstimation:()=>lg,GLPNModel:()=>ig,GLPNPreTrainedModel:()=>Xo,GPT2LMHeadModel:()=>wg,GPT2Model:()=>gg,GPT2PreTrainedModel:()=>Zo,GPTBigCodeForCausalLM:()=>ug,GPTBigCodeModel:()=>cg,GPTBigCodePreTrainedModel:()=>Ko,GPTJForCausalLM:()=>yg,GPTJModel:()=>xg,GPTJPreTrainedModel:()=>ea,GPTNeoForCausalLM:()=>dg,GPTNeoModel:()=>pg,GPTNeoPreTrainedModel:()=>Yo,GPTNeoXForCausalLM:()=>mg,GPTNeoXModel:()=>fg,GPTNeoXPreTrainedModel:()=>Qo,Gemma2ForCausalLM:()=>rg,Gemma2Model:()=>tg,Gemma2PreTrainedModel:()=>qo,Gemma3ForCausalLM:()=>ng,Gemma3Model:()=>sg,Gemma3PreTrainedModel:()=>Wo,Gemma3nForConditionalGeneration:()=>Vo,Gemma3nPreTrainedModel:()=>uc,GemmaForCausalLM:()=>eg,GemmaModel:()=>Z_,GemmaPreTrainedModel:()=>Go,GlmForCausalLM:()=>ag,GlmModel:()=>og,GlmPreTrainedModel:()=>Ho,GptOssForCausalLM:()=>_g,GptOssModel:()=>hg,GptOssPreTrainedModel:()=>Jo,GraniteForCausalLM:()=>vg,GraniteModel:()=>bg,GraniteMoeHybridForCausalLM:()=>Eg,GraniteMoeHybridModel:()=>kg,GraniteMoeHybridPreTrainedModel:()=>ra,GranitePreTrainedModel:()=>ta,GroundingDinoForObjectDetection:()=>Ag,GroundingDinoPreTrainedModel:()=>pc,GroupViTModel:()=>Mg,GroupViTPreTrainedModel:()=>dc,HeliumForCausalLM:()=>Sg,HeliumModel:()=>Tg,HeliumPreTrainedModel:()=>sa,HieraForImageClassification:()=>Ig,HieraModel:()=>Og,HieraPreTrainedModel:()=>na,HubertForCTC:()=>Rg,HubertForSequenceClassification:()=>Ug,HubertModel:()=>$g,HubertPreTrainedModel:()=>Ng,HunYuanDenseV1ForCausalLM:()=>Dg,HunYuanDenseV1Model:()=>Bg,HunYuanDenseV1PreTrainedModel:()=>oa,IJepaForImageClassification:()=>Gg,IJepaModel:()=>jg,IJepaPreTrainedModel:()=>aa,Idefics3ForConditionalGeneration:()=>mc,Idefics3PreTrainedModel:()=>fc,JAISLMHeadModel:()=>Wg,JAISModel:()=>qg,JAISPreTrainedModel:()=>ia,JinaCLIPModel:()=>Vg,JinaCLIPPreTrainedModel:()=>pn,JinaCLIPTextModel:()=>la,JinaCLIPVisionModel:()=>Hg,Lfm2ForCausalLM:()=>Kg,Lfm2Model:()=>Xg,Lfm2MoeForCausalLM:()=>Qg,Lfm2MoeModel:()=>Yg,Lfm2MoePreTrainedModel:()=>ua,Lfm2PreTrainedModel:()=>ca,LiteWhisperForConditionalGeneration:()=>E0,Llama4ForCausalLM:()=>ew,Llama4PreTrainedModel:()=>hc,LlamaForCausalLM:()=>Zg,LlamaModel:()=>Jg,LlamaPreTrainedModel:()=>pa,LlavaForConditionalGeneration:()=>dn,LlavaOnevisionForConditionalGeneration:()=>dn,LlavaPreTrainedModel:()=>_c,LlavaQwen2ForCausalLM:()=>rw,LongT5ForConditionalGeneration:()=>nw,LongT5Model:()=>sw,LongT5PreTrainedModel:()=>da,M2M100ForConditionalGeneration:()=>aw,M2M100Model:()=>ow,M2M100PreTrainedModel:()=>fa,MBartForCausalLM:()=>mw,MBartForConditionalGeneration:()=>dw,MBartForSequenceClassification:()=>fw,MBartModel:()=>pw,MBartPreTrainedModel:()=>bs,MPNetForMaskedLM:()=>Jw,MPNetForQuestionAnswering:()=>tx,MPNetForSequenceClassification:()=>Zw,MPNetForTokenClassification:()=>ex,MPNetModel:()=>Qw,MPNetPreTrainedModel:()=>Ur,MT5ForConditionalGeneration:()=>ox,MT5Model:()=>nx,MT5PreTrainedModel:()=>Aa,MarianMTModel:()=>lw,MarianModel:()=>iw,MarianPreTrainedModel:()=>ma,MaskFormerForInstanceSegmentation:()=>uw,MaskFormerModel:()=>cw,MaskFormerPreTrainedModel:()=>ha,Metric3DForDepthEstimation:()=>hw,Metric3DPreTrainedModel:()=>gc,Metric3Dv2ForDepthEstimation:()=>_w,Metric3Dv2PreTrainedModel:()=>wc,MgpstrForSceneTextRecognition:()=>gw,MgpstrModelOutput:()=>xc,MgpstrPreTrainedModel:()=>yc,MimiDecoderModel:()=>ga,MimiDecoderOutput:()=>vc,MimiEncoderModel:()=>_a,MimiEncoderOutput:()=>bc,MimiModel:()=>ww,MimiPreTrainedModel:()=>fn,MistralForCausalLM:()=>yw,MistralModel:()=>xw,MistralPreTrainedModel:()=>wa,MobileBertForMaskedLM:()=>vw,MobileBertForQuestionAnswering:()=>Ew,MobileBertForSequenceClassification:()=>kw,MobileBertModel:()=>bw,MobileBertPreTrainedModel:()=>vs,MobileLLMForCausalLM:()=>Mw,MobileLLMModel:()=>Aw,MobileLLMPreTrainedModel:()=>xa,MobileNetV1ForImageClassification:()=>Sw,MobileNetV1ForSemanticSegmentation:()=>Ow,MobileNetV1Model:()=>Tw,MobileNetV1PreTrainedModel:()=>mn,MobileNetV2ForImageClassification:()=>Cw,MobileNetV2ForSemanticSegmentation:()=>Pw,MobileNetV2Model:()=>Iw,MobileNetV2PreTrainedModel:()=>hn,MobileNetV3ForImageClassification:()=>Lw,MobileNetV3ForSemanticSegmentation:()=>Nw,MobileNetV3Model:()=>zw,MobileNetV3PreTrainedModel:()=>_n,MobileNetV4ForImageClassification:()=>Rw,MobileNetV4ForSemanticSegmentation:()=>Uw,MobileNetV4Model:()=>$w,MobileNetV4PreTrainedModel:()=>gn,MobileViTForImageClassification:()=>Dw,MobileViTModel:()=>Bw,MobileViTPreTrainedModel:()=>ya,MobileViTV2ForImageClassification:()=>jw,MobileViTV2Model:()=>Fw,MobileViTV2PreTrainedModel:()=>ba,ModernBertDecoderForCausalLM:()=>Xw,ModernBertDecoderModel:()=>Hw,ModernBertDecoderPreTrainedModel:()=>va,ModernBertForMaskedLM:()=>qw,ModernBertForSequenceClassification:()=>Ww,ModernBertForTokenClassification:()=>Vw,ModernBertModel:()=>Gw,ModernBertPreTrainedModel:()=>ks,Moondream1ForConditionalGeneration:()=>tw,MoonshineForConditionalGeneration:()=>Yw,MoonshineModel:()=>Kw,MoonshinePreTrainedModel:()=>ka,MptForCausalLM:()=>sx,MptModel:()=>rx,MptPreTrainedModel:()=>Ea,MultiModalityCausalLM:()=>ax,MultiModalityPreTrainedModel:()=>kc,MusicgenForCausalLM:()=>lx,MusicgenForConditionalGeneration:()=>Ta,MusicgenModel:()=>ix,MusicgenPreTrainedModel:()=>Ma,NanoChatForCausalLM:()=>ux,NanoChatModel:()=>cx,NanoChatPreTrainedModel:()=>Sa,NeoBertForMaskedLM:()=>dx,NeoBertForQuestionAnswering:()=>hx,NeoBertForSequenceClassification:()=>fx,NeoBertForTokenClassification:()=>mx,NeoBertModel:()=>px,NeoBertPreTrainedModel:()=>Br,NomicBertModel:()=>_x,NomicBertPreTrainedModel:()=>Ec,OPTForCausalLM:()=>Mx,OPTModel:()=>Ax,OPTPreTrainedModel:()=>za,Olmo2ForCausalLM:()=>yx,Olmo2Model:()=>xx,Olmo2PreTrainedModel:()=>Ia,Olmo3ForCausalLM:()=>vx,Olmo3Model:()=>bx,Olmo3PreTrainedModel:()=>Ca,OlmoForCausalLM:()=>wx,OlmoModel:()=>gx,OlmoPreTrainedModel:()=>Oa,OpenELMForCausalLM:()=>Ex,OpenELMModel:()=>kx,OpenELMPreTrainedModel:()=>Pa,OwlViTForObjectDetection:()=>Ix,OwlViTModel:()=>Ox,OwlViTPreTrainedModel:()=>Na,Owlv2ForObjectDetection:()=>Sx,Owlv2Model:()=>Tx,Owlv2PreTrainedModel:()=>La,PaliGemmaForConditionalGeneration:()=>Cx,PaliGemmaPreTrainedModel:()=>Ac,ParakeetForCTC:()=>Px,ParakeetPreTrainedModel:()=>Mc,PatchTSMixerForPrediction:()=>Lx,PatchTSMixerModel:()=>zx,PatchTSMixerPreTrainedModel:()=>$a,PatchTSTForPrediction:()=>$x,PatchTSTModel:()=>Nx,PatchTSTPreTrainedModel:()=>Ra,Phi3ForCausalLM:()=>Dx,Phi3Model:()=>Bx,Phi3PreTrainedModel:()=>Ba,Phi3VForCausalLM:()=>Da,Phi3VPreTrainedModel:()=>Tc,PhiForCausalLM:()=>Ux,PhiModel:()=>Rx,PhiPreTrainedModel:()=>Ua,PreTrainedModel:()=>y,PvtForImageClassification:()=>jx,PvtModel:()=>Fx,PvtPreTrainedModel:()=>Fa,PyAnnoteForAudioFrameClassification:()=>qx,PyAnnoteModel:()=>Gx,PyAnnotePreTrainedModel:()=>ja,Qwen2ForCausalLM:()=>Vx,Qwen2Model:()=>Wx,Qwen2PreTrainedModel:()=>Ga,Qwen2VLForConditionalGeneration:()=>Hx,Qwen2VLPreTrainedModel:()=>Sc,Qwen3ForCausalLM:()=>Kx,Qwen3Model:()=>Xx,Qwen3PreTrainedModel:()=>qa,RFDetrForObjectDetection:()=>Zx,RFDetrModel:()=>Jx,RFDetrObjectDetectionOutput:()=>Oc,RFDetrPreTrainedModel:()=>Va,RTDetrForObjectDetection:()=>Kh,RTDetrModel:()=>Xh,RTDetrObjectDetectionOutput:()=>lr,RTDetrPreTrainedModel:()=>Oo,RTDetrV2ForObjectDetection:()=>py,RTDetrV2Model:()=>uy,RTDetrV2ObjectDetectionOutput:()=>Ic,RTDetrV2PreTrainedModel:()=>Ha,ResNetForImageClassification:()=>Qx,ResNetModel:()=>Yx,ResNetPreTrainedModel:()=>Wa,RoFormerForMaskedLM:()=>ay,RoFormerForQuestionAnswering:()=>cy,RoFormerForSequenceClassification:()=>iy,RoFormerForTokenClassification:()=>ly,RoFormerModel:()=>oy,RoFormerPreTrainedModel:()=>Fr,RobertaForMaskedLM:()=>ty,RobertaForQuestionAnswering:()=>ny,RobertaForSequenceClassification:()=>ry,RobertaForTokenClassification:()=>sy,RobertaModel:()=>ey,RobertaPreTrainedModel:()=>Dr,Sam2ImageSegmentationOutput:()=>zc,Sam2Model:()=>Xa,Sam2PreTrainedModel:()=>Lc,Sam3TrackerModel:()=>my,SamImageSegmentationOutput:()=>Cc,SamModel:()=>dy,SamPreTrainedModel:()=>Pc,SapiensForDepthEstimation:()=>_y,SapiensForNormalEstimation:()=>gy,SapiensForSemanticSegmentation:()=>hy,SapiensPreTrainedModel:()=>wn,SegformerForImageClassification:()=>xy,SegformerForSemanticSegmentation:()=>yy,SegformerModel:()=>wy,SegformerPreTrainedModel:()=>xn,SiglipModel:()=>by,SiglipPreTrainedModel:()=>Ka,SiglipTextModel:()=>Ya,SiglipVisionModel:()=>vy,SmolLM3ForCausalLM:()=>Ey,SmolLM3Model:()=>ky,SmolLM3PreTrainedModel:()=>Qa,SmolVLMForConditionalGeneration:()=>Fg,SnacDecoderModel:()=>Za,SnacEncoderModel:()=>Ja,SnacModel:()=>Ay,SnacPreTrainedModel:()=>yn,SpeechT5ForSpeechToText:()=>Ty,SpeechT5ForTextToSpeech:()=>Sy,SpeechT5HifiGan:()=>Oy,SpeechT5Model:()=>My,SpeechT5PreTrainedModel:()=>bn,SqueezeBertForMaskedLM:()=>Cy,SqueezeBertForQuestionAnswering:()=>zy,SqueezeBertForSequenceClassification:()=>Py,SqueezeBertModel:()=>Iy,SqueezeBertPreTrainedModel:()=>Es,StableLmForCausalLM:()=>Ny,StableLmModel:()=>Ly,StableLmPreTrainedModel:()=>ei,Starcoder2ForCausalLM:()=>Ry,Starcoder2Model:()=>$y,Starcoder2PreTrainedModel:()=>ti,StyleTextToSpeech2Model:()=>Uy,StyleTextToSpeech2PreTrainedModel:()=>Nc,SupertonicForConditionalGeneration:()=>ri,SupertonicPreTrainedModel:()=>$c,Swin2SRForImageSuperResolution:()=>Gy,Swin2SRModel:()=>jy,Swin2SRPreTrainedModel:()=>si,SwinForImageClassification:()=>Dy,SwinForSemanticSegmentation:()=>Fy,SwinModel:()=>By,SwinPreTrainedModel:()=>vn,T5ForConditionalGeneration:()=>Wy,T5Model:()=>qy,T5PreTrainedModel:()=>ni,TableTransformerForObjectDetection:()=>Hy,TableTransformerModel:()=>Vy,TableTransformerObjectDetectionOutput:()=>Rc,TableTransformerPreTrainedModel:()=>oi,TrOCRForCausalLM:()=>Xy,TrOCRPreTrainedModel:()=>Uc,UltravoxModel:()=>Dc,UltravoxPreTrainedModel:()=>Bc,UniSpeechForCTC:()=>Qy,UniSpeechForSequenceClassification:()=>Jy,UniSpeechModel:()=>Yy,UniSpeechPreTrainedModel:()=>kn,UniSpeechSatForAudioFrameClassification:()=>r0,UniSpeechSatForCTC:()=>e0,UniSpeechSatForSequenceClassification:()=>t0,UniSpeechSatModel:()=>Zy,UniSpeechSatPreTrainedModel:()=>As,VaultGemmaForCausalLM:()=>n0,VaultGemmaModel:()=>s0,VaultGemmaPreTrainedModel:()=>ai,ViTForImageClassification:()=>i0,ViTMAEModel:()=>l0,ViTMAEPreTrainedModel:()=>Fc,ViTMSNForImageClassification:()=>u0,ViTMSNModel:()=>c0,ViTMSNPreTrainedModel:()=>li,ViTModel:()=>a0,ViTPreTrainedModel:()=>ii,VisionEncoderDecoderModel:()=>o0,VitMatteForImageMatting:()=>p0,VitMattePreTrainedModel:()=>jc,VitPoseForPoseEstimation:()=>d0,VitPosePreTrainedModel:()=>Gc,VitsModel:()=>f0,VitsModelOutput:()=>qc,VitsPreTrainedModel:()=>Wc,VoxtralForConditionalGeneration:()=>Ky,Wav2Vec2BertForCTC:()=>h0,Wav2Vec2BertForSequenceClassification:()=>_0,Wav2Vec2BertModel:()=>m0,Wav2Vec2BertPreTrainedModel:()=>En,Wav2Vec2ForAudioFrameClassification:()=>Lg,Wav2Vec2ForCTC:()=>Pg,Wav2Vec2ForSequenceClassification:()=>zg,Wav2Vec2Model:()=>Cg,Wav2Vec2PreTrainedModel:()=>Jt,WavLMForAudioFrameClassification:()=>b0,WavLMForCTC:()=>w0,WavLMForSequenceClassification:()=>x0,WavLMForXVector:()=>y0,WavLMModel:()=>g0,WavLMPreTrainedModel:()=>jr,WeSpeakerResNetModel:()=>v0,WeSpeakerResNetPreTrainedModel:()=>Hc,WhisperForConditionalGeneration:()=>Kc,WhisperModel:()=>k0,WhisperPreTrainedModel:()=>ci,XLMForQuestionAnswering:()=>O0,XLMForSequenceClassification:()=>T0,XLMForTokenClassification:()=>S0,XLMModel:()=>A0,XLMPreTrainedModel:()=>Gr,XLMRobertaForMaskedLM:()=>C0,XLMRobertaForQuestionAnswering:()=>L0,XLMRobertaForSequenceClassification:()=>P0,XLMRobertaForTokenClassification:()=>z0,XLMRobertaModel:()=>I0,XLMRobertaPreTrainedModel:()=>qr,XLMWithLMHeadModel:()=>M0,XVectorOutput:()=>Vc,YolosForObjectDetection:()=>$0,YolosModel:()=>N0,YolosObjectDetectionOutput:()=>Yc,YolosPreTrainedModel:()=>ui,YoutuForCausalLM:()=>U0,YoutuModel:()=>R0,YoutuPreTrainedModel:()=>pi});var xs=class extends y{},Ym=class extends xs{},Qm=class extends xs{async _call(e){return new F(await super._call(e))}},Jm=class extends xs{async _call(e){return new Ae(await super._call(e))}},Zm=class extends xs{async _call(e){return new we(await super._call(e))}};var fo=class extends y{},eh=class extends fo{},th=class extends fo{};var mo=class extends y{},rh=class extends mo{},sh=class extends mo{};var ho=class extends y{},nh=class extends ho{},oh=class extends ho{};var on=class extends y{},ah=class extends on{},ih=class extends on{},lh=class extends on{async _call(e){return new F(await super._call(e))}};var _o=class extends y{},ch=class extends _o{},uh=class extends _o{async _call(e){return new F(await super._call(e))}};var Cr=class extends y{},ph=class extends Cr{},dh=class extends Cr{async _call(e){return new we(await super._call(e))}},fh=class extends Cr{async _call(e){return new F(await super._call(e))}},mh=class extends Cr{async _call(e){return new _e(await super._call(e))}},hh=class extends Cr{async _call(e){return new Ae(await super._call(e))}};var go=class extends y{},_h=class extends go{},gh=class extends go{};var wo=class extends y{},wh=class extends wo{},xh=class extends wo{};var xo=class extends y{},yh=class extends xo{},bh=class extends xo{};var Pr=class extends y{},vh=class extends Pr{},kh=class extends Pr{async _call(e){return new we(await super._call(e))}},Eh=class extends Pr{async _call(e){return new F(await super._call(e))}},Ah=class extends Pr{async _call(e){return new _e(await super._call(e))}},Mh=class extends Pr{async _call(e){return new Ae(await super._call(e))}};var DP=4299n,sA=6561n,Jl=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"];main_input_name="input_ids";_return_dict_in_generate_keys=["audio_tokens","speaker_embeddings","speaker_features"]},yo=class extends Jl{async encode_speech(e){return ce(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:r=null,audio_values:s=null,exaggeration:n=null,position_ids:o=null,inputs_embeds:a=null,past_key_values:i=null,generation_config:l=null,logits_processor:u=null,audio_features:d=null,audio_tokens:f=null,speaker_embeddings:m=null,speaker_features:_=null,...w}){let x;if(!a){let E=this.sessions.embed_tokens.inputNames,M={input_ids:e};if(E.includes("exaggeration")){if(!(n instanceof U)){let I=e.dims[0];if(n==null)n=Ve([I],.5);else if(typeof n=="number")n=Ve([I],n);else if(Array.isArray(n))n=new U("float32",n,[I]);else throw new Error("Unsupported type for `exaggeration` input")}M.exaggeration=n}if(E.includes("position_ids")&&(M.position_ids=o),{inputs_embeds:a}=await ce(this.sessions.embed_tokens,M),d&&f&&m&&_&&(x={audio_features:d,audio_tokens:f,speaker_embeddings:m,speaker_features:_}),x||s)x??=await this.encode_speech(s),a=Ee([x.audio_features,a],1),r=it([a.dims[0],a.dims[1]]);else{let I=a.dims[1];if(!i||I!==1)throw new Error("Incorrect state encountered during generation.");let T=Object.values(i)[0].dims.at(-2);r=it([a.dims[0],T+I])}}return{...await Tt(this,{inputs_embeds:a,past_key_values:i,attention_mask:r,generation_config:l,logits_processor:u},!1),...x}}prepare_inputs_for_generation(e,r,s){if(!r.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(r.input_ids.dims[1]===1){let n=Array.from({length:e.length},(o,a)=>e[a].length-e[a].findLastIndex(i=>i==sA)-1);r.position_ids=new U("int64",n,[e.length,1])}else{let o=r.input_ids.tolist().map(a=>{let i=0;return a.map(l=>l>=sA?0:i++)});r.position_ids=new U("int64",o.flat(),r.input_ids.dims)}return r.input_ids.dims[1]===1&&(delete r.audio_values,delete r.audio_features,delete r.audio_tokens,delete r.speaker_embeddings,delete r.speaker_features),uo(this,e,r,s)}async generate(e){let{sequences:r,audio_tokens:s,speaker_embeddings:n,speaker_features:o}=await super.generate({...e,return_dict_in_generate:!0}),a=r.slice(null,[e.input_ids.dims[1],-1]),i=Ve([a.dims[0],3],DP),l=Ee([s,a,i],1),{waveform:u}=await ce(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return u}};var Zl=class extends y{},Th=class extends Zl{};var an=class extends y{},Sh=class extends an{},bo=class extends an{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},vo=class extends an{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"audio_model"})}};var ir=class extends y{},Oh=class extends ir{},Ih=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},ko=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},Ch=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}},Ph=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var Eo=class extends y{},zh=class extends Eo{},Lh=class extends Eo{};var Ao=class extends y{},Nh=class extends Ao{},$h=class extends Ao{};var Mo=class extends y{},Rh=class extends Mo{},Uh=class extends Mo{};var zr=class extends y{},Bh=class extends zr{},Dh=class extends zr{async _call(e){return new we(await super._call(e))}},Fh=class extends zr{async _call(e){return new F(await super._call(e))}},jh=class extends zr{async _call(e){return new _e(await super._call(e))}},Gh=class extends zr{async _call(e){return new Ae(await super._call(e))}};var To=class extends y{},qh=class extends To{},Wh=class extends To{async _call(e){return new F(await super._call(e))}};var So=class extends y{},Vh=class extends So{},Hh=class extends So{async _call(e){return new F(await super._call(e))}};var Oo=class extends y{},Xh=class extends Oo{},Kh=class extends Oo{async _call(e){return new lr(await super._call(e))}},lr=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}};var Io=class extends y{},Yh=class extends Io{},Qh=class extends Io{async _call(e){return new lr(await super._call(e))}};var ec=class extends ze{constructor({audio_codes:e}){super(),this.audio_codes=e}},tc=class extends ze{constructor({audio_values:e}){super(),this.audio_values=e}},ln=class extends y{main_input_name="input_values";forward_params=["input_values"]},Jh=class extends ln{async encode(e){return new ec(await ce(this.sessions.encoder_model,e))}async decode(e){return new tc(await ce(this.sessions.decoder_model,e))}},Co=class extends ln{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},Po=class extends ln{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var Lr=class extends y{},Zh=class extends Lr{},e_=class extends Lr{async _call(e){return new we(await super._call(e))}},t_=class extends Lr{async _call(e){return new F(await super._call(e))}},r_=class extends Lr{async _call(e){return new _e(await super._call(e))}},s_=class extends Lr{async _call(e){return new Ae(await super._call(e))}};var Nr=class extends y{},n_=class extends Nr{},o_=class extends Nr{async _call(e){return new we(await super._call(e))}},a_=class extends Nr{async _call(e){return new F(await super._call(e))}},i_=class extends Nr{async _call(e){return new _e(await super._call(e))}},l_=class extends Nr{async _call(e){return new Ae(await super._call(e))}};var rc=class extends y{},c_=class extends rc{};var zo=class extends y{},u_=class extends zo{},p_=class extends zo{async _call(e){return new F(await super._call(e))}};var sc=class extends y{},d_=class extends sc{};var nc=class extends y{},f_=class extends nc{};var cn=class extends y{},m_=class extends cn{},h_=class extends cn{async _call(e){return new un(await super._call(e))}},__=class extends cn{async _call(e){return new oc(await super._call(e))}},un=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}},oc=class extends ze{constructor({logits:e,pred_boxes:r,pred_masks:s}){super(),this.logits=e,this.pred_boxes=r,this.pred_masks=s}};var Lo=class extends y{},g_=class extends Lo{},w_=class extends Lo{async _call(e){return new F(await super._call(e))}};var No=class extends y{},x_=class extends No{},y_=class extends No{async _call(e){return new F(await super._call(e))}};var ac=class extends y{},b_=class extends ac{};var ic=class extends y{},v_=class extends ic{};var $r=class extends y{},k_=class extends $r{},E_=class extends $r{async _call(e){return new F(await super._call(e))}},A_=class extends $r{async _call(e){return new _e(await super._call(e))}},M_=class extends $r{async _call(e){return new Ae(await super._call(e))}},T_=class extends $r{async _call(e){return new we(await super._call(e))}};var lc=class extends y{},S_=class extends lc{};var $o=class extends y{},O_=class extends $o{},I_=class extends $o{};var Ro=class extends y{},C_=class extends Ro{},P_=class extends Ro{async _call(e){return new F(await super._call(e))}};var Rr=class extends y{},z_=class extends Rr{},L_=class extends Rr{async _call(e){return new we(await super._call(e))}},N_=class extends Rr{async _call(e){return new F(await super._call(e))}},$_=class extends Rr{async _call(e){return new _e(await super._call(e))}},R_=class extends Rr{async _call(e){return new Ae(await super._call(e))}};var Uo=class extends y{},U_=class extends Uo{},B_=class extends Uo{};var ys=class extends y{},D_=class extends ys{},F_=class extends ys{async _call(e){return new we(await super._call(e))}},j_=class extends ys{async _call(e){return new F(await super._call(e))}},G_=class extends ys{async _call(e){return new _e(await super._call(e))}};var Bo=class extends y{},q_=class extends Bo{},W_=class extends Bo{};var Do=class extends y{},V_=class extends Do{},H_=class extends Do{};var Fo=class extends y{},X_=class extends Fo{},K_=class extends Fo{};var jo=class extends y{},Y_=class extends jo{},Q_=class extends jo{async _call(e){return new F(await super._call(e))}};var cc=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds"},J_=class extends cc{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:r,input_ids:s,attention_mask:n}){return{inputs_embeds:Ee([r,e],1),attention_mask:Ee([it(r.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:r,inputs_embeds:s,attention_mask:n}){if(!e&&!r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let o,a;return e&&(o=await this.encode_text({input_ids:e})),r&&(a=await this.encode_image({pixel_values:r})),o&&a?{inputs_embeds:s,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:o,image_features:a,input_ids:e,attention_mask:n}):s=o||a,{inputs_embeds:s,attention_mask:n}}async forward({input_ids:e,pixel_values:r,attention_mask:s,decoder_input_ids:n,decoder_attention_mask:o,encoder_outputs:a,past_key_values:i,inputs_embeds:l,decoder_inputs_embeds:u}){if(l||({inputs_embeds:l,attention_mask:s}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:r,inputs_embeds:l,attention_mask:s})),!a){let{last_hidden_state:f}=await Gt(this,{inputs_embeds:l,attention_mask:s});a=f}if(!u){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");u=await this.encode_text({input_ids:n})}return await Tt(this,{inputs_embeds:u,attention_mask:o,encoder_attention_mask:s,encoder_hidden_states:a,past_key_values:i},!0)}};var Go=class extends y{},Z_=class extends Go{},eg=class extends Go{};var qo=class extends y{},tg=class extends qo{},rg=class extends qo{};var Wo=class extends y{},sg=class extends Wo{},ng=class extends Wo{};var uc=class extends y{forward_params=["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"]},Vo=class extends uc{async forward({input_ids:e=null,attention_mask:r=null,pixel_values:s=null,input_features:n=null,input_features_mask:o=null,position_ids:a=null,inputs_embeds:i=null,per_layer_inputs:l=null,past_key_values:u=null,generation_config:d=null,logits_processor:f=null,...m}){if((!i||!l)&&({inputs_embeds:i,per_layer_inputs:l}=await ce(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(s){let{image_features:w}=await ce(this.sessions.vision_encoder,{pixel_values:s});({inputs_embeds:i,attention_mask:r}=this._merge_input_ids_with_image_features({image_features:w,inputs_embeds:i,input_ids:e,attention_mask:r}))}if(n){let{audio_features:w}=await ce(this.sessions.audio_encoder,{input_features:n,input_features_mask:o});({inputs_embeds:i,attention_mask:r}=this._merge_input_ids_with_audio_features({audio_features:w,inputs_embeds:i,input_ids:e,attention_mask:r}))}}return await Tt(this,{inputs_embeds:i,per_layer_inputs:l,past_key_values:u,attention_mask:r,position_ids:a,generation_config:d,logits_processor:f},!0)}_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_id,...e,image_features:s})}_merge_input_ids_with_audio_features(e){let r=e.audio_features.dims.at(-1),s=e.audio_features.view(-1,r);return Ql({audio_token_id:this.config.audio_token_id,...e,audio_features:s})}};var Ho=class extends y{},og=class extends Ho{},ag=class extends Ho{};var Xo=class extends y{},ig=class extends Xo{},lg=class extends Xo{};var Ko=class extends y{},cg=class extends Ko{},ug=class extends Ko{};var Yo=class extends y{},pg=class extends Yo{},dg=class extends Yo{};var Qo=class extends y{},fg=class extends Qo{},mg=class extends Qo{};var Jo=class extends y{},hg=class extends Jo{},_g=class extends Jo{};var Zo=class extends y{},gg=class extends Zo{},wg=class extends Zo{};var ea=class extends y{},xg=class extends ea{},yg=class extends ea{};var ta=class extends y{},bg=class extends ta{},vg=class extends ta{};var ra=class extends y{},kg=class extends ra{},Eg=class extends ra{};var pc=class extends y{},Ag=class extends pc{};var dc=class extends y{},Mg=class extends dc{};var sa=class extends y{},Tg=class extends sa{},Sg=class extends sa{};var na=class extends y{},Og=class extends na{},Ig=class extends na{async _call(e){return new F(await super._call(e))}};var Jt=class extends y{},Cg=class extends Jt{},Pg=class extends Jt{async _call(e){return new gt(await super._call(e))}},zg=class extends Jt{async _call(e){return new F(await super._call(e))}},Lg=class extends Jt{async _call(e){return new _e(await super._call(e))}};var Ng=class extends y{},$g=class extends Jt{},Rg=class extends Jt{async _call(e){return new gt(await super._call(e))}},Ug=class extends Jt{async _call(e){return new F(await super._call(e))}};var oa=class extends y{},Bg=class extends oa{},Dg=class extends oa{};var fc=class extends y{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]},mc=class extends fc{async encode_image({pixel_values:e,pixel_attention_mask:r}){return(await ce(this.sessions.vision_encoder,{pixel_values:e,pixel_attention_mask:r})).image_features}_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_id,...e,image_features:s})}},Fg=class extends mc{};var aa=class extends y{},jg=class extends aa{},Gg=class extends aa{async _call(e){return new F(await super._call(e))}};var ia=class extends y{},qg=class extends ia{},Wg=class extends ia{};var pn=class extends y{},Vg=class extends pn{async forward(e){let r=!e.input_ids,s=!e.pixel_values;if(r&&s)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(r&&(e.input_ids=it([e.pixel_values.dims[0],1])),s){let{image_size:u}=this.config.vision_config;e.pixel_values=Ve([0,3,u,u],0)}let{text_embeddings:n,image_embeddings:o,l2norm_text_embeddings:a,l2norm_image_embeddings:i}=await super.forward(e),l={};return r||(l.text_embeddings=n,l.l2norm_text_embeddings=a),s||(l.image_embeddings=o,l.l2norm_image_embeddings=i),l}},la=class extends pn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},Hg=class extends pn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var ca=class extends y{},Xg=class extends ca{},Kg=class extends ca{};var ua=class extends y{},Yg=class extends ua{},Qg=class extends ua{};var pa=class extends y{},Jg=class extends pa{},Zg=class extends pa{};var hc=class extends y{},ew=class extends hc{};var _c=class extends y{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},dn=class extends _c{_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_index,...e,image_features:s})}},tw=class extends dn{},rw=class extends dn{};var da=class extends y{},sw=class extends da{},nw=class extends da{};var fa=class extends y{},ow=class extends fa{},aw=class extends fa{};var ma=class extends y{},iw=class extends ma{},lw=class extends ma{};var ha=class extends y{},cw=class extends ha{},uw=class extends ha{};var bs=class extends y{},pw=class extends bs{},dw=class extends bs{},fw=class extends bs{async _call(e){return new F(await super._call(e))}},mw=class extends bs{};var gc=class extends y{},hw=class extends gc{};var wc=class extends y{},_w=class extends wc{};var xc=class extends ze{constructor({char_logits:e,bpe_logits:r,wp_logits:s}){super(),this.char_logits=e,this.bpe_logits=r,this.wp_logits=s}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},yc=class extends y{},gw=class extends yc{async _call(e){return new xc(await super._call(e))}};var bc=class extends ze{constructor({audio_codes:e}){super(),this.audio_codes=e}},vc=class extends ze{constructor({audio_values:e}){super(),this.audio_values=e}},fn=class extends y{main_input_name="input_values";forward_params=["input_values"]},ww=class extends fn{async encode(e){return new bc(await ce(this.sessions.encoder_model,e))}async decode(e){return new vc(await ce(this.sessions.decoder_model,e))}},_a=class extends fn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},ga=class extends fn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var wa=class extends y{},xw=class extends wa{},yw=class extends wa{};var vs=class extends y{},bw=class extends vs{},vw=class extends vs{async _call(e){return new we(await super._call(e))}},kw=class extends vs{async _call(e){return new F(await super._call(e))}},Ew=class extends vs{async _call(e){return new Ae(await super._call(e))}};var xa=class extends y{},Aw=class extends xa{},Mw=class extends xa{};var mn=class extends y{},Tw=class extends mn{},Sw=class extends mn{async _call(e){return new F(await super._call(e))}},Ow=class extends mn{};var hn=class extends y{},Iw=class extends hn{},Cw=class extends hn{async _call(e){return new F(await super._call(e))}},Pw=class extends hn{};var _n=class extends y{},zw=class extends _n{},Lw=class extends _n{async _call(e){return new F(await super._call(e))}},Nw=class extends _n{};var gn=class extends y{},$w=class extends gn{},Rw=class extends gn{async _call(e){return new F(await super._call(e))}},Uw=class extends gn{};var ya=class extends y{},Bw=class extends ya{},Dw=class extends ya{async _call(e){return new F(await super._call(e))}};var ba=class extends y{},Fw=class extends ba{},jw=class extends ba{async _call(e){return new F(await super._call(e))}};var ks=class extends y{},Gw=class extends ks{},qw=class extends ks{async _call(e){return new we(await super._call(e))}},Ww=class extends ks{async _call(e){return new F(await super._call(e))}},Vw=class extends ks{async _call(e){return new _e(await super._call(e))}};var va=class extends y{},Hw=class extends va{},Xw=class extends va{};var ka=class extends y{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},Kw=class extends ka{},Yw=class extends ka{};var Ur=class extends y{},Qw=class extends Ur{},Jw=class extends Ur{async _call(e){return new we(await super._call(e))}},Zw=class extends Ur{async _call(e){return new F(await super._call(e))}},ex=class extends Ur{async _call(e){return new _e(await super._call(e))}},tx=class extends Ur{async _call(e){return new Ae(await super._call(e))}};var Ea=class extends y{},rx=class extends Ea{},sx=class extends Ea{};var Aa=class extends y{},nx=class extends Aa{},ox=class extends Aa{};var kc=class extends y{},ax=class extends kc{forward_params=["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"];constructor(...e){super(...e),this._generation_mode="text"}async forward(e){let r=this._generation_mode??"text",s;if(r==="text"||!e.past_key_values){let l=this.sessions.prepare_inputs_embeds,u=ot(e,l.inputNames);s=await ce(l,u)}else{let l=this.sessions.gen_img_embeds,u=ot({image_ids:e.input_ids},l.inputNames);s=await ce(l,u)}let n={...e,...s},o=await Tt(this,n),a=this.sessions[r==="text"?"lm_head":"gen_head"];if(!a)throw new Error(`Unable to find "${a}" generation head`);let i=await ce(a,ot(o,a.inputNames));return{...s,...o,...i}}prepare_inputs_for_generation(e,r,s){let n=!!r.past_key_values;return s.guidance_scale!==null&&s.guidance_scale>1&&(n?r.input_ids=Ee([r.input_ids,r.input_ids],0):(r.input_ids=Ee([r.input_ids,Qn(r.input_ids,BigInt(s.pad_token_id))],0),r.attention_mask=Ee([r.attention_mask,Qn(r.attention_mask,0n)],0))),(n||!r.pixel_values)&&(r.pixel_values=Ve([0,0,3,384,384],1)),n&&(r.images_seq_mask=new U("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),r.images_emb_mask=new U("bool",new Array(0).fill(!1),[1,1,0])),r}async generate(e){return this._generation_mode="text",super.generate(e)}async generate_images(e){this._generation_mode="image";let r=(e.inputs??e[this.main_input_name]).dims[1],n=(await super.generate(e)).slice(null,[r,null]),o=this.sessions.image_decode,{decoded_image:a}=await ce(o,{generated_tokens:n}),i=a.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let u of i){let d=Xe.fromTensor(u);l.push(d)}return l}};var Ma=class extends y{},ix=class extends Ma{},lx=class extends Ma{},Ta=class extends y{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];_apply_and_filter_by_delay_pattern_mask(e){let[r,s]=e.dims,n=this.config.decoder.num_codebooks,o=s-n,a=0;for(let u=0;u<e.size;++u){if(e.data[u]==this.config.decoder.pad_token_id)continue;let d=u%s,f=Math.floor(u/s)%n,m=d-f;m>0&&m<=o&&(e.data[a++]=e.data[u])}let i=Math.floor(r/n),l=a/(i*n);return new U(e.type,e.data.slice(0,a),[i,n,l])}prepare_inputs_for_generation(e,r,s){let n=BigInt(this.config.decoder.pad_token_id),o=structuredClone(e);for(let a=0;a<o.length;++a)for(let i=0;i<o[a].length;++i)a%this.config.decoder.num_codebooks>=i&&(o[a][i]=n);return s.guidance_scale!==null&&s.guidance_scale>1&&(o=o.concat(o)),po(this,o,r,s)}async generate(e){let r=await super.generate(e),s=this._apply_and_filter_by_delay_pattern_mask(r).unsqueeze_(0),{audio_values:n}=await ce(this.sessions.encodec_decode,{audio_codes:s});return n}};var Sa=class extends y{},cx=class extends Sa{},ux=class extends Sa{};var Br=class extends y{},px=class extends Br{},dx=class extends Br{async _call(e){return new we(await super._call(e))}},fx=class extends Br{async _call(e){return new F(await super._call(e))}},mx=class extends Br{async _call(e){return new _e(await super._call(e))}},hx=class extends Br{async _call(e){return new Ae(await super._call(e))}};var Ec=class extends y{},_x=class extends Ec{};var Oa=class extends y{},gx=class extends Oa{},wx=class extends Oa{};var Ia=class extends y{},xx=class extends Ia{},yx=class extends Ia{};var Ca=class extends y{},bx=class extends Ca{},vx=class extends Ca{};var Pa=class extends y{},kx=class extends Pa{},Ex=class extends Pa{};var za=class extends y{},Ax=class extends za{},Mx=class extends za{};var La=class extends y{},Tx=class extends La{},Sx=class extends La{};var Na=class extends y{},Ox=class extends Na{},Ix=class extends Na{};var Ac=class extends y{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Cx=class extends Ac{_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_index,...e,image_features:s})}};var Mc=class extends y{},Px=class extends Mc{async _call(e){return new gt(await super._call(e))}};var $a=class extends y{},zx=class extends $a{},Lx=class extends $a{};var Ra=class extends y{},Nx=class extends Ra{},$x=class extends Ra{};var Ua=class extends y{},Rx=class extends Ua{},Ux=class extends Ua{};var Ba=class extends y{},Bx=class extends Ba{},Dx=class extends Ba{};var Tc=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},Da=class extends Tc{async forward({input_ids:e=null,attention_mask:r=null,pixel_values:s=null,image_sizes:n=null,position_ids:o=null,inputs_embeds:a=null,past_key_values:i=null,generation_config:l=null,logits_processor:u=null,...d}){if(!a){let m;if(s&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:m}=await ce(this.sessions.vision_encoder,{pixel_values:s,image_sizes:n}))}else{let _=this.config.normalized_config.hidden_size;m=new U("float32",[],[0,_])}({inputs_embeds:a}=await ce(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:m}))}return await Tt(this,{inputs_embeds:a,past_key_values:i,attention_mask:r,position_ids:o,generation_config:l,logits_processor:u},!1)}};var Fa=class extends y{},Fx=class extends Fa{},jx=class extends Fa{async _call(e){return new F(await super._call(e))}};var ja=class extends y{},Gx=class extends ja{},qx=class extends ja{async _call(e){return new _e(await super._call(e))}};var Ga=class extends y{},Wx=class extends Ga{},Vx=class extends Ga{};var Sc=class extends y{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},Hx=class extends Sc{get_rope_index(e,r,s,n){let{vision_config:o,image_token_id:a,video_token_id:i,vision_start_token_id:l}=this.config,u=o.spatial_merge_size??2,d=[];if(r||s){let f=e.tolist();n||(n=il(e));let m=n.tolist(),_=Array.from({length:3},M=>Array.from({length:e.dims[0]},I=>Array.from({length:e.dims[1]},T=>1))),w=r?r.tolist():[],x=s?s.tolist():[],k=0,E=0;for(let M=0;M<f.length;++M){let I=f[M].filter((S,L)=>m[M][L]==1),z=I.reduce((S,L,R)=>(L==l&&S.push(R),S),[]).map(S=>I[S+1]),C=z.filter(S=>S==a).length,v=z.filter(S=>S==i).length,G=[],X=0,V=C,Q=v;for(let S=0;S<z.length;++S){let L=I.findIndex((Et,et)=>et>X&&Et==a),R=I.findIndex((Et,et)=>et>X&&Et==i),te=V>0&&L!==-1?L:I.length+1,ue=Q>0&&R!==-1?R:I.length+1,Be,Ce,vt,Qe;te<ue?([Ce,vt,Qe]=w[k],++k,--V,Be=te):([Ce,vt,Qe]=x[E],++E,--Q,Be=ue);let[Ze,rt,Me]=[Number(Ce),Math.floor(Number(vt)/u),Math.floor(Number(Qe)/u)],xe=Be-X,Ge=G.length>0?Te(G.at(-1))[0]+1:0;G.push(Array.from({length:3*xe},(Et,et)=>Ge+et%xe));let kt=xe+Ge,ge=Ze*rt*Me,Le=Array.from({length:ge},(Et,et)=>kt+Math.floor(et/(rt*Me))),xr=Array.from({length:ge},(Et,et)=>kt+Math.floor(et/Me)%rt),Hr=Array.from({length:ge},(Et,et)=>kt+et%Me);G.push([Le,xr,Hr].flat()),X=Be+ge}if(X<I.length){let S=G.length>0?Te(G.at(-1))[0]+1:0,L=I.length-X;G.push(Array.from({length:3*L},(R,te)=>S+te%L))}let K=G.reduce((S,L)=>S+L.length,0),Y=new Array(K),B=0;for(let S=0;S<3;++S)for(let L=0;L<G.length;++L){let R=G[L],te=R.length/3;for(let ue=S*te;ue<(S+1)*te;++ue)Y[B++]=R[ue]}let P=0,se=m[M];for(let S=0;S<se.length;++S)if(se[S]==1){for(let L=0;L<3;++L)_[L][M][S]=Y[L*K/3+P];++P}let ie=Te(Y)[0];d.push(ie+1-f[M].length)}return[new U("int64",_.flat(1/0),[3,e.dims[0],e.dims[1]]),new U("int64",d,[d.length,1])]}else if(n){let{data:f,dims:m}=Km(n),_=BigInt64Array.from({length:3*f.length},(x,k)=>f[k%f.length]),w=Array.from({length:m[0]},(x,k)=>Te(f.subarray(m[1]*k,m[1]*(k+1)))[0]+1n+BigInt(m[1]));return[new U("int64",_,[3,...m]),new U("int64",w,[w.length,1])]}else{let[f,m]=e.dims,_=BigInt64Array.from({length:3*f*m},(w,x)=>BigInt(Math.floor(x%m/f)));return[new U("int64",_,[3,...e.dims]),vd([f,1])]}}async encode_image({pixel_values:e,image_grid_thw:r}){return(await ce(this.sessions.vision_encoder,{pixel_values:e,grid_thw:r})).image_features}_merge_input_ids_with_image_features(e){return ar({image_token_id:this.config.image_token_id,...e})}prepare_inputs_for_generation(e,r,s){if(r.attention_mask&&!r.position_ids)if(!r.past_key_values)[r.position_ids,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);else{r.pixel_values=null;let n=BigInt(Object.values(r.past_key_values)[0].dims.at(-2)),o=r.rope_deltas.map(a=>n+a);r.position_ids=Ft([o,o,o],0)}return r}};var qa=class extends y{},Xx=class extends qa{},Kx=class extends qa{};var Wa=class extends y{},Yx=class extends Wa{},Qx=class extends Wa{async _call(e){return new F(await super._call(e))}};var Va=class extends y{},Jx=class extends Va{},Zx=class extends Va{async _call(e){return new Oc(await super._call(e))}},Oc=class extends lr{};var Dr=class extends y{},ey=class extends Dr{},ty=class extends Dr{async _call(e){return new we(await super._call(e))}},ry=class extends Dr{async _call(e){return new F(await super._call(e))}},sy=class extends Dr{async _call(e){return new _e(await super._call(e))}},ny=class extends Dr{async _call(e){return new Ae(await super._call(e))}};var Fr=class extends y{},oy=class extends Fr{},ay=class extends Fr{async _call(e){return new we(await super._call(e))}},iy=class extends Fr{async _call(e){return new F(await super._call(e))}},ly=class extends Fr{async _call(e){return new _e(await super._call(e))}},cy=class extends Fr{async _call(e){return new Ae(await super._call(e))}};var Ha=class extends y{},uy=class extends Ha{},py=class extends Ha{async _call(e){return new Ic(await super._call(e))}},Ic=class extends lr{};var Cc=class extends ze{constructor({iou_scores:e,pred_masks:r}){super(),this.iou_scores=e,this.pred_masks=r}},Pc=class extends y{},dy=class extends Pc{async get_image_embeddings({pixel_values:e}){return await Gt(this,{pixel_values:e})}async forward(e){!e.image_embeddings||!e.image_positional_embeddings?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_labels??=it(e.input_points.dims.slice(0,-1));let r={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(r.input_points=e.input_points),e.input_labels&&(r.input_labels=e.input_labels),e.input_boxes&&(r.input_boxes=e.input_boxes),await ce(this.sessions.prompt_encoder_mask_decoder,r)}async _call(e){return new Cc(await super._call(e))}};var zc=class extends ze{constructor({iou_scores:e,pred_masks:r,object_score_logits:s}){super(),this.iou_scores=e,this.pred_masks=r,this.object_score_logits=s}},Lc=class extends y{},Xa=class extends Lc{async get_image_embeddings({pixel_values:e}){return await Gt(this,{pixel_values:e})}async forward(e){let{num_feature_levels:r}=this.config.vision_config;if(Array.from({length:r},(a,i)=>`image_embeddings.${i}`).some(a=>!e[a])?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_points){if(e.input_boxes&&e.input_boxes.dims[1]!==1)throw new Error("When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.");let a=e.input_points.dims;e.input_labels??=it(a.slice(0,-1)),e.input_boxes??=Ve([a[0],0,4],0)}else if(e.input_boxes){let a=e.input_boxes.dims;e.input_labels=Ve([a[0],a[1],0],-1n),e.input_points=Ve([a[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");let n=this.sessions.prompt_encoder_mask_decoder,o=ot(e,n.inputNames);return await ce(n,o)}async _call(e){return new zc(await super._call(e))}},fy=class extends Xa{},my=class extends Xa{};var wn=class extends y{},hy=class extends wn{},_y=class extends wn{},gy=class extends wn{};var xn=class extends y{},wy=class extends xn{},xy=class extends xn{},yy=class extends xn{};var Ka=class extends y{},by=class extends Ka{},Ya=class extends Ka{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},vy=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var Qa=class extends y{},ky=class extends Qa{},Ey=class extends Qa{};var yn=class extends y{main_input_name="input_values";forward_params=["input_values"]},Ay=class extends yn{async encode(e){return await ce(this.sessions.encoder_model,e)}async decode(e){return await ce(this.sessions.decoder_model,e)}},Ja=class extends yn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},Za=class extends yn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var bn=class extends y{},My=class extends bn{},Ty=class extends bn{},Sy=class extends bn{async generate_speech(e,r,{threshold:s=.5,minlenratio:n=0,maxlenratio:o=20,vocoder:a=null}={}){let i={input_ids:e},{encoder_outputs:l,encoder_attention_mask:u}=await Gt(this,i),d=l.dims[1]/this.config.reduction_factor,f=Math.floor(d*o),m=Math.floor(d*n),_=this.config.num_mel_bins,w=[],x=null,k=null,E=0;for(;;){++E;let T=Xm(!!k),z;k?z=k.output_sequence_out:z=new U("float32",new Float32Array(_),[1,1,_]);let C={use_cache_branch:T,output_sequence:z,encoder_attention_mask:u,speaker_embeddings:r,encoder_hidden_states:l};this.addPastKeyValues(C,x),k=await ce(this.sessions.decoder_model_merged,C),x=this.getPastKeyValues(k,x);let{prob:v,spectrum:G}=k;if(w.push(G),E>=m&&(Array.from(v.data).filter(X=>X>=s).length>0||E>=f))break}let M=Ee(w),{waveform:I}=await ce(a.sessions.model,{spectrogram:M});return{spectrogram:M,waveform:I}}},Oy=class extends y{main_input_name="spectrogram"};var Es=class extends y{},Iy=class extends Es{},Cy=class extends Es{async _call(e){return new we(await super._call(e))}},Py=class extends Es{async _call(e){return new F(await super._call(e))}},zy=class extends Es{async _call(e){return new Ae(await super._call(e))}};var ei=class extends y{},Ly=class extends ei{},Ny=class extends ei{};var ti=class extends y{},$y=class extends ti{},Ry=class extends ti{};var Nc=class extends y{},Uy=class extends Nc{};var $c=class extends y{},ri=class extends $c{async generate_speech({input_ids:e,attention_mask:r,style:s,num_inference_steps:n=5,speed:o=1.05}){let{sampling_rate:a,chunk_compress_factor:i,base_chunk_size:l,latent_dim:u}=this.config,{last_hidden_state:d,durations:f}=await ce(this.sessions.text_encoder,{input_ids:e,attention_mask:r,style:s}),m=f.div(o).mul_(a),_=l*i,w=m.data,x=Int32Array.from(w,V=>Math.ceil(V/_)),k=Math.max(...x),E=e.dims[0],M=new BigInt64Array(E*k);for(let V=0;V<E;++V)M.fill(1n,V*k,V*k+x[V]);let I=new U("int64",M,[E,k]),T=u*i,z=T*k,C=PE([E,T,k]),v=C.data;for(let V=0;V<E;++V)if(x[V]!==k)for(let Q=0;Q<T;++Q)v.fill(0,V*z+Q*k+x[V],V*z+(Q+1)*k);let G=Ve([E],n);for(let V=0;V<n;++V){let Q=Ve([E],V);({denoised_latents:C}=await ce(this.sessions.latent_denoiser,{style:s,noisy_latents:C,latent_mask:I,encoder_outputs:d,attention_mask:r,timestep:Q,num_inference_steps:G}))}let{waveform:X}=await ce(this.sessions.voice_decoder,{latents:C});return{waveform:X,durations:m}}};var vn=class extends y{},By=class extends vn{},Dy=class extends vn{async _call(e){return new F(await super._call(e))}},Fy=class extends vn{};var si=class extends y{},jy=class extends si{},Gy=class extends si{};var ni=class extends y{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},qy=class extends ni{},Wy=class extends ni{};var oi=class extends y{},Vy=class extends oi{},Hy=class extends oi{async _call(e){return new Rc(await super._call(e))}},Rc=class extends un{};var Uc=class extends y{},Xy=class extends Uc{};var Bc=class extends y{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},Dc=class extends Bc{_merge_input_ids_with_audio_features(e){let r=e.audio_features.dims.at(-1),s=e.audio_features.view(-1,r);return Ql({audio_token_id:this.config.ignore_index??this.config.audio_token_id,...e,audio_features:s})}},Ky=class extends Dc{};var kn=class extends y{},Yy=class extends kn{},Qy=class extends kn{async _call(e){return new gt(await super._call(e))}},Jy=class extends kn{async _call(e){return new F(await super._call(e))}};var As=class extends y{},Zy=class extends As{},e0=class extends As{async _call(e){return new gt(await super._call(e))}},t0=class extends As{async _call(e){return new F(await super._call(e))}},r0=class extends As{async _call(e){return new _e(await super._call(e))}};var ai=class extends y{},s0=class extends ai{},n0=class extends ai{};var o0=class extends y{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var ii=class extends y{},a0=class extends ii{},i0=class extends ii{async _call(e){return new F(await super._call(e))}};var Fc=class extends y{},l0=class extends Fc{};var li=class extends y{},c0=class extends li{},u0=class extends li{async _call(e){return new F(await super._call(e))}};var jc=class extends y{},p0=class extends jc{async _call(e){return new Ll(await super._call(e))}};var Gc=class extends y{},d0=class extends Gc{};var qc=class extends ze{constructor({waveform:e,spectrogram:r}){super(),this.waveform=e,this.spectrogram=r}},Wc=class extends y{},f0=class extends Wc{async _call(e){return new qc(await super._call(e))}};var En=class extends y{},m0=class extends En{},h0=class extends En{async _call(e){return new gt(await super._call(e))}},_0=class extends En{async _call(e){return new F(await super._call(e))}};var Vc=class extends ze{constructor({logits:e,embeddings:r}){super(),this.logits=e,this.embeddings=r}},jr=class extends y{},g0=class extends jr{},w0=class extends jr{async _call(e){return new gt(await super._call(e))}},x0=class extends jr{async _call(e){return new F(await super._call(e))}},y0=class extends jr{async _call(e){return new Vc(await super._call(e))}},b0=class extends jr{async _call(e){return new _e(await super._call(e))}};var Hc=class extends y{},v0=class extends Hc{};var Xc=class extends sn{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1};var ci=class extends y{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"]},k0=class extends ci{},Kc=class extends ci{_prepare_generation_config(e,r){return super._prepare_generation_config(e,r,Xc)}_retrieve_init_tokens(e){let r=[e.decoder_start_token_id],s=e.language,n=e.task;if(e.is_multilingual){s||(console.warn("No language specified - defaulting to English (en)."),s="en");let a=`<|${NE(s)}|>`;r.push(e.lang_to_id[a]),r.push(e.task_to_id[n??"transcribe"])}else if(s||n)throw new Error("Cannot specify `task` or `language` for an English-only model. If the model is intended to be multilingual, pass `is_multilingual=true` to generate, or update the generation config.");return!e.return_timestamps&&e.no_timestamps_token_id&&r.at(-1)!==e.no_timestamps_token_id?r.push(e.no_timestamps_token_id):e.return_timestamps&&r.at(-1)===e.no_timestamps_token_id&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),r.pop()),r.filter(o=>o!=null)}async generate({inputs:e=null,generation_config:r=null,logits_processor:s=null,stopping_criteria:n=null,...o}){r=this._prepare_generation_config(r,o);let a=o.decoder_input_ids??this._retrieve_init_tokens(r);if(r.return_timestamps&&(s??=new hs,s.push(new Rl(r,a))),r.begin_suppress_tokens&&(s??=new hs,s.push(new rn(r.begin_suppress_tokens,a.length))),r.return_token_timestamps){if(!r.alignment_heads)throw new Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");r.task==="translate"&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),r.output_attentions=!0,r.return_dict_in_generate=!0}let i=await super.generate({inputs:e,generation_config:r,logits_processor:s,decoder_input_ids:a,...o});return r.return_token_timestamps&&(i.token_timestamps=this._extract_token_timestamps(i,r.alignment_heads,r.num_frames)),i}_extract_token_timestamps(e,r,s=null,n=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");s==null&&console.warn("`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds).");let o=this.config.median_filter_width;o===void 0&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),o=7);let a=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},(x,k)=>Ee(a.map(E=>E[k]),2)),l=Ft(r.map(([x,k])=>{if(x>=i.length)throw new Error(`Layer index ${x} is out of bounds for cross attentions (length ${i.length}).`);return s?i[x].slice(null,k,null,[0,s]):i[x].slice(null,k)})).transpose(1,0,2,3),[u,d]=yd(l,-2,0,!0),f=l.clone();for(let x=0;x<f.dims[0];++x){let k=f[x];for(let E=0;E<k.dims[0];++E){let M=k[E],I=u[x][E][0].data,T=d[x][E][0].data;for(let z=0;z<M.dims[0];++z){let C=M[z].data;for(let v=0;v<C.length;++v)C[v]=(C[v]-T[v])/I[v];C.set(Vv(C,o))}}}let m=[al(f,1)],_=e.sequences.dims,w=new U("float32",new Float32Array(_[0]*_[1]),_);for(let x=0;x<_[0];++x){let k=m[x].neg().squeeze_(0),[E,M]=Xv(k.tolist()),I=Array.from({length:E.length-1},(C,v)=>E[v+1]-E[v]),T=dt([1],I).map(C=>!!C),z=[];for(let C=0;C<T.length;++C)T[C]&&z.push(M[C]*n);w[x].data.set(z,1)}return w}},E0=class extends Kc{};var Gr=class extends y{},A0=class extends Gr{},M0=class extends Gr{async _call(e){return new we(await super._call(e))}},T0=class extends Gr{async _call(e){return new F(await super._call(e))}},S0=class extends Gr{async _call(e){return new _e(await super._call(e))}},O0=class extends Gr{async _call(e){return new Ae(await super._call(e))}};var qr=class extends y{},I0=class extends qr{},C0=class extends qr{async _call(e){return new we(await super._call(e))}},P0=class extends qr{async _call(e){return new F(await super._call(e))}},z0=class extends qr{async _call(e){return new _e(await super._call(e))}},L0=class extends qr{async _call(e){return new Ae(await super._call(e))}};var ui=class extends y{},N0=class extends ui{},$0=class extends ui{async _call(e){return new Yc(await super._call(e))}},Yc=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}};var pi=class extends y{},R0=class extends pi{},U0=class extends pi{};var FP=new Map([["bert","BertModel"],["neobert","NeoBertModel"],["modernbert","ModernBertModel"],["nomic_bert","NomicBertModel"],["roformer","RoFormerModel"],["electra","ElectraModel"],["esm","EsmModel"],["convbert","ConvBertModel"],["camembert","CamembertModel"],["deberta","DebertaModel"],["deberta-v2","DebertaV2Model"],["mpnet","MPNetModel"],["albert","AlbertModel"],["distilbert","DistilBertModel"],["roberta","RobertaModel"],["xlm","XLMModel"],["xlm-roberta","XLMRobertaModel"],["clap","ClapModel"],["clip","CLIPModel"],["clipseg","CLIPSegModel"],["chinese_clip","ChineseCLIPModel"],["siglip","SiglipModel"],["jina_clip","JinaCLIPModel"],["mobilebert","MobileBertModel"],["squeezebert","SqueezeBertModel"],["wav2vec2","Wav2Vec2Model"],["wav2vec2-bert","Wav2Vec2BertModel"],["unispeech","UniSpeechModel"],["unispeech-sat","UniSpeechSatModel"],["hubert","HubertModel"],["wavlm","WavLMModel"],["audio-spectrogram-transformer","ASTModel"],["vits","VitsModel"],["pyannote","PyAnnoteModel"],["wespeaker-resnet","WeSpeakerResNetModel"],["detr","DetrModel"],["rt_detr","RTDetrModel"],["rt_detr_v2","RTDetrV2Model"],["rf_detr","RFDetrModel"],["d_fine","DFineModel"],["table-transformer","TableTransformerModel"],["vit","ViTModel"],["ijepa","IJepaModel"],["pvt","PvtModel"],["vit_msn","ViTMSNModel"],["vit_mae","ViTMAEModel"],["groupvit","GroupViTModel"],["fastvit","FastViTModel"],["mobilevit","MobileViTModel"],["mobilevitv2","MobileViTV2Model"],["owlvit","OwlViTModel"],["owlv2","Owlv2Model"],["beit","BeitModel"],["deit","DeiTModel"],["hiera","HieraModel"],["convnext","ConvNextModel"],["convnextv2","ConvNextV2Model"],["dinov2","Dinov2Model"],["dinov2_with_registers","Dinov2WithRegistersModel"],["dinov3_vit","DINOv3ViTModel"],["dinov3_convnext","DINOv3ConvNextModel"],["resnet","ResNetModel"],["swin","SwinModel"],["swin2sr","Swin2SRModel"],["donut-swin","DonutSwinModel"],["yolos","YolosModel"],["dpt","DPTModel"],["glpn","GLPNModel"],["hifigan","SpeechT5HifiGan"],["efficientnet","EfficientNetModel"],["decision_transformer","DecisionTransformerModel"],["patchtst","PatchTSTModel"],["patchtsmixer","PatchTSMixerModel"],["mobilenet_v1","MobileNetV1Model"],["mobilenet_v2","MobileNetV2Model"],["mobilenet_v3","MobileNetV3Model"],["mobilenet_v4","MobileNetV4Model"],["maskformer","MaskFormerModel"],["mgp-str","MgpstrForSceneTextRecognition"],["style_text_to_speech_2","StyleTextToSpeech2Model"]]),jP=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),GP=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),qP=new Map([["bloom","BloomModel"],["jais","JAISModel"],["gpt2","GPT2Model"],["gpt_oss","GptOssModel"],["gptj","GPTJModel"],["gpt_bigcode","GPTBigCodeModel"],["gpt_neo","GPTNeoModel"],["gpt_neox","GPTNeoXModel"],["codegen","CodeGenModel"],["llama","LlamaModel"],["apertus","ApertusModel"],["nanochat","NanoChatModel"],["arcee","ArceeModel"],["lfm2","Lfm2Model"],["lfm2_moe","Lfm2MoeModel"],["smollm3","SmolLM3Model"],["exaone","ExaoneModel"],["olmo","OlmoModel"],["olmo2","Olmo2Model"],["olmo3","Olmo3Model"],["mobilellm","MobileLLMModel"],["granite","GraniteModel"],["granitemoehybrid","GraniteMoeHybridModel"],["cohere","CohereModel"],["gemma","GemmaModel"],["gemma2","Gemma2Model"],["vaultgemma","VaultGemmaModel"],["gemma3_text","Gemma3Model"],["helium","HeliumModel"],["glm","GlmModel"],["openelm","OpenELMModel"],["qwen2","Qwen2Model"],["qwen3","Qwen3Model"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5_Model"],["starcoder2","Starcoder2Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),nA=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),oA=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),aA=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),iA=new Map([["bert","BertForSequenceClassification"],["neobert","NeoBertForSequenceClassification"],["modernbert","ModernBertForSequenceClassification"],["roformer","RoFormerForSequenceClassification"],["electra","ElectraForSequenceClassification"],["esm","EsmForSequenceClassification"],["convbert","ConvBertForSequenceClassification"],["camembert","CamembertForSequenceClassification"],["deberta","DebertaForSequenceClassification"],["deberta-v2","DebertaV2ForSequenceClassification"],["mpnet","MPNetForSequenceClassification"],["albert","AlbertForSequenceClassification"],["distilbert","DistilBertForSequenceClassification"],["roberta","RobertaForSequenceClassification"],["xlm","XLMForSequenceClassification"],["xlm-roberta","XLMRobertaForSequenceClassification"],["bart","BartForSequenceClassification"],["mbart","MBartForSequenceClassification"],["mobilebert","MobileBertForSequenceClassification"],["squeezebert","SqueezeBertForSequenceClassification"]]),lA=new Map([["bert","BertForTokenClassification"],["neobert","NeoBertForTokenClassification"],["modernbert","ModernBertForTokenClassification"],["roformer","RoFormerForTokenClassification"],["electra","ElectraForTokenClassification"],["esm","EsmForTokenClassification"],["convbert","ConvBertForTokenClassification"],["camembert","CamembertForTokenClassification"],["deberta","DebertaForTokenClassification"],["deberta-v2","DebertaV2ForTokenClassification"],["mpnet","MPNetForTokenClassification"],["distilbert","DistilBertForTokenClassification"],["roberta","RobertaForTokenClassification"],["xlm","XLMForTokenClassification"],["xlm-roberta","XLMRobertaForTokenClassification"]]),cA=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),uA=new Map([["bloom","BloomForCausalLM"],["gpt2","GPT2LMHeadModel"],["gpt_oss","GptOssForCausalLM"],["jais","JAISLMHeadModel"],["gptj","GPTJForCausalLM"],["gpt_bigcode","GPTBigCodeForCausalLM"],["gpt_neo","GPTNeoForCausalLM"],["gpt_neox","GPTNeoXForCausalLM"],["codegen","CodeGenForCausalLM"],["llama","LlamaForCausalLM"],["nanochat","NanoChatForCausalLM"],["apertus","ApertusForCausalLM"],["llama4_text","Llama4ForCausalLM"],["arcee","ArceeForCausalLM"],["lfm2","Lfm2ForCausalLM"],["lfm2_moe","Lfm2MoeForCausalLM"],["smollm3","SmolLM3ForCausalLM"],["exaone","ExaoneForCausalLM"],["olmo","OlmoForCausalLM"],["olmo2","Olmo2ForCausalLM"],["olmo3","Olmo3ForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen3","Qwen3ForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5_ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["trocr","TrOCRForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),WP=new Map([["multi_modality","MultiModalityCausalLM"]]),pA=new Map([["bert","BertForMaskedLM"],["neobert","NeoBertForMaskedLM"],["modernbert","ModernBertForMaskedLM"],["roformer","RoFormerForMaskedLM"],["electra","ElectraForMaskedLM"],["esm","EsmForMaskedLM"],["convbert","ConvBertForMaskedLM"],["camembert","CamembertForMaskedLM"],["deberta","DebertaForMaskedLM"],["deberta-v2","DebertaV2ForMaskedLM"],["mpnet","MPNetForMaskedLM"],["albert","AlbertForMaskedLM"],["distilbert","DistilBertForMaskedLM"],["roberta","RobertaForMaskedLM"],["xlm","XLMWithLMHeadModel"],["xlm-roberta","XLMRobertaForMaskedLM"],["mobilebert","MobileBertForMaskedLM"],["squeezebert","SqueezeBertForMaskedLM"]]),dA=new Map([["bert","BertForQuestionAnswering"],["neobert","NeoBertForQuestionAnswering"],["roformer","RoFormerForQuestionAnswering"],["electra","ElectraForQuestionAnswering"],["convbert","ConvBertForQuestionAnswering"],["camembert","CamembertForQuestionAnswering"],["deberta","DebertaForQuestionAnswering"],["deberta-v2","DebertaV2ForQuestionAnswering"],["mpnet","MPNetForQuestionAnswering"],["albert","AlbertForQuestionAnswering"],["distilbert","DistilBertForQuestionAnswering"],["roberta","RobertaForQuestionAnswering"],["xlm","XLMForQuestionAnswering"],["xlm-roberta","XLMRobertaForQuestionAnswering"],["mobilebert","MobileBertForQuestionAnswering"],["squeezebert","SqueezeBertForQuestionAnswering"]]),fA=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),mA=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2-vl","Qwen2VLForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"]]),hA=new Map([["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"]]),VP=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),_A=new Map([["vit","ViTForImageClassification"],["ijepa","IJepaForImageClassification"],["pvt","PvtForImageClassification"],["vit_msn","ViTMSNForImageClassification"],["fastvit","FastViTForImageClassification"],["mobilevit","MobileViTForImageClassification"],["mobilevitv2","MobileViTV2ForImageClassification"],["beit","BeitForImageClassification"],["deit","DeiTForImageClassification"],["hiera","HieraForImageClassification"],["convnext","ConvNextForImageClassification"],["convnextv2","ConvNextV2ForImageClassification"],["dinov2","Dinov2ForImageClassification"],["dinov2_with_registers","Dinov2WithRegistersForImageClassification"],["resnet","ResNetForImageClassification"],["swin","SwinForImageClassification"],["segformer","SegformerForImageClassification"],["efficientnet","EfficientNetForImageClassification"],["mobilenet_v1","MobileNetV1ForImageClassification"],["mobilenet_v2","MobileNetV2ForImageClassification"],["mobilenet_v3","MobileNetV3ForImageClassification"],["mobilenet_v4","MobileNetV4ForImageClassification"]]),gA=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),wA=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),An=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),xA=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),yA=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),bA=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),vA=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),kA=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),EA=new Map([["wavlm","WavLMForXVector"]]),AA=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),MA=new Map([["vitmatte","VitMatteForImageMatting"]]),HP=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),TA=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),SA=new Map([["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),OA=new Map([["sapiens","SapiensForNormalEstimation"]]),IA=new Map([["vitpose","VitPoseForPoseEstimation"]]),CA=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),B0=[[FP,H.EncoderOnly],[jP,H.EncoderDecoder],[qP,H.DecoderOnlyWithoutHead],[GP,H.AutoEncoder],[iA,H.EncoderOnly],[lA,H.EncoderOnly],[cA,H.Seq2Seq],[nA,H.Seq2Seq],[uA,H.DecoderOnly],[WP,H.MultiModality],[pA,H.EncoderOnly],[dA,H.EncoderOnly],[fA,H.Vision2Seq],[mA,H.ImageTextToText],[hA,H.AudioTextToText],[_A,H.EncoderOnly],[An,H.EncoderOnly],[yA,H.EncoderOnly],[xA,H.EncoderOnly],[MA,H.EncoderOnly],[HP,H.EncoderOnly],[TA,H.EncoderOnly],[SA,H.EncoderOnly],[OA,H.EncoderOnly],[IA,H.EncoderOnly],[gA,H.EncoderOnly],[wA,H.EncoderOnly],[bA,H.MaskGeneration],[vA,H.EncoderOnly],[kA,H.EncoderOnly],[oA,H.Seq2Seq],[aA,H.EncoderOnly],[EA,H.EncoderOnly],[AA,H.EncoderOnly],[CA,H.EncoderOnly]];for(let[t,e]of B0)for(let r of t.values()){ws.set(r,e);let s=di[r];gs.set(s,r),Yl.set(r,s)}var XP=[["MusicgenForConditionalGeneration",Ta,H.Musicgen],["Phi3VForCausalLM",Da,H.Phi3V],["CLIPTextModelWithProjection",ko,H.EncoderOnly],["SiglipTextModel",Ya,H.EncoderOnly],["JinaCLIPTextModel",la,H.EncoderOnly],["ClapTextModelWithProjection",bo,H.EncoderOnly],["ClapAudioModelWithProjection",vo,H.EncoderOnly],["DacEncoderModel",Co,H.EncoderOnly],["DacDecoderModel",Po,H.EncoderOnly],["MimiEncoderModel",_a,H.EncoderOnly],["MimiDecoderModel",ga,H.EncoderOnly],["SnacEncoderModel",Ja,H.EncoderOnly],["SnacDecoderModel",Za,H.EncoderOnly],["Gemma3nForConditionalGeneration",Vo,H.ImageAudioTextToText],["SupertonicForConditionalGeneration",ri,H.Supertonic],["ChatterboxModel",yo,H.Chatterbox]];for(let[t,e,r]of XP)ws.set(t,r),gs.set(e,t),Yl.set(t,e);var D0=new Map([["modnet",An],["birefnet",An],["isnet",An],["ben",An]]);for(let[t,e]of D0.entries())e.set(t,"PreTrainedModel"),ws.set(t,H.EncoderOnly),Yl.set(t,y);ws.set("PreTrainedModel",H.EncoderOnly);gs.set(y,"PreTrainedModel");var Ie={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:iA,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:lA,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:oA,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:aA,MODEL_FOR_MASKED_LM_MAPPING_NAMES:pA,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:dA,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:_A,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:An,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:xA,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:yA,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:gA,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:wA,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:bA,MODEL_FOR_CTC_MAPPING_NAMES:vA,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:kA,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:EA,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:AA,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:VP,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:MA,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:TA,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:SA,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:OA,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:IA,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:CA,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:mA,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:hA,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:cA,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:nA,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:uA,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:fA};eA(Ie);var Se=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",model_file_name:i=null,subfolder:l="onnx",device:u=null,dtype:d=null,use_external_data_format:f=null,session_options:m={}}={}){let _={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,model_file_name:i,subfolder:l,device:u,dtype:d,use_external_data_format:f,session_options:m};if(_.config=await ms.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let w=_.config.model_type;for(let x of this.MODEL_CLASS_MAPPINGS){let k=x.get(w);if(!k){for(let E of x.values())if(E[0]===w){k=E;break}if(!k)continue}return await di[k].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return D0.has(w)||console.warn(`Unknown model class "${w}", attempting to construct from base class.`),await y.from_pretrained(e,_);throw Error(`Unsupported model type: ${w}`)}},wr=class extends Se{static MODEL_CLASS_MAPPINGS=B0.map(e=>e[0]);static BASE_IF_FAIL=!0},fi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},Qc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},Mn=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},Jc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},Zc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},eu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},tu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},ru=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},su=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},nu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},ou=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},mi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},hi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},_i=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},au=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},iu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},PA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},lu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_CTC_MAPPING_NAMES]},cu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},zA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},LA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},uu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},NA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},pu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},du=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},$A=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},RA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},fu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},UA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},BA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function Ye(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>Xe.read(e)))}async function Wr(t,e){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(r=>typeof r=="string"||r instanceof URL?xf(r,e):r instanceof Float64Array?new Float32Array(r):r))}function gi(t,e){e&&(t=t.map(a=>a|0));let[r,s,n,o]=t;return{xmin:r,ymin:s,xmax:n,ymax:o}}var pe=class extends Je{constructor({task:e,model:r,tokenizer:s=null,processor:n=null}){super(),this.task=e,this.model=r,this.tokenizer=s,this.processor=n}async dispose(){await this.model.dispose()}};var mu=class extends pe{async _call(e,{top_k:r=1}={}){let s=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(s),{problem_type:o,id2label:a}=this.model.config,i=o==="multi_label_classification"?u=>u.sigmoid():u=>new U("float32",Pe(u.data),u.dims),l=[];for(let u of n.logits){let d=i(u),f=await Yt(d,r),m=f[0].tolist(),w=f[1].tolist().map((x,k)=>({label:a?a[x]:`LABEL_${x}`,score:m[k]}));r===1?l.push(...w):l.push(w)}return Array.isArray(e)||r===1?l:l[0]}};var hu=class extends pe{async _call(e,{ignore_labels:r=["O"]}={}){let s=Array.isArray(e),n=this.tokenizer(s?e:[e],{padding:!0,truncation:!0}),a=(await this.model(n)).logits,i=this.model.config.id2label,l=[];for(let u=0;u<a.dims[0];++u){let d=n.input_ids[u],f=a[u],m=[];for(let _=0;_<f.dims[0];++_){let w=f[_],x=Te(w.data)[1],k=i?i[x]:`LABEL_${x}`;if(r.includes(k))continue;let E=this.tokenizer.decode([d[_].item()],{skip_special_tokens:!0});if(E==="")continue;let M=Pe(w.data);m.push({entity:k,score:M[x],index:_,word:E})}l.push(m)}return s?l:l[0]}};var _u=class extends pe{async _call(e,r,{top_k:s=1}={}){let n=this.tokenizer(e,{text_pair:r,padding:!0,truncation:!0}),o=Array.isArray(e),{start_logits:a,end_logits:i}=await this.model(n),l=n.input_ids.tolist(),u=n.attention_mask.tolist(),{all_special_ids:d,sep_token_id:f}=this.tokenizer,m=[];for(let _=0;_<a.dims[0];++_){let w=l[_],x=w.findIndex(C=>C==f),k=a[_].tolist(),E=i[_].tolist();for(let C=1;C<k.length;++C)(u[_]==0||C<=x||d.findIndex(v=>v==w[C])!==-1)&&(k[C]=-1/0,E[C]=-1/0);let M=Pe(k).map((C,v)=>[C,v]),I=Pe(E).map((C,v)=>[C,v]);M[0][0]=0,I[0][0]=0;let T=zv(M,I).filter(C=>C[0][1]<=C[1][1]).map(C=>[C[0][1],C[1][1],C[0][0]*C[1][0]]).sort((C,v)=>v[2]-C[2]),z=[];for(let C=0;C<Math.min(T.length,s);++C){let[v,G,X]=T[C],V=w.slice(v,G+1),Q=this.tokenizer.decode(V,{skip_special_tokens:!0});z.push({answer:Q,score:X})}s===1?m.push(...z):m.push(z)}return o?m:m[0]}};var gu=class extends pe{async _call(e,{top_k:r=5}={}){let{mask_token_id:s,mask_token:n}=this.tokenizer,o=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:a}=await this.model(o),i=[],l=o.input_ids.tolist();for(let u=0;u<l.length;++u){let d=l[u],f=d.findIndex(k=>k==s);if(f===-1)throw Error(`Mask token (${n}) not found in text.`);let m=a[u][f],_=await Yt(new U("float32",Pe(m.data),m.dims),r),w=_[0].tolist(),x=_[1].tolist();i.push(x.map((k,E)=>{let M=d.slice();return M[f]=k,{score:w[E],token:Number(k),token_str:this.tokenizer.decode([k]),sequence:this.tokenizer.decode(M,{skip_special_tokens:!0})}}))}return Array.isArray(e)?i:i[0]}};var Vr=class extends pe{_key="generated_text";async _call(e,r={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(l=>this.model.config.prefix+l));let s=this.model.config.task_specific_params;s&&s[this.task]&&s[this.task].prefix&&(e=e.map(l=>s[this.task].prefix+l));let n=this.tokenizer,o={padding:!0,truncation:!0},a;this.task==="translation"&&"_build_translation_inputs"in n?a=n._build_translation_inputs(e,o,r):a=n(e,o);let i=await this.model.generate({...a,...r});return n.batch_decode(i,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}};var wu=class extends Vr{_key="summary_text"};var xu=class extends Vr{_key="translation_text"};function DA(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var yu=class extends pe{async _call(e,r={}){let s=!1,n=!1,o=r.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,a=r.tokenizer_encode_kwargs,i;if(typeof e=="string")i=e=[e];else if(Array.isArray(e)&&e.every(w=>typeof w=="string"))s=!0,i=e;else{if(DA(e))e=[e];else if(Array.isArray(e)&&e.every(DA))s=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");n=!0,i=e.map(w=>this.tokenizer.apply_chat_template(w,{tokenize:!1,add_generation_prompt:!0,...a})),o=!1,a=void 0}let l=n?!1:r.return_full_text??!0;this.tokenizer.padding_side="left";let u=this.tokenizer(i,{add_special_tokens:o,padding:!0,truncation:!0,...a}),d=await this.model.generate({...u,...r}),f=this.tokenizer.batch_decode(d,{skip_special_tokens:!0}),m;!l&&u.input_ids.dims.at(-1)>0&&(m=this.tokenizer.batch_decode(u.input_ids,{skip_special_tokens:!0}).map(w=>w.length));let _=Array.from({length:e.length},w=>[]);for(let w=0;w<f.length;++w){let x=Math.floor(w/d.dims[0]*e.length);m&&(f[w]=f[w].slice(m[x])),_[x].push({generated_text:n?[...e[x],{role:"assistant",content:f[w]}]:f[w]})}return!s&&_.length===1?_[0]:_}};var bu=class extends pe{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([r,s])=>[r.toLowerCase(),s])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,r,{hypothesis_template:s="This example is {}.",multi_label:n=!1}={}){let o=Array.isArray(e);o||(e=[e]),Array.isArray(r)||(r=[r]);let a=r.map(u=>s.replace("{}",u)),i=n||r.length===1,l=[];for(let u of e){let d=[];for(let _ of a){let w=this.tokenizer(u,{text_pair:_,padding:!0,truncation:!0}),x=await this.model(w);i?d.push([x.logits.data[this.contradiction_id],x.logits.data[this.entailment_id]]):d.push(x.logits.data[this.entailment_id])}let m=(i?d.map(_=>Pe(_)[1]):Pe(d)).map((_,w)=>[_,w]).sort((_,w)=>w[0]-_[0]);l.push({sequence:u,labels:m.map(_=>r[_[1]]),scores:m.map(_=>_[0])})}return o?l:l[0]}};var vu=class extends pe{async _call(e,{top_k:r=5}={}){let s=this.processor.feature_extractor.config.sampling_rate,n=await Wr(e,s),o=this.model.config.id2label,a=[];for(let i of n){let l=await this.processor(i),d=(await this.model(l)).logits[0],f=await Yt(new U("float32",Pe(d.data),d.dims),r),m=f[0].tolist(),w=f[1].tolist().map((x,k)=>({label:o?o[x]:`LABEL_${x}`,score:m[k]}));a.push(w)}return Array.isArray(e)?a:a[0]}};var ku=class extends pe{async _call(e,r,{hypothesis_template:s="This is a sound of {}."}={}){let n=!Array.isArray(e);n&&(e=[e]);let o=r.map(d=>s.replace("{}",d)),a=this.tokenizer(o,{padding:!0,truncation:!0}),i=this.processor.feature_extractor.config.sampling_rate,l=await Wr(e,i),u=[];for(let d of l){let f=await this.processor(d),m=await this.model({...a,...f}),_=Pe(m.logits_per_audio.data);u.push([..._].map((w,x)=>({score:w,label:r[x]})))}return n?u[0]:u}};var Eu=class extends pe{async _call(e,r={}){switch(this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(e,r);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(e,r);case"moonshine":return this._call_moonshine(e,r);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,r){r.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),r.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');let s=!Array.isArray(e),n=s?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,a=await Wr(n,o),i=[];for(let l of a){let u=await this.processor(l),f=(await this.model(u)).logits[0],m=[];for(let w of f)m.push(Te(w.data)[1]);let _=this.tokenizer.decode(m,{skip_special_tokens:!0}).trim();i.push({text:_})}return s?i[0]:i}async _call_whisper(e,r){let s=r.return_timestamps??!1,n=r.chunk_length_s??0,o=r.force_full_sequences??!1,a=r.stride_length_s??null,i={...r};s==="word"&&(i.return_token_timestamps=!0,i.return_timestamps=!1);let l=!Array.isArray(e),u=l?[e]:e,d=this.processor.feature_extractor.config,f=d.chunk_length/this.model.config.max_source_positions,m=d.hop_length,_=d.sampling_rate,w=await Wr(u,_),x=[];for(let k of w){let E=[];if(n>0){if(a===null)a=n/6;else if(n<=a)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let T=_*n,z=_*a,C=T-2*z,v=0;for(;;){let G=v+T,X=k.subarray(v,G),V=await this.processor(X),Q=v===0,K=G>=k.length;if(E.push({stride:[X.length,Q?0:z,K?0:z],input_features:V.input_features,is_last:K}),K)break;v+=C}}else E=[{stride:[k.length,0,0],input_features:(await this.processor(k)).input_features,is_last:!0}];for(let T of E){i.num_frames=Math.floor(T.stride[0]/m);let z=await this.model.generate({inputs:T.input_features,...i});s==="word"?(T.tokens=z.sequences.tolist()[0],T.token_timestamps=z.token_timestamps.tolist()[0].map(C=>rs(C,2))):T.tokens=z[0].tolist(),T.stride=T.stride.map(C=>C/_)}let[M,I]=this.tokenizer._decode_asr(E,{time_precision:f,return_timestamps:s,force_full_sequences:o});x.push({text:M,...I})}return l?x[0]:x}async _call_moonshine(e,r){let s=!Array.isArray(e),n=s?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,a=await Wr(n,o),i=[];for(let l of a){let u=await this.processor(l),d=Math.floor(l.length/o)*6,f=await this.model.generate({max_new_tokens:d,...r,...u}),m=this.processor.batch_decode(f,{skip_special_tokens:!0})[0];i.push({text:m})}return s?i[0]:i}};var Au=class extends pe{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _prepare_speaker_embeddings(e,r){if((typeof e=="string"||e instanceof URL)&&(e=new Float32Array(await(await fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new U("float32",e,[e.length]);else if(!(e instanceof U))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(r>1){if(e.dims[0]===1)e=e.repeat(r,1);else if(e.dims[0]!==r)throw new Error(`Expected speaker embeddings batch size to be 1 or ${r}, but got ${e.dims[0]}.`)}return e}_postprocess_waveform(e,r,s,n=null){let o=r.data,[a,i]=r.dims,l=n?n.data:null,u=[];for(let d=0;d<a;++d){let f=l?Math.min(Math.ceil(l[d]),i):i,m=d*i;u.push(new to(o.slice(m,m+f),s))}return Array.isArray(e)?u:u[0]}async _call(e,r){return this.processor?this._call_text_to_spectrogram(e,r):this.model.config.model_type==="supertonic"?this._call_supertonic(e,r):this._call_text_to_waveform(e)}async _call_supertonic(e,{speaker_embeddings:r,num_inference_steps:s,speed:n}){if(!r)throw new Error("Speaker embeddings must be provided for Supertonic models.");let{sampling_rate:o,style_dim:a}=this.model.config,i=this.tokenizer(e,{padding:!0,truncation:!0}),l=i.input_ids.dims[0];r=await this._prepare_speaker_embeddings(r,l),r=r.view(l,-1,a);let{waveform:u,durations:d}=await this.model.generate_speech({...i,style:r,num_inference_steps:s,speed:n});return this._postprocess_waveform(e,u,o,d)}async _call_text_to_waveform(e){let r=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model(r),n=this.model.config.sampling_rate;return this._postprocess_waveform(e,s,n)}async _call_text_to_spectrogram(e,{speaker_embeddings:r}){this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await wr.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));let{input_ids:s}=this.tokenizer(e,{padding:!0,truncation:!0}),n=s.dims[0];r=await this._prepare_speaker_embeddings(r,n),r=r.view(n,-1);let{waveform:o}=await this.model.generate_speech(s,r,{vocoder:this.vocoder}),a=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(e,o,a)}};var Mu=class extends pe{async _call(e,r={}){let s=Array.isArray(e),n=await Ye(e),{pixel_values:o}=await this.processor(n),a=[];for(let i of o){i.dims=[1,...i.dims];let l=await this.model.generate({inputs:i,...r}),u=this.tokenizer.batch_decode(l,{skip_special_tokens:!0}).map(d=>({generated_text:d.trim()}));a.push(u)}return s?a:a[0]}};var Tu=class extends pe{async _call(e,{top_k:r=5}={}){let s=await Ye(e),{pixel_values:n}=await this.processor(s),o=await this.model({pixel_values:n}),{id2label:a}=this.model.config,i=[];for(let l of o.logits){let u=await Yt(new U("float32",Pe(l.data),l.dims),r),d=u[0].tolist(),m=u[1].tolist().map((_,w)=>({label:a?a[_]:`LABEL_${_}`,score:d[w]}));i.push(m)}return Array.isArray(e)?i:i[0]}};var FA={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},Tn=class extends pe{async _call(e,{threshold:r=.5,mask_threshold:s=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:o=null,target_sizes:a=null,subtask:i=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");let u=await Ye(e),d=u.map(M=>[M.height,M.width]),f=await this.processor(u),{inputNames:m,outputNames:_}=this.model.sessions.model;if(!m.includes("pixel_values")){if(m.length!==1)throw Error(`Expected a single input name, but got ${m.length} inputs: ${m}.`);let M=m[0];if(M in f)throw Error(`Input name ${M} already exists in the inputs.`);f[M]=f.pixel_values}let w=await this.model(f),x=null;if(i!==null)x=FA[i];else if(this.processor.image_processor){for(let[M,I]of Object.entries(FA))if(I in this.processor.image_processor){x=this.processor.image_processor[I].bind(this.processor.image_processor),i=M;break}}let k=this.model.config.id2label,E=[];if(i)if(i==="panoptic"||i==="instance"){let M=x(w,r,s,n,o,a??d)[0],I=M.segmentation;for(let T of M.segments_info){let z=new Uint8ClampedArray(I.data.length);for(let v=0;v<I.data.length;++v)I.data[v]===T.id&&(z[v]=255);let C=new Xe(z,I.dims[1],I.dims[0],1);E.push({score:T.score,label:k[T.label_id],mask:C})}}else if(i==="semantic"){let{segmentation:M,labels:I}=x(w,a??d)[0];for(let T of I){let z=new Uint8ClampedArray(M.data.length);for(let v=0;v<M.data.length;++v)M.data[v]===T&&(z[v]=255);let C=new Xe(z,M.dims[1],M.dims[0],1);E.push({score:null,label:k[T],mask:C})}}else throw Error(`Subtask ${i} not supported.`);else{let I=w[_[0]];for(let T=0;T<d.length;++T){let z=d[T],C=I[T];C.data.some(G=>G<-1e-5||G>1+1e-5)&&C.sigmoid_();let v=await Xe.fromTensor(C.mul_(255).to("uint8")).resize(z[1],z[0]);E.push({label:null,score:null,mask:v})}}return E}};var Su=class extends Tn{async _call(e,r={}){let s=await Ye(e),n=await super._call(e,r),o=s.map((a,i)=>{let l=a.clone();return l.putAlpha(n[i].mask),l});return Array.isArray(e)?o:o[0]}};var Ou=class extends pe{async _call(e,r,{hypothesis_template:s="This is a photo of {}"}={}){let n=Array.isArray(e),o=await Ye(e),a=r.map(m=>s.replace("{}",m)),i=this.tokenizer(a,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:l}=await this.processor(o),u=await this.model({...i,pixel_values:l}),d=this.model.config.model_type==="siglip"?m=>m.sigmoid().data:m=>Pe(m.data),f=[];for(let m of u.logits_per_image){let w=[...d(m)].map((x,k)=>({score:x,label:r[k]}));w.sort((x,k)=>k.score-x.score),f.push(w)}return n?f:f[0]}};var Iu=class extends pe{async _call(e,{threshold:r=.9,percentage:s=!1}={}){let n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");let o=await Ye(e),a=s?null:o.map(_=>[_.height,_.width]),{pixel_values:i,pixel_mask:l}=await this.processor(o),u=await this.model({pixel_values:i,pixel_mask:l}),d=this.processor.image_processor.post_process_object_detection(u,r,a),{id2label:f}=this.model.config,m=d.map(_=>_.boxes.map((w,x)=>({score:_.scores[x],label:f[_.classes[x]],box:gi(w,!s)})));return n?m:m[0]}};var Cu=class extends pe{async _call(e,r,{threshold:s=.1,top_k:n=null,percentage:o=!1}={}){let a=Array.isArray(e),i=await Ye(e),l=this.tokenizer(r,{padding:!0,truncation:!0}),u=await this.processor(i),d=[];for(let f=0;f<i.length;++f){let m=i[f],_=o?null:[[m.height,m.width]],w=u.pixel_values[f].unsqueeze_(0),x=await this.model({...l,pixel_values:w}),k;if("post_process_grounded_object_detection"in this.processor){let E=this.processor.post_process_grounded_object_detection(x,l.input_ids,{box_threshold:s,text_threshold:s,target_sizes:_})[0];k=E.boxes.map((M,I)=>({score:E.scores[I],label:E.labels[I],box:gi(M,!o)}))}else{let E=this.processor.image_processor.post_process_object_detection(x,s,_,!0)[0];k=E.boxes.map((M,I)=>({score:E.scores[I],label:r[E.classes[I]],box:gi(M,!o)}))}k.sort((E,M)=>M.score-E.score),n!==null&&(k=k.slice(0,n)),d.push(k)}return a?d:d[0]}};var Pu=class extends pe{async _call(e,r,s={}){if(Array.isArray(e)){if(e.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");e=e[0]}let n=(await Ye(e))[0],{pixel_values:o}=await this.processor(n),a=`<s_docvqa><s_question>${r}</s_question><s_answer>`,i=this.tokenizer(a,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:o,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:i,...s}),d=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/),f=null;return d&&d.length>=2&&(f=d[1].trim()),[{answer:f}]}};var zu=class extends pe{async _call(e){let r=await Ye(e),s=await this.processor(r),n=await this.model(s),o=[];for(let a of n.reconstruction){let i=a.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");o.push(Xe.fromTensor(i))}return Array.isArray(e)?o:o[0]}};var Lu=class extends pe{async _call(e){let r=await Ye(e),s=await this.processor(r),{predicted_depth:n}=await this.model(s),o=[];for(let a=0;a<r.length;++a){let i=n[a],[l,u]=i.dims.slice(-2),[d,f]=r[a].size,m=(await Dt(i.view(1,1,l,u),{size:[f,d],mode:"bilinear"})).view(f,d),_=m.min().item(),w=m.max().item(),x=m.sub(_).div_(w-_).mul_(255).to("uint8").unsqueeze(0),k=Xe.fromTensor(x);o.push({predicted_depth:m,depth:k})}return Array.isArray(e)?o:o[0]}};var Nu=class extends pe{async _call(e,{pooling:r="none",normalize:s=!1,quantize:n=!1,precision:o="binary"}={}){let a=this.tokenizer(e,{padding:!0,truncation:!0}),i=await this.model(a),l=i.last_hidden_state??i.logits??i.token_embeddings;switch(r){case"none":break;case"mean":l=CE(l,a.attention_mask);break;case"first_token":case"cls":l=l.slice(null,0);break;case"last_token":case"eos":l=l.slice(null,-1);break;default:throw Error(`Pooling method '${r}' not supported.`)}return s&&(l=l.normalize(2,-1)),n&&(l=zE(l,o)),l}};var $u=class extends pe{async _call(e,{pool:r=null}={}){let s=await Ye(e),{pixel_values:n}=await this.processor(s),o=await this.model({pixel_values:n}),a;if(r){if(!("pooler_output"in o))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");a=o.pooler_output}else a=o.last_hidden_state??o.logits??o.image_embeds;return a}};var jA=Object.freeze({"text-classification":{tokenizer:J,pipeline:mu,model:fi,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:J,pipeline:hu,model:Qc,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:J,pipeline:_u,model:su,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:J,pipeline:gu,model:ru,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{tokenizer:J,pipeline:wu,model:Mn,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:J,pipeline:xu,model:Mn,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:J,pipeline:Vr,model:Mn,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:J,pipeline:yu,model:tu,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{tokenizer:J,pipeline:bu,model:fi,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:vu,model:cu,processor:ut,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:J,pipeline:ku,model:wr,processor:ut,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:J,pipeline:Eu,model:[Jc,lu],processor:ut,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:J,pipeline:Au,model:[eu,Zc],processor:[ut,null],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{tokenizer:J,pipeline:Mu,model:nu,processor:ut,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:Tu,model:ou,processor:ut,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:Tn,model:[mi,hi,_i],processor:ut,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:Su,model:[mi,hi,_i],processor:ut,default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{tokenizer:J,pipeline:Ou,model:wr,processor:ut,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:Iu,model:au,processor:ut,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:J,pipeline:Cu,model:iu,processor:ut,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:J,pipeline:Pu,model:uu,processor:ut,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:zu,model:pu,processor:ut,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:Lu,model:du,processor:ut,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{tokenizer:J,pipeline:Nu,model:wr,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{processor:ut,pipeline:$u,model:[fu,wr],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),KP=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function Eee(t,e=null,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",device:i=null,dtype:l=null,subfolder:u="onnx",use_external_data_format:d=null,model_file_name:f=null,session_options:m={}}={}){t=KP[t]??t;let _=jA[t.split("_",1)[0]];if(!_)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(jA)}]`);e||(e=_.default.model,console.log(`No model specified. Using default model: "${e}".`),!l&&_.default.dtype&&(l=_.default.dtype));let w={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,device:i,dtype:l,subfolder:u,use_external_data_format:d,model_file_name:f,session_options:m},x=new Map([["tokenizer",_.tokenizer],["model",_.model],["processor",_.processor]]),k=await YP(x,e,w);k.task=t,hr(r,{status:"ready",task:t,model:e});let E=_.pipeline;return new E(k)}async function YP(t,e,r){let s=Object.create(null),n=[];for(let[o,a]of t.entries()){if(!a)continue;let i;Array.isArray(a)?i=new Promise(async(l,u)=>{let d;for(let f of a){if(f===null){l(null);return}try{l(await f.from_pretrained(e,r));return}catch(m){if(m.message?.includes("Unsupported model type"))d=m;else if(m.message?.includes("Could not locate file"))d=m;else{u(m);return}}}u(d)}):i=a.from_pretrained(e,r),s[o]=i,n.push(i)}await Promise.all(n);for(let[o,a]of Object.entries(s))s[o]=await a;return s}var QP=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,F0=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},GA=be.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),j0=class extends F0{constructor(e,{skip_prompt:r=!1,callback_function:s=null,token_callback_function:n=null,skip_special_tokens:o=!0,decode_kwargs:a={},...i}={}){super(),this.tokenizer=e,this.skip_prompt=r,this.callback_function=s??GA,this.token_callback_function=n,this.decode_kwargs={skip_special_tokens:o,...a,...i},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0}put(e){if(e.length>1)throw Error("TextStreamer only supports batch size of 1");let r=this.next_tokens_are_prompt;if(r&&(this.next_tokens_are_prompt=!1,this.skip_prompt))return;let s=e[0];this.token_callback_function?.(s),this.token_cache=dt(this.token_cache,s);let n=this.tokenizer.decode(this.token_cache,this.decode_kwargs),o;r||n.endsWith(`
27
+ `}):(console.warn("You are passing both `text` and `images` to `PaliGemmaProcessor`. The processor expects special image tokens in the text, as many tokens as there are images per each text. It is recommended to add `<image>` tokens in the very beginning of your text. For this call, we will infer how many images each text has and add special tokens."),a=r.map(u=>TP(u,n,o,en,e.length)));let i=this.tokenizer(a,s);return{...await this.image_processor(e,s),...i}}};var VE="<|image|>",SP=/<\|image_\d+\|>/g,zm=class extends ne{static image_processor_class=$e;static tokenizer_class=J;async _call(e,r=null,{padding:s=!0,truncation:n=!0,num_crops:o=null}={}){Array.isArray(e)||(e=[e]);let a,i;if(r){i=await this.image_processor(r,{num_crops:o});let{num_img_tokens:l}=i,u=e.map((f,m)=>f.split(SP).join(VE.repeat(l[m])));a=this.tokenizer(u,{padding:s,truncation:n});let d=this.tokenizer._tokenizer.token_to_id(VE);a.input_ids.map_(f=>f==d?-f:f)}else a=this.tokenizer(e);return{...a,...i}}};var Lm=class extends ne{static tokenizer_class=J;static image_processor_class=$e;static uses_processor_config=!0;async _call(e,r=null,s={}){let n=await this.image_processor(e,s);if(r){let[a,i]=n.pixel_values.dims.slice(-2),{image_token:l,image_break_token:u,image_end_token:d,patch_size:f,spatial_merge_size:m}=this.config,_=f*m,w=Math.floor(a/_),x=Math.floor(i/_);r=structuredClone(r),Array.isArray(r)||(r=[r]);for(let k=0;k<r.length;++k){let E=l.repeat(x),M=E+u,I=E+d,T=M.repeat(w-1)+I;r[k]=r[k].replace(l,T)}}let o=r?this.tokenizer(r,s):{};return{...n,...o}}};var Nm=class extends ne{static feature_extractor_class=no;async _call(e){return await this.feature_extractor(e)}post_process_speaker_diarization(...e){return this.feature_extractor.post_process_speaker_diarization(...e)}get sampling_rate(){return this.feature_extractor.config.sampling_rate}};var $m=class extends ne{static image_processor_class=$e;static tokenizer_class=J;async _call(e,r=null,...s){Array.isArray(e)||(e=[e]);let n,o;if(r&&(n=await this.image_processor(r),o=n.image_grid_thw),o){let i=this.image_processor.config.merge_size**2,l=0,u=o.tolist();e=e.map(d=>{for(;d.includes("<|image_pad|>");){let f=Number(u[l++].reduce((m,_)=>m*_,1n));d=d.replace("<|image_pad|>","<|placeholder|>".repeat(Math.floor(f/i)))}return d.replaceAll("<|placeholder|>","<|image_pad|>")})}return{...this.tokenizer(e),...n}}};var io=class extends ne{static image_processor_class=$e;async _call(...e){return await this.image_processor(...e)}post_process_masks(...e){return this.image_processor.post_process_masks(...e)}reshape_input_points(...e){return this.image_processor.reshape_input_points(...e)}};var Ol=class extends io{},Rm=class extends Ol{};var Um=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var Bm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;static uses_processor_config=!0;async _call(e,r=null,s={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(r){let a=r.length,{input_features:i}=await this.feature_extractor(r,{...s,max_length:a}),l=Math.round(a/this.config.encoder_ds_factor+1e-4),u=1+Math.ceil(l/this.config.stack_factor);n.audio_token_len=[u],n.audio_values=i;let d=this.config.audio_placeholder;if(!e.includes(d))throw new Error(`The input text does not contain the image token ${d}.`);e=e.replaceAll(d,d.repeat(u))}return{...this.tokenizer(e,{add_special_tokens:!1,...s}),...n}}};var Il="[AUDIO]",OP="[BEGIN_AUDIO]",IP=375;function CP(t,e){let r=[];for(let s=0;s<t.length;s+=e)r.push(t.subarray(s,Math.min(s+e,t.length)));return r}var Dm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;static uses_processor_config=!1;async _call(e,r=null,s={}){if(Array.isArray(e))throw new Error("Batched inputs are not supported yet.");let n={};if(r){if(!e.includes(Il))throw new Error(`The input text does not contain the audio token ${Il}.`);Array.isArray(r)||(r=[r]);let a=e.split(Il),i=a.length-1;if(i!==r.length)throw new Error(`The number of audio inputs (${r.length}) does not match the number of audio tokens in the text (${i}).`);let l=this.feature_extractor.config.n_samples,u=r.map(w=>CP(w,l)),d=u.map(w=>w.length),f=u.flat(),m=(await Promise.all(f.map(w=>this.feature_extractor(w,s)))).map(w=>w.input_features);n.audio_values=m.length>1?Ee(m,0):m[0];let _=a[0];for(let w=0;w<d.length;++w){_+=OP;for(let x=0;x<d[w];++x)_+=Il.repeat(IP);_+=a[w+1]}e=_}return{...this.tokenizer(e,{add_special_tokens:!1,...s}),...n}}};var Fm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var jm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var Gm=class extends ne{static tokenizer_class=J;static feature_extractor_class=tt;async _call(e){return await this.feature_extractor(e)}};var ut=class{static async from_pretrained(e,r={}){let s=await at(e,Xs,!0,r),{image_processor_type:n,feature_extractor_type:o,processor_class:a}=s;if(a&&Cl[a])return Cl[a].from_pretrained(e,r);if(!n&&!o)throw new Error("No `image_processor_type` or `feature_extractor_type` found in the config.");let i={};if(n){let u=Zs[n.replace(/Fast$/,"")];if(!u)throw new Error(`Unknown image_processor_type: '${n}'.`);i.image_processor=new u(s)}if(o){let u=Zs[o];if(u)i.image_processor=new u(s);else{let d=oo[o];if(!d)throw new Error(`Unknown feature_extractor_type: '${o}'.`);i.feature_extractor=new d(s)}}let l={};return new ne(l,i,null)}};async function PP(t,e){return await at(t,"config.json",!0,e)}function tn(t){let e={},r={};switch(t.model_type){case"llava":case"paligemma":case"gemma3":case"florence2":case"llava_onevision":case"idefics3":case"ultravox":case"voxtral":case"smolvlm":case"gemma3n":case"chatterbox":case"mistral3":r=tn(t.text_config);break;case"moondream1":r=tn(t.phi_config);break;case"musicgen":r=tn(t.decoder);break;case"multi_modality":r=tn(t.language_config);break;case"gpt2":case"gptj":case"jais":case"codegen":case"gpt_bigcode":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="n_embd";break;case"gpt_neox":case"stablelm":case"opt":case"falcon":case"modernbert-decoder":e.num_heads="num_attention_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size";break;case"gpt_oss":case"llama":case"llama4_text":case"nanochat":case"apertus":case"arcee":case"lfm2":case"lfm2_moe":case"smollm3":case"olmo":case"olmo2":case"olmo3":case"mobilellm":case"granite":case"granitemoehybrid":case"cohere":case"mistral":case"starcoder2":case"qwen2":case"qwen2_vl":case"phi":case"phi3":case"phi3_v":case"llava_qwen2":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.hidden_size="hidden_size",e.num_attention_heads="num_attention_heads",e.dim_kv="head_dim";break;case"qwen3":case"gemma":case"gemma2":case"vaultgemma":case"gemma3_text":case"gemma3n_text":case"glm":case"helium":case"ernie4_5":case"hunyuan_v1_dense":case"falcon_h1":case"ministral":case"ministral3":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="head_dim";break;case"openelm":e.num_heads="num_kv_heads",e.num_layers="num_transformer_layers",e.dim_kv="head_dim";break;case"gpt_neo":case"donut-swin":e.num_heads="num_heads",e.num_layers="num_layers",e.hidden_size="hidden_size";break;case"bloom":e.num_heads="n_head",e.num_layers="n_layer",e.hidden_size="hidden_size";break;case"mpt":e.num_heads="n_heads",e.num_layers="n_layers",e.hidden_size="d_model";break;case"exaone":e.num_heads="num_key_value_heads",e.num_layers="num_layers",e.dim_kv="head_dim",e.num_attention_heads="num_attention_heads";break;case"youtu":e.num_heads="num_key_value_heads",e.num_layers="num_hidden_layers",e.dim_kv="qk_head_dim",e.num_attention_heads="num_attention_heads";break;case"t5":case"mt5":case"longt5":e.num_decoder_layers="num_decoder_layers",e.num_decoder_heads="num_heads",e.decoder_dim_kv="d_kv",e.num_encoder_layers="num_layers",e.num_encoder_heads="num_heads",e.encoder_dim_kv="d_kv";break;case"bart":case"mbart":case"marian":case"whisper":case"lite-whisper":case"m2m_100":case"blenderbot":case"blenderbot-small":case"florence2_language":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="d_model",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="d_model";break;case"speecht5":e.num_decoder_layers="decoder_layers",e.num_decoder_heads="decoder_attention_heads",e.decoder_hidden_size="hidden_size",e.num_encoder_layers="encoder_layers",e.num_encoder_heads="encoder_attention_heads",e.encoder_hidden_size="hidden_size";break;case"trocr":e.num_encoder_layers=e.num_decoder_layers="decoder_layers",e.num_encoder_heads=e.num_decoder_heads="decoder_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="d_model";break;case"musicgen_decoder":e.num_encoder_layers=e.num_decoder_layers="num_hidden_layers",e.num_encoder_heads=e.num_decoder_heads="num_attention_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"moonshine":e.num_decoder_layers="decoder_num_hidden_layers",e.num_decoder_heads="decoder_num_key_value_heads",e.num_encoder_layers="encoder_num_hidden_layers",e.num_encoder_heads="encoder_num_key_value_heads",e.encoder_hidden_size=e.decoder_hidden_size="hidden_size";break;case"vision-encoder-decoder":let n=tn(t.decoder),o="num_decoder_layers"in n,a=ot(t,["model_type","is_encoder_decoder"]);return o?(a.num_decoder_layers=n.num_decoder_layers,a.num_decoder_heads=n.num_decoder_heads,a.decoder_hidden_size=n.decoder_hidden_size,a.num_encoder_layers=n.num_encoder_layers,a.num_encoder_heads=n.num_encoder_heads,a.encoder_hidden_size=n.encoder_hidden_size):(a.num_layers=n.num_layers,a.num_heads=n.num_heads,a.hidden_size=n.hidden_size),a}let s={...r,...ot(t,["model_type","multi_query","is_encoder_decoder"])};for(let n in e)s[n]=t[e[n]];return s}function zl(t,e){if(["lfm2","lfm2_moe"].includes(t.model_type)){let r=e?.prefix??"past_key_values",s=r==="present"?"present":"past",n={},{layer_types:o,num_attention_heads:a,num_key_value_heads:i,hidden_size:l,conv_L_cache:u}=t,d=l/a,f=e?.batch_size??1;for(let m=0;m<o.length;++m)if(o[m]==="full_attention")for(let _ of["key","value"])n[`${r}.${m}.${_}`]=[f,i,0,d];else if(o[m]==="conv")n[`${s}_conv.${m}`]=[f,l,u];else throw new Error(`Unsupported layer type: ${o[m]}`);return n}else if(["granitemoehybrid","falcon_h1"].includes(t.model_type)){let r=e?.prefix??"past_key_values",s=r==="present"?"present":"past",n={},{layer_types:o,num_hidden_layers:a,num_attention_heads:i,num_key_value_heads:l,hidden_size:u,mamba_d_conv:d,mamba_n_heads:f,mamba_d_head:m,mamba_d_state:_,mamba_n_groups:w,mamba_expand:x,mamba_d_ssm:k}=t,E=u/i,M=e?.batch_size??1,I=(k??x*u)+2*w*_;for(let T=0;T<a;++T)if((!o||o[T]==="mamba")&&(n[`${s}_conv.${T}`]=[M,I,d],n[`${s}_ssm.${T}`]=[M,f,m,_]),!o||o[T]==="attention")for(let z of["key","value"])n[`${r}.${T}.${z}`]=[M,l,0,E];return n}return zP(t,e)}function zP(t,{prefix:e="past_key_values",batch_size:r=1}={}){let s={},n=t.normalized_config;if(n.is_encoder_decoder&&"num_encoder_heads"in n&&"num_decoder_heads"in n){let o=n.encoder_dim_kv??n.encoder_hidden_size/n.num_encoder_heads,a=n.decoder_dim_kv??n.decoder_hidden_size/n.num_decoder_heads,i=[r,n.num_encoder_heads,0,o],l=[r,n.num_decoder_heads,0,a];for(let u=0;u<n.num_decoder_layers;++u)s[`${e}.${u}.encoder.key`]=i,s[`${e}.${u}.encoder.value`]=i,s[`${e}.${u}.decoder.key`]=l,s[`${e}.${u}.decoder.value`]=l}else{let o=n.num_heads,a=n.num_layers,i=n.dim_kv??n.hidden_size/(n.num_attention_heads??o);if(n.model_type==="falcon"){let l=[r*o,0,i];for(let u=0;u<a;++u)s[`${e}.${u}.key`]=l,s[`${e}.${u}.value`]=l}else if(n.multi_query){let l=[r*o,0,2*i];for(let u=0;u<a;++u)s[`${e}.${u}.key_value`]=l}else if(n.model_type==="bloom"){let l=[r*o,i,0],u=[r*o,0,i];for(let d=0;d<a;++d)s[`${e}.${d}.key`]=l,s[`${e}.${d}.value`]=u}else if(n.model_type==="openelm")for(let l=0;l<a;++l){let u=[r,o[l],0,i];s[`${e}.${l}.key`]=u,s[`${e}.${l}.value`]=u}else{let l=[r,o,0,i];for(let u=0;u<a;++u)s[`${e}.${u}.key`]=l,s[`${e}.${u}.value`]=l}}return s}var Pl=class t{model_type=null;is_encoder_decoder=!1;max_position_embeddings;"transformers.js_config";constructor(e){Object.assign(this,e),this.normalized_config=tn(this)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main"}={}){s&&!(s instanceof t)&&(s=new t(s));let i=s??await PP(e,{progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a});return new this(i)}},ms=class{static async from_pretrained(...e){return Pl.from_pretrained(...e)}};async function HE(t,e,r,s){let n=`${e}${s}.onnx`,o=`${r.subfolder??""}/${n}`;return await Bn(t,o,!0,r,be.IS_NODE_ENV)}async function XE(t,e,r,s,n,o={}){let a=`${e}${r}.onnx`,i=be.IS_NODE_ENV,l=[];if(n){let u;typeof n=="object"?n.hasOwnProperty(a)?u=n[a]:n.hasOwnProperty(e)?u=n[e]:u=!1:u=n;let d=+u;if(d>Bi)throw new Error(`The number of external data chunks (${d}) exceeds the maximum allowed value (${Bi}).`);for(let f=0;f<d;++f){let m=`${a}_data${f===0?"":"_"+f}`,_=`${s.subfolder??""}/${m}`;l.push(new Promise(async(w,x)=>{let k=await Bn(t,_,!0,s,i);w(k instanceof Uint8Array?{path:m,data:k}:m)}))}}else o.externalData!==void 0&&(l=o.externalData.map(async u=>{if(typeof u.data=="string"){let d=await Bn(t,u.data,!0,s);return{...u,data:d}}return u}));return Promise.all(l)}async function LP(t,e,r,s=!1){let n=r.config?.["transformers.js_config"]??{},o=r.device??n.device;o&&typeof o!="string"&&(o.hasOwnProperty(e)?o=o[e]:(console.warn(`device not specified for "${e}". Using the default device.`),o=null));let a=o??(be.IS_NODE_ENV?"cpu":"wasm"),i=kE(a),l=n.device_config??{};l.hasOwnProperty(a)&&(n={...n,...l[a]});let u=r.dtype??n.dtype;if(typeof u!="string"&&(u&&u.hasOwnProperty(e)?u=u[e]:(u=_d[a]??mt.fp32,console.warn(`dtype not specified for "${e}". Using the default dtype (${u}) for this device (${a}).`))),u===mt.auto){let z=n.dtype;typeof z!="string"&&(z=z?.[e]),z&&z!==mt.auto&&mt.hasOwnProperty(z)?u=z:u=_d[a]??mt.fp32}let d=u;if(gd.hasOwnProperty(d)){if(a==="webgpu"&&!be.IS_NODE_ENV&&d===mt.fp16&&!await TE())throw new Error(`The device (${a}) does not support fp16.`)}else throw new Error(`Invalid dtype: ${d}. Should be one of: ${Object.keys(mt).join(", ")}`);let f=n.kv_cache_dtype,m=f?typeof f=="string"?f:f[d]??"float32":void 0;if(m&&!["float32","float16"].includes(m))throw new Error(`Invalid kv_cache_dtype: ${m}. Should be one of: float32, float16`);let _=gd[d],w={...r.session_options};w.executionProviders??=i;let x=n.free_dimension_overrides;x?w.freeDimensionOverrides??=x:a.startsWith("webnn")&&!w.freeDimensionOverrides&&console.warn(`WebNN does not currently support dynamic shapes and requires 'free_dimension_overrides' to be set in config.json, preferably as a field within config["transformers.js_config"]["device_config"]["${a}"]. When 'free_dimension_overrides' is not set, you may experience significant performance degradation.`);let k=HE(t,e,r,_),E=r.use_external_data_format??n.use_external_data_format,M=await XE(t,e,_,r,E,w);if(M.length>0&&!be.IS_NODE_ENV&&(w.externalData=M),s&&a==="webgpu"&&f!==!1){let z=zl(r.config,{prefix:"present"});if(Object.keys(z).length>0&&!Kn()){let C={};for(let v in z)C[v]="gpu-buffer";w.preferredOutputLocation=C}}return{buffer_or_path:await k,session_options:w,session_config:{dtype:d,kv_cache_dtype:m,device:a}}}async function bt(t,e,r,s=void 0){return Object.fromEntries(await Promise.all(Object.keys(e).map(async n=>{let{buffer_or_path:o,session_options:a,session_config:i}=await LP(t,e[n],r,n===s),l=await tl(o,a,i);return[n,l]})))}function KE(t){for(let e in t)sl(t[e])?t[e]=new U(t[e]):typeof t[e]=="object"&&KE(t[e]);return t}async function ce(t,e){let r=NP(t,e);try{let s=Object.fromEntries(Object.entries(r).map(([o,a])=>{let i=a.ort_tensor;return be.IS_NODE_ENV&&typeof Float16Array<"u"&&i.cpuData instanceof Float16Array&&(i.cpuData=new Uint16Array(i.cpuData.buffer)),[o,i]})),n=await rl(t,s);return KE(n)}catch(s){let n=Object.fromEntries(Object.entries(r).map(([o,a])=>{let i={type:a.type,dims:a.dims,location:a.location};return i.location!=="gpu-buffer"&&(i.data=a.data),[o,i]}));throw console.error(`An error occurred during model execution: "${s}".`),console.error("Inputs given to model:",n),s}}function NP(t,e){let r=Object.create(null),s=[];for(let a of t.inputNames){let i=e[a];if(!(i instanceof U)){s.push(a);continue}r[a]=Kn()?i.clone():i}if(s.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${s.join(", ")}.`);let n=Object.keys(e).length,o=t.inputNames.length;if(n>o){let a=Object.keys(e).filter(i=>!t.inputNames.includes(i));console.warn(`WARNING: Too many inputs were provided (${n} > ${o}). The following inputs will be ignored: "${a.join(", ")}".`)}return r}var ze=class{};var F=class extends ze{constructor({logits:e,...r}){super(),this.logits=e;let s=Object.values(r);s.length>0&&(this.attentions=s)}},_e=class extends ze{constructor({logits:e}){super(),this.logits=e}},we=class extends ze{constructor({logits:e}){super(),this.logits=e}},Ae=class extends ze{constructor({start_logits:e,end_logits:r}){super(),this.start_logits=e,this.end_logits=r}},gt=class extends ze{constructor({logits:e}){super(),this.logits=e}};var Ll=class extends ze{constructor({alphas:e}){super(),this.alphas=e}};var jt=class extends Je{_call(e,r){throw Error("`_call` should be implemented in a subclass")}},lo=class extends Je{_call(e,r){throw Error("`_call` should be implemented in a subclass")}},hs=class extends Je{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,r){let s=r;for(let n of this.processors)s=n(e,s);return s}[Symbol.iterator](){return this.processors.values()}},Nl=class extends jt{constructor(e){super(),this.bos_token_id=e}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===1){let n=r[s].data;n.fill(-1/0),n[this.bos_token_id]=0}return r}},$l=class extends jt{constructor(e,r){super(),this.max_length=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===this.max_length-1){let n=r[s].data;n.fill(-1/0);for(let o of this.eos_token_id)n[o]=0}return r}},rn=class extends jt{constructor(e,r){super(),this.begin_suppress_tokens=e,this.begin_index=r}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length===this.begin_index){let n=r[s].data;for(let o of this.begin_suppress_tokens)n[o]=-1/0}return r}},Rl=class extends jt{constructor(e,r){super(),this.eos_token_id=Array.isArray(e.eos_token_id)?e.eos_token_id[0]:e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=r.length,r.at(-1)===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data;if(n[this.no_timestamps_token_id]=-1/0,e[s].length===this.begin_index-1){n.fill(-1/0),n[this.timestamp_begin]=0;continue}let o=e[s].slice(this.begin_index),a=o.length>=1&&o[o.length-1]>=this.timestamp_begin,i=o.length<2||o[o.length-2]>=this.timestamp_begin;if(a&&(i?n.subarray(this.timestamp_begin).fill(-1/0):n.subarray(0,this.eos_token_id).fill(-1/0)),e[s].length===this.begin_index&&this.max_initial_timestamp_index!==null){let f=this.timestamp_begin+this.max_initial_timestamp_index;n.subarray(f+1).fill(-1/0)}let l=vp(n),u=Math.log(l.subarray(this.timestamp_begin).map(Math.exp).reduce((f,m)=>f+m)),d=Te(l.subarray(0,this.timestamp_begin))[0];u>d&&n.subarray(0,this.timestamp_begin).fill(-1/0)}return r}},Ul=class extends jt{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){let r=e.length,s=[];for(let o=0;o<r+1-this.no_repeat_ngram_size;++o){let a=[];for(let i=0;i<this.no_repeat_ngram_size;++i)a.push(e[o+i]);s.push(a.map(Number))}let n=new Map;for(let o of s){let a=o.slice(0,o.length-1),i=JSON.stringify(a),l=n.get(i)??[];l.push(o[o.length-1]),n.set(i,l)}return n}getGeneratedNgrams(e,r){let s=r.slice(r.length+1-this.no_repeat_ngram_size,r.length);return e.get(JSON.stringify(s.map(Number)))??[]}calcBannedNgramTokens(e){let r=[];if(e.length+1<this.no_repeat_ngram_size)return r;{let s=this.getNgrams(e);return this.getGeneratedNgrams(s,e)}}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data,o=this.calcBannedNgramTokens(e[s]);for(let a of o)n[a]=-1/0}return r}},Bl=class extends jt{constructor(e){super(),this.penalty=e}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data;for(let o of new Set(e[s])){let a=Number(o);n[a]<0?n[a]*=this.penalty:n[a]/=this.penalty}}return r}},Dl=class extends jt{constructor(e,r){super(),this.min_length=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length<this.min_length){let n=r[s].data;for(let o of this.eos_token_id)n[o]=-1/0}return r}},Fl=class extends jt{constructor(e,r,s){super(),this.prompt_length_to_skip=e,this.min_new_tokens=r,this.eos_token_id=Array.isArray(s)?s:[s]}_call(e,r){for(let s=0;s<e.length;++s)if(e[s].length-this.prompt_length_to_skip<this.min_new_tokens){let o=r[s].data;for(let a of this.eos_token_id)o[a]=-1/0}return r}},jl=class extends jt{constructor(e,r){super(),this.bad_words_ids=e,this.eos_token_id=Array.isArray(r)?r:[r]}_call(e,r){for(let s=0;s<e.length;++s){let n=r[s].data,o=e[s];for(let a of this.bad_words_ids){if(o.length<a.length-1)continue;let i=!0;for(let l=1;l<=a.length-1;++l)if(a.at(-l-1)!=o.at(-l)){i=!1;break}i&&(n[a.at(-1)]=-1/0)}}return r}},Gl=class extends jt{constructor(e){if(super(),e<=1)throw new Error(`Require guidance scale >1 to use the classifier free guidance processor, got guidance scale ${e}.`);this.guidance_scale=e}_call(e,r){if(r.dims[0]!==2*e.length)throw new Error(`Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size ${r.dims[0]} for the logits and ${e.length} for the input ids.`);let s=e.length,n=r.slice([0,s],null),o=r.slice([s,r.dims[0]],null);for(let a=0;a<o.data.length;++a)o.data[a]+=(n.data[a]-o.data[a])*this.guidance_scale;return o}},ql=class extends lo{constructor(e){if(super(),typeof e!="number"||e<=0){let r=`\`temperature\` (=${e}) must be a strictly positive float, otherwise your next token scores will be invalid.`;e===0&&(r+=" If you're looking for greedy decoding strategies, set `do_sample=false`.")}this.temperature=e}_call(e,r){let s=r.data;for(let n=0;n<s.length;++n)s[n]/=this.temperature;return r}},YE=class extends lo{constructor(e,{filter_value:r=-1/0,min_tokens_to_keep:s=1}={}){if(super(),e<0||e>1)throw new Error(`\`top_p\` must be a float > 0 and < 1, but is ${e}`);if(!Number.isInteger(s)||s<1)throw new Error(`\`min_tokens_to_keep\` must be a positive integer, but is ${s}`);this.top_p=e,this.filter_value=r,this.min_tokens_to_keep=s}},QE=class extends lo{constructor(e,{filter_value:r=-1/0,min_tokens_to_keep:s=1}={}){if(super(),!Number.isInteger(e)||e<0)throw new Error(`\`top_k\` must be a positive integer, but is ${e}`);this.top_k=Math.max(e,s),this.filter_value=r}};var sn=class{max_length=20;max_new_tokens=null;min_length=0;min_new_tokens=null;early_stopping=!1;max_time=null;do_sample=!1;num_beams=1;num_beam_groups=1;penalty_alpha=null;use_cache=!0;temperature=1;top_k=50;top_p=1;typical_p=1;epsilon_cutoff=0;eta_cutoff=0;diversity_penalty=0;repetition_penalty=1;encoder_repetition_penalty=1;length_penalty=1;no_repeat_ngram_size=0;bad_words_ids=null;force_words_ids=null;renormalize_logits=!1;constraints=null;forced_bos_token_id=null;forced_eos_token_id=null;remove_invalid_values=!1;exponential_decay_length_penalty=null;suppress_tokens=null;streamer=null;begin_suppress_tokens=null;forced_decoder_ids=null;guidance_scale=null;num_return_sequences=1;output_attentions=!1;output_hidden_states=!1;output_scores=!1;return_dict_in_generate=!1;pad_token_id=null;bos_token_id=null;eos_token_id=null;encoder_no_repeat_ngram_size=0;decoder_start_token_id=null;generation_kwargs={};constructor(e){Object.assign(this,ot(e,Object.getOwnPropertyNames(this)))}};var nn=class extends Je{_call(e,r){throw Error("StoppingCriteria needs to be subclassed")}},Wl=class t extends Je{constructor(){super(),this.criteria=[]}push(e){this.criteria.push(e)}extend(e){e instanceof t?e=e.criteria:e instanceof nn&&(e=[e]),this.criteria.push(...e)}_call(e,r){let s=new Array(e.length).fill(!1);for(let n of this.criteria){let o=n(e,r);for(let a=0;a<s.length;++a)s[a]||=o[a]}return s}[Symbol.iterator](){return this.criteria.values()}},Vl=class extends nn{constructor(e,r=null){super(),this.max_length=e,this.max_position_embeddings=r}_call(e){return e.map(r=>r.length>=this.max_length)}},Hl=class extends nn{constructor(e){super(),Array.isArray(e)||(e=[e]),this.eos_token_id=e}_call(e,r){return e.map(s=>{let n=s.at(-1);return this.eos_token_id.some(o=>n==o)})}},JE=class extends nn{constructor(){super(),this.interrupted=!1}interrupt(){this.interrupted=!0}reset(){this.interrupted=!1}_call(e,r){return new Array(e.length).fill(this.interrupted)}};var _s=class extends Je{constructor(e){super(),this.generation_config=e}async _call(e){return this.sample(e)}async sample(e){throw Error("sample should be implemented in subclasses.")}getLogits(e,r){let s=e.dims.at(-1),n=e.data;if(r===-1)n=n.slice(-s);else{let o=r*s;n=n.slice(o,o+s)}return n}randomSelect(e){let r=0;for(let n=0;n<e.length;++n)r+=e[n];let s=Math.random()*r;for(let n=0;n<e.length;++n)if(s-=e[n],s<=0)return n;return 0}static getSampler(e){if(e.do_sample)return new Wm(e);if(e.num_beams>1)return new Vm(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new qm(e)}},qm=class extends _s{async sample(e){let r=Te(e.data)[1];return[[BigInt(r),0]]}},Wm=class extends _s{async sample(e){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let[s,n]=await Yt(e,r),o=Pe(s.data);return Array.from({length:this.generation_config.num_beams},()=>{let a=this.randomSelect(o);return[n.data[a],Math.log(o[a])]})}},Vm=class extends _s{async sample(e){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));let[s,n]=await Yt(e,r),o=Pe(s.data);return Array.from({length:this.generation_config.num_beams},(a,i)=>[n.data[i],Math.log(o[i])])}};var co=null;function eA(t){co=t}function Hm(t){if(t instanceof U)return t;if(t.length===0)throw Error("items must be non-empty");if(Array.isArray(t[0])){if(t.some(e=>e.length!==t[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new U("int64",BigInt64Array.from(t.flat().map(e=>BigInt(e))),[t.length,t[0].length])}else return new U("int64",BigInt64Array.from(t.map(e=>BigInt(e))),[1,t.length])}function Xm(t){return new U("bool",[t],[1])}var H={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,DecoderOnlyWithoutHead:5,MaskGeneration:6,ImageTextToText:7,Musicgen:8,MultiModality:9,Phi3V:10,AudioTextToText:11,AutoEncoder:12,ImageAudioTextToText:13,Supertonic:14,Chatterbox:15},ZE={[H.DecoderOnly]:{can_generate:!0,forward:Tt,prepare_inputs:uo},[H.DecoderOnlyWithoutHead]:{can_generate:!1,forward:Tt,prepare_inputs:uo},[H.Seq2Seq]:{can_generate:!0,forward:Xl,prepare_inputs:po},[H.Vision2Seq]:{can_generate:!0,forward:Xl,prepare_inputs:po},[H.Musicgen]:{can_generate:!0,forward:Xl},[H.EncoderDecoder]:{can_generate:!1,forward:Xl},[H.ImageTextToText]:{can_generate:!0,forward:UP,prepare_inputs:Kl},[H.AudioTextToText]:{can_generate:!0,forward:RP,prepare_inputs:Kl},[H.Phi3V]:{can_generate:!0,prepare_inputs:Kl},[H.ImageAudioTextToText]:{can_generate:!0,prepare_inputs:Kl},[H.MultiModality]:{can_generate:!0},[H.AutoEncoder]:{can_generate:!1,forward:$P},[H.Chatterbox]:{can_generate:!0,forward:Gt},default:{can_generate:!1,forward:Gt}},ws=new Map,Yl=new Map,gs=new Map,y=class extends Je{main_input_name="input_ids";forward_params=["input_ids","attention_mask"];_return_dict_in_generate_keys=null;constructor(e,r,s){super(),this.config=e,this.sessions=r,this.configs=s;let n=gs.get(this.constructor),o=ws.get(n),a=ZE[o]??ZE.default;this.can_generate=a.can_generate,this._forward=a.forward,this._prepare_inputs_for_generation=a.prepare_inputs,this.can_generate&&this.forward_params.push("past_key_values"),this.custom_config=this.config["transformers.js_config"]??{}}async dispose(){let e=[];for(let r of Object.values(this.sessions))e.push(r.release?.());return await Promise.all(e)}static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",model_file_name:i=null,subfolder:l="onnx",device:u=null,dtype:d=null,use_external_data_format:f=null,session_options:m={}}={}){let _={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,model_file_name:i,subfolder:l,device:u,dtype:d,use_external_data_format:f,session_options:m},w=gs.get(this),x=ws.get(w);s=_.config=await ms.from_pretrained(e,_);let k;if(x===H.DecoderOnly)k=await Promise.all([bt(e,{model:_.model_file_name??"model"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Seq2Seq||x===H.Vision2Seq)k=await Promise.all([bt(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.MaskGeneration)k=await Promise.all([bt(e,{model:"vision_encoder",prompt_encoder_mask_decoder:"prompt_encoder_mask_decoder"},_)]);else if(x===H.EncoderDecoder)k=await Promise.all([bt(e,{model:"encoder_model",decoder_model_merged:"decoder_model_merged"},_,"decoder_model_merged")]);else if(x===H.ImageTextToText){let E={embed_tokens:"embed_tokens",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};s.is_encoder_decoder&&(E.model="encoder_model"),k=await Promise.all([bt(e,E,_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.AudioTextToText){let E={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",decoder_model_merged:"decoder_model_merged"};k=await Promise.all([bt(e,E,_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.ImageAudioTextToText){let E={embed_tokens:"embed_tokens",audio_encoder:"audio_encoder",vision_encoder:"vision_encoder",decoder_model_merged:"decoder_model_merged"};k=await Promise.all([bt(e,E,_),gr(e,{generation_config:"generation_config.json"},_)])}else if(x===H.Musicgen)k=await Promise.all([bt(e,{model:"text_encoder",decoder_model_merged:"decoder_model_merged",encodec_decode:"encodec_decode"},_,"decoder_model_merged"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.MultiModality)k=await Promise.all([bt(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"language_model",lm_head:"lm_head",gen_head:"gen_head",gen_img_embeds:"gen_img_embeds",image_decode:"image_decode"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Phi3V)k=await Promise.all([bt(e,{prepare_inputs_embeds:"prepare_inputs_embeds",model:"model",vision_encoder:"vision_encoder"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.Chatterbox)k=await Promise.all([bt(e,{embed_tokens:"embed_tokens",speech_encoder:"speech_encoder",model:"language_model",conditional_decoder:"conditional_decoder"},_,"model"),gr(e,{generation_config:"generation_config.json"},_)]);else if(x===H.AutoEncoder)k=await Promise.all([bt(e,{encoder_model:"encoder_model",decoder_model:"decoder_model"},_)]);else if(x===H.Supertonic)k=await Promise.all([bt(e,{text_encoder:"text_encoder",latent_denoiser:"latent_denoiser",voice_decoder:"voice_decoder"},_)]);else{if(x===void 0){let E=w??s?.model_type;E!=="custom"&&console.warn(`Model type for '${E}' not found, assuming encoder-only architecture. Please report this at ${Hs}.`)}k=await Promise.all([bt(e,{model:_.model_file_name??"model"},_)])}return new this(s,...k)}async _call(e){return await this.forward(e)}async forward(e){return await this._forward(this,e)}get generation_config(){return this.configs?.generation_config??null}_get_logits_processor(e,r,s=null){let n=new hs;if(e.repetition_penalty!==null&&e.repetition_penalty!==1&&n.push(new Bl(e.repetition_penalty)),e.no_repeat_ngram_size!==null&&e.no_repeat_ngram_size>0&&n.push(new Ul(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&n.push(new jl(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&n.push(new Dl(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&n.push(new Fl(r,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&n.push(new Nl(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&n.push(new $l(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let o=r>1||e.forced_bos_token_id===null?r:r+1;n.push(new rn(e.begin_suppress_tokens,o))}return e.guidance_scale!==null&&e.guidance_scale>1&&n.push(new Gl(e.guidance_scale)),e.temperature===0&&e.do_sample&&(console.warn("`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`."),e.do_sample=!1),e.do_sample&&e.temperature!==null&&e.temperature!==1&&n.push(new ql(e.temperature)),s!==null&&n.extend(s),n}_prepare_generation_config(e,r,s=sn){let n={...this.config};for(let a of["decoder","generator","text_config"])a in n&&Object.assign(n,n[a]);let o=new s(n);return Object.assign(o,this.generation_config??{}),e&&Object.assign(o,e),r&&Object.assign(o,ot(r,Object.getOwnPropertyNames(o))),o}_get_stopping_criteria(e,r=null){let s=new Wl;return e.max_length!==null&&s.push(new Vl(e.max_length,this.config.max_position_embeddings??null)),e.eos_token_id!==null&&s.push(new Hl(e.eos_token_id)),r&&s.extend(r),s}_validate_model_class(){if(!this.can_generate){let e=[co.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES,co.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,co.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,co.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES].filter(Boolean),r=gs.get(this.constructor),s=new Set,n=this.config.model_type;for(let a of e){let i=a?.get(n);i&&s.add(i)}let o=`The current model class (${r}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;throw s.size>0&&(o+=` Please use the following class instead: ${[...s].join(", ")}`),Error(o)}}prepare_inputs_for_generation(...e){if(!this._prepare_inputs_for_generation)throw new Error("prepare_inputs_for_generation is not implemented for this model.");return this._prepare_inputs_for_generation(this,...e)}_update_model_kwargs_for_generation({generated_input_ids:e,outputs:r,model_inputs:s,is_encoder_decoder:n}){return s.past_key_values=this.getPastKeyValues(r,s.past_key_values),s.input_ids=new U("int64",e.flat(),[e.length,1]),n?"decoder_attention_mask"in s:s.attention_mask=Ee([s.attention_mask,it([s.attention_mask.dims[0],1])],1),s.position_ids=null,s}_prepare_model_inputs({inputs:e,bos_token_id:r,model_kwargs:s}){let n=ot(s,this.forward_params),o=this.main_input_name;if(o in n){if(e)throw new Error("`inputs`: {inputs}` were passed alongside {input_name} which is not allowed. Make sure to either pass {inputs} or {input_name}=...")}else n[o]=e;return{inputs_tensor:n[o],model_inputs:n,model_input_name:o}}async _prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:e,model_inputs:r,model_input_name:s,generation_config:n}){if(this.sessions.model.inputNames.includes("inputs_embeds")&&!r.inputs_embeds&&"_prepare_inputs_embeds"in this){let{input_ids:a,pixel_values:i,attention_mask:l,...u}=r,d=await this._prepare_inputs_embeds(r);r={...u,...ot(d,["inputs_embeds","attention_mask"])}}let{last_hidden_state:o}=await Gt(this,r);if(n.guidance_scale!==null&&n.guidance_scale>1)o=Ee([o,Qn(o,0)],0),"attention_mask"in r&&(r.attention_mask=Ee([r.attention_mask,kd(r.attention_mask)],0));else if(r.decoder_input_ids){let a=Hm(r.decoder_input_ids).dims[0];if(a!==o.dims[0]){if(o.dims[0]!==1)throw new Error(`The encoder outputs have a different batch size (${o.dims[0]}) than the decoder inputs (${a}).`);o=Ee(Array.from({length:a},()=>o),0)}}return r.encoder_outputs=o,r}_prepare_decoder_input_ids_for_generation({batch_size:e,model_input_name:r,model_kwargs:s,decoder_start_token_id:n,bos_token_id:o,generation_config:a}){let{decoder_input_ids:i,...l}=s;if(!(i instanceof U)){if(i)Array.isArray(i[0])||(i=Array.from({length:e},()=>i));else if(n??=o,this.config.model_type==="musicgen")i=Array.from({length:e*this.config.decoder.num_codebooks},()=>[n]);else if(Array.isArray(n)){if(n.length!==e)throw new Error(`\`decoder_start_token_id\` expcted to have length ${e} but got ${n.length}`);i=n}else i=Array.from({length:e},()=>[n]);i=Hm(i)}return s.decoder_attention_mask=il(i),{input_ids:i,model_inputs:l}}async generate({inputs:e=null,generation_config:r=null,logits_processor:s=null,stopping_criteria:n=null,streamer:o=null,...a}){this._validate_model_class(),r=this._prepare_generation_config(r,a);let{inputs_tensor:i,model_inputs:l,model_input_name:u}=this._prepare_model_inputs({inputs:e,model_kwargs:a}),d=this.config.is_encoder_decoder;d&&("encoder_outputs"in l||(l=await this._prepare_encoder_decoder_kwargs_for_generation({inputs_tensor:i,model_inputs:l,model_input_name:u,generation_config:r})));let f;d?{input_ids:f,model_inputs:l}=this._prepare_decoder_input_ids_for_generation({batch_size:l[u].dims.at(0),model_input_name:u,model_kwargs:l,decoder_start_token_id:r.decoder_start_token_id,bos_token_id:r.bos_token_id,generation_config:r}):f=l[u];let m=f.dims.at(-1);r.max_new_tokens!==null&&(r.max_length=m+r.max_new_tokens);let _=this._get_logits_processor(r,m,s),w=this._get_stopping_criteria(r,n),x=l[u].dims.at(0),k=_s.getSampler(r),E=new Array(x).fill(0),M=f.tolist();o&&o.put(M);let I,T={},z={};for(;;){if(l=this.prepare_inputs_for_generation(M,l,r),I=await this.forward(l),r.return_dict_in_generate)if(r.output_attentions){let K=this.getAttentions(I);for(let Y in K)Y in T||(T[Y]=[]),T[Y].push(K[Y])}else this._return_dict_in_generate_keys&&Object.assign(z,ot(I,this._return_dict_in_generate_keys));let G=I.logits.slice(null,-1,null).to("float32"),X=_(M,G),V=[];for(let K=0;K<X.dims.at(0);++K){let Y=X[K],B=await k(Y);for(let[P,se]of B){let ie=BigInt(P);E[K]+=se,M[K].push(ie),V.push([ie]);break}}if(o&&o.put(V),w(M).every(K=>K))break;l=this._update_model_kwargs_for_generation({generated_input_ids:V,outputs:I,model_inputs:l,is_encoder_decoder:d})}o&&o.end();let C=this.getPastKeyValues(I,l.past_key_values,!0),v=new U("int64",M.flat(),[M.length,M[0].length]);if(r.return_dict_in_generate)return{sequences:v,past_key_values:C,...T,...z};for(let G of Object.values(I))G.location==="gpu-buffer"&&G.dispose();return v}getPastKeyValues(e,r,s=!1){let n=Object.create(null);for(let o in e)if(o.startsWith("present")){let a=o.replace("present_ssm","past_ssm").replace("present_conv","past_conv").replace("present","past_key_values"),i=o.includes("encoder");if(i&&r?n[a]=r[a]:n[a]=e[o],r&&(!i||s)){let l=r[a];l.location==="gpu-buffer"&&l.dispose()}}return n}getAttentions(e){let r={};for(let s of["cross_attentions","encoder_attentions","decoder_attentions"])for(let n in e)n.startsWith(s)&&(s in r||(r[s]=[]),r[s].push(e[n]));return r}addPastKeyValues(e,r){if(r)Object.assign(e,r);else{let s=this.sessions.decoder_model_merged??this.sessions.model,n=(e[this.main_input_name]??e.attention_mask)?.dims?.[0]??1,o=s?.config?.kv_cache_dtype??"float32",a=o==="float16"?Ws.float16:Ws.float32,i=zl(this.config,{batch_size:n});for(let l in i){let u=i[l].reduce((d,f)=>d*f,1);e[l]=new U(o,new a(u),i[l])}}}async encode_image({pixel_values:e}){return(await ce(this.sessions.vision_encoder,{pixel_values:e})).image_features}async encode_text({input_ids:e}){return(await ce(this.sessions.embed_tokens,{input_ids:e})).inputs_embeds}async encode_audio({audio_values:e}){return(await ce(this.sessions.audio_encoder,{audio_values:e})).audio_features}};async function Xl(t,e){let{encoder_outputs:r,input_ids:s,decoder_input_ids:n,...o}=e;if(!r){let a=ot(e,t.sessions.model.inputNames);r=(await Gt(t,a)).last_hidden_state}return o.input_ids=n,o.encoder_hidden_states=r,t.sessions.decoder_model_merged.inputNames.includes("encoder_attention_mask")&&(o.encoder_attention_mask=e.attention_mask),await Tt(t,o,!0)}async function Gt(t,e){let r=t.sessions.model,s=ot(e,r.inputNames);if(r.inputNames.includes("inputs_embeds")&&!s.inputs_embeds){if(!e.input_ids)throw new Error("Both `input_ids` and `inputs_embeds` are missing in the model inputs.");s.inputs_embeds=await t.encode_text({input_ids:e.input_ids})}if(r.inputNames.includes("token_type_ids")&&!s.token_type_ids){if(!s.input_ids)throw new Error("Both `input_ids` and `token_type_ids` are missing in the model inputs.");s.token_type_ids=kd(s.input_ids)}if(r.inputNames.includes("pixel_mask")&&!s.pixel_mask){if(!s.pixel_values)throw new Error("Both `pixel_values` and `pixel_mask` are missing in the model inputs.");let n=s.pixel_values.dims;s.pixel_mask=it([n[0],n[2],n[3]])}return await ce(r,s)}async function $P(t,e){let r=await t.encode(e);return await t.decode(r)}async function Tt(t,e,r=!1){let s=t.sessions[r?"decoder_model_merged":"model"],{past_key_values:n,...o}=e;if(s.inputNames.includes("use_cache_branch")&&(o.use_cache_branch=Xm(!!n)),s.inputNames.includes("position_ids")&&o.attention_mask&&!o.position_ids){let i=["paligemma","gemma3_text","gemma3"].includes(t.config.model_type)?1:0;o.position_ids=BP(o,n,i)}t.addPastKeyValues(o,n);let a=ot(o,s.inputNames);return await ce(s,a)}async function tA(t,{encode_function:e,merge_function:r,modality_input_name:s,modality_output_name:n,input_ids:o=null,attention_mask:a=null,position_ids:i=null,inputs_embeds:l=null,past_key_values:u=null,generation_config:d=null,logits_processor:f=null,...m}){let _=m[s];if(!l){if(l=await t.encode_text({input_ids:o,...m}),_&&o.dims[1]!==1){let x=await e({[s]:_,...m});({inputs_embeds:l,attention_mask:a}=r({[n]:x,inputs_embeds:l,input_ids:o,attention_mask:a}))}else if(u&&_&&o.dims[1]===1){let x=o.dims[1],k=Object.values(u)[0].dims.at(-2);a=Ee([it([o.dims[0],k]),a.slice(null,[a.dims[1]-x,a.dims[1]])],1)}}if(!i&&t.config.model_type==="qwen2_vl"){let{image_grid_thw:x,video_grid_thw:k}=m;[i]=t.get_rope_index(o,x,k,a)}return await Tt(t,{inputs_embeds:l,past_key_values:u,attention_mask:a,position_ids:i,generation_config:d,logits_processor:f},!0)}async function RP(t,e){return await tA(t,{...e,modality_input_name:"audio_values",modality_output_name:"audio_features",encode_function:t.encode_audio.bind(t),merge_function:t._merge_input_ids_with_audio_features.bind(t)})}async function UP(t,e){return await tA(t,{...e,modality_input_name:"pixel_values",modality_output_name:"image_features",encode_function:t.encode_image.bind(t),merge_function:t._merge_input_ids_with_image_features.bind(t)})}function Km(t,e=0){let[r,s]=t.dims,n=t.data,o=new BigInt64Array(n.length);for(let a=0;a<r;++a){let i=a*s,l=BigInt(e);for(let u=0;u<s;++u){let d=i+u;n[d]===0n?o[d]=BigInt(1):(o[d]=l,l+=n[d])}}return{data:o,dims:t.dims}}function BP(t,e=null,r=0){let{input_ids:s,inputs_embeds:n,attention_mask:o}=t,{data:a,dims:i}=Km(o,r),l=new U("int64",a,i);if(e){let u=-(s??n).dims.at(1);l=l.slice(null,[u,null])}return l}function uo(t,e,r,s){let n=r.past_key_values?Object.values(r.past_key_values)[0].dims.at(-2):0;if(!r.attention_mask){let o;for(let a of["input_ids","inputs_embeds","position_ids"])if(r[a]){o=r[a].dims;break}if(!o)throw new Error("attention_mask is not provided, and unable to infer its shape from model inputs.");r.attention_mask=it([o[0],n+o[1]])}if(r.past_key_values){let{input_ids:o,attention_mask:a}=r;a&&a.dims[1]>o.dims[1]||n<o.dims[1]&&(r.input_ids=o.slice(null,[n,null]))}return r}function po(t,e,r,s){return r.past_key_values&&(e=e.map(n=>[n.at(-1)])),{...r,decoder_input_ids:Hm(e)}}function Kl(t,...e){return t.config.is_encoder_decoder?po(t,...e):uo(t,...e)}function rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n}){let o=s.tolist().map(u=>u.reduce((d,f,m)=>(f==t&&d.push(m),d),[])),a=o.reduce((u,d)=>u+d.length,0),i=r.dims[0];if(a!==i)throw new Error(`Number of tokens and features do not match: tokens: ${a}, features ${i}`);let l=0;for(let u=0;u<o.length;++u){let d=o[u],f=e[u];for(let m=0;m<d.length;++m)f[d[m]].data.set(r[l++].data)}return{inputs_embeds:e,attention_mask:n}}function ar({image_token_id:t,inputs_embeds:e,image_features:r,input_ids:s,attention_mask:n}){return rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n})}function Ql({audio_token_id:t,inputs_embeds:e,audio_features:r,input_ids:s,attention_mask:n}){return rA({modality_token_id:t,inputs_embeds:e,modality_features:r,input_ids:s,attention_mask:n})}async function gr(t,e,r){return Object.fromEntries(await Promise.all(Object.keys(e).map(async s=>{let n=await at(t,e[s],!1,r);return[s,n]})))}var di={};Ps(di,{ASTForAudioClassification:()=>oh,ASTModel:()=>nh,ASTPreTrainedModel:()=>ho,AlbertForMaskedLM:()=>Zm,AlbertForQuestionAnswering:()=>Jm,AlbertForSequenceClassification:()=>Qm,AlbertModel:()=>Ym,AlbertPreTrainedModel:()=>xs,ApertusForCausalLM:()=>th,ApertusModel:()=>eh,ApertusPreTrainedModel:()=>fo,ArceeForCausalLM:()=>sh,ArceeModel:()=>rh,ArceePreTrainedModel:()=>mo,BartForConditionalGeneration:()=>ih,BartForSequenceClassification:()=>lh,BartModel:()=>ah,BartPretrainedModel:()=>on,BeitForImageClassification:()=>uh,BeitModel:()=>ch,BeitPreTrainedModel:()=>_o,BertForMaskedLM:()=>dh,BertForQuestionAnswering:()=>hh,BertForSequenceClassification:()=>fh,BertForTokenClassification:()=>mh,BertModel:()=>ph,BertPreTrainedModel:()=>Cr,BlenderbotForConditionalGeneration:()=>gh,BlenderbotModel:()=>_h,BlenderbotPreTrainedModel:()=>go,BlenderbotSmallForConditionalGeneration:()=>xh,BlenderbotSmallModel:()=>wh,BlenderbotSmallPreTrainedModel:()=>wo,BloomForCausalLM:()=>bh,BloomModel:()=>yh,BloomPreTrainedModel:()=>xo,CLIPModel:()=>Oh,CLIPPreTrainedModel:()=>ir,CLIPSegForImageSegmentation:()=>Lh,CLIPSegModel:()=>zh,CLIPSegPreTrainedModel:()=>Eo,CLIPTextModel:()=>Ih,CLIPTextModelWithProjection:()=>ko,CLIPVisionModel:()=>Ch,CLIPVisionModelWithProjection:()=>Ph,CamembertForMaskedLM:()=>kh,CamembertForQuestionAnswering:()=>Mh,CamembertForSequenceClassification:()=>Eh,CamembertForTokenClassification:()=>Ah,CamembertModel:()=>vh,CamembertPreTrainedModel:()=>Pr,ChatterboxModel:()=>yo,ChatterboxPreTrainedModel:()=>Jl,ChineseCLIPModel:()=>Th,ChineseCLIPPreTrainedModel:()=>Zl,ClapAudioModelWithProjection:()=>vo,ClapModel:()=>Sh,ClapPreTrainedModel:()=>an,ClapTextModelWithProjection:()=>bo,CodeGenForCausalLM:()=>$h,CodeGenModel:()=>Nh,CodeGenPreTrainedModel:()=>Ao,CohereForCausalLM:()=>Uh,CohereModel:()=>Rh,CoherePreTrainedModel:()=>Mo,ConvBertForMaskedLM:()=>Dh,ConvBertForQuestionAnswering:()=>Gh,ConvBertForSequenceClassification:()=>Fh,ConvBertForTokenClassification:()=>jh,ConvBertModel:()=>Bh,ConvBertPreTrainedModel:()=>zr,ConvNextForImageClassification:()=>Wh,ConvNextModel:()=>qh,ConvNextPreTrainedModel:()=>To,ConvNextV2ForImageClassification:()=>Hh,ConvNextV2Model:()=>Vh,ConvNextV2PreTrainedModel:()=>So,DFineForObjectDetection:()=>Qh,DFineModel:()=>Yh,DFinePreTrainedModel:()=>Io,DINOv3ConvNextModel:()=>b_,DINOv3ConvNextPreTrainedModel:()=>ac,DINOv3ViTModel:()=>v_,DINOv3ViTPreTrainedModel:()=>ic,DPTForDepthEstimation:()=>I_,DPTModel:()=>O_,DPTPreTrainedModel:()=>$o,DacDecoderModel:()=>Po,DacDecoderOutput:()=>tc,DacEncoderModel:()=>Co,DacEncoderOutput:()=>ec,DacModel:()=>Jh,DacPreTrainedModel:()=>ln,DebertaForMaskedLM:()=>e_,DebertaForQuestionAnswering:()=>s_,DebertaForSequenceClassification:()=>t_,DebertaForTokenClassification:()=>r_,DebertaModel:()=>Zh,DebertaPreTrainedModel:()=>Lr,DebertaV2ForMaskedLM:()=>o_,DebertaV2ForQuestionAnswering:()=>l_,DebertaV2ForSequenceClassification:()=>a_,DebertaV2ForTokenClassification:()=>i_,DebertaV2Model:()=>n_,DebertaV2PreTrainedModel:()=>Nr,DecisionTransformerModel:()=>c_,DecisionTransformerPreTrainedModel:()=>rc,DeiTForImageClassification:()=>p_,DeiTModel:()=>u_,DeiTPreTrainedModel:()=>zo,DepthAnythingForDepthEstimation:()=>d_,DepthAnythingPreTrainedModel:()=>sc,DepthProForDepthEstimation:()=>f_,DepthProPreTrainedModel:()=>nc,DetrForObjectDetection:()=>h_,DetrForSegmentation:()=>__,DetrModel:()=>m_,DetrObjectDetectionOutput:()=>un,DetrPreTrainedModel:()=>cn,DetrSegmentationOutput:()=>oc,Dinov2ForImageClassification:()=>w_,Dinov2Model:()=>g_,Dinov2PreTrainedModel:()=>Lo,Dinov2WithRegistersForImageClassification:()=>y_,Dinov2WithRegistersModel:()=>x_,Dinov2WithRegistersPreTrainedModel:()=>No,DistilBertForMaskedLM:()=>T_,DistilBertForQuestionAnswering:()=>M_,DistilBertForSequenceClassification:()=>E_,DistilBertForTokenClassification:()=>A_,DistilBertModel:()=>k_,DistilBertPreTrainedModel:()=>$r,DonutSwinModel:()=>S_,DonutSwinPreTrainedModel:()=>lc,EdgeTamModel:()=>fy,EfficientNetForImageClassification:()=>P_,EfficientNetModel:()=>C_,EfficientNetPreTrainedModel:()=>Ro,ElectraForMaskedLM:()=>L_,ElectraForQuestionAnswering:()=>R_,ElectraForSequenceClassification:()=>N_,ElectraForTokenClassification:()=>$_,ElectraModel:()=>z_,ElectraPreTrainedModel:()=>Rr,Ernie4_5ForCausalLM:()=>B_,Ernie4_5Model:()=>U_,Ernie4_5PretrainedModel:()=>Uo,EsmForMaskedLM:()=>F_,EsmForSequenceClassification:()=>j_,EsmForTokenClassification:()=>G_,EsmModel:()=>D_,EsmPreTrainedModel:()=>ys,ExaoneForCausalLM:()=>W_,ExaoneModel:()=>q_,ExaonePreTrainedModel:()=>Bo,FalconForCausalLM:()=>H_,FalconH1ForCausalLM:()=>K_,FalconH1Model:()=>X_,FalconH1PreTrainedModel:()=>Fo,FalconModel:()=>V_,FalconPreTrainedModel:()=>Do,FastViTForImageClassification:()=>Q_,FastViTModel:()=>Y_,FastViTPreTrainedModel:()=>jo,Florence2ForConditionalGeneration:()=>J_,Florence2PreTrainedModel:()=>cc,GLPNForDepthEstimation:()=>lg,GLPNModel:()=>ig,GLPNPreTrainedModel:()=>Xo,GPT2LMHeadModel:()=>wg,GPT2Model:()=>gg,GPT2PreTrainedModel:()=>Zo,GPTBigCodeForCausalLM:()=>ug,GPTBigCodeModel:()=>cg,GPTBigCodePreTrainedModel:()=>Ko,GPTJForCausalLM:()=>yg,GPTJModel:()=>xg,GPTJPreTrainedModel:()=>ea,GPTNeoForCausalLM:()=>dg,GPTNeoModel:()=>pg,GPTNeoPreTrainedModel:()=>Yo,GPTNeoXForCausalLM:()=>mg,GPTNeoXModel:()=>fg,GPTNeoXPreTrainedModel:()=>Qo,Gemma2ForCausalLM:()=>rg,Gemma2Model:()=>tg,Gemma2PreTrainedModel:()=>qo,Gemma3ForCausalLM:()=>ng,Gemma3Model:()=>sg,Gemma3PreTrainedModel:()=>Wo,Gemma3nForConditionalGeneration:()=>Vo,Gemma3nPreTrainedModel:()=>uc,GemmaForCausalLM:()=>eg,GemmaModel:()=>Z_,GemmaPreTrainedModel:()=>Go,GlmForCausalLM:()=>ag,GlmModel:()=>og,GlmPreTrainedModel:()=>Ho,GptOssForCausalLM:()=>_g,GptOssModel:()=>hg,GptOssPreTrainedModel:()=>Jo,GraniteForCausalLM:()=>vg,GraniteModel:()=>bg,GraniteMoeHybridForCausalLM:()=>Eg,GraniteMoeHybridModel:()=>kg,GraniteMoeHybridPreTrainedModel:()=>ra,GranitePreTrainedModel:()=>ta,GroundingDinoForObjectDetection:()=>Ag,GroundingDinoPreTrainedModel:()=>pc,GroupViTModel:()=>Mg,GroupViTPreTrainedModel:()=>dc,HeliumForCausalLM:()=>Sg,HeliumModel:()=>Tg,HeliumPreTrainedModel:()=>sa,HieraForImageClassification:()=>Ig,HieraModel:()=>Og,HieraPreTrainedModel:()=>na,HubertForCTC:()=>Rg,HubertForSequenceClassification:()=>Ug,HubertModel:()=>$g,HubertPreTrainedModel:()=>Ng,HunYuanDenseV1ForCausalLM:()=>Dg,HunYuanDenseV1Model:()=>Bg,HunYuanDenseV1PreTrainedModel:()=>oa,IJepaForImageClassification:()=>Gg,IJepaModel:()=>jg,IJepaPreTrainedModel:()=>aa,Idefics3ForConditionalGeneration:()=>mc,Idefics3PreTrainedModel:()=>fc,JAISLMHeadModel:()=>Wg,JAISModel:()=>qg,JAISPreTrainedModel:()=>ia,JinaCLIPModel:()=>Vg,JinaCLIPPreTrainedModel:()=>pn,JinaCLIPTextModel:()=>la,JinaCLIPVisionModel:()=>Hg,Lfm2ForCausalLM:()=>Kg,Lfm2Model:()=>Xg,Lfm2MoeForCausalLM:()=>Qg,Lfm2MoeModel:()=>Yg,Lfm2MoePreTrainedModel:()=>ua,Lfm2PreTrainedModel:()=>ca,LiteWhisperForConditionalGeneration:()=>E0,Llama4ForCausalLM:()=>ew,Llama4PreTrainedModel:()=>hc,LlamaForCausalLM:()=>Zg,LlamaModel:()=>Jg,LlamaPreTrainedModel:()=>pa,LlavaForConditionalGeneration:()=>dn,LlavaOnevisionForConditionalGeneration:()=>dn,LlavaPreTrainedModel:()=>_c,LlavaQwen2ForCausalLM:()=>rw,LongT5ForConditionalGeneration:()=>nw,LongT5Model:()=>sw,LongT5PreTrainedModel:()=>da,M2M100ForConditionalGeneration:()=>aw,M2M100Model:()=>ow,M2M100PreTrainedModel:()=>fa,MBartForCausalLM:()=>mw,MBartForConditionalGeneration:()=>dw,MBartForSequenceClassification:()=>fw,MBartModel:()=>pw,MBartPreTrainedModel:()=>bs,MPNetForMaskedLM:()=>Jw,MPNetForQuestionAnswering:()=>tx,MPNetForSequenceClassification:()=>Zw,MPNetForTokenClassification:()=>ex,MPNetModel:()=>Qw,MPNetPreTrainedModel:()=>Ur,MT5ForConditionalGeneration:()=>ox,MT5Model:()=>nx,MT5PreTrainedModel:()=>Aa,MarianMTModel:()=>lw,MarianModel:()=>iw,MarianPreTrainedModel:()=>ma,MaskFormerForInstanceSegmentation:()=>uw,MaskFormerModel:()=>cw,MaskFormerPreTrainedModel:()=>ha,Metric3DForDepthEstimation:()=>hw,Metric3DPreTrainedModel:()=>gc,Metric3Dv2ForDepthEstimation:()=>_w,Metric3Dv2PreTrainedModel:()=>wc,MgpstrForSceneTextRecognition:()=>gw,MgpstrModelOutput:()=>xc,MgpstrPreTrainedModel:()=>yc,MimiDecoderModel:()=>ga,MimiDecoderOutput:()=>vc,MimiEncoderModel:()=>_a,MimiEncoderOutput:()=>bc,MimiModel:()=>ww,MimiPreTrainedModel:()=>fn,MistralForCausalLM:()=>yw,MistralModel:()=>xw,MistralPreTrainedModel:()=>wa,MobileBertForMaskedLM:()=>vw,MobileBertForQuestionAnswering:()=>Ew,MobileBertForSequenceClassification:()=>kw,MobileBertModel:()=>bw,MobileBertPreTrainedModel:()=>vs,MobileLLMForCausalLM:()=>Mw,MobileLLMModel:()=>Aw,MobileLLMPreTrainedModel:()=>xa,MobileNetV1ForImageClassification:()=>Sw,MobileNetV1ForSemanticSegmentation:()=>Ow,MobileNetV1Model:()=>Tw,MobileNetV1PreTrainedModel:()=>mn,MobileNetV2ForImageClassification:()=>Cw,MobileNetV2ForSemanticSegmentation:()=>Pw,MobileNetV2Model:()=>Iw,MobileNetV2PreTrainedModel:()=>hn,MobileNetV3ForImageClassification:()=>Lw,MobileNetV3ForSemanticSegmentation:()=>Nw,MobileNetV3Model:()=>zw,MobileNetV3PreTrainedModel:()=>_n,MobileNetV4ForImageClassification:()=>Rw,MobileNetV4ForSemanticSegmentation:()=>Uw,MobileNetV4Model:()=>$w,MobileNetV4PreTrainedModel:()=>gn,MobileViTForImageClassification:()=>Dw,MobileViTModel:()=>Bw,MobileViTPreTrainedModel:()=>ya,MobileViTV2ForImageClassification:()=>jw,MobileViTV2Model:()=>Fw,MobileViTV2PreTrainedModel:()=>ba,ModernBertDecoderForCausalLM:()=>Xw,ModernBertDecoderModel:()=>Hw,ModernBertDecoderPreTrainedModel:()=>va,ModernBertForMaskedLM:()=>qw,ModernBertForSequenceClassification:()=>Ww,ModernBertForTokenClassification:()=>Vw,ModernBertModel:()=>Gw,ModernBertPreTrainedModel:()=>ks,Moondream1ForConditionalGeneration:()=>tw,MoonshineForConditionalGeneration:()=>Yw,MoonshineModel:()=>Kw,MoonshinePreTrainedModel:()=>ka,MptForCausalLM:()=>sx,MptModel:()=>rx,MptPreTrainedModel:()=>Ea,MultiModalityCausalLM:()=>ax,MultiModalityPreTrainedModel:()=>kc,MusicgenForCausalLM:()=>lx,MusicgenForConditionalGeneration:()=>Ta,MusicgenModel:()=>ix,MusicgenPreTrainedModel:()=>Ma,NanoChatForCausalLM:()=>ux,NanoChatModel:()=>cx,NanoChatPreTrainedModel:()=>Sa,NeoBertForMaskedLM:()=>dx,NeoBertForQuestionAnswering:()=>hx,NeoBertForSequenceClassification:()=>fx,NeoBertForTokenClassification:()=>mx,NeoBertModel:()=>px,NeoBertPreTrainedModel:()=>Br,NomicBertModel:()=>_x,NomicBertPreTrainedModel:()=>Ec,OPTForCausalLM:()=>Mx,OPTModel:()=>Ax,OPTPreTrainedModel:()=>za,Olmo2ForCausalLM:()=>yx,Olmo2Model:()=>xx,Olmo2PreTrainedModel:()=>Ia,Olmo3ForCausalLM:()=>vx,Olmo3Model:()=>bx,Olmo3PreTrainedModel:()=>Ca,OlmoForCausalLM:()=>wx,OlmoModel:()=>gx,OlmoPreTrainedModel:()=>Oa,OpenELMForCausalLM:()=>Ex,OpenELMModel:()=>kx,OpenELMPreTrainedModel:()=>Pa,OwlViTForObjectDetection:()=>Ix,OwlViTModel:()=>Ox,OwlViTPreTrainedModel:()=>Na,Owlv2ForObjectDetection:()=>Sx,Owlv2Model:()=>Tx,Owlv2PreTrainedModel:()=>La,PaliGemmaForConditionalGeneration:()=>Cx,PaliGemmaPreTrainedModel:()=>Ac,ParakeetForCTC:()=>Px,ParakeetPreTrainedModel:()=>Mc,PatchTSMixerForPrediction:()=>Lx,PatchTSMixerModel:()=>zx,PatchTSMixerPreTrainedModel:()=>$a,PatchTSTForPrediction:()=>$x,PatchTSTModel:()=>Nx,PatchTSTPreTrainedModel:()=>Ra,Phi3ForCausalLM:()=>Dx,Phi3Model:()=>Bx,Phi3PreTrainedModel:()=>Ba,Phi3VForCausalLM:()=>Da,Phi3VPreTrainedModel:()=>Tc,PhiForCausalLM:()=>Ux,PhiModel:()=>Rx,PhiPreTrainedModel:()=>Ua,PreTrainedModel:()=>y,PvtForImageClassification:()=>jx,PvtModel:()=>Fx,PvtPreTrainedModel:()=>Fa,PyAnnoteForAudioFrameClassification:()=>qx,PyAnnoteModel:()=>Gx,PyAnnotePreTrainedModel:()=>ja,Qwen2ForCausalLM:()=>Vx,Qwen2Model:()=>Wx,Qwen2PreTrainedModel:()=>Ga,Qwen2VLForConditionalGeneration:()=>Hx,Qwen2VLPreTrainedModel:()=>Sc,Qwen3ForCausalLM:()=>Kx,Qwen3Model:()=>Xx,Qwen3PreTrainedModel:()=>qa,RFDetrForObjectDetection:()=>Zx,RFDetrModel:()=>Jx,RFDetrObjectDetectionOutput:()=>Oc,RFDetrPreTrainedModel:()=>Va,RTDetrForObjectDetection:()=>Kh,RTDetrModel:()=>Xh,RTDetrObjectDetectionOutput:()=>lr,RTDetrPreTrainedModel:()=>Oo,RTDetrV2ForObjectDetection:()=>py,RTDetrV2Model:()=>uy,RTDetrV2ObjectDetectionOutput:()=>Ic,RTDetrV2PreTrainedModel:()=>Ha,ResNetForImageClassification:()=>Qx,ResNetModel:()=>Yx,ResNetPreTrainedModel:()=>Wa,RoFormerForMaskedLM:()=>ay,RoFormerForQuestionAnswering:()=>cy,RoFormerForSequenceClassification:()=>iy,RoFormerForTokenClassification:()=>ly,RoFormerModel:()=>oy,RoFormerPreTrainedModel:()=>Fr,RobertaForMaskedLM:()=>ty,RobertaForQuestionAnswering:()=>ny,RobertaForSequenceClassification:()=>ry,RobertaForTokenClassification:()=>sy,RobertaModel:()=>ey,RobertaPreTrainedModel:()=>Dr,Sam2ImageSegmentationOutput:()=>zc,Sam2Model:()=>Xa,Sam2PreTrainedModel:()=>Lc,Sam3TrackerModel:()=>my,SamImageSegmentationOutput:()=>Cc,SamModel:()=>dy,SamPreTrainedModel:()=>Pc,SapiensForDepthEstimation:()=>_y,SapiensForNormalEstimation:()=>gy,SapiensForSemanticSegmentation:()=>hy,SapiensPreTrainedModel:()=>wn,SegformerForImageClassification:()=>xy,SegformerForSemanticSegmentation:()=>yy,SegformerModel:()=>wy,SegformerPreTrainedModel:()=>xn,SiglipModel:()=>by,SiglipPreTrainedModel:()=>Ka,SiglipTextModel:()=>Ya,SiglipVisionModel:()=>vy,SmolLM3ForCausalLM:()=>Ey,SmolLM3Model:()=>ky,SmolLM3PreTrainedModel:()=>Qa,SmolVLMForConditionalGeneration:()=>Fg,SnacDecoderModel:()=>Za,SnacEncoderModel:()=>Ja,SnacModel:()=>Ay,SnacPreTrainedModel:()=>yn,SpeechT5ForSpeechToText:()=>Ty,SpeechT5ForTextToSpeech:()=>Sy,SpeechT5HifiGan:()=>Oy,SpeechT5Model:()=>My,SpeechT5PreTrainedModel:()=>bn,SqueezeBertForMaskedLM:()=>Cy,SqueezeBertForQuestionAnswering:()=>zy,SqueezeBertForSequenceClassification:()=>Py,SqueezeBertModel:()=>Iy,SqueezeBertPreTrainedModel:()=>Es,StableLmForCausalLM:()=>Ny,StableLmModel:()=>Ly,StableLmPreTrainedModel:()=>ei,Starcoder2ForCausalLM:()=>Ry,Starcoder2Model:()=>$y,Starcoder2PreTrainedModel:()=>ti,StyleTextToSpeech2Model:()=>Uy,StyleTextToSpeech2PreTrainedModel:()=>Nc,SupertonicForConditionalGeneration:()=>ri,SupertonicPreTrainedModel:()=>$c,Swin2SRForImageSuperResolution:()=>Gy,Swin2SRModel:()=>jy,Swin2SRPreTrainedModel:()=>si,SwinForImageClassification:()=>Dy,SwinForSemanticSegmentation:()=>Fy,SwinModel:()=>By,SwinPreTrainedModel:()=>vn,T5ForConditionalGeneration:()=>Wy,T5Model:()=>qy,T5PreTrainedModel:()=>ni,TableTransformerForObjectDetection:()=>Hy,TableTransformerModel:()=>Vy,TableTransformerObjectDetectionOutput:()=>Rc,TableTransformerPreTrainedModel:()=>oi,TrOCRForCausalLM:()=>Xy,TrOCRPreTrainedModel:()=>Uc,UltravoxModel:()=>Dc,UltravoxPreTrainedModel:()=>Bc,UniSpeechForCTC:()=>Qy,UniSpeechForSequenceClassification:()=>Jy,UniSpeechModel:()=>Yy,UniSpeechPreTrainedModel:()=>kn,UniSpeechSatForAudioFrameClassification:()=>r0,UniSpeechSatForCTC:()=>e0,UniSpeechSatForSequenceClassification:()=>t0,UniSpeechSatModel:()=>Zy,UniSpeechSatPreTrainedModel:()=>As,VaultGemmaForCausalLM:()=>n0,VaultGemmaModel:()=>s0,VaultGemmaPreTrainedModel:()=>ai,ViTForImageClassification:()=>i0,ViTMAEModel:()=>l0,ViTMAEPreTrainedModel:()=>Fc,ViTMSNForImageClassification:()=>u0,ViTMSNModel:()=>c0,ViTMSNPreTrainedModel:()=>li,ViTModel:()=>a0,ViTPreTrainedModel:()=>ii,VisionEncoderDecoderModel:()=>o0,VitMatteForImageMatting:()=>p0,VitMattePreTrainedModel:()=>jc,VitPoseForPoseEstimation:()=>d0,VitPosePreTrainedModel:()=>Gc,VitsModel:()=>f0,VitsModelOutput:()=>qc,VitsPreTrainedModel:()=>Wc,VoxtralForConditionalGeneration:()=>Ky,Wav2Vec2BertForCTC:()=>h0,Wav2Vec2BertForSequenceClassification:()=>_0,Wav2Vec2BertModel:()=>m0,Wav2Vec2BertPreTrainedModel:()=>En,Wav2Vec2ForAudioFrameClassification:()=>Lg,Wav2Vec2ForCTC:()=>Pg,Wav2Vec2ForSequenceClassification:()=>zg,Wav2Vec2Model:()=>Cg,Wav2Vec2PreTrainedModel:()=>Jt,WavLMForAudioFrameClassification:()=>b0,WavLMForCTC:()=>w0,WavLMForSequenceClassification:()=>x0,WavLMForXVector:()=>y0,WavLMModel:()=>g0,WavLMPreTrainedModel:()=>jr,WeSpeakerResNetModel:()=>v0,WeSpeakerResNetPreTrainedModel:()=>Hc,WhisperForConditionalGeneration:()=>Kc,WhisperModel:()=>k0,WhisperPreTrainedModel:()=>ci,XLMForQuestionAnswering:()=>O0,XLMForSequenceClassification:()=>T0,XLMForTokenClassification:()=>S0,XLMModel:()=>A0,XLMPreTrainedModel:()=>Gr,XLMRobertaForMaskedLM:()=>C0,XLMRobertaForQuestionAnswering:()=>L0,XLMRobertaForSequenceClassification:()=>P0,XLMRobertaForTokenClassification:()=>z0,XLMRobertaModel:()=>I0,XLMRobertaPreTrainedModel:()=>qr,XLMWithLMHeadModel:()=>M0,XVectorOutput:()=>Vc,YolosForObjectDetection:()=>$0,YolosModel:()=>N0,YolosObjectDetectionOutput:()=>Yc,YolosPreTrainedModel:()=>ui,YoutuForCausalLM:()=>U0,YoutuModel:()=>R0,YoutuPreTrainedModel:()=>pi});var xs=class extends y{},Ym=class extends xs{},Qm=class extends xs{async _call(e){return new F(await super._call(e))}},Jm=class extends xs{async _call(e){return new Ae(await super._call(e))}},Zm=class extends xs{async _call(e){return new we(await super._call(e))}};var fo=class extends y{},eh=class extends fo{},th=class extends fo{};var mo=class extends y{},rh=class extends mo{},sh=class extends mo{};var ho=class extends y{},nh=class extends ho{},oh=class extends ho{};var on=class extends y{},ah=class extends on{},ih=class extends on{},lh=class extends on{async _call(e){return new F(await super._call(e))}};var _o=class extends y{},ch=class extends _o{},uh=class extends _o{async _call(e){return new F(await super._call(e))}};var Cr=class extends y{},ph=class extends Cr{},dh=class extends Cr{async _call(e){return new we(await super._call(e))}},fh=class extends Cr{async _call(e){return new F(await super._call(e))}},mh=class extends Cr{async _call(e){return new _e(await super._call(e))}},hh=class extends Cr{async _call(e){return new Ae(await super._call(e))}};var go=class extends y{},_h=class extends go{},gh=class extends go{};var wo=class extends y{},wh=class extends wo{},xh=class extends wo{};var xo=class extends y{},yh=class extends xo{},bh=class extends xo{};var Pr=class extends y{},vh=class extends Pr{},kh=class extends Pr{async _call(e){return new we(await super._call(e))}},Eh=class extends Pr{async _call(e){return new F(await super._call(e))}},Ah=class extends Pr{async _call(e){return new _e(await super._call(e))}},Mh=class extends Pr{async _call(e){return new Ae(await super._call(e))}};var DP=4299n,sA=6561n,Jl=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","audio_values","exaggeration","audio_features","audio_tokens","speaker_embeddings","speaker_features","past_key_values"];main_input_name="input_ids";_return_dict_in_generate_keys=["audio_tokens","speaker_embeddings","speaker_features"]},yo=class extends Jl{async encode_speech(e){return ce(this.sessions.speech_encoder,{audio_values:e})}async forward({input_ids:e=null,attention_mask:r=null,audio_values:s=null,exaggeration:n=null,position_ids:o=null,inputs_embeds:a=null,past_key_values:i=null,generation_config:l=null,logits_processor:u=null,audio_features:d=null,audio_tokens:f=null,speaker_embeddings:m=null,speaker_features:_=null,...w}){let x;if(!a){let E=this.sessions.embed_tokens.inputNames,M={input_ids:e};if(E.includes("exaggeration")){if(!(n instanceof U)){let I=e.dims[0];if(n==null)n=Ve([I],.5);else if(typeof n=="number")n=Ve([I],n);else if(Array.isArray(n))n=new U("float32",n,[I]);else throw new Error("Unsupported type for `exaggeration` input")}M.exaggeration=n}if(E.includes("position_ids")&&(M.position_ids=o),{inputs_embeds:a}=await ce(this.sessions.embed_tokens,M),d&&f&&m&&_&&(x={audio_features:d,audio_tokens:f,speaker_embeddings:m,speaker_features:_}),x||s)x??=await this.encode_speech(s),a=Ee([x.audio_features,a],1),r=it([a.dims[0],a.dims[1]]);else{let I=a.dims[1];if(!i||I!==1)throw new Error("Incorrect state encountered during generation.");let T=Object.values(i)[0].dims.at(-2);r=it([a.dims[0],T+I])}}return{...await Tt(this,{inputs_embeds:a,past_key_values:i,attention_mask:r,generation_config:l,logits_processor:u},!1),...x}}prepare_inputs_for_generation(e,r,s){if(!r.position_ids&&this.sessions.embed_tokens.inputNames.includes("position_ids"))if(r.input_ids.dims[1]===1){let n=Array.from({length:e.length},(o,a)=>e[a].length-e[a].findLastIndex(i=>i==sA)-1);r.position_ids=new U("int64",n,[e.length,1])}else{let o=r.input_ids.tolist().map(a=>{let i=0;return a.map(l=>l>=sA?0:i++)});r.position_ids=new U("int64",o.flat(),r.input_ids.dims)}return r.input_ids.dims[1]===1&&(delete r.audio_values,delete r.audio_features,delete r.audio_tokens,delete r.speaker_embeddings,delete r.speaker_features),uo(this,e,r,s)}async generate(e){let{sequences:r,audio_tokens:s,speaker_embeddings:n,speaker_features:o}=await super.generate({...e,return_dict_in_generate:!0}),a=r.slice(null,[e.input_ids.dims[1],-1]),i=Ve([a.dims[0],3],DP),l=Ee([s,a,i],1),{waveform:u}=await ce(this.sessions.conditional_decoder,{speech_tokens:l,speaker_features:o,speaker_embeddings:n});return u}};var Zl=class extends y{},Th=class extends Zl{};var an=class extends y{},Sh=class extends an{},bo=class extends an{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},vo=class extends an{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"audio_model"})}};var ir=class extends y{},Oh=class extends ir{},Ih=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},ko=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},Ch=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}},Ph=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var Eo=class extends y{},zh=class extends Eo{},Lh=class extends Eo{};var Ao=class extends y{},Nh=class extends Ao{},$h=class extends Ao{};var Mo=class extends y{},Rh=class extends Mo{},Uh=class extends Mo{};var zr=class extends y{},Bh=class extends zr{},Dh=class extends zr{async _call(e){return new we(await super._call(e))}},Fh=class extends zr{async _call(e){return new F(await super._call(e))}},jh=class extends zr{async _call(e){return new _e(await super._call(e))}},Gh=class extends zr{async _call(e){return new Ae(await super._call(e))}};var To=class extends y{},qh=class extends To{},Wh=class extends To{async _call(e){return new F(await super._call(e))}};var So=class extends y{},Vh=class extends So{},Hh=class extends So{async _call(e){return new F(await super._call(e))}};var Oo=class extends y{},Xh=class extends Oo{},Kh=class extends Oo{async _call(e){return new lr(await super._call(e))}},lr=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}};var Io=class extends y{},Yh=class extends Io{},Qh=class extends Io{async _call(e){return new lr(await super._call(e))}};var ec=class extends ze{constructor({audio_codes:e}){super(),this.audio_codes=e}},tc=class extends ze{constructor({audio_values:e}){super(),this.audio_values=e}},ln=class extends y{main_input_name="input_values";forward_params=["input_values"]},Jh=class extends ln{async encode(e){return new ec(await ce(this.sessions.encoder_model,e))}async decode(e){return new tc(await ce(this.sessions.decoder_model,e))}},Co=class extends ln{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},Po=class extends ln{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var Lr=class extends y{},Zh=class extends Lr{},e_=class extends Lr{async _call(e){return new we(await super._call(e))}},t_=class extends Lr{async _call(e){return new F(await super._call(e))}},r_=class extends Lr{async _call(e){return new _e(await super._call(e))}},s_=class extends Lr{async _call(e){return new Ae(await super._call(e))}};var Nr=class extends y{},n_=class extends Nr{},o_=class extends Nr{async _call(e){return new we(await super._call(e))}},a_=class extends Nr{async _call(e){return new F(await super._call(e))}},i_=class extends Nr{async _call(e){return new _e(await super._call(e))}},l_=class extends Nr{async _call(e){return new Ae(await super._call(e))}};var rc=class extends y{},c_=class extends rc{};var zo=class extends y{},u_=class extends zo{},p_=class extends zo{async _call(e){return new F(await super._call(e))}};var sc=class extends y{},d_=class extends sc{};var nc=class extends y{},f_=class extends nc{};var cn=class extends y{},m_=class extends cn{},h_=class extends cn{async _call(e){return new un(await super._call(e))}},__=class extends cn{async _call(e){return new oc(await super._call(e))}},un=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}},oc=class extends ze{constructor({logits:e,pred_boxes:r,pred_masks:s}){super(),this.logits=e,this.pred_boxes=r,this.pred_masks=s}};var Lo=class extends y{},g_=class extends Lo{},w_=class extends Lo{async _call(e){return new F(await super._call(e))}};var No=class extends y{},x_=class extends No{},y_=class extends No{async _call(e){return new F(await super._call(e))}};var ac=class extends y{},b_=class extends ac{};var ic=class extends y{},v_=class extends ic{};var $r=class extends y{},k_=class extends $r{},E_=class extends $r{async _call(e){return new F(await super._call(e))}},A_=class extends $r{async _call(e){return new _e(await super._call(e))}},M_=class extends $r{async _call(e){return new Ae(await super._call(e))}},T_=class extends $r{async _call(e){return new we(await super._call(e))}};var lc=class extends y{},S_=class extends lc{};var $o=class extends y{},O_=class extends $o{},I_=class extends $o{};var Ro=class extends y{},C_=class extends Ro{},P_=class extends Ro{async _call(e){return new F(await super._call(e))}};var Rr=class extends y{},z_=class extends Rr{},L_=class extends Rr{async _call(e){return new we(await super._call(e))}},N_=class extends Rr{async _call(e){return new F(await super._call(e))}},$_=class extends Rr{async _call(e){return new _e(await super._call(e))}},R_=class extends Rr{async _call(e){return new Ae(await super._call(e))}};var Uo=class extends y{},U_=class extends Uo{},B_=class extends Uo{};var ys=class extends y{},D_=class extends ys{},F_=class extends ys{async _call(e){return new we(await super._call(e))}},j_=class extends ys{async _call(e){return new F(await super._call(e))}},G_=class extends ys{async _call(e){return new _e(await super._call(e))}};var Bo=class extends y{},q_=class extends Bo{},W_=class extends Bo{};var Do=class extends y{},V_=class extends Do{},H_=class extends Do{};var Fo=class extends y{},X_=class extends Fo{},K_=class extends Fo{};var jo=class extends y{},Y_=class extends jo{},Q_=class extends jo{async _call(e){return new F(await super._call(e))}};var cc=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","pixel_values","encoder_outputs","decoder_input_ids","decoder_inputs_embeds","decoder_attention_mask","past_key_values"];main_input_name="inputs_embeds"},J_=class extends cc{_merge_input_ids_with_image_features({inputs_embeds:e,image_features:r,input_ids:s,attention_mask:n}){return{inputs_embeds:Ee([r,e],1),attention_mask:Ee([it(r.dims.slice(0,2)),n],1)}}async _prepare_inputs_embeds({input_ids:e,pixel_values:r,inputs_embeds:s,attention_mask:n}){if(!e&&!r)throw new Error("Either `input_ids` or `pixel_values` should be provided.");let o,a;return e&&(o=await this.encode_text({input_ids:e})),r&&(a=await this.encode_image({pixel_values:r})),o&&a?{inputs_embeds:s,attention_mask:n}=this._merge_input_ids_with_image_features({inputs_embeds:o,image_features:a,input_ids:e,attention_mask:n}):s=o||a,{inputs_embeds:s,attention_mask:n}}async forward({input_ids:e,pixel_values:r,attention_mask:s,decoder_input_ids:n,decoder_attention_mask:o,encoder_outputs:a,past_key_values:i,inputs_embeds:l,decoder_inputs_embeds:u}){if(l||({inputs_embeds:l,attention_mask:s}=await this._prepare_inputs_embeds({input_ids:e,pixel_values:r,inputs_embeds:l,attention_mask:s})),!a){let{last_hidden_state:f}=await Gt(this,{inputs_embeds:l,attention_mask:s});a=f}if(!u){if(!n)throw new Error("Either `decoder_input_ids` or `decoder_inputs_embeds` should be provided.");u=await this.encode_text({input_ids:n})}return await Tt(this,{inputs_embeds:u,attention_mask:o,encoder_attention_mask:s,encoder_hidden_states:a,past_key_values:i},!0)}};var Go=class extends y{},Z_=class extends Go{},eg=class extends Go{};var qo=class extends y{},tg=class extends qo{},rg=class extends qo{};var Wo=class extends y{},sg=class extends Wo{},ng=class extends Wo{};var uc=class extends y{forward_params=["input_ids","attention_mask","inputs_embeds","per_layer_inputs","position_ids","pixel_values","input_features","input_features_mask","past_key_values"]},Vo=class extends uc{async forward({input_ids:e=null,attention_mask:r=null,pixel_values:s=null,input_features:n=null,input_features_mask:o=null,position_ids:a=null,inputs_embeds:i=null,per_layer_inputs:l=null,past_key_values:u=null,generation_config:d=null,logits_processor:f=null,...m}){if((!i||!l)&&({inputs_embeds:i,per_layer_inputs:l}=await ce(this.sessions.embed_tokens,{input_ids:e}),e.dims[1]!==1)){if(s){let{image_features:w}=await ce(this.sessions.vision_encoder,{pixel_values:s});({inputs_embeds:i,attention_mask:r}=this._merge_input_ids_with_image_features({image_features:w,inputs_embeds:i,input_ids:e,attention_mask:r}))}if(n){let{audio_features:w}=await ce(this.sessions.audio_encoder,{input_features:n,input_features_mask:o});({inputs_embeds:i,attention_mask:r}=this._merge_input_ids_with_audio_features({audio_features:w,inputs_embeds:i,input_ids:e,attention_mask:r}))}}return await Tt(this,{inputs_embeds:i,per_layer_inputs:l,past_key_values:u,attention_mask:r,position_ids:a,generation_config:d,logits_processor:f},!0)}_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_id,...e,image_features:s})}_merge_input_ids_with_audio_features(e){let r=e.audio_features.dims.at(-1),s=e.audio_features.view(-1,r);return Ql({audio_token_id:this.config.audio_token_id,...e,audio_features:s})}};var Ho=class extends y{},og=class extends Ho{},ag=class extends Ho{};var Xo=class extends y{},ig=class extends Xo{},lg=class extends Xo{};var Ko=class extends y{},cg=class extends Ko{},ug=class extends Ko{};var Yo=class extends y{},pg=class extends Yo{},dg=class extends Yo{};var Qo=class extends y{},fg=class extends Qo{},mg=class extends Qo{};var Jo=class extends y{},hg=class extends Jo{},_g=class extends Jo{};var Zo=class extends y{},gg=class extends Zo{},wg=class extends Zo{};var ea=class extends y{},xg=class extends ea{},yg=class extends ea{};var ta=class extends y{},bg=class extends ta{},vg=class extends ta{};var ra=class extends y{},kg=class extends ra{},Eg=class extends ra{};var pc=class extends y{},Ag=class extends pc{};var dc=class extends y{},Mg=class extends dc{};var sa=class extends y{},Tg=class extends sa{},Sg=class extends sa{};var na=class extends y{},Og=class extends na{},Ig=class extends na{async _call(e){return new F(await super._call(e))}};var Jt=class extends y{},Cg=class extends Jt{},Pg=class extends Jt{async _call(e){return new gt(await super._call(e))}},zg=class extends Jt{async _call(e){return new F(await super._call(e))}},Lg=class extends Jt{async _call(e){return new _e(await super._call(e))}};var Ng=class extends y{},$g=class extends Jt{},Rg=class extends Jt{async _call(e){return new gt(await super._call(e))}},Ug=class extends Jt{async _call(e){return new F(await super._call(e))}};var oa=class extends y{},Bg=class extends oa{},Dg=class extends oa{};var fc=class extends y{forward_params=["input_ids","attention_mask","pixel_values","pixel_attention_mask","position_ids","past_key_values"]},mc=class extends fc{async encode_image({pixel_values:e,pixel_attention_mask:r}){return(await ce(this.sessions.vision_encoder,{pixel_values:e,pixel_attention_mask:r})).image_features}_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_id,...e,image_features:s})}},Fg=class extends mc{};var aa=class extends y{},jg=class extends aa{},Gg=class extends aa{async _call(e){return new F(await super._call(e))}};var ia=class extends y{},qg=class extends ia{},Wg=class extends ia{};var pn=class extends y{},Vg=class extends pn{async forward(e){let r=!e.input_ids,s=!e.pixel_values;if(r&&s)throw new Error("Either `input_ids` or `pixel_values` should be provided.");if(r&&(e.input_ids=it([e.pixel_values.dims[0],1])),s){let{image_size:u}=this.config.vision_config;e.pixel_values=Ve([0,3,u,u],0)}let{text_embeddings:n,image_embeddings:o,l2norm_text_embeddings:a,l2norm_image_embeddings:i}=await super.forward(e),l={};return r||(l.text_embeddings=n,l.l2norm_text_embeddings=a),s||(l.image_embeddings=o,l.l2norm_image_embeddings=i),l}},la=class extends pn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},Hg=class extends pn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var ca=class extends y{},Xg=class extends ca{},Kg=class extends ca{};var ua=class extends y{},Yg=class extends ua{},Qg=class extends ua{};var pa=class extends y{},Jg=class extends pa{},Zg=class extends pa{};var hc=class extends y{},ew=class extends hc{};var _c=class extends y{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},dn=class extends _c{_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_index,...e,image_features:s})}},tw=class extends dn{},rw=class extends dn{};var da=class extends y{},sw=class extends da{},nw=class extends da{};var fa=class extends y{},ow=class extends fa{},aw=class extends fa{};var ma=class extends y{},iw=class extends ma{},lw=class extends ma{};var ha=class extends y{},cw=class extends ha{},uw=class extends ha{};var bs=class extends y{},pw=class extends bs{},dw=class extends bs{},fw=class extends bs{async _call(e){return new F(await super._call(e))}},mw=class extends bs{};var gc=class extends y{},hw=class extends gc{};var wc=class extends y{},_w=class extends wc{};var xc=class extends ze{constructor({char_logits:e,bpe_logits:r,wp_logits:s}){super(),this.char_logits=e,this.bpe_logits=r,this.wp_logits=s}get logits(){return[this.char_logits,this.bpe_logits,this.wp_logits]}},yc=class extends y{},gw=class extends yc{async _call(e){return new xc(await super._call(e))}};var bc=class extends ze{constructor({audio_codes:e}){super(),this.audio_codes=e}},vc=class extends ze{constructor({audio_values:e}){super(),this.audio_values=e}},fn=class extends y{main_input_name="input_values";forward_params=["input_values"]},ww=class extends fn{async encode(e){return new bc(await ce(this.sessions.encoder_model,e))}async decode(e){return new vc(await ce(this.sessions.decoder_model,e))}},_a=class extends fn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},ga=class extends fn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var wa=class extends y{},xw=class extends wa{},yw=class extends wa{};var vs=class extends y{},bw=class extends vs{},vw=class extends vs{async _call(e){return new we(await super._call(e))}},kw=class extends vs{async _call(e){return new F(await super._call(e))}},Ew=class extends vs{async _call(e){return new Ae(await super._call(e))}};var xa=class extends y{},Aw=class extends xa{},Mw=class extends xa{};var mn=class extends y{},Tw=class extends mn{},Sw=class extends mn{async _call(e){return new F(await super._call(e))}},Ow=class extends mn{};var hn=class extends y{},Iw=class extends hn{},Cw=class extends hn{async _call(e){return new F(await super._call(e))}},Pw=class extends hn{};var _n=class extends y{},zw=class extends _n{},Lw=class extends _n{async _call(e){return new F(await super._call(e))}},Nw=class extends _n{};var gn=class extends y{},$w=class extends gn{},Rw=class extends gn{async _call(e){return new F(await super._call(e))}},Uw=class extends gn{};var ya=class extends y{},Bw=class extends ya{},Dw=class extends ya{async _call(e){return new F(await super._call(e))}};var ba=class extends y{},Fw=class extends ba{},jw=class extends ba{async _call(e){return new F(await super._call(e))}};var ks=class extends y{},Gw=class extends ks{},qw=class extends ks{async _call(e){return new we(await super._call(e))}},Ww=class extends ks{async _call(e){return new F(await super._call(e))}},Vw=class extends ks{async _call(e){return new _e(await super._call(e))}};var va=class extends y{},Hw=class extends va{},Xw=class extends va{};var ka=class extends y{requires_attention_mask=!1;main_input_name="input_values";forward_params=["input_values","decoder_input_ids","past_key_values"]},Kw=class extends ka{},Yw=class extends ka{};var Ur=class extends y{},Qw=class extends Ur{},Jw=class extends Ur{async _call(e){return new we(await super._call(e))}},Zw=class extends Ur{async _call(e){return new F(await super._call(e))}},ex=class extends Ur{async _call(e){return new _e(await super._call(e))}},tx=class extends Ur{async _call(e){return new Ae(await super._call(e))}};var Ea=class extends y{},rx=class extends Ea{},sx=class extends Ea{};var Aa=class extends y{},nx=class extends Aa{},ox=class extends Aa{};var kc=class extends y{},ax=class extends kc{forward_params=["input_ids","pixel_values","images_seq_mask","images_emb_mask","attention_mask","position_ids","past_key_values"];constructor(...e){super(...e),this._generation_mode="text"}async forward(e){let r=this._generation_mode??"text",s;if(r==="text"||!e.past_key_values){let l=this.sessions.prepare_inputs_embeds,u=ot(e,l.inputNames);s=await ce(l,u)}else{let l=this.sessions.gen_img_embeds,u=ot({image_ids:e.input_ids},l.inputNames);s=await ce(l,u)}let n={...e,...s},o=await Tt(this,n),a=this.sessions[r==="text"?"lm_head":"gen_head"];if(!a)throw new Error(`Unable to find "${a}" generation head`);let i=await ce(a,ot(o,a.inputNames));return{...s,...o,...i}}prepare_inputs_for_generation(e,r,s){let n=!!r.past_key_values;return s.guidance_scale!==null&&s.guidance_scale>1&&(n?r.input_ids=Ee([r.input_ids,r.input_ids],0):(r.input_ids=Ee([r.input_ids,Qn(r.input_ids,BigInt(s.pad_token_id))],0),r.attention_mask=Ee([r.attention_mask,Qn(r.attention_mask,0n)],0))),(n||!r.pixel_values)&&(r.pixel_values=Ve([0,0,3,384,384],1)),n&&(r.images_seq_mask=new U("bool",new Array(1).fill(!0).fill(!1,0,1),[1,1]),r.images_emb_mask=new U("bool",new Array(0).fill(!1),[1,1,0])),r}async generate(e){return this._generation_mode="text",super.generate(e)}async generate_images(e){this._generation_mode="image";let r=(e.inputs??e[this.main_input_name]).dims[1],n=(await super.generate(e)).slice(null,[r,null]),o=this.sessions.image_decode,{decoded_image:a}=await ce(o,{generated_tokens:n}),i=a.add_(1).mul_(255/2).clamp_(0,255).to("uint8"),l=[];for(let u of i){let d=Xe.fromTensor(u);l.push(d)}return l}};var Ma=class extends y{},ix=class extends Ma{},lx=class extends Ma{},Ta=class extends y{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"];_apply_and_filter_by_delay_pattern_mask(e){let[r,s]=e.dims,n=this.config.decoder.num_codebooks,o=s-n,a=0;for(let u=0;u<e.size;++u){if(e.data[u]==this.config.decoder.pad_token_id)continue;let d=u%s,f=Math.floor(u/s)%n,m=d-f;m>0&&m<=o&&(e.data[a++]=e.data[u])}let i=Math.floor(r/n),l=a/(i*n);return new U(e.type,e.data.slice(0,a),[i,n,l])}prepare_inputs_for_generation(e,r,s){let n=BigInt(this.config.decoder.pad_token_id),o=structuredClone(e);for(let a=0;a<o.length;++a)for(let i=0;i<o[a].length;++i)a%this.config.decoder.num_codebooks>=i&&(o[a][i]=n);return s.guidance_scale!==null&&s.guidance_scale>1&&(o=o.concat(o)),po(this,o,r,s)}async generate(e){let r=await super.generate(e),s=this._apply_and_filter_by_delay_pattern_mask(r).unsqueeze_(0),{audio_values:n}=await ce(this.sessions.encodec_decode,{audio_codes:s});return n}};var Sa=class extends y{},cx=class extends Sa{},ux=class extends Sa{};var Br=class extends y{},px=class extends Br{},dx=class extends Br{async _call(e){return new we(await super._call(e))}},fx=class extends Br{async _call(e){return new F(await super._call(e))}},mx=class extends Br{async _call(e){return new _e(await super._call(e))}},hx=class extends Br{async _call(e){return new Ae(await super._call(e))}};var Ec=class extends y{},_x=class extends Ec{};var Oa=class extends y{},gx=class extends Oa{},wx=class extends Oa{};var Ia=class extends y{},xx=class extends Ia{},yx=class extends Ia{};var Ca=class extends y{},bx=class extends Ca{},vx=class extends Ca{};var Pa=class extends y{},kx=class extends Pa{},Ex=class extends Pa{};var za=class extends y{},Ax=class extends za{},Mx=class extends za{};var La=class extends y{},Tx=class extends La{},Sx=class extends La{};var Na=class extends y{},Ox=class extends Na{},Ix=class extends Na{};var Ac=class extends y{forward_params=["input_ids","attention_mask","pixel_values","position_ids","past_key_values"]},Cx=class extends Ac{_merge_input_ids_with_image_features(e){let r=e.image_features.dims.at(-1),s=e.image_features.view(-1,r);return ar({image_token_id:this.config.image_token_index,...e,image_features:s})}};var Mc=class extends y{},Px=class extends Mc{async _call(e){return new gt(await super._call(e))}};var $a=class extends y{},zx=class extends $a{},Lx=class extends $a{};var Ra=class extends y{},Nx=class extends Ra{},$x=class extends Ra{};var Ua=class extends y{},Rx=class extends Ua{},Ux=class extends Ua{};var Ba=class extends y{},Bx=class extends Ba{},Dx=class extends Ba{};var Tc=class extends y{forward_params=["input_ids","inputs_embeds","attention_mask","position_ids","pixel_values","image_sizes","past_key_values"]},Da=class extends Tc{async forward({input_ids:e=null,attention_mask:r=null,pixel_values:s=null,image_sizes:n=null,position_ids:o=null,inputs_embeds:a=null,past_key_values:i=null,generation_config:l=null,logits_processor:u=null,...d}){if(!a){let m;if(s&&e.dims[1]!==1){if(!n)throw new Error("`image_sizes` must be provided when `pixel_values` is provided.");({image_features:m}=await ce(this.sessions.vision_encoder,{pixel_values:s,image_sizes:n}))}else{let _=this.config.normalized_config.hidden_size;m=new U("float32",[],[0,_])}({inputs_embeds:a}=await ce(this.sessions.prepare_inputs_embeds,{input_ids:e,image_features:m}))}return await Tt(this,{inputs_embeds:a,past_key_values:i,attention_mask:r,position_ids:o,generation_config:l,logits_processor:u},!1)}};var Fa=class extends y{},Fx=class extends Fa{},jx=class extends Fa{async _call(e){return new F(await super._call(e))}};var ja=class extends y{},Gx=class extends ja{},qx=class extends ja{async _call(e){return new _e(await super._call(e))}};var Ga=class extends y{},Wx=class extends Ga{},Vx=class extends Ga{};var Sc=class extends y{forward_params=["input_ids","attention_mask","position_ids","past_key_values","pixel_values","image_grid_thw"]},Hx=class extends Sc{get_rope_index(e,r,s,n){let{vision_config:o,image_token_id:a,video_token_id:i,vision_start_token_id:l}=this.config,u=o.spatial_merge_size??2,d=[];if(r||s){let f=e.tolist();n||(n=il(e));let m=n.tolist(),_=Array.from({length:3},M=>Array.from({length:e.dims[0]},I=>Array.from({length:e.dims[1]},T=>1))),w=r?r.tolist():[],x=s?s.tolist():[],k=0,E=0;for(let M=0;M<f.length;++M){let I=f[M].filter((S,L)=>m[M][L]==1),z=I.reduce((S,L,R)=>(L==l&&S.push(R),S),[]).map(S=>I[S+1]),C=z.filter(S=>S==a).length,v=z.filter(S=>S==i).length,G=[],X=0,V=C,Q=v;for(let S=0;S<z.length;++S){let L=I.findIndex((Et,et)=>et>X&&Et==a),R=I.findIndex((Et,et)=>et>X&&Et==i),te=V>0&&L!==-1?L:I.length+1,ue=Q>0&&R!==-1?R:I.length+1,Be,Ce,vt,Qe;te<ue?([Ce,vt,Qe]=w[k],++k,--V,Be=te):([Ce,vt,Qe]=x[E],++E,--Q,Be=ue);let[Ze,rt,Me]=[Number(Ce),Math.floor(Number(vt)/u),Math.floor(Number(Qe)/u)],xe=Be-X,Ge=G.length>0?Te(G.at(-1))[0]+1:0;G.push(Array.from({length:3*xe},(Et,et)=>Ge+et%xe));let kt=xe+Ge,ge=Ze*rt*Me,Le=Array.from({length:ge},(Et,et)=>kt+Math.floor(et/(rt*Me))),xr=Array.from({length:ge},(Et,et)=>kt+Math.floor(et/Me)%rt),Hr=Array.from({length:ge},(Et,et)=>kt+et%Me);G.push([Le,xr,Hr].flat()),X=Be+ge}if(X<I.length){let S=G.length>0?Te(G.at(-1))[0]+1:0,L=I.length-X;G.push(Array.from({length:3*L},(R,te)=>S+te%L))}let K=G.reduce((S,L)=>S+L.length,0),Y=new Array(K),B=0;for(let S=0;S<3;++S)for(let L=0;L<G.length;++L){let R=G[L],te=R.length/3;for(let ue=S*te;ue<(S+1)*te;++ue)Y[B++]=R[ue]}let P=0,se=m[M];for(let S=0;S<se.length;++S)if(se[S]==1){for(let L=0;L<3;++L)_[L][M][S]=Y[L*K/3+P];++P}let ie=Te(Y)[0];d.push(ie+1-f[M].length)}return[new U("int64",_.flat(1/0),[3,e.dims[0],e.dims[1]]),new U("int64",d,[d.length,1])]}else if(n){let{data:f,dims:m}=Km(n),_=BigInt64Array.from({length:3*f.length},(x,k)=>f[k%f.length]),w=Array.from({length:m[0]},(x,k)=>Te(f.subarray(m[1]*k,m[1]*(k+1)))[0]+1n+BigInt(m[1]));return[new U("int64",_,[3,...m]),new U("int64",w,[w.length,1])]}else{let[f,m]=e.dims,_=BigInt64Array.from({length:3*f*m},(w,x)=>BigInt(Math.floor(x%m/f)));return[new U("int64",_,[3,...e.dims]),vd([f,1])]}}async encode_image({pixel_values:e,image_grid_thw:r}){return(await ce(this.sessions.vision_encoder,{pixel_values:e,grid_thw:r})).image_features}_merge_input_ids_with_image_features(e){return ar({image_token_id:this.config.image_token_id,...e})}prepare_inputs_for_generation(e,r,s){if(r.attention_mask&&!r.position_ids)if(!r.past_key_values)[r.position_ids,r.rope_deltas]=this.get_rope_index(r.input_ids,r.image_grid_thw,r.video_grid_thw,r.attention_mask);else{r.pixel_values=null;let n=BigInt(Object.values(r.past_key_values)[0].dims.at(-2)),o=r.rope_deltas.map(a=>n+a);r.position_ids=Ft([o,o,o],0)}return r}};var qa=class extends y{},Xx=class extends qa{},Kx=class extends qa{};var Wa=class extends y{},Yx=class extends Wa{},Qx=class extends Wa{async _call(e){return new F(await super._call(e))}};var Va=class extends y{},Jx=class extends Va{},Zx=class extends Va{async _call(e){return new Oc(await super._call(e))}},Oc=class extends lr{};var Dr=class extends y{},ey=class extends Dr{},ty=class extends Dr{async _call(e){return new we(await super._call(e))}},ry=class extends Dr{async _call(e){return new F(await super._call(e))}},sy=class extends Dr{async _call(e){return new _e(await super._call(e))}},ny=class extends Dr{async _call(e){return new Ae(await super._call(e))}};var Fr=class extends y{},oy=class extends Fr{},ay=class extends Fr{async _call(e){return new we(await super._call(e))}},iy=class extends Fr{async _call(e){return new F(await super._call(e))}},ly=class extends Fr{async _call(e){return new _e(await super._call(e))}},cy=class extends Fr{async _call(e){return new Ae(await super._call(e))}};var Ha=class extends y{},uy=class extends Ha{},py=class extends Ha{async _call(e){return new Ic(await super._call(e))}},Ic=class extends lr{};var Cc=class extends ze{constructor({iou_scores:e,pred_masks:r}){super(),this.iou_scores=e,this.pred_masks=r}},Pc=class extends y{},dy=class extends Pc{async get_image_embeddings({pixel_values:e}){return await Gt(this,{pixel_values:e})}async forward(e){!e.image_embeddings||!e.image_positional_embeddings?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_labels??=it(e.input_points.dims.slice(0,-1));let r={image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings};return e.input_points&&(r.input_points=e.input_points),e.input_labels&&(r.input_labels=e.input_labels),e.input_boxes&&(r.input_boxes=e.input_boxes),await ce(this.sessions.prompt_encoder_mask_decoder,r)}async _call(e){return new Cc(await super._call(e))}};var zc=class extends ze{constructor({iou_scores:e,pred_masks:r,object_score_logits:s}){super(),this.iou_scores=e,this.pred_masks=r,this.object_score_logits=s}},Lc=class extends y{},Xa=class extends Lc{async get_image_embeddings({pixel_values:e}){return await Gt(this,{pixel_values:e})}async forward(e){let{num_feature_levels:r}=this.config.vision_config;if(Array.from({length:r},(a,i)=>`image_embeddings.${i}`).some(a=>!e[a])?e={...e,...await this.get_image_embeddings(e)}:e={...e},e.input_points){if(e.input_boxes&&e.input_boxes.dims[1]!==1)throw new Error("When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.");let a=e.input_points.dims;e.input_labels??=it(a.slice(0,-1)),e.input_boxes??=Ve([a[0],0,4],0)}else if(e.input_boxes){let a=e.input_boxes.dims;e.input_labels=Ve([a[0],a[1],0],-1n),e.input_points=Ve([a[0],1,0,2],0)}else throw new Error("At least one of `input_points` or `input_boxes` must be provided.");let n=this.sessions.prompt_encoder_mask_decoder,o=ot(e,n.inputNames);return await ce(n,o)}async _call(e){return new zc(await super._call(e))}},fy=class extends Xa{},my=class extends Xa{};var wn=class extends y{},hy=class extends wn{},_y=class extends wn{},gy=class extends wn{};var xn=class extends y{},wy=class extends xn{},xy=class extends xn{},yy=class extends xn{};var Ka=class extends y{},by=class extends Ka{},Ya=class extends Ka{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"text_model"})}},vy=class extends ir{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"vision_model"})}};var Qa=class extends y{},ky=class extends Qa{},Ey=class extends Qa{};var yn=class extends y{main_input_name="input_values";forward_params=["input_values"]},Ay=class extends yn{async encode(e){return await ce(this.sessions.encoder_model,e)}async decode(e){return await ce(this.sessions.decoder_model,e)}},Ja=class extends yn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"encoder_model"})}},Za=class extends yn{static async from_pretrained(e,r={}){return super.from_pretrained(e,{...r,model_file_name:r.model_file_name??"decoder_model"})}};var bn=class extends y{},My=class extends bn{},Ty=class extends bn{},Sy=class extends bn{async generate_speech(e,r,{threshold:s=.5,minlenratio:n=0,maxlenratio:o=20,vocoder:a=null}={}){let i={input_ids:e},{encoder_outputs:l,encoder_attention_mask:u}=await Gt(this,i),d=l.dims[1]/this.config.reduction_factor,f=Math.floor(d*o),m=Math.floor(d*n),_=this.config.num_mel_bins,w=[],x=null,k=null,E=0;for(;;){++E;let T=Xm(!!k),z;k?z=k.output_sequence_out:z=new U("float32",new Float32Array(_),[1,1,_]);let C={use_cache_branch:T,output_sequence:z,encoder_attention_mask:u,speaker_embeddings:r,encoder_hidden_states:l};this.addPastKeyValues(C,x),k=await ce(this.sessions.decoder_model_merged,C),x=this.getPastKeyValues(k,x);let{prob:v,spectrum:G}=k;if(w.push(G),E>=m&&(Array.from(v.data).filter(X=>X>=s).length>0||E>=f))break}let M=Ee(w),{waveform:I}=await ce(a.sessions.model,{spectrogram:M});return{spectrogram:M,waveform:I}}},Oy=class extends y{main_input_name="spectrogram"};var Es=class extends y{},Iy=class extends Es{},Cy=class extends Es{async _call(e){return new we(await super._call(e))}},Py=class extends Es{async _call(e){return new F(await super._call(e))}},zy=class extends Es{async _call(e){return new Ae(await super._call(e))}};var ei=class extends y{},Ly=class extends ei{},Ny=class extends ei{};var ti=class extends y{},$y=class extends ti{},Ry=class extends ti{};var Nc=class extends y{},Uy=class extends Nc{};var $c=class extends y{},ri=class extends $c{async generate_speech({input_ids:e,attention_mask:r,style:s,num_inference_steps:n=5,speed:o=1.05}){let{sampling_rate:a,chunk_compress_factor:i,base_chunk_size:l,latent_dim:u}=this.config,{last_hidden_state:d,durations:f}=await ce(this.sessions.text_encoder,{input_ids:e,attention_mask:r,style:s}),m=f.div(o).mul_(a),_=l*i,w=m.data,x=Int32Array.from(w,V=>Math.ceil(V/_)),k=Math.max(...x),E=e.dims[0],M=new BigInt64Array(E*k);for(let V=0;V<E;++V)M.fill(1n,V*k,V*k+x[V]);let I=new U("int64",M,[E,k]),T=u*i,z=T*k,C=PE([E,T,k]),v=C.data;for(let V=0;V<E;++V)if(x[V]!==k)for(let Q=0;Q<T;++Q)v.fill(0,V*z+Q*k+x[V],V*z+(Q+1)*k);let G=Ve([E],n);for(let V=0;V<n;++V){let Q=Ve([E],V);({denoised_latents:C}=await ce(this.sessions.latent_denoiser,{style:s,noisy_latents:C,latent_mask:I,encoder_outputs:d,attention_mask:r,timestep:Q,num_inference_steps:G}))}let{waveform:X}=await ce(this.sessions.voice_decoder,{latents:C});return{waveform:X,durations:m}}};var vn=class extends y{},By=class extends vn{},Dy=class extends vn{async _call(e){return new F(await super._call(e))}},Fy=class extends vn{};var si=class extends y{},jy=class extends si{},Gy=class extends si{};var ni=class extends y{forward_params=["input_ids","attention_mask","encoder_outputs","decoder_input_ids","decoder_attention_mask","past_key_values"]},qy=class extends ni{},Wy=class extends ni{};var oi=class extends y{},Vy=class extends oi{},Hy=class extends oi{async _call(e){return new Rc(await super._call(e))}},Rc=class extends un{};var Uc=class extends y{},Xy=class extends Uc{};var Bc=class extends y{forward_params=["input_ids","attention_mask","position_ids","audio_values","past_key_values"]},Dc=class extends Bc{_merge_input_ids_with_audio_features(e){let r=e.audio_features.dims.at(-1),s=e.audio_features.view(-1,r);return Ql({audio_token_id:this.config.ignore_index??this.config.audio_token_id,...e,audio_features:s})}},Ky=class extends Dc{};var kn=class extends y{},Yy=class extends kn{},Qy=class extends kn{async _call(e){return new gt(await super._call(e))}},Jy=class extends kn{async _call(e){return new F(await super._call(e))}};var As=class extends y{},Zy=class extends As{},e0=class extends As{async _call(e){return new gt(await super._call(e))}},t0=class extends As{async _call(e){return new F(await super._call(e))}},r0=class extends As{async _call(e){return new _e(await super._call(e))}};var ai=class extends y{},s0=class extends ai{},n0=class extends ai{};var o0=class extends y{main_input_name="pixel_values";forward_params=["pixel_values","decoder_input_ids","encoder_hidden_states","past_key_values"]};var ii=class extends y{},a0=class extends ii{},i0=class extends ii{async _call(e){return new F(await super._call(e))}};var Fc=class extends y{},l0=class extends Fc{};var li=class extends y{},c0=class extends li{},u0=class extends li{async _call(e){return new F(await super._call(e))}};var jc=class extends y{},p0=class extends jc{async _call(e){return new Ll(await super._call(e))}};var Gc=class extends y{},d0=class extends Gc{};var qc=class extends ze{constructor({waveform:e,spectrogram:r}){super(),this.waveform=e,this.spectrogram=r}},Wc=class extends y{},f0=class extends Wc{async _call(e){return new qc(await super._call(e))}};var En=class extends y{},m0=class extends En{},h0=class extends En{async _call(e){return new gt(await super._call(e))}},_0=class extends En{async _call(e){return new F(await super._call(e))}};var Vc=class extends ze{constructor({logits:e,embeddings:r}){super(),this.logits=e,this.embeddings=r}},jr=class extends y{},g0=class extends jr{},w0=class extends jr{async _call(e){return new gt(await super._call(e))}},x0=class extends jr{async _call(e){return new F(await super._call(e))}},y0=class extends jr{async _call(e){return new Vc(await super._call(e))}},b0=class extends jr{async _call(e){return new _e(await super._call(e))}};var Hc=class extends y{},v0=class extends Hc{};var Xc=class extends sn{return_timestamps=null;return_token_timestamps=null;num_frames=null;alignment_heads=null;task=null;language=null;no_timestamps_token_id=null;prompt_ids=null;is_multilingual=null;lang_to_id=null;task_to_id=null;max_initial_timestamp_index=1};var ci=class extends y{requires_attention_mask=!1;main_input_name="input_features";forward_params=["input_features","attention_mask","decoder_input_ids","decoder_attention_mask","past_key_values"]},k0=class extends ci{},Kc=class extends ci{_prepare_generation_config(e,r){return super._prepare_generation_config(e,r,Xc)}_retrieve_init_tokens(e){let r=[e.decoder_start_token_id],s=e.language,n=e.task;if(e.is_multilingual){s||(console.warn("No language specified - defaulting to English (en)."),s="en");let a=`<|${NE(s)}|>`;r.push(e.lang_to_id[a]),r.push(e.task_to_id[n??"transcribe"])}else if(s||n)throw new Error("Cannot specify `task` or `language` for an English-only model. If the model is intended to be multilingual, pass `is_multilingual=true` to generate, or update the generation config.");return!e.return_timestamps&&e.no_timestamps_token_id&&r.at(-1)!==e.no_timestamps_token_id?r.push(e.no_timestamps_token_id):e.return_timestamps&&r.at(-1)===e.no_timestamps_token_id&&(console.warn("<|notimestamps|> prompt token is removed from generation_config since `return_timestamps` is set to `true`."),r.pop()),r.filter(o=>o!=null)}async generate({inputs:e=null,generation_config:r=null,logits_processor:s=null,stopping_criteria:n=null,...o}){r=this._prepare_generation_config(r,o);let a=o.decoder_input_ids??this._retrieve_init_tokens(r);if(r.return_timestamps&&(s??=new hs,s.push(new Rl(r,a))),r.begin_suppress_tokens&&(s??=new hs,s.push(new rn(r.begin_suppress_tokens,a.length))),r.return_token_timestamps){if(!r.alignment_heads)throw new Error("Model generation config has no `alignment_heads`, token-level timestamps not available. See https://gist.github.com/hollance/42e32852f24243b748ae6bc1f985b13a on how to add this property to the generation config.");r.task==="translate"&&console.warn("Token-level timestamps may not be reliable for task 'translate'."),r.output_attentions=!0,r.return_dict_in_generate=!0}let i=await super.generate({inputs:e,generation_config:r,logits_processor:s,decoder_input_ids:a,...o});return r.return_token_timestamps&&(i.token_timestamps=this._extract_token_timestamps(i,r.alignment_heads,r.num_frames)),i}_extract_token_timestamps(e,r,s=null,n=.02){if(!e.cross_attentions)throw new Error("Model outputs must contain cross attentions to extract timestamps. This is most likely because the model was not exported with `output_attentions=True`.");s==null&&console.warn("`num_frames` has not been set, meaning the entire audio will be analyzed. This may lead to inaccurate token-level timestamps for short audios (< 30 seconds).");let o=this.config.median_filter_width;o===void 0&&(console.warn("Model config has no `median_filter_width`, using default value of 7."),o=7);let a=e.cross_attentions,i=Array.from({length:this.config.decoder_layers},(x,k)=>Ee(a.map(E=>E[k]),2)),l=Ft(r.map(([x,k])=>{if(x>=i.length)throw new Error(`Layer index ${x} is out of bounds for cross attentions (length ${i.length}).`);return s?i[x].slice(null,k,null,[0,s]):i[x].slice(null,k)})).transpose(1,0,2,3),[u,d]=yd(l,-2,0,!0),f=l.clone();for(let x=0;x<f.dims[0];++x){let k=f[x];for(let E=0;E<k.dims[0];++E){let M=k[E],I=u[x][E][0].data,T=d[x][E][0].data;for(let z=0;z<M.dims[0];++z){let C=M[z].data;for(let v=0;v<C.length;++v)C[v]=(C[v]-T[v])/I[v];C.set(Vv(C,o))}}}let m=[al(f,1)],_=e.sequences.dims,w=new U("float32",new Float32Array(_[0]*_[1]),_);for(let x=0;x<_[0];++x){let k=m[x].neg().squeeze_(0),[E,M]=Xv(k.tolist()),I=Array.from({length:E.length-1},(C,v)=>E[v+1]-E[v]),T=dt([1],I).map(C=>!!C),z=[];for(let C=0;C<T.length;++C)T[C]&&z.push(M[C]*n);w[x].data.set(z,1)}return w}},E0=class extends Kc{};var Gr=class extends y{},A0=class extends Gr{},M0=class extends Gr{async _call(e){return new we(await super._call(e))}},T0=class extends Gr{async _call(e){return new F(await super._call(e))}},S0=class extends Gr{async _call(e){return new _e(await super._call(e))}},O0=class extends Gr{async _call(e){return new Ae(await super._call(e))}};var qr=class extends y{},I0=class extends qr{},C0=class extends qr{async _call(e){return new we(await super._call(e))}},P0=class extends qr{async _call(e){return new F(await super._call(e))}},z0=class extends qr{async _call(e){return new _e(await super._call(e))}},L0=class extends qr{async _call(e){return new Ae(await super._call(e))}};var ui=class extends y{},N0=class extends ui{},$0=class extends ui{async _call(e){return new Yc(await super._call(e))}},Yc=class extends ze{constructor({logits:e,pred_boxes:r}){super(),this.logits=e,this.pred_boxes=r}};var pi=class extends y{},R0=class extends pi{},U0=class extends pi{};var FP=new Map([["bert","BertModel"],["neobert","NeoBertModel"],["modernbert","ModernBertModel"],["nomic_bert","NomicBertModel"],["roformer","RoFormerModel"],["electra","ElectraModel"],["esm","EsmModel"],["convbert","ConvBertModel"],["camembert","CamembertModel"],["deberta","DebertaModel"],["deberta-v2","DebertaV2Model"],["mpnet","MPNetModel"],["albert","AlbertModel"],["distilbert","DistilBertModel"],["roberta","RobertaModel"],["xlm","XLMModel"],["xlm-roberta","XLMRobertaModel"],["clap","ClapModel"],["clip","CLIPModel"],["clipseg","CLIPSegModel"],["chinese_clip","ChineseCLIPModel"],["siglip","SiglipModel"],["jina_clip","JinaCLIPModel"],["mobilebert","MobileBertModel"],["squeezebert","SqueezeBertModel"],["wav2vec2","Wav2Vec2Model"],["wav2vec2-bert","Wav2Vec2BertModel"],["unispeech","UniSpeechModel"],["unispeech-sat","UniSpeechSatModel"],["hubert","HubertModel"],["wavlm","WavLMModel"],["audio-spectrogram-transformer","ASTModel"],["vits","VitsModel"],["pyannote","PyAnnoteModel"],["wespeaker-resnet","WeSpeakerResNetModel"],["detr","DetrModel"],["rt_detr","RTDetrModel"],["rt_detr_v2","RTDetrV2Model"],["rf_detr","RFDetrModel"],["d_fine","DFineModel"],["table-transformer","TableTransformerModel"],["vit","ViTModel"],["ijepa","IJepaModel"],["pvt","PvtModel"],["vit_msn","ViTMSNModel"],["vit_mae","ViTMAEModel"],["groupvit","GroupViTModel"],["fastvit","FastViTModel"],["mobilevit","MobileViTModel"],["mobilevitv2","MobileViTV2Model"],["owlvit","OwlViTModel"],["owlv2","Owlv2Model"],["beit","BeitModel"],["deit","DeiTModel"],["hiera","HieraModel"],["convnext","ConvNextModel"],["convnextv2","ConvNextV2Model"],["dinov2","Dinov2Model"],["dinov2_with_registers","Dinov2WithRegistersModel"],["dinov3_vit","DINOv3ViTModel"],["dinov3_convnext","DINOv3ConvNextModel"],["resnet","ResNetModel"],["swin","SwinModel"],["swin2sr","Swin2SRModel"],["donut-swin","DonutSwinModel"],["yolos","YolosModel"],["dpt","DPTModel"],["glpn","GLPNModel"],["hifigan","SpeechT5HifiGan"],["efficientnet","EfficientNetModel"],["decision_transformer","DecisionTransformerModel"],["patchtst","PatchTSTModel"],["patchtsmixer","PatchTSMixerModel"],["mobilenet_v1","MobileNetV1Model"],["mobilenet_v2","MobileNetV2Model"],["mobilenet_v3","MobileNetV3Model"],["mobilenet_v4","MobileNetV4Model"],["maskformer","MaskFormerModel"],["mgp-str","MgpstrForSceneTextRecognition"],["style_text_to_speech_2","StyleTextToSpeech2Model"]]),jP=new Map([["t5","T5Model"],["longt5","LongT5Model"],["mt5","MT5Model"],["bart","BartModel"],["mbart","MBartModel"],["marian","MarianModel"],["whisper","WhisperModel"],["m2m_100","M2M100Model"],["blenderbot","BlenderbotModel"],["blenderbot-small","BlenderbotSmallModel"]]),GP=new Map([["mimi","MimiModel"],["dac","DacModel"],["snac","SnacModel"]]),qP=new Map([["bloom","BloomModel"],["jais","JAISModel"],["gpt2","GPT2Model"],["gpt_oss","GptOssModel"],["gptj","GPTJModel"],["gpt_bigcode","GPTBigCodeModel"],["gpt_neo","GPTNeoModel"],["gpt_neox","GPTNeoXModel"],["codegen","CodeGenModel"],["llama","LlamaModel"],["apertus","ApertusModel"],["nanochat","NanoChatModel"],["arcee","ArceeModel"],["lfm2","Lfm2Model"],["lfm2_moe","Lfm2MoeModel"],["smollm3","SmolLM3Model"],["exaone","ExaoneModel"],["olmo","OlmoModel"],["olmo2","Olmo2Model"],["olmo3","Olmo3Model"],["mobilellm","MobileLLMModel"],["granite","GraniteModel"],["granitemoehybrid","GraniteMoeHybridModel"],["cohere","CohereModel"],["gemma","GemmaModel"],["gemma2","Gemma2Model"],["vaultgemma","VaultGemmaModel"],["gemma3_text","Gemma3Model"],["helium","HeliumModel"],["glm","GlmModel"],["openelm","OpenELMModel"],["qwen2","Qwen2Model"],["qwen3","Qwen3Model"],["phi","PhiModel"],["phi3","Phi3Model"],["mpt","MptModel"],["opt","OPTModel"],["mistral","MistralModel"],["ministral","MinistralModel"],["ministral3","Ministral3Model"],["ernie4_5","Ernie4_5_Model"],["starcoder2","Starcoder2Model"],["falcon","FalconModel"],["falcon_h1","FalconH1Model"],["stablelm","StableLmModel"],["modernbert-decoder","ModernBertDecoderModel"],["hunyuan_v1_dense","HunYuanDenseV1Model"],["youtu","YoutuModel"]]),nA=new Map([["speecht5","SpeechT5ForSpeechToText"],["whisper","WhisperForConditionalGeneration"],["lite-whisper","LiteWhisperForConditionalGeneration"],["moonshine","MoonshineForConditionalGeneration"]]),oA=new Map([["speecht5","SpeechT5ForTextToSpeech"]]),aA=new Map([["vits","VitsModel"],["musicgen","MusicgenForConditionalGeneration"],["supertonic","SupertonicForConditionalGeneration"]]),iA=new Map([["bert","BertForSequenceClassification"],["neobert","NeoBertForSequenceClassification"],["modernbert","ModernBertForSequenceClassification"],["roformer","RoFormerForSequenceClassification"],["electra","ElectraForSequenceClassification"],["esm","EsmForSequenceClassification"],["convbert","ConvBertForSequenceClassification"],["camembert","CamembertForSequenceClassification"],["deberta","DebertaForSequenceClassification"],["deberta-v2","DebertaV2ForSequenceClassification"],["mpnet","MPNetForSequenceClassification"],["albert","AlbertForSequenceClassification"],["distilbert","DistilBertForSequenceClassification"],["roberta","RobertaForSequenceClassification"],["xlm","XLMForSequenceClassification"],["xlm-roberta","XLMRobertaForSequenceClassification"],["bart","BartForSequenceClassification"],["mbart","MBartForSequenceClassification"],["mobilebert","MobileBertForSequenceClassification"],["squeezebert","SqueezeBertForSequenceClassification"]]),lA=new Map([["bert","BertForTokenClassification"],["neobert","NeoBertForTokenClassification"],["modernbert","ModernBertForTokenClassification"],["roformer","RoFormerForTokenClassification"],["electra","ElectraForTokenClassification"],["esm","EsmForTokenClassification"],["convbert","ConvBertForTokenClassification"],["camembert","CamembertForTokenClassification"],["deberta","DebertaForTokenClassification"],["deberta-v2","DebertaV2ForTokenClassification"],["mpnet","MPNetForTokenClassification"],["distilbert","DistilBertForTokenClassification"],["roberta","RobertaForTokenClassification"],["xlm","XLMForTokenClassification"],["xlm-roberta","XLMRobertaForTokenClassification"]]),cA=new Map([["t5","T5ForConditionalGeneration"],["longt5","LongT5ForConditionalGeneration"],["mt5","MT5ForConditionalGeneration"],["bart","BartForConditionalGeneration"],["mbart","MBartForConditionalGeneration"],["marian","MarianMTModel"],["m2m_100","M2M100ForConditionalGeneration"],["blenderbot","BlenderbotForConditionalGeneration"],["blenderbot-small","BlenderbotSmallForConditionalGeneration"]]),uA=new Map([["bloom","BloomForCausalLM"],["gpt2","GPT2LMHeadModel"],["gpt_oss","GptOssForCausalLM"],["jais","JAISLMHeadModel"],["gptj","GPTJForCausalLM"],["gpt_bigcode","GPTBigCodeForCausalLM"],["gpt_neo","GPTNeoForCausalLM"],["gpt_neox","GPTNeoXForCausalLM"],["codegen","CodeGenForCausalLM"],["llama","LlamaForCausalLM"],["nanochat","NanoChatForCausalLM"],["apertus","ApertusForCausalLM"],["llama4_text","Llama4ForCausalLM"],["arcee","ArceeForCausalLM"],["lfm2","Lfm2ForCausalLM"],["lfm2_moe","Lfm2MoeForCausalLM"],["smollm3","SmolLM3ForCausalLM"],["exaone","ExaoneForCausalLM"],["olmo","OlmoForCausalLM"],["olmo2","Olmo2ForCausalLM"],["olmo3","Olmo3ForCausalLM"],["mobilellm","MobileLLMForCausalLM"],["granite","GraniteForCausalLM"],["granitemoehybrid","GraniteMoeHybridForCausalLM"],["cohere","CohereForCausalLM"],["gemma","GemmaForCausalLM"],["gemma2","Gemma2ForCausalLM"],["vaultgemma","VaultGemmaForCausalLM"],["gemma3_text","Gemma3ForCausalLM"],["helium","HeliumForCausalLM"],["glm","GlmForCausalLM"],["openelm","OpenELMForCausalLM"],["qwen2","Qwen2ForCausalLM"],["qwen3","Qwen3ForCausalLM"],["phi","PhiForCausalLM"],["phi3","Phi3ForCausalLM"],["mpt","MptForCausalLM"],["opt","OPTForCausalLM"],["mbart","MBartForCausalLM"],["mistral","MistralForCausalLM"],["ministral","MinistralForCausalLM"],["ministral3","Ministral3ForCausalLM"],["ernie4_5","Ernie4_5_ForCausalLM"],["starcoder2","Starcoder2ForCausalLM"],["falcon","FalconForCausalLM"],["falcon_h1","FalconH1ForCausalLM"],["trocr","TrOCRForCausalLM"],["stablelm","StableLmForCausalLM"],["modernbert-decoder","ModernBertDecoderForCausalLM"],["hunyuan_v1_dense","HunYuanDenseV1ForCausalLM"],["youtu","YoutuForCausalLM"],["phi3_v","Phi3VForCausalLM"]]),WP=new Map([["multi_modality","MultiModalityCausalLM"]]),pA=new Map([["bert","BertForMaskedLM"],["neobert","NeoBertForMaskedLM"],["modernbert","ModernBertForMaskedLM"],["roformer","RoFormerForMaskedLM"],["electra","ElectraForMaskedLM"],["esm","EsmForMaskedLM"],["convbert","ConvBertForMaskedLM"],["camembert","CamembertForMaskedLM"],["deberta","DebertaForMaskedLM"],["deberta-v2","DebertaV2ForMaskedLM"],["mpnet","MPNetForMaskedLM"],["albert","AlbertForMaskedLM"],["distilbert","DistilBertForMaskedLM"],["roberta","RobertaForMaskedLM"],["xlm","XLMWithLMHeadModel"],["xlm-roberta","XLMRobertaForMaskedLM"],["mobilebert","MobileBertForMaskedLM"],["squeezebert","SqueezeBertForMaskedLM"]]),dA=new Map([["bert","BertForQuestionAnswering"],["neobert","NeoBertForQuestionAnswering"],["roformer","RoFormerForQuestionAnswering"],["electra","ElectraForQuestionAnswering"],["convbert","ConvBertForQuestionAnswering"],["camembert","CamembertForQuestionAnswering"],["deberta","DebertaForQuestionAnswering"],["deberta-v2","DebertaV2ForQuestionAnswering"],["mpnet","MPNetForQuestionAnswering"],["albert","AlbertForQuestionAnswering"],["distilbert","DistilBertForQuestionAnswering"],["roberta","RobertaForQuestionAnswering"],["xlm","XLMForQuestionAnswering"],["xlm-roberta","XLMRobertaForQuestionAnswering"],["mobilebert","MobileBertForQuestionAnswering"],["squeezebert","SqueezeBertForQuestionAnswering"]]),fA=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"]]),mA=new Map([["llava","LlavaForConditionalGeneration"],["llava_onevision","LlavaOnevisionForConditionalGeneration"],["moondream1","Moondream1ForConditionalGeneration"],["florence2","Florence2ForConditionalGeneration"],["qwen2-vl","Qwen2VLForConditionalGeneration"],["idefics3","Idefics3ForConditionalGeneration"],["smolvlm","SmolVLMForConditionalGeneration"],["paligemma","PaliGemmaForConditionalGeneration"],["llava_qwen2","LlavaQwen2ForCausalLM"],["gemma3n","Gemma3nForConditionalGeneration"],["mistral3","Mistral3ForConditionalGeneration"]]),hA=new Map([["ultravox","UltravoxModel"],["voxtral","VoxtralForConditionalGeneration"]]),VP=new Map([["vision-encoder-decoder","VisionEncoderDecoderModel"]]),_A=new Map([["vit","ViTForImageClassification"],["ijepa","IJepaForImageClassification"],["pvt","PvtForImageClassification"],["vit_msn","ViTMSNForImageClassification"],["fastvit","FastViTForImageClassification"],["mobilevit","MobileViTForImageClassification"],["mobilevitv2","MobileViTV2ForImageClassification"],["beit","BeitForImageClassification"],["deit","DeiTForImageClassification"],["hiera","HieraForImageClassification"],["convnext","ConvNextForImageClassification"],["convnextv2","ConvNextV2ForImageClassification"],["dinov2","Dinov2ForImageClassification"],["dinov2_with_registers","Dinov2WithRegistersForImageClassification"],["resnet","ResNetForImageClassification"],["swin","SwinForImageClassification"],["segformer","SegformerForImageClassification"],["efficientnet","EfficientNetForImageClassification"],["mobilenet_v1","MobileNetV1ForImageClassification"],["mobilenet_v2","MobileNetV2ForImageClassification"],["mobilenet_v3","MobileNetV3ForImageClassification"],["mobilenet_v4","MobileNetV4ForImageClassification"]]),gA=new Map([["detr","DetrForObjectDetection"],["rt_detr","RTDetrForObjectDetection"],["rt_detr_v2","RTDetrV2ForObjectDetection"],["rf_detr","RFDetrForObjectDetection"],["d_fine","DFineForObjectDetection"],["table-transformer","TableTransformerForObjectDetection"],["yolos","YolosForObjectDetection"]]),wA=new Map([["owlvit","OwlViTForObjectDetection"],["owlv2","Owlv2ForObjectDetection"],["grounding-dino","GroundingDinoForObjectDetection"]]),An=new Map([["detr","DetrForSegmentation"],["clipseg","CLIPSegForImageSegmentation"]]),xA=new Map([["segformer","SegformerForSemanticSegmentation"],["sapiens","SapiensForSemanticSegmentation"],["swin","SwinForSemanticSegmentation"],["mobilenet_v1","MobileNetV1ForSemanticSegmentation"],["mobilenet_v2","MobileNetV2ForSemanticSegmentation"],["mobilenet_v3","MobileNetV3ForSemanticSegmentation"],["mobilenet_v4","MobileNetV4ForSemanticSegmentation"]]),yA=new Map([["detr","DetrForSegmentation"],["maskformer","MaskFormerForInstanceSegmentation"]]),bA=new Map([["sam","SamModel"],["sam2","Sam2Model"],["edgetam","EdgeTamModel"],["sam3_tracker","Sam3TrackerModel"]]),vA=new Map([["wav2vec2","Wav2Vec2ForCTC"],["wav2vec2-bert","Wav2Vec2BertForCTC"],["unispeech","UniSpeechForCTC"],["unispeech-sat","UniSpeechSatForCTC"],["wavlm","WavLMForCTC"],["hubert","HubertForCTC"],["parakeet_ctc","ParakeetForCTC"]]),kA=new Map([["wav2vec2","Wav2Vec2ForSequenceClassification"],["wav2vec2-bert","Wav2Vec2BertForSequenceClassification"],["unispeech","UniSpeechForSequenceClassification"],["unispeech-sat","UniSpeechSatForSequenceClassification"],["wavlm","WavLMForSequenceClassification"],["hubert","HubertForSequenceClassification"],["audio-spectrogram-transformer","ASTForAudioClassification"]]),EA=new Map([["wavlm","WavLMForXVector"]]),AA=new Map([["unispeech-sat","UniSpeechSatForAudioFrameClassification"],["wavlm","WavLMForAudioFrameClassification"],["wav2vec2","Wav2Vec2ForAudioFrameClassification"],["pyannote","PyAnnoteForAudioFrameClassification"]]),MA=new Map([["vitmatte","VitMatteForImageMatting"]]),HP=new Map([["patchtst","PatchTSTForPrediction"],["patchtsmixer","PatchTSMixerForPrediction"]]),TA=new Map([["swin2sr","Swin2SRForImageSuperResolution"]]),SA=new Map([["dpt","DPTForDepthEstimation"],["depth_anything","DepthAnythingForDepthEstimation"],["glpn","GLPNForDepthEstimation"],["sapiens","SapiensForDepthEstimation"],["depth_pro","DepthProForDepthEstimation"],["metric3d","Metric3DForDepthEstimation"],["metric3dv2","Metric3Dv2ForDepthEstimation"]]),OA=new Map([["sapiens","SapiensForNormalEstimation"]]),IA=new Map([["vitpose","VitPoseForPoseEstimation"]]),CA=new Map([["clip","CLIPVisionModelWithProjection"],["siglip","SiglipVisionModel"],["jina_clip","JinaCLIPVisionModel"]]),B0=[[FP,H.EncoderOnly],[jP,H.EncoderDecoder],[qP,H.DecoderOnlyWithoutHead],[GP,H.AutoEncoder],[iA,H.EncoderOnly],[lA,H.EncoderOnly],[cA,H.Seq2Seq],[nA,H.Seq2Seq],[uA,H.DecoderOnly],[WP,H.MultiModality],[pA,H.EncoderOnly],[dA,H.EncoderOnly],[fA,H.Vision2Seq],[mA,H.ImageTextToText],[hA,H.AudioTextToText],[_A,H.EncoderOnly],[An,H.EncoderOnly],[yA,H.EncoderOnly],[xA,H.EncoderOnly],[MA,H.EncoderOnly],[HP,H.EncoderOnly],[TA,H.EncoderOnly],[SA,H.EncoderOnly],[OA,H.EncoderOnly],[IA,H.EncoderOnly],[gA,H.EncoderOnly],[wA,H.EncoderOnly],[bA,H.MaskGeneration],[vA,H.EncoderOnly],[kA,H.EncoderOnly],[oA,H.Seq2Seq],[aA,H.EncoderOnly],[EA,H.EncoderOnly],[AA,H.EncoderOnly],[CA,H.EncoderOnly]];for(let[t,e]of B0)for(let r of t.values()){ws.set(r,e);let s=di[r];gs.set(s,r),Yl.set(r,s)}var XP=[["MusicgenForConditionalGeneration",Ta,H.Musicgen],["Phi3VForCausalLM",Da,H.Phi3V],["CLIPTextModelWithProjection",ko,H.EncoderOnly],["SiglipTextModel",Ya,H.EncoderOnly],["JinaCLIPTextModel",la,H.EncoderOnly],["ClapTextModelWithProjection",bo,H.EncoderOnly],["ClapAudioModelWithProjection",vo,H.EncoderOnly],["DacEncoderModel",Co,H.EncoderOnly],["DacDecoderModel",Po,H.EncoderOnly],["MimiEncoderModel",_a,H.EncoderOnly],["MimiDecoderModel",ga,H.EncoderOnly],["SnacEncoderModel",Ja,H.EncoderOnly],["SnacDecoderModel",Za,H.EncoderOnly],["Gemma3nForConditionalGeneration",Vo,H.ImageAudioTextToText],["SupertonicForConditionalGeneration",ri,H.Supertonic],["ChatterboxModel",yo,H.Chatterbox]];for(let[t,e,r]of XP)ws.set(t,r),gs.set(e,t),Yl.set(t,e);var D0=new Map([["modnet",An],["birefnet",An],["isnet",An],["ben",An]]);for(let[t,e]of D0.entries())e.set(t,"PreTrainedModel"),ws.set(t,H.EncoderOnly),Yl.set(t,y);ws.set("PreTrainedModel",H.EncoderOnly);gs.set(y,"PreTrainedModel");var Ie={MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES:iA,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES:lA,MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES:oA,MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES:aA,MODEL_FOR_MASKED_LM_MAPPING_NAMES:pA,MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES:dA,MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES:_A,MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES:An,MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES:xA,MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES:yA,MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES:gA,MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES:wA,MODEL_FOR_MASK_GENERATION_MAPPING_NAMES:bA,MODEL_FOR_CTC_MAPPING_NAMES:vA,MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES:kA,MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES:EA,MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES:AA,MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES:VP,MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES:MA,MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES:TA,MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES:SA,MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES:OA,MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES:IA,MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES:CA,MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES:mA,MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES:hA,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES:cA,MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES:nA,MODEL_FOR_CAUSAL_LM_MAPPING_NAMES:uA,MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES:fA};eA(Ie);var Se=class{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",model_file_name:i=null,subfolder:l="onnx",device:u=null,dtype:d=null,use_external_data_format:f=null,session_options:m={}}={}){let _={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,model_file_name:i,subfolder:l,device:u,dtype:d,use_external_data_format:f,session_options:m};if(_.config=await ms.from_pretrained(e,_),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);let w=_.config.model_type;for(let x of this.MODEL_CLASS_MAPPINGS){let k=x.get(w);if(!k){for(let E of x.values())if(E[0]===w){k=E;break}if(!k)continue}return await di[k].from_pretrained(e,_)}if(this.BASE_IF_FAIL)return D0.has(w)||console.warn(`Unknown model class "${w}", attempting to construct from base class.`),await y.from_pretrained(e,_);throw Error(`Unsupported model type: ${w}`)}},wr=class extends Se{static MODEL_CLASS_MAPPINGS=B0.map(e=>e[0]);static BASE_IF_FAIL=!0},fi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]},Qc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]},Mn=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]},Jc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]},Zc=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]},eu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]},tu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_CAUSAL_LM_MAPPING_NAMES]},ru=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_MASKED_LM_MAPPING_NAMES]},su=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]},nu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]},ou=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]},mi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]},hi=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]},_i=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING_NAMES]},au=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]},iu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]},PA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_MASK_GENERATION_MAPPING_NAMES]},lu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_CTC_MAPPING_NAMES]},cu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]},zA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES]},LA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES]},uu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]},NA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES]},pu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]},du=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]},$A=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_NORMAL_ESTIMATION_MAPPING_NAMES]},RA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_POSE_ESTIMATION_MAPPING_NAMES]},fu=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_FEATURE_EXTRACTION_MAPPING_NAMES]},UA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES]},BA=class extends Se{static MODEL_CLASS_MAPPINGS=[Ie.MODEL_FOR_AUDIO_TEXT_TO_TEXT_MAPPING_NAMES]};async function Ye(t){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(e=>Xe.read(e)))}async function Wr(t,e){return Array.isArray(t)||(t=[t]),await Promise.all(t.map(r=>typeof r=="string"||r instanceof URL?xf(r,e):r instanceof Float64Array?new Float32Array(r):r))}function gi(t,e){e&&(t=t.map(a=>a|0));let[r,s,n,o]=t;return{xmin:r,ymin:s,xmax:n,ymax:o}}var pe=class extends Je{constructor({task:e,model:r,tokenizer:s=null,processor:n=null}){super(),this.task=e,this.model=r,this.tokenizer=s,this.processor=n}async dispose(){await this.model.dispose()}};var mu=class extends pe{async _call(e,{top_k:r=1}={}){let s=this.tokenizer(e,{padding:!0,truncation:!0}),n=await this.model(s),{problem_type:o,id2label:a}=this.model.config,i=o==="multi_label_classification"?u=>u.sigmoid():u=>new U("float32",Pe(u.data),u.dims),l=[];for(let u of n.logits){let d=i(u),f=await Yt(d,r),m=f[0].tolist(),w=f[1].tolist().map((x,k)=>({label:a?a[x]:`LABEL_${x}`,score:m[k]}));r===1?l.push(...w):l.push(w)}return Array.isArray(e)||r===1?l:l[0]}};var hu=class extends pe{async _call(e,{ignore_labels:r=["O"]}={}){let s=Array.isArray(e),n=this.tokenizer(s?e:[e],{padding:!0,truncation:!0}),a=(await this.model(n)).logits,i=this.model.config.id2label,l=[];for(let u=0;u<a.dims[0];++u){let d=n.input_ids[u],f=a[u],m=[];for(let _=0;_<f.dims[0];++_){let w=f[_],x=Te(w.data)[1],k=i?i[x]:`LABEL_${x}`;if(r.includes(k))continue;let E=this.tokenizer.decode([d[_].item()],{skip_special_tokens:!0});if(E==="")continue;let M=Pe(w.data);m.push({entity:k,score:M[x],index:_,word:E})}l.push(m)}return s?l:l[0]}};var _u=class extends pe{async _call(e,r,{top_k:s=1}={}){let n=this.tokenizer(e,{text_pair:r,padding:!0,truncation:!0}),o=Array.isArray(e),{start_logits:a,end_logits:i}=await this.model(n),l=n.input_ids.tolist(),u=n.attention_mask.tolist(),{all_special_ids:d,sep_token_id:f}=this.tokenizer,m=[];for(let _=0;_<a.dims[0];++_){let w=l[_],x=w.findIndex(C=>C==f),k=a[_].tolist(),E=i[_].tolist();for(let C=1;C<k.length;++C)(u[_]==0||C<=x||d.findIndex(v=>v==w[C])!==-1)&&(k[C]=-1/0,E[C]=-1/0);let M=Pe(k).map((C,v)=>[C,v]),I=Pe(E).map((C,v)=>[C,v]);M[0][0]=0,I[0][0]=0;let T=zv(M,I).filter(C=>C[0][1]<=C[1][1]).map(C=>[C[0][1],C[1][1],C[0][0]*C[1][0]]).sort((C,v)=>v[2]-C[2]),z=[];for(let C=0;C<Math.min(T.length,s);++C){let[v,G,X]=T[C],V=w.slice(v,G+1),Q=this.tokenizer.decode(V,{skip_special_tokens:!0});z.push({answer:Q,score:X})}s===1?m.push(...z):m.push(z)}return o?m:m[0]}};var gu=class extends pe{async _call(e,{top_k:r=5}={}){let{mask_token_id:s,mask_token:n}=this.tokenizer,o=this.tokenizer(e,{padding:!0,truncation:!0}),{logits:a}=await this.model(o),i=[],l=o.input_ids.tolist();for(let u=0;u<l.length;++u){let d=l[u],f=d.findIndex(k=>k==s);if(f===-1)throw Error(`Mask token (${n}) not found in text.`);let m=a[u][f],_=await Yt(new U("float32",Pe(m.data),m.dims),r),w=_[0].tolist(),x=_[1].tolist();i.push(x.map((k,E)=>{let M=d.slice();return M[f]=k,{score:w[E],token:Number(k),token_str:this.tokenizer.decode([k]),sequence:this.tokenizer.decode(M,{skip_special_tokens:!0})}}))}return Array.isArray(e)?i:i[0]}};var Vr=class extends pe{_key="generated_text";async _call(e,r={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(l=>this.model.config.prefix+l));let s=this.model.config.task_specific_params;s&&s[this.task]&&s[this.task].prefix&&(e=e.map(l=>s[this.task].prefix+l));let n=this.tokenizer,o={padding:!0,truncation:!0},a;this.task==="translation"&&"_build_translation_inputs"in n?a=n._build_translation_inputs(e,o,r):a=n(e,o);let i=await this.model.generate({...a,...r});return n.batch_decode(i,{skip_special_tokens:!0}).map(l=>({[this._key]:l}))}};var wu=class extends Vr{_key="summary_text"};var xu=class extends Vr{_key="translation_text"};function DA(t){return Array.isArray(t)&&t.every(e=>"role"in e&&"content"in e)}var yu=class extends pe{async _call(e,r={}){let s=!1,n=!1,o=r.add_special_tokens??(this.tokenizer.add_bos_token||this.tokenizer.add_eos_token)??!1,a=r.tokenizer_encode_kwargs,i;if(typeof e=="string")i=e=[e];else if(Array.isArray(e)&&e.every(w=>typeof w=="string"))s=!0,i=e;else{if(DA(e))e=[e];else if(Array.isArray(e)&&e.every(DA))s=!0;else throw new Error("Input must be a string, an array of strings, a Chat, or an array of Chats");n=!0,i=e.map(w=>this.tokenizer.apply_chat_template(w,{tokenize:!1,add_generation_prompt:!0,...a})),o=!1,a=void 0}let l=n?!1:r.return_full_text??!0;this.tokenizer.padding_side="left";let u=this.tokenizer(i,{add_special_tokens:o,padding:!0,truncation:!0,...a}),d=await this.model.generate({...u,...r}),f=this.tokenizer.batch_decode(d,{skip_special_tokens:!0}),m;!l&&u.input_ids.dims.at(-1)>0&&(m=this.tokenizer.batch_decode(u.input_ids,{skip_special_tokens:!0}).map(w=>w.length));let _=Array.from({length:e.length},w=>[]);for(let w=0;w<f.length;++w){let x=Math.floor(w/d.dims[0]*e.length);m&&(f[w]=f[w].slice(m[x])),_[x].push({generated_text:n?[...e[x],{role:"assistant",content:f[w]}]:f[w]})}return!s&&_.length===1?_[0]:_}};var bu=class extends pe{constructor(e){super(e),this.label2id=Object.fromEntries(Object.entries(this.model.config.label2id).map(([r,s])=>[r.toLowerCase(),s])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,r,{hypothesis_template:s="This example is {}.",multi_label:n=!1}={}){let o=Array.isArray(e);o||(e=[e]),Array.isArray(r)||(r=[r]);let a=r.map(u=>s.replace("{}",u)),i=n||r.length===1,l=[];for(let u of e){let d=[];for(let _ of a){let w=this.tokenizer(u,{text_pair:_,padding:!0,truncation:!0}),x=await this.model(w);i?d.push([x.logits.data[this.contradiction_id],x.logits.data[this.entailment_id]]):d.push(x.logits.data[this.entailment_id])}let m=(i?d.map(_=>Pe(_)[1]):Pe(d)).map((_,w)=>[_,w]).sort((_,w)=>w[0]-_[0]);l.push({sequence:u,labels:m.map(_=>r[_[1]]),scores:m.map(_=>_[0])})}return o?l:l[0]}};var vu=class extends pe{async _call(e,{top_k:r=5}={}){let s=this.processor.feature_extractor.config.sampling_rate,n=await Wr(e,s),o=this.model.config.id2label,a=[];for(let i of n){let l=await this.processor(i),d=(await this.model(l)).logits[0],f=await Yt(new U("float32",Pe(d.data),d.dims),r),m=f[0].tolist(),w=f[1].tolist().map((x,k)=>({label:o?o[x]:`LABEL_${x}`,score:m[k]}));a.push(w)}return Array.isArray(e)?a:a[0]}};var ku=class extends pe{async _call(e,r,{hypothesis_template:s="This is a sound of {}."}={}){let n=!Array.isArray(e);n&&(e=[e]);let o=r.map(d=>s.replace("{}",d)),a=this.tokenizer(o,{padding:!0,truncation:!0}),i=this.processor.feature_extractor.config.sampling_rate,l=await Wr(e,i),u=[];for(let d of l){let f=await this.processor(d),m=await this.model({...a,...f}),_=Pe(m.logits_per_audio.data);u.push([..._].map((w,x)=>({score:w,label:r[x]})))}return n?u[0]:u}};var Eu=class extends pe{async _call(e,r={}){switch(this.model.config.model_type){case"whisper":case"lite-whisper":return this._call_whisper(e,r);case"wav2vec2":case"wav2vec2-bert":case"unispeech":case"unispeech-sat":case"hubert":case"parakeet_ctc":return this._call_wav2vec2(e,r);case"moonshine":return this._call_moonshine(e,r);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,r){r.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),r.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');let s=!Array.isArray(e),n=s?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,a=await Wr(n,o),i=[];for(let l of a){let u=await this.processor(l),f=(await this.model(u)).logits[0],m=[];for(let w of f)m.push(Te(w.data)[1]);let _=this.tokenizer.decode(m,{skip_special_tokens:!0}).trim();i.push({text:_})}return s?i[0]:i}async _call_whisper(e,r){let s=r.return_timestamps??!1,n=r.chunk_length_s??0,o=r.force_full_sequences??!1,a=r.stride_length_s??null,i={...r};s==="word"&&(i.return_token_timestamps=!0,i.return_timestamps=!1);let l=!Array.isArray(e),u=l?[e]:e,d=this.processor.feature_extractor.config,f=d.chunk_length/this.model.config.max_source_positions,m=d.hop_length,_=d.sampling_rate,w=await Wr(u,_),x=[];for(let k of w){let E=[];if(n>0){if(a===null)a=n/6;else if(n<=a)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");let T=_*n,z=_*a,C=T-2*z,v=0;for(;;){let G=v+T,X=k.subarray(v,G),V=await this.processor(X),Q=v===0,K=G>=k.length;if(E.push({stride:[X.length,Q?0:z,K?0:z],input_features:V.input_features,is_last:K}),K)break;v+=C}}else E=[{stride:[k.length,0,0],input_features:(await this.processor(k)).input_features,is_last:!0}];for(let T of E){i.num_frames=Math.floor(T.stride[0]/m);let z=await this.model.generate({inputs:T.input_features,...i});s==="word"?(T.tokens=z.sequences.tolist()[0],T.token_timestamps=z.token_timestamps.tolist()[0].map(C=>rs(C,2))):T.tokens=z[0].tolist(),T.stride=T.stride.map(C=>C/_)}let[M,I]=this.tokenizer._decode_asr(E,{time_precision:f,return_timestamps:s,force_full_sequences:o});x.push({text:M,...I})}return l?x[0]:x}async _call_moonshine(e,r){let s=!Array.isArray(e),n=s?[e]:e,o=this.processor.feature_extractor.config.sampling_rate,a=await Wr(n,o),i=[];for(let l of a){let u=await this.processor(l),d=Math.floor(l.length/o)*6,f=await this.model.generate({max_new_tokens:d,...r,...u}),m=this.processor.batch_decode(f,{skip_special_tokens:!0})[0];i.push({text:m})}return s?i[0]:i}};var Au=class extends pe{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _prepare_speaker_embeddings(e,r){if((typeof e=="string"||e instanceof URL)&&(e=new Float32Array(await(await fetch(e)).arrayBuffer())),e instanceof Float32Array)e=new U("float32",e,[e.length]);else if(!(e instanceof U))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");if(r>1){if(e.dims[0]===1)e=e.repeat(r,1);else if(e.dims[0]!==r)throw new Error(`Expected speaker embeddings batch size to be 1 or ${r}, but got ${e.dims[0]}.`)}return e}_postprocess_waveform(e,r,s,n=null){let o=r.data,[a,i]=r.dims,l=n?n.data:null,u=[];for(let d=0;d<a;++d){let f=l?Math.min(Math.ceil(l[d]),i):i,m=d*i;u.push(new to(o.slice(m,m+f),s))}return Array.isArray(e)?u:u[0]}async _call(e,r){return this.processor?this._call_text_to_spectrogram(e,r):this.model.config.model_type==="supertonic"?this._call_supertonic(e,r):this._call_text_to_waveform(e)}async _call_supertonic(e,{speaker_embeddings:r,num_inference_steps:s,speed:n}){if(!r)throw new Error("Speaker embeddings must be provided for Supertonic models.");let{sampling_rate:o,style_dim:a}=this.model.config,i=this.tokenizer(e,{padding:!0,truncation:!0}),l=i.input_ids.dims[0];r=await this._prepare_speaker_embeddings(r,l),r=r.view(l,-1,a);let{waveform:u,durations:d}=await this.model.generate_speech({...i,style:r,num_inference_steps:s,speed:n});return this._postprocess_waveform(e,u,o,d)}async _call_text_to_waveform(e){let r=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:s}=await this.model(r),n=this.model.config.sampling_rate;return this._postprocess_waveform(e,s,n)}async _call_text_to_spectrogram(e,{speaker_embeddings:r}){this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await wr.from_pretrained(this.DEFAULT_VOCODER_ID,{dtype:"fp32"}));let{input_ids:s}=this.tokenizer(e,{padding:!0,truncation:!0}),n=s.dims[0];r=await this._prepare_speaker_embeddings(r,n),r=r.view(n,-1);let{waveform:o}=await this.model.generate_speech(s,r,{vocoder:this.vocoder}),a=this.processor.feature_extractor.config.sampling_rate;return this._postprocess_waveform(e,o,a)}};var Mu=class extends pe{async _call(e,r={}){let s=Array.isArray(e),n=await Ye(e),{pixel_values:o}=await this.processor(n),a=[];for(let i of o){i.dims=[1,...i.dims];let l=await this.model.generate({inputs:i,...r}),u=this.tokenizer.batch_decode(l,{skip_special_tokens:!0}).map(d=>({generated_text:d.trim()}));a.push(u)}return s?a:a[0]}};var Tu=class extends pe{async _call(e,{top_k:r=5}={}){let s=await Ye(e),{pixel_values:n}=await this.processor(s),o=await this.model({pixel_values:n}),{id2label:a}=this.model.config,i=[];for(let l of o.logits){let u=await Yt(new U("float32",Pe(l.data),l.dims),r),d=u[0].tolist(),m=u[1].tolist().map((_,w)=>({label:a?a[_]:`LABEL_${_}`,score:d[w]}));i.push(m)}return Array.isArray(e)?i:i[0]}};var FA={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"},Tn=class extends pe{async _call(e,{threshold:r=.5,mask_threshold:s=.5,overlap_mask_area_threshold:n=.8,label_ids_to_fuse:o=null,target_sizes:a=null,subtask:i=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");let u=await Ye(e),d=u.map(M=>[M.height,M.width]),f=await this.processor(u),{inputNames:m,outputNames:_}=this.model.sessions.model;if(!m.includes("pixel_values")){if(m.length!==1)throw Error(`Expected a single input name, but got ${m.length} inputs: ${m}.`);let M=m[0];if(M in f)throw Error(`Input name ${M} already exists in the inputs.`);f[M]=f.pixel_values}let w=await this.model(f),x=null;if(i!==null)x=FA[i];else if(this.processor.image_processor){for(let[M,I]of Object.entries(FA))if(I in this.processor.image_processor){x=this.processor.image_processor[I].bind(this.processor.image_processor),i=M;break}}let k=this.model.config.id2label,E=[];if(i)if(i==="panoptic"||i==="instance"){let M=x(w,r,s,n,o,a??d)[0],I=M.segmentation;for(let T of M.segments_info){let z=new Uint8ClampedArray(I.data.length);for(let v=0;v<I.data.length;++v)I.data[v]===T.id&&(z[v]=255);let C=new Xe(z,I.dims[1],I.dims[0],1);E.push({score:T.score,label:k[T.label_id],mask:C})}}else if(i==="semantic"){let{segmentation:M,labels:I}=x(w,a??d)[0];for(let T of I){let z=new Uint8ClampedArray(M.data.length);for(let v=0;v<M.data.length;++v)M.data[v]===T&&(z[v]=255);let C=new Xe(z,M.dims[1],M.dims[0],1);E.push({score:null,label:k[T],mask:C})}}else throw Error(`Subtask ${i} not supported.`);else{let I=w[_[0]];for(let T=0;T<d.length;++T){let z=d[T],C=I[T];C.data.some(G=>G<-1e-5||G>1+1e-5)&&C.sigmoid_();let v=await Xe.fromTensor(C.mul_(255).to("uint8")).resize(z[1],z[0]);E.push({label:null,score:null,mask:v})}}return E}};var Su=class extends Tn{async _call(e,r={}){let s=await Ye(e),n=await super._call(e,r),o=s.map((a,i)=>{let l=a.clone();return l.putAlpha(n[i].mask),l});return Array.isArray(e)?o:o[0]}};var Ou=class extends pe{async _call(e,r,{hypothesis_template:s="This is a photo of {}"}={}){let n=Array.isArray(e),o=await Ye(e),a=r.map(m=>s.replace("{}",m)),i=this.tokenizer(a,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:l}=await this.processor(o),u=await this.model({...i,pixel_values:l}),d=this.model.config.model_type==="siglip"?m=>m.sigmoid().data:m=>Pe(m.data),f=[];for(let m of u.logits_per_image){let w=[...d(m)].map((x,k)=>({score:x,label:r[k]}));w.sort((x,k)=>k.score-x.score),f.push(w)}return n?f:f[0]}};var Iu=class extends pe{async _call(e,{threshold:r=.9,percentage:s=!1}={}){let n=Array.isArray(e);if(n&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");let o=await Ye(e),a=s?null:o.map(_=>[_.height,_.width]),{pixel_values:i,pixel_mask:l}=await this.processor(o),u=await this.model({pixel_values:i,pixel_mask:l}),d=this.processor.image_processor.post_process_object_detection(u,r,a),{id2label:f}=this.model.config,m=d.map(_=>_.boxes.map((w,x)=>({score:_.scores[x],label:f[_.classes[x]],box:gi(w,!s)})));return n?m:m[0]}};var Cu=class extends pe{async _call(e,r,{threshold:s=.1,top_k:n=null,percentage:o=!1}={}){let a=Array.isArray(e),i=await Ye(e),l=this.tokenizer(r,{padding:!0,truncation:!0}),u=await this.processor(i),d=[];for(let f=0;f<i.length;++f){let m=i[f],_=o?null:[[m.height,m.width]],w=u.pixel_values[f].unsqueeze_(0),x=await this.model({...l,pixel_values:w}),k;if("post_process_grounded_object_detection"in this.processor){let E=this.processor.post_process_grounded_object_detection(x,l.input_ids,{box_threshold:s,text_threshold:s,target_sizes:_})[0];k=E.boxes.map((M,I)=>({score:E.scores[I],label:E.labels[I],box:gi(M,!o)}))}else{let E=this.processor.image_processor.post_process_object_detection(x,s,_,!0)[0];k=E.boxes.map((M,I)=>({score:E.scores[I],label:r[E.classes[I]],box:gi(M,!o)}))}k.sort((E,M)=>M.score-E.score),n!==null&&(k=k.slice(0,n)),d.push(k)}return a?d:d[0]}};var Pu=class extends pe{async _call(e,r,s={}){if(Array.isArray(e)){if(e.length!==1)throw Error("Document Question Answering pipeline currently only supports a batch size of 1.");e=e[0]}let n=(await Ye(e))[0],{pixel_values:o}=await this.processor(n),a=`<s_docvqa><s_question>${r}</s_question><s_answer>`,i=this.tokenizer(a,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,l=await this.model.generate({inputs:o,max_length:this.model.config.decoder.max_position_embeddings,decoder_input_ids:i,...s}),d=this.tokenizer.batch_decode(l)[0].match(/<s_answer>(.*?)<\/s_answer>/),f=null;return d&&d.length>=2&&(f=d[1].trim()),[{answer:f}]}};var zu=class extends pe{async _call(e){let r=await Ye(e),s=await this.processor(r),n=await this.model(s),o=[];for(let a of n.reconstruction){let i=a.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");o.push(Xe.fromTensor(i))}return Array.isArray(e)?o:o[0]}};var Lu=class extends pe{async _call(e){let r=await Ye(e),s=await this.processor(r),{predicted_depth:n}=await this.model(s),o=[];for(let a=0;a<r.length;++a){let i=n[a],[l,u]=i.dims.slice(-2),[d,f]=r[a].size,m=(await Dt(i.view(1,1,l,u),{size:[f,d],mode:"bilinear"})).view(f,d),_=m.min().item(),w=m.max().item(),x=m.sub(_).div_(w-_).mul_(255).to("uint8").unsqueeze(0),k=Xe.fromTensor(x);o.push({predicted_depth:m,depth:k})}return Array.isArray(e)?o:o[0]}};var Nu=class extends pe{async _call(e,{pooling:r="none",normalize:s=!1,quantize:n=!1,precision:o="binary"}={}){let a=this.tokenizer(e,{padding:!0,truncation:!0}),i=await this.model(a),l=i.last_hidden_state??i.logits??i.token_embeddings;switch(r){case"none":break;case"mean":l=CE(l,a.attention_mask);break;case"first_token":case"cls":l=l.slice(null,0);break;case"last_token":case"eos":l=l.slice(null,-1);break;default:throw Error(`Pooling method '${r}' not supported.`)}return s&&(l=l.normalize(2,-1)),n&&(l=zE(l,o)),l}};var $u=class extends pe{async _call(e,{pool:r=null}={}){let s=await Ye(e),{pixel_values:n}=await this.processor(s),o=await this.model({pixel_values:n}),a;if(r){if(!("pooler_output"in o))throw Error("No pooled output was returned. Make sure the model has a 'pooler' layer when using the 'pool' option.");a=o.pooler_output}else a=o.last_hidden_state??o.logits??o.image_embeds;return a}};var jA=Object.freeze({"text-classification":{tokenizer:J,pipeline:mu,model:fi,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:J,pipeline:hu,model:Qc,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:J,pipeline:_u,model:su,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:J,pipeline:gu,model:ru,default:{model:"onnx-community/ettin-encoder-32m-ONNX",dtype:"fp32"},type:"text"},summarization:{tokenizer:J,pipeline:wu,model:Mn,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:J,pipeline:xu,model:Mn,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:J,pipeline:Vr,model:Mn,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:J,pipeline:yu,model:tu,default:{model:"onnx-community/Qwen3-0.6B-ONNX",dtype:"q4"},type:"text"},"zero-shot-classification":{tokenizer:J,pipeline:bu,model:fi,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:vu,model:cu,processor:ut,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:J,pipeline:ku,model:wr,processor:ut,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:J,pipeline:Eu,model:[Jc,lu],processor:ut,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:J,pipeline:Au,model:[eu,Zc],processor:[ut,null],default:{model:"onnx-community/Supertonic-TTS-ONNX",dtype:"fp32"},type:"text"},"image-to-text":{tokenizer:J,pipeline:Mu,model:nu,processor:ut,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:Tu,model:ou,processor:ut,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:Tn,model:[mi,hi,_i],processor:ut,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"background-removal":{pipeline:Su,model:[mi,hi,_i],processor:ut,default:{model:"Xenova/modnet"},type:"image"},"zero-shot-image-classification":{tokenizer:J,pipeline:Ou,model:wr,processor:ut,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:Iu,model:au,processor:ut,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:J,pipeline:Cu,model:iu,processor:ut,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:J,pipeline:Pu,model:uu,processor:ut,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:zu,model:pu,processor:ut,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:Lu,model:du,processor:ut,default:{model:"onnx-community/depth-anything-v2-small"},type:"image"},"feature-extraction":{tokenizer:J,pipeline:Nu,model:wr,default:{model:"onnx-community/all-MiniLM-L6-v2-ONNX",dtype:"fp32"},type:"text"},"image-feature-extraction":{processor:ut,pipeline:$u,model:[fu,wr],default:{model:"onnx-community/dinov3-vits16-pretrain-lvd1689m-ONNX",dtype:"fp32"},type:"image"}}),KP=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function Eee(t,e=null,{progress_callback:r=null,config:s=null,cache_dir:n=null,local_files_only:o=!1,revision:a="main",device:i=null,dtype:l=null,subfolder:u="onnx",use_external_data_format:d=null,model_file_name:f=null,session_options:m={}}={}){t=KP[t]??t;let _=jA[t.split("_",1)[0]];if(!_)throw Error(`Unsupported pipeline: ${t}. Must be one of [${Object.keys(jA)}]`);e||(e=_.default.model,console.log(`No model specified. Using default model: "${e}".`),!l&&_.default.dtype&&(l=_.default.dtype));let w={progress_callback:r,config:s,cache_dir:n,local_files_only:o,revision:a,device:i,dtype:l,subfolder:u,use_external_data_format:d,model_file_name:f,session_options:m},x=new Map([["tokenizer",_.tokenizer],["model",_.model],["processor",_.processor]]),k=await YP(x,e,w);k.task=t,hr(r,{status:"ready",task:t,model:e});let E=_.pipeline;return new E(k)}async function YP(t,e,r){let s=Object.create(null),n=[];for(let[o,a]of t.entries()){if(!a)continue;let i;Array.isArray(a)?i=new Promise(async(l,u)=>{let d;for(let f of a){if(f===null){l(null);return}try{l(await f.from_pretrained(e,r));return}catch(m){if(m.message?.includes("Unsupported model type"))d=m;else if(m.message?.includes("Could not locate file"))d=m;else{u(m);return}}}u(d)}):i=a.from_pretrained(e,r),s[o]=i,n.push(i)}await Promise.all(n);for(let[o,a]of Object.entries(s))s[o]=await a;return s}var QP=t=>t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791||t>=173824&&t<=177983||t>=177984&&t<=178207||t>=178208&&t<=183983||t>=63744&&t<=64255||t>=194560&&t<=195103,F0=class{put(e){throw Error("Not implemented")}end(){throw Error("Not implemented")}},GA=be.IS_PROCESS_AVAILABLE?t=>process.stdout.write(t):t=>console.log(t),j0=class extends F0{constructor(e,{skip_prompt:r=!1,callback_function:s=null,token_callback_function:n=null,skip_special_tokens:o=!0,decode_kwargs:a={},...i}={}){super(),this.tokenizer=e,this.skip_prompt=r,this.callback_function=s??GA,this.token_callback_function=n,this.decode_kwargs={skip_special_tokens:o,...a,...i},this.token_cache=[],this.print_len=0,this.next_tokens_are_prompt=!0,this.special_ids=new Set(this.tokenizer.all_special_ids.map(BigInt))}put(e){if(e.length>1)throw Error("TextStreamer only supports batch size of 1");let r=this.next_tokens_are_prompt;if(r&&(this.next_tokens_are_prompt=!1,this.skip_prompt))return;let s=e[0];if(this.token_callback_function?.(s),s.length===1&&this.special_ids.has(s[0])){if(this.decode_kwargs.skip_special_tokens)return;if(this.token_cache.length>0){let l=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len);this.on_finalized_text(l,!1),this.token_cache=[],this.print_len=0}let a=this.tokenizer.decode(s,this.decode_kwargs);this.on_finalized_text(a,!1);return}this.token_cache=dt(this.token_cache,s);let n=this.tokenizer.decode(this.token_cache,this.decode_kwargs),o;r||n.endsWith(`
28
28
  `)?(o=n.slice(this.print_len),this.token_cache=[],this.print_len=0):n.length>0&&QP(n.charCodeAt(n.length-1))?(o=n.slice(this.print_len),this.print_len+=o.length):(o=n.slice(this.print_len,n.lastIndexOf(" ")+1),this.print_len+=o.length),this.on_finalized_text(o,!1)}end(){let e;this.token_cache.length>0?(e=this.tokenizer.decode(this.token_cache,this.decode_kwargs).slice(this.print_len),this.token_cache=[],this.print_len=0):e="",this.next_tokens_are_prompt=!0,this.on_finalized_text(e,!0)}on_finalized_text(e,r){e.length>0&&this.callback_function?.(e),r&&this.callback_function===GA&&be.IS_PROCESS_AVAILABLE&&this.callback_function?.(`
29
29
  `)}},qA=class extends j0{constructor(e,{skip_prompt:r=!1,callback_function:s=null,token_callback_function:n=null,on_chunk_start:o=null,on_chunk_end:a=null,on_finalize:i=null,time_precision:l=.02,skip_special_tokens:u=!0,decode_kwargs:d={}}={}){super(e,{skip_prompt:r,skip_special_tokens:u,callback_function:s,token_callback_function:n,decode_kwargs:d}),this.timestamp_begin=e.timestamp_begin,this.on_chunk_start=o,this.on_chunk_end=a,this.on_finalize=i,this.time_precision=l,this.waiting_for_timestamp=!1}put(e){if(e.length>1)throw Error("WhisperTextStreamer only supports batch size of 1");let r=e[0];if(r.length===1){let s=Number(r[0])-this.timestamp_begin;if(s>=0){let n=s*this.time_precision;this.waiting_for_timestamp?this.on_chunk_end?.(n):this.on_chunk_start?.(n),this.waiting_for_timestamp=!this.waiting_for_timestamp,this.token_callback_function?.(r);return}}return super.put(e)}end(){super.end(),this.on_finalize?.()}};var wi=class{constructor(e,r){this.image=e,this.timestamp=r}},Ru=class{constructor(e,r){e.length>0&&e[0]instanceof Xe&&(e=e.map((s,n)=>new wi(s,(n+1)/(e.length+1)*r))),this.frames=e,this.duration=r}get width(){return this.frames[0].image.width}get height(){return this.frames[0].image.height}get fps(){return this.frames.length/this.duration}};async function JP(t,{num_frames:e=null,fps:r=null}={}){if(!be.IS_BROWSER_ENV)throw new Error("`load_video` is currently only supported in browser environments.");if(e==null&&r==null)throw new Error("Either num_frames or fps must be provided.");let s=[],n=document.createElement("video");if(n.crossOrigin="anonymous",n.muted=!0,typeof t=="string")n.src=t;else if(t instanceof Blob)n.src=URL.createObjectURL(t);else if(t instanceof HTMLVideoElement)n.src=t.src;else throw new Error("Invalid URL or video element provided.");if(await new Promise(f=>n.onloadedmetadata=f),n.seekable.start(0)===n.seekable.end(0)){let m=await(await fetch(n.src)).blob();n.src=URL.createObjectURL(m),await new Promise(_=>n.onloadedmetadata=_)}let o=n.duration,a,i;e!=null?(a=e,i=e===1?0:o/(e-1)):(i=1/r,a=Math.floor(o/i));let l=[];for(let f=0;f<a;++f)l.push(e===1?o/2:f*i);let u=document.createElement("canvas");u.width=n.videoWidth,u.height=n.videoHeight;let d=u.getContext("2d",{willReadFrequently:!0});for(let f of l){n.currentTime=f,await new Promise(x=>{n.onseeked=x}),d.drawImage(n,0,0,u.width,u.height);let m=d.getImageData(0,0,u.width,u.height),_=new Xe(m.data,u.width,u.height,4),w=new wi(_,f);s.push(w)}return n.remove(),new Ru(s,o)}export{yf as ASTFeatureExtractor,oh as ASTForAudioClassification,nh as ASTModel,ho as ASTPreTrainedModel,Zm as AlbertForMaskedLM,Jm as AlbertForQuestionAnswering,Qm as AlbertForSequenceClassification,Ym as AlbertModel,xs as AlbertPreTrainedModel,Md as AlbertTokenizer,th as ApertusForCausalLM,eh as ApertusModel,fo as ApertusPreTrainedModel,sh as ArceeForCausalLM,rh as ArceeModel,mo as ArceePreTrainedModel,vu as AudioClassificationPipeline,ms as AutoConfig,tt as AutoFeatureExtractor,$e as AutoImageProcessor,wr as AutoModel,cu as AutoModelForAudioClassification,LA as AutoModelForAudioFrameClassification,BA as AutoModelForAudioTextToText,lu as AutoModelForCTC,tu as AutoModelForCausalLM,du as AutoModelForDepthEstimation,uu as AutoModelForDocumentQuestionAnswering,ou as AutoModelForImageClassification,fu as AutoModelForImageFeatureExtraction,NA as AutoModelForImageMatting,mi as AutoModelForImageSegmentation,UA as AutoModelForImageTextToText,pu as AutoModelForImageToImage,PA as AutoModelForMaskGeneration,ru as AutoModelForMaskedLM,$A as AutoModelForNormalEstimation,au as AutoModelForObjectDetection,RA as AutoModelForPoseEstimation,su as AutoModelForQuestionAnswering,hi as AutoModelForSemanticSegmentation,Mn as AutoModelForSeq2SeqLM,fi as AutoModelForSequenceClassification,Jc as AutoModelForSpeechSeq2Seq,Zc as AutoModelForTextToSpectrogram,eu as AutoModelForTextToWaveform,Qc as AutoModelForTokenClassification,_i as AutoModelForUniversalSegmentation,nu as AutoModelForVision2Seq,zA as AutoModelForXVector,iu as AutoModelForZeroShotObjectDetection,ut as AutoProcessor,J as AutoTokenizer,Eu as AutomaticSpeechRecognitionPipeline,Su as BackgroundRemovalPipeline,ih as BartForConditionalGeneration,lh as BartForSequenceClassification,ah as BartModel,on as BartPretrainedModel,Td as BartTokenizer,F0 as BaseStreamer,$f as BeitFeatureExtractor,uh as BeitForImageClassification,ch as BeitModel,_o as BeitPreTrainedModel,dh as BertForMaskedLM,hh as BertForQuestionAnswering,fh as BertForSequenceClassification,mh as BertForTokenClassification,ph as BertModel,Cr as BertPreTrainedModel,Sd as BertTokenizer,Rf as BitImageProcessor,gh as BlenderbotForConditionalGeneration,_h as BlenderbotModel,go as BlenderbotPreTrainedModel,xh as BlenderbotSmallForConditionalGeneration,wh as BlenderbotSmallModel,wo as BlenderbotSmallPreTrainedModel,Od as BlenderbotSmallTokenizer,Id as BlenderbotTokenizer,bh as BloomForCausalLM,yh as BloomModel,xo as BloomPreTrainedModel,Cd as BloomTokenizer,Bf as CLIPFeatureExtractor,fl as CLIPImageProcessor,Oh as CLIPModel,ir as CLIPPreTrainedModel,Lh as CLIPSegForImageSegmentation,zh as CLIPSegModel,Eo as CLIPSegPreTrainedModel,Ih as CLIPTextModel,ko as CLIPTextModelWithProjection,zd as CLIPTokenizer,Ch as CLIPVisionModel,Ph as CLIPVisionModelWithProjection,kh as CamembertForMaskedLM,Mh as CamembertForQuestionAnswering,Eh as CamembertForSequenceClassification,Ah as CamembertForTokenClassification,vh as CamembertModel,Pr as CamembertPreTrainedModel,Pd as CamembertTokenizer,bf as ChatterboxFeatureExtractor,yo as ChatterboxModel,Jl as ChatterboxPreTrainedModel,Pf as ChatterboxProcessor,Uf as ChineseCLIPFeatureExtractor,Th as ChineseCLIPModel,Zl as ChineseCLIPPreTrainedModel,vo as ClapAudioModelWithProjection,vf as ClapFeatureExtractor,Sh as ClapModel,an as ClapPreTrainedModel,bo as ClapTextModelWithProjection,Gl as ClassifierFreeGuidanceLogitsProcessor,$h as CodeGenForCausalLM,Nh as CodeGenModel,Ao as CodeGenPreTrainedModel,Nd as CodeGenTokenizer,Ld as CodeLlamaTokenizer,Uh as CohereForCausalLM,Rh as CohereModel,Mo as CoherePreTrainedModel,$d as CohereTokenizer,Dh as ConvBertForMaskedLM,Gh as ConvBertForQuestionAnswering,Fh as ConvBertForSequenceClassification,jh as ConvBertForTokenClassification,Bh as ConvBertModel,zr as ConvBertPreTrainedModel,Rd as ConvBertTokenizer,Df as ConvNextFeatureExtractor,Wh as ConvNextForImageClassification,ml as ConvNextImageProcessor,qh as ConvNextModel,To as ConvNextPreTrainedModel,Hh as ConvNextV2ForImageClassification,Vh as ConvNextV2Model,So as ConvNextV2PreTrainedModel,Qh as DFineForObjectDetection,Yh as DFineModel,Io as DFinePreTrainedModel,b_ as DINOv3ConvNextModel,ac as DINOv3ConvNextPreTrainedModel,Gf as DINOv3ViTImageProcessor,v_ as DINOv3ViTModel,ic as DINOv3ViTPreTrainedModel,Wf as DPTFeatureExtractor,I_ as DPTForDepthEstimation,gl as DPTImageProcessor,O_ as DPTModel,$o as DPTPreTrainedModel,Po as DacDecoderModel,tc as DacDecoderOutput,Co as DacEncoderModel,ec as DacEncoderOutput,so as DacFeatureExtractor,Jh as DacModel,ln as DacPreTrainedModel,e_ as DebertaForMaskedLM,s_ as DebertaForQuestionAnswering,t_ as DebertaForSequenceClassification,r_ as DebertaForTokenClassification,Zh as DebertaModel,Lr as DebertaPreTrainedModel,Bd as DebertaTokenizer,o_ as DebertaV2ForMaskedLM,l_ as DebertaV2ForQuestionAnswering,a_ as DebertaV2ForSequenceClassification,i_ as DebertaV2ForTokenClassification,n_ as DebertaV2Model,Nr as DebertaV2PreTrainedModel,Ud as DebertaV2Tokenizer,c_ as DecisionTransformerModel,rc as DecisionTransformerPreTrainedModel,Ff as DeiTFeatureExtractor,p_ as DeiTForImageClassification,hl as DeiTImageProcessor,u_ as DeiTModel,zo as DeiTPreTrainedModel,d_ as DepthAnythingForDepthEstimation,sc as DepthAnythingPreTrainedModel,Lu as DepthEstimationPipeline,f_ as DepthProForDepthEstimation,nc as DepthProPreTrainedModel,jf as DetrFeatureExtractor,h_ as DetrForObjectDetection,__ as DetrForSegmentation,_l as DetrImageProcessor,m_ as DetrModel,un as DetrObjectDetectionOutput,cn as DetrPreTrainedModel,oc as DetrSegmentationOutput,w_ as Dinov2ForImageClassification,g_ as Dinov2Model,Lo as Dinov2PreTrainedModel,y_ as Dinov2WithRegistersForImageClassification,x_ as Dinov2WithRegistersModel,No as Dinov2WithRegistersPreTrainedModel,T_ as DistilBertForMaskedLM,M_ as DistilBertForQuestionAnswering,E_ as DistilBertForSequenceClassification,A_ as DistilBertForTokenClassification,k_ as DistilBertModel,$r as DistilBertPreTrainedModel,Dd as DistilBertTokenizer,Pu as DocumentQuestionAnsweringPipeline,qf as DonutFeatureExtractor,Ks as DonutImageProcessor,S_ as DonutSwinModel,lc as DonutSwinPreTrainedModel,fy as EdgeTamModel,P_ as EfficientNetForImageClassification,Vf as EfficientNetImageProcessor,C_ as EfficientNetModel,Ro as EfficientNetPreTrainedModel,L_ as ElectraForMaskedLM,R_ as ElectraForQuestionAnswering,N_ as ElectraForSequenceClassification,$_ as ElectraForTokenClassification,z_ as ElectraModel,Rr as ElectraPreTrainedModel,Fd as ElectraTokenizer,ro as EncodecFeatureExtractor,Hl as EosTokenCriteria,B_ as Ernie4_5ForCausalLM,U_ as Ernie4_5Model,Uo as Ernie4_5PretrainedModel,F_ as EsmForMaskedLM,j_ as EsmForSequenceClassification,G_ as EsmForTokenClassification,D_ as EsmModel,ys as EsmPreTrainedModel,jd as EsmTokenizer,W_ as ExaoneForCausalLM,q_ as ExaoneModel,Bo as ExaonePreTrainedModel,H_ as FalconForCausalLM,K_ as FalconH1ForCausalLM,X_ as FalconH1Model,Fo as FalconH1PreTrainedModel,V_ as FalconModel,Do as FalconPreTrainedModel,Gd as FalconTokenizer,Q_ as FastViTForImageClassification,Y_ as FastViTModel,jo as FastViTPreTrainedModel,Nu as FeatureExtractionPipeline,Ne as FeatureExtractor,gu as FillMaskPipeline,J_ as Florence2ForConditionalGeneration,cc as Florence2PreTrainedModel,km as Florence2Processor,Nl as ForcedBOSTokenLogitsProcessor,$l as ForcedEOSTokenLogitsProcessor,Hf as GLPNFeatureExtractor,lg as GLPNForDepthEstimation,ig as GLPNModel,Xo as GLPNPreTrainedModel,wg as GPT2LMHeadModel,gg as GPT2Model,Zo as GPT2PreTrainedModel,Vd as GPT2Tokenizer,ug as GPTBigCodeForCausalLM,cg as GPTBigCodeModel,Ko as GPTBigCodePreTrainedModel,yg as GPTJForCausalLM,xg as GPTJModel,ea as GPTJPreTrainedModel,dg as GPTNeoForCausalLM,pg as GPTNeoModel,Yo as GPTNeoPreTrainedModel,mg as GPTNeoXForCausalLM,fg as GPTNeoXModel,Qo as GPTNeoXPreTrainedModel,Wd as GPTNeoXTokenizer,rg as Gemma2ForCausalLM,tg as Gemma2Model,qo as Gemma2PreTrainedModel,ng as Gemma3ForCausalLM,sg as Gemma3Model,Wo as Gemma3PreTrainedModel,kf as Gemma3nAudioFeatureExtractor,Vo as Gemma3nForConditionalGeneration,uc as Gemma3nPreTrainedModel,Em as Gemma3nProcessor,eg as GemmaForCausalLM,Z_ as GemmaModel,Go as GemmaPreTrainedModel,qd as GemmaTokenizer,ag as GlmForCausalLM,og as GlmModel,Ho as GlmPreTrainedModel,_g as GptOssForCausalLM,hg as GptOssModel,Jo as GptOssPreTrainedModel,vg as GraniteForCausalLM,bg as GraniteModel,Eg as GraniteMoeHybridForCausalLM,kg as GraniteMoeHybridModel,ra as GraniteMoeHybridPreTrainedModel,ta as GranitePreTrainedModel,Ag as GroundingDinoForObjectDetection,Xf as GroundingDinoImageProcessor,pc as GroundingDinoPreTrainedModel,Am as GroundingDinoProcessor,Mg as GroupViTModel,dc as GroupViTPreTrainedModel,Sg as HeliumForCausalLM,Tg as HeliumModel,sa as HeliumPreTrainedModel,Hd as HerbertTokenizer,Ig as HieraForImageClassification,Og as HieraModel,na as HieraPreTrainedModel,Rg as HubertForCTC,Ug as HubertForSequenceClassification,$g as HubertModel,Ng as HubertPreTrainedModel,Dg as HunYuanDenseV1ForCausalLM,Bg as HunYuanDenseV1Model,oa as HunYuanDenseV1PreTrainedModel,Gg as IJepaForImageClassification,jg as IJepaModel,aa as IJepaPreTrainedModel,mc as Idefics3ForConditionalGeneration,wl as Idefics3ImageProcessor,fc as Idefics3PreTrainedModel,Sl as Idefics3Processor,Tu as ImageClassificationPipeline,$u as ImageFeatureExtractionPipeline,W as ImageFeatureExtractor,W as ImageProcessor,Tn as ImageSegmentationPipeline,zu as ImageToImagePipeline,Mu as ImageToTextPipeline,JE as InterruptableStoppingCriteria,Wg as JAISLMHeadModel,qg as JAISModel,ia as JAISPreTrainedModel,Yf as JinaCLIPImageProcessor,Vg as JinaCLIPModel,pn as JinaCLIPPreTrainedModel,Tm as JinaCLIPProcessor,la as JinaCLIPTextModel,Hg as JinaCLIPVisionModel,Kg as Lfm2ForCausalLM,Xg as Lfm2Model,Qg as Lfm2MoeForCausalLM,Yg as Lfm2MoeModel,ua as Lfm2MoePreTrainedModel,ca as Lfm2PreTrainedModel,E0 as LiteWhisperForConditionalGeneration,ew as Llama4ForCausalLM,hc as Llama4PreTrainedModel,Zg as LlamaForCausalLM,Jg as LlamaModel,pa as LlamaPreTrainedModel,Xd as LlamaTokenizer,dn as LlavaForConditionalGeneration,dn as LlavaOnevisionForConditionalGeneration,Qf as LlavaOnevisionImageProcessor,_c as LlavaPreTrainedModel,Sm as LlavaProcessor,rw as LlavaQwen2ForCausalLM,jt as LogitsProcessor,hs as LogitsProcessorList,lo as LogitsWarper,nw as LongT5ForConditionalGeneration,sw as LongT5Model,da as LongT5PreTrainedModel,aw as M2M100ForConditionalGeneration,ow as M2M100Model,fa as M2M100PreTrainedModel,Kd as M2M100Tokenizer,Qd as MBart50Tokenizer,mw as MBartForCausalLM,dw as MBartForConditionalGeneration,fw as MBartForSequenceClassification,pw as MBartModel,bs as MBartPreTrainedModel,Jn as MBartTokenizer,Jw as MPNetForMaskedLM,tx as MPNetForQuestionAnswering,Zw as MPNetForSequenceClassification,ex as MPNetForTokenClassification,Qw as MPNetModel,Ur as MPNetPreTrainedModel,ef as MPNetTokenizer,ox as MT5ForConditionalGeneration,nx as MT5Model,Aa as MT5PreTrainedModel,lw as MarianMTModel,iw as MarianModel,ma as MarianPreTrainedModel,Yd as MarianTokenizer,Zf as Mask2FormerImageProcessor,Jf as MaskFormerFeatureExtractor,uw as MaskFormerForInstanceSegmentation,Ys as MaskFormerImageProcessor,cw as MaskFormerModel,ha as MaskFormerPreTrainedModel,Vl as MaxLengthCriteria,hw as Metric3DForDepthEstimation,gc as Metric3DPreTrainedModel,_w as Metric3Dv2ForDepthEstimation,wc as Metric3Dv2PreTrainedModel,gw as MgpstrForSceneTextRecognition,xc as MgpstrModelOutput,yc as MgpstrPreTrainedModel,Om as MgpstrProcessor,Jd as MgpstrTokenizer,ga as MimiDecoderModel,vc as MimiDecoderOutput,_a as MimiEncoderModel,bc as MimiEncoderOutput,ww as MimiModel,fn as MimiPreTrainedModel,Dl as MinLengthLogitsProcessor,Fl as MinNewTokensLengthLogitsProcessor,yw as MistralForCausalLM,xw as MistralModel,wa as MistralPreTrainedModel,vw as MobileBertForMaskedLM,Ew as MobileBertForQuestionAnswering,kw as MobileBertForSequenceClassification,bw as MobileBertModel,vs as MobileBertPreTrainedModel,Zd as MobileBertTokenizer,Mw as MobileLLMForCausalLM,Aw as MobileLLMModel,xa as MobileLLMPreTrainedModel,em as MobileNetV1FeatureExtractor,Sw as MobileNetV1ForImageClassification,Ow as MobileNetV1ForSemanticSegmentation,xl as MobileNetV1ImageProcessor,Tw as MobileNetV1Model,mn as MobileNetV1PreTrainedModel,tm as MobileNetV2FeatureExtractor,Cw as MobileNetV2ForImageClassification,Pw as MobileNetV2ForSemanticSegmentation,yl as MobileNetV2ImageProcessor,Iw as MobileNetV2Model,hn as MobileNetV2PreTrainedModel,rm as MobileNetV3FeatureExtractor,Lw as MobileNetV3ForImageClassification,Nw as MobileNetV3ForSemanticSegmentation,bl as MobileNetV3ImageProcessor,zw as MobileNetV3Model,_n as MobileNetV3PreTrainedModel,sm as MobileNetV4FeatureExtractor,Rw as MobileNetV4ForImageClassification,Uw as MobileNetV4ForSemanticSegmentation,vl as MobileNetV4ImageProcessor,$w as MobileNetV4Model,gn as MobileNetV4PreTrainedModel,nm as MobileViTFeatureExtractor,Dw as MobileViTForImageClassification,kl as MobileViTImageProcessor,Bw as MobileViTModel,ya as MobileViTPreTrainedModel,jw as MobileViTV2ForImageClassification,Fw as MobileViTV2Model,ba as MobileViTV2PreTrainedModel,Xw as ModernBertDecoderForCausalLM,Hw as ModernBertDecoderModel,va as ModernBertDecoderPreTrainedModel,qw as ModernBertForMaskedLM,Ww as ModernBertForSequenceClassification,Vw as ModernBertForTokenClassification,Gw as ModernBertModel,ks as ModernBertPreTrainedModel,tw as Moondream1ForConditionalGeneration,Ef as MoonshineFeatureExtractor,Yw as MoonshineForConditionalGeneration,Kw as MoonshineModel,ka as MoonshinePreTrainedModel,Im as MoonshineProcessor,sx as MptForCausalLM,rx as MptModel,Ea as MptPreTrainedModel,ax as MultiModalityCausalLM,kc as MultiModalityPreTrainedModel,lx as MusicgenForCausalLM,Ta as MusicgenForConditionalGeneration,ix as MusicgenModel,Ma as MusicgenPreTrainedModel,ux as NanoChatForCausalLM,cx as NanoChatModel,Sa as NanoChatPreTrainedModel,dx as NeoBertForMaskedLM,hx as NeoBertForQuestionAnswering,fx as NeoBertForSequenceClassification,mx as NeoBertForTokenClassification,px as NeoBertModel,Br as NeoBertPreTrainedModel,tf as NllbTokenizer,jl as NoBadWordsLogitsProcessor,Ul as NoRepeatNGramLogitsProcessor,_x as NomicBertModel,Ec as NomicBertPreTrainedModel,om as NougatImageProcessor,rf as NougatTokenizer,Mx as OPTForCausalLM,Ax as OPTModel,za as OPTPreTrainedModel,Iu as ObjectDetectionPipeline,yx as Olmo2ForCausalLM,xx as Olmo2Model,Ia as Olmo2PreTrainedModel,vx as Olmo3ForCausalLM,bx as Olmo3Model,Ca as Olmo3PreTrainedModel,wx as OlmoForCausalLM,gx as OlmoModel,Oa as OlmoPreTrainedModel,Ex as OpenELMForCausalLM,kx as OpenELMModel,Pa as OpenELMPreTrainedModel,am as OwlViTFeatureExtractor,Ix as OwlViTForObjectDetection,Qs as OwlViTImageProcessor,Ox as OwlViTModel,Na as OwlViTPreTrainedModel,Cm as OwlViTProcessor,Sx as Owlv2ForObjectDetection,im as Owlv2ImageProcessor,Tx as Owlv2Model,La as Owlv2PreTrainedModel,Cx as PaliGemmaForConditionalGeneration,Ac as PaliGemmaPreTrainedModel,Pm as PaliGemmaProcessor,Af as ParakeetFeatureExtractor,Px as ParakeetForCTC,Mc as ParakeetPreTrainedModel,Lx as PatchTSMixerForPrediction,zx as PatchTSMixerModel,$a as PatchTSMixerPreTrainedModel,$x as PatchTSTForPrediction,Nx as PatchTSTModel,Ra as PatchTSTPreTrainedModel,Dx as Phi3ForCausalLM,Bx as Phi3Model,Ba as Phi3PreTrainedModel,Da as Phi3VForCausalLM,um as Phi3VImageProcessor,Tc as Phi3VPreTrainedModel,zm as Phi3VProcessor,Ux as PhiForCausalLM,Rx as PhiModel,Ua as PhiPreTrainedModel,pm as PixtralImageProcessor,Lm as PixtralProcessor,y as PreTrainedModel,j as PreTrainedTokenizer,Pl as PretrainedConfig,ne as Processor,jx as PvtForImageClassification,dm as PvtImageProcessor,Fx as PvtModel,Fa as PvtPreTrainedModel,no as PyAnnoteFeatureExtractor,qx as PyAnnoteForAudioFrameClassification,Gx as PyAnnoteModel,ja as PyAnnotePreTrainedModel,Nm as PyAnnoteProcessor,_u as QuestionAnsweringPipeline,Vx as Qwen2ForCausalLM,Wx as Qwen2Model,Ga as Qwen2PreTrainedModel,sf as Qwen2Tokenizer,Hx as Qwen2VLForConditionalGeneration,fm as Qwen2VLImageProcessor,Sc as Qwen2VLPreTrainedModel,$m as Qwen2VLProcessor,Kx as Qwen3ForCausalLM,Xx as Qwen3Model,qa as Qwen3PreTrainedModel,Zx as RFDetrForObjectDetection,Jx as RFDetrModel,Oc as RFDetrObjectDetectionOutput,Va as RFDetrPreTrainedModel,Kh as RTDetrForObjectDetection,mm as RTDetrImageProcessor,Xh as RTDetrModel,lr as RTDetrObjectDetectionOutput,Oo as RTDetrPreTrainedModel,py as RTDetrV2ForObjectDetection,uy as RTDetrV2Model,Ic as RTDetrV2ObjectDetectionOutput,Ha as RTDetrV2PreTrainedModel,to as RawAudio,Xe as RawImage,Ru as RawVideo,wi as RawVideoFrame,Bl as RepetitionPenaltyLogitsProcessor,Qx as ResNetForImageClassification,Yx as ResNetModel,Wa as ResNetPreTrainedModel,ay as RoFormerForMaskedLM,cy as RoFormerForQuestionAnswering,iy as RoFormerForSequenceClassification,ly as RoFormerForTokenClassification,oy as RoFormerModel,Fr as RoFormerPreTrainedModel,of as RoFormerTokenizer,ty as RobertaForMaskedLM,ny as RobertaForQuestionAnswering,ry as RobertaForSequenceClassification,sy as RobertaForTokenClassification,ey as RobertaModel,Dr as RobertaPreTrainedModel,nf as RobertaTokenizer,ao as Sam2ImageProcessor,zc as Sam2ImageSegmentationOutput,Xa as Sam2Model,Lc as Sam2PreTrainedModel,Ol as Sam2Processor,Rm as Sam2VideoProcessor,ao as Sam3ImageProcessor,my as Sam3TrackerModel,ao as SamImageProcessor,Cc as SamImageSegmentationOutput,dy as SamModel,Pc as SamPreTrainedModel,io as SamProcessor,hm as SapiensFeatureExtractor,_y as SapiensForDepthEstimation,gy as SapiensForNormalEstimation,hy as SapiensForSemanticSegmentation,El as SapiensImageProcessor,wn as SapiensPreTrainedModel,Mf as SeamlessM4TFeatureExtractor,_m as SegformerFeatureExtractor,xy as SegformerForImageClassification,yy as SegformerForSemanticSegmentation,Al as SegformerImageProcessor,wy as SegformerModel,xn as SegformerPreTrainedModel,gm as SiglipImageProcessor,by as SiglipModel,Ka as SiglipPreTrainedModel,Ya as SiglipTextModel,af as SiglipTokenizer,vy as SiglipVisionModel,Ey as SmolLM3ForCausalLM,ky as SmolLM3Model,Qa as SmolLM3PreTrainedModel,Fg as SmolVLMForConditionalGeneration,wl as SmolVLMImageProcessor,Sl as SmolVLMProcessor,Za as SnacDecoderModel,Ja as SnacEncoderModel,Tf as SnacFeatureExtractor,Ay as SnacModel,yn as SnacPreTrainedModel,Sf as SpeechT5FeatureExtractor,Ty as SpeechT5ForSpeechToText,Sy as SpeechT5ForTextToSpeech,Oy as SpeechT5HifiGan,My as SpeechT5Model,bn as SpeechT5PreTrainedModel,Um as SpeechT5Processor,lf as SpeechT5Tokenizer,Cy as SqueezeBertForMaskedLM,zy as SqueezeBertForQuestionAnswering,Py as SqueezeBertForSequenceClassification,Iy as SqueezeBertModel,Es as SqueezeBertPreTrainedModel,cf as SqueezeBertTokenizer,Ny as StableLmForCausalLM,Ly as StableLmModel,ei as StableLmPreTrainedModel,Ry as Starcoder2ForCausalLM,$y as Starcoder2Model,ti as Starcoder2PreTrainedModel,nn as StoppingCriteria,Wl as StoppingCriteriaList,Uy as StyleTextToSpeech2Model,Nc as StyleTextToSpeech2PreTrainedModel,wu as SummarizationPipeline,ri as SupertonicForConditionalGeneration,$c as SupertonicPreTrainedModel,rn as SuppressTokensAtBeginLogitsProcessor,Gy as Swin2SRForImageSuperResolution,wm as Swin2SRImageProcessor,jy as Swin2SRModel,si as Swin2SRPreTrainedModel,Dy as SwinForImageClassification,Fy as SwinForSemanticSegmentation,By as SwinModel,vn as SwinPreTrainedModel,Wy as T5ForConditionalGeneration,qy as T5Model,ni as T5PreTrainedModel,uf as T5Tokenizer,Hy as TableTransformerForObjectDetection,Vy as TableTransformerModel,Rc as TableTransformerObjectDetectionOutput,oi as TableTransformerPreTrainedModel,ql as TemperatureLogitsWarper,U as Tensor,Vr as Text2TextGenerationPipeline,mu as TextClassificationPipeline,yu as TextGenerationPipeline,j0 as TextStreamer,Au as TextToAudioPipeline,hu as TokenClassificationPipeline,j as TokenizersBackend,QE as TopKLogitsWarper,YE as TopPLogitsWarper,Xy as TrOCRForCausalLM,Uc as TrOCRPreTrainedModel,xu as TranslationPipeline,Dc as UltravoxModel,Bc as UltravoxPreTrainedModel,Bm as UltravoxProcessor,Qy as UniSpeechForCTC,Jy as UniSpeechForSequenceClassification,Yy as UniSpeechModel,kn as UniSpeechPreTrainedModel,r0 as UniSpeechSatForAudioFrameClassification,e0 as UniSpeechSatForCTC,t0 as UniSpeechSatForSequenceClassification,Zy as UniSpeechSatModel,As as UniSpeechSatPreTrainedModel,Mm as VLChatProcessor,Kf as VLMImageProcessor,n0 as VaultGemmaForCausalLM,s0 as VaultGemmaModel,ai as VaultGemmaPreTrainedModel,xm as ViTFeatureExtractor,i0 as ViTForImageClassification,Ml as ViTImageProcessor,l0 as ViTMAEModel,Fc as ViTMAEPreTrainedModel,u0 as ViTMSNForImageClassification,c0 as ViTMSNModel,li as ViTMSNPreTrainedModel,a0 as ViTModel,ii as ViTPreTrainedModel,o0 as VisionEncoderDecoderModel,p0 as VitMatteForImageMatting,ym as VitMatteImageProcessor,jc as VitMattePreTrainedModel,d0 as VitPoseForPoseEstimation,bm as VitPoseImageProcessor,Gc as VitPosePreTrainedModel,f0 as VitsModel,qc as VitsModelOutput,Wc as VitsPreTrainedModel,df as VitsTokenizer,Ky as VoxtralForConditionalGeneration,Dm as VoxtralProcessor,h0 as Wav2Vec2BertForCTC,_0 as Wav2Vec2BertForSequenceClassification,m0 as Wav2Vec2BertModel,En as Wav2Vec2BertPreTrainedModel,ff as Wav2Vec2CTCTokenizer,Of as Wav2Vec2FeatureExtractor,Lg as Wav2Vec2ForAudioFrameClassification,Pg as Wav2Vec2ForCTC,zg as Wav2Vec2ForSequenceClassification,Cg as Wav2Vec2Model,Jt as Wav2Vec2PreTrainedModel,Fm as Wav2Vec2Processor,jm as Wav2Vec2ProcessorWithLM,b0 as WavLMForAudioFrameClassification,w0 as WavLMForCTC,x0 as WavLMForSequenceClassification,y0 as WavLMForXVector,g0 as WavLMModel,jr as WavLMPreTrainedModel,If as WeSpeakerFeatureExtractor,v0 as WeSpeakerResNetModel,Hc as WeSpeakerResNetPreTrainedModel,Cf as WhisperFeatureExtractor,Kc as WhisperForConditionalGeneration,k0 as WhisperModel,ci as WhisperPreTrainedModel,Gm as WhisperProcessor,qA as WhisperTextStreamer,Rl as WhisperTimeStampLogitsProcessor,mf as WhisperTokenizer,O0 as XLMForQuestionAnswering,T0 as XLMForSequenceClassification,S0 as XLMForTokenClassification,A0 as XLMModel,Gr as XLMPreTrainedModel,C0 as XLMRobertaForMaskedLM,L0 as XLMRobertaForQuestionAnswering,P0 as XLMRobertaForSequenceClassification,z0 as XLMRobertaForTokenClassification,I0 as XLMRobertaModel,qr as XLMRobertaPreTrainedModel,hf as XLMRobertaTokenizer,_f as XLMTokenizer,M0 as XLMWithLMHeadModel,Vc as XVectorOutput,vm as YolosFeatureExtractor,$0 as YolosForObjectDetection,Tl as YolosImageProcessor,N0 as YolosModel,Yc as YolosObjectDetectionOutput,ui as YolosPreTrainedModel,U0 as YoutuForCausalLM,R0 as YoutuModel,pi as YoutuPreTrainedModel,ku as ZeroShotAudioClassificationPipeline,bu as ZeroShotClassificationPipeline,Ou as ZeroShotImageClassificationPipeline,Cu as ZeroShotObjectDetectionPipeline,Ee as cat,fC as cos_sim,qv as dot,De as env,Ve as full,Qn as full_like,xd as interpolate,Dt as interpolate_4d,JN as layer_norm,gP as load_image,JP as load_video,vp as log_softmax,IE as matmul,al as mean,CE as mean_pooling,it as ones,il as ones_like,KC as permute,Eee as pipeline,zE as quantize_embeddings,ZN as rand,PE as randn,xf as read_audio,QN as rfft,ol as slice,Pe as softmax,Ft as stack,yd as std_mean,Yt as topk,vd as zeros,kd as zeros_like};